]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/toolbar.cpp
Merge wxBitmapButton and wxButton panels in the xrc sample.
[wxWidgets.git] / src / gtk / toolbar.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
0b83552a 2// Name: src/gtk/toolbar.cpp
c801d85f
KB
3// Purpose: GTK toolbar
4// Author: Robert Roebling
8a0681f9 5// Modified: 13.12.99 by VZ to derive from wxToolBarBase
32e9da8b 6// RCS-ID: $Id$
c801d85f 7// Copyright: (c) Robert Roebling
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
14f355c2
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
8a0681f9 14#if wxUSE_TOOLBAR_NATIVE
dcf924a3 15
4e3e485b
WS
16#include "wx/toolbar.h"
17
9e691f46 18#include "wx/gtk/private.h"
fc6557a6 19
8a0681f9
VZ
20// ----------------------------------------------------------------------------
21// globals
22// ----------------------------------------------------------------------------
acfd422a 23
314055fa 24// data
9b7e522a
RR
25extern bool g_blockEventsOnDrag;
26extern wxCursor g_globalCursor;
314055fa 27
8a0681f9
VZ
28// ----------------------------------------------------------------------------
29// wxToolBarTool
30// ----------------------------------------------------------------------------
31
32class wxToolBarTool : public wxToolBarToolBase
33{
34public:
35 wxToolBarTool(wxToolBar *tbar,
36 int id,
e76c0b5f 37 const wxString& label,
8a0681f9
VZ
38 const wxBitmap& bitmap1,
39 const wxBitmap& bitmap2,
e76c0b5f 40 wxItemKind kind,
8a0681f9
VZ
41 wxObject *clientData,
42 const wxString& shortHelpString,
43 const wxString& longHelpString)
e76c0b5f 44 : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
8a0681f9
VZ
45 clientData, shortHelpString, longHelpString)
46 {
a1cb0b11 47 m_item = NULL;
8a0681f9
VZ
48 }
49
07d02e9e
VZ
50 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
51 : wxToolBarToolBase(tbar, control, label)
8a0681f9 52 {
a1cb0b11 53 m_item = NULL;
1be45608
VZ
54 }
55
a1cb0b11
PC
56 void SetImage();
57 void CreateDropDown();
58 void ShowDropdown(GtkToggleButton* button);
8a0681f9 59
a1cb0b11 60 GtkToolItem* m_item;
8a0681f9
VZ
61};
62
63// ----------------------------------------------------------------------------
64// wxWin macros
65// ----------------------------------------------------------------------------
66
2eb10e2a 67IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
8a0681f9
VZ
68
69// ============================================================================
70// implementation
71// ============================================================================
72
c801d85f 73//-----------------------------------------------------------------------------
a1cb0b11 74// "clicked" from m_item
c801d85f
KB
75//-----------------------------------------------------------------------------
76
865bb325 77extern "C" {
a1cb0b11 78static void item_clicked(GtkToolButton*, wxToolBarTool* tool)
c801d85f 79{
1144d24d 80 if (g_blockEventsOnDrag) return;
a3622daa 81
a1cb0b11
PC
82 tool->GetToolBar()->OnLeftClick(tool->GetId(), false);
83}
84}
7062497f 85
a1cb0b11
PC
86//-----------------------------------------------------------------------------
87// "toggled" from m_item
88//-----------------------------------------------------------------------------
8a0681f9 89
a1cb0b11
PC
90extern "C" {
91static void item_toggled(GtkToggleToolButton* button, wxToolBarTool* tool)
92{
93 if (g_blockEventsOnDrag) return;
38762f09 94
a1cb0b11
PC
95 const bool active = gtk_toggle_tool_button_get_active(button) != 0;
96 tool->Toggle(active);
97 if (!active && tool->GetKind() == wxITEM_RADIO)
98 return;
a3622daa 99
a1cb0b11 100 if (!tool->GetToolBar()->OnLeftClick(tool->GetId(), active))
6bb7cee4
VZ
101 {
102 // revert back
103 tool->Toggle();
6bb7cee4 104 }
fc008f25 105}
865bb325 106}
c801d85f 107
729b4756 108//-----------------------------------------------------------------------------
a1cb0b11 109// "button_press_event" from m_item child
729b4756 110//-----------------------------------------------------------------------------
a1cb0b11 111
729b4756 112extern "C" {
a1cb0b11
PC
113static gboolean
114button_press_event(GtkWidget*, GdkEventButton* event, wxToolBarTool* tool)
729b4756
RR
115{
116 if (event->button != 3)
117 return FALSE;
118
729b4756 119 if (g_blockEventsOnDrag) return TRUE;
729b4756 120
a1cb0b11
PC
121 tool->GetToolBar()->OnRightClick(
122 tool->GetId(), int(event->x), int(event->y));
729b4756
RR
123
124 return TRUE;
125}
126}
127
fc6557a6 128//-----------------------------------------------------------------------------
a1cb0b11 129// "child_detached" from m_widget
fc6557a6
RR
130//-----------------------------------------------------------------------------
131
132extern "C" {
a1cb0b11 133static void child_detached(GtkWidget*, GtkToolbar* toolbar, void*)
fc6557a6 134{
a1cb0b11
PC
135 // disable showing overflow arrow when toolbar is detached,
136 // otherwise toolbar collapses to just an arrow
137 gtk_toolbar_set_show_arrow(toolbar, false);
fc6557a6
RR
138}
139}
140
141//-----------------------------------------------------------------------------
a1cb0b11 142// "child_attached" from m_widget
fc6557a6
RR
143//-----------------------------------------------------------------------------
144
a1cb0b11
PC
145extern "C" {
146static void child_attached(GtkWidget*, GtkToolbar* toolbar, void*)
fc6557a6 147{
a1cb0b11 148 gtk_toolbar_set_show_arrow(toolbar, true);
fc6557a6
RR
149}
150}
151
2f2aa628 152//-----------------------------------------------------------------------------
a1cb0b11 153// "enter_notify_event" / "leave_notify_event" from m_item
2f2aa628
RR
154//-----------------------------------------------------------------------------
155
865bb325 156extern "C" {
a1cb0b11
PC
157static gboolean
158enter_notify_event(GtkWidget*, GdkEventCrossing* event, wxToolBarTool* tool)
314055fa 159{
1144d24d 160 if (g_blockEventsOnDrag) return TRUE;
248bcf0a 161
a1cb0b11
PC
162 int id = -1;
163 if (event->type == GDK_ENTER_NOTIFY)
164 id = tool->GetId();
165 tool->GetToolBar()->OnMouseEnter(id);
248bcf0a 166
1144d24d 167 return FALSE;
314055fa 168}
865bb325 169}
314055fa 170
cca410b3
PC
171//-----------------------------------------------------------------------------
172// "size_request" from m_toolbar
173//-----------------------------------------------------------------------------
174
175extern "C" {
176static void
177size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
178{
179 const wxSize margins = win->GetMargins();
180 req->width += margins.x;
181 req->height += 2 * margins.y;
182}
183}
184
a1cb0b11
PC
185//-----------------------------------------------------------------------------
186// "expose_event" from GtkImage inside m_item
187//-----------------------------------------------------------------------------
188
189extern "C" {
190static gboolean
191image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
192{
193 const wxBitmap& bitmap = tool->GetDisabledBitmap();
194 if (tool->IsEnabled() || !bitmap.IsOk())
195 return false;
196
197 // draw disabled bitmap ourselves, GtkImage has no way to specify it
198 const GtkAllocation& alloc = widget->allocation;
199 gdk_draw_pixbuf(
200 widget->window, widget->style->black_gc, bitmap.GetPixbuf(),
201 0, 0,
202 alloc.x + (alloc.width - widget->requisition.width) / 2,
203 alloc.y + (alloc.height - widget->requisition.height) / 2,
204 -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
205 return true;
206}
207}
208
209//-----------------------------------------------------------------------------
210// "toggled" from dropdown menu button
211//-----------------------------------------------------------------------------
212
213extern "C" {
214static void arrow_toggled(GtkToggleButton* button, wxToolBarTool* tool)
215{
216 if (gtk_toggle_button_get_active(button))
217 {
218 tool->ShowDropdown(button);
219 gtk_toggle_button_set_active(button, false);
220 }
221}
222}
223
224//-----------------------------------------------------------------------------
225// "button_press_event" from dropdown menu button
226//-----------------------------------------------------------------------------
227
228extern "C" {
229static gboolean
230arrow_button_press_event(GtkToggleButton* button, GdkEventButton* event, wxToolBarTool* tool)
231{
232 if (event->button == 1)
233 {
234 g_signal_handlers_block_by_func(button, (void*)arrow_toggled, tool);
235 gtk_toggle_button_set_active(button, true);
236 tool->ShowDropdown(button);
237 gtk_toggle_button_set_active(button, false);
238 g_signal_handlers_unblock_by_func(button, (void*)arrow_toggled, tool);
239 return true;
240 }
241 return false;
242}
243}
244
48200154 245void wxToolBar::AddChildGTK(wxWindowGTK* child)
bf9e3e73 246{
205177b0
PC
247 GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
248 gtk_widget_show(align);
249 gtk_container_add(GTK_CONTAINER(align), child->m_widget);
250 GtkToolItem* item = gtk_tool_item_new();
251 gtk_container_add(GTK_CONTAINER(item), align);
205177b0 252 // position will be corrected in DoInsertTool if necessary
48200154 253 gtk_toolbar_insert(GTK_TOOLBAR(GTK_BIN(m_widget)->child), item, -1);
bf9e3e73
RR
254}
255
8a0681f9
VZ
256// ----------------------------------------------------------------------------
257// wxToolBarTool
258// ----------------------------------------------------------------------------
c801d85f 259
a1cb0b11 260void wxToolBarTool::SetImage()
8a0681f9 261{
a1cb0b11
PC
262 const wxBitmap& bitmap = GetNormalBitmap();
263 wxCHECK_RET(bitmap.IsOk(), "invalid bitmap for wxToolBar icon");
264
265 GtkWidget* image = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(m_item));
266 // always use pixbuf, because pixmap mask does not
267 // work with disabled images in some themes
268 gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
269}
270
271// helper to create a dropdown menu item
272void wxToolBarTool::CreateDropDown()
273{
274 gtk_tool_item_set_homogeneous(m_item, false);
275 GtkWidget* box;
276 GtkWidget* arrow;
277 if (GetToolBar()->HasFlag(wxTB_LEFT | wxTB_RIGHT))
278 {
279 box = gtk_vbox_new(false, 0);
280 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
281 }
282 else
283 {
284 box = gtk_hbox_new(false, 0);
285 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
286 }
287 GtkWidget* tool_button = GTK_BIN(m_item)->child;
288 gtk_widget_reparent(tool_button, box);
289 GtkWidget* arrow_button = gtk_toggle_button_new();
290 gtk_button_set_relief(GTK_BUTTON(arrow_button),
291 gtk_tool_item_get_relief_style(GTK_TOOL_ITEM(m_item)));
292 gtk_container_add(GTK_CONTAINER(arrow_button), arrow);
293 gtk_container_add(GTK_CONTAINER(box), arrow_button);
294 gtk_widget_show_all(box);
295 gtk_container_add(GTK_CONTAINER(m_item), box);
296
297 g_signal_connect(arrow_button, "toggled", G_CALLBACK(arrow_toggled), this);
298 g_signal_connect(arrow_button, "button_press_event",
299 G_CALLBACK(arrow_button_press_event), this);
300}
301
302void wxToolBarTool::ShowDropdown(GtkToggleButton* button)
303{
304 wxToolBarBase* toolbar = GetToolBar();
305 wxCommandEvent event(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, GetId());
306 if (!toolbar->HandleWindowEvent(event))
307 {
308 wxMenu* menu = GetDropdownMenu();
309 if (menu)
310 {
311 const GtkAllocation& alloc = GTK_WIDGET(button)->allocation;
312 int x = alloc.x;
313 int y = alloc.y;
314 if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT))
315 x += alloc.width;
316 else
317 y += alloc.height;
318 toolbar->PopupMenu(menu, x, y);
319 }
320 }
8a0681f9 321}
c801d85f 322
8a0681f9 323wxToolBarToolBase *wxToolBar::CreateTool(int id,
e76c0b5f 324 const wxString& text,
8a0681f9
VZ
325 const wxBitmap& bitmap1,
326 const wxBitmap& bitmap2,
e76c0b5f 327 wxItemKind kind,
8a0681f9
VZ
328 wxObject *clientData,
329 const wxString& shortHelpString,
330 const wxString& longHelpString)
331{
e76c0b5f 332 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
8a0681f9
VZ
333 clientData, shortHelpString, longHelpString);
334}
b1da76e1 335
07d02e9e
VZ
336wxToolBarToolBase *
337wxToolBar::CreateTool(wxControl *control, const wxString& label)
c801d85f 338{
07d02e9e 339 return new wxToolBarTool(this, control, label);
fc008f25 340}
c801d85f 341
8a0681f9
VZ
342//-----------------------------------------------------------------------------
343// wxToolBar construction
344//-----------------------------------------------------------------------------
345
346void wxToolBar::Init()
c801d85f 347{
d3b9f782 348 m_toolbar = NULL;
a1cb0b11 349 m_tooltips = NULL;
fc008f25 350}
c801d85f 351
a3622daa 352wxToolBar::~wxToolBar()
c801d85f 353{
a1cb0b11
PC
354 if (m_tooltips)
355 {
356 gtk_object_destroy(GTK_OBJECT(m_tooltips));
357 g_object_unref(m_tooltips);
358 }
fc008f25 359}
c801d85f 360
8a0681f9
VZ
361bool wxToolBar::Create( wxWindow *parent,
362 wxWindowID id,
363 const wxPoint& pos,
364 const wxSize& size,
365 long style,
366 const wxString& name )
c801d85f 367{
8a0681f9
VZ
368 if ( !PreCreation( parent, pos, size ) ||
369 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
4dcaf11a 370 {
223d09f6 371 wxFAIL_MSG( wxT("wxToolBar creation failed") );
c801d85f 372
91af0895 373 return false;
8a0681f9 374 }
a3622daa 375
d408730c
VZ
376 FixupStyle();
377
9e691f46 378 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
a1cb0b11
PC
379 m_tooltips = gtk_tooltips_new();
380 g_object_ref(m_tooltips);
352cd79f 381 gtk_object_sink(GTK_OBJECT(m_tooltips));
e76c0b5f 382 GtkSetStyle();
99e8cb50 383
3502e687
RR
384 if (style & wxTB_DOCKABLE)
385 {
386 m_widget = gtk_handle_box_new();
a1cb0b11
PC
387
388 g_signal_connect(m_widget, "child_detached",
389 G_CALLBACK(child_detached), NULL);
390 g_signal_connect(m_widget, "child_attached",
391 G_CALLBACK(child_attached), NULL);
8a0681f9 392
f03fc89f 393 if (style & wxTB_FLAT)
858b5bdd 394 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
3502e687
RR
395 }
396 else
248bcf0a
RD
397 {
398 m_widget = gtk_event_box_new();
248bcf0a 399 ConnectWidget( m_widget );
3502e687 400 }
9ff9d30c 401 g_object_ref(m_widget);
a1cb0b11
PC
402 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar));
403 gtk_widget_show(GTK_WIDGET(m_toolbar));
be25e480 404
f03fc89f 405 m_parent->DoAddChild( this );
8a0681f9 406
abdeb9e7 407 PostCreation(size);
a3622daa 408
cca410b3
PC
409 g_signal_connect_after(m_toolbar, "size_request",
410 G_CALLBACK(size_request), this);
411
91af0895 412 return true;
fc008f25 413}
c801d85f 414
e4161a2a 415GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
48468900
RR
416{
417 return GTK_WIDGET(m_toolbar)->window;
418}
419
e76c0b5f
VZ
420void wxToolBar::GtkSetStyle()
421{
a1cb0b11
PC
422 GtkOrientation orient = GTK_ORIENTATION_HORIZONTAL;
423 if (HasFlag(wxTB_LEFT | wxTB_RIGHT))
424 orient = GTK_ORIENTATION_VERTICAL;
425
426 GtkToolbarStyle style = GTK_TOOLBAR_ICONS;
427 if (HasFlag(wxTB_NOICONS))
428 style = GTK_TOOLBAR_TEXT;
429 else if (HasFlag(wxTB_TEXT))
430 {
431 style = GTK_TOOLBAR_BOTH;
432 if (HasFlag(wxTB_HORZ_LAYOUT))
433 style = GTK_TOOLBAR_BOTH_HORIZ;
434 }
e76c0b5f
VZ
435
436 gtk_toolbar_set_orientation(m_toolbar, orient);
437 gtk_toolbar_set_style(m_toolbar, style);
438}
439
440void wxToolBar::SetWindowStyleFlag( long style )
441{
442 wxToolBarBase::SetWindowStyleFlag(style);
8ad31f9d 443
e76c0b5f
VZ
444 if ( m_toolbar )
445 GtkSetStyle();
446}
447
9067c6c5
VZ
448bool wxToolBar::Realize()
449{
450 if ( !wxToolBarBase::Realize() )
451 return false;
452
453 // bring the initial state of all the toolbar items in line with the
454 // internal state if the latter was changed by calling wxToolBarTool::
455 // Enable(): this works under MSW, where the toolbar items are only created
456 // in Realize() which uses the internal state to determine the initial
457 // button state, so make it work under GTK too
458 for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
459 i != m_tools.end();
460 ++i )
461 {
462 // by default the toolbar items are enabled and not toggled, so we only
463 // have to do something if their internal state doesn't correspond to
464 // this
465 if ( !(*i)->IsEnabled() )
466 DoEnableTool(*i, false);
467 if ( (*i)->IsToggled() )
468 DoToggleTool(*i, true);
469 }
470
471 return true;
472}
473
8a0681f9 474bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 475{
5c33522f 476 wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
248bcf0a 477
a1cb0b11 478 GSList* radioGroup;
8a0681f9
VZ
479 switch ( tool->GetStyle() )
480 {
481 case wxTOOL_STYLE_BUTTON:
a1cb0b11 482 switch (tool->GetKind())
8a0681f9 483 {
a1cb0b11
PC
484 case wxITEM_CHECK:
485 tool->m_item = gtk_toggle_tool_button_new();
486 g_signal_connect(tool->m_item, "toggled",
487 G_CALLBACK(item_toggled), tool);
488 break;
489 case wxITEM_RADIO:
490 radioGroup = GetRadioGroup(pos);
491 if (radioGroup)
38762f09
VZ
492 {
493 // this is the first button in the radio button group,
494 // it will be toggled automatically by GTK so bring the
495 // internal flag in sync
91af0895 496 tool->Toggle(true);
38762f09 497 }
a1cb0b11
PC
498 tool->m_item = gtk_radio_tool_button_new(radioGroup);
499 g_signal_connect(tool->m_item, "toggled",
500 G_CALLBACK(item_toggled), tool);
501 break;
502 default:
503 wxFAIL_MSG("unknown toolbar child type");
504 // fall through
505 case wxITEM_DROPDOWN:
506 case wxITEM_NORMAL:
507 tool->m_item = gtk_tool_button_new(NULL, "");
508 g_signal_connect(tool->m_item, "clicked",
509 G_CALLBACK(item_clicked), tool);
510 break;
511 }
512 if (!HasFlag(wxTB_NOICONS))
513 {
514 GtkWidget* image = gtk_image_new();
515 gtk_tool_button_set_icon_widget(
516 GTK_TOOL_BUTTON(tool->m_item), image);
517 tool->SetImage();
518 gtk_widget_show(image);
519 g_signal_connect(image, "expose_event",
520 G_CALLBACK(image_expose_event), tool);
8a0681f9 521 }
a1cb0b11
PC
522 if (!tool->GetLabel().empty())
523 {
524 gtk_tool_button_set_label(
525 GTK_TOOL_BUTTON(tool->m_item), wxGTK_CONV(tool->GetLabel()));
526 // needed for labels in horizontal toolbar with wxTB_HORZ_LAYOUT
527 gtk_tool_item_set_is_important(tool->m_item, true);
528 }
529 if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
530 {
531 gtk_tool_item_set_tooltip(tool->m_item,
532 m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
533 }
534 g_signal_connect(GTK_BIN(tool->m_item)->child, "button_press_event",
535 G_CALLBACK(button_press_event), tool);
536 g_signal_connect(tool->m_item, "enter_notify_event",
537 G_CALLBACK(enter_notify_event), tool);
538 g_signal_connect(tool->m_item, "leave_notify_event",
539 G_CALLBACK(enter_notify_event), tool);
540
541 if (tool->GetKind() == wxITEM_DROPDOWN)
542 tool->CreateDropDown();
205177b0 543 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
8a0681f9
VZ
544 break;
545
546 case wxTOOL_STYLE_SEPARATOR:
a1cb0b11 547 tool->m_item = gtk_separator_tool_item_new();
cc260109
VZ
548 if ( tool->IsStretchable() )
549 {
550 gtk_separator_tool_item_set_draw
551 (
552 GTK_SEPARATOR_TOOL_ITEM(tool->m_item),
553 FALSE
554 );
555 gtk_tool_item_set_expand(tool->m_item, TRUE);
556 }
205177b0 557 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
1be45608 558 break;
bf9e3e73 559
8a0681f9 560 case wxTOOL_STYLE_CONTROL:
a1cb0b11 561 wxWindow* control = tool->GetControl();
205177b0 562 if (control->m_widget->parent == NULL)
48200154 563 AddChildGTK(control);
205177b0
PC
564 tool->m_item = GTK_TOOL_ITEM(control->m_widget->parent->parent);
565 if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos))
566 {
567 g_object_ref(tool->m_item);
568 gtk_container_remove(
569 GTK_CONTAINER(m_toolbar), GTK_WIDGET(tool->m_item));
570 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
571 g_object_unref(tool->m_item);
572 }
a1cb0b11
PC
573 // Inserted items "slide" into place using an animated effect that
574 // causes multiple size events on the item. Must set size request
575 // to keep item size from getting permanently set too small by the
576 // first of these size events.
577 const wxSize size = control->GetSize();
578 gtk_widget_set_size_request(control->m_widget, size.x, size.y);
8a0681f9
VZ
579 break;
580 }
a1cb0b11 581 gtk_widget_show(GTK_WIDGET(tool->m_item));
bf9e3e73 582
9f884528 583 InvalidateBestSize();
bf9e3e73 584
91af0895 585 return true;
bf9e3e73
RR
586}
587
a1cb0b11 588bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase)
c801d85f 589{
5c33522f 590 wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
c801d85f 591
a1cb0b11 592 if (tool->GetStyle() == wxTOOL_STYLE_CONTROL)
97d7bfb8 593 {
a1cb0b11
PC
594 // don't destroy the control here as we can be called from
595 // RemoveTool() and then we need to keep the control alive;
596 // while if we're called from DeleteTool() the control will
597 // be destroyed when wxToolBarToolBase itself is deleted
598 GtkWidget* widget = tool->GetControl()->m_widget;
599 gtk_container_remove(GTK_CONTAINER(widget->parent), widget);
8a0681f9 600 }
a1cb0b11
PC
601 gtk_object_destroy(GTK_OBJECT(tool->m_item));
602 tool->m_item = NULL;
c801d85f 603
9f884528 604 InvalidateBestSize();
91af0895 605 return true;
fc008f25 606}
46dc76ba 607
a1cb0b11
PC
608GSList* wxToolBar::GetRadioGroup(size_t pos)
609{
610 GSList* radioGroup = NULL;
611 GtkToolItem* item = NULL;
612 if (pos > 0)
613 {
614 item = gtk_toolbar_get_nth_item(m_toolbar, int(pos) - 1);
615 if (!GTK_IS_RADIO_TOOL_BUTTON(item))
616 item = NULL;
617 }
618 if (item == NULL && pos < m_tools.size())
619 {
620 item = gtk_toolbar_get_nth_item(m_toolbar, int(pos));
621 if (!GTK_IS_RADIO_TOOL_BUTTON(item))
622 item = NULL;
623 }
624 if (item)
625 radioGroup = gtk_radio_tool_button_get_group((GtkRadioToolButton*)item);
626 return radioGroup;
627}
628
8a0681f9
VZ
629// ----------------------------------------------------------------------------
630// wxToolBar tools state
631// ----------------------------------------------------------------------------
632
633void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
c801d85f 634{
5c33522f 635 wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
8a0681f9 636
8a0681f9 637 if (tool->m_item)
a1cb0b11 638 gtk_widget_set_sensitive(GTK_WIDGET(tool->m_item), enable);
fc008f25 639}
c801d85f 640
248bcf0a 641void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
c801d85f 642{
5c33522f 643 wxToolBarTool* tool = static_cast<wxToolBarTool*>(toolBase);
8a0681f9 644
a1cb0b11 645 if (tool->m_item)
1144d24d 646 {
a1cb0b11 647 g_signal_handlers_block_by_func(tool->m_item, (void*)item_toggled, tool);
8a0681f9 648
a1cb0b11
PC
649 gtk_toggle_tool_button_set_active(
650 GTK_TOGGLE_TOOL_BUTTON(tool->m_item), toggle);
248bcf0a 651
a1cb0b11 652 g_signal_handlers_unblock_by_func(tool->m_item, (void*)item_toggled, tool);
1144d24d 653 }
fc008f25 654}
c801d85f 655
8a0681f9
VZ
656void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
657 bool WXUNUSED(toggle))
c801d85f 658{
8a0681f9 659 // VZ: absolutely no idea about how to do it
9a83f860 660 wxFAIL_MSG( wxT("not implemented") );
fc008f25 661}
c801d85f 662
8a0681f9
VZ
663// ----------------------------------------------------------------------------
664// wxToolBar geometry
665// ----------------------------------------------------------------------------
666
a1cb0b11
PC
667wxSize wxToolBar::DoGetBestSize() const
668{
669 // Unfortunately, if overflow arrow is enabled GtkToolbar only reports size
670 // of arrow. To get the real size, the arrow is temporarily disabled here.
671 // This is gross, since it will cause a queue_resize, and could potentially
672 // lead to an infinite loop. But there seems to be no alternative, short of
673 // disabling the arrow entirely.
674 gtk_toolbar_set_show_arrow(m_toolbar, false);
675 const wxSize size = wxToolBarBase::DoGetBestSize();
676 gtk_toolbar_set_show_arrow(m_toolbar, true);
677 return size;
678}
679
8a0681f9
VZ
680wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
681 wxCoord WXUNUSED(y)) const
c801d85f 682{
8a0681f9 683 // VZ: GTK+ doesn't seem to have such thing
9a83f860 684 wxFAIL_MSG( wxT("wxToolBar::FindToolForPosition() not implemented") );
8a0681f9 685
d3b9f782 686 return NULL;
fc008f25 687}
c801d85f 688
a1f79c1e
VZ
689void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
690{
5c33522f 691 wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
a1f79c1e
VZ
692
693 if ( tool )
694 {
695 (void)tool->SetShortHelp(helpString);
a1cb0b11
PC
696 if (tool->m_item)
697 {
698 gtk_tool_item_set_tooltip(tool->m_item,
699 m_tooltips, wxGTK_CONV(helpString), "");
700 }
a1f79c1e
VZ
701 }
702}
703
bbd321ff
RD
704void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
705{
5c33522f 706 wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
bbd321ff
RD
707 if ( tool )
708 {
709 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
710
711 tool->SetNormalBitmap(bitmap);
a1cb0b11 712 tool->SetImage();
f4322df6 713 }
bbd321ff
RD
714}
715
716void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
717{
5c33522f 718 wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
bbd321ff
RD
719 if ( tool )
720 {
721 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
722
723 tool->SetDisabledBitmap(bitmap);
f4322df6 724 }
bbd321ff
RD
725}
726
8a0681f9
VZ
727// ----------------------------------------------------------------------------
728// wxToolBar idle handling
729// ----------------------------------------------------------------------------
1144d24d 730
9b7e522a
RR
731void wxToolBar::OnInternalIdle()
732{
1417c811 733 // Check if we have to show window now
71ead4bf 734 if (GTKShowFromOnIdle()) return;
f4322df6 735
ffa51479 736 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
e39af974 737 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
9b7e522a
RR
738}
739
9d522606
RD
740
741// ----------------------------------------------------------------------------
742
743// static
744wxVisualAttributes
745wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
746{
9d522606 747 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
9d522606
RD
748}
749
a1f79c1e 750#endif // wxUSE_TOOLBAR_NATIVE