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