1 /* 2 * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 * Julun <host.haiku@gmx.de> 8 * 9 */ 10 11 #include "TimeWindow.h" 12 #include "BaseView.h" 13 #include "DateTimeView.h" 14 #include "TimeMessages.h" 15 #include "TimeSettings.h" 16 #include "ZoneView.h" 17 18 19 #include <Application.h> 20 #include <Message.h> 21 #include <Screen.h> 22 #include <TabView.h> 23 24 25 TTimeWindow::TTimeWindow(BRect rect) 26 : BWindow(rect, "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 27 { 28 _InitWindow(); 29 _AlignWindow(); 30 31 AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED)); 32 } 33 34 35 TTimeWindow::~TTimeWindow() 36 { 37 } 38 39 40 void 41 TTimeWindow::MessageReceived(BMessage *message) 42 { 43 switch(message->what) { 44 case H_USER_CHANGE: 45 fBaseView->ChangeTime(message); 46 break; 47 48 case B_ABOUT_REQUESTED: 49 be_app->PostMessage(B_ABOUT_REQUESTED); 50 break; 51 52 default: 53 BWindow::MessageReceived(message); 54 break; 55 } 56 } 57 58 59 bool 60 TTimeWindow::QuitRequested() 61 { 62 TimeSettings().SetLeftTop(Frame().LeftTop()); 63 64 fBaseView->StopWatchingAll(fTimeZoneView); 65 fBaseView->StopWatchingAll(fDateTimeView); 66 67 be_app->PostMessage(B_QUIT_REQUESTED); 68 69 return BWindow::QuitRequested(); 70 } 71 72 73 void 74 TTimeWindow::_InitWindow() 75 { 76 SetPulseRate(500000); 77 78 fDateTimeView = new DateTimeView(Bounds()); 79 80 BRect bounds = fDateTimeView->Bounds(); 81 fTimeZoneView = new TimeZoneView(bounds); 82 83 fBaseView = new TTimeBaseView(bounds, "baseView"); 84 AddChild(fBaseView); 85 86 fBaseView->StartWatchingAll(fDateTimeView); 87 fBaseView->StartWatchingAll(fTimeZoneView); 88 89 bounds.OffsetBy(10.0, 10.0); 90 BTabView *tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0), 91 "tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE); 92 93 BTab *tab = new BTab(); 94 tabView->AddTab(fDateTimeView, tab); 95 tab->SetLabel("Date & Time"); 96 97 tab = new BTab(); 98 tabView->AddTab(fTimeZoneView, tab); 99 tab->SetLabel("Timezone"); 100 101 fBaseView->AddChild(tabView); 102 tabView->ResizeBy(0.0, tabView->TabHeight()); 103 fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0, 104 tabView->Bounds().Height() + 10.0); 105 106 ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); 107 } 108 109 110 void 111 TTimeWindow::_AlignWindow() 112 { 113 BPoint pt = TimeSettings().LeftTop(); 114 MoveTo(pt); 115 116 BRect frame = Frame(); 117 BRect screen = BScreen().Frame(); 118 if (!frame.Intersects(screen.InsetByCopy(50.0, 50.0))) { 119 BRect bounds(Bounds()); 120 BPoint leftTop((screen.Width() - bounds.Width()) / 2.0, 121 (screen.Height() - bounds.Height()) / 2.0); 122 123 MoveTo(leftTop); 124 } 125 } 126