diff -rcN propsheet.cc propsheet.cc *** propsheet.cc Fri Apr 24 16:57:48 2009 --- propsheet.cc Mon May 18 19:35:42 2009 *************** *** 24,29 **** --- 24,36 ---- #include "RECTWrapper.h" #include "ControlAdjuster.h" #include "threebar.h" + #include "UserSettings.h" + #include "io_stream.h" + #include "getopt++/BoolOption.h" + + static GeometrySetting theSetting; + static BoolOption ResetGeomOption (false, 'g', "reset-geometry", + "Reset saved window geometry to default"); //#include // ...but since there is no shlwapi.h in mingw yet: *************** *** 57,64 **** --- 64,75 ---- DLGTEMPLATEEX, *LPDLGTEMPLATEEX; #include + bool PropSheet::geometryRestored; + WINDOWPLACEMENT *PropSheet::windowPlacement; + PropSheet::PropSheet () { + geometryRestored = false; } PropSheet::~PropSheet () *************** *** 229,238 **** --- 240,266 ---- psd.hasMinRect = true; } + // Only update geometry if initialization is done + if (PropSheet::geometryRestored && + PropSheet::windowPlacement != NULL) + { + GetWindowPlacement (hwnd, PropSheet::windowPlacement); + } + psd.lastClientRect = clientRect; } } break; + case WM_MOVE: + { + // Only update geometry if initialization is done + if (PropSheet::geometryRestored && + PropSheet::windowPlacement != NULL) + { + GetWindowPlacement (hwnd, PropSheet::windowPlacement); + } + } + break; case WM_GETMINMAXINFO: { if (psd.hasMinRect) *************** *** 422,427 **** --- 450,478 ---- int marginY = MulDiv (5, HIWORD(dialogBaseUnits), 8); pageRect.move (marginX, marginY); + + if (!geometryRestored) + { + HWND parent = ::GetParent(page); + if (windowPlacement != NULL) + { + SetWindowPlacement (parent, windowPlacement); + } + else + { + // Allocate and store the initial value for windowPlacement so + // that there is a valid value to store if the user exits without + // moving or resizing the window. + windowPlacement = new WINDOWPLACEMENT; + if (windowPlacement != NULL) + { + windowPlacement->length = sizeof (WINDOWPLACEMENT); + GetWindowPlacement (parent, windowPlacement); + } + } + + geometryRestored = true; + } } SetWindowPos (page, 0, psd.pageRect.left, psd.pageRect.top, *************** *** 464,466 **** --- 515,566 ---- { ::PropSheet_PressButton (GetHWND (), button); } + + void + GeometrySetting::load() + { + if (ResetGeomOption || PropSheet::windowPlacement != NULL) + return; + + io_stream *f = + UserSettings::Instance().settingFileForLoad (GEOMETRY_SETTING_FILE); + if (f) + { + PropSheet::windowPlacement = new WINDOWPLACEMENT; + if (PropSheet::windowPlacement == NULL) + return; + + long bytes = + f->read (PropSheet::windowPlacement, sizeof (WINDOWPLACEMENT)); + delete f; + + if (bytes != sizeof(WINDOWPLACEMENT) || + PropSheet::windowPlacement->length != sizeof (WINDOWPLACEMENT)) + { + log (LOG_PLAIN) + << "The data in \"" + << GEOMETRY_SETTING_FILE + << "\" looks invalid. Using default geometry instead." + << endLog; + delete PropSheet::windowPlacement; + PropSheet::windowPlacement = NULL; + } + } + } + + void + GeometrySetting::save() + { + if (PropSheet::windowPlacement != NULL) + { + io_stream *f = + UserSettings::Instance().settingFileForSave (GEOMETRY_SETTING_FILE); + if (f) + { + f->write (PropSheet::windowPlacement, sizeof (WINDOWPLACEMENT)); + delete f; + } + delete PropSheet::windowPlacement; + PropSheet::windowPlacement = NULL; + } + } diff -rcN propsheet.h propsheet.h *** propsheet.h Mon Oct 25 09:46:26 2004 --- propsheet.h Mon May 18 18:32:11 2009 *************** *** 29,34 **** --- 29,37 ---- #include "window.h" + #include "UserSetting.h" + #define GEOMETRY_SETTING_FILE "last-geometry" + class PropertyPage; class PropSheet : public Window *************** *** 40,45 **** --- 43,53 ---- HPROPSHEETPAGE *CreatePages (); public: + // Whether the window was set to the saved Geometry. + static bool geometryRestored; + + static WINDOWPLACEMENT *windowPlacement; + PropSheet (); virtual ~ PropSheet (); *************** *** 59,62 **** --- 67,80 ---- void PressButton (int button); }; + + // Class to persist and read in user settings to restore setup's window + // geometry on startup. + class GeometrySetting : public UserSetting + { + public: + virtual void load (); + virtual void save (); + }; + #endif /* SETUP_PROPSHEET_H */