]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
3 | // Purpose: GTK toolbar | |
4 | // Author: Robert Roebling | |
32e9da8b | 5 | // RCS-ID: $Id$ |
c801d85f | 6 | // Copyright: (c) Robert Roebling |
a3622daa | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "tbargtk.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/toolbar.h" | |
dcf924a3 RR |
15 | |
16 | #if wxUSE_TOOLBAR | |
17 | ||
e702ff0f | 18 | #include "wx/frame.h" |
c801d85f | 19 | |
83624f79 RR |
20 | #include "glib.h" |
21 | #include "gdk/gdk.h" | |
22 | #include "gtk/gtk.h" | |
23 | ||
acfd422a RR |
24 | //----------------------------------------------------------------------------- |
25 | // idle system | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | extern void wxapp_install_idle_handler(); | |
29 | extern bool g_isIdle; | |
30 | ||
314055fa RR |
31 | //----------------------------------------------------------------------------- |
32 | // data | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | extern bool g_blockEventsOnDrag; | |
36 | ||
c801d85f | 37 | //----------------------------------------------------------------------------- |
2f2aa628 | 38 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
39 | //----------------------------------------------------------------------------- |
40 | ||
41 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) | |
42 | { | |
acfd422a RR |
43 | if (g_isIdle) wxapp_install_idle_handler(); |
44 | ||
1144d24d RR |
45 | if (g_blockEventsOnDrag) return; |
46 | if (!tool->m_enabled) return; | |
a3622daa | 47 | |
85eb36c2 RR |
48 | if (tool->m_isToggle) |
49 | { | |
50 | tool->m_toggleState = !tool->m_toggleState; | |
51 | ||
52 | if (tool->m_bitmap2.Ok()) | |
53 | { | |
54 | wxBitmap bitmap = tool->m_bitmap1; | |
55 | if (tool->m_toggleState) bitmap = tool->m_bitmap2; | |
56 | ||
57 | GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); | |
58 | ||
59 | GdkBitmap *mask = (GdkBitmap *) NULL; | |
60 | if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap(); | |
61 | ||
62 | gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); | |
63 | } | |
64 | } | |
a3622daa | 65 | |
1144d24d | 66 | tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState ); |
fc008f25 | 67 | } |
c801d85f | 68 | |
2f2aa628 RR |
69 | //----------------------------------------------------------------------------- |
70 | // "enter_notify_event" | |
71 | //----------------------------------------------------------------------------- | |
72 | ||
314055fa RR |
73 | static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), |
74 | GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) | |
75 | { | |
acfd422a RR |
76 | if (g_isIdle) wxapp_install_idle_handler(); |
77 | ||
1144d24d | 78 | if (g_blockEventsOnDrag) return TRUE; |
b98d804b | 79 | |
b98d804b RR |
80 | |
81 | wxToolBar *tb = tool->m_owner; | |
82 | ||
c693edf3 RR |
83 | #if (GTK_MINOR_VERSION == 0) |
84 | /* we grey-out the tip text of disabled tool in GTK 1.0 */ | |
b98d804b RR |
85 | if (tool->m_enabled) |
86 | { | |
87 | if (tb->m_fg->red != 0) | |
f03fc89f | 88 | { |
b98d804b RR |
89 | tb->m_fg->red = 0; |
90 | tb->m_fg->green = 0; | |
91 | tb->m_fg->blue = 0; | |
92 | gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); | |
f03fc89f | 93 | |
b98d804b | 94 | gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); |
f03fc89f | 95 | } |
b98d804b RR |
96 | } |
97 | else | |
98 | { | |
99 | if (tb->m_fg->red == 0) | |
f03fc89f | 100 | { |
b98d804b RR |
101 | tb->m_fg->red = 33000; |
102 | tb->m_fg->green = 33000; | |
103 | tb->m_fg->blue = 33000; | |
104 | gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); | |
105 | gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); | |
f03fc89f | 106 | } |
b98d804b | 107 | } |
f7ac40d1 | 108 | #endif |
b98d804b RR |
109 | |
110 | /* emit the event */ | |
314055fa | 111 | |
b98d804b | 112 | tb->OnMouseEnter( tool->m_index ); |
314055fa | 113 | |
1144d24d | 114 | return FALSE; |
314055fa RR |
115 | } |
116 | ||
2f2aa628 RR |
117 | //----------------------------------------------------------------------------- |
118 | // wxToolBar | |
c801d85f KB |
119 | //----------------------------------------------------------------------------- |
120 | ||
716b7364 | 121 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl) |
c801d85f | 122 | |
b1da76e1 RR |
123 | BEGIN_EVENT_TABLE(wxToolBar, wxControl) |
124 | EVT_IDLE(wxToolBar::OnIdle) | |
125 | END_EVENT_TABLE() | |
126 | ||
a3622daa | 127 | wxToolBar::wxToolBar() |
c801d85f | 128 | { |
fc008f25 | 129 | } |
c801d85f | 130 | |
a3622daa | 131 | wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id, |
c801d85f | 132 | const wxPoint& pos, const wxSize& size, |
debe6624 | 133 | long style, const wxString& name ) |
c801d85f | 134 | { |
1144d24d | 135 | Create( parent, id, pos, size, style, name ); |
fc008f25 | 136 | } |
c801d85f | 137 | |
a3622daa | 138 | wxToolBar::~wxToolBar() |
c801d85f | 139 | { |
83624f79 RR |
140 | delete m_fg; |
141 | delete m_bg; | |
fc008f25 | 142 | } |
c801d85f | 143 | |
a3622daa | 144 | bool wxToolBar::Create( wxWindow *parent, wxWindowID id, |
c801d85f | 145 | const wxPoint& pos, const wxSize& size, |
debe6624 | 146 | long style, const wxString& name ) |
c801d85f | 147 | { |
1144d24d | 148 | m_needParent = TRUE; |
a3622daa | 149 | |
4dcaf11a RR |
150 | if (!PreCreation( parent, pos, size ) || |
151 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
152 | { | |
153 | wxFAIL_MSG( _T("wxToolBar creation failed") ); | |
154 | return FALSE; | |
155 | } | |
c801d85f | 156 | |
1144d24d | 157 | m_tools.DeleteContents( TRUE ); |
a3622daa | 158 | |
1144d24d RR |
159 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, |
160 | GTK_TOOLBAR_ICONS ) ); | |
a3622daa | 161 | |
1144d24d RR |
162 | m_separation = 5; |
163 | gtk_toolbar_set_space_size( m_toolbar, m_separation ); | |
164 | m_hasToolAlready = FALSE; | |
3502e687 RR |
165 | |
166 | if (style & wxTB_DOCKABLE) | |
167 | { | |
168 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
169 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
170 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
171 | ||
b0795d45 | 172 | #if (GTK_MINOR_VERSION > 0) |
f03fc89f | 173 | if (style & wxTB_FLAT) |
858b5bdd | 174 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
b0795d45 | 175 | #endif |
3502e687 RR |
176 | } |
177 | else | |
178 | { | |
179 | m_widget = GTK_WIDGET(m_toolbar); | |
180 | } | |
f03fc89f | 181 | |
1144d24d | 182 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); |
858b5bdd RR |
183 | |
184 | #if (GTK_MINOR_VERSION > 0) | |
185 | if (style & wxTB_FLAT) | |
186 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
187 | #endif | |
83624f79 RR |
188 | |
189 | m_fg = new GdkColor; | |
190 | m_fg->red = 0; | |
191 | m_fg->green = 0; | |
192 | m_fg->blue = 0; | |
193 | gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg ); | |
b46e8696 | 194 | |
83624f79 RR |
195 | m_bg = new GdkColor; |
196 | m_bg->red = 65535; | |
197 | m_bg->green = 65535; | |
198 | m_bg->blue = 50000; | |
199 | gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg ); | |
b46e8696 | 200 | |
fac4253c RR |
201 | #if (GTK_MINOR_VERSION > 0) |
202 | gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips ); | |
203 | ||
204 | GtkStyle *g_style = | |
205 | gtk_style_copy( | |
206 | gtk_widget_get_style( | |
207 | GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) ); | |
f03fc89f | 208 | |
fac4253c RR |
209 | g_style->bg[GTK_STATE_NORMAL] = *m_bg; |
210 | gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style ); | |
211 | #else | |
83624f79 | 212 | gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg ); |
fac4253c | 213 | #endif |
a3622daa | 214 | |
1144d24d RR |
215 | m_xMargin = 0; |
216 | m_yMargin = 0; | |
217 | ||
f03fc89f | 218 | m_parent->DoAddChild( this ); |
6ca41e57 | 219 | |
1144d24d | 220 | PostCreation(); |
a3622daa | 221 | |
1144d24d | 222 | Show( TRUE ); |
a3622daa | 223 | |
1144d24d | 224 | return TRUE; |
fc008f25 | 225 | } |
c801d85f | 226 | |
716b7364 | 227 | bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown ) |
c801d85f | 228 | { |
1144d24d RR |
229 | wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex ); |
230 | event.SetEventObject(this); | |
231 | event.SetInt( toolIndex ); | |
232 | event.SetExtraLong((long) toggleDown); | |
c801d85f | 233 | |
1144d24d | 234 | GetEventHandler()->ProcessEvent(event); |
c801d85f | 235 | |
1144d24d | 236 | return TRUE; |
fc008f25 | 237 | } |
c801d85f | 238 | |
716b7364 | 239 | void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) ) |
c801d85f | 240 | { |
1144d24d RR |
241 | wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex ); |
242 | event.SetEventObject( this ); | |
243 | event.SetInt( toolIndex ); | |
c801d85f | 244 | |
1144d24d | 245 | GetEventHandler()->ProcessEvent(event); |
fc008f25 | 246 | } |
c801d85f | 247 | |
716b7364 | 248 | void wxToolBar::OnMouseEnter( int toolIndex ) |
c801d85f | 249 | { |
1144d24d RR |
250 | wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() ); |
251 | event.SetEventObject(this); | |
252 | event.SetInt( toolIndex ); | |
314055fa | 253 | |
1144d24d | 254 | GetEventHandler()->ProcessEvent(event); |
fc008f25 | 255 | } |
c801d85f | 256 | |
a3622daa | 257 | wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, |
debe6624 JS |
258 | const wxBitmap& pushedBitmap, bool toggle, |
259 | float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData, | |
c801d85f KB |
260 | const wxString& helpString1, const wxString& helpString2 ) |
261 | { | |
1144d24d RR |
262 | m_hasToolAlready = TRUE; |
263 | ||
264 | wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL, | |
05939a81 | 265 | _T("invalid bitmap for wxToolBar icon") ); |
a3622daa | 266 | |
1144d24d | 267 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL, |
05939a81 | 268 | _T("wxToolBar doesn't support GdkBitmap") ); |
03f38c58 | 269 | |
1144d24d | 270 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL, |
05939a81 | 271 | _T("wxToolBar::Add needs a wxBitmap") ); |
903f689b | 272 | |
1144d24d | 273 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
903f689b | 274 | |
903f689b | 275 | GdkPixmap *pixmap = bitmap.GetPixmap(); |
a3622daa | 276 | |
68dda785 VZ |
277 | GdkBitmap *mask = (GdkBitmap *)NULL; |
278 | if ( bitmap.GetMask() ) | |
279 | mask = bitmap.GetMask()->GetBitmap(); | |
903f689b RR |
280 | |
281 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); | |
c693edf3 | 282 | #if (GTK_MINOR_VERSION > 0) |
f7ac40d1 | 283 | gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE ); |
c693edf3 | 284 | #endif |
f7ac40d1 | 285 | |
1144d24d | 286 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 287 | |
2b1c162e RR |
288 | wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, |
289 | toggle, clientData, | |
290 | helpString1, helpString2, | |
f03fc89f | 291 | tool_pixmap ); |
2b1c162e | 292 | |
1144d24d RR |
293 | GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON |
294 | : GTK_TOOLBAR_CHILD_BUTTON; | |
03f38c58 | 295 | |
1144d24d | 296 | GtkWidget *item = gtk_toolbar_append_element |
68dda785 VZ |
297 | ( |
298 | GTK_TOOLBAR(m_toolbar), | |
299 | ctype, | |
300 | (GtkWidget *)NULL, | |
301 | (const char *)NULL, | |
05939a81 | 302 | helpString1.mbc_str(), |
68dda785 VZ |
303 | "", |
304 | tool_pixmap, | |
305 | (GtkSignalFunc)gtk_toolbar_callback, | |
306 | (gpointer)tool | |
307 | ); | |
308 | ||
1144d24d | 309 | tool->m_item = item; |
03f38c58 | 310 | |
1144d24d RR |
311 | gtk_signal_connect( GTK_OBJECT(tool->m_item), |
312 | "enter_notify_event", | |
313 | GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback), | |
314 | (gpointer)tool ); | |
314055fa | 315 | |
1144d24d | 316 | m_tools.Append( tool ); |
a3622daa | 317 | |
1144d24d | 318 | return tool; |
fc008f25 | 319 | } |
c801d85f | 320 | |
03f38c58 | 321 | void wxToolBar::AddSeparator() |
c801d85f | 322 | { |
1144d24d | 323 | gtk_toolbar_append_space( m_toolbar ); |
fc008f25 | 324 | } |
c801d85f | 325 | |
03f38c58 | 326 | void wxToolBar::ClearTools() |
c801d85f | 327 | { |
05939a81 | 328 | wxFAIL_MSG( _T("wxToolBar::ClearTools not implemented") ); |
fc008f25 | 329 | } |
c801d85f | 330 | |
1144d24d | 331 | bool wxToolBar::Realize() |
46dc76ba | 332 | { |
1144d24d RR |
333 | m_x = 0; |
334 | m_y = 0; | |
335 | m_width = 100; | |
336 | m_height = 0; | |
46dc76ba | 337 | |
1144d24d RR |
338 | wxNode *node = m_tools.First(); |
339 | while (node) | |
46dc76ba | 340 | { |
1144d24d RR |
341 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); |
342 | if (tool->m_bitmap1.Ok()) | |
343 | { | |
344 | int tool_height = tool->m_bitmap1.GetHeight(); | |
345 | if (tool_height > m_height) m_height = tool_height; | |
346 | } | |
46dc76ba | 347 | |
1144d24d RR |
348 | node = node->Next(); |
349 | } | |
46dc76ba | 350 | |
1144d24d RR |
351 | m_height += 5 + 2*m_yMargin; |
352 | ||
353 | return TRUE; | |
fc008f25 | 354 | } |
46dc76ba | 355 | |
716b7364 | 356 | void wxToolBar::EnableTool(int toolIndex, bool enable) |
c801d85f | 357 | { |
1144d24d RR |
358 | wxNode *node = m_tools.First(); |
359 | while (node) | |
360 | { | |
361 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
362 | if (tool->m_index == toolIndex) | |
2b1c162e | 363 | { |
1144d24d | 364 | tool->m_enabled = enable; |
f03fc89f | 365 | |
c693edf3 RR |
366 | #if (GTK_MINOR_VERSION > 0) |
367 | /* we don't disable the tools for GTK 1.0 as the bitmaps don't get | |
368 | greyed anyway and this also disables tooltips */ | |
f03fc89f VZ |
369 | if (tool->m_item) |
370 | gtk_widget_set_sensitive( tool->m_item, enable ); | |
c693edf3 | 371 | #endif |
f03fc89f | 372 | |
1144d24d RR |
373 | return; |
374 | } | |
375 | node = node->Next(); | |
cf4219e7 | 376 | } |
fc008f25 | 377 | |
05939a81 | 378 | wxFAIL_MSG( _T("wrong toolbar index") ); |
fc008f25 | 379 | } |
c801d85f | 380 | |
fc008f25 | 381 | void wxToolBar::ToggleTool( int toolIndex, bool toggle ) |
c801d85f | 382 | { |
1144d24d RR |
383 | wxNode *node = m_tools.First(); |
384 | while (node) | |
385 | { | |
386 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
387 | if (tool->m_index == toolIndex) | |
388 | { | |
1144d24d | 389 | if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item))) |
e179bd65 RR |
390 | { |
391 | tool->m_toggleState = toggle; | |
392 | ||
393 | if (tool->m_bitmap2.Ok()) | |
394 | { | |
395 | wxBitmap bitmap = tool->m_bitmap1; | |
396 | if (tool->m_toggleState) bitmap = tool->m_bitmap2; | |
397 | ||
398 | GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); | |
399 | ||
400 | GdkBitmap *mask = (GdkBitmap *) NULL; | |
401 | if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap(); | |
402 | ||
403 | gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); | |
404 | } | |
405 | ||
406 | gtk_signal_disconnect_by_func( GTK_OBJECT(tool->m_item), | |
407 | GTK_SIGNAL_FUNC(gtk_toolbar_callback), (gpointer*)tool ); | |
408 | ||
1144d24d | 409 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle ); |
e179bd65 RR |
410 | |
411 | gtk_signal_connect( GTK_OBJECT(tool->m_item), "clicked", | |
412 | GTK_SIGNAL_FUNC(gtk_toolbar_callback), (gpointer*)tool ); | |
413 | } | |
414 | ||
1144d24d RR |
415 | return; |
416 | } | |
417 | node = node->Next(); | |
fc008f25 | 418 | } |
fc008f25 | 419 | |
05939a81 | 420 | wxFAIL_MSG( _T("wrong toolbar index") ); |
fc008f25 | 421 | } |
c801d85f | 422 | |
fc008f25 | 423 | wxObject *wxToolBar::GetToolClientData( int index ) const |
c801d85f | 424 | { |
1144d24d RR |
425 | wxNode *node = m_tools.First(); |
426 | while (node) | |
427 | { | |
428 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
429 | if (tool->m_index == index) return tool->m_clientData;; | |
430 | node = node->Next(); | |
431 | } | |
fc008f25 | 432 | |
05939a81 | 433 | wxFAIL_MSG( _T("wrong toolbar index") ); |
fc008f25 | 434 | |
1144d24d | 435 | return (wxObject*)NULL; |
fc008f25 | 436 | } |
c801d85f | 437 | |
716b7364 | 438 | bool wxToolBar::GetToolState(int toolIndex) const |
c801d85f | 439 | { |
1144d24d RR |
440 | wxNode *node = m_tools.First(); |
441 | while (node) | |
442 | { | |
443 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
444 | if (tool->m_index == toolIndex) return tool->m_toggleState; | |
445 | node = node->Next(); | |
446 | } | |
fc008f25 | 447 | |
05939a81 | 448 | wxFAIL_MSG( _T("wrong toolbar index") ); |
fc008f25 | 449 | |
1144d24d | 450 | return FALSE; |
fc008f25 | 451 | } |
c801d85f | 452 | |
716b7364 | 453 | bool wxToolBar::GetToolEnabled(int toolIndex) const |
c801d85f | 454 | { |
1144d24d RR |
455 | wxNode *node = m_tools.First(); |
456 | while (node) | |
457 | { | |
458 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
459 | if (tool->m_index == toolIndex) return tool->m_enabled; | |
460 | node = node->Next(); | |
461 | } | |
fc008f25 | 462 | |
05939a81 | 463 | wxFAIL_MSG( _T("wrong toolbar index") ); |
fc008f25 | 464 | |
1144d24d | 465 | return FALSE; |
fc008f25 | 466 | } |
c801d85f | 467 | |
1144d24d | 468 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 469 | { |
05939a81 | 470 | wxCHECK_RET( !m_hasToolAlready, _T("wxToolBar::SetMargins must be called before adding tool.") ); |
1144d24d RR |
471 | |
472 | if (x > 2) gtk_toolbar_append_space( m_toolbar ); // oh well | |
473 | ||
474 | m_xMargin = x; | |
475 | m_yMargin = y; | |
fc008f25 | 476 | } |
c801d85f | 477 | |
cf4219e7 | 478 | void wxToolBar::SetToolPacking( int WXUNUSED(packing) ) |
c801d85f | 479 | { |
05939a81 | 480 | wxFAIL_MSG( _T("wxToolBar::SetToolPacking not implemented") ); |
fc008f25 | 481 | } |
c801d85f | 482 | |
cf4219e7 | 483 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 484 | { |
1144d24d RR |
485 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
486 | m_separation = separation; | |
487 | } | |
488 | ||
489 | int wxToolBar::GetToolPacking() | |
490 | { | |
491 | return 0; | |
492 | } | |
493 | ||
494 | int wxToolBar::GetToolSeparation() | |
495 | { | |
496 | return m_separation; | |
497 | } | |
498 | ||
499 | wxString wxToolBar::GetToolLongHelp(int toolIndex) | |
500 | { | |
501 | wxNode *node = m_tools.First(); | |
502 | while (node) | |
503 | { | |
504 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
505 | if (tool->m_index == toolIndex) | |
506 | { | |
507 | return tool->m_longHelpString; | |
508 | } | |
509 | node = node->Next(); | |
510 | } | |
511 | ||
05939a81 | 512 | wxFAIL_MSG( _T("wrong toolbar index") ); |
1144d24d | 513 | |
05939a81 | 514 | return _T(""); |
1144d24d RR |
515 | } |
516 | ||
517 | wxString wxToolBar::GetToolShortHelp(int toolIndex) | |
518 | { | |
519 | wxNode *node = m_tools.First(); | |
520 | while (node) | |
521 | { | |
522 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
523 | if (tool->m_index == toolIndex) | |
524 | { | |
525 | return tool->m_shortHelpString; | |
526 | } | |
527 | node = node->Next(); | |
528 | } | |
529 | ||
05939a81 | 530 | wxFAIL_MSG( _T("wrong toolbar index") ); |
1144d24d | 531 | |
05939a81 | 532 | return _T(""); |
fc008f25 | 533 | } |
c801d85f | 534 | |
1144d24d RR |
535 | void wxToolBar::SetToolLongHelp(int toolIndex, const wxString& helpString) |
536 | { | |
537 | wxNode *node = m_tools.First(); | |
538 | while (node) | |
539 | { | |
540 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
541 | if (tool->m_index == toolIndex) | |
542 | { | |
543 | tool->m_longHelpString = helpString; | |
f03fc89f | 544 | return; |
1144d24d RR |
545 | } |
546 | node = node->Next(); | |
547 | } | |
548 | ||
05939a81 | 549 | wxFAIL_MSG( _T("wrong toolbar index") ); |
1144d24d RR |
550 | |
551 | return; | |
552 | } | |
553 | ||
554 | void wxToolBar::SetToolShortHelp(int toolIndex, const wxString& helpString) | |
555 | { | |
556 | wxNode *node = m_tools.First(); | |
557 | while (node) | |
558 | { | |
559 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
560 | if (tool->m_index == toolIndex) | |
561 | { | |
562 | tool->m_shortHelpString = helpString; | |
f03fc89f | 563 | return; |
1144d24d RR |
564 | } |
565 | node = node->Next(); | |
566 | } | |
567 | ||
05939a81 | 568 | wxFAIL_MSG( _T("wrong toolbar index") ); |
1144d24d RR |
569 | |
570 | return; | |
571 | } | |
572 | ||
b1da76e1 RR |
573 | void wxToolBar::OnIdle( wxIdleEvent &WXUNUSED(ievent) ) |
574 | { | |
575 | wxEvtHandler* evtHandler = GetEventHandler(); | |
576 | ||
577 | wxNode* node = m_tools.First(); | |
578 | while (node) | |
579 | { | |
580 | wxToolBarTool* tool = (wxToolBarTool*) node->Data(); | |
581 | ||
582 | wxUpdateUIEvent event( tool->m_index ); | |
583 | event.SetEventObject(this); | |
584 | ||
585 | if (evtHandler->ProcessEvent( event )) | |
586 | { | |
587 | if (event.GetSetEnabled()) | |
588 | EnableTool(tool->m_index, event.GetEnabled()); | |
589 | if (event.GetSetChecked()) | |
590 | ToggleTool(tool->m_index, event.GetChecked()); | |
591 | /* | |
592 | if (event.GetSetText()) | |
593 | // Set tooltip? | |
594 | */ | |
595 | } | |
596 | ||
597 | node = node->Next(); | |
598 | } | |
599 | } | |
1144d24d | 600 | |
dcf924a3 | 601 | #endif |