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