]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dlgcmn.cpp
added wxAuiNotebook::Split() documentation
[wxWidgets.git] / src / common / dlgcmn.cpp
index ed592fb8cf54015481490f5341ed5a86937f843e..74af36254e2e6ef3e87351d943a2c0a3ba4ec1fb 100644 (file)
@@ -99,9 +99,7 @@ private:
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
-    EVT_BUTTON(wxID_OK, wxDialogBase::OnOK)
-    EVT_BUTTON(wxID_APPLY, wxDialogBase::OnApply)
-    EVT_BUTTON(wxID_CANCEL, wxDialogBase::OnCancel)
+    EVT_BUTTON(wxID_ANY, wxDialogBase::OnButton)
 
     EVT_CLOSE(wxDialogBase::OnCloseWindow)
 
 
     EVT_CLOSE(wxDialogBase::OnCloseWindow)
 
@@ -281,80 +279,62 @@ Wrap(int width)
 
 #endif // wxUSE_STATTEXT
 
 
 #endif // wxUSE_STATTEXT
 
-wxSizer *wxDialogBase::CreateButtonSizer( long flags, bool separated, wxCoord distance )
+wxSizer *wxDialogBase::CreateButtonSizer(long flags)
 {
 {
-#ifdef __SMARTPHONE__
-    wxUnusedVar(separated);
-    wxUnusedVar(distance);
+    wxSizer *sizer = NULL;
 
 
+#ifdef __SMARTPHONE__
     wxDialog* dialog = (wxDialog*) this;
     wxDialog* dialog = (wxDialog*) this;
-    if (flags & wxOK){
+    if ( flags & wxOK )
         dialog->SetLeftMenu(wxID_OK);
         dialog->SetLeftMenu(wxID_OK);
-    }
 
 
-    if (flags & wxCANCEL){
+    if ( flags & wxCANCEL )
         dialog->SetRightMenu(wxID_CANCEL);
         dialog->SetRightMenu(wxID_CANCEL);
-    }
 
 
-    if (flags & wxYES){
+    if ( flags & wxYES )
         dialog->SetLeftMenu(wxID_YES);
         dialog->SetLeftMenu(wxID_YES);
-    }
-
-    if (flags & wxNO){
-        dialog->SetLeftMenu(wxID_NO);
-    }
-    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
-    return sizer;
 
 
+    if ( flags & wxNO )
+        dialog->SetRightMenu(wxID_NO);
 #else // !__SMARTPHONE__
 
 #else // !__SMARTPHONE__
 
+#if wxUSE_BUTTON
+
 #ifdef __POCKETPC__
 #ifdef __POCKETPC__
-    // PocketPC guidelines recommend for Ok/Cancel dialogs to use
-    // OK button located inside caption bar and implement Cancel functionality
-    // through Undo outside dialog. As native behaviour this will be default
-    // here but can be easily replaced with real wxButtons
-    // with "wince.dialog.real-ok-cancel" option set to 1
-    if ( ((flags & ~(wxCANCEL|wxNO_DEFAULT))== wxOK) &&
-         (wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"))==0)
-       )
+    // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
+    // located inside caption bar and implement Cancel functionality through
+    // Undo outside dialog. As native behaviour this will be default here but
+    // can be replaced with real wxButtons by setting the option below to 1
+    if ( (flags & ~(wxCANCEL|wxNO_DEFAULT)) != wxOK ||
+            wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
+#endif // __POCKETPC__
     {
     {
-        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
-        return sizer;
+        sizer = CreateStdDialogButtonSizer(flags);
     }
     }
-#endif // __POCKETPC__
-
-#if wxUSE_BUTTON
-
-    wxSizer* buttonSizer = CreateStdDialogButtonSizer( flags );
-
-    // Mac Human Interface Guidelines recommend not to use static lines as grouping elements
-#if wxUSE_STATLINE && !defined(__WXMAC__)
-    if(!separated)
-        return buttonSizer;
-
-    wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
-    topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxBOTTOM, distance );
-    topsizer->Add( buttonSizer, 0, wxEXPAND );
-    return topsizer;
+#endif // wxUSE_BUTTON
 
 
-#else // !wxUSE_STATLINE
+#endif // __SMARTPHONE__/!__SMARTPHONE__
 
 
-    wxUnusedVar(separated);
-    wxUnusedVar(distance);
-    return buttonSizer;
+    return sizer;
+}
 
 
-#endif // wxUSE_STATLINE/!wxUSE_STATLINE
+wxSizer *wxDialogBase::CreateSeparatedButtonSizer(long flags)
+{
+    wxSizer *sizer = CreateButtonSizer(flags);
+    if ( !sizer )
+        return NULL;
 
 
-#else // !wxUSE_BUTTON
+    // Mac Human Interface Guidelines recommend not to use static lines as
+    // grouping elements
+#if wxUSE_STATLINE && !defined(__WXMAC__)
+    wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
+    topsizer->Add(new wxStaticLine(this),
+                   wxSizerFlags().Expand().DoubleBorder(wxBOTTOM));
+    topsizer->Add(sizer, wxSizerFlags().Expand());
+    sizer = topsizer;
+#endif // wxUSE_STATLINE
 
 
-    wxUnusedVar(separated);
-    wxUnusedVar(distance);
-    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
     return sizer;
     return sizer;
-
-#endif // wxUSE_BUTTON/!wxUSE_BUTTON
-
-#endif // __SMARTPHONE__/!__SMARTPHONE__
 }
 
 #if wxUSE_BUTTON
 }
 
 #if wxUSE_BUTTON
@@ -367,27 +347,32 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
     wxButton *yes = NULL;
     wxButton *no = NULL;
 
     wxButton *yes = NULL;
     wxButton *no = NULL;
 
-    if (flags & wxOK){
+    if (flags & wxOK)
+    {
         ok = new wxButton(this, wxID_OK);
         sizer->AddButton(ok);
     }
 
         ok = new wxButton(this, wxID_OK);
         sizer->AddButton(ok);
     }
 
-    if (flags & wxCANCEL){
+    if (flags & wxCANCEL)
+    {
         wxButton *cancel = new wxButton(this, wxID_CANCEL);
         sizer->AddButton(cancel);
     }
 
         wxButton *cancel = new wxButton(this, wxID_CANCEL);
         sizer->AddButton(cancel);
     }
 
-    if (flags & wxYES){
+    if (flags & wxYES)
+    {
         yes = new wxButton(this, wxID_YES);
         sizer->AddButton(yes);
     }
 
         yes = new wxButton(this, wxID_YES);
         sizer->AddButton(yes);
     }
 
-    if (flags & wxNO){
+    if (flags & wxNO)
+    {
         no = new wxButton(this, wxID_NO);
         sizer->AddButton(no);
     }
 
         no = new wxButton(this, wxID_NO);
         sizer->AddButton(no);
     }
 
-    if (flags & wxHELP){
+    if (flags & wxHELP)
+    {
         wxButton *help = new wxButton(this, wxID_HELP);
         sizer->AddButton(help);
     }
         wxButton *help = new wxButton(this, wxID_HELP);
         sizer->AddButton(help);
     }
@@ -427,11 +412,38 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
 #endif // wxUSE_BUTTON
 
 // ----------------------------------------------------------------------------
 #endif // wxUSE_BUTTON
 
 // ----------------------------------------------------------------------------
-// event handling stuff
+// standard buttons handling
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
+void wxDialogBase::EndDialog(int rc)
+{
+    if ( IsModal() )
+        EndModal(rc);
+    else
+        Hide();
+}
+
+void wxDialogBase::AcceptAndClose()
+{
+    if ( Validate() && TransferDataFromWindow() )
+    {
+        EndDialog(m_affirmativeId);
+    }
+}
+
+void wxDialogBase::SetAffirmativeId(int affirmativeId)
+{
+    m_affirmativeId = affirmativeId;
+}
+
+void wxDialogBase::SetEscapeId(int escapeId)
+{
+    m_escapeId = escapeId;
+}
+
 bool wxDialogBase::EmulateButtonClickIfPresent(int id)
 {
 bool wxDialogBase::EmulateButtonClickIfPresent(int id)
 {
+#if wxUSE_BUTTON
     wxButton *btn = wxDynamicCast(FindWindow(id), wxButton);
 
     if ( !btn || !btn->IsEnabled() || !btn->IsShown() )
     wxButton *btn = wxDynamicCast(FindWindow(id), wxButton);
 
     if ( !btn || !btn->IsEnabled() || !btn->IsShown() )
@@ -442,14 +454,10 @@ bool wxDialogBase::EmulateButtonClickIfPresent(int id)
     btn->GetEventHandler()->ProcessEvent(event);
 
     return true;
     btn->GetEventHandler()->ProcessEvent(event);
 
     return true;
-}
-
-void wxDialogBase::EndDialog(int rc)
-{
-    if ( IsModal() )
-        EndModal(rc);
-    else
-        Hide();
+#else // !wxUSE_BUTTON
+    wxUnusedVar(id);
+    return false;
+#endif // wxUSE_BUTTON/!wxUSE_BUTTON
 }
 
 bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event)
 }
 
 bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event)
