const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE);
- virtual ~MyFrame() { delete m_menu; }
-
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnToolLeftClick(wxCommandEvent& event);
void OnToolEnter(wxCommandEvent& event);
+ void OnCombo(wxCommandEvent& event);
+
private:
void DoEnablePrint();
void DoToggleHelp();
bool m_smallToolbar;
wxTextCtrl* m_textWindow;
- wxMenu *m_menu;
-
DECLARE_EVENT_TABLE()
};
IDM_TOOLBAR_TOGGLETOOLBAR = 200,
IDM_TOOLBAR_ENABLEPRINT,
IDM_TOOLBAR_TOGGLEHELP,
- IDM_MENU_TOGGLE,
- IDM_MENU_APPEND,
- IDM_MENU_DELETE
+
+ ID_COMBO = 1000
};
// ----------------------------------------------------------------------------
EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
- EVT_MENU(IDM_MENU_TOGGLE, MyFrame::OnToggleMenu)
- EVT_MENU(IDM_MENU_APPEND, MyFrame::OnAppendMenu)
- EVT_MENU(IDM_MENU_DELETE, MyFrame::OnDeleteMenu)
-
EVT_MENU(-1, MyFrame::OnToolLeftClick)
+ EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
+
EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
END_EVENT_TABLE()
toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file");
currentX += width + 5;
toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1");
+
+ toolBar->AddSeparator();
+
+ wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO);
+ combo->Append("This");
+ combo->Append("is a");
+ combo->Append("combobox");
+ combo->Append("in a");
+ combo->Append("toolbar");
+ toolBar->AddControl(combo);
if ( !smallicons )
{
currentX += width + 5;
- toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Save file");
- currentX += width + 5;
- toolBar->AddSeparator();
- toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Disable/Enable print button");
+ 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_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print");
currentX += width + 5;
toolBar->AddSeparator();
- toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), *(toolBarBitmaps[6]), TRUE, currentX, -1, (wxObject *) NULL, "Help");
+ toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button");
+ toolBar->ToggleTool( wxID_SAVE, TRUE );
+ toolBar->ToggleTool( wxID_COPY, TRUE );
+ toolBar->ToggleTool( wxID_COPY, FALSE );
toolBar->EnableTool( wxID_PRINT, FALSE );
}
toolBar->Realize();
// Can delete the bitmaps since they're reference counted
- int i, max = smallicons ? 2 : WXSIZEOF(toolBarBitmaps);
+ int i, max = smallicons ? 3 : WXSIZEOF(toolBarBitmaps);
for (i = 0; i < max; i++)
delete toolBarBitmaps[i];
long style)
: wxFrame(parent, id, title, pos, size, style)
{
- m_menu = NULL;
m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
m_smallToolbar = FALSE;
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
- wxMenu *menuMenu = new wxMenu;
- menuMenu->Append(IDM_MENU_APPEND, "&Append menu");
- menuMenu->Append(IDM_MENU_DELETE, "&Delete menu");
- menuMenu->Append(IDM_MENU_TOGGLE, "&Toggle menu", "", TRUE);
-
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
menuBar->Append(fileMenu, "&File");
menuBar->Append(tbarMenu, "&Toolbar");
- menuBar->Append(menuMenu, "&Menubar");
menuBar->Append(helpMenu, "&Help");
// Associate the menu bar with the frame
(void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
}
-void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
-{
- wxMenuBar *mbar = GetMenuBar();
-
- size_t count = mbar->GetMenuCount();
- if ( count == 3 )
- {
- // don't let delete the first 3 menus
- wxLogError("Can't delete any more menus");
- }
- else
- {
- delete mbar->Remove(count - 1);
- }
-}
-
-void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
-{
- static s_count = 0;
-
- wxMenu *menu = new wxMenu;
- menu->Append(0, "First item");
- menu->AppendSeparator();
- menu->Append(0, "Second item");
-
- wxString title;
- title.Printf("Dummy menu &%d", ++s_count);
-
- GetMenuBar()->Append(menu, title);
-}
-
-void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event))
-{
- wxMenuBar *mbar = GetMenuBar();
- if ( !m_menu )
- {
- // hide the menu
- m_menu = mbar->Remove(1);
- }
- else
- {
- // restore it
- mbar->Insert(1, m_menu, "&Toolbar");
- m_menu = NULL;
- }
-}
-
void MyFrame::OnToolLeftClick(wxCommandEvent& event)
{
wxString str;
}
}
+void MyFrame::OnCombo(wxCommandEvent& event)
+{
+ wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str());
+}
+
void MyFrame::DoEnablePrint()
{
wxToolBar *tb = GetToolBar();