]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/taborder/taborder.cpp
Make a couple virtuals protected so they can be overridden.
[wxWidgets.git] / samples / taborder / taborder.cpp
index 18b6593055ad4c5591cc26a1b1385e19da01ed68..934dedcd3d2366c3caa0ce4f3b149c4305625f13 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Vadim Zeitlin
 // RCS-ID:      $Id$
 // Copyright:   (c) 2007 Vadim Zeitlin
 // Author:      Vadim Zeitlin
 // RCS-ID:      $Id$
 // Copyright:   (c) 2007 Vadim Zeitlin
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 #endif
 
 #ifndef WX_PRECOMP
 #endif
 
 #ifndef WX_PRECOMP
-    #include "wx/wx.h"
+    #include "wx/app.h"
+    #include "wx/log.h"
+    #include "wx/frame.h"
+    #include "wx/menu.h"
+    #include "wx/sizer.h"
+
+    #include "wx/panel.h"
+    #include "wx/msgdlg.h"
+
+    #include "wx/button.h"
+    #include "wx/listbox.h"
+    #include "wx/stattext.h"
+    #include "wx/textctrl.h"
 #endif
 
 #endif
 
+#include "wx/notebook.h"
+
+#ifndef wxHAS_IMAGES_IN_RESOURCES
+    #include "../sample.xpm"
+#endif
+
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -33,8 +52,8 @@
 enum
 {
     // file menu
 enum
 {
     // file menu
-    TabOrder_Quit = 100,
-    TabOrder_About,
+    TabOrder_Quit = wxID_EXIT,
+    TabOrder_About = wxID_ABOUT,
 
     // navigation menu
     TabOrder_TabForward = 200,
 
     // navigation menu
     TabOrder_TabForward = 200,
@@ -78,17 +97,18 @@ private:
 
     void OnIdle(wxIdleEvent& event);
 
 
     void OnIdle(wxIdleEvent& event);
 
-    void DoNavigate(long flags)
+    void DoNavigate(int flags)
     {
     {
-        wxNavigationKeyEvent event;
-        event.SetFlags(flags);
-        if ( m_panel->ProcessEvent(event) )
-            wxLogStatus(this, _T("Navigation event processed"));
+        if ( m_panel->NavigateIn(flags) )
+        {
+            wxLogStatus(this, wxT("Navigation event processed"));
+        }
         else
         else
-            wxLogStatus(this, _T("Navigation event ignored"));
+        {
+            wxLogStatus(this, wxT("Navigation event ignored"));
+        }
     }
 
     }
 
-
     wxPanel *m_panel;
 
     DECLARE_EVENT_TABLE()
     wxPanel *m_panel;
 
     DECLARE_EVENT_TABLE()
@@ -99,6 +119,44 @@ class MyPanel : public wxPanel
 {
 public:
     MyPanel(wxWindow *parent);
 {
 public:
     MyPanel(wxWindow *parent);
+
+private:
+    wxWindow *CreateButtonPage(wxWindow *parent);
+    wxWindow *CreateTextPage(wxWindow *parent);
+};
+
+// a text control which checks if processing Tab presses in controls with
+// wxTE_PROCESS_TAB style really works
+class MyTabTextCtrl : public wxTextCtrl
+{
+public:
+    MyTabTextCtrl(wxWindow *parent, const wxString& value, int flags = 0)
+        : wxTextCtrl(parent, wxID_ANY, value,
+                     wxDefaultPosition, wxDefaultSize,
+                     flags)
+    {
+        Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyTabTextCtrl::OnKeyDown));
+    }
+
+private:
+    void OnKeyDown(wxKeyEvent& event)
+    {
+        if ( event.GetKeyCode() == WXK_TAB &&
+                wxMessageBox
+                (
+                    wxT("Let the Tab be used for navigation?"),
+                    wxT("wxWidgets TabOrder sample: Tab key pressed"),
+                    wxICON_QUESTION | wxYES_NO,
+                    this
+                ) != wxYES )
+        {
+            // skip Skip() below: we consume the Tab press ourselves and so the
+            // focus shouldn't change
+            return;
+        }
+
+        event.Skip();
+    }
 };
 
 // ============================================================================
 };
 
 // ============================================================================
@@ -137,23 +195,25 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 END_EVENT_TABLE()
 
 MyFrame::MyFrame()
 END_EVENT_TABLE()
 
 MyFrame::MyFrame()