@@ -475,7 +483,7 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
                 // but if there is no such button, then fall back to wxID_OK
                 if ( EmulateButtonClickIfPresent(wxID_CANCEL) )
                     return;
                 // but if there is no such button, then fall back to wxID_OK
                 if ( EmulateButtonClickIfPresent(wxID_CANCEL) )
                     return;
-                idCancel = wxID_OK;
+                idCancel = GetAffirmativeId();
                 // fall through
 
             default:
                 // fall through
 
             default:
@@ -488,26 +496,34 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
     event.Skip();
 }
 
     event.Skip();
 }
 
-void wxDialogBase::OnOK(wxCommandEvent& WXUNUSED(event))
+void wxDialogBase::OnButton(wxCommandEvent& event)
 {
 {
-  if ( Validate() && TransferDataFromWindow() )
-  {
-      EndDialog(wxID_OK);
-  }
-}
-
-void wxDialogBase::OnApply(wxCommandEvent& WXUNUSED(event))
-{
-    if ( Validate() )
-        TransferDataFromWindow();
+    const int id = event.GetId();
+    if ( id == GetAffirmativeId() )
+    {
+        AcceptAndClose();
+    }
+    else if ( id == wxID_APPLY )
+    {
+        if ( Validate() )
+            TransferDataFromWindow();
 
 
-    // TODO probably need to disable the Apply button until things change again
+        // TODO: disable the Apply button until things change again
+    }
+    else if ( id == GetEscapeId() ||
+                (id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
+    {
+        EndDialog(wxID_CANCEL);
+    }
+    else // not a standard button
+    {
+        event.Skip();
+    }
 }
 
 }
 
-void wxDialogBase::OnCancel(wxCommandEvent& WXUNUSED(event))
-{
-    EndDialog(wxID_CANCEL);
-}
+// ----------------------------------------------------------------------------
+// other event handlers
+// ----------------------------------------------------------------------------
 
 void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {
 
 void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {