diff --git a/src/preferences/printers/Jamfile b/src/preferences/printers/Jamfile index 3944c92d7b..0ac27d02c3 100644 --- a/src/preferences/printers/Jamfile +++ b/src/preferences/printers/Jamfile @@ -8,6 +8,7 @@ Preference Printers : PrintersWindow.cpp PrinterListView.cpp JobListView.cpp + ScreenSettings.cpp SpoolFolder.cpp TestPageView.cpp TransportMenu.cpp diff --git a/src/preferences/printers/Printers.cpp b/src/preferences/printers/Printers.cpp index 916f2ff965..b8b565f373 100644 --- a/src/preferences/printers/Printers.cpp +++ b/src/preferences/printers/Printers.cpp @@ -14,13 +14,14 @@ #include "pr_server.h" #include "Messages.h" #include "PrintersWindow.h" +#include "ScreenSettings.h" int main() { PrintersApp app; - app.Run(); + app.Run(); return 0; } @@ -34,7 +35,7 @@ PrintersApp::PrintersApp() void PrintersApp::ReadyToRun() { - PrintersWindow* win = new PrintersWindow(BRect(78, 71, 561, 409)); + PrintersWindow* win = new PrintersWindow(new ScreenSettings()); win->Show(); } diff --git a/src/preferences/printers/Printers.h b/src/preferences/printers/Printers.h index 6b5bcaf477..657e89ac6d 100644 --- a/src/preferences/printers/Printers.h +++ b/src/preferences/printers/Printers.h @@ -12,6 +12,8 @@ #include #include +#include "ScreenSettings.h" + #define PRINTERS_SIGNATURE "application/x-vnd.Be-PRNT" diff --git a/src/preferences/printers/PrintersWindow.cpp b/src/preferences/printers/PrintersWindow.cpp index d5afdbad75..9d534c18a2 100644 --- a/src/preferences/printers/PrintersWindow.cpp +++ b/src/preferences/printers/PrintersWindow.cpp @@ -32,6 +32,7 @@ #include "Messages.h" #include "PrinterListView.h" #include "TestPageView.h" +#include "ScreenSettings.h" #include "SpoolFolder.h" @@ -44,15 +45,16 @@ public: TestPageWindow(BPrintJob* job, PrinterItem* printer); virtual ~TestPageWindow(); - void MessageReceived(BMessage* message); + void MessageReceived(BMessage* message); private: - BPrintJob* fJob; - TestPageView* fTestPage; + BPrintJob* fJob; + TestPageView* fTestPage; }; TestPageWindow::TestPageWindow(BPrintJob* job, PrinterItem* printer) - : BWindow(job->PaperRect().OffsetByCopy(-20000, -20000), B_TRANSLATE("Test page"), + : BWindow(job->PaperRect().OffsetByCopy(-20000, -20000), + B_TRANSLATE("Test page"), B_TITLED_WINDOW, 0), fJob(job) { fTestPage = new TestPageView(job->PrintableRect(), printer); @@ -93,10 +95,11 @@ TestPageWindow::MessageReceived(BMessage* message) // #pragma mark PrintersWindow main class -PrintersWindow::PrintersWindow(BRect frame) +PrintersWindow::PrintersWindow(ScreenSettings* settings) : - BWindow(BRect(78, 71, 761, 509), B_TRANSLATE_SYSTEM_NAME("Printers"), + BWindow(settings->WindowFrame(), B_TRANSLATE_SYSTEM_NAME("Printers"), B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS), + fSettings(settings), fSelectedPrinter(NULL), fAddingPrinter(false) { @@ -104,9 +107,17 @@ PrintersWindow::PrintersWindow(BRect frame) } +PrintersWindow::~PrintersWindow() +{ + delete fSettings; +} + + bool PrintersWindow::QuitRequested() { + fSettings->SetWindowFrame(Frame()); + bool result = Inherited::QuitRequested(); if (result) be_app->PostMessage(B_QUIT_REQUESTED); @@ -118,7 +129,7 @@ PrintersWindow::QuitRequested() void PrintersWindow::MessageReceived(BMessage* msg) { - switch(msg->what) { + switch (msg->what) { case kMsgPrinterSelected: { fSelectedPrinter = fPrinterListView->SelectedItem(); diff --git a/src/preferences/printers/PrintersWindow.h b/src/preferences/printers/PrintersWindow.h index 9835f88467..c61a50e160 100644 --- a/src/preferences/printers/PrintersWindow.h +++ b/src/preferences/printers/PrintersWindow.h @@ -19,26 +19,29 @@ class JobListView; class Job; class SpoolFolder; class PrinterItem; +class ScreenSettings; class PrintersWindow : public BWindow { public: - PrintersWindow(BRect frame); + PrintersWindow(ScreenSettings *settings); + virtual ~PrintersWindow(); - void MessageReceived(BMessage* msg); - bool QuitRequested(); + void MessageReceived(BMessage* msg); + bool QuitRequested(); - void PrintTestPage(PrinterItem* printer); + void PrintTestPage(PrinterItem* printer); - void AddJob(SpoolFolder* folder, Job* job); - void RemoveJob(SpoolFolder* folder, Job* job); - void UpdateJob(SpoolFolder* folder, Job* job); + void AddJob(SpoolFolder* folder, Job* job); + void RemoveJob(SpoolFolder* folder, Job* job); + void UpdateJob(SpoolFolder* folder, Job* job); private: - void _BuildGUI(); - bool _IsSelected(PrinterItem* printer); - void _UpdatePrinterButtons(); - void _UpdateJobButtons(); + ScreenSettings* fSettings; + void _BuildGUI(); + bool _IsSelected(PrinterItem* printer); + void _UpdatePrinterButtons(); + void _UpdateJobButtons(); typedef BWindow Inherited; @@ -53,9 +56,9 @@ private: BBox* fJobsBox; - PrinterItem* fSelectedPrinter; + PrinterItem* fSelectedPrinter; - bool fAddingPrinter; + bool fAddingPrinter; }; #endif // _PRINTERS_WINDOW_H diff --git a/src/preferences/printers/ScreenSettings.cpp b/src/preferences/printers/ScreenSettings.cpp new file mode 100644 index 0000000000..9f776c06eb --- /dev/null +++ b/src/preferences/printers/ScreenSettings.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2001-2015, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Rafael Romo + * Stefano Ceccherini (burton666@libero.it) + * Axel Dörfler, axeld@pinc-software.de + */ + + +#include "ScreenSettings.h" + +#include +#include +#include + + +static const char* kSettingsFileName = "Screen_data"; + + +ScreenSettings::ScreenSettings() +{ + fWindowFrame.Set(0, 0, 450, 250); + BPoint offset; + + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { + path.Append(kSettingsFileName); + + BFile file(path.Path(), B_READ_ONLY); + if (file.InitCheck() == B_OK) + file.Read(&offset, sizeof(BPoint)); + } + + fWindowFrame.OffsetBy(offset); +} + + +ScreenSettings::~ScreenSettings() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) + return; + + path.Append(kSettingsFileName); + + BPoint offset = fWindowFrame.LeftTop(); + + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); + if (file.InitCheck() == B_OK) + file.Write(&offset, sizeof(BPoint)); +} + + +void +ScreenSettings::SetWindowFrame(BRect frame) +{ + fWindowFrame = frame; +} diff --git a/src/preferences/printers/ScreenSettings.h b/src/preferences/printers/ScreenSettings.h new file mode 100644 index 0000000000..a4236f4cfa --- /dev/null +++ b/src/preferences/printers/ScreenSettings.h @@ -0,0 +1,29 @@ +/* + * Copyright 2001-2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Rafael Romo + * Stefano Ceccherini (burton666@libero.it) + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef SCREEN_SETTINGS_H +#define SCREEN_SETTINGS_H + + +#include + + +class ScreenSettings { + public: + ScreenSettings(); + virtual ~ScreenSettings(); + + BRect WindowFrame() const { return fWindowFrame; }; + void SetWindowFrame(BRect); + + private: + BRect fWindowFrame; +}; + +#endif // SCREEN_SETTINGS_H