use "new" GtkToolbar API
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54995 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,15 +37,11 @@ public:
|
|||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = 0,
|
long style = wxTB_HORIZONTAL,
|
||||||
const wxString& name = wxToolBarNameStr );
|
const wxString& name = wxToolBarNameStr );
|
||||||
|
|
||||||
virtual ~wxToolBar();
|
virtual ~wxToolBar();
|
||||||
|
|
||||||
// override base class virtuals
|
|
||||||
virtual void SetMargins(int x, int y);
|
|
||||||
virtual void SetToolSeparation(int separation);
|
|
||||||
|
|
||||||
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
|
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
|
||||||
|
|
||||||
virtual void SetToolShortHelp(int id, const wxString& helpString);
|
virtual void SetToolShortHelp(int id, const wxString& helpString);
|
||||||
@@ -61,19 +57,10 @@ public:
|
|||||||
// implementation from now on
|
// implementation from now on
|
||||||
// --------------------------
|
// --------------------------
|
||||||
|
|
||||||
GtkToolbar *m_toolbar;
|
|
||||||
|
|
||||||
bool m_blockEvent;
|
|
||||||
|
|
||||||
void OnInternalIdle();
|
void OnInternalIdle();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
virtual wxSize DoGetBestSize() const;
|
||||||
void Init();
|
|
||||||
|
|
||||||
// set the GTK toolbar style and orientation
|
|
||||||
void GtkSetStyle();
|
|
||||||
|
|
||||||
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
|
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
@@ -96,6 +83,13 @@ protected:
|
|||||||
const wxString& label);
|
const wxString& label);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Init();
|
||||||
|
void GtkSetStyle();
|
||||||
|
GSList* GetRadioGroup(size_t pos);
|
||||||
|
|
||||||
|
GtkToolbar* m_toolbar;
|
||||||
|
GtkTooltips* m_tooltips;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -15,33 +15,8 @@
|
|||||||
|
|
||||||
#include "wx/toolbar.h"
|
#include "wx/toolbar.h"
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
|
||||||
#include "wx/menu.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// FIXME: Use GtkImage instead of GtkPixmap. Use the new toolbar API for when gtk runtime is new enough?
|
|
||||||
// Beware that the new and old toolbar API may not be mixed in usage.
|
|
||||||
#undef GTK_DISABLE_DEPRECATED
|
|
||||||
|
|
||||||
#include "wx/gtk/private.h"
|
#include "wx/gtk/private.h"
|
||||||
|
|
||||||
/* XPM */
|
|
||||||
static const char *arrow_down_xpm[] = {
|
|
||||||
/* columns rows colors chars-per-pixel */
|
|
||||||
"7 7 2 1",
|
|
||||||
" c None",
|
|
||||||
". c Black",
|
|
||||||
/* pixels */
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
".......",
|
|
||||||
" ..... ",
|
|
||||||
" ... ",
|
|
||||||
" . "
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// globals
|
// globals
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -50,31 +25,6 @@ static const char *arrow_down_xpm[] = {
|
|||||||
extern bool g_blockEventsOnDrag;
|
extern bool g_blockEventsOnDrag;
|
||||||
extern wxCursor g_globalCursor;
|
extern wxCursor g_globalCursor;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// private functions
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// translate wxWidgets toolbar style flags to GTK orientation and style
|
|
||||||
static void GetGtkStyle(long style,
|
|
||||||
GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
|
|
||||||
{
|
|
||||||
*orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
|
|
||||||
|
|
||||||
|
|
||||||
if ( style & wxTB_TEXT )
|
|
||||||
{
|
|
||||||
*gtkStyle = style & wxTB_NOICONS
|
|
||||||
? GTK_TOOLBAR_TEXT
|
|
||||||
: (
|
|
||||||
style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ :
|
|
||||||
GTK_TOOLBAR_BOTH);
|
|
||||||
}
|
|
||||||
else // no text, hence we must have the icons or what would we show?
|
|
||||||
{
|
|
||||||
*gtkStyle = GTK_TOOLBAR_ICONS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxToolBarTool
|
// wxToolBarTool
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -94,13 +44,13 @@ public:
|
|||||||
: wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
|
: wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
|
||||||
clientData, shortHelpString, longHelpString)
|
clientData, shortHelpString, longHelpString)
|
||||||
{
|
{
|
||||||
Init();
|
m_item = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
|
wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
|
||||||
: wxToolBarToolBase(tbar, control, label)
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
Init();
|
m_item = NULL;
|
||||||
// Hold a reference to keep control alive until DoInsertTool() is
|
// Hold a reference to keep control alive until DoInsertTool() is
|
||||||
// called, or if RemoveTool() is called (see DoDeleteTool)
|
// called, or if RemoveTool() is called (see DoDeleteTool)
|
||||||
g_object_ref(control->m_widget);
|
g_object_ref(control->m_widget);
|
||||||
@@ -109,53 +59,11 @@ public:
|
|||||||
control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
|
control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a radio button?
|
void SetImage();
|
||||||
//
|
void CreateDropDown();
|
||||||
// unlike GetKind(), can be called for any kind of tools, not just buttons
|
void ShowDropdown(GtkToggleButton* button);
|
||||||
bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; }
|
|
||||||
|
|
||||||
// this is only called for the normal buttons, i.e. not separators nor
|
GtkToolItem* m_item;
|
||||||
// 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_DROPDOWN:
|
|
||||||
case wxITEM_NORMAL:
|
|
||||||
return GTK_TOOLBAR_CHILD_BUTTON;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetImage(const wxBitmap& bitmap)
|
|
||||||
{
|
|
||||||
if (bitmap.Ok())
|
|
||||||
{
|
|
||||||
// setting from pixmap doesn't seem to work right, but pixbuf works well
|
|
||||||
gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the toolbar element for button tools or a GtkAlignment containing the
|
|
||||||
// control for control tools
|
|
||||||
GtkWidget *m_item;
|
|
||||||
// dropdown element for button tools
|
|
||||||
GtkWidget *m_itemDropdown;
|
|
||||||
|
|
||||||
// a GtkImage containing the image for a button-type tool, may be NULL
|
|
||||||
GtkWidget *m_image;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void Init();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -169,169 +77,98 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// "clicked" (internal from gtk_toolbar)
|
// "clicked" from m_item
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static void gtk_toolbar_callback( GtkWidget *widget,
|
static void item_clicked(GtkToolButton*, wxToolBarTool* tool)
|
||||||
wxToolBarTool *tool )
|
|
||||||
{
|
{
|
||||||
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
|
|
||||||
|
|
||||||
if (tbar->m_blockEvent) return;
|
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) return;
|
if (g_blockEventsOnDrag) return;
|
||||||
if (!tool->IsEnabled()) return;
|
|
||||||
|
|
||||||
if (tool->CanBeToggled())
|
tool->GetToolBar()->OnLeftClick(tool->GetId(), false);
|
||||||
{
|
}
|
||||||
if (tool->IsRadio() &&
|
}
|
||||||
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget)) &&
|
|
||||||
tool->IsToggled())
|
//-----------------------------------------------------------------------------
|
||||||
{
|
// "toggled" from m_item
|
||||||
// pressed an already pressed radio button
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static void item_toggled(GtkToggleToolButton* button, wxToolBarTool* tool)
|
||||||
|
{
|
||||||
|
if (g_blockEventsOnDrag) return;
|
||||||
|
|
||||||
|
const bool active = gtk_toggle_tool_button_get_active(button) != 0;
|
||||||
|
tool->Toggle(active);
|
||||||
|
if (!active && tool->GetKind() == wxITEM_RADIO)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
tool->Toggle();
|
if (!tool->GetToolBar()->OnLeftClick(tool->GetId(), active))
|
||||||
|
|
||||||
tool->SetImage(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
|
// revert back
|
||||||
tool->Toggle();
|
tool->Toggle();
|
||||||
|
|
||||||
tool->SetImage(tool->GetBitmap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// "right-click"
|
// "button_press_event" from m_item child
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static gboolean gtk_toolbar_tool_rclick_callback(GtkWidget *WXUNUSED(widget),
|
static gboolean
|
||||||
GdkEventButton *event,
|
button_press_event(GtkWidget*, GdkEventButton* event, wxToolBarTool* tool)
|
||||||
wxToolBarToolBase *tool)
|
|
||||||
{
|
{
|
||||||
if (event->button != 3)
|
if (event->button != 3)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
|
|
||||||
|
|
||||||
if (tbar->m_blockEvent) return TRUE;
|
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) return TRUE;
|
if (g_blockEventsOnDrag) return TRUE;
|
||||||
if (!tool->IsEnabled()) return TRUE;
|
|
||||||
|
|
||||||
tbar->OnRightClick( tool->GetId(), (int)event->x, (int)event->y );
|
tool->GetToolBar()->OnRightClick(
|
||||||
|
tool->GetId(), int(event->x), int(event->y));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// "enter_notify_event" / "leave_notify_event" from dropdown
|
// "child_detached" from m_widget
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static gint gtk_toolbar_buddy_enter_callback( GtkWidget *WXUNUSED(widget),
|
static void child_detached(GtkWidget*, GtkToolbar* toolbar, void*)
|
||||||
GdkEventCrossing *WXUNUSED(gdk_event),
|
|
||||||
GtkWidget *tool )
|
|
||||||
{
|
{
|
||||||
guint8 state = GTK_WIDGET_STATE( tool );
|
// disable showing overflow arrow when toolbar is detached,
|
||||||
state |= GTK_STATE_PRELIGHT;
|
// otherwise toolbar collapses to just an arrow
|
||||||
gtk_widget_set_state( tool, (GtkStateType) state );
|
gtk_toolbar_set_show_arrow(toolbar, false);
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint gtk_toolbar_buddy_leave_callback( GtkWidget *WXUNUSED(widget),
|
|
||||||
GdkEventCrossing *WXUNUSED(gdk_event),
|
|
||||||
GtkWidget *tool )
|
|
||||||
{
|
|
||||||
guint8 state = GTK_WIDGET_STATE( tool );
|
|
||||||
state &= ~GTK_STATE_PRELIGHT;
|
|
||||||
gtk_widget_set_state( tool, (GtkStateType) state );
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// "left-click" on dropdown
|
// "child_attached" from m_widget
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
static void gtk_pop_tb_hide_callback( GtkWidget *WXUNUSED(menu), GtkToggleButton *button )
|
|
||||||
{
|
|
||||||
gtk_toggle_button_set_active( button, FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean gtk_toolbar_dropdown_lclick_callback(GtkWidget *widget,
|
|
||||||
GdkEventButton *event,
|
|
||||||
wxToolBarToolBase *tool)
|
|
||||||
{
|
|
||||||
if (event->button != 1)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
|
|
||||||
|
|
||||||
if (tbar->m_blockEvent) return FALSE;
|
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) return FALSE;
|
|
||||||
if (!tool->IsEnabled()) return FALSE;
|
|
||||||
|
|
||||||
wxCommandEvent evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, tool->GetId() );
|
|
||||||
if ( tbar->HandleWindowEvent(evt) )
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMenu * const menu = tool->GetDropdownMenu();
|
|
||||||
if (!menu)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
// simulate press
|
|
||||||
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(widget), TRUE );
|
|
||||||
|
|
||||||
g_signal_connect (menu->m_menu, "hide",
|
|
||||||
G_CALLBACK (gtk_pop_tb_hide_callback),
|
|
||||||
widget);
|
|
||||||
|
|
||||||
tbar->PopupMenu( menu, widget->allocation.x,
|
|
||||||
widget->allocation.y + widget->allocation.height );
|
|
||||||
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// "enter_notify_event" / "leave_notify_event"
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
|
static void child_attached(GtkWidget*, GtkToolbar* toolbar, void*)
|
||||||
GdkEventCrossing *gdk_event,
|
{
|
||||||
wxToolBarTool *tool )
|
gtk_toolbar_set_show_arrow(toolbar, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// "enter_notify_event" / "leave_notify_event" from m_item
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static gboolean
|
||||||
|
enter_notify_event(GtkWidget*, GdkEventCrossing* event, wxToolBarTool* tool)
|
||||||
{
|
{
|
||||||
if (g_blockEventsOnDrag) return TRUE;
|
if (g_blockEventsOnDrag) return TRUE;
|
||||||
|
|
||||||
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
|
int id = -1;
|
||||||
|
if (event->type == GDK_ENTER_NOTIFY)
|
||||||
// emit the event
|
id = tool->GetId();
|
||||||
if( gdk_event->type == GDK_ENTER_NOTIFY )
|
tool->GetToolBar()->OnMouseEnter(id);
|
||||||
tb->OnMouseEnter( tool->GetId() );
|
|
||||||
else
|
|
||||||
tb->OnMouseEnter( -1 );
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -351,6 +188,66 @@ size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// "expose_event" from GtkImage inside m_item
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static gboolean
|
||||||
|
image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
|
||||||
|
{
|
||||||
|
const wxBitmap& bitmap = tool->GetDisabledBitmap();
|
||||||
|
if (tool->IsEnabled() || !bitmap.IsOk())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// draw disabled bitmap ourselves, GtkImage has no way to specify it
|
||||||
|
const GtkAllocation& alloc = widget->allocation;
|
||||||
|
gdk_draw_pixbuf(
|
||||||
|
widget->window, widget->style->black_gc, bitmap.GetPixbuf(),
|
||||||
|
0, 0,
|
||||||
|
alloc.x + (alloc.width - widget->requisition.width) / 2,
|
||||||
|
alloc.y + (alloc.height - widget->requisition.height) / 2,
|
||||||
|
-1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// "toggled" from dropdown menu button
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static void arrow_toggled(GtkToggleButton* button, wxToolBarTool* tool)
|
||||||
|
{
|
||||||
|
if (gtk_toggle_button_get_active(button))
|
||||||
|
{
|
||||||
|
tool->ShowDropdown(button);
|
||||||
|
gtk_toggle_button_set_active(button, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// "button_press_event" from dropdown menu button
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static gboolean
|
||||||
|
arrow_button_press_event(GtkToggleButton* button, GdkEventButton* event, wxToolBarTool* tool)
|
||||||
|
{
|
||||||
|
if (event->button == 1)
|
||||||
|
{
|
||||||
|
g_signal_handlers_block_by_func(button, (void*)arrow_toggled, tool);
|
||||||
|
gtk_toggle_button_set_active(button, true);
|
||||||
|
tool->ShowDropdown(button);
|
||||||
|
gtk_toggle_button_set_active(button, false);
|
||||||
|
g_signal_handlers_unblock_by_func(button, (void*)arrow_toggled, tool);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// InsertChild callback for wxToolBar
|
// InsertChild callback for wxToolBar
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -365,11 +262,67 @@ static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
|
|||||||
// wxToolBarTool
|
// wxToolBarTool
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxToolBarTool::Init()
|
void wxToolBarTool::SetImage()
|
||||||
{
|
{
|
||||||
m_item =
|
const wxBitmap& bitmap = GetNormalBitmap();
|
||||||
m_itemDropdown =
|
wxCHECK_RET(bitmap.IsOk(), "invalid bitmap for wxToolBar icon");
|
||||||
m_image = NULL;
|
|
||||||
|
GtkWidget* image = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(m_item));
|
||||||
|
// always use pixbuf, because pixmap mask does not
|
||||||
|
// work with disabled images in some themes
|
||||||
|
gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper to create a dropdown menu item
|
||||||
|
void wxToolBarTool::CreateDropDown()
|
||||||
|
{
|
||||||
|
gtk_tool_item_set_homogeneous(m_item, false);
|
||||||
|
GtkWidget* box;
|
||||||
|
GtkWidget* arrow;
|
||||||
|
if (GetToolBar()->HasFlag(wxTB_LEFT | wxTB_RIGHT))
|
||||||
|
{
|
||||||
|
box = gtk_vbox_new(false, 0);
|
||||||
|
arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
box = gtk_hbox_new(false, 0);
|
||||||
|
arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
||||||
|
}
|
||||||
|
GtkWidget* tool_button = GTK_BIN(m_item)->child;
|
||||||
|
gtk_widget_reparent(tool_button, box);
|
||||||
|
GtkWidget* arrow_button = gtk_toggle_button_new();
|
||||||
|
gtk_button_set_relief(GTK_BUTTON(arrow_button),
|
||||||
|
gtk_tool_item_get_relief_style(GTK_TOOL_ITEM(m_item)));
|
||||||
|
gtk_container_add(GTK_CONTAINER(arrow_button), arrow);
|
||||||
|
gtk_container_add(GTK_CONTAINER(box), arrow_button);
|
||||||
|
gtk_widget_show_all(box);
|
||||||
|
gtk_container_add(GTK_CONTAINER(m_item), box);
|
||||||
|
|
||||||
|
g_signal_connect(arrow_button, "toggled", G_CALLBACK(arrow_toggled), this);
|
||||||
|
g_signal_connect(arrow_button, "button_press_event",
|
||||||
|
G_CALLBACK(arrow_button_press_event), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxToolBarTool::ShowDropdown(GtkToggleButton* button)
|
||||||
|
{
|
||||||
|
wxToolBarBase* toolbar = GetToolBar();
|
||||||
|
wxCommandEvent event(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, GetId());
|
||||||
|
if (!toolbar->HandleWindowEvent(event))
|
||||||
|
{
|
||||||
|
wxMenu* menu = GetDropdownMenu();
|
||||||
|
if (menu)
|
||||||
|
{
|
||||||
|
const GtkAllocation& alloc = GTK_WIDGET(button)->allocation;
|
||||||
|
int x = alloc.x;
|
||||||
|
int y = alloc.y;
|
||||||
|
if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT))
|
||||||
|
x += alloc.width;
|
||||||
|
else
|
||||||
|
y += alloc.height;
|
||||||
|
toolbar->PopupMenu(menu, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
||||||
@@ -398,13 +351,16 @@ wxToolBar::CreateTool(wxControl *control, const wxString& label)
|
|||||||
void wxToolBar::Init()
|
void wxToolBar::Init()
|
||||||
{
|
{
|
||||||
m_toolbar = (GtkToolbar *)NULL;
|
m_toolbar = (GtkToolbar *)NULL;
|
||||||
m_blockEvent = false;
|
m_tooltips = NULL;
|
||||||
m_defaultWidth = 32;
|
|
||||||
m_defaultHeight = 32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBar::~wxToolBar()
|
wxToolBar::~wxToolBar()
|
||||||
{
|
{
|
||||||
|
if (m_tooltips)
|
||||||
|
{
|
||||||
|
gtk_object_destroy(GTK_OBJECT(m_tooltips));
|
||||||
|
g_object_unref(m_tooltips);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::Create( wxWindow *parent,
|
bool wxToolBar::Create( wxWindow *parent,
|
||||||
@@ -427,19 +383,19 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
FixupStyle();
|
FixupStyle();
|
||||||
|
|
||||||
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
|
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
|
||||||
|
m_tooltips = gtk_tooltips_new();
|
||||||
|
g_object_ref(m_tooltips);
|
||||||
|
gtk_object_sink(GTK_OBJECT(m_tooltips));
|
||||||
GtkSetStyle();
|
GtkSetStyle();
|
||||||
|
|
||||||
// Doesn't work this way.
|
|
||||||
// GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
|
|
||||||
// gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
|
|
||||||
|
|
||||||
SetToolSeparation(7);
|
|
||||||
|
|
||||||
if (style & wxTB_DOCKABLE)
|
if (style & wxTB_DOCKABLE)
|
||||||
{
|
{
|
||||||
m_widget = gtk_handle_box_new();
|
m_widget = gtk_handle_box_new();
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
|
||||||
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
g_signal_connect(m_widget, "child_detached",
|
||||||
|
G_CALLBACK(child_detached), NULL);
|
||||||
|
g_signal_connect(m_widget, "child_attached",
|
||||||
|
G_CALLBACK(child_attached), NULL);
|
||||||
|
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
|
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
|
||||||
@@ -447,16 +403,10 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_widget = gtk_event_box_new();
|
m_widget = gtk_event_box_new();
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
|
||||||
ConnectWidget( m_widget );
|
ConnectWidget( m_widget );
|
||||||
gtk_widget_show(GTK_WIDGET(m_toolbar));
|
|
||||||
}
|
}
|
||||||
|
gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar));
|
||||||
// FIXME: there is no such function for toolbars in 2.0
|
gtk_widget_show(GTK_WIDGET(m_toolbar));
|
||||||
#if 0
|
|
||||||
if (style & wxTB_FLAT)
|
|
||||||
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
@@ -475,13 +425,22 @@ GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
|
|||||||
|
|
||||||
void wxToolBar::GtkSetStyle()
|
void wxToolBar::GtkSetStyle()
|
||||||
{
|
{
|
||||||
GtkOrientation orient;
|
GtkOrientation orient = GTK_ORIENTATION_HORIZONTAL;
|
||||||
GtkToolbarStyle style;
|
if (HasFlag(wxTB_LEFT | wxTB_RIGHT))
|
||||||
GetGtkStyle(GetWindowStyle(), &orient, &style);
|
orient = GTK_ORIENTATION_VERTICAL;
|
||||||
|
|
||||||
|
GtkToolbarStyle style = GTK_TOOLBAR_ICONS;
|
||||||
|
if (HasFlag(wxTB_NOICONS))
|
||||||
|
style = GTK_TOOLBAR_TEXT;
|
||||||
|
else if (HasFlag(wxTB_TEXT))
|
||||||
|
{
|
||||||
|
style = GTK_TOOLBAR_BOTH;
|
||||||
|
if (HasFlag(wxTB_HORZ_LAYOUT))
|
||||||
|
style = GTK_TOOLBAR_BOTH_HORIZ;
|
||||||
|
}
|
||||||
|
|
||||||
gtk_toolbar_set_orientation(m_toolbar, orient);
|
gtk_toolbar_set_orientation(m_toolbar, orient);
|
||||||
gtk_toolbar_set_style(m_toolbar, style);
|
gtk_toolbar_set_style(m_toolbar, style);
|
||||||
gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetWindowStyleFlag( long style )
|
void wxToolBar::SetWindowStyleFlag( long style )
|
||||||
@@ -496,200 +455,141 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
{
|
{
|
||||||
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
||||||
|
|
||||||
if ( tool->IsButton() )
|
GSList* radioGroup;
|
||||||
{
|
|
||||||
if ( !HasFlag(wxTB_NOICONS) )
|
|
||||||
{
|
|
||||||
wxBitmap bitmap = tool->GetNormalBitmap();
|
|
||||||
|
|
||||||
wxCHECK_MSG( bitmap.Ok(), false,
|
|
||||||
wxT("invalid bitmap for wxToolBar icon") );
|
|
||||||
|
|
||||||
tool->m_image = gtk_image_new();
|
|
||||||
tool->SetImage(bitmap);
|
|
||||||
|
|
||||||
gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int posGtk = 0;
|
|
||||||
if ( pos > 0 )
|
|
||||||
{
|
|
||||||
for ( size_t i = 0; i < pos; i++ )
|
|
||||||
{
|
|
||||||
posGtk++;
|
|
||||||
|
|
||||||
// if we have a dropdown menu, we use 2 GTK tools internally
|
|
||||||
wxToolBarToolsList::compatibility_iterator node = m_tools.Item( i );
|
|
||||||
wxToolBarTool * const tool2 = (wxToolBarTool*) node->GetData();
|
|
||||||
if ( tool2->IsButton() && tool2->GetKind() == wxITEM_DROPDOWN )
|
|
||||||
posGtk++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch ( tool->GetStyle() )
|
switch ( tool->GetStyle() )
|
||||||
{
|
{
|
||||||
case wxTOOL_STYLE_BUTTON:
|
case wxTOOL_STYLE_BUTTON:
|
||||||
// for a radio button we need the widget which starts the radio
|
switch (tool->GetKind())
|
||||||
// group it belongs to, i.e. the first radio button immediately
|
|
||||||
// preceding this one
|
|
||||||
{
|
{
|
||||||
GtkWidget *widget = NULL;
|
case wxITEM_CHECK:
|
||||||
|
tool->m_item = gtk_toggle_tool_button_new();
|
||||||
if ( tool->IsRadio() )
|
g_signal_connect(tool->m_item, "toggled",
|
||||||
{
|
G_CALLBACK(item_toggled), tool);
|
||||||
wxToolBarToolsList::compatibility_iterator node
|
|
||||||
= wxToolBarToolsList::compatibility_iterator();
|
|
||||||
if ( pos )
|
|
||||||
node = m_tools.Item(pos - 1);
|
|
||||||
|
|
||||||
while ( node )
|
|
||||||
{
|
|
||||||
wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData();
|
|
||||||
if ( !toolNext->IsRadio() )
|
|
||||||
break;
|
break;
|
||||||
|
case wxITEM_RADIO:
|
||||||
widget = toolNext->m_item;
|
radioGroup = GetRadioGroup(pos);
|
||||||
|
if (radioGroup)
|
||||||
node = node->GetPrevious();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !widget )
|
|
||||||
{
|
{
|
||||||
// this is the first button in the radio button group,
|
// this is the first button in the radio button group,
|
||||||
// it will be toggled automatically by GTK so bring the
|
// it will be toggled automatically by GTK so bring the
|
||||||
// internal flag in sync
|
// internal flag in sync
|
||||||
tool->Toggle(true);
|
tool->Toggle(true);
|
||||||
}
|
}
|
||||||
|
tool->m_item = gtk_radio_tool_button_new(radioGroup);
|
||||||
|
g_signal_connect(tool->m_item, "toggled",
|
||||||
|
G_CALLBACK(item_toggled), tool);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG("unknown toolbar child type");
|
||||||
|
// fall through
|
||||||
|
case wxITEM_DROPDOWN:
|
||||||
|
case wxITEM_NORMAL:
|
||||||
|
tool->m_item = gtk_tool_button_new(NULL, "");
|
||||||
|
g_signal_connect(tool->m_item, "clicked",
|
||||||
|
G_CALLBACK(item_clicked), tool);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (!HasFlag(wxTB_NOICONS))
|
||||||
tool->m_item = gtk_toolbar_insert_element
|
{
|
||||||
(
|
GtkWidget* image = gtk_image_new();
|
||||||
m_toolbar,
|
gtk_tool_button_set_icon_widget(
|
||||||
tool->GetGtkChildType(),
|
GTK_TOOL_BUTTON(tool->m_item), image);
|
||||||
widget,
|
tool->SetImage();
|
||||||
tool->GetLabel().empty()
|
gtk_widget_show(image);
|
||||||
? NULL
|
g_signal_connect(image, "expose_event",
|
||||||
: (const char*) wxGTK_CONV( tool->GetLabel() ),
|
G_CALLBACK(image_expose_event), tool);
|
||||||
tool->GetShortHelp().empty()
|
}
|
||||||
? NULL
|
if (!tool->GetLabel().empty())
|
||||||
: (const char*) wxGTK_CONV( tool->GetShortHelp() ),
|
{
|
||||||
"", // tooltip_private_text (?)
|
gtk_tool_button_set_label(
|
||||||
tool->m_image,
|
GTK_TOOL_BUTTON(tool->m_item), wxGTK_CONV(tool->GetLabel()));
|
||||||
(GtkSignalFunc)gtk_toolbar_callback,
|
// needed for labels in horizontal toolbar with wxTB_HORZ_LAYOUT
|
||||||
(gpointer)tool,
|
gtk_tool_item_set_is_important(tool->m_item, true);
|
||||||
posGtk
|
}
|
||||||
);
|
if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
|
||||||
|
{
|
||||||
wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
|
gtk_tool_item_set_tooltip(tool->m_item,
|
||||||
|
m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
|
||||||
g_signal_connect (tool->m_item, "enter_notify_event",
|
}
|
||||||
G_CALLBACK (gtk_toolbar_tool_callback),
|
g_signal_connect(GTK_BIN(tool->m_item)->child, "button_press_event",
|
||||||
tool);
|
G_CALLBACK(button_press_event), tool);
|
||||||
g_signal_connect (tool->m_item, "leave_notify_event",
|
g_signal_connect(tool->m_item, "enter_notify_event",
|
||||||
G_CALLBACK (gtk_toolbar_tool_callback),
|
G_CALLBACK(enter_notify_event), tool);
|
||||||
tool);
|
g_signal_connect(tool->m_item, "leave_notify_event",
|
||||||
g_signal_connect(tool->m_item, "button-press-event",
|
G_CALLBACK(enter_notify_event), tool);
|
||||||
G_CALLBACK (gtk_toolbar_tool_rclick_callback),
|
|
||||||
tool);
|
|
||||||
|
|
||||||
if (tool->GetKind() == wxITEM_DROPDOWN)
|
if (tool->GetKind() == wxITEM_DROPDOWN)
|
||||||
{
|
tool->CreateDropDown();
|
||||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data( arrow_down_xpm );
|
|
||||||
GtkWidget *dropdown = gtk_toggle_button_new();
|
|
||||||
GtkWidget *image = gtk_image_new_from_pixbuf( pixbuf );
|
|
||||||
gtk_widget_show( image );
|
|
||||||
gtk_container_add( GTK_CONTAINER(dropdown), image );
|
|
||||||
g_object_unref(pixbuf);
|
|
||||||
|
|
||||||
if (GetWindowStyle() & wxTB_FLAT)
|
|
||||||
gtk_button_set_relief( GTK_BUTTON(dropdown), GTK_RELIEF_NONE );
|
|
||||||
GTK_WIDGET_UNSET_FLAGS (dropdown, GTK_CAN_FOCUS);
|
|
||||||
gtk_widget_show( dropdown );
|
|
||||||
|
|
||||||
g_signal_connect (dropdown, "enter_notify_event",
|
|
||||||
G_CALLBACK (gtk_toolbar_buddy_enter_callback),
|
|
||||||
tool->m_item);
|
|
||||||
g_signal_connect (dropdown, "leave_notify_event",
|
|
||||||
G_CALLBACK (gtk_toolbar_buddy_leave_callback),
|
|
||||||
tool->m_item);
|
|
||||||
g_signal_connect(dropdown, "button-press-event",
|
|
||||||
G_CALLBACK (gtk_toolbar_dropdown_lclick_callback),
|
|
||||||
tool);
|
|
||||||
|
|
||||||
GtkRequisition req;
|
|
||||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(tool->m_item) )->size_request )
|
|
||||||
(tool->m_item, &req );
|
|
||||||
gtk_widget_set_size_request( dropdown, -1, req.height );
|
|
||||||
|
|
||||||
gtk_toolbar_insert_widget(m_toolbar, dropdown, NULL, NULL,
|
|
||||||
posGtk + 1);
|
|
||||||
tool->m_itemDropdown = dropdown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
gtk_toolbar_insert_space( m_toolbar, posGtk );
|
tool->m_item = gtk_separator_tool_item_new();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxTOOL_STYLE_CONTROL:
|
case wxTOOL_STYLE_CONTROL:
|
||||||
GtkWidget * const align = gtk_alignment_new(0.5, 0.5, 0, 0);
|
GtkWidget * const align = gtk_alignment_new(0.5, 0.5, 0, 0);
|
||||||
gtk_widget_show(align);
|
gtk_widget_show(align);
|
||||||
gtk_container_add(GTK_CONTAINER(align),
|
wxWindow* control = tool->GetControl();
|
||||||
tool->GetControl()->m_widget);
|
gtk_container_add(GTK_CONTAINER(align), control->m_widget);
|
||||||
gtk_toolbar_insert_widget(m_toolbar, align, NULL, NULL, posGtk);
|
tool->m_item = gtk_tool_item_new();
|
||||||
|
gtk_container_add(GTK_CONTAINER(tool->m_item), align);
|
||||||
// remember the container we're in so that we could remove
|
// Inserted items "slide" into place using an animated effect that
|
||||||
// ourselves from it when we're detached from the toolbar
|
// causes multiple size events on the item. Must set size request
|
||||||
tool->m_item = align;
|
// to keep item size from getting permanently set too small by the
|
||||||
|
// first of these size events.
|
||||||
|
const wxSize size = control->GetSize();
|
||||||
|
gtk_widget_set_size_request(control->m_widget, size.x, size.y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
gtk_widget_show(GTK_WIDGET(tool->m_item));
|
||||||
|
gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
|
||||||
|
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
|
bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase)
|
||||||
{
|
{
|
||||||
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
||||||
|
|
||||||
switch ( tool->GetStyle() )
|
if (tool->GetStyle() == wxTOOL_STYLE_CONTROL)
|
||||||
{
|
{
|
||||||
case wxTOOL_STYLE_CONTROL:
|
|
||||||
// don't destroy the control here as we can be called from
|
// don't destroy the control here as we can be called from
|
||||||
// RemoveTool() and then we need to keep the control alive;
|
// RemoveTool() and then we need to keep the control alive;
|
||||||
// while if we're called from DeleteTool() the control will
|
// while if we're called from DeleteTool() the control will
|
||||||
// be destroyed when wxToolBarToolBase itself is deleted
|
// be destroyed when wxToolBarToolBase itself is deleted
|
||||||
gtk_container_remove(
|
GtkWidget* widget = tool->GetControl()->m_widget;
|
||||||
GTK_CONTAINER(tool->m_item), tool->GetControl()->m_widget);
|
gtk_container_remove(GTK_CONTAINER(widget->parent), widget);
|
||||||
// fall through
|
}
|
||||||
|
gtk_object_destroy(GTK_OBJECT(tool->m_item));
|
||||||
case wxTOOL_STYLE_BUTTON:
|
|
||||||
gtk_widget_destroy( tool->m_item );
|
|
||||||
tool->m_item = NULL;
|
tool->m_item = NULL;
|
||||||
if (tool->m_itemDropdown)
|
|
||||||
{
|
|
||||||
gtk_widget_destroy(tool->m_itemDropdown);
|
|
||||||
tool->m_itemDropdown = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
|
||||||
gtk_toolbar_remove_space( m_toolbar, pos );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG( "unknown tool style" );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GSList* wxToolBar::GetRadioGroup(size_t pos)
|
||||||
|
{
|
||||||
|
GSList* radioGroup = NULL;
|
||||||
|
GtkToolItem* item = NULL;
|
||||||
|
if (pos > 0)
|
||||||
|
{
|
||||||
|
item = gtk_toolbar_get_nth_item(m_toolbar, int(pos) - 1);
|
||||||
|
if (!GTK_IS_RADIO_TOOL_BUTTON(item))
|
||||||
|
item = NULL;
|
||||||
|
}
|
||||||
|
if (item == NULL && pos < m_tools.size())
|
||||||
|
{
|
||||||
|
item = gtk_toolbar_get_nth_item(m_toolbar, int(pos));
|
||||||
|
if (!GTK_IS_RADIO_TOOL_BUTTON(item))
|
||||||
|
item = NULL;
|
||||||
|
}
|
||||||
|
if (item)
|
||||||
|
radioGroup = gtk_radio_tool_button_get_group((GtkRadioToolButton*)item);
|
||||||
|
return radioGroup;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxToolBar tools state
|
// wxToolBar tools state
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -699,25 +599,21 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
|
|||||||
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
||||||
|
|
||||||
if (tool->m_item)
|
if (tool->m_item)
|
||||||
{
|
gtk_widget_set_sensitive(GTK_WIDGET(tool->m_item), enable);
|
||||||
gtk_widget_set_sensitive( tool->m_item, enable );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
|
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
|
||||||
{
|
{
|
||||||
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
|
||||||
|
|
||||||
GtkWidget *item = tool->m_item;
|
if (tool->m_item)
|
||||||
if ( item && GTK_IS_TOGGLE_BUTTON(item) )
|
|
||||||
{
|
{
|
||||||
tool->SetImage(tool->GetBitmap());
|
g_signal_handlers_block_by_func(tool->m_item, (void*)item_toggled, tool);
|
||||||
|
|
||||||
m_blockEvent = true;
|
gtk_toggle_tool_button_set_active(
|
||||||
|
GTK_TOGGLE_TOOL_BUTTON(tool->m_item), toggle);
|
||||||
|
|
||||||
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
|
g_signal_handlers_unblock_by_func(tool->m_item, (void*)item_toggled, tool);
|
||||||
|
|
||||||
m_blockEvent = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,6 +628,19 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
|
|||||||
// wxToolBar geometry
|
// wxToolBar geometry
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxSize wxToolBar::DoGetBestSize() const
|
||||||
|
{
|
||||||
|
// Unfortunately, if overflow arrow is enabled GtkToolbar only reports size
|
||||||
|
// of arrow. To get the real size, the arrow is temporarily disabled here.
|
||||||
|
// This is gross, since it will cause a queue_resize, and could potentially
|
||||||
|
// lead to an infinite loop. But there seems to be no alternative, short of
|
||||||
|
// disabling the arrow entirely.
|
||||||
|
gtk_toolbar_set_show_arrow(m_toolbar, false);
|
||||||
|
const wxSize size = wxToolBarBase::DoGetBestSize();
|
||||||
|
gtk_toolbar_set_show_arrow(m_toolbar, true);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
||||||
wxCoord WXUNUSED(y)) const
|
wxCoord WXUNUSED(y)) const
|
||||||
{
|
{
|
||||||
@@ -741,25 +650,6 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
|||||||
return (wxToolBarToolBase *)NULL;
|
return (wxToolBarToolBase *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetMargins( int x, int y )
|
|
||||||
{
|
|
||||||
wxCHECK_RET( GetToolsCount() == 0,
|
|
||||||
wxT("wxToolBar::SetMargins must be called before adding tools.") );
|
|
||||||
|
|
||||||
m_xMargin = x;
|
|
||||||
m_yMargin = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::SetToolSeparation( int separation )
|
|
||||||
{
|
|
||||||
// FIXME: this function disappeared
|
|
||||||
#if 0
|
|
||||||
gtk_toolbar_set_space_size( m_toolbar, separation );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_toolSeparation = separation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
|
void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
|
||||||
{
|
{
|
||||||
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
|
wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
|
||||||
@@ -767,8 +657,11 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
|
|||||||
if ( tool )
|
if ( tool )
|
||||||
{
|
{
|
||||||
(void)tool->SetShortHelp(helpString);
|
(void)tool->SetShortHelp(helpString);
|
||||||
gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
|
if (tool->m_item)
|
||||||
wxGTK_CONV( helpString ), "");
|
{
|
||||||
|
gtk_tool_item_set_tooltip(tool->m_item,
|
||||||
|
m_tooltips, wxGTK_CONV(helpString), "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,7 +673,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
|
|||||||
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
|
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
|
||||||
|
|
||||||
tool->SetNormalBitmap(bitmap);
|
tool->SetNormalBitmap(bitmap);
|
||||||
tool->SetImage(tool->GetBitmap());
|
tool->SetImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,7 +685,6 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
|
|||||||
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
|
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
|
||||||
|
|
||||||
tool->SetDisabledBitmap(bitmap);
|
tool->SetDisabledBitmap(bitmap);
|
||||||
tool->SetImage(tool->GetBitmap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,10 +724,9 @@ void wxToolBar::OnInternalIdle()
|
|||||||
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
|
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
|
|
||||||
GtkWidget *item = tool->m_item;
|
if (tool->m_item)
|
||||||
if ( item )
|
|
||||||
{
|
{
|
||||||
GdkWindow *window = item->window;
|
GdkWindow* window = GTK_WIDGET(tool->m_item)->window;
|
||||||
|
|
||||||
if ( window )
|
if ( window )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user