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