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