]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/tbargtk.cpp
IS_KIND_OF -> wxIS_KIND_OF compilation fix
[wxWidgets.git] / src / gtk1 / tbargtk.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: tbargtk.cpp
3// Purpose: GTK toolbar
4// Author: Robert Roebling
32e9da8b 5// RCS-ID: $Id$
c801d85f 6// Copyright: (c) Robert Roebling
a3622daa 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "tbargtk.h"
12#endif
13
14#include "wx/toolbar.h"
15
314055fa
RR
16//-----------------------------------------------------------------------------
17// data
18//-----------------------------------------------------------------------------
19
20extern bool g_blockEventsOnDrag;
21
c801d85f
KB
22//-----------------------------------------------------------------------------
23// wxToolBarTool
24//-----------------------------------------------------------------------------
25
26IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject)
a3622daa
VZ
27
28wxToolBarTool::wxToolBarTool( wxToolBar *owner, int theIndex,
03f38c58
VZ
29 const wxBitmap& bitmap1, const wxBitmap& bitmap2,
30 bool toggle,
31 wxObject *clientData,
32 const wxString& shortHelpString,
33 const wxString& longHelpString,
34 GtkWidget *item )
c801d85f
KB
35{
36 m_owner = owner;
37 m_index = theIndex;
38 m_bitmap1 = bitmap1;
39 m_bitmap2 = bitmap2;
40 m_isToggle = toggle;
41 m_enabled = TRUE;
42 m_toggleState = FALSE;
43 m_shortHelpString = shortHelpString;
44 m_longHelpString = longHelpString;
45 m_isMenuCommand = TRUE;
46 m_clientData = clientData;
47 m_deleteSecondBitmap = FALSE;
fc008f25
RR
48 m_item = item;
49}
c801d85f 50
a3622daa 51wxToolBarTool::~wxToolBarTool()
c801d85f 52{
fc008f25 53}
c801d85f
KB
54
55//-----------------------------------------------------------------------------
2f2aa628 56// "clicked" (internal from gtk_toolbar)
c801d85f
KB
57//-----------------------------------------------------------------------------
58
59static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
60{
314055fa 61 if (g_blockEventsOnDrag) return;
c801d85f 62 if (!tool->m_enabled) return;
a3622daa 63
c801d85f 64 if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState;
a3622daa 65
c801d85f 66 tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
fc008f25 67}
c801d85f 68
2f2aa628
RR
69//-----------------------------------------------------------------------------
70// "enter_notify_event"
71//-----------------------------------------------------------------------------
72
314055fa
RR
73static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
74 GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool )
75{
76 if (g_blockEventsOnDrag) return TRUE;
77
78 tool->m_owner->OnMouseEnter( tool->m_index );
79
83058c58 80 return FALSE;
314055fa
RR
81}
82
2f2aa628
RR
83//-----------------------------------------------------------------------------
84// wxToolBar
c801d85f
KB
85//-----------------------------------------------------------------------------
86
716b7364 87IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
c801d85f 88
a3622daa 89wxToolBar::wxToolBar()
c801d85f 90{
fc008f25 91}
c801d85f 92
a3622daa 93wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
c801d85f 94 const wxPoint& pos, const wxSize& size,
debe6624 95 long style, const wxString& name )
c801d85f
KB
96{
97 Create( parent, id, pos, size, style, name );
fc008f25 98}
c801d85f 99
a3622daa 100wxToolBar::~wxToolBar()
c801d85f 101{
fc008f25 102}
c801d85f 103
a3622daa 104bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
c801d85f 105 const wxPoint& pos, const wxSize& size,
debe6624 106 long style, const wxString& name )
c801d85f
KB
107{
108 m_needParent = TRUE;
a3622daa 109
c801d85f
KB
110 PreCreation( parent, id, pos, size, style, name );
111
112 m_tools.DeleteContents( TRUE );
a3622daa 113
68dda785
VZ
114 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL,
115 GTK_TOOLBAR_ICONS ) );
a3622daa 116
32e9da8b
RR
117 m_widget = GTK_WIDGET(m_toolbar);
118
119 gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
b46e8696
RR
120
121 m_fg.red = 0;
122 m_fg.green = 0;
123 m_fg.blue = 0;
124 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), &m_fg );
125
126 m_bg.red = 65535;
127 m_bg.green = 65535;
128 m_bg.blue = 50000;
129 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), &m_bg );
130
131 gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, &m_bg, &m_fg );
a3622daa 132
907789a0
RR
133 gtk_toolbar_append_space( m_toolbar );
134
6ca41e57
RR
135 m_parent->AddChild( this );
136
137 (m_parent->m_insertCallback)( m_parent, this );
138
c801d85f 139 PostCreation();
a3622daa 140
c801d85f 141 Show( TRUE );
a3622daa 142
c801d85f 143 return TRUE;
fc008f25 144}
c801d85f 145
716b7364 146bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
c801d85f 147{
cf4219e7 148 wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
c801d85f 149 event.SetEventObject(this);
46dc76ba 150 event.SetInt( toolIndex );
c801d85f
KB
151 event.SetExtraLong((long) toggleDown);
152
153 GetEventHandler()->ProcessEvent(event);
154
155 return TRUE;
fc008f25 156}
c801d85f 157
716b7364 158void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
c801d85f 159{
cf4219e7 160 wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex );
46dc76ba
RR
161 event.SetEventObject( this );
162 event.SetInt( toolIndex );
c801d85f
KB
163
164 GetEventHandler()->ProcessEvent(event);
fc008f25 165}
c801d85f 166
716b7364 167void wxToolBar::OnMouseEnter( int toolIndex )
c801d85f 168{
314055fa 169 wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() );
c801d85f 170 event.SetEventObject(this);
46dc76ba 171 event.SetInt( toolIndex );
314055fa 172
c801d85f 173 GetEventHandler()->ProcessEvent(event);
fc008f25 174}
c801d85f 175
a3622daa 176wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
debe6624
JS
177 const wxBitmap& pushedBitmap, bool toggle,
178 float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData,
c801d85f
KB
179 const wxString& helpString1, const wxString& helpString2 )
180{
03f38c58
VZ
181 wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
182 "invalid bitmap for wxToolBar icon" );
a3622daa 183
03f38c58
VZ
184 wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
185 toggle, clientData,
186 helpString1, helpString2 );
a3622daa 187
03f38c58
VZ
188 wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
189 "wxToolBar doesn't support GdkBitmap" );
190
191 wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL,
192 "wxToolBar::Add needs a wxBitmap" );
903f689b 193
68dda785 194 GtkWidget *tool_pixmap = (GtkWidget *)NULL;
903f689b 195
03f38c58 196 if (TRUE) // FIXME huh?
903f689b
RR
197 {
198 GdkPixmap *pixmap = bitmap.GetPixmap();
a3622daa 199
68dda785
VZ
200 GdkBitmap *mask = (GdkBitmap *)NULL;
201 if ( bitmap.GetMask() )
202 mask = bitmap.GetMask()->GetBitmap();
903f689b
RR
203
204 tool_pixmap = gtk_pixmap_new( pixmap, mask );
205 }
206
c801d85f 207 gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
a3622daa 208
03f38c58
VZ
209 GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
210 : GTK_TOOLBAR_CHILD_BUTTON;
211
68dda785
VZ
212 GtkWidget *item = gtk_toolbar_append_element
213 (
214 GTK_TOOLBAR(m_toolbar),
215 ctype,
216 (GtkWidget *)NULL,
217 (const char *)NULL,
218 helpString1,
219 "",
220 tool_pixmap,
221 (GtkSignalFunc)gtk_toolbar_callback,
222 (gpointer)tool
223 );
224
68dda785 225 tool->m_item = item;
03f38c58
VZ
226
227 gtk_signal_connect( GTK_OBJECT(tool->m_item),
228 "enter_notify_event",
229 GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
230 (gpointer)tool );
314055fa 231
a3622daa
VZ
232 m_tools.Append( tool );
233
c801d85f 234 return tool;
fc008f25 235}
c801d85f 236
03f38c58 237void wxToolBar::AddSeparator()
c801d85f
KB
238{
239 gtk_toolbar_append_space( m_toolbar );
fc008f25 240}
c801d85f 241
03f38c58 242void wxToolBar::ClearTools()
c801d85f 243{
fc008f25
RR
244 wxFAIL_MSG( "wxToolBar::ClearTools not implemented" );
245}
c801d85f 246
03f38c58 247void wxToolBar::Realize()
46dc76ba
RR
248{
249 m_x = 0;
250 m_y = 0;
251 m_width = 100;
252 m_height = 0;
253
254 wxNode *node = m_tools.First();
255 while (node)
256 {
257 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
258 if (tool->m_bitmap1.Ok())
259 {
260 int tool_height = tool->m_bitmap1.GetHeight();
261 if (tool_height > m_height) m_height = tool_height;
fc008f25 262 }
46dc76ba
RR
263
264 node = node->Next();
fc008f25 265 }
46dc76ba 266
907789a0 267 m_height += 12;
fc008f25 268}
46dc76ba 269
716b7364 270void wxToolBar::EnableTool(int toolIndex, bool enable)
c801d85f 271{
cf4219e7
RR
272 wxNode *node = m_tools.First();
273 while (node)
274 {
275 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
276 if (tool->m_index == toolIndex)
277 {
278 tool->m_enabled = enable;
279 return;
280 }
281 node = node->Next();
fc008f25
RR
282 }
283
284 wxFAIL_MSG( "wrong toolbar index" );
285}
c801d85f 286
fc008f25 287void wxToolBar::ToggleTool( int toolIndex, bool toggle )
c801d85f 288{
fc008f25
RR
289 wxNode *node = m_tools.First();
290 while (node)
291 {
292 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
293 if (tool->m_index == toolIndex)
294 {
295 tool->m_toggleState = toggle;
296 if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item)))
297 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle );
298 return;
299 }
300 node = node->Next();
301 }
302
303 wxFAIL_MSG( "wrong toolbar index" );
304}
c801d85f 305
fc008f25 306wxObject *wxToolBar::GetToolClientData( int index ) const
c801d85f 307{
cf4219e7
RR
308 wxNode *node = m_tools.First();
309 while (node)
310 {
311 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
312 if (tool->m_index == index) return tool->m_clientData;;
313 node = node->Next();
fc008f25
RR
314 }
315
316 wxFAIL_MSG( "wrong toolbar index" );
317
cf4219e7 318 return (wxObject*)NULL;
fc008f25 319}
c801d85f 320
716b7364 321bool wxToolBar::GetToolState(int toolIndex) const
c801d85f 322{
cf4219e7
RR
323 wxNode *node = m_tools.First();
324 while (node)
325 {
326 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
327 if (tool->m_index == toolIndex) return tool->m_toggleState;
328 node = node->Next();
fc008f25
RR
329 }
330
331 wxFAIL_MSG( "wrong toolbar index" );
332
cf4219e7 333 return FALSE;
fc008f25 334}
c801d85f 335
716b7364 336bool wxToolBar::GetToolEnabled(int toolIndex) const
c801d85f 337{
cf4219e7
RR
338 wxNode *node = m_tools.First();
339 while (node)
340 {
341 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
342 if (tool->m_index == toolIndex) return tool->m_enabled;
343 node = node->Next();
fc008f25
RR
344 }
345
346 wxFAIL_MSG( "wrong toolbar index" );
347
cf4219e7 348 return FALSE;
fc008f25 349}
c801d85f 350
cf4219e7 351void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) )
c801d85f 352{
907789a0 353// wxFAIL_MSG( "wxToolBar::SetMargins not implemented" );
fc008f25 354}
c801d85f 355
cf4219e7 356void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
c801d85f 357{
03f38c58 358 wxFAIL_MSG( "wxToolBar::SetToolPacking not implemented" );
fc008f25 359}
c801d85f 360
cf4219e7 361void wxToolBar::SetToolSeparation( int separation )
c801d85f 362{
cf4219e7 363 gtk_toolbar_set_space_size( m_toolbar, separation );
fc008f25 364}
c801d85f 365