]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/toolbar/toolbar.cpp
In wxPropertyGrid::HandleCustomEditorEvent(), also filter out excess wxEVT_COMMAND_TE...
[wxWidgets.git] / samples / toolbar / toolbar.cpp
index 7629206d39226bc035d845f86c6e27a97fe4116f..2c62dcd5c0a4a11e28a8373b1ba0e443f6d9a58b 100644 (file)
@@ -134,6 +134,7 @@ public:
 
     void OnToolbarStyle(wxCommandEvent& event);
     void OnToolbarBgCol(wxCommandEvent& event);
 
     void OnToolbarStyle(wxCommandEvent& event);
     void OnToolbarBgCol(wxCommandEvent& event);
+    void OnToolbarCustomBg(wxCommandEvent& event);
     void OnToolbarCustomBitmap(wxCommandEvent& event);
 
     void OnToolLeftClick(wxCommandEvent& event);
     void OnToolbarCustomBitmap(wxCommandEvent& event);
 
     void OnToolLeftClick(wxCommandEvent& event);
@@ -148,6 +149,8 @@ public:
         { event.Enable( m_tbar != NULL ); }
 
 private:
         { event.Enable( m_tbar != NULL ); }
 
 private:
+    void OnEraseToolBarBackground(wxEraseEvent& event);
+
     void DoEnablePrint();
     void DoDeletePrint();
     void DoToggleHelp();
     void DoEnablePrint();
     void DoDeletePrint();
     void DoToggleHelp();
@@ -206,6 +209,7 @@ enum
     IDM_TOOLBAR_SHOW_ICONS,
     IDM_TOOLBAR_SHOW_BOTH,
     IDM_TOOLBAR_BG_COL,
     IDM_TOOLBAR_SHOW_ICONS,
     IDM_TOOLBAR_SHOW_BOTH,
     IDM_TOOLBAR_BG_COL,
+    IDM_TOOLBAR_CUSTOM_BG,
     IDM_TOOLBAR_CUSTOM_PATH,
     IDM_TOOLBAR_TOP_ORIENTATION,
     IDM_TOOLBAR_LEFT_ORIENTATION,
     IDM_TOOLBAR_CUSTOM_PATH,
     IDM_TOOLBAR_TOP_ORIENTATION,
     IDM_TOOLBAR_LEFT_ORIENTATION,
@@ -264,6 +268,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
                    MyFrame::OnToolbarStyle)
     EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol)
     EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
                    MyFrame::OnToolbarStyle)
     EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol)
+    EVT_MENU(IDM_TOOLBAR_CUSTOM_BG, MyFrame::OnToolbarCustomBg)
 
     EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap)
 
 
     EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap)
 
@@ -305,7 +310,7 @@ bool MyApp::OnInit()
     // Create the main frame window
     MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY,
                                  wxT("wxToolBar Sample"),
     // Create the main frame window
     MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY,
                                  wxT("wxToolBar Sample"),
-                                  wxPoint(100, 100), wxSize(550, 300));
+                                  wxPoint(100, 100), wxSize(650, 300));
 
     frame->Show(true);
 
 
     frame->Show(true);
 
@@ -371,6 +376,17 @@ void MyFrame::RecreateToolbar()
     toolBar = CreateToolBar(style, ID_TOOLBAR);
 #endif
 
     toolBar = CreateToolBar(style, ID_TOOLBAR);
 #endif
 
+    if ( GetMenuBar()->IsChecked(IDM_TOOLBAR_CUSTOM_BG) )
+    {
+        toolBar->Connect
+                 (
+                    wxEVT_ERASE_BACKGROUND,
+                    wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
+                    NULL,
+                    this
+                 );
+    }
+
     PopulateToolbar(toolBar);
 }
 
     PopulateToolbar(toolBar);
 }
 
@@ -458,9 +474,12 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
 #endif // USE_CONTROLS_IN_TOOLBAR
 
     toolBar->AddTool(wxID_SAVE, wxT("Save"), toolBarBitmaps[Tool_save], wxT("Toggle button 1"), wxITEM_CHECK);
 #endif // USE_CONTROLS_IN_TOOLBAR
 
     toolBar->AddTool(wxID_SAVE, wxT("Save"), toolBarBitmaps[Tool_save], wxT("Toggle button 1"), wxITEM_CHECK);
