Revision: 7446
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7446&view=rev
Author:   vadz
Date:     2008-05-01 18:14:10 -0700 (Thu, 01 May 2008)

Log Message:
-----------
refactor: move the multiple config sources hadling to 
wxProfileSettingsEditDialog and derive wxOptionsEditDialog from it

Modified Paths:
--------------
    trunk/M/include/gui/wxDialogLayout.h
    trunk/M/src/gui/wxDialogLayout.cpp
    trunk/M/src/gui/wxHeadersDialogs.cpp
    trunk/M/src/gui/wxMFolderDialogs.cpp
    trunk/M/src/gui/wxOptionsDlg.cpp

Modified: trunk/M/include/gui/wxDialogLayout.h
===================================================================
--- trunk/M/include/gui/wxDialogLayout.h        2008-05-02 01:13:17 UTC (rev 
7445)
+++ trunk/M/include/gui/wxDialogLayout.h        2008-05-02 01:14:10 UTC (rev 
7446)
@@ -202,6 +202,81 @@
 };
 
 // ----------------------------------------------------------------------------
+// A base class for all dialogs which are used to edit the profile settings.
+// ----------------------------------------------------------------------------
+
+class wxProfileSettingsEditDialog : public wxManuallyLaidOutDialog
+{
+public:
+   wxProfileSettingsEditDialog(wxWindow *parent,
+                               const wxString& title,
+                               const wxString& profileKey);
+
+   virtual bool HasChanges() const { return m_bDirty; }
+   virtual void SetDirty() { m_bDirty = TRUE; }
+
+   virtual void EndModal(int rc);
+
+protected:
+   // override this to return the profile which we're editing
+   //
+   // we will DecRef() it so return a new or IncRef()'d profile
+   virtual Profile *GetProfile() const = 0;
+
+   // these methods may (or must) be overridden to create the dialog contents:
+   // the dialog consists of the main window, optional controls above it,
+   // optional controls below it and the buttons below them
+
+   // create the controls above the main window, return the last control
+   // created (in the top-to-bottom order)
+   virtual wxControl *CreateControlsAbove(wxPanel * /* panel */) { return 
NULL; }
+
+   // create the main window itself
+   virtual wxWindow *CreateMainWindow(wxPanel *panel) = 0;
+
+   // create the controls below the main window, return the top-most
+   virtual wxControl *CreateControlsBelow(wxPanel *panel);
+
+   // must call this from the derived class ctor to create the main window and
+   // the standard Ok/Cancel/Apply buttons, calls CreateControlsAbove/Below()
+   // and CreateMainWindow() which may be overridden in the derived classes
+   void CreateAllControls();
+
+   // call this after creating a new profile (as is done by the folder creation
+   // dialog which only creates the profile when the folder itself is being
+   // created) to ensure that changes to it are written to the config source
+   // selected by the user
+   void ApplyConfigSourceSelectedByUser(Profile& profile);
+
+
+   // true if anything changed in the dialog
+   bool m_bDirty;
+
+   wxButton *m_btnHelp,
+            *m_btnOk,
+            *m_btnApply;
+
+private:
+   // event handlers
+   void OnConfigSourceChange(wxCommandEvent& event);
+
+
+   // choice containing all config sources, may be NULL
+   wxChoice *m_chcSources;
+
+   // original config source used by profile returned by GetProfile(): only
+   // valid if m_changedConfigSource == true
+   class ConfigSource *m_configOld;
+
+   // true if we had called SetConfigSourceForWriting() on our profile
+   bool m_changedConfigSource;
+
+
+   DECLARE_EVENT_TABLE()
+   DECLARE_NO_COPY_CLASS(wxProfileSettingsEditDialog)
+};
+
+// ----------------------------------------------------------------------------
 // a dialog which contains a notebook with the standard Ok/Cancel/Apply buttons
 // below it and, optionally, some extra controls above/below the notebook. For
 // example, options dialog and folder creation dialogs in M derive from this
@@ -212,7 +287,7 @@
 // via virtual GetProfile() function - and it is only used for this purpose.
 // ----------------------------------------------------------------------------
 
