* 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
This commit is contained in:
Karsten Heimrich
2007-10-20 18:56:20 +00:00
parent 2e548bd870
commit dc7de148c3
6 changed files with 51 additions and 56 deletions
+9 -26
View File
@@ -9,24 +9,23 @@
*/ */
#include "Time.h" #include "Time.h"
#include "TimeMessages.h"
#include "TimeSettings.h"
#include "TimeWindow.h" #include "TimeWindow.h"
#include <Alert.h> #include <Alert.h>
#include <Message.h>
#include <unistd.h> #include <unistd.h>
const char* kAppSignature = "application/x-vnd.Be-TIME";
TimeApplication::TimeApplication() TimeApplication::TimeApplication()
: BApplication(HAIKU_APP_SIGNATURE), : BApplication(kAppSignature),
fWindow(NULL) fWindow(NULL)
{ {
BPoint pt = TimeSettings().LeftTop(); fWindow = new TTimeWindow(BRect(100, 100, 570, 327));
fWindow = new TTimeWindow(pt);
} }
@@ -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 void
TimeApplication::ReadyToRun() TimeApplication::ReadyToRun()
{ {
@@ -63,8 +44,10 @@ TimeApplication::ReadyToRun()
void void
TimeApplication::AboutRequested() TimeApplication::AboutRequested()
{ {
BAlert alert("about", "Time & Date, by\n\nAndrew Edward McCall\nMike Berg", "OK"); BAlert *alert = new BAlert("about",
alert.Go(); "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
"Julun\n\nCopyright 2004-2007, Haiku.", "OK");
alert->Go();
} }
-2
View File
@@ -14,7 +14,6 @@
#include <Application.h> #include <Application.h>
class BMessage;
class TTimeWindow; class TTimeWindow;
@@ -23,7 +22,6 @@ class TimeApplication : public BApplication {
TimeApplication(); TimeApplication();
virtual ~TimeApplication(); virtual ~TimeApplication();
virtual void MessageReceived(BMessage* message);
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void AboutRequested(); virtual void AboutRequested();
-4
View File
@@ -10,10 +10,6 @@
#ifndef TIME_MESSAGES_H #ifndef TIME_MESSAGES_H
#define TIME_MESSAGES_H #define TIME_MESSAGES_H
#define HAIKU_APP_SIGNATURE "application/x-vnd.Be-TIME"
const uint32 UPDATE_SETTINGS = 'TDUS';
//Timezone messages //Timezone messages
const uint32 H_REGION_CHANGED = 'h_RC'; const uint32 H_REGION_CHANGED = 'h_RC';
const uint32 H_CITY_CHANGED = 'h_CC'; const uint32 H_CITY_CHANGED = 'h_CC';
+1 -1
View File
@@ -33,7 +33,7 @@ BPoint
TimeSettings::LeftTop() const TimeSettings::LeftTop() const
{ {
BPath path; BPath path;
BPoint leftTop(50.0, 50.0); BPoint leftTop(-1000.0, -1000.0);
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
path.Append(fSettingsFile.String()); path.Append(fSettingsFile.String());
+35 -19
View File
@@ -12,6 +12,7 @@
#include "BaseView.h" #include "BaseView.h"
#include "DateTimeView.h" #include "DateTimeView.h"
#include "TimeMessages.h" #include "TimeMessages.h"
#include "TimeSettings.h"
#include "ZoneView.h" #include "ZoneView.h"
@@ -21,24 +22,18 @@
#include <TabView.h> #include <TabView.h>
#define WINDOW_RIGHT 470 TTimeWindow::TTimeWindow(BRect rect)
#define WINDOW_BOTTOM 227 : BWindow(rect, "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
TTimeWindow::TTimeWindow(const BPoint leftTop)
: BWindow(BRect(leftTop, leftTop + BPoint(WINDOW_RIGHT, WINDOW_BOTTOM)),
"Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{ {
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(); _InitWindow();
SetPulseRate(500000); _AlignWindow();
AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED));
}
TTimeWindow::~TTimeWindow()
{
} }
@@ -50,6 +45,10 @@ TTimeWindow::MessageReceived(BMessage *message)
fBaseView->ChangeTime(message); fBaseView->ChangeTime(message);
break; break;
case B_ABOUT_REQUESTED:
be_app->PostMessage(B_ABOUT_REQUESTED);
break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -60,9 +59,7 @@ TTimeWindow::MessageReceived(BMessage *message)
bool bool
TTimeWindow::QuitRequested() TTimeWindow::QuitRequested()
{ {
BMessage msg(UPDATE_SETTINGS); TimeSettings().SetLeftTop(Frame().LeftTop());
msg.AddPoint("LeftTop", Frame().LeftTop());
be_app->PostMessage(&msg);
fBaseView->StopWatchingAll(fTimeZones); fBaseView->StopWatchingAll(fTimeZones);
fBaseView->StopWatchingAll(fDateTimeView); fBaseView->StopWatchingAll(fDateTimeView);
@@ -76,6 +73,8 @@ TTimeWindow::QuitRequested()
void void
TTimeWindow::_InitWindow() TTimeWindow::_InitWindow()
{ {
SetPulseRate(500000);
BRect bounds(Bounds()); BRect bounds(Bounds());
fBaseView = new TTimeBaseView(bounds, "background view"); fBaseView = new TTimeBaseView(bounds, "background view");
@@ -112,3 +111,20 @@ TTimeWindow::_InitWindow()
ResizeTo(width +10, height + tabview->TabHeight() +25); 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);
}
}
+4 -2
View File
@@ -22,15 +22,17 @@ class TZoneView;
class TTimeWindow : public BWindow { class TTimeWindow : public BWindow {
public: public:
TTimeWindow(const BPoint topLeft); TTimeWindow(BRect rect);
virtual ~TTimeWindow() {} virtual ~TTimeWindow();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
private: private:
void _InitWindow(); void _InitWindow();
void _AlignWindow();
private:
TTimeBaseView *fBaseView; TTimeBaseView *fBaseView;
DateTimeView *fDateTimeView; DateTimeView *fDateTimeView;
TZoneView *fTimeZones; TZoneView *fTimeZones;