xref: /haiku/src/preferences/time/TimeWindow.cpp (revision 0b2dbe7d46ee888392907c60131b7f7652314175)
1 /*
2  * TTimeWindow.cpp
3  * Time mccall@@digitalparadise.co.uk
4  *
5  */
6 
7 #include <Application.h>
8 #include <Message.h>
9 #include <Screen.h>
10 #include <TabView.h>
11 #include <stdio.h>
12 
13 #include "BaseView.h"
14 #include "Time.h"
15 #include "TimeMessages.h"
16 #include "TimeView.h"
17 #include "TimeWindow.h"
18 
19 #define TIME_WINDOW_RIGHT	361 //332
20 #define TIME_WINDOW_BOTTOM	227 //208
21 
22 
23 TTimeWindow::TTimeWindow()
24 	: BWindow(BRect(0,0,TIME_WINDOW_RIGHT,TIME_WINDOW_BOTTOM),
25 		"Time & Date", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
26 {
27 	BScreen screen;
28 
29 	MoveTo(dynamic_cast<TimeApplication *>(be_app)->WindowCorner());
30 
31 	// Code to make sure that the window doesn't get drawn off screen...
32 	if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom))
33 		MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5);
34 
35 	InitWindow();
36 	SetPulseRate(500000);
37 }
38 
39 
40 TTimeWindow::~TTimeWindow()
41 {
42 }
43 
44 
45 void
46 TTimeWindow::MessageReceived(BMessage *message)
47 {
48 	switch(message->what) {
49 		case H_USER_CHANGE:
50 		{
51 			bool istime;
52 			if (message->FindBool("time", &istime) == B_OK)
53 				f_BaseView->ChangeTime(message);
54 		}
55 		break;
56 		case H_RTC_CHANGE:
57 		{
58 			f_BaseView->SetGMTime(f_TimeSettings->GMTime());
59 		}
60 		break;
61 
62 		default:
63 			BWindow::MessageReceived(message);
64 		break;
65 	}
66 }
67 
68 
69 bool
70 TTimeWindow::QuitRequested()
71 {
72 	dynamic_cast<TimeApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
73 
74 	f_BaseView->StopWatchingAll(f_TimeSettings);
75 	f_BaseView->StopWatchingAll(f_TimeZones);
76 
77 	be_app->PostMessage(B_QUIT_REQUESTED);
78 
79 	return(true);
80 
81 }
82 
83 
84 void
85 TTimeWindow::InitWindow()
86 {
87 	BRect bounds(Bounds());
88 
89 	f_BaseView = new TTimeBaseView(bounds, "background view");
90 	f_BaseView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
91 	AddChild(f_BaseView);
92 
93 	bounds.top = 9;
94 	BTabView *tabview = new BTabView(bounds, "tab_view");
95 
96 	bounds = tabview->Bounds();
97 	bounds.InsetBy(4, 6);
98 	bounds.bottom -= tabview->TabHeight();
99 
100 	f_TimeSettings = new TSettingsView(bounds);
101 	if (f_BaseView->StartWatchingAll(f_TimeSettings) != B_OK)
102 		printf("StartWatchingAll(TimeSettings) failed!!!\n");
103 
104 	f_TimeZones = new TZoneView(bounds);
105 	if (f_BaseView->StartWatchingAll(f_TimeZones) != B_OK)
106 		printf("TimeZones->StartWatchingAll(TimeZone) failed!!!\n");
107 	// add tabs
108 	BTab *tab;
109 	tab = new BTab();
110 	tabview->AddTab(f_TimeSettings, tab);
111 	tab->SetLabel("Settings");
112 
113 	tab = new BTab();
114 	tabview->AddTab(f_TimeZones, tab);
115 	tab->SetLabel("Time Zone");
116 
117 	f_BaseView->AddChild(tabview);
118 	f_BaseView->Pulse();
119 
120 }
121