home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / samples / toolbar / toolbar.cpp < prev    next >
C/C++ Source or Header  |  2002-12-28  |  20KB  |  660 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        toolbar.cpp
  3. // Purpose:     wxToolBar sample
  4. // Author:      Julian Smart
  5. // Modified by:
  6. // Created:     04/01/98
  7. // RCS-ID:      $Id: toolbar.cpp,v 1.24.2.4 2002/12/28 18:37:06 JS Exp $
  8. // Copyright:   (c) Julian Smart
  9. // Licence:     wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. // ============================================================================
  13. // declarations
  14. // ============================================================================
  15.  
  16. // ----------------------------------------------------------------------------
  17. // headers
  18. // ----------------------------------------------------------------------------
  19.  
  20. // For compilers that support precompilation, includes "wx/wx.h".
  21. #include "wx/wxprec.h"
  22.  
  23. #ifdef __BORLANDC__
  24.     #pragma hdrstop
  25. #endif
  26.  
  27. #ifndef WX_PRECOMP
  28.     #include <wx/wx.h>
  29. #endif
  30.  
  31. #include <wx/toolbar.h>
  32. #include <wx/log.h>
  33. #include <wx/image.h>
  34.  
  35. // define this to 1 to use wxToolBarSimple instead of the native one
  36. #define USE_GENERIC_TBAR 0
  37.  
  38. // define this to use XPMs everywhere (by default, BMPs are used under Win)
  39. // BMPs use less space, but aren't compiled into the executable on other platforms
  40. #ifdef __WXMSW__
  41.     #define USE_XPM_BITMAPS 0
  42. #else
  43.     #define USE_XPM_BITMAPS 1
  44. #endif
  45.  
  46. #if USE_GENERIC_TBAR
  47.     #if !wxUSE_TOOLBAR_SIMPLE
  48.         #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
  49.                to 1 in setup.h and recompile the library.
  50.     #else
  51.         #include <wx/tbarsmpl.h>
  52.     #endif
  53. #endif // USE_GENERIC_TBAR
  54.  
  55. #if USE_XPM_BITMAPS && defined(__WXMSW__) && !wxUSE_XPM_IN_MSW
  56.     #error You need to enable XPM support to use XPM bitmaps with toolbar!
  57. #endif // USE_XPM_BITMAPS
  58.  
  59. // ----------------------------------------------------------------------------
  60. // resources
  61. // ----------------------------------------------------------------------------
  62.  
  63. #if USE_XPM_BITMAPS
  64.     #include "mondrian.xpm"
  65.     #include "bitmaps/new.xpm"
  66.     #include "bitmaps/open.xpm"
  67.     #include "bitmaps/save.xpm"
  68.     #include "bitmaps/copy.xpm"
  69.     #include "bitmaps/cut.xpm"
  70.     #include "bitmaps/preview.xpm"  // paste XPM
  71.     #include "bitmaps/print.xpm"
  72.     #include "bitmaps/help.xpm"
  73. #endif // USE_XPM_BITMAPS
  74.  
  75. // ----------------------------------------------------------------------------
  76. // classes
  77. // ----------------------------------------------------------------------------
  78.  
  79. // Define a new application
  80. class MyApp : public wxApp
  81. {
  82. public:
  83.     bool OnInit();
  84. };
  85.  
  86. // Define a new frame
  87. class MyFrame: public wxFrame
  88. {
  89. public:
  90.     MyFrame(wxFrame *parent,
  91.             wxWindowID id = -1,
  92.             const wxString& title = _T("wxToolBar Sample"),
  93.             const wxPoint& pos = wxDefaultPosition,
  94.             const wxSize& size = wxDefaultSize,
  95.             long style = wxDEFAULT_FRAME_STYLE);
  96.  
  97.     void RecreateToolbar();
  98.  
  99.     void OnQuit(wxCommandEvent& event);
  100.     void OnAbout(wxCommandEvent& event);
  101.  
  102.     void OnSize(wxSizeEvent& event);
  103.  
  104.     void OnToggleToolbar(wxCommandEvent& event);
  105.     void OnToggleAnotherToolbar(wxCommandEvent& event);
  106.  
  107.     void OnToggleToolbarSize(wxCommandEvent& event);
  108.     void OnToggleToolbarOrient(wxCommandEvent& event);
  109.     void OnToggleToolbarRows(wxCommandEvent& event);
  110.  
  111.     void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
  112.     void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); }
  113.     void OnInsertPrint(wxCommandEvent& event);
  114.     void OnChangeToolTip(wxCommandEvent& event);
  115.     void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); }
  116.  
  117.     void OnToolbarStyle(wxCommandEvent& event);
  118.  
  119.     void OnToolLeftClick(wxCommandEvent& event);
  120.     void OnToolEnter(wxCommandEvent& event);
  121.  
  122.     void OnCombo(wxCommandEvent& event);
  123.  
  124.     void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
  125.  
  126. #if USE_GENERIC_TBAR
  127.     virtual wxToolBar *OnCreateToolBar(long style,
  128.                                        wxWindowID id,
  129.                                        const wxString& name );
  130. #endif // USE_GENERIC_TBAR
  131.  
  132. private:
  133.     void DoEnablePrint();
  134.     void DoDeletePrint();
  135.     void DoToggleHelp();
  136.  
  137.     void LayoutChildren();
  138.  
  139.     bool                m_smallToolbar,
  140.                         m_horzToolbar;
  141.     size_t              m_rows;             // 1 or 2 only
  142.  
  143.     // the number of print buttons we have (they're added/removed dynamically)
  144.     size_t              m_nPrint;
  145.  
  146.     wxTextCtrl         *m_textWindow;
  147.  
  148.     wxToolBar          *m_tbar;
  149.  
  150.     DECLARE_EVENT_TABLE()
  151. };
  152.  
  153. // ----------------------------------------------------------------------------
  154. // constants
  155. // ----------------------------------------------------------------------------
  156.  
  157. const int ID_TOOLBAR = 500;
  158.  
  159. static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT ;
  160.  
  161. enum
  162. {
  163.     IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
  164.     IDM_TOOLBAR_TOGGLETOOLBARORIENT,
  165.     IDM_TOOLBAR_TOGGLETOOLBARROWS,
  166.     IDM_TOOLBAR_ENABLEPRINT,
  167.     IDM_TOOLBAR_DELETEPRINT,
  168.     IDM_TOOLBAR_INSERTPRINT,
  169.     IDM_TOOLBAR_TOGGLEHELP,
  170.     IDM_TOOLBAR_TOGGLE_TOOLBAR,
  171.     IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
  172.     IDM_TOOLBAR_CHANGE_TOOLTIP,
  173.     IDM_TOOLBAR_SHOW_TEXT,
  174.     IDM_TOOLBAR_SHOW_ICONS,
  175.     IDM_TOOLBAR_SHOW_BOTH,
  176.  
  177.     ID_COMBO = 1000
  178. };
  179.  
  180. // ----------------------------------------------------------------------------
  181. // event tables
  182. // ----------------------------------------------------------------------------
  183.  
  184. // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
  185. // help button.
  186.  
  187. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  188.     EVT_SIZE(MyFrame::OnSize)
  189.  
  190.     EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
  191.     EVT_MENU(wxID_HELP, MyFrame::OnAbout)
  192.  
  193.     EVT_MENU(IDM_TOOLBAR_TOGGLE_TOOLBAR, MyFrame::OnToggleToolbar)
  194.     EVT_MENU(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR, MyFrame::OnToggleAnotherToolbar)
  195.  
  196.     EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
  197.     EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
  198.     EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
  199.  
  200.     EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
  201.     EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
  202.     EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
  203.     EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
  204.     EVT_MENU(IDM_TOOLBAR_CHANGE_TOOLTIP, MyFrame::OnChangeToolTip)
  205.  
  206.     EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
  207.                    MyFrame::OnToolbarStyle)
  208.  
  209.     EVT_MENU(-1, MyFrame::OnToolLeftClick)
  210.  
  211.     EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
  212.  
  213.     EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
  214.  
  215.     EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut)
  216.     EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut)
  217. END_EVENT_TABLE()
  218.  
  219. // ============================================================================
  220. // implementation
  221. // ============================================================================
  222.  
  223. // ----------------------------------------------------------------------------
  224. // MyApp
  225. // ----------------------------------------------------------------------------
  226.  
  227. IMPLEMENT_APP(MyApp)
  228.  
  229. // The `main program' equivalent, creating the windows and returning the
  230. // main frame
  231. bool MyApp::OnInit()
  232. {
  233.     // Create the main frame window
  234.     MyFrame* frame = new MyFrame((wxFrame *) NULL, -1,
  235.                                  _T("wxToolBar Sample"),
  236.                                  wxPoint(100, 100), wxSize(550, 300));
  237.  
  238.     frame->Show(TRUE);
  239.  
  240.     frame->SetStatusText(_T("Hello, wxWindows"));
  241.  
  242.     SetTopWindow(frame);
  243.  
  244.     return TRUE;
  245. }
  246.  
  247. void MyFrame::RecreateToolbar()
  248. {
  249.     // delete and recreate the toolbar
  250.     wxToolBarBase *toolBar = GetToolBar();
  251.     long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE;
  252.  
  253.     delete toolBar;
  254.  
  255.     SetToolBar(NULL);
  256.  
  257.     style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL);
  258.     style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL;
  259.  
  260.     toolBar = CreateToolBar(style, ID_TOOLBAR);
  261.  
  262.     // Set up toolbar
  263.     wxBitmap toolBarBitmaps[8];
  264.  
  265. #if USE_XPM_BITMAPS
  266.     toolBarBitmaps[0] = wxBitmap(new_xpm);
  267.     toolBarBitmaps[1] = wxBitmap(open_xpm);
  268.     toolBarBitmaps[2] = wxBitmap(save_xpm);
  269.     toolBarBitmaps[3] = wxBitmap(copy_xpm);
  270.     toolBarBitmaps[4] = wxBitmap(cut_xpm);
  271.     toolBarBitmaps[5] = wxBitmap(paste_xpm);
  272.     toolBarBitmaps[6] = wxBitmap(print_xpm);
  273.     toolBarBitmaps[7] = wxBitmap(help_xpm);
  274. #else // !USE_XPM_BITMAPS
  275.     toolBarBitmaps[0] = wxBITMAP(new);
  276.     toolBarBitmaps[1] = wxBITMAP(open);
  277.     toolBarBitmaps[2] = wxBITMAP(save);
  278.     toolBarBitmaps[3] = wxBITMAP(copy);
  279.     toolBarBitmaps[4] = wxBITMAP(cut);
  280.     toolBarBitmaps[5] = wxBITMAP(paste);
  281.     toolBarBitmaps[6] = wxBITMAP(print);
  282.     toolBarBitmaps[7] = wxBITMAP(help);
  283. #endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
  284.  
  285.     if ( !m_smallToolbar )
  286.     {
  287.         int w = 2*toolBarBitmaps[0].GetWidth(),
  288.             h = 2*toolBarBitmaps[0].GetHeight();
  289.         for ( size_t n = 0; n < WXSIZEOF(toolBarBitmaps); n++ )
  290.         {
  291.             toolBarBitmaps[n] =
  292.                 wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
  293.         }
  294.  
  295.         toolBar->SetToolBitmapSize(wxSize(w, h));
  296.     }
  297.  
  298.     toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file"));
  299.     toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file"));
  300.  
  301.     // neither the generic nor Motif native toolbars really support this
  302. #if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__) && !defined(__WXMAC__)
  303.     // adding a combo to a vertical toolbar is not very smart
  304.     if ( m_horzToolbar )
  305.     {
  306.         wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, _T(""), wxDefaultPosition, wxSize(200,-1) );
  307.         combo->Append(_T("This"));
  308.         combo->Append(_T("is a"));
  309.         combo->Append(_T("combobox"));
  310.         combo->Append(_T("in a"));
  311.         combo->Append(_T("toolbar"));
  312.         toolBar->AddControl(combo);
  313.     }
  314. #endif // toolbars which don't support controls
  315.  
  316.     toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[2], _T("Toggle button 1"), wxITEM_CHECK);
  317.     toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[3], _T("Toggle button 2"), wxITEM_CHECK);
  318.     toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[4], _T("Toggle/Untoggle help button"));
  319.     toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[5], _T("Paste"));
  320.     toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[6], _T("Delete this tool"));
  321.     toolBar->AddSeparator();
  322.     toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[7], _T("Help button"), wxITEM_CHECK);
  323.  
  324.     // after adding the buttons to the toolbar, must call Realize() to reflect
  325.     // the changes
  326.     toolBar->Realize();
  327.  
  328.     toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
  329. }
  330.  
  331. // ----------------------------------------------------------------------------
  332. // MyFrame
  333. // ----------------------------------------------------------------------------
  334.  
  335. // Define my frame constructor
  336. MyFrame::MyFrame(wxFrame* parent,
  337.                  wxWindowID id,
  338.                  const wxString& title,
  339.                  const wxPoint& pos,
  340.                  const wxSize& size,
  341.                  long style)
  342.        : wxFrame(parent, id, title, pos, size, style)
  343. {
  344.     m_tbar = NULL;
  345.     m_textWindow = new wxTextCtrl(this, -1, _T(""), wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
  346.  
  347.     m_smallToolbar = TRUE;
  348.     m_horzToolbar = TRUE;
  349.     m_rows = 1;
  350.     m_nPrint = 1;
  351.  
  352.     // Give it a status line
  353.     CreateStatusBar();
  354.  
  355.     // Give it an icon
  356.     SetIcon(wxICON(mondrian));
  357.  
  358.     // Make a menubar
  359.     wxMenu *tbarMenu = new wxMenu;
  360.     tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_TOOLBAR,
  361.                               _T("Toggle &toolbar\tCtrl-Z"),
  362.                               _T("Show or hide the toolbar"));
  363.  
  364.     tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
  365.                               _T("Toggle &another toolbar\tCtrl-A"),
  366.                               _T("Show/hide another test toolbar"));
  367.  
  368.     tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARSIZE,
  369.                               _T("&Toggle toolbar size\tCtrl-S"),
  370.                               _T("Toggle between big/small toolbar"));
  371.  
  372.     tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARORIENT,
  373.                               _T("Toggle toolbar &orientation\tCtrl-O"),
  374.                               _T("Toggle toolbar orientation"));
  375.  
  376.     tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLBARROWS,
  377.                               _T("Toggle number of &rows\tCtrl-R"),
  378.                               _T("Toggle number of toolbar rows between 1 and 2"));
  379.  
  380.     tbarMenu->AppendSeparator();
  381.  
  382.     tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, _T("&Enable print button\tCtrl-E"), _T(""));
  383.     tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, _T("&Delete print button\tCtrl-D"), _T(""));
  384.     tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, _T("&Insert print button\tCtrl-I"), _T(""));
  385.     tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, _T("Toggle &help button\tCtrl-T"), _T(""));
  386.     tbarMenu->AppendSeparator();
  387.     tbarMenu->Append(IDM_TOOLBAR_CHANGE_TOOLTIP, _T("Change tool tip"), _T(""));
  388.     tbarMenu->AppendSeparator();
  389.     tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_TEXT, _T("Show &text\tAlt-T"));
  390.     tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_ICONS, _T("Show &icons\tAlt-I"));
  391.     tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, _T("Show &both\tAlt-B"));
  392.  
  393.     wxMenu *fileMenu = new wxMenu;
  394.     fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit toolbar sample") );
  395.  
  396.     wxMenu *helpMenu = new wxMenu;
  397.     helpMenu->Append(wxID_HELP, _T("&About"), _T("About toolbar sample"));
  398.  
  399.     wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
  400.  
  401.     menuBar->Append(fileMenu, _T("&File"));
  402.     menuBar->Append(tbarMenu, _T("&Toolbar"));
  403.     menuBar->Append(helpMenu, _T("&Help"));
  404.  
  405.     // Associate the menu bar with the frame
  406.     SetMenuBar(menuBar);
  407.  
  408.     menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE);
  409.  
  410.     // Create the toolbar
  411.     RecreateToolbar();
  412. }
  413.  
  414. #if USE_GENERIC_TBAR
  415.  
  416. wxToolBar* MyFrame::OnCreateToolBar(long style,
  417.                                     wxWindowID id,
  418.                                     const wxString& name)
  419. {
  420.     return (wxToolBar *)new wxToolBarSimple(this, id,
  421.                                             wxDefaultPosition, wxDefaultSize,
  422.                                             style, name);
  423. }
  424.  
  425. #endif // USE_GENERIC_TBAR
  426.  
  427. void MyFrame::LayoutChildren()
  428. {
  429.     wxSize size = GetClientSize();
  430.  
  431.     int offset;
  432.     if ( m_tbar )
  433.     {
  434.         m_tbar->SetSize(-1, size.y);
  435.         m_tbar->Move(0, 0);
  436.  
  437.         offset = m_tbar->GetSize().x;
  438.     }
  439.     else
  440.     {
  441.         offset = 0;
  442.     }
  443.  
  444.     m_textWindow->SetSize(offset, 0, size.x - offset, size.y);
  445. }
  446.  
  447. void MyFrame::OnSize(wxSizeEvent& event)
  448. {
  449.     if ( m_tbar )
  450.     {
  451.         LayoutChildren();
  452.     }
  453.     else
  454.     {
  455.         event.Skip();
  456.     }
  457. }
  458.  
  459. void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
  460. {
  461.     wxToolBar *tbar = GetToolBar();
  462.  
  463.     if ( !tbar )
  464.     {
  465.         RecreateToolbar();
  466.     }
  467.     else
  468.     {
  469.         delete tbar;
  470.  
  471.         SetToolBar(NULL);
  472.     }
  473. }
  474.  
  475. void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
  476. {
  477.     if ( m_tbar )
  478.     {
  479.         delete m_tbar;
  480.         m_tbar = NULL;
  481.     }
  482.     else
  483.     {
  484.         long style = GetToolBar()->GetWindowStyle();
  485.         style &= ~wxTB_HORIZONTAL;
  486.         style |= wxTB_VERTICAL;
  487.  
  488.         m_tbar = new wxToolBar(this, -1,
  489.                                wxDefaultPosition, wxDefaultSize,
  490.                                style);
  491.  
  492.         m_tbar->SetMargins(4, 4);
  493.  
  494.         m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new));
  495.         m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open));
  496.         m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save));
  497.         m_tbar->AddSeparator();
  498.         m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help));
  499.  
  500.         m_tbar->Realize();
  501.     }
  502.  
  503.     LayoutChildren();
  504. }
  505.  
  506. void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
  507. {
  508.     m_smallToolbar = !m_smallToolbar;
  509.  
  510.     RecreateToolbar();
  511. }
  512.  
  513. void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
  514. {
  515.     // m_rows may be only 1 or 2
  516.     m_rows = 3 - m_rows;
  517.  
  518.     GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
  519.  
  520.     //RecreateToolbar(); -- this is unneeded
  521. }
  522.  
  523. void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
  524. {
  525.     m_horzToolbar = !m_horzToolbar;
  526.  
  527.     RecreateToolbar();
  528. }
  529.  
  530. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  531. {
  532.     Close(TRUE);
  533. }
  534.  
  535. void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
  536. {
  537.     (void)wxMessageBox(_T("wxWindows toolbar sample"), _T("About wxToolBar"));
  538. }
  539.  
  540. void MyFrame::OnToolLeftClick(wxCommandEvent& event)
  541. {
  542.     wxString str;
  543.     str.Printf( _T("Clicked on tool %d\n"), event.GetId());
  544.     m_textWindow->WriteText( str );
  545.  
  546.     if (event.GetId() == wxID_HELP)
  547.     {
  548.         if ( event.GetExtraLong() != 0 )
  549.             m_textWindow->WriteText( _T("Help button down now.\n") );
  550.         else
  551.             m_textWindow->WriteText( _T("Help button up now.\n") );
  552.     }
  553.  
  554.     if (event.GetId() == wxID_COPY)
  555.     {
  556.         DoEnablePrint();
  557.     }
  558.  
  559.     if (event.GetId() == wxID_CUT)
  560.     {
  561.         DoToggleHelp();
  562.     }
  563.  
  564.     if (event.GetId() == wxID_PRINT)
  565.     {
  566.         DoDeletePrint();
  567.     }
  568. }
  569.  
  570. void MyFrame::OnCombo(wxCommandEvent& event)
  571. {
  572.     wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str());
  573. }
  574.  
  575. void MyFrame::DoEnablePrint()
  576. {
  577.     if ( !m_nPrint )
  578.         return;
  579.  
  580.     wxToolBarBase *tb = GetToolBar();
  581.     tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT));
  582. }
  583.  
  584. void MyFrame::DoDeletePrint()
  585. {
  586.     if ( !m_nPrint )
  587.         return;
  588.  
  589.     wxToolBarBase *tb = GetToolBar();
  590.     tb->DeleteTool( wxID_PRINT );
  591.  
  592.     m_nPrint--;
  593. }
  594.  
  595. void MyFrame::DoToggleHelp()
  596. {
  597.     wxToolBarBase *tb = GetToolBar();
  598.     tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
  599. }
  600.  
  601. void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
  602. {
  603.     event.Enable( m_textWindow->CanCopy() );
  604. }
  605.  
  606. void MyFrame::OnChangeToolTip(wxCommandEvent& WXUNUSED(event))
  607. {
  608.     GetToolBar()->SetToolShortHelp(wxID_NEW, _T("New toolbar button"));
  609. }
  610.  
  611. void MyFrame::OnToolbarStyle(wxCommandEvent& event)
  612. {
  613.     long style = GetToolBar()->GetWindowStyle();
  614.     style &= ~(wxTB_NOICONS | wxTB_TEXT);
  615.  
  616.     switch ( event.GetId() )
  617.     {
  618.         case IDM_TOOLBAR_SHOW_TEXT:
  619.             style |= wxTB_NOICONS | wxTB_TEXT;
  620.             break;
  621.  
  622.         case IDM_TOOLBAR_SHOW_ICONS:
  623.             // nothing to do
  624.             break;
  625.  
  626.         case IDM_TOOLBAR_SHOW_BOTH:
  627.             style |= wxTB_TEXT;
  628.     }
  629.  
  630.     GetToolBar()->SetWindowStyle(style);
  631. }
  632.  
  633. void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
  634. {
  635.     m_nPrint++;
  636.  
  637.     wxToolBarBase *tb = GetToolBar();
  638.     tb->InsertTool(0, wxID_PRINT, _T("New print"),
  639.                    wxBITMAP(print), wxNullBitmap,
  640.                    wxITEM_NORMAL,
  641.                    _T("Delete this tool"),
  642.                    _T("This button was inserted into the toolbar"));
  643.  
  644.     // must call Realize() after adding a new button
  645.     tb->Realize();
  646. }
  647.  
  648. void MyFrame::OnToolEnter(wxCommandEvent& event)
  649. {
  650.     if (event.GetSelection() > -1)
  651.     {
  652.         wxString str;
  653.         str.Printf(_T("This is tool number %d"), event.GetSelection());
  654.         SetStatusText(str);
  655.     }
  656.     else
  657.         SetStatusText(_T(""));
  658. }
  659.  
  660.