-class wxOptionsEditDialog : public wxManuallyLaidOutDialog
+class wxOptionsEditDialog : public wxProfileSettingsEditDialog
 {
 public:
    // ctor
@@ -220,19 +295,6 @@
                        const wxString& title,
                        const wxString& profileKey = wxEmptyString);
 
-   // populate the dialog
-      // create the controls above the main notebook, return the last control
-      // created (in the top-to-bottom order)
-   virtual wxControl *CreateControlsAbove(wxPanel * /* panel */) { return 
NULL; }
-      // create the notebook itself (assign the pointer to m_notebook)
-   virtual void CreateNotebook(wxPanel *panel) = 0;
-      // create the controls below the main notebook, return the top-most
-   virtual wxControl *CreateControlsBelow(wxPanel *panel);
-      // create the notebook and the standard Ok/Cancel/Apply buttons, calls
-      // CreateControlsAbove/Below() and CreateNotebook() which may be
-      // overriden in the derived classes
-   void CreateAllControls();
-
    // function called when the user chooses Apply or Ok button and something
    // has really changed in the dialog: return TRUE from it to allow change
    // (and close the dialog), FALSE to forbid it and keep the dialog opened.
@@ -263,13 +325,7 @@
    void OnOK(wxCommandEvent& event);
    void OnApply(wxCommandEvent& event);
    void OnCancel(wxCommandEvent& event);
-   void OnConfigSourceChange(wxCommandEvent& event);
 
-   virtual void EndModal(int rc);
-
-   // unimplemented default ctor for DECLARE_DYNAMIC_CLASS
-   wxOptionsEditDialog() { wxFAIL_MSG(_T("unaccessible")); }
-
    // disable or reenable Ok and Apply buttons
    virtual void EnableButtons(bool enable);
 
@@ -283,31 +339,30 @@
       m_btnApply->Enable(FALSE);
    }
 
-   // call this after creating a new profile (as is done by the folder creation
-   // dialog which only creates the profile when the folder itself is being
-   // created) to ensure that changes to it are written to the config source
-   // selected by the user
-   void ApplyConfigSourceSelectedByUser(Profile& profile);
-
    // the helper for the handlers of Apply/Ok buttons, returns TRUE if the
    // changes were accepted
    bool DoApply();
 
-   // get the profile for event sending: the caller will DecRef() it
-   virtual Profile *GetProfile() const = 0;
 
-
    // the notebook occupying the main part of the dialog
    wxPNotebook *m_notebook;
 
 private:
+   // implement base class pure virtual in terms of our existing function for
+   // compatibility (CreateNotebook() existed before CreateMainWindow())
+   virtual wxWindow *CreateMainWindow(wxPanel *panel)
+   {
+      CreateNotebook(panel);
+      return m_notebook;
+   }
+
+   // override this to create the notebook and assign the pointer to m_notebook
+   virtual void CreateNotebook(wxPanel *panel) = 0;
+
+
    // send a notification event about options change using m_lastBtn value
    void SendOptionsChangeEvent();
 
-   wxButton *m_btnHelp,
-            *m_btnOk,
-            *m_btnApply;
-
    // Ok/Cancel/Apply depending on the last button pressed
    MEventOptionsChangeData::ChangeKind m_lastBtn;
 
@@ -317,67 +372,34 @@
    // with the same path
    Profile *m_profileForButtons;
 
-   // choice containing all config sources, may be NULL
-   wxChoice *m_chcSources;
-
-   // original config source used by profile returned by GetProfile(): only
-   // valid if m_changedConfigSource == true
-   class ConfigSource *m_configOld;
-
-   // true if we had called SetConfigSourceForWriting() on our profile
-   bool m_changedConfigSource;
-
    // flags
-   bool m_bDirty,           // something changed
-        m_bTest,            // test new settings?
+   bool m_bTest,            // test new settings?
         m_bRestartWarning;  // changes will take effect after restart
 
 