-       : wxFrame(NULL, wxID_ANY, _T("TabOrder wxWidgets Sample"),
+       : wxFrame(NULL, wxID_ANY, wxT("TabOrder wxWidgets Sample"),
                  wxDefaultPosition, wxSize(700, 450))
 {
                  wxDefaultPosition, wxSize(700, 450))
 {
+    SetIcon(wxICON(sample));
+
     wxMenu *menuFile = new wxMenu;
     wxMenu *menuFile = new wxMenu;
-    menuFile->Append(TabOrder_About, _T("&About...\tF1"));
+    menuFile->Append(TabOrder_About);
     menuFile->AppendSeparator();
     menuFile->AppendSeparator();
-    menuFile->Append(TabOrder_Quit, _T("E&xit\tAlt-X"), _T("Quit the sample"));
+    menuFile->Append(TabOrder_Quit);
 
     wxMenu *menuNav = new wxMenu;
 
     wxMenu *menuNav = new wxMenu;
-    menuNav->Append(TabOrder_TabForward, _T("Tab &forward\tCtrl-F"),
-                    _T("Emulate a <Tab> press"));
-    menuNav->Append(TabOrder_TabBackward, _T("Tab &backward\tCtrl-B"),
-                    _T("Emulate a <Shift-Tab> press"));
+    menuNav->Append(TabOrder_TabForward, wxT("Tab &forward\tCtrl-F"),
+                    wxT("Emulate a <Tab> press"));
+    menuNav->Append(TabOrder_TabBackward, wxT("Tab &backward\tCtrl-B"),
+                    wxT("Emulate a <Shift-Tab> press"));
 
     wxMenuBar *mbar = new wxMenuBar;
 
     wxMenuBar *mbar = new wxMenuBar;
-    mbar->Append(menuFile, _T("&File"));
-    mbar->Append(menuNav, _T("&Navigate"));
+    mbar->Append(menuFile, wxT("&File"));
+    mbar->Append(menuNav, wxT("&Navigate"));
 
     SetMenuBar(mbar);
 
 
     SetMenuBar(mbar);
 
@@ -169,8 +229,8 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
-    wxMessageBox(_T("Tab navigation sample\n(c) 2007 Vadim Zeitlin"),
-                 _T("About TabOrder wxWidgets Sample"), wxOK, this);
+    wxMessageBox(wxT("Tab navigation sample\n(c) 2007 Vadim Zeitlin"),
+                 wxT("About TabOrder wxWidgets Sample"), wxOK, this);
 }
 
 void MyFrame::OnTabForward(wxCommandEvent& WXUNUSED(event))
 }
 
 void MyFrame::OnTabForward(wxCommandEvent& WXUNUSED(event))
@@ -195,11 +255,11 @@ void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
         wxString msg;
         if ( focus )
         {
         wxString msg;
         if ( focus )
         {
-            msg.Printf(_T("Focus is at %s"), s_windowFocus->GetName().c_str());
+            msg.Printf(wxT("Focus is at %s"), s_windowFocus->GetName().c_str());
         }
         else
         {
         }
         else
         {
-            msg = _T("No focus");
+            msg = wxT("No focus");
         }
 
         SetStatusText(msg, StatusPane_Focus);
         }
 
         SetStatusText(msg, StatusPane_Focus);
@@ -212,16 +272,60 @@ void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
 
 MyPanel::MyPanel(wxWindow *parent)
        : wxPanel(parent, wxID_ANY)
 
 MyPanel::MyPanel(wxWindow *parent)
        : wxPanel(parent, wxID_ANY)
+{
+    wxNotebook *notebook = new wxNotebook(this, wxID_ANY);
+    notebook->AddPage(CreateButtonPage(notebook), wxT("Button"));
+    notebook->AddPage(CreateTextPage(notebook), wxT("Text"));
+
+    wxSizer *sizerV = new wxBoxSizer(wxVERTICAL);
+    sizerV->Add(notebook, wxSizerFlags(1).Expand());
+
+    wxListBox *lbox = new wxListBox(this, wxID_ANY);
+    lbox->AppendString(wxT("Just a"));
+    lbox->AppendString(wxT("simple"));
+    lbox->AppendString(wxT("listbox"));
+    sizerV->Add(lbox, wxSizerFlags(1).Expand());
+
+    SetSizerAndFit(sizerV);
+}
+
+wxWindow *MyPanel::CreateButtonPage(wxWindow *parent)
+{
+    wxSizerFlags flagsBorder = wxSizerFlags().Border().Centre();
+
+    wxPanel *page = new wxPanel(parent);
+    wxSizer *sizerPage = new wxBoxSizer(wxHORIZONTAL);
+    sizerPage->Add(new wxButton(page, wxID_ANY, wxT("&First")), flagsBorder);
+    sizerPage->Add(new wxStaticText(page, wxID_ANY, wxT("[st&atic]")),
+                   flagsBorder);
+    sizerPage->Add(new wxButton(page, wxID_ANY, wxT("&Second")), flagsBorder);
+
+    page->SetSizer(sizerPage);
+
+    return page;
+}
+
+wxWindow *MyPanel::CreateTextPage(wxWindow *parent)
 {
     wxSizerFlags flagsBorder = wxSizerFlags().Border();
 
 {
     wxSizerFlags flagsBorder = wxSizerFlags().Border();
 
+    wxSizer *sizerPage = new wxBoxSizer(wxVERTICAL);
+    wxPanel *page = new wxPanel(parent);
+
     wxSizer *sizerH = new wxBoxSizer(wxHORIZONTAL);
     wxSizer *sizerH = new wxBoxSizer(wxHORIZONTAL);
-    sizerH->Add(new wxButton(this, wxID_ANY, _T("&First")), flagsBorder);
-    sizerH->Add(new wxButton(this, wxID_ANY, _T("&Second")), flagsBorder);
+    sizerH->Add(new wxStaticText(page, wxID_ANY, wxT("&Label:")), flagsBorder);
+    sizerH->Add(new MyTabTextCtrl(page, wxT("TAB ignored here")), flagsBorder);
+    sizerPage->Add(sizerH, wxSizerFlags(1).Expand());
 
 
-    wxSizer *sizerV = new wxBoxSizer(wxVERTICAL);
-    sizerV->Add(sizerH, wxSizerFlags(1).Expand());
-    sizerV->Add(new wxListBox(this, wxID_ANY), wxSizerFlags(1).Expand());
-    SetSizerAndFit(sizerV);
+    sizerH = new wxBoxSizer(wxHORIZONTAL);
+    sizerH->Add(new wxStaticText(page, wxID_ANY, wxT("&Another one:")),
+                flagsBorder);
+    sizerH->Add(new MyTabTextCtrl(page, wxT("press Tab here"), wxTE_PROCESS_TAB),
+                flagsBorder);
+    sizerPage->Add(sizerH, wxSizerFlags(1).Expand());
+
+    page->SetSizer(sizerPage);
+
+    return page;
 }
 
 }