]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dialogs/dialogs.cpp
exposing control key combinations as before, fixing unicodekey casing
[wxWidgets.git] / samples / dialogs / dialogs.cpp
index 53fd1a8c467de54afb47bd2ff2c72c93091a9ad2..eeeecdac1f1db15c3d60f4f5f4bdbe1e975919e8 100644 (file)
@@ -152,6 +152,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #endif // wxUSE_INFOBAR
 
 #if wxUSE_TEXTDLG
+    EVT_MENU(DIALOGS_LINE_ENTRY,                    MyFrame::LineEntry)
     EVT_MENU(DIALOGS_TEXT_ENTRY,                    MyFrame::TextEntry)
     EVT_MENU(DIALOGS_PASSWORD_ENTRY,                MyFrame::PasswordEntry)
 #endif // wxUSE_TEXTDLG
@@ -395,7 +396,8 @@ bool MyApp::OnInit()
     wxMenu *entry_menu = new wxMenu;
 
     #if wxUSE_TEXTDLG
-        entry_menu->Append(DIALOGS_TEXT_ENTRY,  wxT("Text &entry\tCtrl-E"));
+        entry_menu->Append(DIALOGS_LINE_ENTRY,  wxT("Single line &entry\tCtrl-E"));
+        entry_menu->Append(DIALOGS_TEXT_ENTRY,  wxT("Multi line text &entry\tShift-Ctrl-E"));
         entry_menu->Append(DIALOGS_PASSWORD_ENTRY,  wxT("&Password entry\tCtrl-P"));
     #endif // wxUSE_TEXTDLG
 
@@ -539,8 +541,23 @@ bool MyApp::OnInit()
     menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, wxT("About (&custom)...\tCtrl-Shift-F1"));
 #endif // wxUSE_ABOUTDLG
 
+    wxMenu* editMenu = new wxMenu;
+    editMenu->Append(wxID_UNDO, _("&Undo\tCtrl+Z"));
+    editMenu->Append(wxID_REDO, _("&Redo\tCtrl+Y"));
+    editMenu->AppendSeparator();
+    editMenu->Append(wxID_CUT, _("Cu&t\tCtrl+X"));
+    editMenu->Append(wxID_COPY, _("&Copy\tCtrl+C"));
+    editMenu->Append(wxID_PASTE, _("&Paste\tCtrl+V"));
+    editMenu->Append(wxID_CLEAR, _("&Delete"));
+    
+    editMenu->AppendSeparator();
+    editMenu->Append(wxID_SELECTALL, _("Select All\tCtrl+A"));
+
     wxMenuBar *menubar = new wxMenuBar;
     menubar->Append(menuDlg, wxT("&Dialogs"));
+    
+    menubar->Append(editMenu, wxT("&Edit"));
+    
 #if wxUSE_ABOUTDLG
     menubar->Append(menuHelp, wxT("&Help"));
 #endif // wxUSE_ABOUTDLG
@@ -631,6 +648,24 @@ MyFrame::MyFrame(const wxString& title)
     // covers our entire client area to avoid jarring colour jumps
     SetOwnBackgroundColour(m_canvas->GetBackgroundColour());
 #endif // wxUSE_INFOBAR
+
+#ifdef __WXMSW__
+    // Test MSW-specific function allowing to access the "system" menu.
+    wxMenu * const menu = MSWGetSystemMenu();
+    if ( menu )
+    {
+        menu->AppendSeparator();
+
+        // The ids of the menu commands in MSW system menu must be multiple of
+        // 16 so we can't use DIALOGS_ABOUTDLG_SIMPLE here because it might not
+        // satisfy this condition and need to define and connect a separate id.
+        static const int DIALOGS_SYSTEM_ABOUT = 0x4010;
+
+        menu->Append(DIALOGS_SYSTEM_ABOUT, "&About...");
+        Connect(DIALOGS_SYSTEM_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
+                wxCommandEventHandler(MyFrame::ShowSimpleAboutDialog));
+    }
+#endif // __WXMSW__
 }
 
 MyFrame::~MyFrame()
@@ -809,7 +844,7 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
                            wxCENTER |
                            wxNO_DEFAULT | wxYES_NO | wxCANCEL |
                            wxICON_INFORMATION);
-    
+
     wxString extmsg;
     if ( dialog.SetYesNoCancelLabels
         (
@@ -827,21 +862,21 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
         "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
     }
     dialog.SetExtendedMessage(extmsg);
-    
+
     switch ( dialog.ShowModal() )
     {
         case wxID_YES:
             wxLogStatus(wxT("You pressed \"Yes\""));
             break;
-            
+
         case wxID_NO:
             wxLogStatus(wxT("You pressed \"No\""));
             break;
-            
+
         case wxID_CANCEL:
             wxLogStatus(wxT("You pressed \"Cancel\""));
             break;
-            
+
         default:
             wxLogError(wxT("Unexpected wxMessageDialog return code!"));
     }
@@ -963,7 +998,7 @@ void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
     }
 }
 