-   DECLARE_DYNAMIC_CLASS_NO_COPY(wxOptionsEditDialog)
+   DECLARE_ABSTRACT_CLASS(wxOptionsEditDialog)
+   DECLARE_NO_COPY_CLASS(wxOptionsEditDialog)
    DECLARE_EVENT_TABLE()
 };
 
 // ----------------------------------------------------------------------------
-// a base class for all dialogs which are used to edit the profile settings: it
-// adds the member profile variable and the "hasChanges" flag. As it derives
-// from wxPDialog, it saves and restores its position.
-// ----------------------------------------------------------------------------
-
-class wxProfileSettingsEditDialog : public wxManuallyLaidOutDialog
-{
-public:
-   wxProfileSettingsEditDialog(Profile *profile,
-                                       const wxString& profileKey,
-                                       wxWindow *parent,
-                                       const wxString& title);
-
-   virtual ~wxProfileSettingsEditDialog();
-   virtual Profile *GetProfile() const { return m_profile; }
-
-   virtual bool HasChanges() const { return m_hasChanges; }
-   virtual void MarkDirty() { m_hasChanges = TRUE; }
-
-protected:
-   Profile *m_profile;
-   bool         m_hasChanges;
-
-   DECLARE_NO_COPY_CLASS(wxProfileSettingsEditDialog)
-};
-
-// ----------------------------------------------------------------------------
 // this class eats all command events which shouldn't propagate upwards to the
 // parent: this is useful when we're shown from the options dialog because the
 // option pages there suppose that all command events can only originate from
 // their controls.
+//
+// it also conveniently stores the profile passed to its ctor (it doesn't take
+// its ownership)
 // ----------------------------------------------------------------------------
 
-class wxOptionsPageSubdialog : public wxProfileSettingsEditDialog
+class wxOptionsPageSubdialog : public wxManuallyLaidOutDialog,
+                               public ProfileHolder
 {
 public:
    wxOptionsPageSubdialog(Profile *profile,
-                                  wxWindow *parent,
-                                  const wxString& label,
-                                  const wxString& windowName);
+                          wxWindow *parent,
+                          const wxString& label,
+                          const wxString& windowName);
 
    virtual void OnChange(wxCommandEvent& event);
 

Modified: trunk/M/src/gui/wxDialogLayout.cpp
===================================================================
--- trunk/M/src/gui/wxDialogLayout.cpp  2008-05-02 01:13:17 UTC (rev 7445)
+++ trunk/M/src/gui/wxDialogLayout.cpp  2008-05-02 01:14:10 UTC (rev 7446)
@@ -110,18 +110,21 @@
 // event tables
 // 
-----------------------------------------------------------------------------
 
-BEGIN_EVENT_TABLE(wxOptionsPageSubdialog, wxProfileSettingsEditDialog)
+BEGIN_EVENT_TABLE(wxProfileSettingsEditDialog, wxManuallyLaidOutDialog)
+   EVT_CHOICE(-1, wxProfileSettingsEditDialog::OnConfigSourceChange)
+END_EVENT_TABLE()
+
+BEGIN_EVENT_TABLE(wxOptionsPageSubdialog, wxManuallyLaidOutDialog)
    EVT_CHECKBOX(-1, wxOptionsPageSubdialog::OnChange)
    EVT_RADIOBOX(-1, wxOptionsPageSubdialog::OnChange)
    EVT_TEXT(-1,     wxOptionsPageSubdialog::OnChange)
 END_EVENT_TABLE()
 
-BEGIN_EVENT_TABLE(wxOptionsEditDialog, wxDialog)
+BEGIN_EVENT_TABLE(wxOptionsEditDialog, wxProfileSettingsEditDialog)
    EVT_BUTTON(M_WXID_HELP, wxOptionsEditDialog::OnHelp)
    EVT_BUTTON(wxID_OK,     wxOptionsEditDialog::OnOK)
    EVT_BUTTON(wxID_APPLY,  wxOptionsEditDialog::OnApply)
    EVT_BUTTON(wxID_CANCEL, wxOptionsEditDialog::OnCancel)
