]>
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 | { | |
55 | *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL | |
56 | : GTK_ORIENTATION_HORIZONTAL; | |
57 | ||
58 | ||
59 | if ( style & wxTB_TEXT ) | |
60 | { | |
99e8cb50 VZ |
61 | *gtkStyle = style & wxTB_NOICONS |
62 | ? GTK_TOOLBAR_TEXT | |
63 | : ( | |
99e8cb50 | 64 | style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ : |
99e8cb50 | 65 | GTK_TOOLBAR_BOTH); |
e76c0b5f VZ |
66 | } |
67 | else // no text, hence we must have the icons or what would we show? | |
68 | { | |
69 | *gtkStyle = GTK_TOOLBAR_ICONS; | |
70 | } | |
71 | } | |
72 | ||
8a0681f9 VZ |
73 | // ---------------------------------------------------------------------------- |
74 | // wxToolBarTool | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | class wxToolBarTool : public wxToolBarToolBase | |
78 | { | |
79 | public: | |
80 | wxToolBarTool(wxToolBar *tbar, | |
81 | int id, | |
e76c0b5f | 82 | const wxString& label, |
8a0681f9 VZ |
83 | const wxBitmap& bitmap1, |
84 | const wxBitmap& bitmap2, | |
e76c0b5f | 85 | wxItemKind kind, |
8a0681f9 VZ |
86 | wxObject *clientData, |
87 | const wxString& shortHelpString, | |
88 | const wxString& longHelpString) | |
e76c0b5f | 89 | : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
90 | clientData, shortHelpString, longHelpString) |
91 | { | |
92 | Init(); | |
93 | } | |
94 | ||
95 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
96 | : wxToolBarToolBase(tbar, control) | |
97 | { | |
98 | Init(); | |
99 | } | |
100 | ||
38762f09 VZ |
101 | // is this a radio button? |
102 | // | |
103 | // unlike GetKind(), can be called for any kind of tools, not just buttons | |
104 | bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; } | |
105 | ||
e76c0b5f VZ |
106 | // this is only called for the normal buttons, i.e. not separators nor |
107 | // controls | |
108 | GtkToolbarChildType GetGtkChildType() const | |
109 | { | |
110 | switch ( GetKind() ) | |
111 | { | |
112 | case wxITEM_CHECK: | |
113 | return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
114 | ||
115 | case wxITEM_RADIO: | |
116 | return GTK_TOOLBAR_CHILD_RADIOBUTTON; | |
117 | ||
118 | default: | |
119 | wxFAIL_MSG( _T("unknown toolbar child type") ); | |
120 | // fall through | |
121 | ||
122 | case wxITEM_NORMAL: | |
123 | return GTK_TOOLBAR_CHILD_BUTTON; | |
124 | } | |
125 | } | |
126 | ||
ab86c659 VS |
127 | void SetPixmap(const wxBitmap& bitmap) |
128 | { | |
129 | if (bitmap.Ok()) | |
130 | { | |
131 | GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() | |
132 | : (GdkBitmap *)NULL; | |
ab86c659 | 133 | if (bitmap.HasPixbuf()) |
f05e0979 | 134 | gtk_image_set_from_pixbuf( GTK_IMAGE(m_pixmap), bitmap.GetPixbuf() ); |
ab86c659 | 135 | else |
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 | { |
14819684 | 207 | // don't need to install idle handler, its done from "event" signal |
acfd422a | 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 | 295 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); |
e76c0b5f | 296 | GtkSetStyle(); |
99e8cb50 | 297 | |
2b5f62a0 VZ |
298 | // Doesn't work this way. |
299 | // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY; | |
300 | // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL); | |
a3622daa | 301 | |
8a0681f9 | 302 | SetToolSeparation(7); |
3502e687 RR |
303 | |
304 | if (style & wxTB_DOCKABLE) | |
305 | { | |
306 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
307 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
308 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
8a0681f9 | 309 | |
f03fc89f | 310 | if (style & wxTB_FLAT) |
858b5bdd | 311 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
3502e687 RR |
312 | } |
313 | else | |
248bcf0a RD |
314 | { |
315 | m_widget = gtk_event_box_new(); | |
316 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); | |
317 | ConnectWidget( m_widget ); | |
318 | gtk_widget_show(GTK_WIDGET(m_toolbar)); | |
3502e687 | 319 | } |
8a0681f9 | 320 | |
9e691f46 | 321 | // FIXME: there is no such function for toolbars in 2.0 |
68567a96 | 322 | #if 0 |
858b5bdd RR |
323 | if (style & wxTB_FLAT) |
324 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
9e691f46 | 325 | #endif |
be25e480 | 326 | |
f03fc89f | 327 | m_parent->DoAddChild( this ); |
8a0681f9 | 328 | |
abdeb9e7 | 329 | PostCreation(size); |
a3622daa | 330 | |
91af0895 | 331 | return true; |
fc008f25 | 332 | } |
c801d85f | 333 | |
48468900 RR |
334 | GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const |
335 | { | |
336 | return GTK_WIDGET(m_toolbar)->window; | |
337 | } | |
338 | ||
e76c0b5f VZ |
339 | void wxToolBar::GtkSetStyle() |
340 | { | |
341 | GtkOrientation orient; | |
342 | GtkToolbarStyle style; | |
343 | GetGtkStyle(GetWindowStyle(), &orient, &style); | |
344 | ||
345 | gtk_toolbar_set_orientation(m_toolbar, orient); | |
346 | gtk_toolbar_set_style(m_toolbar, style); | |
8ad31f9d | 347 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), !(style & wxTB_NO_TOOLTIPS) ); |
e76c0b5f VZ |
348 | } |
349 | ||
350 | void wxToolBar::SetWindowStyleFlag( long style ) | |
351 | { | |
352 | wxToolBarBase::SetWindowStyleFlag(style); | |
8ad31f9d | 353 | |
e76c0b5f VZ |
354 | if ( m_toolbar ) |
355 | GtkSetStyle(); | |
356 | } | |
357 | ||
8a0681f9 | 358 | bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 359 | { |
8a0681f9 | 360 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 361 | |
2b5f62a0 | 362 | size_t posGtk = pos; |
248bcf0a | 363 | |
8a0681f9 VZ |
364 | if ( tool->IsButton() ) |
365 | { | |
2b5f62a0 VZ |
366 | if ( !HasFlag(wxTB_NOICONS) ) |
367 | { | |
368 | wxBitmap bitmap = tool->GetNormalBitmap(); | |
c801d85f | 369 | |
91af0895 | 370 | wxCHECK_MSG( bitmap.Ok(), false, |
2b5f62a0 | 371 | wxT("invalid bitmap for wxToolBar icon") ); |
a3622daa | 372 | |
b85229d1 | 373 | wxCHECK_MSG( bitmap.GetDepth() != 1, false, |
2b5f62a0 | 374 | wxT("wxToolBar doesn't support GdkBitmap") ); |
03f38c58 | 375 | |
91af0895 | 376 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, false, |
2b5f62a0 | 377 | wxT("wxToolBar::Add needs a wxBitmap") ); |
248bcf0a | 378 | |
2b5f62a0 | 379 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
248bcf0a | 380 | |
ab86c659 | 381 | |
f05e0979 RR |
382 | if (bitmap.HasPixbuf()) |
383 | { | |
384 | tool_pixmap = gtk_image_new(); | |
385 | tool->m_pixmap = tool_pixmap; | |
386 | tool->SetPixmap(bitmap); | |
387 | } | |
388 | else | |
f05e0979 RR |
389 | { |
390 | GdkPixmap *pixmap = bitmap.GetPixmap(); | |
a3622daa | 391 | |
f05e0979 RR |
392 | GdkBitmap *mask = (GdkBitmap *)NULL; |
393 | if ( bitmap.GetMask() ) | |
394 | mask = bitmap.GetMask()->GetBitmap(); | |
91af0895 | 395 | |
f05e0979 RR |
396 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); |
397 | gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE ); | |
398 | } | |
248bcf0a | 399 | |
2b5f62a0 | 400 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 401 | |
2b5f62a0 VZ |
402 | tool->m_pixmap = tool_pixmap; |
403 | } | |
8a0681f9 | 404 | } |
c801d85f | 405 | |
8a0681f9 VZ |
406 | switch ( tool->GetStyle() ) |
407 | { | |
408 | case wxTOOL_STYLE_BUTTON: | |
38762f09 VZ |
409 | // for a radio button we need the widget which starts the radio |
410 | // group it belongs to, i.e. the first radio button immediately | |
411 | // preceding this one | |
8a0681f9 | 412 | { |
38762f09 VZ |
413 | GtkWidget *widget = NULL; |
414 | ||
415 | if ( tool->IsRadio() ) | |
416 | { | |
98fc1d65 MB |
417 | wxToolBarToolsList::compatibility_iterator node |
418 | = wxToolBarToolsList::compatibility_iterator(); | |
17a1ebd1 VZ |
419 | if ( pos ) |
420 | node = m_tools.Item(pos - 1); | |
222ed1d6 | 421 | |
38762f09 VZ |
422 | while ( node ) |
423 | { | |
17a1ebd1 VZ |
424 | wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData(); |
425 | if ( !toolNext->IsRadio() ) | |
38762f09 VZ |
426 | break; |
427 | ||
17a1ebd1 | 428 | widget = toolNext->m_item; |
38762f09 VZ |
429 | |
430 | node = node->GetPrevious(); | |
431 | } | |
432 | ||
433 | if ( !widget ) | |
434 | { | |
435 | // this is the first button in the radio button group, | |
436 | // it will be toggled automatically by GTK so bring the | |
437 | // internal flag in sync | |
91af0895 | 438 | tool->Toggle(true); |
38762f09 VZ |
439 | } |
440 | } | |
441 | ||
442 | tool->m_item = gtk_toolbar_insert_element | |
443 | ( | |
444 | m_toolbar, | |
445 | tool->GetGtkChildType(), | |
446 | widget, | |
447 | tool->GetLabel().empty() | |
448 | ? NULL | |
fab591c5 | 449 | : (const char*) wxGTK_CONV( tool->GetLabel() ), |
38762f09 VZ |
450 | tool->GetShortHelp().empty() |
451 | ? NULL | |
fab591c5 | 452 | : (const char*) wxGTK_CONV( tool->GetShortHelp() ), |
38762f09 VZ |
453 | "", // tooltip_private_text (?) |
454 | tool->m_pixmap, | |
455 | (GtkSignalFunc)gtk_toolbar_callback, | |
456 | (gpointer)tool, | |
6a1359c0 | 457 | posGtk |
38762f09 VZ |
458 | ); |
459 | ||
460 | if ( !tool->m_item ) | |
461 | { | |
462 | wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") ); | |
463 | ||
91af0895 | 464 | return false; |
38762f09 | 465 | } |
99e8cb50 | 466 | |
9fa72bd2 MR |
467 | g_signal_connect (tool->m_item, "enter_notify_event", |
468 | G_CALLBACK (gtk_toolbar_tool_callback), | |
469 | tool); | |
470 | g_signal_connect (tool->m_item, "leave_notify_event", | |
471 | G_CALLBACK (gtk_toolbar_tool_callback), | |
472 | tool); | |
8a0681f9 | 473 | } |
8a0681f9 VZ |
474 | break; |
475 | ||
476 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 477 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
478 | |
479 | // skip the rest | |
91af0895 | 480 | return true; |
bf9e3e73 | 481 | |
8a0681f9 VZ |
482 | case wxTOOL_STYLE_CONTROL: |
483 | gtk_toolbar_insert_widget( | |
484 | m_toolbar, | |
485 | tool->GetControl()->m_widget, | |
486 | (const char *) NULL, | |
487 | (const char *) NULL, | |
6a1359c0 | 488 | posGtk |
8a0681f9 VZ |
489 | ); |
490 | break; | |
491 | } | |
bf9e3e73 | 492 | |
bf9e3e73 | 493 | GtkRequisition req; |
2afa14f2 OK |
494 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
495 | (m_widget, &req ); | |
00655497 | 496 | m_width = req.width + m_xMargin; |
6f67eafe | 497 | m_height = req.height + 2*m_yMargin; |
9f884528 | 498 | InvalidateBestSize(); |
bf9e3e73 | 499 | |
91af0895 | 500 | return true; |
bf9e3e73 RR |
501 | } |
502 | ||
4a64a89c | 503 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 504 | { |
8a0681f9 | 505 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 506 | |
8a0681f9 | 507 | switch ( tool->GetStyle() ) |
97d7bfb8 | 508 | { |
8a0681f9 VZ |
509 | case wxTOOL_STYLE_CONTROL: |
510 | tool->GetControl()->Destroy(); | |
511 | break; | |
97d7bfb8 | 512 | |
8a0681f9 VZ |
513 | case wxTOOL_STYLE_BUTTON: |
514 | gtk_widget_destroy( tool->m_item ); | |
515 | break; | |
97d7bfb8 | 516 | |
4a64a89c RD |
517 | case wxTOOL_STYLE_SEPARATOR: |
518 | gtk_toolbar_remove_space( m_toolbar, pos ); | |
519 | break; | |
8a0681f9 | 520 | } |
c801d85f | 521 | |
9f884528 | 522 | InvalidateBestSize(); |
91af0895 | 523 | return true; |
fc008f25 | 524 | } |
46dc76ba | 525 | |
8a0681f9 VZ |
526 | // ---------------------------------------------------------------------------- |
527 | // wxToolBar tools state | |
528 | // ---------------------------------------------------------------------------- | |
529 | ||
530 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) | |
c801d85f | 531 | { |
8a0681f9 VZ |
532 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
533 | ||
8a0681f9 | 534 | if (tool->m_item) |
fab591c5 | 535 | { |
8a0681f9 | 536 | gtk_widget_set_sensitive( tool->m_item, enable ); |
fab591c5 | 537 | } |
fc008f25 | 538 | } |
c801d85f | 539 | |
248bcf0a | 540 | void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) |
c801d85f | 541 | { |
8a0681f9 VZ |
542 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
543 | ||
544 | GtkWidget *item = tool->m_item; | |
545 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 546 | { |
ab86c659 | 547 | tool->SetPixmap(tool->GetBitmap()); |
c801d85f | 548 | |
91af0895 | 549 | m_blockEvent = true; |
8a0681f9 | 550 | |
e343da37 | 551 | gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle ); |
248bcf0a | 552 | |
91af0895 | 553 | m_blockEvent = false; |
1144d24d | 554 | } |
fc008f25 | 555 | } |
c801d85f | 556 | |
8a0681f9 VZ |
557 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
558 | bool WXUNUSED(toggle)) | |
c801d85f | 559 | { |
8a0681f9 VZ |
560 | // VZ: absolutely no idea about how to do it |
561 | wxFAIL_MSG( _T("not implemented") ); | |
fc008f25 | 562 | } |
c801d85f | 563 | |
8a0681f9 VZ |
564 | // ---------------------------------------------------------------------------- |
565 | // wxToolBar geometry | |
566 | // ---------------------------------------------------------------------------- | |
567 | ||
568 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), | |
569 | wxCoord WXUNUSED(y)) const | |
c801d85f | 570 | { |
8a0681f9 VZ |
571 | // VZ: GTK+ doesn't seem to have such thing |
572 | wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") ); | |
573 | ||
574 | return (wxToolBarToolBase *)NULL; | |
fc008f25 | 575 | } |
c801d85f | 576 | |
1144d24d | 577 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 578 | { |
8a0681f9 VZ |
579 | wxCHECK_RET( GetToolsCount() == 0, |
580 | wxT("wxToolBar::SetMargins must be called before adding tools.") ); | |
248bcf0a | 581 | |
1144d24d RR |
582 | m_xMargin = x; |
583 | m_yMargin = y; | |
fc008f25 | 584 | } |
c801d85f | 585 | |
cf4219e7 | 586 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 587 | { |
9e691f46 | 588 | // FIXME: this function disappeared |
68567a96 | 589 | #if 0 |
1144d24d | 590 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
9e691f46 VZ |
591 | #endif |
592 | ||
8a0681f9 | 593 | m_toolSeparation = separation; |
1144d24d RR |
594 | } |
595 | ||
a1f79c1e VZ |
596 | void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) |
597 | { | |
598 | wxToolBarTool *tool = (wxToolBarTool *)FindById(id); | |
599 | ||
600 | if ( tool ) | |
601 | { | |
602 | (void)tool->SetShortHelp(helpString); | |
603 | gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item, | |
fab591c5 | 604 | wxGTK_CONV( helpString ), ""); |
a1f79c1e VZ |
605 | } |
606 | } | |
607 | ||
8a0681f9 VZ |
608 | // ---------------------------------------------------------------------------- |
609 | // wxToolBar idle handling | |
610 | // ---------------------------------------------------------------------------- | |
1144d24d | 611 | |
9b7e522a RR |
612 | void wxToolBar::OnInternalIdle() |
613 | { | |
1417c811 RR |
614 | // Check if we have to show window now |
615 | if (GtkShowFromOnIdle()) return; | |
616 | ||
9b7e522a RR |
617 | wxCursor cursor = m_cursor; |
618 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
619 | ||
f7a11f8c | 620 | if (cursor.Ok()) |
9b7e522a | 621 | { |
f7a11f8c | 622 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
623 | as setting the cursor in a parent window also effects the |
624 | windows above so that checking for the current cursor is | |
625 | not possible. */ | |
85ec2f26 RR |
626 | |
627 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 628 | { |
8a0681f9 VZ |
629 | /* if the toolbar is dockable, then m_widget stands for the |
630 | GtkHandleBox widget, which uses its own window so that we | |
631 | can set the cursor for it. if the toolbar is not dockable, | |
632 | m_widget comes from m_toolbar which uses its parent's | |
633 | window ("windowless windows") and thus we cannot set the | |
634 | cursor. */ | |
635 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
636 | } | |
637 | ||
222ed1d6 | 638 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
639 | while ( node ) |
640 | { | |
641 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
642 | node = node->GetNext(); | |
643 | ||
644 | GtkWidget *item = tool->m_item; | |
645 | if ( item ) | |
646 | { | |
647 | GdkWindow *window = item->window; | |
648 | ||
649 | if ( window ) | |
650 | { | |
651 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
652 | } | |
653 | } | |
9b7e522a RR |
654 | } |
655 | } | |
656 | ||
e39af974 JS |
657 | if (wxUpdateUIEvent::CanUpdate(this)) |
658 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
659 | } |
660 | ||
9d522606 RD |
661 | |
662 | // ---------------------------------------------------------------------------- | |
663 | ||
664 | // static | |
665 | wxVisualAttributes | |
666 | wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
667 | { | |
9d522606 | 668 | return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); |
9d522606 RD |
669 | } |
670 | ||
a1f79c1e | 671 | #endif // wxUSE_TOOLBAR_NATIVE |