From 020fbae790fce3b5b955fb0bb64f3c675aa47e07 Mon Sep 17 00:00:00 2001 From: Phil Greenway Date: Mon, 19 Aug 2002 22:02:05 +0000 Subject: [PATCH] Loads and Saves Window Position using Flatten BMessages git-svn-id: file:///srv/svn/repos/haiku/trunk/current@828 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/dun/DUNWindow.cpp | 61 ++++++++++++++++++++++++++++++++++--- src/prefs/dun/DUNWindow.h | 3 ++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/prefs/dun/DUNWindow.cpp b/src/prefs/dun/DUNWindow.cpp index 2648bf1953..5328c8bc9a 100644 --- a/src/prefs/dun/DUNWindow.cpp +++ b/src/prefs/dun/DUNWindow.cpp @@ -8,15 +8,19 @@ DUNWindow by Sikosis (beos@gravity24hr.com) #include "app/Application.h" #include +#include #include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -236,6 +240,16 @@ void DUNWindow::InitWindow(void) { // Add the Drawing View AddChild(aDUNview = new DUNView(r)); + + // Load User Settings + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY,&path); + path.Append("DUN/OBOS_DUN_settings",true); + BFile file(path.Path(),B_READ_ONLY); + BMessage msg; + msg.Unflatten(&file); + LoadSettings (&msg); + } // ------------------------------------------------------------------------------- // @@ -250,13 +264,52 @@ DUNWindow::~DUNWindow() { } // ------------------------------------------------------------------------------- // -// DUNWindow::QuitRequested -- Post a message to the app to quit -bool DUNWindow::QuitRequested() { - be_app->PostMessage(B_QUIT_REQUESTED); - return true; + +// DUNWindow::LoadSettings -- Loads your current DUN settings +void DUNWindow::LoadSettings(BMessage *msg) +{ + BRect frame; + if (B_OK == msg->FindRect("windowframe",&frame)) { + MoveTo(frame.left,frame.top); + ResizeTo(frame.right-frame.left,frame.bottom-frame.top); + } + } // ------------------------------------------------------------------------------- // + +// DUNWindow::SaveSettings -- Saves the Users DUN settings +void DUNWindow::SaveSettings(void) +{ + BMessage msg; + msg.AddRect("windowframe",Frame()); + + /*int selection=ListView1->CurrentSelection(0); + if (selection>=0) + msg.AddString("modulename", ((BStringItem *)(ListView1->ItemAt(selection)))->Text()); + msg.what=POPULATE; */ + + BPath path; + status_t result = find_directory(B_USER_SETTINGS_DIRECTORY,&path); + if (result == B_OK) + { + path.Append("DUN/OBOS_DUN_settings",true); + BFile file(path.Path(),B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); + msg.Flatten(&file); + } +} +// ------------------------------------------------------------------------------- // + + +// DUNWindow::QuitRequested -- Post a message to the app to quit +bool DUNWindow::QuitRequested() { + SaveSettings(); + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} +// ------------------------------------------------------------------------------- // + + // DUNWindow::MessageReceived -- receives messages void DUNWindow::MessageReceived (BMessage *message) { switch(message->what) { diff --git a/src/prefs/dun/DUNWindow.h b/src/prefs/dun/DUNWindow.h index 1aa110e2c4..a724d0c987 100644 --- a/src/prefs/dun/DUNWindow.h +++ b/src/prefs/dun/DUNWindow.h @@ -19,6 +19,9 @@ public: ~DUNWindow(); virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); + + void LoadSettings(BMessage *msg); + void SaveSettings(void); private: ModemWindow *modemWindow; void InitWindow(void);