-   EVT_CHOICE(-1,          wxOptionsEditDialog::OnConfigSourceChange)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxEnhancedPanel, wxPanel)
@@ -553,13 +556,13 @@
                                                wxWindow *parent,
                                                const wxString& label,
                                                const wxString& windowName)
-                      : wxProfileSettingsEditDialog
+                      : wxManuallyLaidOutDialog
                         (
-                           profile,
-                           windowName,
                            GET_PARENT_OF_CLASS(parent, wxFrame),
-                           label
-                        )
+                           label,
+                           windowName
+                        ),
+                        ProfileHolder(profile)
 {
 }
 
@@ -1264,43 +1267,81 @@
 // wxProfileSettingsEditDialog
 // ----------------------------------------------------------------------------
 
-wxProfileSettingsEditDialog::wxProfileSettingsEditDialog(Profile *profile,
-                                    const wxString& profileKey,
-                                    wxWindow *parent,
-                                    const wxString& title)
-   : wxManuallyLaidOutDialog(parent, title, profileKey)
+wxProfileSettingsEditDialog::wxProfileSettingsEditDialog(wxWindow *parent,
+                                                         const wxString& title,
+                                                         const wxString& key)
+   : wxManuallyLaidOutDialog(parent, title, key)
 {
-   m_profile = profile;
-   m_profile->IncRef(); // paranoid
-   m_hasChanges = FALSE;
+   m_bDirty = false;
+   m_changedConfigSource = false;
 }
 
-wxProfileSettingsEditDialog::~wxProfileSettingsEditDialog()
+void wxProfileSettingsEditDialog::OnConfigSourceChange(wxCommandEvent& event)
 {
-   m_profile->DecRef();
+   if ( event.GetEventObject() != m_chcSources )
+   {
+      event.Skip();
+      return;
+   }
+
+   Profile_obj profile(GetProfile());
+   if ( profile )
+   {
+      ApplyConfigSourceSelectedByUser(*profile);
+   }
+   //else: this can happen when we're creating a new folder, its profile isn't
+   //      created before the folder itself is
 }
 
-// 
-----------------------------------------------------------------------------
-// wxOptionsEditDialog
-// 
-----------------------------------------------------------------------------
-
-wxOptionsEditDialog::wxOptionsEditDialog(wxFrame *parent,
-                                   const wxString& title,
-                                   const wxString& profileKey)
-                   : wxManuallyLaidOutDialog(parent, title, profileKey)
+void
+wxProfileSettingsEditDialog::ApplyConfigSourceSelectedByUser(Profile& profile)
 {
-   m_btnOk =
-   m_btnApply = NULL;
+   const int sel = m_chcSources->GetSelection();
+   ConfigSource *config = NULL;
+   if ( sel != -1 )
+   {
+      AllConfigSources::List::iterator
+         i = AllConfigSources::Get().GetSources().begin();
+      for ( int n = 0; n < sel; n++ )
+         ++i;
 
-   m_profileForButtons = NULL;
+      config = i.operator->();
+   }
 
-   m_lastBtn = MEventOptionsChangeData::Invalid;
+   ConfigSource *configOld = profile.SetConfigSourceForWriting(config);
 
-   m_changedConfigSource = false;
+   // remember the original config source if this is the first time we change
+   // it
+   if ( !m_changedConfigSource )
+   {
+      m_configOld = configOld;
+      m_changedConfigSource = true;
+   }
 }
 
