+public:
+ wxToolBarTool(wxToolBar *tbar,
+ int id,
+ const wxString& label,
+ const wxBitmap& bitmap1,
+ const wxBitmap& bitmap2,
+ wxItemKind kind,
+ wxObject *clientData,
+ const wxString& shortHelpString,
+ const wxString& longHelpString)
+ : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
+ clientData, shortHelpString, longHelpString)
+ {
+ Init();
+ }
+
+ wxToolBarTool(wxToolBar *tbar, wxControl *control)
+ : wxToolBarToolBase(tbar, control)
+ {
+ Init();
+ }
+
+ // is this a radio button?
+ //
+ // unlike GetKind(), can be called for any kind of tools, not just buttons
+ bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; }
+
+ // this is only called for the normal buttons, i.e. not separators nor
+ // controls
+ GtkToolbarChildType GetGtkChildType() const
+ {
+ switch ( GetKind() )
+ {
+ case wxITEM_CHECK:
+ return GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
+
+ case wxITEM_RADIO:
+ return GTK_TOOLBAR_CHILD_RADIOBUTTON;
+
+ default:
+ wxFAIL_MSG( _T("unknown toolbar child type") );
+ // fall through
+
+ case wxITEM_NORMAL:
+ return GTK_TOOLBAR_CHILD_BUTTON;
+ }
+ }
+
+ void SetPixmap(const wxBitmap& bitmap)
+ {
+ if (bitmap.Ok())
+ {
+ GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
+ : (GdkBitmap *)NULL;
+#ifdef __WXGTK20__
+ if (bitmap.HasPixbuf())
+ gtk_image_set_from_pixbuf( GTK_IMAGE(m_pixmap), bitmap.GetPixbuf() );
+ else
+#endif // !__WXGTK20__
+ gtk_pixmap_set( GTK_PIXMAP(m_pixmap), bitmap.GetPixmap(), mask );
+ }
+ }
+
+ GtkWidget *m_item;
+ GtkWidget *m_pixmap;
+
+protected:
+ void Init();
+};
+
+// ----------------------------------------------------------------------------
+// wxWin macros
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+//-----------------------------------------------------------------------------
+// "clicked" (internal from gtk_toolbar)
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
+ wxToolBarTool *tool )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
+
+ if (tbar->m_blockEvent) return;
+
+ if (g_blockEventsOnDrag) return;
+ if (!tool->IsEnabled()) return;
+
+ if (tool->CanBeToggled())
+ {
+ tool->Toggle();
+
+ tool->SetPixmap(tool->GetBitmap());
+
+ if ( tool->IsRadio() && !tool->IsToggled() )
+ {
+ // radio button went up, don't report this as a wxWin event
+ return;
+ }
+ }
+
+ if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() )
+ {
+ // revert back
+ tool->Toggle();
+
+ tool->SetPixmap(tool->GetBitmap());
+ }
+}