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