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