static void GetGtkStyle(long style,
GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
{
- *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
- : GTK_ORIENTATION_HORIZONTAL;
+ *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
if ( style & wxTB_TEXT )
Init();
}
- wxToolBarTool(wxToolBar *tbar, wxControl *control)
- : wxToolBarToolBase(tbar, control)
+ wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
+ : wxToolBarToolBase(tbar, control, label)
{
Init();
}
}
}
- void SetPixmap(const wxBitmap& bitmap)
+ void SetImage(const wxBitmap& bitmap)
{
if (bitmap.Ok())
{
- GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
- : (GdkBitmap *)NULL;
- if (bitmap.HasPixbuf())
- gtk_image_set_from_pixbuf( GTK_IMAGE(m_pixmap), bitmap.GetPixbuf() );
- else
- gtk_pixmap_set( GTK_PIXMAP(m_pixmap), bitmap.GetPixmap(), mask );
+ // setting from pixmap doesn't seem to work right, but pixbuf works well
+ gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
}
}
GtkWidget *m_item;
- GtkWidget *m_pixmap;
+ GtkWidget *m_image;
protected:
void Init();
{
tool->Toggle();
- tool->SetPixmap(tool->GetBitmap());
+ tool->SetImage(tool->GetBitmap());
if ( tool->IsRadio() && !tool->IsToggled() )
{
// revert back
tool->Toggle();
- tool->SetPixmap(tool->GetBitmap());
+ tool->SetImage(tool->GetBitmap());
}
}
}
GdkEventCrossing *gdk_event,
wxToolBarTool *tool )
{
- if (g_isIdle) wxapp_install_idle_handler();
+ // don't need to install idle handler, its done from "event" signal
if (g_blockEventsOnDrag) return TRUE;
}
}
+extern "C" {
+static
+void gtktoolwidget_size_callback( GtkWidget *widget,
+ GtkAllocation *alloc,
+ wxWindow *win )
+{
+ // this shouldn't happen...
+ if (win->GetParent()->m_wxwindow) return;
+
+ wxSize size = win->GetEffectiveMinSize();
+ if (size.y != alloc->height)
+ {
+ GtkAllocation alloc2;
+ alloc2.x = alloc->x;
+ alloc2.y = (alloc->height - size.y + 3) / 2;
+ alloc2.width = alloc->width;
+ alloc2.height = size.y;
+ gtk_widget_size_allocate( widget, &alloc2 );
+ }
+}
+}
//-----------------------------------------------------------------------------
// InsertChild callback for wxToolBar
//-----------------------------------------------------------------------------
void wxToolBarTool::Init()
{
m_item =
- m_pixmap = (GtkWidget *)NULL;
+ m_image = NULL;
}
wxToolBarToolBase *wxToolBar::CreateTool(int id,
clientData, shortHelpString, longHelpString);
}
-wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
+wxToolBarToolBase *
+wxToolBar::CreateTool(wxControl *control, const wxString& label)
{
- return new wxToolBarTool(this, control);
+ return new wxToolBarTool(this, control, label);
}
//-----------------------------------------------------------------------------
return false;
}
+ FixupStyle();
+
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
GtkSetStyle();
return true;
}
+GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const
+{
+ return GTK_WIDGET(m_toolbar)->window;
+}
+
void wxToolBar::GtkSetStyle()
{
GtkOrientation orient;
gtk_toolbar_set_orientation(m_toolbar, orient);
gtk_toolbar_set_style(m_toolbar, style);
- gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), !(style & wxTB_NO_TOOLTIPS) );
+ gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
}
void wxToolBar::SetWindowStyleFlag( long style )
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
{
- wxToolBarTool *tool = (wxToolBarTool *)toolBase;
-
- size_t posGtk = pos;
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
if ( tool->IsButton() )
{
wxCHECK_MSG( bitmap.Ok(), false,
wxT("invalid bitmap for wxToolBar icon") );
- wxCHECK_MSG( bitmap.GetDepth() != 1, false,
- wxT("wxToolBar doesn't support GdkBitmap") );
-
- wxCHECK_MSG( bitmap.GetPixmap() != NULL, false,
- wxT("wxToolBar::Add needs a wxBitmap") );
-
- GtkWidget *tool_pixmap = (GtkWidget *)NULL;
-
-
- if (bitmap.HasPixbuf())
- {
- tool_pixmap = gtk_image_new();
- tool->m_pixmap = tool_pixmap;
- tool->SetPixmap(bitmap);
- }
- else
- {
- GdkPixmap *pixmap = bitmap.GetPixmap();
-
- GdkBitmap *mask = (GdkBitmap *)NULL;
- if ( bitmap.GetMask() )
- mask = bitmap.GetMask()->GetBitmap();
-
- tool_pixmap = gtk_pixmap_new( pixmap, mask );
- gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
- }
-
- gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
+ tool->m_image = gtk_image_new();
+ tool->SetImage(bitmap);
- tool->m_pixmap = tool_pixmap;
+ gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
}
}
+ const int posGtk = int(pos);
+
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_BUTTON:
? NULL
: (const char*) wxGTK_CONV( tool->GetShortHelp() ),
"", // tooltip_private_text (?)
- tool->m_pixmap,
+ tool->m_image,
(GtkSignalFunc)gtk_toolbar_callback,
(gpointer)tool,
posGtk
);
- if ( !tool->m_item )
- {
- wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
-
- return false;
- }
+ wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
g_signal_connect (tool->m_item, "enter_notify_event",
G_CALLBACK (gtk_toolbar_tool_callback),
(const char *) NULL,
posGtk
);
+
+ // connect after in order to correct size_allocate events
+ g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate",
+ G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl());
+
break;
}
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
{
- wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
switch ( tool->GetStyle() )
{
void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
{
- wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
if (tool->m_item)
{
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
{
- wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
GtkWidget *item = tool->m_item;
if ( item && GTK_IS_TOGGLE_BUTTON(item) )
{
- tool->SetPixmap(tool->GetBitmap());
+ tool->SetImage(tool->GetBitmap());
m_blockEvent = true;
void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
{
- wxToolBarTool *tool = (wxToolBarTool *)FindById(id);
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
if ( tool )
{
}
}
+void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
+{
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ if ( tool )
+ {
+ wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
+
+ tool->SetNormalBitmap(bitmap);
+ tool->SetImage(tool->GetBitmap());
+ }
+}
+
+void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
+{
+ wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ if ( tool )
+ {
+ wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
+
+ tool->SetDisabledBitmap(bitmap);
+ tool->SetImage(tool->GetBitmap());
+ }
+}
+
// ----------------------------------------------------------------------------
// wxToolBar idle handling
// ----------------------------------------------------------------------------
{
// Check if we have to show window now
if (GtkShowFromOnIdle()) return;
-
+
wxCursor cursor = m_cursor;
if (g_globalCursor.Ok()) cursor = g_globalCursor;