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