]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/toolbar/toolbar.cpp
Quick VA fix
[wxWidgets.git] / samples / toolbar / toolbar.cpp
index e7feb997ea30502f6c5ed87b83d7ba2196f4fdf2..2394247175fcc6ded50bde7107cba930a6ab2f99 100644 (file)
 
 #include <wx/toolbar.h>
 #include <wx/log.h>
+#include <wx/image.h>
+
+// define this to 1 to use wxToolBarSimple instead of the native one
+#define USE_GENERIC_TBAR 0
+
+#if USE_GENERIC_TBAR
+    #if !wxUSE_TOOLBAR_SIMPLE
+        #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
+               to 1 in setup.h and recompile the library.
+    #else
+        #include <wx/tbarsmpl.h>
+    #endif
+#endif // USE_GENERIC_TBAR
 
 // ----------------------------------------------------------------------------
 // resources
@@ -76,11 +89,12 @@ public:
 
     void OnToggleToolbarSize(wxCommandEvent& event);
     void OnToggleToolbarOrient(wxCommandEvent& event);
+    void OnToggleToolbarRows(wxCommandEvent& event);
 
-    void OnEnablePrint(wxCommandEvent& event) { DoEnablePrint(); }
-    void OnDeletePrint(wxCommandEvent& event) { DoDeletePrint(); }
+    void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
+    void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); }
     void OnInsertPrint(wxCommandEvent& event);
-    void OnToggleHelp(wxCommandEvent& event) { DoToggleHelp(); }
+    void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); }
 
     void OnToolLeftClick(wxCommandEvent& event);
     void OnToolEnter(wxCommandEvent& event);
@@ -89,6 +103,14 @@ public:
 
     void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
 
+    void OnToggleFullScreen(wxCommandEvent& event);
+
+#if USE_GENERIC_TBAR
+    virtual wxToolBar *OnCreateToolBar(long style,
+                                       wxWindowID id,
+                                       const wxString& name );
+#endif // USE_GENERIC_TBAR
+
 private:
     void DoEnablePrint();
     void DoDeletePrint();
@@ -96,6 +118,8 @@ private:
 
     bool                m_smallToolbar,
                         m_horzToolbar;
+    size_t              m_rows;             // 1 or 2 only
+
     wxTextCtrl*         m_textWindow;
 
     DECLARE_EVENT_TABLE()
@@ -111,10 +135,12 @@ enum
 {
     IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
     IDM_TOOLBAR_TOGGLETOOLBARORIENT,
+    IDM_TOOLBAR_TOGGLETOOLBARROWS,
     IDM_TOOLBAR_ENABLEPRINT,
     IDM_TOOLBAR_DELETEPRINT,
     IDM_TOOLBAR_INSERTPRINT,
     IDM_TOOLBAR_TOGGLEHELP,
+    IDM_TOOLBAR_TOGGLEFULLSCREEN,
 
     ID_COMBO = 1000
 };
@@ -132,11 +158,13 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 
     EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
     EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
+    EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
 
     EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
     EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
     EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
     EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
+    EVT_MENU(IDM_TOOLBAR_TOGGLEFULLSCREEN, MyFrame::OnToggleFullScreen)
 
     EVT_MENU(-1, MyFrame::OnToolLeftClick)
 
@@ -167,14 +195,6 @@ bool MyApp::OnInit()
                                  "wxToolBar Sample",
                                  wxPoint(100, 100), wxSize(450, 300));
 
-    // VZ: what's this for??
-#if 0
-    // Force a resize. This should probably be replaced by a call to a wxFrame
-    // function that lays out default decorations and the remaining content window.
-    wxSizeEvent event(wxSize(-1, -1), frame->GetId());
-    frame->OnSize(event);
-#endif // 0
-
     frame->Show(TRUE);
 
     frame->SetStatusText("Hello, wxWindows");
