X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c67daf87774c71ae9f73af9969008af220e52a11..bbc3925a8a46e8c80b22277f5571dfb2465aca25:/samples/config/conftest.cpp diff --git a/samples/config/conftest.cpp b/samples/config/conftest.cpp index 9c97ccce3f..a3aff05a03 100644 --- a/samples/config/conftest.cpp +++ b/samples/config/conftest.cpp @@ -2,7 +2,7 @@ // Name: conftest.cpp // Purpose: demo of wxConfig and related classes // Author: Vadim Zeitlin -// Modified by: +// Modified by: // Created: 03.08.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin @@ -28,6 +28,7 @@ // ---------------------------------------------------------------------------- // classes // ---------------------------------------------------------------------------- + class MyApp: public wxApp { public: @@ -41,12 +42,11 @@ class MyFrame: public wxFrame public: MyFrame(); virtual ~MyFrame(); - + // callbacks void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnDelete(wxCommandEvent& event); - bool OnClose() { return TRUE; } private: wxTextCtrl *m_text; @@ -57,18 +57,19 @@ private: enum { - Minimal_Quit, - Minimal_About, - Minimal_Delete + ConfTest_Quit, + ConfTest_About, + ConfTest_Delete }; // ---------------------------------------------------------------------------- // event tables // ---------------------------------------------------------------------------- + BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(Minimal_Quit, MyFrame::OnQuit) - EVT_MENU(Minimal_About, MyFrame::OnAbout) - EVT_MENU(Minimal_Delete, MyFrame::OnDelete) + EVT_MENU(ConfTest_Quit, MyFrame::OnQuit) + EVT_MENU(ConfTest_About, MyFrame::OnAbout) + EVT_MENU(ConfTest_Delete, MyFrame::OnDelete) END_EVENT_TABLE() // ============================================================================ @@ -78,6 +79,7 @@ END_EVENT_TABLE() // ---------------------------------------------------------------------------- // application // ---------------------------------------------------------------------------- + IMPLEMENT_APP(MyApp) // `Main program' equivalent, creating windows and returning main app frame @@ -98,6 +100,11 @@ bool MyApp::OnInit() wxConfigBase *pConfig = wxConfigBase::Get(); + // uncomment this to force writing back of the defaults for all values + // if they're not present in the config - this can give the user an idea + // of all possible settings for this program + pConfig->SetRecordDefaults(); + // or you could also write something like this: // wxFileConfig *pConfig = new wxFileConfig("conftest"); // wxConfigBase::Set(pConfig); @@ -143,11 +150,11 @@ MyFrame::MyFrame() // menu wxMenu *file_menu = new wxMenu; - file_menu->Append(Minimal_Delete, "&Delete", "Delete config file"); + file_menu->Append(ConfTest_Delete, "&Delete", "Delete config file"); file_menu->AppendSeparator(); - file_menu->Append(Minimal_About, "&About", "About this sample"); + file_menu->Append(ConfTest_About, "&About\tF1", "About this sample"); file_menu->AppendSeparator(); - file_menu->Append(Minimal_Quit, "E&xit", "Exit the program"); + file_menu->Append(ConfTest_Quit, "E&xit\tAlt-X", "Exit the program"); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&File"); SetMenuBar(menu_bar); @@ -187,6 +194,17 @@ MyFrame::MyFrame() h = pConfig->Read("h", 200); Move(x, y); SetClientSize(w, h); + + pConfig->SetPath("/"); + wxString s; + if ( pConfig->Read("TestValue", &s) ) + { + wxLogStatus(this, wxT("TestValue from config is '%s'"), s.c_str()); + } + else + { + wxLogStatus(this, wxT("TestValue not found in the config")); + } } void MyFrame::OnQuit(wxCommandEvent&) @@ -196,20 +214,23 @@ void MyFrame::OnQuit(wxCommandEvent&) void MyFrame::OnAbout(wxCommandEvent&) { - wxMessageBox("wxConfig demo\n© Vadim Zeitlin 1998", "About", + wxMessageBox(_T("wxConfig demo\n© 1998-2001 Vadim Zeitlin"), _T("About"), wxICON_INFORMATION | wxOK); } void MyFrame::OnDelete(wxCommandEvent&) { - if ( wxConfigBase::Get()->DeleteAll() ) { - wxLogMessage("Config file/registry key successfully deleted."); - - delete wxConfigBase::Set((wxConfigBase *) NULL); - wxConfigBase::DontCreateOnDemand(); - } - else - wxLogError("Deleting config file/registry key failed."); + if ( wxConfigBase::Get()->DeleteAll() ) + { + wxLogMessage(_T("Config file/registry key successfully deleted.")); + + delete wxConfigBase::Set((wxConfigBase *) NULL); + wxConfigBase::DontCreateOnDemand(); + } + else + { + wxLogError(_T("Deleting config file/registry key failed.")); + } } MyFrame::~MyFrame() @@ -225,8 +246,10 @@ MyFrame::~MyFrame() int x, y, w, h; GetClientSize(&w, &h); GetPosition(&x, &y); - pConfig->Write("/MainFrame/x", x); - pConfig->Write("/MainFrame/y", y); - pConfig->Write("/MainFrame/w", w); - pConfig->Write("/MainFrame/h", h); + pConfig->Write("/MainFrame/x", (long) x); + pConfig->Write("/MainFrame/y", (long) y); + pConfig->Write("/MainFrame/w", (long) w); + pConfig->Write("/MainFrame/h", (long) h); + + pConfig->Write("/TestValue", ""); }