- int currentX = 5;
-
- 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");
-
- 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, 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");
- }
-
- toolBar->Realize();
-
- // Can delete the bitmaps since they're reference counted
- int i, max = smallicons ? 2 : WXSIZEOF(toolBarBitmaps);
- for (i = 0; i < max; i++)
- delete toolBarBitmaps[i];
-
- return TRUE;
+
+ PopulateToolbar(toolBar);
+}
+
+void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
+{
+ // Set up toolbar
+ enum
+ {
+ Tool_new,
+ Tool_open,
+ Tool_save,
+ Tool_copy,
+ Tool_cut,
+ Tool_paste,
+ Tool_print,
+ Tool_help,
+ Tool_Max
+ };
+
+ wxBitmap toolBarBitmaps[Tool_Max];
+
+#if USE_XPM_BITMAPS
+ #define INIT_TOOL_BMP(bmp) \
+ toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
+#else // !USE_XPM_BITMAPS
+ #define INIT_TOOL_BMP(bmp) \
+ toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
+#endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS
+
+ INIT_TOOL_BMP(new);
+ INIT_TOOL_BMP(open);
+ INIT_TOOL_BMP(save);
+ INIT_TOOL_BMP(copy);
+ INIT_TOOL_BMP(cut);
+ INIT_TOOL_BMP(paste);
+ INIT_TOOL_BMP(print);
+ INIT_TOOL_BMP(help);
+
+ int w = toolBarBitmaps[Tool_new].GetWidth(),
+ h = toolBarBitmaps[Tool_new].GetHeight();
+
+ if ( !m_smallToolbar )
+ {
+ w *= 2;
+ h *= 2;
+
+ for ( size_t n = Tool_new; n < WXSIZEOF(toolBarBitmaps); n++ )
+ {
+ toolBarBitmaps[n] =
+ wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
+ }
+ }
+
+ toolBar->SetToolBitmapSize(wxSize(w, h));
+
+ toolBar->AddTool(wxID_NEW, _T("New"),
+ toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN,
+ _T("New file"), _T("This is help for new file tool"));
+
+ wxMenu* menu = new wxMenu;
+ menu->Append(wxID_ANY, _T("&First dummy item"));
+ menu->Append(wxID_ANY, _T("&Second dummy item"));
+ menu->AppendSeparator();
+ menu->Append(wxID_EXIT, _T("Exit"));
+ toolBar->SetDropdownMenu(wxID_NEW, menu);
+
+ toolBar->AddTool(wxID_OPEN, _T("Open"),
+ toolBarBitmaps[Tool_open], wxNullBitmap, wxITEM_NORMAL,
+ _T("Open file"), _T("This is help for open file tool"));
+
+#if USE_CONTROLS_IN_TOOLBAR
+ // adding a combo to a vertical toolbar is not very smart
+ if ( !toolBar->IsVertical() )
+ {
+ wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
+ combo->Append(_T("This"));
+ combo->Append(_T("is a"));
+ combo->Append(_T("combobox"));
+ combo->Append(_T("in a"));
+ combo->Append(_T("toolbar"));
+ toolBar->AddControl(combo, _T("Combo Label"));
+ }
+#endif // USE_CONTROLS_IN_TOOLBAR
+
+ toolBar->AddTool(wxID_SAVE, _T("Save"), toolBarBitmaps[Tool_save], _T("Toggle button 1"), wxITEM_CHECK);
+ toolBar->AddTool(wxID_COPY, _T("Copy"), toolBarBitmaps[Tool_copy], _T("Toggle button 2"), wxITEM_CHECK);
+ toolBar->AddTool(wxID_CUT, _T("Cut"), toolBarBitmaps[Tool_cut], _T("Toggle/Untoggle help button"));
+ toolBar->AddTool(wxID_PASTE, _T("Paste"), toolBarBitmaps[Tool_paste], _T("Paste"));
+
+ if ( m_useCustomDisabled )
+ {
+ wxBitmap bmpDisabled(w, h);
+ {
+ wxMemoryDC dc;
+ dc.SelectObject(bmpDisabled);
+ dc.DrawBitmap(toolBarBitmaps[Tool_print], 0, 0);
+
+ wxPen pen(*wxRED, 5);
+ dc.SetPen(pen);
+ dc.DrawLine(0, 0, w, h);
+ }
+
+ toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[Tool_print],
+ bmpDisabled);
+ }
+ else
+ {
+ toolBar->AddTool(wxID_PRINT, _T("Print"), toolBarBitmaps[Tool_print],
+ _T("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();
+ toolBar->AddTool(wxID_HELP, _T("Help"), toolBarBitmaps[Tool_help], _T("Help button"), wxITEM_CHECK);
+
+ if ( !m_pathBmp.empty() )
+ {
+ // create a tool with a custom bitmap for testing
+ wxImage img(m_pathBmp);
+ if ( img.Ok() )
+ {
+ if ( img.GetWidth() > w && img.GetHeight() > h )
+ img = img.GetSubImage(wxRect(0, 0, w, h));
+
+ toolBar->AddSeparator();
+ toolBar->AddTool(wxID_ANY, _T("Custom"), img);
+ }
+ }
+
+ // after adding the buttons to the toolbar, must call Realize() to reflect
+ // the changes
+ toolBar->Realize();
+
+ toolBar->SetRows(!(toolBar->IsVertical()) ? m_rows : 10 / m_rows);