]>
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 |
a3622daa | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
8a0681f9 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
c801d85f | 19 | #ifdef __GNUG__ |
8a0681f9 | 20 | #pragma implementation "tbargtk.h" |
c801d85f KB |
21 | #endif |
22 | ||
23 | #include "wx/toolbar.h" | |
dcf924a3 | 24 | |
8a0681f9 | 25 | #if wxUSE_TOOLBAR_NATIVE |
dcf924a3 | 26 | |
e702ff0f | 27 | #include "wx/frame.h" |
c801d85f | 28 | |
9e691f46 VZ |
29 | #include <glib.h> |
30 | #include "wx/gtk/private.h" | |
83624f79 | 31 | |
f6bcfd97 BP |
32 | extern GdkFont *GtkGetDefaultGuiFont(); |
33 | ||
8a0681f9 VZ |
34 | // ---------------------------------------------------------------------------- |
35 | // globals | |
36 | // ---------------------------------------------------------------------------- | |
acfd422a | 37 | |
8a0681f9 | 38 | // idle system |
acfd422a RR |
39 | extern void wxapp_install_idle_handler(); |
40 | extern bool g_isIdle; | |
41 | ||
314055fa | 42 | // data |
9b7e522a RR |
43 | extern bool g_blockEventsOnDrag; |
44 | extern wxCursor g_globalCursor; | |
314055fa | 45 | |
e76c0b5f VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // private functions | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | // translate wxWindows toolbar style flags to GTK orientation and style | |
51 | static void GetGtkStyle(long style, | |
52 | GtkOrientation *orient, GtkToolbarStyle *gtkStyle) | |
53 | { | |
54 | *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL | |
55 | : GTK_ORIENTATION_HORIZONTAL; | |
56 | ||
57 | ||
58 | if ( style & wxTB_TEXT ) | |
59 | { | |
f9dae779 VZ |
60 | *gtkStyle = style & wxTB_NOICONS ? GTK_TOOLBAR_TEXT : |
61 | ( style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ: 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 | ||
8a0681f9 VZ |
123 | GtkWidget *m_item; |
124 | GtkWidget *m_pixmap; | |
125 | ||
126 | protected: | |
127 | void Init(); | |
128 | }; | |
129 | ||
130 | // ---------------------------------------------------------------------------- | |
131 | // wxWin macros | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
12ed316d | 134 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) |
8a0681f9 VZ |
135 | |
136 | // ============================================================================ | |
137 | // implementation | |
138 | // ============================================================================ | |
139 | ||
c801d85f | 140 | //----------------------------------------------------------------------------- |
2f2aa628 | 141 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
142 | //----------------------------------------------------------------------------- |
143 | ||
8a0681f9 VZ |
144 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), |
145 | wxToolBarTool *tool ) | |
c801d85f | 146 | { |
248bcf0a | 147 | if (g_isIdle) |
59fe1666 RR |
148 | wxapp_install_idle_handler(); |
149 | ||
8a0681f9 | 150 | wxToolBar *tbar = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 151 | |
9864c56d | 152 | if (tbar->m_blockEvent) return; |
acfd422a | 153 | |
1144d24d | 154 | if (g_blockEventsOnDrag) return; |
8a0681f9 | 155 | if (!tool->IsEnabled()) return; |
a3622daa | 156 | |
8a0681f9 | 157 | if (tool->CanBeToggled()) |
248bcf0a | 158 | { |
8a0681f9 VZ |
159 | tool->Toggle(); |
160 | ||
161 | wxBitmap bitmap = tool->GetBitmap(); | |
162 | if ( bitmap.Ok() ) | |
163 | { | |
85eb36c2 | 164 | GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); |
8a0681f9 VZ |
165 | |
166 | GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() | |
167 | : (GdkBitmap *)NULL; | |
168 | ||
85eb36c2 | 169 | gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); |
8a0681f9 | 170 | } |
38762f09 VZ |
171 | |
172 | if ( tool->IsRadio() && !tool->IsToggled() ) | |
173 | { | |
174 | // radio button went up, don't report this as a wxWin event | |
175 | return; | |
176 | } | |
85eb36c2 | 177 | } |
a3622daa | 178 | |
8a0681f9 | 179 | tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ); |
fc008f25 | 180 | } |
c801d85f | 181 | |
2f2aa628 | 182 | //----------------------------------------------------------------------------- |
a8945eef | 183 | // "enter_notify_event" / "leave_notify_event" |
2f2aa628 RR |
184 | //----------------------------------------------------------------------------- |
185 | ||
248bcf0a | 186 | static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), |
a8945eef MB |
187 | GdkEventCrossing *gdk_event, |
188 | wxToolBarTool *tool ) | |
314055fa | 189 | { |
acfd422a RR |
190 | if (g_isIdle) wxapp_install_idle_handler(); |
191 | ||
1144d24d | 192 | if (g_blockEventsOnDrag) return TRUE; |
248bcf0a | 193 | |
8a0681f9 | 194 | wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 195 | |
47c93b63 | 196 | // emit the event |
a8945eef MB |
197 | if( gdk_event->type == GDK_ENTER_NOTIFY ) |
198 | tb->OnMouseEnter( tool->GetId() ); | |
199 | else | |
200 | tb->OnMouseEnter( -1 ); | |
248bcf0a | 201 | |
1144d24d | 202 | return FALSE; |
314055fa RR |
203 | } |
204 | ||
bf9e3e73 RR |
205 | //----------------------------------------------------------------------------- |
206 | // InsertChild callback for wxToolBar | |
207 | //----------------------------------------------------------------------------- | |
208 | ||
8a0681f9 VZ |
209 | static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), |
210 | wxWindow* WXUNUSED(child) ) | |
bf9e3e73 | 211 | { |
47c93b63 | 212 | // we don't do anything here |
bf9e3e73 RR |
213 | } |
214 | ||
8a0681f9 VZ |
215 | // ---------------------------------------------------------------------------- |
216 | // wxToolBarTool | |
217 | // ---------------------------------------------------------------------------- | |
c801d85f | 218 | |
8a0681f9 VZ |
219 | void wxToolBarTool::Init() |
220 | { | |
221 | m_item = | |
222 | m_pixmap = (GtkWidget *)NULL; | |
223 | } | |
c801d85f | 224 | |
8a0681f9 | 225 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
e76c0b5f | 226 | const wxString& text, |
8a0681f9 VZ |
227 | const wxBitmap& bitmap1, |
228 | const wxBitmap& bitmap2, | |
e76c0b5f | 229 | wxItemKind kind, |
8a0681f9 VZ |
230 | wxObject *clientData, |
231 | const wxString& shortHelpString, | |
232 | const wxString& longHelpString) | |
233 | { | |
e76c0b5f | 234 | return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
235 | clientData, shortHelpString, longHelpString); |
236 | } | |
b1da76e1 | 237 | |
8a0681f9 | 238 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) |
c801d85f | 239 | { |
8a0681f9 | 240 | return new wxToolBarTool(this, control); |
fc008f25 | 241 | } |
c801d85f | 242 | |
8a0681f9 VZ |
243 | //----------------------------------------------------------------------------- |
244 | // wxToolBar construction | |
245 | //----------------------------------------------------------------------------- | |
246 | ||
247 | void wxToolBar::Init() | |
c801d85f | 248 | { |
8a0681f9 VZ |
249 | m_fg = |
250 | m_bg = (GdkColor *)NULL; | |
8a0681f9 | 251 | m_toolbar = (GtkToolbar *)NULL; |
9864c56d | 252 | m_blockEvent = FALSE; |
fc008f25 | 253 | } |
c801d85f | 254 | |
a3622daa | 255 | wxToolBar::~wxToolBar() |
c801d85f | 256 | { |
83624f79 RR |
257 | delete m_fg; |
258 | delete m_bg; | |
fc008f25 | 259 | } |
c801d85f | 260 | |
8a0681f9 VZ |
261 | bool wxToolBar::Create( wxWindow *parent, |
262 | wxWindowID id, | |
263 | const wxPoint& pos, | |
264 | const wxSize& size, | |
265 | long style, | |
266 | const wxString& name ) | |
c801d85f | 267 | { |
1144d24d | 268 | m_needParent = TRUE; |
bf9e3e73 | 269 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; |
a3622daa | 270 | |
8a0681f9 VZ |
271 | if ( !PreCreation( parent, pos, size ) || |
272 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
4dcaf11a | 273 | { |
223d09f6 | 274 | wxFAIL_MSG( wxT("wxToolBar creation failed") ); |
c801d85f | 275 | |
8a0681f9 VZ |
276 | return FALSE; |
277 | } | |
a3622daa | 278 | |
9e691f46 VZ |
279 | #ifdef __WXGTK20__ |
280 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); | |
e76c0b5f | 281 | GtkSetStyle(); |
2b5f62a0 VZ |
282 | |
283 | // Doesn't work this way. | |
284 | // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY; | |
285 | // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL); | |
9e691f46 | 286 | #else |
e76c0b5f VZ |
287 | GtkOrientation orient; |
288 | GtkToolbarStyle gtkStyle; | |
289 | GetGtkStyle(style, &orient, >kStyle); | |
290 | ||
291 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new(orient, gtkStyle) ); | |
9e691f46 | 292 | #endif |
a3622daa | 293 | |
8a0681f9 | 294 | SetToolSeparation(7); |
3502e687 RR |
295 | |
296 | if (style & wxTB_DOCKABLE) | |
297 | { | |
298 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
299 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
300 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
8a0681f9 | 301 | |
f03fc89f | 302 | if (style & wxTB_FLAT) |
858b5bdd | 303 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
3502e687 RR |
304 | } |
305 | else | |
248bcf0a RD |
306 | { |
307 | m_widget = gtk_event_box_new(); | |
308 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); | |
309 | ConnectWidget( m_widget ); | |
310 | gtk_widget_show(GTK_WIDGET(m_toolbar)); | |
3502e687 | 311 | } |
8a0681f9 | 312 | |
1144d24d | 313 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); |
8a0681f9 | 314 | |
9e691f46 VZ |
315 | // FIXME: there is no such function for toolbars in 2.0 |
316 | #ifndef __WXGTK20__ | |
858b5bdd RR |
317 | if (style & wxTB_FLAT) |
318 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
9e691f46 | 319 | #endif |
be25e480 | 320 | |
83624f79 RR |
321 | |
322 | m_fg = new GdkColor; | |
248bcf0a RD |
323 | m_fg->red = 0; |
324 | m_fg->green = 0; | |
83624f79 | 325 | m_fg->blue = 0; |
be25e480 RR |
326 | wxColour fg(0,0,0); |
327 | fg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) ); | |
328 | m_fg->pixel = fg.GetPixel(); | |
248bcf0a | 329 | |
83624f79 RR |
330 | m_bg = new GdkColor; |
331 | m_bg->red = 65535; | |
332 | m_bg->green = 65535; | |
be25e480 RR |
333 | m_bg->blue = 49980; |
334 | wxColour bg(255,255,196); | |
335 | bg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) ); | |
336 | m_bg->pixel = bg.GetPixel(); | |
248bcf0a | 337 | |
fac4253c RR |
338 | gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips ); |
339 | ||
248bcf0a | 340 | GtkStyle *g_style = |
8a0681f9 | 341 | gtk_style_copy( |
248bcf0a | 342 | gtk_widget_get_style( |
8a0681f9 VZ |
343 | GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) ); |
344 | ||
fac4253c | 345 | g_style->bg[GTK_STATE_NORMAL] = *m_bg; |
9e691f46 | 346 | |
fac4253c | 347 | gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style ); |
a3622daa | 348 | |
f03fc89f | 349 | m_parent->DoAddChild( this ); |
8a0681f9 | 350 | |
1144d24d | 351 | PostCreation(); |
a3622daa | 352 | |
1144d24d | 353 | Show( TRUE ); |
a3622daa | 354 | |
1144d24d | 355 | return TRUE; |
fc008f25 | 356 | } |
c801d85f | 357 | |
e76c0b5f VZ |
358 | void wxToolBar::GtkSetStyle() |
359 | { | |
360 | GtkOrientation orient; | |
361 | GtkToolbarStyle style; | |
362 | GetGtkStyle(GetWindowStyle(), &orient, &style); | |
363 | ||
364 | gtk_toolbar_set_orientation(m_toolbar, orient); | |
365 | gtk_toolbar_set_style(m_toolbar, style); | |
366 | } | |
367 | ||
368 | void wxToolBar::SetWindowStyleFlag( long style ) | |
369 | { | |
370 | wxToolBarBase::SetWindowStyleFlag(style); | |
371 | ||
372 | if ( m_toolbar ) | |
373 | GtkSetStyle(); | |
374 | } | |
375 | ||
8a0681f9 | 376 | bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 377 | { |
8a0681f9 | 378 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 379 | |
2b5f62a0 | 380 | #ifndef __WXGTK20__ |
6a1359c0 VZ |
381 | // if we have inserted a space before all the tools we must change the GTK |
382 | // index by 1 | |
383 | size_t posGtk = m_xMargin > 1 ? pos + 1 : pos; | |
2b5f62a0 VZ |
384 | #else |
385 | size_t posGtk = pos; | |
386 | #endif | |
248bcf0a | 387 | |
8a0681f9 VZ |
388 | if ( tool->IsButton() ) |
389 | { | |
2b5f62a0 VZ |
390 | if ( !HasFlag(wxTB_NOICONS) ) |
391 | { | |
392 | wxBitmap bitmap = tool->GetNormalBitmap(); | |
c801d85f | 393 | |
2b5f62a0 VZ |
394 | wxCHECK_MSG( bitmap.Ok(), FALSE, |
395 | wxT("invalid bitmap for wxToolBar icon") ); | |
a3622daa | 396 | |
2b5f62a0 VZ |
397 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE, |
398 | wxT("wxToolBar doesn't support GdkBitmap") ); | |
03f38c58 | 399 | |
2b5f62a0 VZ |
400 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE, |
401 | wxT("wxToolBar::Add needs a wxBitmap") ); | |
248bcf0a | 402 | |
2b5f62a0 | 403 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
248bcf0a | 404 | |
2b5f62a0 | 405 | GdkPixmap *pixmap = bitmap.GetPixmap(); |
a3622daa | 406 | |
2b5f62a0 VZ |
407 | GdkBitmap *mask = (GdkBitmap *)NULL; |
408 | if ( bitmap.GetMask() ) | |
409 | mask = bitmap.GetMask()->GetBitmap(); | |
248bcf0a | 410 | |
2b5f62a0 VZ |
411 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); |
412 | gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE ); | |
248bcf0a | 413 | |
2b5f62a0 | 414 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 415 | |
2b5f62a0 VZ |
416 | tool->m_pixmap = tool_pixmap; |
417 | } | |
8a0681f9 | 418 | } |
c801d85f | 419 | |
8a0681f9 VZ |
420 | switch ( tool->GetStyle() ) |
421 | { | |
422 | case wxTOOL_STYLE_BUTTON: | |
38762f09 VZ |
423 | // for a radio button we need the widget which starts the radio |
424 | // group it belongs to, i.e. the first radio button immediately | |
425 | // preceding this one | |
8a0681f9 | 426 | { |
38762f09 VZ |
427 | GtkWidget *widget = NULL; |
428 | ||
429 | if ( tool->IsRadio() ) | |
430 | { | |
431 | wxToolBarToolsList::Node *node = pos ? m_tools.Item(pos - 1) | |
432 | : NULL; | |
433 | while ( node ) | |
434 | { | |
435 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
436 | if ( !tool->IsRadio() ) | |
437 | break; | |
438 | ||
439 | widget = tool->m_item; | |
440 | ||
441 | node = node->GetPrevious(); | |
442 | } | |
443 | ||
444 | if ( !widget ) | |
445 | { | |
446 | // this is the first button in the radio button group, | |
447 | // it will be toggled automatically by GTK so bring the | |
448 | // internal flag in sync | |
449 | tool->Toggle(TRUE); | |
450 | } | |
451 | } | |
452 | ||
453 | tool->m_item = gtk_toolbar_insert_element | |
454 | ( | |
455 | m_toolbar, | |
456 | tool->GetGtkChildType(), | |
457 | widget, | |
458 | tool->GetLabel().empty() | |
459 | ? NULL | |
fab591c5 | 460 | : (const char*) wxGTK_CONV( tool->GetLabel() ), |
38762f09 VZ |
461 | tool->GetShortHelp().empty() |
462 | ? NULL | |
fab591c5 | 463 | : (const char*) wxGTK_CONV( tool->GetShortHelp() ), |
38762f09 VZ |
464 | "", // tooltip_private_text (?) |
465 | tool->m_pixmap, | |
466 | (GtkSignalFunc)gtk_toolbar_callback, | |
467 | (gpointer)tool, | |
6a1359c0 | 468 | posGtk |
38762f09 VZ |
469 | ); |
470 | ||
471 | if ( !tool->m_item ) | |
472 | { | |
473 | wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") ); | |
474 | ||
475 | return FALSE; | |
476 | } | |
2b5f62a0 | 477 | |
38762f09 | 478 | gtk_signal_connect( GTK_OBJECT(tool->m_item), |
248bcf0a | 479 | "enter_notify_event", |
38762f09 VZ |
480 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
481 | (gpointer)tool ); | |
482 | gtk_signal_connect( GTK_OBJECT(tool->m_item), | |
248bcf0a | 483 | "leave_notify_event", |
38762f09 VZ |
484 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
485 | (gpointer)tool ); | |
8a0681f9 | 486 | } |
8a0681f9 VZ |
487 | break; |
488 | ||
489 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 490 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
491 | |
492 | // skip the rest | |
493 | return TRUE; | |
bf9e3e73 | 494 | |
8a0681f9 VZ |
495 | case wxTOOL_STYLE_CONTROL: |
496 | gtk_toolbar_insert_widget( | |
497 | m_toolbar, | |
498 | tool->GetControl()->m_widget, | |
499 | (const char *) NULL, | |
500 | (const char *) NULL, | |
6a1359c0 | 501 | posGtk |
8a0681f9 VZ |
502 | ); |
503 | break; | |
504 | } | |
bf9e3e73 | 505 | |
bf9e3e73 | 506 | GtkRequisition req; |
2afa14f2 OK |
507 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
508 | (m_widget, &req ); | |
00655497 | 509 | m_width = req.width + m_xMargin; |
6f67eafe | 510 | m_height = req.height + 2*m_yMargin; |
bf9e3e73 | 511 | |
bf9e3e73 RR |
512 | return TRUE; |
513 | } | |
514 | ||
9c2882d9 | 515 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) |
c801d85f | 516 | { |
8a0681f9 | 517 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 518 | |
8a0681f9 | 519 | switch ( tool->GetStyle() ) |
97d7bfb8 | 520 | { |
8a0681f9 VZ |
521 | case wxTOOL_STYLE_CONTROL: |
522 | tool->GetControl()->Destroy(); | |
523 | break; | |
97d7bfb8 | 524 | |
8a0681f9 VZ |
525 | case wxTOOL_STYLE_BUTTON: |
526 | gtk_widget_destroy( tool->m_item ); | |
527 | break; | |
97d7bfb8 | 528 | |
8a0681f9 VZ |
529 | //case wxTOOL_STYLE_SEPARATOR: -- nothing to do |
530 | } | |
c801d85f | 531 | |
1144d24d | 532 | return TRUE; |
fc008f25 | 533 | } |
46dc76ba | 534 | |
8a0681f9 VZ |
535 | // ---------------------------------------------------------------------------- |
536 | // wxToolBar tools state | |
537 | // ---------------------------------------------------------------------------- | |
538 | ||
539 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) | |
c801d85f | 540 | { |
8a0681f9 VZ |
541 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
542 | ||
8a0681f9 | 543 | if (tool->m_item) |
fab591c5 | 544 | { |
8a0681f9 | 545 | gtk_widget_set_sensitive( tool->m_item, enable ); |
fab591c5 | 546 | } |
fc008f25 | 547 | } |
c801d85f | 548 | |
248bcf0a | 549 | void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) |
c801d85f | 550 | { |
8a0681f9 VZ |
551 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
552 | ||
553 | GtkWidget *item = tool->m_item; | |
554 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 555 | { |
8a0681f9 VZ |
556 | wxBitmap bitmap = tool->GetBitmap(); |
557 | if ( bitmap.Ok() ) | |
558 | { | |
559 | GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); | |
560 | ||
561 | GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() | |
562 | : (GdkBitmap *)NULL; | |
563 | ||
564 | gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); | |
1144d24d | 565 | } |
c801d85f | 566 | |
9864c56d | 567 | m_blockEvent = TRUE; |
8a0681f9 VZ |
568 | |
569 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle ); | |
248bcf0a | 570 | |
9864c56d | 571 | m_blockEvent = FALSE; |
1144d24d | 572 | } |
fc008f25 | 573 | } |
c801d85f | 574 | |
8a0681f9 VZ |
575 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
576 | bool WXUNUSED(toggle)) | |
c801d85f | 577 | { |
8a0681f9 VZ |
578 | // VZ: absolutely no idea about how to do it |
579 | wxFAIL_MSG( _T("not implemented") ); | |
fc008f25 | 580 | } |
c801d85f | 581 | |
8a0681f9 VZ |
582 | // ---------------------------------------------------------------------------- |
583 | // wxToolBar geometry | |
584 | // ---------------------------------------------------------------------------- | |
585 | ||
586 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), | |
587 | wxCoord WXUNUSED(y)) const | |
c801d85f | 588 | { |
8a0681f9 VZ |
589 | // VZ: GTK+ doesn't seem to have such thing |
590 | wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") ); | |
591 | ||
592 | return (wxToolBarToolBase *)NULL; | |
fc008f25 | 593 | } |
c801d85f | 594 | |
1144d24d | 595 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 596 | { |
8a0681f9 VZ |
597 | wxCHECK_RET( GetToolsCount() == 0, |
598 | wxT("wxToolBar::SetMargins must be called before adding tools.") ); | |
248bcf0a | 599 | |
2b5f62a0 | 600 | #ifndef __WXGTK20__ |
6a1359c0 VZ |
601 | if (x > 1) |
602 | gtk_toolbar_append_space( m_toolbar ); // oh well | |
2b5f62a0 | 603 | #endif |
248bcf0a | 604 | |
1144d24d RR |
605 | m_xMargin = x; |
606 | m_yMargin = y; | |
fc008f25 | 607 | } |
c801d85f | 608 | |
cf4219e7 | 609 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 610 | { |
9e691f46 VZ |
611 | // FIXME: this function disappeared |
612 | #ifndef __WXGTK20__ | |
1144d24d | 613 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
9e691f46 VZ |
614 | #endif |
615 | ||
8a0681f9 | 616 | m_toolSeparation = separation; |
1144d24d RR |
617 | } |
618 | ||
a1f79c1e VZ |
619 | void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) |
620 | { | |
621 | wxToolBarTool *tool = (wxToolBarTool *)FindById(id); | |
622 | ||
623 | if ( tool ) | |
624 | { | |
625 | (void)tool->SetShortHelp(helpString); | |
626 | gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item, | |
fab591c5 | 627 | wxGTK_CONV( helpString ), ""); |
a1f79c1e VZ |
628 | } |
629 | } | |
630 | ||
8a0681f9 VZ |
631 | // ---------------------------------------------------------------------------- |
632 | // wxToolBar idle handling | |
633 | // ---------------------------------------------------------------------------- | |
1144d24d | 634 | |
9b7e522a RR |
635 | void wxToolBar::OnInternalIdle() |
636 | { | |
637 | wxCursor cursor = m_cursor; | |
638 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
639 | ||
f7a11f8c | 640 | if (cursor.Ok()) |
9b7e522a | 641 | { |
f7a11f8c | 642 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
643 | as setting the cursor in a parent window also effects the |
644 | windows above so that checking for the current cursor is | |
645 | not possible. */ | |
85ec2f26 RR |
646 | |
647 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 648 | { |
8a0681f9 VZ |
649 | /* if the toolbar is dockable, then m_widget stands for the |
650 | GtkHandleBox widget, which uses its own window so that we | |
651 | can set the cursor for it. if the toolbar is not dockable, | |
652 | m_widget comes from m_toolbar which uses its parent's | |
653 | window ("windowless windows") and thus we cannot set the | |
654 | cursor. */ | |
655 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
656 | } | |
657 | ||
658 | wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
659 | while ( node ) | |
660 | { | |
661 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
662 | node = node->GetNext(); | |
663 | ||
664 | GtkWidget *item = tool->m_item; | |
665 | if ( item ) | |
666 | { | |
667 | GdkWindow *window = item->window; | |
668 | ||
669 | if ( window ) | |
670 | { | |
671 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
672 | } | |
673 | } | |
9b7e522a RR |
674 | } |
675 | } | |
676 | ||
e39af974 JS |
677 | if (wxUpdateUIEvent::CanUpdate(this)) |
678 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
679 | } |
680 | ||
a1f79c1e | 681 | #endif // wxUSE_TOOLBAR_NATIVE |