1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tbargtk.cpp
|
|
|
|
// Purpose: GTK toolbar
|
|
|
|
// Author: Robert Roebling
|
1999-12-15 19:47:54 +00:00
|
|
|
// Modified: 13.12.99 by VZ to derive from wxToolBarBase
|
1998-10-24 20:25:36 +00:00
|
|
|
// RCS-ID: $Id$
|
1998-05-20 14:01:55 +00:00
|
|
|
// Copyright: (c) Robert Roebling
|
1998-08-07 15:09:04 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#ifdef __GNUG__
|
1999-12-15 19:47:54 +00:00
|
|
|
#pragma implementation "tbargtk.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/toolbar.h"
|
1999-06-14 23:04:05 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
#if wxUSE_TOOLBAR_NATIVE
|
1999-06-14 23:04:05 +00:00
|
|
|
|
1999-04-07 21:33:22 +00:00
|
|
|
#include "wx/frame.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
#include "glib.h"
|
|
|
|
#include "gdk/gdk.h"
|
|
|
|
#include "gtk/gtk.h"
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// globals
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-04-27 19:32:19 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// idle system
|
1999-04-27 19:32:19 +00:00
|
|
|
extern void wxapp_install_idle_handler();
|
|
|
|
extern bool g_isIdle;
|
|
|
|
|
1998-08-18 17:41:55 +00:00
|
|
|
// data
|
1999-10-04 09:03:48 +00:00
|
|
|
extern bool g_blockEventsOnDrag;
|
|
|
|
extern wxCursor g_globalCursor;
|
1998-08-18 17:41:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBarTool
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxToolBarTool : public wxToolBarToolBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxToolBarTool(wxToolBar *tbar,
|
|
|
|
int id,
|
|
|
|
const wxBitmap& bitmap1,
|
|
|
|
const wxBitmap& bitmap2,
|
|
|
|
bool toggle,
|
|
|
|
wxObject *clientData,
|
|
|
|
const wxString& shortHelpString,
|
|
|
|
const wxString& longHelpString)
|
|
|
|
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
|
|
|
|
clientData, shortHelpString, longHelpString)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
|
|
|
: wxToolBarToolBase(tbar, control)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *m_item;
|
|
|
|
GtkWidget *m_pixmap;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void Init();
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1998-09-02 12:15:35 +00:00
|
|
|
// "clicked" (internal from gtk_toolbar)
|
1998-05-20 14:01:55 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
|
|
|
|
wxToolBarTool *tool )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-10-31 16:42:46 +00:00
|
|
|
if (g_isIdle)
|
|
|
|
wxapp_install_idle_handler();
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
|
|
|
|
if ( tbar->m_blockNextEvent )
|
1999-10-31 16:42:46 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
tbar->m_blockNextEvent = FALSE;
|
1999-10-31 16:42:46 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-04-27 19:32:19 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
if (g_blockEventsOnDrag) return;
|
1999-12-15 19:47:54 +00:00
|
|
|
if (!tool->IsEnabled()) return;
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
if (tool->CanBeToggled())
|
1999-05-31 10:47:44 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
tool->Toggle();
|
|
|
|
|
|
|
|
wxBitmap bitmap = tool->GetBitmap();
|
|
|
|
if ( bitmap.Ok() )
|
|
|
|
{
|
1999-05-31 10:47:44 +00:00
|
|
|
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
|
|
|
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
|
|
|
|
: (GdkBitmap *)NULL;
|
|
|
|
|
1999-05-31 10:47:44 +00:00
|
|
|
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
|
1999-12-15 19:47:54 +00:00
|
|
|
}
|
1999-05-31 10:47:44 +00:00
|
|
|
}
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
tbar->OnLeftClick( tool->GetId(), tool->IsToggled() );
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-09-02 12:15:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// "enter_notify_event"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1998-08-18 17:41:55 +00:00
|
|
|
static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
|
1999-12-15 19:47:54 +00:00
|
|
|
GdkEventCrossing *WXUNUSED(gdk_event),
|
|
|
|
wxToolBarTool *tool )
|
1998-08-18 17:41:55 +00:00
|
|
|
{
|
1999-04-27 19:32:19 +00:00
|
|
|
if (g_isIdle) wxapp_install_idle_handler();
|
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
if (g_blockEventsOnDrag) return TRUE;
|
1999-02-11 20:44:38 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
|
1999-02-11 20:44:38 +00:00
|
|
|
|
1999-06-28 13:22:00 +00:00
|
|
|
#if (GTK_MINOR_VERSION == 0)
|
|
|
|
/* we grey-out the tip text of disabled tool in GTK 1.0 */
|
1999-12-15 19:47:54 +00:00
|
|
|
if (tool->IsEnabled())
|
1999-02-11 20:44:38 +00:00
|
|
|
{
|
|
|
|
if (tb->m_fg->red != 0)
|
1999-05-09 22:17:03 +00:00
|
|
|
{
|
1999-02-11 20:44:38 +00:00
|
|
|
tb->m_fg->red = 0;
|
|
|
|
tb->m_fg->green = 0;
|
|
|
|
tb->m_fg->blue = 0;
|
|
|
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg );
|
1999-05-09 22:17:03 +00:00
|
|
|
|
1999-02-11 20:44:38 +00:00
|
|
|
gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg );
|
1999-05-09 22:17:03 +00:00
|
|
|
}
|
1999-02-11 20:44:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tb->m_fg->red == 0)
|
1999-05-09 22:17:03 +00:00
|
|
|
{
|
1999-02-11 20:44:38 +00:00
|
|
|
tb->m_fg->red = 33000;
|
|
|
|
tb->m_fg->green = 33000;
|
|
|
|
tb->m_fg->blue = 33000;
|
|
|
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg );
|
|
|
|
gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg );
|
1999-05-09 22:17:03 +00:00
|
|
|
}
|
1999-02-11 20:44:38 +00:00
|
|
|
}
|
1999-06-01 14:29:59 +00:00
|
|
|
#endif
|
1999-02-11 20:44:38 +00:00
|
|
|
|
|
|
|
/* emit the event */
|
1998-08-18 17:41:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
tb->OnMouseEnter( tool->GetId() );
|
1998-08-18 17:41:55 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
return FALSE;
|
1998-08-18 17:41:55 +00:00
|
|
|
}
|
|
|
|
|
1999-11-14 15:14:23 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// InsertChild callback for wxToolBar
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
|
|
|
|
wxWindow* WXUNUSED(child) )
|
1999-11-14 15:14:23 +00:00
|
|
|
{
|
|
|
|
/* we don't do anything here but pray */
|
|
|
|
}
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBarTool
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
void wxToolBarTool::Init()
|
|
|
|
{
|
|
|
|
m_item =
|
|
|
|
m_pixmap = (GtkWidget *)NULL;
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
|
|
|
const wxBitmap& bitmap1,
|
|
|
|
const wxBitmap& bitmap2,
|
|
|
|
bool toggle,
|
|
|
|
wxObject *clientData,
|
|
|
|
const wxString& shortHelpString,
|
|
|
|
const wxString& longHelpString)
|
|
|
|
{
|
|
|
|
return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
|
|
|
|
clientData, shortHelpString, longHelpString);
|
|
|
|
}
|
1999-04-15 12:08:59 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
return new wxToolBarTool(this, control);
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxToolBar construction
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void wxToolBar::Init()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
m_fg =
|
|
|
|
m_bg = (GdkColor *)NULL;
|
|
|
|
|
|
|
|
m_toolbar = (GtkToolbar *)NULL;
|
|
|
|
|
|
|
|
m_blockNextEvent = FALSE;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-08-07 15:09:04 +00:00
|
|
|
wxToolBar::~wxToolBar()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-01-02 19:13:25 +00:00
|
|
|
delete m_fg;
|
|
|
|
delete m_bg;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
bool wxToolBar::Create( wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxString& name )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1998-12-16 12:17:14 +00:00
|
|
|
m_needParent = TRUE;
|
1999-11-14 15:14:23 +00:00
|
|
|
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
if ( !PreCreation( parent, pos, size ) ||
|
|
|
|
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
|
1999-07-27 20:23:13 +00:00
|
|
|
{
|
1999-10-08 14:35:56 +00:00
|
|
|
wxFAIL_MSG( wxT("wxToolBar creation failed") );
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
GtkOrientation orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
|
|
|
|
: GTK_ORIENTATION_HORIZONTAL;
|
|
|
|
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( orient, GTK_TOOLBAR_ICONS ) );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
SetToolSeparation(7);
|
1999-02-10 23:08:27 +00:00
|
|
|
|
|
|
|
if (style & wxTB_DOCKABLE)
|
|
|
|
{
|
|
|
|
m_widget = gtk_handle_box_new();
|
1999-05-09 22:17:03 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
|
|
|
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1999-05-03 14:28:51 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
1999-05-09 22:17:03 +00:00
|
|
|
if (style & wxTB_FLAT)
|
1999-05-03 12:19:16 +00:00
|
|
|
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
|
1999-05-03 14:28:51 +00:00
|
|
|
#endif
|
1999-02-10 23:08:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_widget = GTK_WIDGET(m_toolbar);
|
|
|
|
}
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1999-05-03 12:19:16 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
|
|
|
if (style & wxTB_FLAT)
|
|
|
|
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
|
|
|
#endif
|
1999-01-02 19:13:25 +00:00
|
|
|
|
|
|
|
m_fg = new GdkColor;
|
|
|
|
m_fg->red = 0;
|
|
|
|
m_fg->green = 0;
|
|
|
|
m_fg->blue = 0;
|
|
|
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
m_bg = new GdkColor;
|
|
|
|
m_bg->red = 65535;
|
|
|
|
m_bg->green = 65535;
|
|
|
|
m_bg->blue = 50000;
|
|
|
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1999-05-02 09:19:44 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
|
|
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
|
|
|
|
|
|
|
GtkStyle *g_style =
|
1999-12-15 19:47:54 +00:00
|
|
|
gtk_style_copy(
|
|
|
|
gtk_widget_get_style(
|
|
|
|
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
|
|
|
|
1999-05-02 09:19:44 +00:00
|
|
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
|
|
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
|
|
|
#else
|
1999-01-02 19:13:25 +00:00
|
|
|
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
1999-05-02 09:19:44 +00:00
|
|
|
#endif
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-05-09 22:17:03 +00:00
|
|
|
m_parent->DoAddChild( this );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
PostCreation();
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
Show( TRUE );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
return TRUE;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-20 20:16:37 +00:00
|
|
|
// we have inserted a space before all the tools
|
|
|
|
if (m_xMargin > 1) pos++;
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
if ( tool->IsButton() )
|
|
|
|
{
|
|
|
|
wxBitmap bitmap = tool->GetBitmap1();
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxCHECK_MSG( bitmap.Ok(), FALSE,
|
|
|
|
wxT("invalid bitmap for wxToolBar icon") );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
|
|
|
|
wxT("wxToolBar doesn't support GdkBitmap") );
|
1998-10-12 13:09:15 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE,
|
|
|
|
wxT("wxToolBar::Add needs a wxBitmap") );
|
|
|
|
|
|
|
|
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
|
|
|
|
|
|
|
|
GdkPixmap *pixmap = bitmap.GetPixmap();
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
GdkBitmap *mask = (GdkBitmap *)NULL;
|
|
|
|
if ( bitmap.GetMask() )
|
|
|
|
mask = bitmap.GetMask()->GetBitmap();
|
|
|
|
|
|
|
|
tool_pixmap = gtk_pixmap_new( pixmap, mask );
|
1999-06-28 13:22:00 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
1999-12-15 19:47:54 +00:00
|
|
|
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
|
1999-06-28 13:22:00 +00:00
|
|
|
#endif
|
1999-12-15 19:47:54 +00:00
|
|
|
|
|
|
|
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
tool->m_pixmap = tool_pixmap;
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
switch ( tool->GetStyle() )
|
|
|
|
{
|
|
|
|
case wxTOOL_STYLE_BUTTON:
|
|
|
|
tool->m_item = gtk_toolbar_insert_element
|
|
|
|
(
|
|
|
|
m_toolbar,
|
|
|
|
tool->CanBeToggled()
|
|
|
|
? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
|
|
|
|
: GTK_TOOLBAR_CHILD_BUTTON,
|
|
|
|
(GtkWidget *)NULL,
|
|
|
|
(const char *)NULL,
|
|
|
|
tool->GetShortHelp().mbc_str(),
|
|
|
|
"", // tooltip_private_text (?)
|
|
|
|
tool->m_pixmap,
|
|
|
|
(GtkSignalFunc)gtk_toolbar_callback,
|
|
|
|
(gpointer)tool,
|
|
|
|
pos
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !tool->m_item )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_signal_connect( GTK_OBJECT(tool->m_item),
|
|
|
|
"enter_notify_event",
|
|
|
|
GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
|
|
|
|
(gpointer)tool );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxTOOL_STYLE_SEPARATOR:
|
|
|
|
gtk_toolbar_append_space( m_toolbar );
|
|
|
|
|
|
|
|
// skip the rest
|
|
|
|
return TRUE;
|
1999-11-14 15:14:23 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
case wxTOOL_STYLE_CONTROL:
|
|
|
|
gtk_toolbar_insert_widget(
|
|
|
|
m_toolbar,
|
|
|
|
tool->GetControl()->m_widget,
|
|
|
|
(const char *) NULL,
|
|
|
|
(const char *) NULL,
|
|
|
|
pos
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
1999-11-14 15:14:23 +00:00
|
|
|
|
|
|
|
GtkRequisition req;
|
|
|
|
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
|
1999-12-07 14:54:32 +00:00
|
|
|
m_width = req.width + m_xMargin;
|
1999-12-20 20:16:37 +00:00
|
|
|
m_height = req.height + 2*m_yMargin;
|
1999-11-14 15:14:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-12-26 21:52:50 +00:00
|
|
|
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
switch ( tool->GetStyle() )
|
1999-11-18 15:58:35 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
case wxTOOL_STYLE_CONTROL:
|
|
|
|
tool->GetControl()->Destroy();
|
|
|
|
break;
|
1999-11-18 15:58:35 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
case wxTOOL_STYLE_BUTTON:
|
|
|
|
gtk_widget_destroy( tool->m_item );
|
|
|
|
break;
|
1999-11-18 15:58:35 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
//case wxTOOL_STYLE_SEPARATOR: -- nothing to do
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
return TRUE;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-07-24 19:05:25 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBar tools state
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-06-28 13:22:00 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
|
|
|
|
|
|
|
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
|
|
|
|
greyed anyway and this also disables tooltips */
|
|
|
|
if (tool->m_item)
|
|
|
|
gtk_widget_set_sensitive( tool->m_item, enable );
|
1999-06-28 13:22:00 +00:00
|
|
|
#endif
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
|
|
|
|
|
|
|
GtkWidget *item = tool->m_item;
|
|
|
|
if ( item && GTK_IS_TOGGLE_BUTTON(item) )
|
1998-12-16 12:17:14 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
wxBitmap bitmap = tool->GetBitmap();
|
|
|
|
if ( bitmap.Ok() )
|
|
|
|
{
|
|
|
|
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
|
|
|
|
|
|
|
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
|
|
|
|
: (GdkBitmap *)NULL;
|
|
|
|
|
|
|
|
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
|
1998-12-16 12:17:14 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
|
|
|
|
|
|
|
|
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle );
|
1998-12-16 12:17:14 +00:00
|
|
|
}
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
|
|
|
|
bool WXUNUSED(toggle))
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
// VZ: absolutely no idea about how to do it
|
|
|
|
wxFAIL_MSG( _T("not implemented") );
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBar geometry
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
|
|
|
wxCoord WXUNUSED(y)) const
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
// VZ: GTK+ doesn't seem to have such thing
|
|
|
|
wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
|
|
|
|
|
|
|
|
return (wxToolBarToolBase *)NULL;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-12-16 12:17:14 +00:00
|
|
|
void wxToolBar::SetMargins( int x, int y )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
wxCHECK_RET( GetToolsCount() == 0,
|
|
|
|
wxT("wxToolBar::SetMargins must be called before adding tools.") );
|
1998-12-16 12:17:14 +00:00
|
|
|
|
1999-12-07 14:54:32 +00:00
|
|
|
if (x > 1) gtk_toolbar_append_space( m_toolbar ); // oh well
|
1998-12-16 12:17:14 +00:00
|
|
|
|
|
|
|
m_xMargin = x;
|
|
|
|
m_yMargin = y;
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-07-29 13:21:22 +00:00
|
|
|
void wxToolBar::SetToolSeparation( int separation )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1998-12-16 12:17:14 +00:00
|
|
|
gtk_toolbar_set_space_size( m_toolbar, separation );
|
1999-12-15 19:47:54 +00:00
|
|
|
m_toolSeparation = separation;
|
1998-12-16 12:17:14 +00:00
|
|
|
}
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBar idle handling
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-12-16 12:17:14 +00:00
|
|
|
|
1999-10-04 09:03:48 +00:00
|
|
|
void wxToolBar::OnInternalIdle()
|
|
|
|
{
|
|
|
|
wxCursor cursor = m_cursor;
|
|
|
|
if (g_globalCursor.Ok()) cursor = g_globalCursor;
|
|
|
|
|
1999-10-05 19:38:05 +00:00
|
|
|
if (cursor.Ok())
|
1999-10-04 09:03:48 +00:00
|
|
|
{
|
1999-10-05 19:38:05 +00:00
|
|
|
/* I now set the cursor the anew in every OnInternalIdle call
|
1999-12-15 19:47:54 +00:00
|
|
|
as setting the cursor in a parent window also effects the
|
|
|
|
windows above so that checking for the current cursor is
|
|
|
|
not possible. */
|
1999-12-12 17:02:50 +00:00
|
|
|
|
|
|
|
if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
|
1999-10-04 09:03:48 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
/* if the toolbar is dockable, then m_widget stands for the
|
|
|
|
GtkHandleBox widget, which uses its own window so that we
|
|
|
|
can set the cursor for it. if the toolbar is not dockable,
|
|
|
|
m_widget comes from m_toolbar which uses its parent's
|
|
|
|
window ("windowless windows") and thus we cannot set the
|
|
|
|
cursor. */
|
|
|
|
gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxToolBarToolsList::Node *node = m_tools.GetFirst();
|
|
|
|
while ( node )
|
|
|
|
{
|
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
|
|
|
|
node = node->GetNext();
|
|
|
|
|
|
|
|
GtkWidget *item = tool->m_item;
|
|
|
|
if ( item )
|
|
|
|
{
|
|
|
|
GdkWindow *window = item->window;
|
|
|
|
|
|
|
|
if ( window )
|
|
|
|
{
|
|
|
|
gdk_window_set_cursor( window, cursor.GetCursor() );
|
|
|
|
}
|
|
|
|
}
|
1999-10-04 09:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateWindowUI();
|
|
|
|
}
|
|
|
|
|
1999-06-14 23:04:05 +00:00
|
|
|
#endif
|