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