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