]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
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 | ||
c801d85f | 22 | #include "wx/toolbar.h" |
dcf924a3 | 23 | |
8a0681f9 | 24 | #if wxUSE_TOOLBAR_NATIVE |
dcf924a3 | 25 | |
e702ff0f | 26 | #include "wx/frame.h" |
c801d85f | 27 | |
9e691f46 VZ |
28 | #include <glib.h> |
29 | #include "wx/gtk/private.h" | |
83624f79 | 30 | |
8a0681f9 VZ |
31 | // ---------------------------------------------------------------------------- |
32 | // globals | |
33 | // ---------------------------------------------------------------------------- | |
acfd422a | 34 | |
8a0681f9 | 35 | // idle system |
acfd422a RR |
36 | extern void wxapp_install_idle_handler(); |
37 | extern bool g_isIdle; | |
38 | ||
314055fa | 39 | // data |
9b7e522a RR |
40 | extern bool g_blockEventsOnDrag; |
41 | extern wxCursor g_globalCursor; | |
314055fa | 42 | |
e76c0b5f VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // private functions | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
77ffb593 | 47 | // translate wxWidgets toolbar style flags to GTK orientation and style |
e76c0b5f VZ |
48 | static void GetGtkStyle(long style, |
49 | GtkOrientation *orient, GtkToolbarStyle *gtkStyle) | |
50 | { | |
51 | *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL | |
52 | : GTK_ORIENTATION_HORIZONTAL; | |
53 | ||
54 | ||
55 | if ( style & wxTB_TEXT ) | |
56 | { | |
99e8cb50 VZ |
57 | *gtkStyle = style & wxTB_NOICONS |
58 | ? GTK_TOOLBAR_TEXT | |
59 | : ( | |
99e8cb50 | 60 | style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ : |
99e8cb50 | 61 | GTK_TOOLBAR_BOTH); |
e76c0b5f VZ |
62 | } |
63 | else // no text, hence we must have the icons or what would we show? | |
64 | { | |
65 | *gtkStyle = GTK_TOOLBAR_ICONS; | |
66 | } | |
67 | } | |
68 | ||
8a0681f9 VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // wxToolBarTool | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
73 | class wxToolBarTool : public wxToolBarToolBase | |
74 | { | |
75 | public: | |
76 | wxToolBarTool(wxToolBar *tbar, | |
77 | int id, | |
e76c0b5f | 78 | const wxString& label, |
8a0681f9 VZ |
79 | const wxBitmap& bitmap1, |
80 | const wxBitmap& bitmap2, | |
e76c0b5f | 81 | wxItemKind kind, |
8a0681f9 VZ |
82 | wxObject *clientData, |
83 | const wxString& shortHelpString, | |
84 | const wxString& longHelpString) | |
e76c0b5f | 85 | : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
86 | clientData, shortHelpString, longHelpString) |
87 | { | |
88 | Init(); | |
89 | } | |
90 | ||
91 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
92 | : wxToolBarToolBase(tbar, control) | |
93 | { | |
94 | Init(); | |
95 | } | |
96 | ||
38762f09 VZ |
97 | // is this a radio button? |
98 | // | |
99 | // unlike GetKind(), can be called for any kind of tools, not just buttons | |
100 | bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; } | |
101 | ||
e76c0b5f VZ |
102 | // this is only called for the normal buttons, i.e. not separators nor |
103 | // controls | |
104 | GtkToolbarChildType GetGtkChildType() const | |
105 | { | |
106 | switch ( GetKind() ) | |
107 | { | |
108 | case wxITEM_CHECK: | |
109 | return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
110 | ||
111 | case wxITEM_RADIO: | |
112 | return GTK_TOOLBAR_CHILD_RADIOBUTTON; | |
113 | ||
114 | default: | |
115 | wxFAIL_MSG( _T("unknown toolbar child type") ); | |
116 | // fall through | |
117 | ||
118 | case wxITEM_NORMAL: | |
119 | return GTK_TOOLBAR_CHILD_BUTTON; | |
120 | } | |
121 | } | |
122 | ||
ab86c659 VS |
123 | void SetPixmap(const wxBitmap& bitmap) |
124 | { | |
125 | if (bitmap.Ok()) | |
126 | { | |
127 | GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() | |
128 | : (GdkBitmap *)NULL; | |
ab86c659 | 129 | if (bitmap.HasPixbuf()) |
f05e0979 | 130 | gtk_image_set_from_pixbuf( GTK_IMAGE(m_pixmap), bitmap.GetPixbuf() ); |
ab86c659 | 131 | else |
f05e0979 | 132 | gtk_pixmap_set( GTK_PIXMAP(m_pixmap), bitmap.GetPixmap(), mask ); |
ab86c659 VS |
133 | } |
134 | } | |
135 | ||
8a0681f9 VZ |
136 | GtkWidget *m_item; |
137 | GtkWidget *m_pixmap; | |
138 | ||
139 | protected: | |
140 | void Init(); | |
141 | }; | |
142 | ||
143 | // ---------------------------------------------------------------------------- | |
144 | // wxWin macros | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
2eb10e2a | 147 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
8a0681f9 VZ |
148 | |
149 | // ============================================================================ | |
150 | // implementation | |
151 | // ============================================================================ | |
152 | ||
c801d85f | 153 | //----------------------------------------------------------------------------- |
2f2aa628 | 154 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
155 | //----------------------------------------------------------------------------- |
156 | ||
865bb325 | 157 | extern "C" { |
8a0681f9 VZ |
158 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), |
159 | wxToolBarTool *tool ) | |
c801d85f | 160 | { |
248bcf0a | 161 | if (g_isIdle) |
59fe1666 RR |
162 | wxapp_install_idle_handler(); |
163 | ||
8a0681f9 | 164 | wxToolBar *tbar = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 165 | |
9864c56d | 166 | if (tbar->m_blockEvent) return; |
acfd422a | 167 | |
1144d24d | 168 | if (g_blockEventsOnDrag) return; |
8a0681f9 | 169 | if (!tool->IsEnabled()) return; |
a3622daa | 170 | |
8a0681f9 | 171 | if (tool->CanBeToggled()) |
248bcf0a | 172 | { |
8a0681f9 VZ |
173 | tool->Toggle(); |
174 | ||
ab86c659 | 175 | tool->SetPixmap(tool->GetBitmap()); |
38762f09 VZ |
176 | |
177 | if ( tool->IsRadio() && !tool->IsToggled() ) | |
178 | { | |
179 | // radio button went up, don't report this as a wxWin event | |
180 | return; | |
181 | } | |
85eb36c2 | 182 | } |
a3622daa | 183 | |
6bb7cee4 VZ |
184 | if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() ) |
185 | { | |
186 | // revert back | |
187 | tool->Toggle(); | |
188 | ||
ab86c659 | 189 | tool->SetPixmap(tool->GetBitmap()); |
6bb7cee4 | 190 | } |
fc008f25 | 191 | } |
865bb325 | 192 | } |
c801d85f | 193 | |
2f2aa628 | 194 | //----------------------------------------------------------------------------- |
a8945eef | 195 | // "enter_notify_event" / "leave_notify_event" |
2f2aa628 RR |
196 | //----------------------------------------------------------------------------- |
197 | ||
865bb325 | 198 | extern "C" { |
248bcf0a | 199 | static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), |
a8945eef MB |
200 | GdkEventCrossing *gdk_event, |
201 | wxToolBarTool *tool ) | |
314055fa | 202 | { |
acfd422a RR |
203 | if (g_isIdle) wxapp_install_idle_handler(); |
204 | ||
1144d24d | 205 | if (g_blockEventsOnDrag) return TRUE; |
248bcf0a | 206 | |
8a0681f9 | 207 | wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 208 | |
47c93b63 | 209 | // emit the event |
a8945eef MB |
210 | if( gdk_event->type == GDK_ENTER_NOTIFY ) |
211 | tb->OnMouseEnter( tool->GetId() ); | |
212 | else | |
213 | tb->OnMouseEnter( -1 ); | |
248bcf0a | 214 | |
1144d24d | 215 | return FALSE; |
314055fa | 216 | } |
865bb325 | 217 | } |
314055fa | 218 | |
bf9e3e73 RR |
219 | //----------------------------------------------------------------------------- |
220 | // InsertChild callback for wxToolBar | |
221 | //----------------------------------------------------------------------------- | |
222 | ||
8a0681f9 VZ |
223 | static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), |
224 | wxWindow* WXUNUSED(child) ) | |
bf9e3e73 | 225 | { |
47c93b63 | 226 | // we don't do anything here |
bf9e3e73 RR |
227 | } |
228 | ||
8a0681f9 VZ |
229 | // ---------------------------------------------------------------------------- |
230 | // wxToolBarTool | |
231 | // ---------------------------------------------------------------------------- | |
c801d85f | 232 | |
8a0681f9 VZ |
233 | void wxToolBarTool::Init() |
234 | { | |
235 | m_item = | |
236 | m_pixmap = (GtkWidget *)NULL; | |
237 | } | |
c801d85f | 238 | |
8a0681f9 | 239 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
e76c0b5f | 240 | const wxString& text, |
8a0681f9 VZ |
241 | const wxBitmap& bitmap1, |
242 | const wxBitmap& bitmap2, | |
e76c0b5f | 243 | wxItemKind kind, |
8a0681f9 VZ |
244 | wxObject *clientData, |
245 | const wxString& shortHelpString, | |
246 | const wxString& longHelpString) | |
247 | { | |
e76c0b5f | 248 | return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
249 | clientData, shortHelpString, longHelpString); |
250 | } | |
b1da76e1 | 251 | |
8a0681f9 | 252 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) |
c801d85f | 253 | { |
8a0681f9 | 254 | return new wxToolBarTool(this, control); |
fc008f25 | 255 | } |
c801d85f | 256 | |
8a0681f9 VZ |
257 | //----------------------------------------------------------------------------- |
258 | // wxToolBar construction | |
259 | //----------------------------------------------------------------------------- | |
260 | ||
261 | void wxToolBar::Init() | |
c801d85f | 262 | { |
8a0681f9 | 263 | m_toolbar = (GtkToolbar *)NULL; |
91af0895 | 264 | m_blockEvent = false; |
d2c0a964 RD |
265 | m_defaultWidth = 32; |
266 | m_defaultHeight = 32; | |
fc008f25 | 267 | } |
c801d85f | 268 | |
a3622daa | 269 | wxToolBar::~wxToolBar() |
c801d85f | 270 | { |
fc008f25 | 271 | } |
c801d85f | 272 | |
8a0681f9 VZ |
273 | bool wxToolBar::Create( wxWindow *parent, |
274 | wxWindowID id, | |
275 | const wxPoint& pos, | |
276 | const wxSize& size, | |
277 | long style, | |
278 | const wxString& name ) | |
c801d85f | 279 | { |
91af0895 | 280 | m_needParent = true; |
bf9e3e73 | 281 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; |
a3622daa | 282 | |
8a0681f9 VZ |
283 | if ( !PreCreation( parent, pos, size ) || |
284 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
4dcaf11a | 285 | { |
223d09f6 | 286 | wxFAIL_MSG( wxT("wxToolBar creation failed") ); |
c801d85f | 287 | |
91af0895 | 288 | return false; |
8a0681f9 | 289 | } |
a3622daa | 290 | |
9e691f46 | 291 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); |
e76c0b5f | 292 | GtkSetStyle(); |
99e8cb50 | 293 | |
2b5f62a0 VZ |
294 | // Doesn't work this way. |
295 | // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY; | |
296 | // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL); | |
a3622daa | 297 | |
8a0681f9 | 298 | SetToolSeparation(7); |
3502e687 RR |
299 | |
300 | if (style & wxTB_DOCKABLE) | |
301 | { | |
302 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
303 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
304 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
8a0681f9 | 305 | |
f03fc89f | 306 | if (style & wxTB_FLAT) |
858b5bdd | 307 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
3502e687 RR |
308 | } |
309 | else | |
248bcf0a RD |
310 | { |
311 | m_widget = gtk_event_box_new(); | |
312 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); | |
313 | ConnectWidget( m_widget ); | |
314 | gtk_widget_show(GTK_WIDGET(m_toolbar)); | |
3502e687 | 315 | } |
8a0681f9 | 316 | |
1144d24d | 317 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); |
8a0681f9 | 318 | |
9e691f46 | 319 | // FIXME: there is no such function for toolbars in 2.0 |
68567a96 | 320 | #if 0 |
858b5bdd RR |
321 | if (style & wxTB_FLAT) |
322 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
9e691f46 | 323 | #endif |
be25e480 | 324 | |
f03fc89f | 325 | m_parent->DoAddChild( this ); |
8a0681f9 | 326 | |
abdeb9e7 | 327 | PostCreation(size); |
a3622daa | 328 | |
91af0895 | 329 | return true; |
fc008f25 | 330 | } |
c801d85f | 331 | |
e76c0b5f VZ |
332 | void wxToolBar::GtkSetStyle() |
333 | { | |
334 | GtkOrientation orient; | |
335 | GtkToolbarStyle style; | |
336 | GetGtkStyle(GetWindowStyle(), &orient, &style); | |
337 | ||
338 | gtk_toolbar_set_orientation(m_toolbar, orient); | |
339 | gtk_toolbar_set_style(m_toolbar, style); | |
340 | } | |
341 | ||
342 | void wxToolBar::SetWindowStyleFlag( long style ) | |
343 | { | |
344 | wxToolBarBase::SetWindowStyleFlag(style); | |
345 | ||
346 | if ( m_toolbar ) | |
347 | GtkSetStyle(); | |
348 | } | |
349 | ||
8a0681f9 | 350 | bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 351 | { |
8a0681f9 | 352 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 353 | |
2b5f62a0 | 354 | size_t posGtk = pos; |
248bcf0a | 355 | |
8a0681f9 VZ |
356 | if ( tool->IsButton() ) |
357 | { | |
2b5f62a0 VZ |
358 | if ( !HasFlag(wxTB_NOICONS) ) |
359 | { | |
360 | wxBitmap bitmap = tool->GetNormalBitmap(); | |
c801d85f | 361 | |
91af0895 | 362 | wxCHECK_MSG( bitmap.Ok(), false, |
2b5f62a0 | 363 | wxT("invalid bitmap for wxToolBar icon") ); |
a3622daa | 364 | |
91af0895 | 365 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, false, |
2b5f62a0 | 366 | wxT("wxToolBar doesn't support GdkBitmap") ); |
03f38c58 | 367 | |
91af0895 | 368 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, false, |
2b5f62a0 | 369 | wxT("wxToolBar::Add needs a wxBitmap") ); |
248bcf0a | 370 | |
2b5f62a0 | 371 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
248bcf0a | 372 | |
ab86c659 | 373 | |
f05e0979 RR |
374 | if (bitmap.HasPixbuf()) |
375 | { | |
376 | tool_pixmap = gtk_image_new(); | |
377 | tool->m_pixmap = tool_pixmap; | |
378 | tool->SetPixmap(bitmap); | |
379 | } | |
380 | else | |
f05e0979 RR |
381 | { |
382 | GdkPixmap *pixmap = bitmap.GetPixmap(); | |
a3622daa | 383 | |
f05e0979 RR |
384 | GdkBitmap *mask = (GdkBitmap *)NULL; |
385 | if ( bitmap.GetMask() ) | |
386 | mask = bitmap.GetMask()->GetBitmap(); | |
91af0895 | 387 | |
f05e0979 RR |
388 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); |
389 | gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE ); | |
390 | } | |
248bcf0a | 391 | |
2b5f62a0 | 392 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 393 | |
2b5f62a0 VZ |
394 | tool->m_pixmap = tool_pixmap; |
395 | } | |
8a0681f9 | 396 | } |
c801d85f | 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 VZ |
445 | "", // tooltip_private_text (?) |
446 | tool->m_pixmap, | |
447 | (GtkSignalFunc)gtk_toolbar_callback, | |
448 | (gpointer)tool, | |
6a1359c0 | 449 | posGtk |
38762f09 VZ |
450 | ); |
451 | ||
452 | if ( !tool->m_item ) | |
453 | { | |
454 | wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") ); | |
455 | ||
91af0895 | 456 | return false; |
38762f09 | 457 | } |
99e8cb50 | 458 | |
9fa72bd2 MR |
459 | g_signal_connect (tool->m_item, "enter_notify_event", |
460 | G_CALLBACK (gtk_toolbar_tool_callback), | |
461 | tool); | |
462 | g_signal_connect (tool->m_item, "leave_notify_event", | |
463 | G_CALLBACK (gtk_toolbar_tool_callback), | |
464 | tool); | |
8a0681f9 | 465 | } |
8a0681f9 VZ |
466 | break; |
467 | ||
468 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 469 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
470 | |
471 | // skip the rest | |
91af0895 | 472 | return true; |
bf9e3e73 | 473 | |
8a0681f9 VZ |
474 | case wxTOOL_STYLE_CONTROL: |
475 | gtk_toolbar_insert_widget( | |
476 | m_toolbar, | |
477 | tool->GetControl()->m_widget, | |
478 | (const char *) NULL, | |
479 | (const char *) NULL, | |
6a1359c0 | 480 | posGtk |
8a0681f9 VZ |
481 | ); |
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 | { |
8a0681f9 | 497 | wxToolBarTool *tool = (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 | { |
8a0681f9 VZ |
524 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
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 | { |
8a0681f9 VZ |
534 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
535 | ||
536 | GtkWidget *item = tool->m_item; | |
537 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 538 | { |
ab86c659 | 539 | tool->SetPixmap(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 | { | |
590 | wxToolBarTool *tool = (wxToolBarTool *)FindById(id); | |
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 | ||
8a0681f9 VZ |
600 | // ---------------------------------------------------------------------------- |
601 | // wxToolBar idle handling | |
602 | // ---------------------------------------------------------------------------- | |
1144d24d | 603 | |
9b7e522a RR |
604 | void wxToolBar::OnInternalIdle() |
605 | { | |
606 | wxCursor cursor = m_cursor; | |
607 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
608 | ||
f7a11f8c | 609 | if (cursor.Ok()) |
9b7e522a | 610 | { |
f7a11f8c | 611 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
612 | as setting the cursor in a parent window also effects the |
613 | windows above so that checking for the current cursor is | |
614 | not possible. */ | |
85ec2f26 RR |
615 | |
616 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 617 | { |
8a0681f9 VZ |
618 | /* if the toolbar is dockable, then m_widget stands for the |
619 | GtkHandleBox widget, which uses its own window so that we | |
620 | can set the cursor for it. if the toolbar is not dockable, | |
621 | m_widget comes from m_toolbar which uses its parent's | |
622 | window ("windowless windows") and thus we cannot set the | |
623 | cursor. */ | |
624 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
625 | } | |
626 | ||
222ed1d6 | 627 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
628 | while ( node ) |
629 | { | |
630 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
631 | node = node->GetNext(); | |
632 | ||
633 | GtkWidget *item = tool->m_item; | |
634 | if ( item ) | |
635 | { | |
636 | GdkWindow *window = item->window; | |
637 | ||
638 | if ( window ) | |
639 | { | |
640 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
641 | } | |
642 | } | |
9b7e522a RR |
643 | } |
644 | } | |
645 | ||
e39af974 JS |
646 | if (wxUpdateUIEvent::CanUpdate(this)) |
647 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
648 | } |
649 | ||
9d522606 RD |
650 | |
651 | // ---------------------------------------------------------------------------- | |
652 | ||
653 | // static | |
654 | wxVisualAttributes | |
655 | wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
656 | { | |
9d522606 | 657 | return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); |
9d522606 RD |
658 | } |
659 | ||
a1f79c1e | 660 | #endif // wxUSE_TOOLBAR_NATIVE |