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
|
|
|
|
2002-03-12 19:24:30 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include "wx/gtk/private.h"
|
1999-01-02 19:13:25 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
extern GdkFont *GtkGetDefaultGuiFont();
|
|
|
|
|
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
|
|
|
|
2002-03-25 21:38:18 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// translate wxWindows toolbar style flags to GTK orientation and style
|
|
|
|
static void GetGtkStyle(long style,
|
|
|
|
GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
|
|
|
|
{
|
|
|
|
*orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
|
|
|
|
: GTK_ORIENTATION_HORIZONTAL;
|
|
|
|
|
|
|
|
|
|
|
|
if ( style & wxTB_TEXT )
|
|
|
|
{
|
|
|
|
*gtkStyle = style & wxTB_NOICONS ? GTK_TOOLBAR_TEXT : GTK_TOOLBAR_BOTH;
|
|
|
|
}
|
|
|
|
else // no text, hence we must have the icons or what would we show?
|
|
|
|
{
|
|
|
|
*gtkStyle = GTK_TOOLBAR_ICONS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxToolBarTool
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxToolBarTool : public wxToolBarToolBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxToolBarTool(wxToolBar *tbar,
|
|
|
|
int id,
|
2002-03-25 21:38:18 +00:00
|
|
|
const wxString& label,
|
1999-12-15 19:47:54 +00:00
|
|
|
const wxBitmap& bitmap1,
|
|
|
|
const wxBitmap& bitmap2,
|
2002-03-25 21:38:18 +00:00
|
|
|
wxItemKind kind,
|
1999-12-15 19:47:54 +00:00
|
|
|
wxObject *clientData,
|
|
|
|
const wxString& shortHelpString,
|
|
|
|
const wxString& longHelpString)
|
2002-03-25 21:38:18 +00:00
|
|
|
: wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
|
1999-12-15 19:47:54 +00:00
|
|
|
clientData, shortHelpString, longHelpString)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
|
|
|
: wxToolBarToolBase(tbar, control)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2002-03-26 16:09:32 +00:00
|
|
|
// 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; }
|
|
|
|
|
2002-03-25 21:38:18 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
GtkWidget *m_item;
|
|
|
|
GtkWidget *m_pixmap;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void Init();
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-10-06 16:52:29 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
|
1999-12-15 19:47:54 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// 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
|
|
|
{
|
2002-09-05 22:58:06 +00:00
|
|
|
if (g_isIdle)
|
1999-10-31 16:42:46 +00:00
|
|
|
wxapp_install_idle_handler();
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2001-11-17 23:50:58 +00:00
|
|
|
if (tbar->m_blockEvent) 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())
|
2002-09-05 22:58:06 +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
|
|
|
}
|
2002-03-26 16:09:32 +00:00
|
|
|
|
|
|
|
if ( tool->IsRadio() && !tool->IsToggled() )
|
|
|
|
{
|
|
|
|
// radio button went up, don't report this as a wxWin event
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
//-----------------------------------------------------------------------------
|
2001-09-23 15:38:01 +00:00
|
|
|
// "enter_notify_event" / "leave_notify_event"
|
1998-09-02 12:15:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-09-05 22:58:06 +00:00
|
|
|
static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
|
2001-09-23 15:38:01 +00:00
|
|
|
GdkEventCrossing *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;
|
2002-09-05 22:58:06 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2000-12-16 12:27:26 +00:00
|
|
|
// emit the event
|
2001-09-23 15:38:01 +00:00
|
|
|
if( gdk_event->type == GDK_ENTER_NOTIFY )
|
|
|
|
tb->OnMouseEnter( tool->GetId() );
|
|
|
|
else
|
|
|
|
tb->OnMouseEnter( -1 );
|
2002-09-05 22:58:06 +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
|
|
|
{
|
2000-12-16 12:27:26 +00:00
|
|
|
// we don't do anything here
|
1999-11-14 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2002-03-25 21:38:18 +00:00
|
|
|
const wxString& text,
|
1999-12-15 19:47:54 +00:00
|
|
|
const wxBitmap& bitmap1,
|
|
|
|
const wxBitmap& bitmap2,
|
2002-03-25 21:38:18 +00:00
|
|
|
wxItemKind kind,
|
1999-12-15 19:47:54 +00:00
|
|
|
wxObject *clientData,
|
|
|
|
const wxString& shortHelpString,
|
|
|
|
const wxString& longHelpString)
|
|
|
|
{
|
2002-03-25 21:38:18 +00:00
|
|
|
return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
|
1999-12-15 19:47:54 +00:00
|
|
|
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;
|
2001-11-17 23:50:58 +00:00
|
|
|
m_blockEvent = 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
|
|
|
|
2002-03-12 19:24:30 +00:00
|
|
|
#ifdef __WXGTK20__
|
|
|
|
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
|
2002-03-25 21:38:18 +00:00
|
|
|
GtkSetStyle();
|
2002-12-04 14:11:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2002-03-12 19:24:30 +00:00
|
|
|
#else
|
2002-03-25 21:38:18 +00:00
|
|
|
GtkOrientation orient;
|
|
|
|
GtkToolbarStyle gtkStyle;
|
|
|
|
GetGtkStyle(style, &orient, >kStyle);
|
|
|
|
|
|
|
|
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new(orient, gtkStyle) );
|
2002-03-12 19:24:30 +00:00
|
|
|
#endif
|
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-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-02-10 23:08:27 +00:00
|
|
|
}
|
|
|
|
else
|
2002-09-05 22:58:06 +00:00
|
|
|
{
|
|
|
|
m_widget = gtk_event_box_new();
|
|
|
|
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
|
|
|
ConnectWidget( m_widget );
|
|
|
|
gtk_widget_show(GTK_WIDGET(m_toolbar));
|
1999-02-10 23:08:27 +00:00
|
|
|
}
|
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
|
|
|
|
2002-03-12 19:24:30 +00:00
|
|
|
// FIXME: there is no such function for toolbars in 2.0
|
|
|
|
#ifndef __WXGTK20__
|
1999-05-03 12:19:16 +00:00
|
|
|
if (style & wxTB_FLAT)
|
|
|
|
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
2002-03-12 19:24:30 +00:00
|
|
|
#endif
|
1999-12-27 13:01:07 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
|
|
|
|
m_fg = new GdkColor;
|
2002-09-05 22:58:06 +00:00
|
|
|
m_fg->red = 0;
|
|
|
|
m_fg->green = 0;
|
1999-01-02 19:13:25 +00:00
|
|
|
m_fg->blue = 0;
|
1999-12-27 13:01:07 +00:00
|
|
|
wxColour fg(0,0,0);
|
|
|
|
fg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
|
|
|
m_fg->pixel = fg.GetPixel();
|
2002-09-05 22:58:06 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
m_bg = new GdkColor;
|
|
|
|
m_bg->red = 65535;
|
|
|
|
m_bg->green = 65535;
|
1999-12-27 13:01:07 +00:00
|
|
|
m_bg->blue = 49980;
|
|
|
|
wxColour bg(255,255,196);
|
|
|
|
bg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
|
|
|
m_bg->pixel = bg.GetPixel();
|
2002-09-05 22:58:06 +00:00
|
|
|
|
1999-05-02 09:19:44 +00:00
|
|
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
|
|
|
|
2002-09-05 22:58:06 +00:00
|
|
|
GtkStyle *g_style =
|
1999-12-15 19:47:54 +00:00
|
|
|
gtk_style_copy(
|
2002-09-05 22:58:06 +00:00
|
|
|
gtk_widget_get_style(
|
1999-12-15 19:47:54 +00:00
|
|
|
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
|
|
|
|
1999-05-02 09:19:44 +00:00
|
|
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
2002-03-12 19:24:30 +00:00
|
|
|
|
1999-05-02 09:19:44 +00:00
|
|
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
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
|
|
|
|
2002-03-25 21:38:18 +00:00
|
|
|
void wxToolBar::GtkSetStyle()
|
|
|
|
{
|
|
|
|
GtkOrientation orient;
|
|
|
|
GtkToolbarStyle style;
|
|
|
|
GetGtkStyle(GetWindowStyle(), &orient, &style);
|
|
|
|
|
|
|
|
gtk_toolbar_set_orientation(m_toolbar, orient);
|
|
|
|
gtk_toolbar_set_style(m_toolbar, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxToolBar::SetWindowStyleFlag( long style )
|
|
|
|
{
|
|
|
|
wxToolBarBase::SetWindowStyleFlag(style);
|
|
|
|
|
|
|
|
if ( m_toolbar )
|
|
|
|
GtkSetStyle();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#ifndef __WXGTK20__
|
2002-09-06 18:28:58 +00:00
|
|
|
// if we have inserted a space before all the tools we must change the GTK
|
|
|
|
// index by 1
|
|
|
|
size_t posGtk = m_xMargin > 1 ? pos + 1 : pos;
|
2002-12-04 14:11:26 +00:00
|
|
|
#else
|
|
|
|
size_t posGtk = pos;
|
|
|
|
#endif
|
2002-09-05 22:58:06 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
if ( tool->IsButton() )
|
|
|
|
{
|
2002-12-04 14:11:26 +00:00
|
|
|
if ( !HasFlag(wxTB_NOICONS) )
|
|
|
|
{
|
|
|
|
wxBitmap bitmap = tool->GetNormalBitmap();
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
wxCHECK_MSG( bitmap.Ok(), FALSE,
|
|
|
|
wxT("invalid bitmap for wxToolBar icon") );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
|
|
|
|
wxT("wxToolBar doesn't support GdkBitmap") );
|
1998-10-12 13:09:15 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE,
|
|
|
|
wxT("wxToolBar::Add needs a wxBitmap") );
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
GdkPixmap *pixmap = bitmap.GetPixmap();
|
1998-08-07 15:09:04 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
GdkBitmap *mask = (GdkBitmap *)NULL;
|
|
|
|
if ( bitmap.GetMask() )
|
|
|
|
mask = bitmap.GetMask()->GetBitmap();
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
tool_pixmap = gtk_pixmap_new( pixmap, mask );
|
|
|
|
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
|
1998-08-07 15:09:04 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
tool->m_pixmap = tool_pixmap;
|
|
|
|
}
|
1999-12-15 19:47:54 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
switch ( tool->GetStyle() )
|
|
|
|
{
|
|
|
|
case wxTOOL_STYLE_BUTTON:
|
2002-03-26 16:09:32 +00:00
|
|
|
// for a radio button we need the widget which starts the radio
|
|
|
|
// group it belongs to, i.e. the first radio button immediately
|
|
|
|
// preceding this one
|
1999-12-15 19:47:54 +00:00
|
|
|
{
|
2002-03-26 16:09:32 +00:00
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
|
|
|
|
if ( tool->IsRadio() )
|
|
|
|
{
|
|
|
|
wxToolBarToolsList::Node *node = pos ? m_tools.Item(pos - 1)
|
|
|
|
: NULL;
|
|
|
|
while ( node )
|
|
|
|
{
|
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
|
|
|
|
if ( !tool->IsRadio() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
widget = tool->m_item;
|
|
|
|
|
|
|
|
node = node->GetPrevious();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !widget )
|
|
|
|
{
|
|
|
|
// this is the first button in the radio button group,
|
|
|
|
// it will be toggled automatically by GTK so bring the
|
|
|
|
// internal flag in sync
|
|
|
|
tool->Toggle(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->m_item = gtk_toolbar_insert_element
|
|
|
|
(
|
|
|
|
m_toolbar,
|
|
|
|
tool->GetGtkChildType(),
|
|
|
|
widget,
|
|
|
|
tool->GetLabel().empty()
|
|
|
|
? NULL
|
2002-08-05 17:59:20 +00:00
|
|
|
: (const char*) wxGTK_CONV( tool->GetLabel() ),
|
2002-03-26 16:09:32 +00:00
|
|
|
tool->GetShortHelp().empty()
|
|
|
|
? NULL
|
2002-08-05 17:59:20 +00:00
|
|
|
: (const char*) wxGTK_CONV( tool->GetShortHelp() ),
|
2002-03-26 16:09:32 +00:00
|
|
|
"", // tooltip_private_text (?)
|
|
|
|
tool->m_pixmap,
|
|
|
|
(GtkSignalFunc)gtk_toolbar_callback,
|
|
|
|
(gpointer)tool,
|
2002-09-06 18:28:58 +00:00
|
|
|
posGtk
|
2002-03-26 16:09:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !tool->m_item )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
|
2002-03-26 16:09:32 +00:00
|
|
|
gtk_signal_connect( GTK_OBJECT(tool->m_item),
|
2002-09-05 22:58:06 +00:00
|
|
|
"enter_notify_event",
|
2002-03-26 16:09:32 +00:00
|
|
|
GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
|
|
|
|
(gpointer)tool );
|
|
|
|
gtk_signal_connect( GTK_OBJECT(tool->m_item),
|
2002-09-05 22:58:06 +00:00
|
|
|
"leave_notify_event",
|
2002-03-26 16:09:32 +00:00
|
|
|
GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
|
|
|
|
(gpointer)tool );
|
1999-12-15 19:47:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxTOOL_STYLE_SEPARATOR:
|
2002-09-06 18:28:58 +00:00
|
|
|
gtk_toolbar_insert_space( m_toolbar, posGtk );
|
1999-12-15 19:47:54 +00:00
|
|
|
|
|
|
|
// 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,
|
2002-09-06 18:28:58 +00:00
|
|
|
posGtk
|
1999-12-15 19:47:54 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
1999-11-14 15:14:23 +00:00
|
|
|
|
|
|
|
GtkRequisition req;
|
2000-07-19 10:28:26 +00:00
|
|
|
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->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-12-15 19:47:54 +00:00
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
|
|
|
|
|
|
|
if (tool->m_item)
|
2002-08-05 17:59:20 +00:00
|
|
|
{
|
1999-12-15 19:47:54 +00:00
|
|
|
gtk_widget_set_sensitive( tool->m_item, enable );
|
2002-08-05 17:59:20 +00:00
|
|
|
}
|
1998-08-13 09:11:23 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2002-09-05 22:58:06 +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
|
|
|
|
2001-11-17 23:50:58 +00:00
|
|
|
m_blockEvent = TRUE;
|
1999-12-15 19:47:54 +00:00
|
|
|
|
|
|
|
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle );
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2001-11-17 23:50:58 +00:00
|
|
|
m_blockEvent = FALSE;
|
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.") );
|
2002-09-05 22:58:06 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#ifndef __WXGTK20__
|
2002-09-06 18:28:58 +00:00
|
|
|
if (x > 1)
|
|
|
|
gtk_toolbar_append_space( m_toolbar ); // oh well
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
2002-09-05 22:58:06 +00:00
|
|
|
|
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
|
|
|
{
|
2002-03-12 19:24:30 +00:00
|
|
|
// FIXME: this function disappeared
|
|
|
|
#ifndef __WXGTK20__
|
1998-12-16 12:17:14 +00:00
|
|
|
gtk_toolbar_set_space_size( m_toolbar, separation );
|
2002-03-12 19:24:30 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-15 19:47:54 +00:00
|
|
|
m_toolSeparation = separation;
|
1998-12-16 12:17:14 +00:00
|
|
|
}
|
|
|
|
|
2000-11-24 17:07:12 +00:00
|
|
|
void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
|
|
|
|
{
|
|
|
|
wxToolBarTool *tool = (wxToolBarTool *)FindById(id);
|
|
|
|
|
|
|
|
if ( tool )
|
|
|
|
{
|
|
|
|
(void)tool->SetShortHelp(helpString);
|
|
|
|
gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
|
2002-08-05 17:59:20 +00:00
|
|
|
wxGTK_CONV( helpString ), "");
|
2000-11-24 17:07:12 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-07 16:21:44 +00:00
|
|
|
if (wxUpdateUIEvent::CanUpdate())
|
|
|
|
UpdateWindowUI();
|
1999-10-04 09:03:48 +00:00
|
|
|
}
|
|
|
|
|
2000-11-24 17:07:12 +00:00
|
|
|
#endif // wxUSE_TOOLBAR_NATIVE
|