-wxControl *wxOptionsEditDialog::CreateControlsBelow(wxPanel *panel)
+void wxProfileSettingsEditDialog::EndModal(int rc)
 {
+   if ( m_changedConfigSource )
+   {
+      Profile_obj profile(GetProfile());
+      if ( profile )
+      {
+         profile->SetConfigSourceForWriting(m_configOld);
+      }
+      else
+      {
+         FAIL_MSG( "no profile in wxOptionsEditDialog?" );
+      }
+
+      m_changedConfigSource = false;
+   }
+
+   wxManuallyLaidOutDialog::EndModal(rc);
+}
+
+
+wxControl *wxProfileSettingsEditDialog::CreateControlsBelow(wxPanel *panel)
+{
    const AllConfigSources::List& sources = 
AllConfigSources::Get().GetSources();
    if ( sources.size() == 1 )
    {
@@ -1345,7 +1386,7 @@
    return line;
 }
 
-void wxOptionsEditDialog::CreateAllControls()
+void wxProfileSettingsEditDialog::CreateAllControls()
 {
    wxLayoutConstraints *c;
 
@@ -1375,7 +1416,7 @@
              *bottom = CreateControlsBelow(panel);
 
    // the notebook itself is created by this function
-   CreateNotebook(panel);
+   wxWindow * const winMain = CreateMainWindow(panel);
 
    c = new wxLayoutConstraints;
    c->left.SameAs(panel, wxLeft, LAYOUT_X_MARGIN);
@@ -1388,7 +1429,7 @@
       c->bottom.SameAs(bottom, wxTop, 2*LAYOUT_Y_MARGIN);
    else
       c->bottom.SameAs(panel, wxBottom, 4*LAYOUT_Y_MARGIN + hBtn);
-   m_notebook->SetConstraints(c);
+   winMain->SetConstraints(c);
 
    // create the buttons
    // ------------------
@@ -1433,6 +1474,23 @@
    SetDefaultSize(6*wBtn, 27*hBtn, TRUE /* set as min size too */);
 }
 
+// 
-----------------------------------------------------------------------------
+// wxOptionsEditDialog
+// 
-----------------------------------------------------------------------------
+
+wxOptionsEditDialog::wxOptionsEditDialog(wxFrame *parent,
+                                   const wxString& title,
+                                   const wxString& profileKey)
+                   : wxProfileSettingsEditDialog(parent, title, profileKey)
+{
+   m_btnOk =
+   m_btnApply = NULL;
+
+   m_profileForButtons = NULL;
+
+   m_lastBtn = MEventOptionsChangeData::Invalid;
+}
+
 // transfer the data to/from notebook pages
 // ----------------------------------------
 
@@ -1511,68 +1569,6 @@
    }
 }
 
-void wxOptionsEditDialog::OnConfigSourceChange(wxCommandEvent& event)
-{
-   if ( event.GetEventObject() != m_chcSources )
-   {
-      event.Skip();
-      return;
-   }
-
-   Profile_obj profile(GetProfile());
-   if ( profile )
-   {
-      ApplyConfigSourceSelectedByUser(*profile);
-   }
-   //else: this can happen when we're creating a new folder, its profile isn't
-   //      created before the folder itself is
-}
-
-void wxOptionsEditDialog::ApplyConfigSourceSelectedByUser(Profile& profile)
-{
-   const int sel = m_chcSources->GetSelection();
-   ConfigSource *config = NULL;
-   if ( sel != -1 )
-   {
-      AllConfigSources::List::iterator
-         i = AllConfigSources::Get().GetSources().begin();
-      for ( int n = 0; n < sel; n++ )
-         ++i;
-
-      config = i.operator->();
-   }
-
-   ConfigSource *configOld = profile.SetConfigSourceForWriting(config);
-
-   // remember the original config source if this is the first time we change
-   // it
-   if ( !m_changedConfigSource )
-   {
-      m_configOld = configOld;
-      m_changedConfigSource = true;
-   }
-}
-
-void wxOptionsEditDialog::EndModal(int rc)
-{
-   if ( m_changedConfigSource )
-   {
-      Profile_obj profile(GetProfile());
-      if ( profile )
-      {
-         profile->SetConfigSourceForWriting(m_configOld);
-      }
-      else
-      {
-         FAIL_MSG( _T("no profile in wxOptionsEditDialog?") );
-      }
-
-      m_changedConfigSource = false;
-   }
-
-   wxManuallyLaidOutDialog::EndModal(rc);
-}
-
 void wxOptionsEditDialog::EnableButtons(bool enable)
 {
    if ( m_btnApply )

Modified: trunk/M/src/gui/wxHeadersDialogs.cpp
===================================================================
--- trunk/M/src/gui/wxHeadersDialogs.cpp        2008-05-02 01:13:17 UTC (rev 
7445)
+++ trunk/M/src/gui/wxHeadersDialogs.cpp        2008-05-02 01:14:10 UTC (rev 
7446)
@@ -169,6 +169,9 @@
    virtual bool TransferDataToWindow();
    virtual bool TransferDataFromWindow();
 
+   // did we do anything?
+   bool HasChanges() const { return m_hasChanges; }
+
 protected:
    // event handlers
 
@@ -195,6 +198,8 @@
 
    static void InitStaticArrays();
 
+   bool m_hasChanges;
+
    DECLARE_EVENT_TABLE()
    DECLARE_NO_COPY_CLASS(wxComposeHeadersDialog)
 };
