- 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));
+ }
+ }
+
+ // this call is actually unnecessary as the toolbar will adjust its tools
+ // size to fit the biggest icon used anyhow but it doesn't hurt neither
+ toolBar->SetToolBitmapSize(wxSize(w, h));
+
+ toolBar->AddTool(wxID_NEW, wxT("New"),
+ toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_DROPDOWN,
+ wxT("New file"), wxT("This is help for new file tool"));
+
+ wxMenu* menu = new wxMenu;
+ menu->Append(wxID_ANY, wxT("&First dummy item"));
+ menu->Append(wxID_ANY, wxT("&Second dummy item"));
+ menu->AppendSeparator();
+ menu->Append(wxID_EXIT, wxT("Exit"));
+ toolBar->SetDropdownMenu(wxID_NEW, menu);
+
+ toolBar->AddTool(wxID_OPEN, wxT("Open"),
+ toolBarBitmaps[Tool_open], wxNullBitmap, wxITEM_NORMAL,
+ wxT("Open file"), wxT("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(wxT("This"));
+ combo->Append(wxT("is a"));
+ combo->Append(wxT("combobox"));
+ combo->Append(wxT("in a"));
+ combo->Append(wxT("toolbar"));
+ toolBar->AddControl(combo, wxT("Combo Label"));
+ }
+#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->AddSeparator();
+
+ 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, wxT("Print"), toolBarBitmaps[Tool_print],
+ bmpDisabled);
+ }
+ else
+ {
+ toolBar->AddTool(wxID_PRINT, wxT("Print"), toolBarBitmaps[Tool_print],
+ 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."));
+ }
+
+ // 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() )
+ {
+ // create a tool with a custom bitmap for testing
+ wxImage img(m_pathBmp);
+ if ( img.IsOk() )
+ {
+ if ( img.GetWidth() > w && img.GetHeight() > h )
+ img = img.GetSubImage(wxRect(0, 0, w, h));
+
+ toolBar->AddSeparator();
+ toolBar->AddTool(wxID_ANY, wxT("Custom"), img);
+ }
+ }
+
+ // after adding the buttons to the toolbar, must call Realize() to reflect
+ // the changes
+ toolBar->Realize();
+
+ toolBar->SetRows(toolBar->IsVertical() ? toolBar->GetToolsCount() / m_rows
+ : m_rows);