From 4a989d1dbf244358b4f2a2da548cda9c633215e5 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Mon, 22 Jun 2015 15:43:38 +0300 Subject: [PATCH] Some structure changes. Added saving of window size --- wxCrossGen/FormBuilderGUI.fbp | 2 +- wxCrossGen/fbgui/fbgui.cpp | 4 ++-- wxCrossGen/fbgui/fbgui.h | 2 +- wxCrossGen/fmain.cpp | 30 ++++++++++++++++++++++++++++++ wxCrossGen/fmain.hpp | 16 ++++------------ wxCrossGen/settingsconsts.hpp | 4 ++++ 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/wxCrossGen/FormBuilderGUI.fbp b/wxCrossGen/FormBuilderGUI.fbp index 1c5d353..9890cf3 100644 --- a/wxCrossGen/FormBuilderGUI.fbp +++ b/wxCrossGen/FormBuilderGUI.fbp @@ -49,7 +49,7 @@ - onExitClick + onWindowClose diff --git a/wxCrossGen/fbgui/fbgui.cpp b/wxCrossGen/fbgui/fbgui.cpp index f2ad504..b8844a4 100644 --- a/wxCrossGen/fbgui/fbgui.cpp +++ b/wxCrossGen/fbgui/fbgui.cpp @@ -88,7 +88,7 @@ VMainFrame::VMainFrame( wxWindow* parent, wxWindowID id, const wxString& title, this->Layout(); // Connect Events - this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onExitClick ) ); + this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onWindowClose ) ); this->Connect( miOpenGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onOpenGridClick ) ); this->Connect( miGenerate->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onGenerateClick ) ); this->Connect( miExport->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExportClick ) ); @@ -102,7 +102,7 @@ VMainFrame::VMainFrame( wxWindow* parent, wxWindowID id, const wxString& title, VMainFrame::~VMainFrame() { // Disconnect Events - this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onExitClick ) ); + this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onWindowClose ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onOpenGridClick ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onGenerateClick ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExportClick ) ); diff --git a/wxCrossGen/fbgui/fbgui.h b/wxCrossGen/fbgui/fbgui.h index f0ceef2..8cde148 100644 --- a/wxCrossGen/fbgui/fbgui.h +++ b/wxCrossGen/fbgui/fbgui.h @@ -51,7 +51,7 @@ class VMainFrame : public wxFrame wxButton* bGenerate; // Virtual event handlers, overide them in your derived class - virtual void onExitClick( wxCloseEvent& event ) { event.Skip(); } + virtual void onWindowClose( wxCloseEvent& event ) { event.Skip(); } virtual void onOpenGridClick( wxCommandEvent& event ) { event.Skip(); } virtual void onGenerateClick( wxCommandEvent& event ) { event.Skip(); } virtual void onExportClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/wxCrossGen/fmain.cpp b/wxCrossGen/fmain.cpp index 5de3a8a..4db9ba9 100644 --- a/wxCrossGen/fmain.cpp +++ b/wxCrossGen/fmain.cpp @@ -1,6 +1,20 @@ #include "fmain.hpp" +MainFrame::MainFrame( wxWindow* parent): VMainFrame(parent) { + // Hack for better background + #ifdef __WINDOWS__ + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); + #endif + _isDictLoaded = false; + srand(time(NULL)); + auto *config = wxConfigBase::Get(); + wxSize sz; + sz.SetHeight(config->Read(SETTINGS_KEY_FMAIN_HEIGHT, SETTINGS_DEFAULT_FMAIN_HEIGHT)); + sz.SetWidth(config->Read(SETTINGS_KEY_FMAIN_WIDTH, SETTINGS_DEFAULT_FMAIN_WIDTH)); + SetSize(sz); +} + void MainFrame::procDict(wxString path){ _dict.clear(); _allWords.clear(); @@ -183,3 +197,19 @@ void MainFrame::onSettingsClick( wxCommandEvent& event ){ } } } + +void MainFrame::onWindowClose( wxCloseEvent& event ){ + saveConfig(); + event.Skip(); +} + +void MainFrame::onExitClick( wxCommandEvent& event ){ + this->Close(); +} + +void MainFrame::saveConfig(){ + auto *config = wxConfigBase::Get(); + auto sz = GetSize(); + config->Write(SETTINGS_KEY_FMAIN_HEIGHT, sz.GetHeight()); + config->Write(SETTINGS_KEY_FMAIN_WIDTH, sz.GetWidth()); +} diff --git a/wxCrossGen/fmain.hpp b/wxCrossGen/fmain.hpp index 38a2a72..4ec704b 100644 --- a/wxCrossGen/fmain.hpp +++ b/wxCrossGen/fmain.hpp @@ -35,23 +35,15 @@ protected: public: void SetGridImage(GridType &grid, size_t w=400); void procDict(wxString path); + void saveConfig(); - MainFrame( wxWindow* parent): VMainFrame(parent) { - // Hack for better background - #ifdef __WINDOWS__ - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - #endif - _isDictLoaded = false; - srand(time(NULL)); - } - void onExitClick( wxCloseEvent& event ) { event.Skip(); } + MainFrame( wxWindow* parent); + void onWindowClose( wxCloseEvent& event ); void onOpenGridClick( wxCommandEvent& event ); void onGenerateClick( wxCommandEvent& event ); void onSettingsClick( wxCommandEvent& event ); void onExportClick( wxCommandEvent& event ); - void onExitClick( wxCommandEvent& event ) { - Close(); - } + void onExitClick( wxCommandEvent& event ); void onAboutClick( wxCommandEvent& event ) { wxAboutDialogInfo info; info.AddDeveloper(_("Aleksey Lobanov")); diff --git a/wxCrossGen/settingsconsts.hpp b/wxCrossGen/settingsconsts.hpp index 66673a9..68f4ab6 100644 --- a/wxCrossGen/settingsconsts.hpp +++ b/wxCrossGen/settingsconsts.hpp @@ -5,5 +5,9 @@ const wxString SETTINGS_KEY_DICT_PATH = wxT("/Dict/Path"); const wxString SETTINGS_DEFAULT_DICTPATH = wxT("big_cross_ru.txt"); +const wxString SETTINGS_KEY_FMAIN_HEIGHT = wxT("fMain/Height"); +const wxString SETTINGS_KEY_FMAIN_WIDTH = wxT("fMain/Width"); +const int SETTINGS_DEFAULT_FMAIN_HEIGHT = 350; +const int SETTINGS_DEFAULT_FMAIN_WIDTH = 600; #endif