tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / time / TimeWindow.cpp
blobf3545892d2738397f2f57b9e5dae8657d10b652d
1 /*
2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Andrew McCall <mccall@@digitalparadise.co.uk>
7 * Julun <host.haiku@gmx.de>
8 * Hamish Morrison <hamish@lavabit.com>
9 */
11 #include "TimeWindow.h"
13 #include <Application.h>
14 #include <Button.h>
15 #include <Catalog.h>
16 #include <LayoutBuilder.h>
17 #include <Message.h>
18 #include <Screen.h>
19 #include <TabView.h>
21 #include "BaseView.h"
22 #include "ClockView.h"
23 #include "DateTimeView.h"
24 #include "NetworkTimeView.h"
25 #include "TimeMessages.h"
26 #include "TimeSettings.h"
27 #include "ZoneView.h"
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "Time"
33 TTimeWindow::TTimeWindow()
35 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Time"), B_TITLED_WINDOW,
36 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
38 _InitWindow();
39 _AlignWindow();
41 AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED));
45 TTimeWindow::~TTimeWindow()
50 bool
51 TTimeWindow::QuitRequested()
53 TimeSettings().SetLeftTop(Frame().LeftTop());
55 fBaseView->StopWatchingAll(fTimeZoneView);
56 fBaseView->StopWatchingAll(fDateTimeView);
58 be_app->PostMessage(B_QUIT_REQUESTED);
60 return BWindow::QuitRequested();
64 void
65 TTimeWindow::MessageReceived(BMessage* message)
67 switch(message->what) {
68 case H_USER_CHANGE:
69 fBaseView->ChangeTime(message);
70 // To make sure no old time message is in the queue
71 _SendTimeChangeFinished();
72 _SetRevertStatus();
73 break;
75 case B_ABOUT_REQUESTED:
76 be_app->PostMessage(B_ABOUT_REQUESTED);
77 break;
79 case kMsgRevert:
80 fDateTimeView->MessageReceived(message);
81 fTimeZoneView->MessageReceived(message);
82 fNetworkTimeView->MessageReceived(message);
83 fClockView->MessageReceived(message);
84 fRevertButton->SetEnabled(false);
85 break;
87 case kRTCUpdate:
88 fDateTimeView->MessageReceived(message);
89 fTimeZoneView->MessageReceived(message);
90 _SetRevertStatus();
91 break;
93 case kMsgChange:
94 _SetRevertStatus();
95 break;
97 case kSelectClockTab:
98 // focus the clock tab (last one)
99 fTabView->Select(fTabView->CountTabs() - 1);
100 break;
102 case kShowHideTime:
103 fClockView->MessageReceived(message);
104 break;
106 default:
107 BWindow::MessageReceived(message);
108 break;
113 void
114 TTimeWindow::_InitWindow()
116 SetPulseRate(500000);
118 fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time"));
119 fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone"));
120 fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time"));
121 fClockView = new ClockView(B_TRANSLATE("Clock"));
123 fBaseView = new TTimeBaseView("baseView");
124 fBaseView->StartWatchingAll(fDateTimeView);
125 fBaseView->StartWatchingAll(fTimeZoneView);
127 fTabView = new BTabView("tabView", B_WIDTH_FROM_WIDEST);
128 fTabView->AddTab(fDateTimeView);
129 fTabView->AddTab(fTimeZoneView);
130 fTabView->AddTab(fNetworkTimeView);
131 fTabView->AddTab(fClockView);
133 fBaseView->AddChild(fTabView);
135 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
136 new BMessage(kMsgRevert));
137 fRevertButton->SetEnabled(false);
138 fRevertButton->SetTarget(this);
139 fRevertButton->SetExplicitAlignment(
140 BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
142 BLayoutBuilder::Group<>(this, B_VERTICAL)
143 .SetInsets(B_USE_DEFAULT_SPACING)
144 .Add(fBaseView)
145 .Add(fRevertButton);
149 void
150 TTimeWindow::_AlignWindow()
152 BPoint pt = TimeSettings().LeftTop();
153 MoveTo(pt);
155 BRect frame = Frame();
156 BRect screen = BScreen().Frame();
157 if (!frame.Intersects(screen.InsetByCopy(50.0, 50.0))) {
158 BRect bounds(Bounds());
159 BPoint leftTop((screen.Width() - bounds.Width()) / 2.0,
160 (screen.Height() - bounds.Height()) / 2.0);
162 MoveTo(leftTop);
167 void
168 TTimeWindow::_SendTimeChangeFinished()
170 BMessenger messenger(fDateTimeView);
171 BMessage msg(kChangeTimeFinished);
172 messenger.SendMessage(&msg);
176 void
177 TTimeWindow::_SetRevertStatus()
179 fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert()
180 || fTimeZoneView->CheckCanRevert()
181 || fNetworkTimeView->CheckCanRevert()
182 || fClockView->CheckCanRevert());