]>
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 | |
38762f09 | 459 | gtk_signal_connect( GTK_OBJECT(tool->m_item), |
248bcf0a | 460 | "enter_notify_event", |
38762f09 VZ |
461 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
462 | (gpointer)tool ); | |
463 | gtk_signal_connect( GTK_OBJECT(tool->m_item), | |
248bcf0a | 464 | "leave_notify_event", |
38762f09 VZ |
465 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
466 | (gpointer)tool ); | |
8a0681f9 | 467 | } |
8a0681f9 VZ |
468 | break; |
469 | ||
470 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 471 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
472 | |
473 | // skip the rest | |
91af0895 | 474 | return true; |
bf9e3e73 | 475 | |
8a0681f9 VZ |
476 | case wxTOOL_STYLE_CONTROL: |
477 | gtk_toolbar_insert_widget( | |
478 | m_toolbar, | |
479 | tool->GetControl()->m_widget, | |
480 | (const char *) NULL, | |
481 | (const char *) NULL, | |
6a1359c0 | 482 | posGtk |
8a0681f9 VZ |
483 | ); |
484 | break; | |
485 | } | |
bf9e3e73 | 486 | |
bf9e3e73 | 487 | GtkRequisition req; |
2afa14f2 OK |
488 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
489 | (m_widget, &req ); | |
00655497 | 490 | m_width = req.width + m_xMargin; |
6f67eafe | 491 | m_height = req.height + 2*m_yMargin; |
9f884528 | 492 | InvalidateBestSize(); |
bf9e3e73 | 493 | |
91af0895 | 494 | return true; |
bf9e3e73 RR |
495 | } |
496 | ||
4a64a89c | 497 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 498 | { |
8a0681f9 | 499 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 500 | |
8a0681f9 | 501 | switch ( tool->GetStyle() ) |
97d7bfb8 | 502 | { |
8a0681f9 VZ |
503 | case wxTOOL_STYLE_CONTROL: |
504 | tool->GetControl()->Destroy(); | |
505 | break; | |
97d7bfb8 | 506 | |
8a0681f9 VZ |
507 | case wxTOOL_STYLE_BUTTON: |
508 | gtk_widget_destroy( tool->m_item ); | |
509 | break; | |
97d7bfb8 | 510 | |
4a64a89c RD |
511 | case wxTOOL_STYLE_SEPARATOR: |
512 | gtk_toolbar_remove_space( m_toolbar, pos ); | |
513 | break; | |
8a0681f9 | 514 | } |
c801d85f | 515 | |
9f884528 | 516 | InvalidateBestSize(); |
91af0895 | 517 | return true; |
fc008f25 | 518 | } |
46dc76ba | 519 | |
8a0681f9 VZ |
520 | // ---------------------------------------------------------------------------- |
521 | // wxToolBar tools state | |
522 | // ---------------------------------------------------------------------------- | |
523 | ||
524 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) | |
c801d85f | 525 | { |
8a0681f9 VZ |
526 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
527 | ||
8a0681f9 | 528 | if (tool->m_item) |
fab591c5 | 529 | { |
8a0681f9 | 530 | gtk_widget_set_sensitive( tool->m_item, enable ); |
fab591c5 | 531 | } |
fc008f25 | 532 | } |
c801d85f | 533 | |
248bcf0a | 534 | void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) |
c801d85f | 535 | { |
8a0681f9 VZ |
536 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
537 | ||
538 | GtkWidget *item = tool->m_item; | |
539 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 540 | { |
ab86c659 | 541 | tool->SetPixmap(tool->GetBitmap()); |
c801d85f | 542 | |
91af0895 | 543 | m_blockEvent = true; |
8a0681f9 VZ |
544 | |
545 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle ); | |
248bcf0a | 546 | |
91af0895 | 547 | m_blockEvent = false; |
1144d24d | 548 | } |
fc008f25 | 549 | } |
c801d85f | 550 | |
8a0681f9 VZ |
551 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
552 | bool WXUNUSED(toggle)) | |
c801d85f | 553 | { |
8a0681f9 VZ |
554 | // VZ: absolutely no idea about how to do it |
555 | wxFAIL_MSG( _T("not implemented") ); | |
fc008f25 | 556 | } |
c801d85f | 557 | |
8a0681f9 VZ |
558 | // ---------------------------------------------------------------------------- |
559 | // wxToolBar geometry | |
560 | // ---------------------------------------------------------------------------- | |
561 | ||
562 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), | |
563 | wxCoord WXUNUSED(y)) const | |
c801d85f | 564 | { |
8a0681f9 VZ |
565 | // VZ: GTK+ doesn't seem to have such thing |
566 | wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") ); | |
567 | ||
568 | return (wxToolBarToolBase *)NULL; | |
fc008f25 | 569 | } |
c801d85f | 570 | |
1144d24d | 571 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 572 | { |
8a0681f9 VZ |
573 | wxCHECK_RET( GetToolsCount() == 0, |
574 | wxT("wxToolBar::SetMargins must be called before adding tools.") ); | |
248bcf0a | 575 | |
1144d24d RR |
576 | m_xMargin = x; |
577 | m_yMargin = y; | |
fc008f25 | 578 | } |
c801d85f | 579 | |
cf4219e7 | 580 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 581 | { |
9e691f46 | 582 | // FIXME: this function disappeared |
68567a96 | 583 | #if 0 |
1144d24d | 584 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
9e691f46 VZ |
585 | #endif |
586 | ||
8a0681f9 | 587 | m_toolSeparation = separation; |
1144d24d RR |
588 | } |
589 | ||
a1f79c1e VZ |
590 | void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) |
591 | { | |
592 | wxToolBarTool *tool = (wxToolBarTool *)FindById(id); | |
593 | ||
594 | if ( tool ) | |
595 | { | |
596 | (void)tool->SetShortHelp(helpString); | |
597 | gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item, | |
fab591c5 | 598 | wxGTK_CONV( helpString ), ""); |
a1f79c1e VZ |
599 | } |
600 | } | |
601 | ||
8a0681f9 VZ |
602 | // ---------------------------------------------------------------------------- |
603 | // wxToolBar idle handling | |
604 | // ---------------------------------------------------------------------------- | |
1144d24d | 605 | |
9b7e522a RR |
606 | void wxToolBar::OnInternalIdle() |
607 | { | |
608 | wxCursor cursor = m_cursor; | |
609 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
610 | ||
f7a11f8c | 611 | if (cursor.Ok()) |
9b7e522a | 612 | { |
f7a11f8c | 613 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
614 | as setting the cursor in a parent window also effects the |
615 | windows above so that checking for the current cursor is | |
616 | not possible. */ | |
85ec2f26 RR |
617 | |
618 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 619 | { |
8a0681f9 VZ |
620 | /* if the toolbar is dockable, then m_widget stands for the |
621 | GtkHandleBox widget, which uses its own window so that we | |
622 | can set the cursor for it. if the toolbar is not dockable, | |
623 | m_widget comes from m_toolbar which uses its parent's | |
624 | window ("windowless windows") and thus we cannot set the | |
625 | cursor. */ | |
626 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
627 | } | |
628 | ||
222ed1d6 | 629 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
630 | while ( node ) |
631 | { | |
632 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
633 | node = node->GetNext(); | |
634 | ||
635 | GtkWidget *item = tool->m_item; | |
636 | if ( item ) | |
637 | { | |
638 | GdkWindow *window = item->window; | |
639 | ||
640 | if ( window ) | |
641 | { | |
642 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
643 | } | |
644 | } | |
9b7e522a RR |
645 | } |
646 | } | |
647 | ||
e39af974 JS |
648 | if (wxUpdateUIEvent::CanUpdate(this)) |
649 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
650 | } |
651 | ||
9d522606 RD |
652 | |
653 | // ---------------------------------------------------------------------------- | |
654 | ||
655 | // static | |
656 | wxVisualAttributes | |
657 | wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
658 | { | |
9d522606 | 659 | return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); |
9d522606 RD |
660 | } |
661 | ||
a1f79c1e | 662 | #endif // wxUSE_TOOLBAR_NATIVE |