@@ -187,7 +207,7 @@ bool MyApp::OnInit()
 void MyFrame::RecreateToolbar()
 {
     // delete and recreate the toolbar
-    wxToolBar *toolBar = GetToolBar();
+    wxToolBarBase *toolBar = GetToolBar();
     delete toolBar;
 
     SetToolBar(NULL);
@@ -203,14 +223,24 @@ void MyFrame::RecreateToolbar()
 
     toolBarBitmaps[0] = wxBITMAP(new);
     toolBarBitmaps[1] = wxBITMAP(open);
+    toolBarBitmaps[2] = wxBITMAP(save);
+    toolBarBitmaps[3] = wxBITMAP(copy);
+    toolBarBitmaps[4] = wxBITMAP(cut);
+    toolBarBitmaps[5] = wxBITMAP(paste);
+    toolBarBitmaps[6] = wxBITMAP(print);
+    toolBarBitmaps[7] = wxBITMAP(help);
+
     if ( !m_smallToolbar )
     {
-        toolBarBitmaps[2] = wxBITMAP(save);
-        toolBarBitmaps[3] = wxBITMAP(copy);
-        toolBarBitmaps[4] = wxBITMAP(cut);
-        toolBarBitmaps[5] = wxBITMAP(paste);
-        toolBarBitmaps[6] = wxBITMAP(print);
-        toolBarBitmaps[7] = wxBITMAP(help);
+        int w = 2*toolBarBitmaps[0].GetWidth(),
+            h = 2*toolBarBitmaps[0].GetHeight();
+        for ( size_t n = 0; n < WXSIZEOF(toolBarBitmaps); n++ )
+        {
+            toolBarBitmaps[n] =
+                wxImage(toolBarBitmaps[n]).Scale(w, h).ConvertToBitmap();
+        }
+
+        toolBar->SetToolBitmapSize(wxSize(w, h));
     }
 
 #ifdef __WXMSW__
@@ -225,6 +255,8 @@ void MyFrame::RecreateToolbar()
     currentX += width + 5;
     toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file");
 
+    // neither the generic nor Motif native toolbars really support this
+#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__)
     // adding a combo to a vertical toolbar is not very smart
     if ( m_horzToolbar )
     {
@@ -236,27 +268,27 @@ void MyFrame::RecreateToolbar()
         combo->Append("toolbar");
         toolBar->AddControl(combo);
     }
+#endif // toolbars which don't support controls
 
-    if ( !m_smallToolbar )
-    {
-        currentX += width + 5;
-        toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1");
-        currentX += width + 5;
-        toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 2");
-        currentX += width + 5;
-        toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Toggle/Untoggle help button");
-        currentX += width + 5;
-        toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste");
-        currentX += width + 5;
-        toolBar->AddTool(wxID_PRINT, toolBarBitmaps[6], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Delete this tool");
-        currentX += width + 5;
-        toolBar->AddSeparator();
-        toolBar->AddTool(wxID_HELP, toolBarBitmaps[7], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button");
-    }
+    currentX += width + 5;
+    toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1");
+    currentX += width + 5;
+    toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 2");
+    currentX += width + 5;
+    toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Toggle/Untoggle help button");
+    currentX += width + 5;
+    toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste");
+    currentX += width + 5;
+    toolBar->AddTool(wxID_PRINT, toolBarBitmaps[6], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Delete this tool");
+    currentX += width + 5;
+    toolBar->AddSeparator();
+    toolBar->AddTool(wxID_HELP, toolBarBitmaps[7], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button");
 
     // after adding the buttons to the toolbar, must call Realize() to reflect
     // the changes
     toolBar->Realize();
+
+    toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
 }
 
 // ----------------------------------------------------------------------------
@@ -273,8 +305,10 @@ MyFrame::MyFrame(wxFrame* parent,
        : wxFrame(parent, id, title, pos, size, style)
 {
     m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
-    m_smallToolbar = FALSE;
-    m_horzToolbar = FALSE;
+
+    m_smallToolbar = TRUE;
+    m_horzToolbar = TRUE;
+    m_rows = 1;
 
     // Give it a status line
     CreateStatusBar();
@@ -292,6 +326,10 @@ MyFrame::MyFrame(wxFrame* parent,
                      "Toggle toolbar &orientation\tCtrl-O",
                      "Toggle toolbar orientation",
                      TRUE);
+    tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBARROWS,
+                     "Toggle number of &rows\tCtrl-R",
+                     "Toggle number of toolbar rows between 1 and 2",
+                     TRUE);
 
     tbarMenu->AppendSeparator();
 
@@ -300,6 +338,11 @@ MyFrame::MyFrame(wxFrame* parent,
     tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, "&Insert print button\tCtrl-I", "");
     tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button\tCtrl-T", "");
 
+#ifdef __WXMSW__
+    tbarMenu->AppendSeparator();
+    tbarMenu->Append(IDM_TOOLBAR_TOGGLEFULLSCREEN, "Toggle &full screen mode\tCtrl-F", "");
+#endif
+
     wxMenu *fileMenu = new wxMenu;
     fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
 
@@ -319,6 +362,19 @@ MyFrame::MyFrame(wxFrame* parent,
     RecreateToolbar();
 }
 
+#if USE_GENERIC_TBAR
+
+wxToolBar* MyFrame::OnCreateToolBar(long style,
+                                    wxWindowID id,
+                                    const wxString& name)
+{
+    return (wxToolBar *)new wxToolBarSimple(this, id,
+                                            wxDefaultPosition, wxDefaultSize,
+                                            style, name);
+}
+
+#endif // USE_GENERIC_TBAR
+
 void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
 {
     m_smallToolbar = !m_smallToolbar;
@@ -326,6 +382,16 @@ void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
     RecreateToolbar();
 }
 
+void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
+{
+    // m_rows may be only 1 or 2
+    m_rows = 3 - m_rows;
+
+    GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
+
+    //RecreateToolbar(); -- this is unneeded
+}
+
 void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
 {
     m_horzToolbar = !m_horzToolbar;
@@ -380,7 +446,7 @@ void MyFrame::OnCombo(wxCommandEvent& event)
 
 void MyFrame::DoEnablePrint()
 {
-    wxToolBar *tb = GetToolBar();
+    wxToolBarBase *tb = GetToolBar();
     if (tb->GetToolEnabled(wxID_PRINT))
         tb->EnableTool( wxID_PRINT, FALSE );
     else
@@ -389,14 +455,14 @@ void MyFrame::DoEnablePrint()
 
 void MyFrame::DoDeletePrint()
 {
-    wxToolBar *tb = GetToolBar();
+    wxToolBarBase *tb = GetToolBar();
 
     tb->DeleteTool( wxID_PRINT );
 }
 
 void MyFrame::DoToggleHelp()
 {
-    wxToolBar *tb = GetToolBar();
+    wxToolBarBase *tb = GetToolBar();
     tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
 }
 
@@ -419,13 +485,20 @@ void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnToolEnter(wxCommandEvent& event)
 {
-  if (event.GetSelection() > -1)
-  {
-    wxString str;
-    str.Printf(_T("This is tool number %d"), event.GetSelection());
-    SetStatusText(str);
-  }
-  else
-    SetStatusText("");
+    if (event.GetSelection() > -1)
+    {
+        wxString str;
+        str.Printf(_T("This is tool number %d"), event.GetSelection());
+        SetStatusText(str);
+    }
+    else
+        SetStatusText("");
+}
+
+void MyFrame::OnToggleFullScreen(wxCommandEvent& event)
+{
+#ifdef __WXMSW__
+    ShowFullScreen(!IsFullScreen());
+#endif
 }