+
+    toolBar->AddSeparator();
     toolBar->AddTool(wxID_COPY, wxT("Copy"), toolBarBitmaps[Tool_copy], wxT("Toggle button 2"), wxITEM_CHECK);
     toolBar->AddTool(wxID_CUT, wxT("Cut"), toolBarBitmaps[Tool_cut], wxT("Toggle/Untoggle help button"));
     toolBar->AddTool(wxID_PASTE, wxT("Paste"), toolBarBitmaps[Tool_paste], wxT("Paste"));
     toolBar->AddTool(wxID_COPY, wxT("Copy"), toolBarBitmaps[Tool_copy], wxT("Toggle button 2"), wxITEM_CHECK);
     toolBar->AddTool(wxID_CUT, wxT("Cut"), toolBarBitmaps[Tool_cut], wxT("Toggle/Untoggle help button"));
     toolBar->AddTool(wxID_PASTE, wxT("Paste"), toolBarBitmaps[Tool_paste], wxT("Paste"));
+    toolBar->AddSeparator();
 
     if ( m_useCustomDisabled )
     {
 
     if ( m_useCustomDisabled )
     {
@@ -484,7 +503,9 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
                          wxT("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with."));
     }
 
                          wxT("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with."));
     }
 
-    toolBar->AddSeparator();
+    // add a stretchable space before the "Help" button to make it
+    // right-aligned
+    toolBar->AddStretchableSpace();
     toolBar->AddTool(wxID_HELP, wxT("Help"), toolBarBitmaps[Tool_help], wxT("Help button"), wxITEM_CHECK);
 
     if ( !m_pathBmp.empty() )
     toolBar->AddTool(wxID_HELP, wxT("Help"), toolBarBitmaps[Tool_help], wxT("Help button"), wxITEM_CHECK);
 
     if ( !m_pathBmp.empty() )
@@ -591,6 +612,7 @@ MyFrame::MyFrame(wxFrame* parent,
     tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B"));
     tbarMenu->AppendSeparator();
     tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour..."));
     tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B"));
     tbarMenu->AppendSeparator();
     tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour..."));
+    tbarMenu->AppendCheckItem(IDM_TOOLBAR_CUSTOM_BG, wxT("Draw custom back&ground"));
     tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B"));
 
     wxMenu *toolMenu = new wxMenu;
     tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B"));
 
     wxMenu *toolMenu = new wxMenu;
@@ -690,6 +712,15 @@ void MyFrame::OnSize(wxSizeEvent& event)
     }
 }
 
     }
 }
 
+void MyFrame::OnEraseToolBarBackground(wxEraseEvent& event)
+{
+    wxDC& dc = *event.GetDC();
+    const wxSize size = dc.GetSize();
+    dc.SetPen(*wxRED_PEN);
+    dc.DrawLine(0, 0, size.x, size.y);
+    dc.DrawLine(0, size.y, size.x, 0);
+}
+
 void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
 {
     wxToolBar *tbar = GetToolBar();
 void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
 {
     wxToolBar *tbar = GetToolBar();
@@ -873,14 +904,12 @@ void MyFrame::DoToggleHelp()
 
 void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event))
 {
 
 void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event))
 {
-    static const int searchPos = 3;
-
     wxToolBarBase * const tb = GetToolBar();
     if ( !m_searchTool )
     {
         wxSearchCtrl * const srch = new wxSearchCtrl(tb, wxID_ANY, "needle");
         srch->SetMinSize(wxSize(80, -1));
     wxToolBarBase * const tb = GetToolBar();
     if ( !m_searchTool )
     {
         wxSearchCtrl * const srch = new wxSearchCtrl(tb, wxID_ANY, "needle");
         srch->SetMinSize(wxSize(80, -1));
-        m_searchTool = tb->InsertControl(searchPos, srch);
+        m_searchTool = tb->AddControl(srch);
     }
     else // tool already exists
     {
     }
     else // tool already exists
     {
@@ -893,7 +922,7 @@ void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event))
         }
         else // tool exists in detached state, attach it back
         {
         }
         else // tool exists in detached state, attach it back
         {
-            tb->InsertTool(searchPos, m_searchTool);
+            tb->AddTool(m_searchTool);
             win->Show();
         }
     }
             win->Show();
         }
     }
@@ -956,6 +985,34 @@ void MyFrame::OnToolbarBgCol(wxCommandEvent& WXUNUSED(event))
     }
 }
 
     }
 }
 
+void MyFrame::OnToolbarCustomBg(wxCommandEvent& event)
+{
+    wxToolBarBase *tb = GetToolBar();
+
+    if ( event.IsChecked() )
+    {
+        tb->Connect
+            (
+             wxEVT_ERASE_BACKGROUND,
+             wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
+             NULL,
+             this
+            );
+    }
+    else
+    {
+        tb->Disconnect
+            (
+             wxEVT_ERASE_BACKGROUND,
+             wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
+             NULL,
+             this
+            );
+    }
+
+    tb->Refresh();
+}
+
 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event))
 {
     m_pathBmp = wxLoadFileSelector("custom bitmap", "");
 void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event))
 {
     m_pathBmp = wxLoadFileSelector("custom bitmap", "");