@@ -398,6 +403,8 @@
                                                  "message composition"),
                                                _T("ComposeHeaders"))
 {
+   m_hasChanges = false;
+
    InitStaticArrays();
 
    // layout the controls

Modified: trunk/M/src/gui/wxMFolderDialogs.cpp
===================================================================
--- trunk/M/src/gui/wxMFolderDialogs.cpp        2008-05-02 01:13:17 UTC (rev 
7445)
+++ trunk/M/src/gui/wxMFolderDialogs.cpp        2008-05-02 01:14:10 UTC (rev 
7446)
@@ -127,6 +127,13 @@
       SafeDecRef(m_profile);
    }
 
+   // call this to show the specified page initially
+   void ShowPage(FolderCreatePage page)
+   {
+      CreateAllControls();
+      SetNotebookPage(page);
+   }
+
    // initialization (should be called before the dialog is shown)
       // set folder we're working with
    void SetFolder(MFolder *folder)
@@ -191,9 +198,6 @@
       return m_profile;
    }
 
-   // unimplemented default ctor for DECLARE_DYNAMIC_CLASS
-   wxFolderBaseDialog() { }
-
 protected:
    // return TRUE if the Ok/Apply buttons should be enabled (depending on the
    // state of the other controls)
@@ -219,7 +223,8 @@
    bool m_mayEnableOk;
 
 private:
-   DECLARE_DYNAMIC_CLASS_NO_COPY(wxFolderBaseDialog)
+   DECLARE_ABSTRACT_CLASS(wxFolderBaseDialog)
+   DECLARE_NO_COPY_CLASS(wxFolderBaseDialog)
 };
 
 // folder properties dialog
@@ -232,11 +237,9 @@
    virtual bool TransferDataToWindow();
    virtual bool TransferDataFromWindow();
 
-   // unimplemented default ctor for DECLARE_DYNAMIC_CLASS
-   wxFolderPropertiesDialog() { wxFAIL_MSG(_T("not reached")); }
-
 private:
-   DECLARE_DYNAMIC_CLASS_NO_COPY(wxFolderPropertiesDialog)
+   DECLARE_ABSTRACT_CLASS(wxFolderPropertiesDialog)
+   DECLARE_NO_COPY_CLASS(wxFolderPropertiesDialog)
 };
 
 // folder creation dialog
@@ -259,15 +262,13 @@
    void OnFolderNameChange(wxCommandEvent& event);
    void OnUpdateButton(wxUpdateUIEvent& event);
 
-   // unimplemented default ctor for DECLARE_DYNAMIC_CLASS
-   wxFolderCreateDialog() { wxFAIL_MSG(_T("not reached")); }
-
 private:
    // set to TRUE if the user changed the folder name, FALSE otherwise and -1
    // if we're changing it programmatically
    int m_nameModifiedByUser;
 
-   DECLARE_DYNAMIC_CLASS_NO_COPY(wxFolderCreateDialog)
+   DECLARE_ABSTRACT_CLASS(wxFolderCreateDialog)
+   DECLARE_NO_COPY_CLASS(wxFolderCreateDialog)
    DECLARE_EVENT_TABLE()
 };
 
