* 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 "TimeMessages.h"
#include "TimeSettings.h"
#include "TimeWindow.h"
#include <Alert.h>
#include <Message.h>
#include <unistd.h>
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();
}
-2
View File
@@ -14,7 +14,6 @@
#include <Application.h>
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();
-4
View File
@@ -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';
+1 -1
View File
@@ -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());
+37 -21
View File
@@ -12,6 +12,7 @@
#include "BaseView.h"
#include "DateTimeView.h"
#include "TimeMessages.h"
#include "TimeSettings.h"
#include "ZoneView.h"
@@ -21,24 +22,18 @@
#include <TabView.h>
#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);
}
}
+4 -2
View File
@@ -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;