]>
Commit | Line | Data |
---|---|---|
10b959e3 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8a0681f9 VZ |
2 | // Name: common/tbarbase.cpp |
3 | // Purpose: wxToolBarBase implementation | |
10b959e3 | 4 | // Author: Julian Smart |
8a0681f9 | 5 | // Modified by: VZ at 11.12.99 (wxScrollableToolBar splitted off) |
10b959e3 JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
1c383dba | 9 | // Licence: wxWindows license |
10b959e3 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8a0681f9 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
10b959e3 | 20 | #ifdef __GNUG__ |
8a0681f9 | 21 | #pragma implementation "tbarbase.h" |
10b959e3 JS |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8a0681f9 | 28 | #pragma hdrstop |
10b959e3 JS |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_TOOLBAR |
32 | ||
10b959e3 | 33 | #ifndef WX_PRECOMP |
f538710f | 34 | #include "wx/control.h" |
10b959e3 JS |
35 | #endif |
36 | ||
e702ff0f | 37 | #include "wx/frame.h" |
c229e50d JS |
38 | #include "wx/image.h" |
39 | #include "wx/settings.h" | |
e702ff0f | 40 | |
10b959e3 JS |
41 | #include "wx/tbarbase.h" |
42 | ||
8a0681f9 VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWindows macros | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
12ed316d JS |
47 | IMPLEMENT_CLASS(wxToolBarBase, wxControl) |
48 | ||
1e6feb95 VZ |
49 | BEGIN_EVENT_TABLE(wxToolBarBase, wxControl) |
50 | EVT_IDLE(wxToolBarBase::OnIdle) | |
51 | END_EVENT_TABLE() | |
52 | ||
8a0681f9 | 53 | #include "wx/listimpl.cpp" |
1c383dba | 54 | |
8a0681f9 | 55 | WX_DEFINE_LIST(wxToolBarToolsList); |
10b959e3 | 56 | |
8a0681f9 VZ |
57 | // ============================================================================ |
58 | // implementation | |
59 | // ============================================================================ | |
10b959e3 | 60 | |
8a0681f9 VZ |
61 | // ---------------------------------------------------------------------------- |
62 | // wxToolBarToolBase | |
63 | // ---------------------------------------------------------------------------- | |
10b959e3 | 64 | |
8a0681f9 | 65 | bool wxToolBarToolBase::Enable(bool enable) |
10b959e3 | 66 | { |
8a0681f9 VZ |
67 | if ( m_enabled == enable ) |
68 | return FALSE; | |
10b959e3 | 69 | |
8a0681f9 | 70 | m_enabled = enable; |
10b959e3 | 71 | |
8a0681f9 | 72 | return TRUE; |
10b959e3 JS |
73 | } |
74 | ||
8a0681f9 | 75 | bool wxToolBarToolBase::Toggle(bool toggle) |
10b959e3 | 76 | { |
e76c0b5f | 77 | wxASSERT_MSG( CanBeToggled(), _T("can't toggle this tool") ); |
8a0681f9 VZ |
78 | |
79 | if ( m_toggled == toggle ) | |
80 | return FALSE; | |
10b959e3 | 81 | |
8a0681f9 VZ |
82 | m_toggled = toggle; |
83 | ||
84 | return TRUE; | |
10b959e3 JS |
85 | } |
86 | ||
8a0681f9 | 87 | bool wxToolBarToolBase::SetToggle(bool toggle) |
10b959e3 | 88 | { |
e76c0b5f VZ |
89 | wxItemKind kind = toggle ? wxITEM_CHECK : wxITEM_NORMAL; |
90 | if ( m_kind == kind ) | |
8a0681f9 | 91 | return FALSE; |
10b959e3 | 92 | |
e76c0b5f | 93 | m_kind = kind; |
10b959e3 JS |
94 | |
95 | return TRUE; | |
96 | } | |
97 | ||
8a0681f9 | 98 | bool wxToolBarToolBase::SetShortHelp(const wxString& help) |
10b959e3 | 99 | { |
8a0681f9 VZ |
100 | if ( m_shortHelpString == help ) |
101 | return FALSE; | |
10b959e3 | 102 | |
8a0681f9 VZ |
103 | m_shortHelpString = help; |
104 | ||
105 | return TRUE; | |
10b959e3 JS |
106 | } |
107 | ||
8a0681f9 | 108 | bool wxToolBarToolBase::SetLongHelp(const wxString& help) |
10b959e3 | 109 | { |
8a0681f9 VZ |
110 | if ( m_longHelpString == help ) |
111 | return FALSE; | |
10b959e3 | 112 | |
8a0681f9 VZ |
113 | m_longHelpString = help; |
114 | ||
115 | return TRUE; | |
10b959e3 JS |
116 | } |
117 | ||
8a0681f9 | 118 | wxToolBarToolBase::~wxToolBarToolBase() |
10b959e3 | 119 | { |
8a0681f9 | 120 | } |
10b959e3 | 121 | |
8a0681f9 VZ |
122 | // ---------------------------------------------------------------------------- |
123 | // wxToolBarBase adding/deleting items | |
124 | // ---------------------------------------------------------------------------- | |
ac91b9d2 | 125 | |
8a0681f9 VZ |
126 | wxToolBarBase::wxToolBarBase() |
127 | { | |
128 | // the list owns the pointers | |
129 | m_tools.DeleteContents(TRUE); | |
10b959e3 | 130 | |
8a0681f9 | 131 | m_xMargin = m_yMargin = 0; |
10b959e3 | 132 | |
8a0681f9 | 133 | m_maxRows = m_maxCols = 0; |
10b959e3 JS |
134 | } |
135 | ||
e76c0b5f VZ |
136 | wxToolBarToolBase *wxToolBarBase::DoAddTool(int id, |
137 | const wxString& label, | |
138 | const wxBitmap& bitmap, | |
139 | const wxBitmap& bmpDisabled, | |
140 | wxItemKind kind, | |
141 | const wxString& shortHelp, | |
142 | const wxString& longHelp, | |
143 | wxObject *clientData, | |
144 | wxCoord WXUNUSED(xPos), | |
145 | wxCoord WXUNUSED(yPos)) | |
10b959e3 | 146 | { |
e76c0b5f VZ |
147 | return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled, |
148 | kind, shortHelp, longHelp, clientData); | |
10b959e3 JS |
149 | } |
150 | ||
8a0681f9 VZ |
151 | wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, |
152 | int id, | |
e76c0b5f | 153 | const wxString& label, |
8a0681f9 | 154 | const wxBitmap& bitmap, |
e76c0b5f VZ |
155 | const wxBitmap& bmpDisabled, |
156 | wxItemKind kind, | |
157 | const wxString& shortHelp, | |
158 | const wxString& longHelp, | |
159 | wxObject *clientData) | |
10b959e3 | 160 | { |
8a0681f9 VZ |
161 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
162 | _T("invalid position in wxToolBar::InsertTool()") ); | |
163 | ||
e76c0b5f VZ |
164 | wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind, |
165 | clientData, shortHelp, longHelp); | |
8a0681f9 VZ |
166 | |
167 | if ( !tool || !DoInsertTool(pos, tool) ) | |
168 | { | |
169 | delete tool; | |
170 | ||
171 | return NULL; | |
172 | } | |
173 | ||
174 | m_tools.Insert(pos, tool); | |
175 | ||
176 | return tool; | |
10b959e3 JS |
177 | } |
178 | ||
8a0681f9 | 179 | wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) |
10b959e3 | 180 | { |
8a0681f9 | 181 | return InsertControl(GetToolsCount(), control); |
10b959e3 JS |
182 | } |
183 | ||
8a0681f9 | 184 | wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) |
10b959e3 | 185 | { |
8a0681f9 VZ |
186 | wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, |
187 | _T("toolbar: can't insert NULL control") ); | |
188 | ||
189 | wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL, | |
190 | _T("control must have toolbar as parent") ); | |
191 | ||
192 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
193 | _T("invalid position in wxToolBar::InsertControl()") ); | |
194 | ||
195 | wxToolBarToolBase *tool = CreateTool(control); | |
196 | ||
197 | if ( !tool || !DoInsertTool(pos, tool) ) | |
198 | { | |
199 | delete tool; | |
200 | ||
201 | return NULL; | |
202 | } | |
203 | ||
204 | m_tools.Insert(pos, tool); | |
205 | ||
206 | return tool; | |
10b959e3 JS |
207 | } |
208 | ||
fba2d5e6 RR |
209 | wxControl *wxToolBarBase::FindControl( int id ) |
210 | { | |
211 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); | |
212 | node; | |
213 | node = node->GetNext() ) | |
214 | { | |
215 | wxControl *control = node->GetData()->GetControl(); | |
216 | ||
217 | if (control) | |
218 | { | |
219 | if (control->GetId() == id) | |
220 | return control; | |
221 | } | |
222 | } | |
223 | ||
224 | return NULL; | |
225 | } | |
226 | ||
8a0681f9 | 227 | wxToolBarToolBase *wxToolBarBase::AddSeparator() |
10b959e3 | 228 | { |
8a0681f9 | 229 | return InsertSeparator(GetToolsCount()); |
10b959e3 JS |
230 | } |
231 | ||
8a0681f9 | 232 | wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) |
10b959e3 | 233 | { |
8a0681f9 VZ |
234 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
235 | _T("invalid position in wxToolBar::InsertSeparator()") ); | |
236 | ||
237 | wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, | |
e76c0b5f | 238 | wxEmptyString, |
8a0681f9 | 239 | wxNullBitmap, wxNullBitmap, |
e76c0b5f | 240 | wxITEM_SEPARATOR, (wxObject *)NULL, |
8a0681f9 VZ |
241 | wxEmptyString, wxEmptyString); |
242 | ||
243 | if ( !tool || !DoInsertTool(pos, tool) ) | |
10b959e3 | 244 | { |
8a0681f9 VZ |
245 | delete tool; |
246 | ||
247 | return NULL; | |
10b959e3 | 248 | } |
8a0681f9 VZ |
249 | |
250 | m_tools.Insert(pos, tool); | |
251 | ||
252 | return tool; | |
10b959e3 JS |
253 | } |
254 | ||
8a0681f9 | 255 | wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) |
10b959e3 | 256 | { |
8a0681f9 VZ |
257 | size_t pos = 0; |
258 | wxToolBarToolsList::Node *node; | |
259 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
10b959e3 | 260 | { |
8a0681f9 VZ |
261 | if ( node->GetData()->GetId() == id ) |
262 | break; | |
263 | ||
264 | pos++; | |
10b959e3 | 265 | } |
10b959e3 | 266 | |
8a0681f9 | 267 | if ( !node ) |
10b959e3 | 268 | { |
8a0681f9 VZ |
269 | // don't give any error messages - sometimes we might call RemoveTool() |
270 | // without knowing whether the tool is or not in the toolbar | |
271 | return (wxToolBarToolBase *)NULL; | |
10b959e3 | 272 | } |
10b959e3 | 273 | |
8a0681f9 VZ |
274 | wxToolBarToolBase *tool = node->GetData(); |
275 | if ( !DoDeleteTool(pos, tool) ) | |
276 | { | |
277 | return (wxToolBarToolBase *)NULL; | |
278 | } | |
10b959e3 | 279 | |
8a0681f9 VZ |
280 | // the node would delete the data, so set it to NULL to avoid this |
281 | node->SetData(NULL); | |
10b959e3 | 282 | |
8a0681f9 | 283 | m_tools.DeleteNode(node); |
10b959e3 | 284 | |
8a0681f9 | 285 | return tool; |
10b959e3 JS |
286 | } |
287 | ||
8a0681f9 | 288 | bool wxToolBarBase::DeleteToolByPos(size_t pos) |
10b959e3 | 289 | { |
8a0681f9 VZ |
290 | wxCHECK_MSG( pos < GetToolsCount(), FALSE, |
291 | _T("invalid position in wxToolBar::DeleteToolByPos()") ); | |
10b959e3 | 292 | |
8a0681f9 | 293 | wxToolBarToolsList::Node *node = m_tools.Item(pos); |
10b959e3 | 294 | |
8a0681f9 VZ |
295 | if ( !DoDeleteTool(pos, node->GetData()) ) |
296 | { | |
297 | return FALSE; | |
298 | } | |
299 | ||
300 | m_tools.DeleteNode(node); | |
301 | ||
302 | return TRUE; | |
10b959e3 JS |
303 | } |
304 | ||
8a0681f9 | 305 | bool wxToolBarBase::DeleteTool(int id) |
10b959e3 | 306 | { |
8a0681f9 VZ |
307 | size_t pos = 0; |
308 | wxToolBarToolsList::Node *node; | |
309 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
310 | { | |
311 | if ( node->GetData()->GetId() == id ) | |
312 | break; | |
313 | ||
314 | pos++; | |
315 | } | |
316 | ||
317 | if ( !node || !DoDeleteTool(pos, node->GetData()) ) | |
318 | { | |
319 | return FALSE; | |
320 | } | |
321 | ||
322 | m_tools.DeleteNode(node); | |
323 | ||
324 | return TRUE; | |
10b959e3 JS |
325 | } |
326 | ||
8a0681f9 | 327 | wxToolBarToolBase *wxToolBarBase::FindById(int id) const |
10b959e3 | 328 | { |
8a0681f9 VZ |
329 | wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; |
330 | ||
331 | for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
332 | node; | |
333 | node = node->GetNext() ) | |
334 | { | |
335 | tool = node->GetData(); | |
336 | if ( tool->GetId() == id ) | |
337 | { | |
338 | // found | |
339 | break; | |
340 | } | |
d9739886 VZ |
341 | |
342 | tool = NULL; | |
8a0681f9 VZ |
343 | } |
344 | ||
345 | return tool; | |
10b959e3 JS |
346 | } |
347 | ||
8a0681f9 | 348 | void wxToolBarBase::ClearTools() |
10b959e3 | 349 | { |
8a0681f9 | 350 | m_tools.Clear(); |
10b959e3 JS |
351 | } |
352 | ||
8a0681f9 | 353 | bool wxToolBarBase::Realize() |
10b959e3 | 354 | { |
8a0681f9 | 355 | return TRUE; |
10b959e3 JS |
356 | } |
357 | ||
8a0681f9 | 358 | wxToolBarBase::~wxToolBarBase() |
10b959e3 | 359 | { |
10b959e3 JS |
360 | } |
361 | ||
8a0681f9 VZ |
362 | // ---------------------------------------------------------------------------- |
363 | // wxToolBarBase tools state | |
364 | // ---------------------------------------------------------------------------- | |
10b959e3 | 365 | |
8a0681f9 | 366 | void wxToolBarBase::EnableTool(int id, bool enable) |
10b959e3 | 367 | { |
8a0681f9 VZ |
368 | wxToolBarToolBase *tool = FindById(id); |
369 | if ( tool ) | |
10b959e3 | 370 | { |
8a0681f9 VZ |
371 | if ( tool->Enable(enable) ) |
372 | { | |
373 | DoEnableTool(tool, enable); | |
374 | } | |
10b959e3 | 375 | } |
8a0681f9 | 376 | } |
10b959e3 | 377 | |
8a0681f9 VZ |
378 | void wxToolBarBase::ToggleTool(int id, bool toggle) |
379 | { | |
380 | wxToolBarToolBase *tool = FindById(id); | |
381 | if ( tool && tool->CanBeToggled() ) | |
10b959e3 | 382 | { |
8a0681f9 VZ |
383 | if ( tool->Toggle(toggle) ) |
384 | { | |
385 | DoToggleTool(tool, toggle); | |
386 | } | |
10b959e3 | 387 | } |
10b959e3 JS |
388 | } |
389 | ||
8a0681f9 VZ |
390 | void wxToolBarBase::SetToggle(int id, bool toggle) |
391 | { | |
392 | wxToolBarToolBase *tool = FindById(id); | |
393 | if ( tool ) | |
10b959e3 | 394 | { |
8a0681f9 VZ |
395 | if ( tool->SetToggle(toggle) ) |
396 | { | |
397 | DoSetToggle(tool, toggle); | |
398 | } | |
10b959e3 | 399 | } |
8a0681f9 VZ |
400 | } |
401 | ||
402 | void wxToolBarBase::SetToolShortHelp(int id, const wxString& help) | |
403 | { | |
404 | wxToolBarToolBase *tool = FindById(id); | |
405 | if ( tool ) | |
10b959e3 | 406 | { |
8a0681f9 | 407 | (void)tool->SetShortHelp(help); |
10b959e3 | 408 | } |
8a0681f9 VZ |
409 | } |
410 | ||
411 | void wxToolBarBase::SetToolLongHelp(int id, const wxString& help) | |
412 | { | |
413 | wxToolBarToolBase *tool = FindById(id); | |
414 | if ( tool ) | |
10b959e3 | 415 | { |
8a0681f9 | 416 | (void)tool->SetLongHelp(help); |
10b959e3 | 417 | } |
10b959e3 JS |
418 | } |
419 | ||
8a0681f9 | 420 | wxObject *wxToolBarBase::GetToolClientData(int id) const |
10b959e3 | 421 | { |
8a0681f9 VZ |
422 | wxToolBarToolBase *tool = FindById(id); |
423 | ||
424 | return tool ? tool->GetClientData() : (wxObject *)NULL; | |
10b959e3 JS |
425 | } |
426 | ||
6fd5fa4f VZ |
427 | void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) |
428 | { | |
429 | wxToolBarToolBase *tool = FindById(id); | |
430 | ||
431 | wxCHECK_RET( tool, _T("no such tool in wxToolBar::SetToolClientData") ); | |
432 | ||
433 | tool->SetClientData(clientData); | |
434 | } | |
435 | ||
8a0681f9 | 436 | bool wxToolBarBase::GetToolState(int id) const |
10b959e3 | 437 | { |
8a0681f9 VZ |
438 | wxToolBarToolBase *tool = FindById(id); |
439 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
440 | ||
441 | return tool->IsToggled(); | |
10b959e3 JS |
442 | } |
443 | ||
8a0681f9 | 444 | bool wxToolBarBase::GetToolEnabled(int id) const |
10b959e3 | 445 | { |
8a0681f9 VZ |
446 | wxToolBarToolBase *tool = FindById(id); |
447 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
448 | ||
449 | return tool->IsEnabled(); | |
10b959e3 JS |
450 | } |
451 | ||
8a0681f9 | 452 | wxString wxToolBarBase::GetToolShortHelp(int id) const |
10b959e3 | 453 | { |
8a0681f9 VZ |
454 | wxToolBarToolBase *tool = FindById(id); |
455 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
456 | ||
457 | return tool->GetShortHelp(); | |
10b959e3 JS |
458 | } |
459 | ||
8a0681f9 | 460 | wxString wxToolBarBase::GetToolLongHelp(int id) const |
10b959e3 | 461 | { |
8a0681f9 VZ |
462 | wxToolBarToolBase *tool = FindById(id); |
463 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
10b959e3 | 464 | |
8a0681f9 | 465 | return tool->GetLongHelp(); |
10b959e3 JS |
466 | } |
467 | ||
8a0681f9 VZ |
468 | // ---------------------------------------------------------------------------- |
469 | // wxToolBarBase geometry | |
470 | // ---------------------------------------------------------------------------- | |
471 | ||
472 | void wxToolBarBase::SetMargins(int x, int y) | |
10b959e3 | 473 | { |
8a0681f9 VZ |
474 | m_xMargin = x; |
475 | m_yMargin = y; | |
10b959e3 JS |
476 | } |
477 | ||
8a0681f9 | 478 | void wxToolBarBase::SetRows(int WXUNUSED(nRows)) |
10b959e3 | 479 | { |
8a0681f9 | 480 | // nothing |
10b959e3 JS |
481 | } |
482 | ||
8a0681f9 VZ |
483 | // ---------------------------------------------------------------------------- |
484 | // event processing | |
485 | // ---------------------------------------------------------------------------- | |
486 | ||
487 | // Only allow toggle if returns TRUE | |
488 | bool wxToolBarBase::OnLeftClick(int id, bool toggleDown) | |
10b959e3 | 489 | { |
8a0681f9 VZ |
490 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id); |
491 | event.SetEventObject(this); | |
6bec54e1 VZ |
492 | |
493 | // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown | |
494 | event.SetInt((int)toggleDown); | |
495 | ||
496 | // and SetExtraLong() for backwards compatibility | |
497 | event.SetExtraLong((long)toggleDown); | |
8a0681f9 VZ |
498 | |
499 | // Send events to this toolbar instead (and thence up the window hierarchy) | |
500 | GetEventHandler()->ProcessEvent(event); | |
501 | ||
502 | return TRUE; | |
10b959e3 JS |
503 | } |
504 | ||
8a0681f9 VZ |
505 | // Call when right button down. |
506 | void wxToolBarBase::OnRightClick(int id, | |
507 | long WXUNUSED(x), | |
508 | long WXUNUSED(y)) | |
10b959e3 | 509 | { |
8a0681f9 VZ |
510 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id); |
511 | event.SetEventObject(this); | |
512 | event.SetInt(id); | |
513 | ||
514 | GetEventHandler()->ProcessEvent(event); | |
515 | } | |
43d811ea | 516 | |
8a0681f9 VZ |
517 | // Called when the mouse cursor enters a tool bitmap (no button pressed). |
518 | // Argument is -1 if mouse is exiting the toolbar. | |
519 | // Note that for this event, the id of the window is used, | |
520 | // and the integer parameter of wxCommandEvent is used to retrieve | |
521 | // the tool id. | |
522 | void wxToolBarBase::OnMouseEnter(int id) | |
523 | { | |
524 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); | |
525 | event.SetEventObject(this); | |
526 | event.SetInt(id); | |
527 | ||
8a0681f9 | 528 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
1f361cdd | 529 | if( frame ) |
66ce9e06 | 530 | { |
1f361cdd MB |
531 | wxToolBarToolBase* tool = id == -1 ? (wxToolBarToolBase*)0 : FindById(id); |
532 | wxString help = tool ? tool->GetLongHelp() : wxString(); | |
533 | frame->DoGiveHelp( help, id != -1 ); | |
66ce9e06 VZ |
534 | } |
535 | ||
1f361cdd | 536 | (void)GetEventHandler()->ProcessEvent(event); |
8a0681f9 VZ |
537 | } |
538 | ||
539 | // ---------------------------------------------------------------------------- | |
540 | // UI updates | |
541 | // ---------------------------------------------------------------------------- | |
542 | ||
543 | void wxToolBarBase::OnIdle(wxIdleEvent& event) | |
544 | { | |
ac91b9d2 | 545 | DoToolbarUpdates(); |
8a0681f9 VZ |
546 | |
547 | event.Skip(); | |
10b959e3 JS |
548 | } |
549 | ||
550 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
ac91b9d2 VZ |
551 | void wxToolBarBase::DoToolbarUpdates() |
552 | { | |
e63fdcd6 JS |
553 | wxWindow* parent = this; |
554 | while (parent->GetParent()) | |
555 | parent = parent->GetParent(); | |
556 | ||
d3734d65 RR |
557 | // This kind of #ifdef is a good way to annoy people. It breaks |
558 | // apps, but only on one platform and due to a hack in officially | |
559 | // platform independent code. It took me hours to fix this. RR. | |
560 | // | |
561 | // #ifdef __WXMSW__ | |
562 | // wxWindow* focusWin = wxFindFocusDescendant(parent); | |
563 | // #else | |
f0e9f0d3 | 564 | wxWindow* focusWin = (wxWindow*) NULL; |
d3734d65 | 565 | // #endif |
e63fdcd6 JS |
566 | |
567 | wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ; | |
e702ff0f | 568 | |
8a0681f9 VZ |
569 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); |
570 | node; | |
571 | node = node->GetNext() ) | |
ac91b9d2 | 572 | { |
8a0681f9 | 573 | int id = node->GetData()->GetId(); |
ac91b9d2 | 574 | |
8a0681f9 | 575 | wxUpdateUIEvent event(id); |
ac91b9d2 VZ |
576 | event.SetEventObject(this); |
577 | ||
8a0681f9 | 578 | if ( evtHandler->ProcessEvent(event) ) |
ac91b9d2 | 579 | { |
8a0681f9 VZ |
580 | if ( event.GetSetEnabled() ) |
581 | EnableTool(id, event.GetEnabled()); | |
582 | if ( event.GetSetChecked() ) | |
583 | ToggleTool(id, event.GetChecked()); | |
584 | #if 0 | |
585 | if ( event.GetSetText() ) | |
ac91b9d2 | 586 | // Set tooltip? |
8a0681f9 | 587 | #endif // 0 |
ac91b9d2 | 588 | } |
ac91b9d2 | 589 | } |
10b959e3 JS |
590 | } |
591 | ||
c229e50d JS |
592 | // Helper function, used by wxCreateGreyedImage |
593 | ||
cee14ca0 VZ |
594 | static void wxGreyOutImage( const wxImage& src, |
595 | wxImage& dest, | |
596 | const wxColour& darkCol, | |
597 | const wxColour& lightCol, | |
598 | const wxColour& bgCol ) | |
c229e50d | 599 | { |
25a14595 JS |
600 | // Second attempt, just making things monochrome |
601 | int width = src.GetWidth(); | |
602 | int height = src.GetHeight(); | |
603 | ||
cee14ca0 VZ |
604 | int redCur, greenCur, blueCur; |
605 | for ( int x = 0; x < width; x++ ) | |
25a14595 | 606 | { |
cee14ca0 VZ |
607 | for ( int y = 1; y < height; y++ ) |
608 | { | |
25a14595 JS |
609 | redCur = src.GetRed(x, y); |
610 | greenCur = src.GetGreen(x, y); | |
cee14ca0 | 611 | blueCur = src.GetBlue(x, y); |
25a14595 | 612 | |
cee14ca0 | 613 | // Change light things to the background colour |
25a14595 JS |
614 | if ( redCur >= (lightCol.Red() - 50) && greenCur >= (lightCol.Green() - 50) && blueCur >= (lightCol.Blue() - 50) ) |
615 | { | |
616 | dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); | |
617 | } | |
618 | else if ( redCur == bgCol.Red() && greenCur == bgCol.Green() && blueCur == bgCol.Blue() ) | |
619 | { | |
cee14ca0 | 620 | // Leave the background colour as-is |
25a14595 JS |
621 | // dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); |
622 | } | |
623 | else // if ( redCur <= darkCol.Red() && greenCur <= darkCol.Green() && blueCur <= darkCol.Blue() ) | |
624 | { | |
cee14ca0 | 625 | // Change dark things to really dark |
c229e50d JS |
626 | dest.SetRGB(x,y, darkCol.Red(), darkCol.Green(), darkCol.Blue()); |
627 | } | |
c229e50d | 628 | } |
cee14ca0 | 629 | } |
c229e50d JS |
630 | } |
631 | ||
632 | /* | |
633 | * Make a greyed-out image suitable for disabled buttons. | |
634 | * This code is adapted from wxNewBitmapButton in FL. | |
635 | */ | |
636 | ||
637 | bool wxCreateGreyedImage(const wxImage& in, wxImage& out) | |
638 | { | |
639 | out = in.Copy(); | |
640 | ||
641 | // assuming the pixels along the edges are of the background color | |
642 | wxColour bgCol(in.GetRed(0, 0), in.GetGreen(0, 0), in.GetBlue(0, 0)); | |
643 | ||
644 | wxColour darkCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ; | |
645 | wxColour lightCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT) ; | |
646 | ||
647 | wxGreyOutImage(in, out, darkCol, lightCol, bgCol); | |
648 | ||
649 | return TRUE; | |
650 | } | |
651 | ||
8a0681f9 | 652 | #endif // wxUSE_TOOLBAR |