@@ -571,9 +572,9 @@
 // event tables
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxFolderBaseDialog, wxOptionsEditDialog)
-IMPLEMENT_DYNAMIC_CLASS(wxFolderCreateDialog, wxFolderBaseDialog)
-IMPLEMENT_DYNAMIC_CLASS(wxFolderPropertiesDialog, wxFolderBaseDialog)
+IMPLEMENT_ABSTRACT_CLASS(wxFolderBaseDialog, wxOptionsEditDialog)
+IMPLEMENT_ABSTRACT_CLASS(wxFolderCreateDialog, wxFolderBaseDialog)
+IMPLEMENT_ABSTRACT_CLASS(wxFolderPropertiesDialog, wxFolderBaseDialog)
 
 BEGIN_EVENT_TABLE(wxFolderCreateDialog, wxOptionsEditDialog)
    EVT_TEXT(wxFolderCreateDialog::Folder_Name,
@@ -2704,8 +2705,7 @@
 static MFolder *DoShowFolderDialog(wxFolderBaseDialog& dlg,
                                    FolderCreatePage page)
 {
-   dlg.CreateAllControls();
-   dlg.SetNotebookPage(page);
+   dlg.ShowPage(page);
 
    if ( dlg.ShowModal() == wxID_OK )
    {

Modified: trunk/M/src/gui/wxOptionsDlg.cpp
===================================================================
--- trunk/M/src/gui/wxOptionsDlg.cpp    2008-05-02 01:13:17 UTC (rev 7445)
+++ trunk/M/src/gui/wxOptionsDlg.cpp    2008-05-02 01:14:10 UTC (rev 7446)
@@ -674,17 +674,18 @@
 class wxGlobalOptionsDialog : public wxOptionsEditDialog
 {
 public:
-   wxGlobalOptionsDialog(wxFrame *parent, const wxString& configKey = 
_T("OptionsDlg"));
+   wxGlobalOptionsDialog(wxFrame *parent,
+                         const wxString& configKey = "OptionsDlg");
 
+   // call this after creation to show a specific page
+   void ShowPage(OptionsPage page);
+
    virtual ~wxGlobalOptionsDialog();
 
    // override base class functions
    virtual void CreateNotebook(wxPanel *panel);
    virtual bool TransferDataToWindow();
 
-   // unimplemented default ctor for DECLARE_DYNAMIC_CLASS
-   wxGlobalOptionsDialog() { wxFAIL_MSG(_T("should be never used")); }
-
    // return TRUE if this dialog edits global options for the program, FALSE
    // if this is another kind of dialog
    virtual bool IsGlobalOptionsDialog() const { return TRUE; }
@@ -697,7 +698,8 @@
    }
 
 private:
-   DECLARE_DYNAMIC_CLASS_NO_COPY(wxGlobalOptionsDialog)
+   DECLARE_ABSTRACT_CLASS(wxGlobalOptionsDialog)
+   DECLARE_NO_COPY_CLASS(wxGlobalOptionsDialog)
 };
 
 // just like wxGlobalOptionsDialog but uses the given wxOptionsPage and not the
@@ -730,6 +732,9 @@
       SafeIncRef(m_profile);
 
       SetPagesDesc(nPages, pageDesc);
+
+      CreateAllControls();
+      Layout();
    }
 
    // delayed initializetion: use these methods for an object constructed with
@@ -802,6 +807,9 @@
       SetPagesDesc(m_nPages, m_aPages);
 
       SetTitle(wxString::Format(_("Settings for identity '%s'"), 
m_identity.c_str()));
+
+      CreateAllControls();
+      Layout();
    }
 
    virtual ~wxIdentityOptionsDialog()
@@ -844,17 +852,23 @@
 
 // another dialog (not for options this one) which allows to restore the
 // previously changed settings
-class wxRestoreDefaultsDialog : public wxProfileSettingsEditDialog
+class wxRestoreDefaultsDialog : public wxManuallyLaidOutDialog,
+                                private ProfileHolder
 {
 public:
    wxRestoreDefaultsDialog(Profile *profile, wxFrame *parent);
 
+   // return true if we did anything
+   bool HasChanges() const { return m_hasChanges; }
+
    // reset the selected options to their default values
    virtual bool TransferDataFromWindow();
 
 private:
    wxCheckListBox *m_checklistBox;
 
+   bool m_hasChanges;
+
    DECLARE_NO_COPY_CLASS(wxRestoreDefaultsDialog)
 };
 
