From dc7de148c3be9339fbab75663b248b929b690d08 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Sat, 20 Oct 2007 18:56:20 +0000 Subject: [PATCH] * save and load the window position inside window class, center on first start git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22627 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/time/Time.cpp | 35 +++++----------- src/preferences/time/Time.h | 2 - src/preferences/time/TimeMessages.h | 4 -- src/preferences/time/TimeSettings.cpp | 2 +- src/preferences/time/TimeWindow.cpp | 58 +++++++++++++++++---------- src/preferences/time/TimeWindow.h | 6 ++- 6 files changed, 51 insertions(+), 56 deletions(-) diff --git a/src/preferences/time/Time.cpp b/src/preferences/time/Time.cpp index a36b42a317..76a2e6966c 100644 --- a/src/preferences/time/Time.cpp +++ b/src/preferences/time/Time.cpp @@ -9,24 +9,23 @@ */ #include "Time.h" -#include "TimeMessages.h" -#include "TimeSettings.h" #include "TimeWindow.h" #include -#include #include +const char* kAppSignature = "application/x-vnd.Be-TIME"; + + TimeApplication::TimeApplication() - : BApplication(HAIKU_APP_SIGNATURE), + : BApplication(kAppSignature), fWindow(NULL) { - BPoint pt = TimeSettings().LeftTop(); - fWindow = new TTimeWindow(pt); + fWindow = new TTimeWindow(BRect(100, 100, 570, 327)); } @@ -35,24 +34,6 @@ TimeApplication::~TimeApplication() } -void -TimeApplication::MessageReceived(BMessage *message) -{ - switch (message->what) { - case UPDATE_SETTINGS: - { - BPoint pt; - if (message->FindPoint("LeftTop", &pt) == B_OK) - TimeSettings().SetLeftTop(pt); - } break; - - default: - BApplication::MessageReceived(message); - break; - } -} - - void TimeApplication::ReadyToRun() { @@ -63,8 +44,10 @@ TimeApplication::ReadyToRun() void TimeApplication::AboutRequested() { - BAlert alert("about", "Time & Date, by\n\nAndrew Edward McCall\nMike Berg", "OK"); - alert.Go(); + BAlert *alert = new BAlert("about", + "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" + "Julun\n\nCopyright 2004-2007, Haiku.", "OK"); + alert->Go(); } diff --git a/src/preferences/time/Time.h b/src/preferences/time/Time.h index 5df1d5aa3e..82fe0500d0 100644 --- a/src/preferences/time/Time.h +++ b/src/preferences/time/Time.h @@ -14,7 +14,6 @@ #include -class BMessage; class TTimeWindow; @@ -23,7 +22,6 @@ class TimeApplication : public BApplication { TimeApplication(); virtual ~TimeApplication(); - virtual void MessageReceived(BMessage* message); virtual void ReadyToRun(); virtual void AboutRequested(); diff --git a/src/preferences/time/TimeMessages.h b/src/preferences/time/TimeMessages.h index 73fb36e67c..9468a80bed 100644 --- a/src/preferences/time/TimeMessages.h +++ b/src/preferences/time/TimeMessages.h @@ -10,10 +10,6 @@ #ifndef TIME_MESSAGES_H #define TIME_MESSAGES_H -#define HAIKU_APP_SIGNATURE "application/x-vnd.Be-TIME" - -const uint32 UPDATE_SETTINGS = 'TDUS'; - //Timezone messages const uint32 H_REGION_CHANGED = 'h_RC'; const uint32 H_CITY_CHANGED = 'h_CC'; diff --git a/src/preferences/time/TimeSettings.cpp b/src/preferences/time/TimeSettings.cpp index cb4ad3a5a2..47a556641f 100644 --- a/src/preferences/time/TimeSettings.cpp +++ b/src/preferences/time/TimeSettings.cpp @@ -33,7 +33,7 @@ BPoint TimeSettings::LeftTop() const { BPath path; - BPoint leftTop(50.0, 50.0); + BPoint leftTop(-1000.0, -1000.0); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(fSettingsFile.String()); diff --git a/src/preferences/time/TimeWindow.cpp b/src/preferences/time/TimeWindow.cpp index 5248682625..03c54d1f92 100644 --- a/src/preferences/time/TimeWindow.cpp +++ b/src/preferences/time/TimeWindow.cpp @@ -12,6 +12,7 @@ #include "BaseView.h" #include "DateTimeView.h" #include "TimeMessages.h" +#include "TimeSettings.h" #include "ZoneView.h" @@ -21,24 +22,18 @@ #include -#define WINDOW_RIGHT 470 -#define WINDOW_BOTTOM 227 - - -TTimeWindow::TTimeWindow(const BPoint leftTop) - : BWindow(BRect(leftTop, leftTop + BPoint(WINDOW_RIGHT, WINDOW_BOTTOM)), - "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +TTimeWindow::TTimeWindow(BRect rect) + : BWindow(rect, "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +{ + _InitWindow(); + _AlignWindow(); + + AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED)); +} + + +TTimeWindow::~TTimeWindow() { - BRect frame = Frame(); - BRect bounds = Bounds(); - BRect screenFrame = BScreen().Frame(); - // Code to make sure that the window doesn't get drawn off screen... - if (!(screenFrame.right >= frame.right && screenFrame.bottom >= frame.bottom)) - MoveTo((screenFrame.right - bounds.right) * 0.5f, - (screenFrame.bottom - bounds.bottom) * 0.5f); - - _InitWindow(); - SetPulseRate(500000); } @@ -50,6 +45,10 @@ TTimeWindow::MessageReceived(BMessage *message) fBaseView->ChangeTime(message); break; + case B_ABOUT_REQUESTED: + be_app->PostMessage(B_ABOUT_REQUESTED); + break; + default: BWindow::MessageReceived(message); break; @@ -60,10 +59,8 @@ TTimeWindow::MessageReceived(BMessage *message) bool TTimeWindow::QuitRequested() { - BMessage msg(UPDATE_SETTINGS); - msg.AddPoint("LeftTop", Frame().LeftTop()); - be_app->PostMessage(&msg); - + TimeSettings().SetLeftTop(Frame().LeftTop()); + fBaseView->StopWatchingAll(fTimeZones); fBaseView->StopWatchingAll(fDateTimeView); @@ -76,6 +73,8 @@ TTimeWindow::QuitRequested() void TTimeWindow::_InitWindow() { + SetPulseRate(500000); + BRect bounds(Bounds()); fBaseView = new TTimeBaseView(bounds, "background view"); @@ -112,3 +111,20 @@ TTimeWindow::_InitWindow() ResizeTo(width +10, height + tabview->TabHeight() +25); } + +void +TTimeWindow::_AlignWindow() +{ + BPoint pt = TimeSettings().LeftTop(); + MoveTo(pt); + + BRect frame = Frame(); + BRect screen = BScreen().Frame(); + if (!frame.Intersects(screen.InsetByCopy(50.0, 50.0))) { + BRect bounds(Bounds()); + BPoint leftTop((screen.Width() - bounds.Width()) / 2.0, + (screen.Height() - bounds.Height()) / 2.0); + + MoveTo(leftTop); + } +} diff --git a/src/preferences/time/TimeWindow.h b/src/preferences/time/TimeWindow.h index 251b6c25eb..4ad01440c8 100644 --- a/src/preferences/time/TimeWindow.h +++ b/src/preferences/time/TimeWindow.h @@ -22,15 +22,17 @@ class TZoneView; class TTimeWindow : public BWindow { public: - TTimeWindow(const BPoint topLeft); - virtual ~TTimeWindow() {} + TTimeWindow(BRect rect); + virtual ~TTimeWindow(); virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); private: void _InitWindow(); + void _AlignWindow(); + private: TTimeBaseView *fBaseView; DateTimeView *fDateTimeView; TZoneView *fTimeZones;