]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
76b49cf4 | 2 | // Name: src/gtk/tbargtk.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 | ||
8a0681f9 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
14f355c2 VS |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
8a0681f9 | 22 | #if wxUSE_TOOLBAR_NATIVE |
dcf924a3 | 23 | |
4e3e485b WS |
24 | #include "wx/toolbar.h" |
25 | ||
76b49cf4 WS |
26 | #ifndef WX_PRECOMP |
27 | #include "wx/frame.h" | |
28 | #endif | |
c801d85f | 29 | |
1efb5db8 MR |
30 | // FIXME: Use GtkImage instead of GtkPixmap. Use the new toolbar API for when gtk runtime is new enough? |
31 | // Beware that the new and old toolbar API may not be mixed in usage. | |
32 | #include <gtk/gtkversion.h> | |
33 | #ifdef GTK_DISABLE_DEPRECATED | |
34 | #undef GTK_DISABLE_DEPRECATED | |
35 | #endif | |
36 | ||
9e691f46 | 37 | #include "wx/gtk/private.h" |
83624f79 | 38 | |
8a0681f9 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // globals | |
41 | // ---------------------------------------------------------------------------- | |
acfd422a | 42 | |
314055fa | 43 | // data |
9b7e522a RR |
44 | extern bool g_blockEventsOnDrag; |
45 | extern wxCursor g_globalCursor; | |
314055fa | 46 | |
e76c0b5f VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // private functions | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
77ffb593 | 51 | // translate wxWidgets toolbar style flags to GTK orientation and style |
e76c0b5f VZ |
52 | static void GetGtkStyle(long style, |
53 | GtkOrientation *orient, GtkToolbarStyle *gtkStyle) | |
54 | { | |
7a976304 | 55 | *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; |
e76c0b5f VZ |
56 | |
57 | ||
58 | if ( style & wxTB_TEXT ) | |
59 | { | |
99e8cb50 VZ |
60 | *gtkStyle = style & wxTB_NOICONS |
61 | ? GTK_TOOLBAR_TEXT | |
62 | : ( | |
99e8cb50 | 63 | style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ : |
99e8cb50 | 64 | GTK_TOOLBAR_BOTH); |
e76c0b5f VZ |
65 | } |
66 | else // no text, hence we must have the icons or what would we show? | |
67 | { | |
68 | *gtkStyle = GTK_TOOLBAR_ICONS; | |
69 | } | |
70 | } | |
71 | ||
8a0681f9 VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // wxToolBarTool | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | class wxToolBarTool : public wxToolBarToolBase | |
77 | { | |
78 | public: | |
79 | wxToolBarTool(wxToolBar *tbar, | |
80 | int id, | |
e76c0b5f | 81 | const wxString& label, |
8a0681f9 VZ |
82 | const wxBitmap& bitmap1, |
83 | const wxBitmap& bitmap2, | |
e76c0b5f | 84 | wxItemKind kind, |
8a0681f9 VZ |
85 | wxObject *clientData, |
86 | const wxString& shortHelpString, | |
87 | const wxString& longHelpString) | |
e76c0b5f | 88 | : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
89 | clientData, shortHelpString, longHelpString) |
90 | { | |
91 | Init(); | |
92 | } | |
93 | ||
94 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
95 | : wxToolBarToolBase(tbar, control) | |
96 | { | |
97 | Init(); | |
98 | } | |
99 | ||
38762f09 VZ |
100 | // is this a radio button? |
101 | // | |
102 | // unlike GetKind(), can be called for any kind of tools, not just buttons | |
103 | bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; } | |
104 | ||
e76c0b5f VZ |
105 | // this is only called for the normal buttons, i.e. not separators nor |
106 | // controls | |
107 | GtkToolbarChildType GetGtkChildType() const | |
108 | { | |
109 | switch ( GetKind() ) | |
110 | { | |
111 | case wxITEM_CHECK: | |
112 | return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
113 | ||
114 | case wxITEM_RADIO: | |
115 | return GTK_TOOLBAR_CHILD_RADIOBUTTON; | |
116 | ||
117 | default: | |
118 | wxFAIL_MSG( _T("unknown toolbar child type") ); | |
119 | // fall through | |
120 | ||
121 | case wxITEM_NORMAL: | |
122 | return GTK_TOOLBAR_CHILD_BUTTON; | |
123 | } | |
124 | } | |
125 | ||
eba91e51 | 126 | void SetImage(const wxBitmap& bitmap) |
ab86c659 VS |
127 | { |
128 | if (bitmap.Ok()) | |
129 | { | |
eba91e51 PC |
130 | // setting from pixmap doesn't seem to work right, but pixbuf works well |
131 | gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf()); | |
ab86c659 VS |
132 | } |
133 | } | |
134 | ||
8a0681f9 | 135 | GtkWidget *m_item; |
eba91e51 | 136 | GtkWidget *m_image; |
8a0681f9 VZ |
137 | |
138 | protected: | |
139 | void Init(); | |
140 | }; | |
141 | ||
142 | // ---------------------------------------------------------------------------- | |
143 | // wxWin macros | |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
2eb10e2a | 146 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
8a0681f9 VZ |
147 | |
148 | // ============================================================================ | |
149 | // implementation | |
150 | // ============================================================================ | |
151 | ||
c801d85f | 152 | //----------------------------------------------------------------------------- |
2f2aa628 | 153 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
154 | //----------------------------------------------------------------------------- |
155 | ||
865bb325 | 156 | extern "C" { |
8a0681f9 VZ |
157 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), |
158 | wxToolBarTool *tool ) | |
c801d85f | 159 | { |
248bcf0a | 160 | if (g_isIdle) |
59fe1666 RR |
161 | wxapp_install_idle_handler(); |
162 | ||
8a0681f9 | 163 | wxToolBar *tbar = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 164 | |
9864c56d | 165 | if (tbar->m_blockEvent) return; |
acfd422a | 166 | |
1144d24d | 167 | if (g_blockEventsOnDrag) return; |
8a0681f9 | 168 | if (!tool->IsEnabled()) return; |
a3622daa | 169 | |
8a0681f9 | 170 | if (tool->CanBeToggled()) |
248bcf0a | 171 | { |
8a0681f9 VZ |
172 | tool->Toggle(); |
173 | ||
eba91e51 | 174 | tool->SetImage(tool->GetBitmap()); |
38762f09 VZ |
175 | |
176 | if ( tool->IsRadio() && !tool->IsToggled() ) | |
177 | { | |
178 | // radio button went up, don't report this as a wxWin event | |
179 | return; | |
180 | } | |
85eb36c2 | 181 | } |
a3622daa | 182 | |
6bb7cee4 VZ |
183 | if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() ) |
184 | { | |
185 | // revert back | |
186 | tool->Toggle(); | |
187 | ||
eba91e51 | 188 | tool->SetImage(tool->GetBitmap()); |
6bb7cee4 | 189 | } |
fc008f25 | 190 | } |
865bb325 | 191 | } |
c801d85f | 192 | |
2f2aa628 | 193 | //----------------------------------------------------------------------------- |
a8945eef | 194 | // "enter_notify_event" / "leave_notify_event" |
2f2aa628 RR |
195 | //----------------------------------------------------------------------------- |
196 | ||
865bb325 | 197 | extern "C" { |
248bcf0a | 198 | static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), |
a8945eef MB |
199 | GdkEventCrossing *gdk_event, |
200 | wxToolBarTool *tool ) | |
314055fa | 201 | { |
14819684 | 202 | // don't need to install idle handler, its done from "event" signal |
acfd422a | 203 | |
1144d24d | 204 | if (g_blockEventsOnDrag) return TRUE; |
248bcf0a | 205 | |
8a0681f9 | 206 | wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 207 | |
47c93b63 | 208 | // emit the event |
a8945eef MB |
209 | if( gdk_event->type == GDK_ENTER_NOTIFY ) |
210 | tb->OnMouseEnter( tool->GetId() ); | |
211 | else | |
212 | tb->OnMouseEnter( -1 ); | |
248bcf0a | 213 | |
1144d24d | 214 | return FALSE; |
314055fa | 215 | } |
865bb325 | 216 | } |
314055fa | 217 | |
86b65467 RR |
218 | extern "C" { |
219 | static | |
220 | void gtktoolwidget_size_callback( GtkWidget *widget, | |
221 | GtkAllocation *alloc, | |
222 | wxWindow *win ) | |
223 | { | |
224 | // this shouldn't happen... | |
225 | if (win->GetParent()->m_wxwindow) return; | |
f4322df6 | 226 | |
86b65467 RR |
227 | wxSize size = win->GetEffectiveMinSize(); |
228 | if (size.y != alloc->height) | |
229 | { | |
230 | GtkAllocation alloc2; | |
231 | alloc2.x = alloc->x; | |
232 | alloc2.y = (alloc->height - size.y + 3) / 2; | |
233 | alloc2.width = alloc->width; | |
234 | alloc2.height = size.y; | |
235 | gtk_widget_size_allocate( widget, &alloc2 ); | |
236 | } | |
237 | } | |
238 | } | |
bf9e3e73 RR |
239 | //----------------------------------------------------------------------------- |
240 | // InsertChild callback for wxToolBar | |
241 | //----------------------------------------------------------------------------- | |
242 | ||
8a0681f9 VZ |
243 | static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), |
244 | wxWindow* WXUNUSED(child) ) | |
bf9e3e73 | 245 | { |
47c93b63 | 246 | // we don't do anything here |
bf9e3e73 RR |
247 | } |
248 | ||
8a0681f9 VZ |
249 | // ---------------------------------------------------------------------------- |
250 | // wxToolBarTool | |
251 | // ---------------------------------------------------------------------------- | |
c801d85f | 252 | |
8a0681f9 VZ |
253 | void wxToolBarTool::Init() |
254 | { | |
255 | m_item = | |
eba91e51 | 256 | m_image = NULL; |
8a0681f9 | 257 | } |
c801d85f | 258 | |
8a0681f9 | 259 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
e76c0b5f | 260 | const wxString& text, |
8a0681f9 VZ |
261 | const wxBitmap& bitmap1, |
262 | const wxBitmap& bitmap2, | |
e76c0b5f | 263 | wxItemKind kind, |
8a0681f9 VZ |
264 | wxObject *clientData, |
265 | const wxString& shortHelpString, | |
266 | const wxString& longHelpString) | |
267 | { | |
e76c0b5f | 268 | return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
269 | clientData, shortHelpString, longHelpString); |
270 | } | |
b1da76e1 | 271 | |
8a0681f9 | 272 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) |
c801d85f | 273 | { |
8a0681f9 | 274 | return new wxToolBarTool(this, control); |
fc008f25 | 275 | } |
c801d85f | 276 | |
8a0681f9 VZ |
277 | //----------------------------------------------------------------------------- |
278 | // wxToolBar construction | |
279 | //----------------------------------------------------------------------------- | |
280 | ||
281 | void wxToolBar::Init() | |
c801d85f | 282 | { |
8a0681f9 | 283 | m_toolbar = (GtkToolbar *)NULL; |
91af0895 | 284 | m_blockEvent = false; |
d2c0a964 RD |
285 | m_defaultWidth = 32; |
286 | m_defaultHeight = 32; | |
fc008f25 | 287 | } |
c801d85f | 288 | |
a3622daa | 289 | wxToolBar::~wxToolBar() |
c801d85f | 290 | { |
fc008f25 | 291 | } |
c801d85f | 292 | |
8a0681f9 VZ |
293 | bool wxToolBar::Create( wxWindow *parent, |
294 | wxWindowID id, | |
295 | const wxPoint& pos, | |
296 | const wxSize& size, | |
297 | long style, | |
298 | const wxString& name ) | |
c801d85f | 299 | { |
91af0895 | 300 | m_needParent = true; |
bf9e3e73 | 301 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; |
a3622daa | 302 | |
8a0681f9 VZ |
303 | if ( !PreCreation( parent, pos, size ) || |
304 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
4dcaf11a | 305 | { |
223d09f6 | 306 | wxFAIL_MSG( wxT("wxToolBar creation failed") ); |
c801d85f | 307 | |
91af0895 | 308 | return false; |
8a0681f9 | 309 | } |
a3622daa | 310 | |
d408730c VZ |
311 | FixupStyle(); |
312 | ||
9e691f46 | 313 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); |
e76c0b5f | 314 | GtkSetStyle(); |
99e8cb50 | 315 | |
2b5f62a0 VZ |
316 | // Doesn't work this way. |
317 | // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY; | |
318 | // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL); | |
a3622daa | 319 | |
8a0681f9 | 320 | SetToolSeparation(7); |
3502e687 RR |
321 | |
322 | if (style & wxTB_DOCKABLE) | |
323 | { | |
324 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
325 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
326 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
8a0681f9 | 327 | |
f03fc89f | 328 | if (style & wxTB_FLAT) |
858b5bdd | 329 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
3502e687 RR |
330 | } |
331 | else | |
248bcf0a RD |
332 | { |
333 | m_widget = gtk_event_box_new(); | |
334 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); | |
335 | ConnectWidget( m_widget ); | |
336 | gtk_widget_show(GTK_WIDGET(m_toolbar)); | |
3502e687 | 337 | } |
8a0681f9 | 338 | |
9e691f46 | 339 | // FIXME: there is no such function for toolbars in 2.0 |
68567a96 | 340 | #if 0 |
858b5bdd RR |
341 | if (style & wxTB_FLAT) |
342 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
9e691f46 | 343 | #endif |
be25e480 | 344 | |
f03fc89f | 345 | m_parent->DoAddChild( this ); |
8a0681f9 | 346 | |
abdeb9e7 | 347 | PostCreation(size); |
a3622daa | 348 | |
91af0895 | 349 | return true; |
fc008f25 | 350 | } |
c801d85f | 351 | |
48468900 RR |
352 | GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const |
353 | { | |
354 | return GTK_WIDGET(m_toolbar)->window; | |
355 | } | |
356 | ||
e76c0b5f VZ |
357 | void wxToolBar::GtkSetStyle() |
358 | { | |
359 | GtkOrientation orient; | |
360 | GtkToolbarStyle style; | |
361 | GetGtkStyle(GetWindowStyle(), &orient, &style); | |
362 | ||
363 | gtk_toolbar_set_orientation(m_toolbar, orient); | |
364 | gtk_toolbar_set_style(m_toolbar, style); | |
8c4e2405 | 365 | gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS)); |
e76c0b5f VZ |
366 | } |
367 | ||
368 | void wxToolBar::SetWindowStyleFlag( long style ) | |
369 | { | |
370 | wxToolBarBase::SetWindowStyleFlag(style); | |
8ad31f9d | 371 | |
e76c0b5f VZ |
372 | if ( m_toolbar ) |
373 | GtkSetStyle(); | |
374 | } | |
375 | ||
8a0681f9 | 376 | bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 377 | { |
8c4e2405 | 378 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); |
248bcf0a | 379 | |
8a0681f9 VZ |
380 | if ( tool->IsButton() ) |
381 | { | |
2b5f62a0 VZ |
382 | if ( !HasFlag(wxTB_NOICONS) ) |
383 | { | |
384 | wxBitmap bitmap = tool->GetNormalBitmap(); | |
c801d85f | 385 | |
91af0895 | 386 | wxCHECK_MSG( bitmap.Ok(), false, |
2b5f62a0 | 387 | wxT("invalid bitmap for wxToolBar icon") ); |
a3622daa | 388 | |
eba91e51 PC |
389 | tool->m_image = gtk_image_new(); |
390 | tool->SetImage(bitmap); | |
248bcf0a | 391 | |
eba91e51 | 392 | gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5); |
2b5f62a0 | 393 | } |
8a0681f9 | 394 | } |
c801d85f | 395 | |
8c4e2405 PC |
396 | const int posGtk = int(pos); |
397 | ||
8a0681f9 VZ |
398 | switch ( tool->GetStyle() ) |
399 | { | |
400 | case wxTOOL_STYLE_BUTTON: | |
38762f09 VZ |
401 | // for a radio button we need the widget which starts the radio |
402 | // group it belongs to, i.e. the first radio button immediately | |
403 | // preceding this one | |
8a0681f9 | 404 | { |
38762f09 VZ |
405 | GtkWidget *widget = NULL; |
406 | ||
407 | if ( tool->IsRadio() ) | |
408 | { | |
98fc1d65 MB |
409 | wxToolBarToolsList::compatibility_iterator node |
410 | = wxToolBarToolsList::compatibility_iterator(); | |
17a1ebd1 VZ |
411 | if ( pos ) |
412 | node = m_tools.Item(pos - 1); | |
222ed1d6 | 413 | |
38762f09 VZ |
414 | while ( node ) |
415 | { | |
17a1ebd1 VZ |
416 | wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData(); |
417 | if ( !toolNext->IsRadio() ) | |
38762f09 VZ |
418 | break; |
419 | ||
17a1ebd1 | 420 | widget = toolNext->m_item; |
38762f09 VZ |
421 | |
422 | node = node->GetPrevious(); | |
423 | } | |
424 | ||
425 | if ( !widget ) | |
426 | { | |
427 | // this is the first button in the radio button group, | |
428 | // it will be toggled automatically by GTK so bring the | |
429 | // internal flag in sync | |
91af0895 | 430 | tool->Toggle(true); |
38762f09 VZ |
431 | } |
432 | } | |
433 | ||
434 | tool->m_item = gtk_toolbar_insert_element | |
435 | ( | |
436 | m_toolbar, | |
437 | tool->GetGtkChildType(), | |
438 | widget, | |
439 | tool->GetLabel().empty() | |
440 | ? NULL | |
fab591c5 | 441 | : (const char*) wxGTK_CONV( tool->GetLabel() ), |
38762f09 VZ |
442 | tool->GetShortHelp().empty() |
443 | ? NULL | |
fab591c5 | 444 | : (const char*) wxGTK_CONV( tool->GetShortHelp() ), |
38762f09 | 445 | "", // tooltip_private_text (?) |
eba91e51 | 446 | tool->m_image, |
38762f09 VZ |
447 | (GtkSignalFunc)gtk_toolbar_callback, |
448 | (gpointer)tool, | |
6a1359c0 | 449 | posGtk |
38762f09 VZ |
450 | ); |
451 | ||
eba91e51 | 452 | wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed")); |
99e8cb50 | 453 | |
9fa72bd2 MR |
454 | g_signal_connect (tool->m_item, "enter_notify_event", |
455 | G_CALLBACK (gtk_toolbar_tool_callback), | |
456 | tool); | |
457 | g_signal_connect (tool->m_item, "leave_notify_event", | |
458 | G_CALLBACK (gtk_toolbar_tool_callback), | |
459 | tool); | |
8a0681f9 | 460 | } |
8a0681f9 VZ |
461 | break; |
462 | ||
463 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 464 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
465 | |
466 | // skip the rest | |
91af0895 | 467 | return true; |
bf9e3e73 | 468 | |
8a0681f9 VZ |
469 | case wxTOOL_STYLE_CONTROL: |
470 | gtk_toolbar_insert_widget( | |
471 | m_toolbar, | |
472 | tool->GetControl()->m_widget, | |
473 | (const char *) NULL, | |
474 | (const char *) NULL, | |
6a1359c0 | 475 | posGtk |
8a0681f9 | 476 | ); |
f4322df6 | 477 | |
86b65467 RR |
478 | // connect after in order to correct size_allocate events |
479 | g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate", | |
480 | G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl()); | |
f4322df6 | 481 | |
8a0681f9 VZ |
482 | break; |
483 | } | |
bf9e3e73 | 484 | |
bf9e3e73 | 485 | GtkRequisition req; |
2afa14f2 OK |
486 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
487 | (m_widget, &req ); | |
00655497 | 488 | m_width = req.width + m_xMargin; |
6f67eafe | 489 | m_height = req.height + 2*m_yMargin; |
9f884528 | 490 | InvalidateBestSize(); |
bf9e3e73 | 491 | |
91af0895 | 492 | return true; |
bf9e3e73 RR |
493 | } |
494 | ||
4a64a89c | 495 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 496 | { |
8c4e2405 | 497 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); |
c801d85f | 498 | |
8a0681f9 | 499 | switch ( tool->GetStyle() ) |
97d7bfb8 | 500 | { |
8a0681f9 VZ |
501 | case wxTOOL_STYLE_CONTROL: |
502 | tool->GetControl()->Destroy(); | |
503 | break; | |
97d7bfb8 | 504 | |
8a0681f9 VZ |
505 | case wxTOOL_STYLE_BUTTON: |
506 | gtk_widget_destroy( tool->m_item ); | |
507 | break; | |
97d7bfb8 | 508 | |
4a64a89c RD |
509 | case wxTOOL_STYLE_SEPARATOR: |
510 | gtk_toolbar_remove_space( m_toolbar, pos ); | |
511 | break; | |
8a0681f9 | 512 | } |
c801d85f | 513 | |
9f884528 | 514 | InvalidateBestSize(); |
91af0895 | 515 | return true; |
fc008f25 | 516 | } |
46dc76ba | 517 | |
8a0681f9 VZ |
518 | // ---------------------------------------------------------------------------- |
519 | // wxToolBar tools state | |
520 | // ---------------------------------------------------------------------------- | |
521 | ||
522 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) | |
c801d85f | 523 | { |
8c4e2405 | 524 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); |
8a0681f9 | 525 | |
8a0681f9 | 526 | if (tool->m_item) |
fab591c5 | 527 | { |
8a0681f9 | 528 | gtk_widget_set_sensitive( tool->m_item, enable ); |
fab591c5 | 529 | } |
fc008f25 | 530 | } |
c801d85f | 531 | |
248bcf0a | 532 | void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) |
c801d85f | 533 | { |
8c4e2405 | 534 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase); |
8a0681f9 VZ |
535 | |
536 | GtkWidget *item = tool->m_item; | |
537 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 538 | { |
eba91e51 | 539 | tool->SetImage(tool->GetBitmap()); |
c801d85f | 540 | |
91af0895 | 541 | m_blockEvent = true; |
8a0681f9 | 542 | |
e343da37 | 543 | gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle ); |
248bcf0a | 544 | |
91af0895 | 545 | m_blockEvent = false; |
1144d24d | 546 | } |
fc008f25 | 547 | } |
c801d85f | 548 | |
8a0681f9 VZ |
549 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
550 | bool WXUNUSED(toggle)) | |
c801d85f | 551 | { |
8a0681f9 VZ |
552 | // VZ: absolutely no idea about how to do it |
553 | wxFAIL_MSG( _T("not implemented") ); | |
fc008f25 | 554 | } |
c801d85f | 555 | |
8a0681f9 VZ |
556 | // ---------------------------------------------------------------------------- |
557 | // wxToolBar geometry | |
558 | // ---------------------------------------------------------------------------- | |
559 | ||
560 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), | |
561 | wxCoord WXUNUSED(y)) const | |
c801d85f | 562 | { |
8a0681f9 VZ |
563 | // VZ: GTK+ doesn't seem to have such thing |
564 | wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") ); | |
565 | ||
566 | return (wxToolBarToolBase *)NULL; | |
fc008f25 | 567 | } |
c801d85f | 568 | |
1144d24d | 569 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 570 | { |
8a0681f9 VZ |
571 | wxCHECK_RET( GetToolsCount() == 0, |
572 | wxT("wxToolBar::SetMargins must be called before adding tools.") ); | |
248bcf0a | 573 | |
1144d24d RR |
574 | m_xMargin = x; |
575 | m_yMargin = y; | |
fc008f25 | 576 | } |
c801d85f | 577 | |
cf4219e7 | 578 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 579 | { |
9e691f46 | 580 | // FIXME: this function disappeared |
68567a96 | 581 | #if 0 |
1144d24d | 582 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
9e691f46 VZ |
583 | #endif |
584 | ||
8a0681f9 | 585 | m_toolSeparation = separation; |
1144d24d RR |
586 | } |
587 | ||
a1f79c1e VZ |
588 | void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) |
589 | { | |
8c4e2405 | 590 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); |
a1f79c1e VZ |
591 | |
592 | if ( tool ) | |
593 | { | |
594 | (void)tool->SetShortHelp(helpString); | |
595 | gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item, | |
fab591c5 | 596 | wxGTK_CONV( helpString ), ""); |
a1f79c1e VZ |
597 | } |
598 | } | |
599 | ||
bbd321ff RD |
600 | void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) |
601 | { | |
602 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); | |
603 | if ( tool ) | |
604 | { | |
605 | wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); | |
606 | ||
607 | tool->SetNormalBitmap(bitmap); | |
608 | tool->SetImage(tool->GetBitmap()); | |
f4322df6 | 609 | } |
bbd321ff RD |
610 | } |
611 | ||
612 | void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) | |
613 | { | |
614 | wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); | |
615 | if ( tool ) | |
616 | { | |
617 | wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); | |
618 | ||
619 | tool->SetDisabledBitmap(bitmap); | |
620 | tool->SetImage(tool->GetBitmap()); | |
f4322df6 | 621 | } |
bbd321ff RD |
622 | } |
623 | ||
8a0681f9 VZ |
624 | // ---------------------------------------------------------------------------- |
625 | // wxToolBar idle handling | |
626 | // ---------------------------------------------------------------------------- | |
1144d24d | 627 | |
9b7e522a RR |
628 | void wxToolBar::OnInternalIdle() |
629 | { | |
1417c811 RR |
630 | // Check if we have to show window now |
631 | if (GtkShowFromOnIdle()) return; | |
f4322df6 | 632 | |
9b7e522a RR |
633 | wxCursor cursor = m_cursor; |
634 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
635 | ||
f7a11f8c | 636 | if (cursor.Ok()) |
9b7e522a | 637 | { |
f7a11f8c | 638 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
639 | as setting the cursor in a parent window also effects the |
640 | windows above so that checking for the current cursor is | |
641 | not possible. */ | |
85ec2f26 RR |
642 | |
643 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 644 | { |
8a0681f9 VZ |
645 | /* if the toolbar is dockable, then m_widget stands for the |
646 | GtkHandleBox widget, which uses its own window so that we | |
647 | can set the cursor for it. if the toolbar is not dockable, | |
648 | m_widget comes from m_toolbar which uses its parent's | |
649 | window ("windowless windows") and thus we cannot set the | |
650 | cursor. */ | |
651 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
652 | } | |
653 | ||
222ed1d6 | 654 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
655 | while ( node ) |
656 | { | |
657 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
658 | node = node->GetNext(); | |
659 | ||
660 | GtkWidget *item = tool->m_item; | |
661 | if ( item ) | |
662 | { | |
663 | GdkWindow *window = item->window; | |
664 | ||
665 | if ( window ) | |
666 | { | |
667 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
668 | } | |
669 | } | |
9b7e522a RR |
670 | } |
671 | } | |
672 | ||
e39af974 JS |
673 | if (wxUpdateUIEvent::CanUpdate(this)) |
674 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
675 | } |
676 | ||
9d522606 RD |
677 | |
678 | // ---------------------------------------------------------------------------- | |
679 | ||
680 | // static | |
681 | wxVisualAttributes | |
682 | wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
683 | { | |
9d522606 | 684 | return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); |
9d522606 RD |
685 | } |
686 | ||
a1f79c1e | 687 | #endif // wxUSE_TOOLBAR_NATIVE |