@@ -902,7 +916,7 @@
 // event tables and such
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxGlobalOptionsDialog, wxOptionsEditDialog)
+IMPLEMENT_ABSTRACT_CLASS(wxGlobalOptionsDialog, wxOptionsEditDialog)
 
 BEGIN_EVENT_TABLE(wxOptionsPage, wxNotebookPageBase)
    // any change should make us dirty
@@ -4643,11 +4657,29 @@
 // wxGlobalOptionsDialog
 // ----------------------------------------------------------------------------
 
-wxGlobalOptionsDialog::wxGlobalOptionsDialog(wxFrame *parent, const wxString& 
configKey)
-               : wxOptionsEditDialog(parent, _("Program options"), configKey)
+wxGlobalOptionsDialog::wxGlobalOptionsDialog(wxFrame *parent,
+                                             const wxString& configKey)
+                     : wxOptionsEditDialog(parent,
+                                           _("Program options"),
+                                           configKey)
 {
 }
 
+void wxGlobalOptionsDialog::ShowPage(OptionsPage page)
+{
+#ifdef PROFILE_OPTIONS_DLG
+   wxStopWatch sw;
+#endif
+
+   CreateAllControls();
+   SetNotebookPage(page);
+   Layout();
+
+#ifdef PROFILE_OPTIONS_DLG
+   wxLogStatus(_T("Options dialog created in %ldms"), sw.Time());
+#endif
+}
+
 bool
 wxGlobalOptionsDialog::TransferDataToWindow()
 {
@@ -4850,14 +4882,16 @@
 
 wxRestoreDefaultsDialog::wxRestoreDefaultsDialog(Profile *profile,
                                                  wxFrame *parent)
-                       : wxProfileSettingsEditDialog
+                       : wxManuallyLaidOutDialog
                          (
-                           profile,
-                           _T("RestoreOptionsDlg"),
                            parent,
-                           _("Restore default options")
-                         )
+                           _("Restore default options"),
+                           "RestoreOptionsDlg"
+                         ),
+                         ProfileHolder(profile)
 {
+   m_hasChanges = false;
+
    wxLayoutConstraints *c;
 
    // create the Ok and Cancel buttons in the bottom right corner
@@ -4927,7 +4961,7 @@
    {
       if ( m_checklistBox->IsChecked(n) )
       {
-         MarkDirty();
+         m_hasChanges = true;
 
          GetProfile()->GetConfig()->DeleteEntry(
                wxOptionsPageStandard::ms_aConfigDefaults[n].name);
@@ -5215,19 +5249,9 @@
 
 void ShowOptionsDialog(wxFrame *parent, OptionsPage page)
 {
-#ifdef PROFILE_OPTIONS_DLG
-   wxStopWatch sw;
-#endif
-
    wxGlobalOptionsDialog dlg(parent);
-   dlg.CreateAllControls();
-   dlg.SetNotebookPage(page);
-   dlg.Layout();
+   dlg.ShowPage(page);
 
-#ifdef PROFILE_OPTIONS_DLG
-   wxLogStatus(_T("Options dialog created in %ldms"), sw.Time());
-#endif
-
    (void)dlg.ShowModal();
 }
 
@@ -5251,8 +5275,6 @@
                              wxFrame *parent)
 {
    wxCustomOptionsDialog dlg(nPages, pageDesc, profile, parent);
-   dlg.CreateAllControls();
-   dlg.Layout();
 
    return dlg.ShowModal() == wxID_OK;
 }
@@ -5260,8 +5282,6 @@
 void ShowIdentityDialog(const wxString& identity, wxFrame *parent)
 {
    wxIdentityOptionsDialog dlg(identity, parent);
-   dlg.CreateAllControls();
-   dlg.Layout();
 
    (void)dlg.ShowModal();
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to