-void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
+void MyFrame::LineEntry(wxCommandEvent& WXUNUSED(event))
 {
     wxTextEntryDialog dialog(this,
                              wxT("This is a small sample\n")
@@ -977,6 +1012,19 @@ void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
         wxMessageBox(dialog.GetValue(), wxT("Got string"), wxOK | wxICON_INFORMATION, this);
     }
 }
+
+void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
+{
+    wxTextEntryDialog dialog(this, "You can enter a multiline string here.",
+                             "Please enter some text",
+                             "First line\nSecond one\nAnd another one too",
+                             wxOK | wxCANCEL | wxTE_MULTILINE);
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        wxMessageBox(dialog.GetValue(), wxT("Got text"), wxOK | wxICON_INFORMATION, this);
+    }
+}
 #endif // wxUSE_TEXTDLG
 
 #if wxUSE_CHOICEDLG
@@ -1739,10 +1787,15 @@ void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
 
 #define ID_CATCH_LISTBOX_DCLICK 100
 #define ID_LISTBOX              101
+#define ID_DISABLE_OK           102
+#define ID_DISABLE_CANCEL       103
 
 BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
     EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK,    TestDefaultActionDialog::OnCatchListBoxDClick)
+    EVT_CHECKBOX(ID_DISABLE_OK,              TestDefaultActionDialog::OnDisableOK)
+    EVT_CHECKBOX(ID_DISABLE_CANCEL,          TestDefaultActionDialog::OnDisableCancel)
     EVT_LISTBOX_DCLICK(ID_LISTBOX,           TestDefaultActionDialog::OnListBoxDClick)
+    EVT_TEXT_ENTER(wxID_ANY,                 TestDefaultActionDialog::OnTextEnter)
 END_EVENT_TABLE()
 
 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
@@ -1771,6 +1824,9 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
     grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
     grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
 
+    grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_OK, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL );
+    grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_CANCEL, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL );
+
     main_sizer->Add( grid_sizer, 0, wxALL, 10 );
 
     wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
@@ -1780,6 +1836,16 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
     SetSizerAndFit( main_sizer );
 }
 
+void TestDefaultActionDialog::OnDisableOK(wxCommandEvent& event)
+{
+    FindWindow(wxID_OK)->Enable(!event.IsChecked());
+}
+
+void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent& event)
+{
+    FindWindow(wxID_CANCEL)->Enable(!event.IsChecked());
+}
+
 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
 {
     event.Skip( !m_catchListBoxDClick );
@@ -1790,6 +1856,11 @@ void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(even
     m_catchListBoxDClick = !m_catchListBoxDClick;
 }
 
+void TestDefaultActionDialog::OnTextEnter(wxCommandEvent& event)
+{
+    wxLogMessage("Text \"%s\" entered.", event.GetString());
+}
+
 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
 {
     TestDefaultActionDialog dialog( this );
@@ -2616,6 +2687,7 @@ const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
     { wxNO,     "&No"     },
     { wxOK,     "&Ok"     },
     { wxCANCEL, "&Cancel" },
+    { wxHELP,   "&Help"   },
 };
 
 BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
@@ -2695,7 +2767,7 @@ bool TestMessageBoxDialog::Create()
     };
 
    wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch );
-   
+
     m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style",
                              wxDefaultPosition, wxDefaultSize,
                              WXSIZEOF(icons), icons,
@@ -2836,6 +2908,11 @@ void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase &dlg)
             dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
         }
     }
+
+    if ( style & wxHELP )
+    {
+        dlg.SetHelpLabel(m_labels[Btn_Help]->GetValue());
+    }
 }
 
 void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
@@ -2843,7 +2920,34 @@ void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
     wxMessageDialog dlg(this, GetMessage(), "Test Message Box", GetStyle());
     PrepareMessageDialog(dlg);
 
-    dlg.ShowModal();
+    wxString btnName;
+    switch ( dlg.ShowModal() )
+    {
+        case wxID_OK:
+            btnName = "OK";
+            break;
+
+        case wxID_CANCEL:
+            // Avoid the extra message box if the dialog was cancelled.
+            return;
+
+        case wxID_YES:
+            btnName = "Yes";
+            break;
+
+        case wxID_NO:
+            btnName = "No";
+            break;
+
+        case wxID_HELP:
+            btnName = "Help";
+            break;
+
+        default:
+            btnName = "Unknown";
+    }
+
+    wxLogMessage("Dialog was closed with the \"%s\" button.", btnName);
 }
 
 void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))