]>
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$ | |
55d99c7a JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
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 | 166 | |
dd91da4e | 167 | if ( !InsertTool(pos, tool) ) |
8a0681f9 VZ |
168 | { |
169 | delete tool; | |
170 | ||
171 | return NULL; | |
172 | } | |
173 | ||
dd91da4e VZ |
174 | return tool; |
175 | } | |
176 | ||
177 | wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool) | |
178 | { | |
179 | return InsertTool(GetToolsCount(), tool); | |
180 | } | |
181 | ||
182 | wxToolBarToolBase * | |
183 | wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) | |
184 | { | |
185 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
186 | _T("invalid position in wxToolBar::InsertTool()") ); | |
187 | ||
188 | if ( !tool || !DoInsertTool(pos, tool) ) | |
189 | { | |
190 | return NULL; | |
191 | } | |
192 | ||
8a0681f9 VZ |
193 | m_tools.Insert(pos, tool); |
194 | ||
195 | return tool; | |
10b959e3 JS |
196 | } |
197 | ||
8a0681f9 | 198 | wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) |
10b959e3 | 199 | { |
8a0681f9 | 200 | return InsertControl(GetToolsCount(), control); |
10b959e3 JS |
201 | } |
202 | ||
8a0681f9 | 203 | wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) |
10b959e3 | 204 | { |
8a0681f9 VZ |
205 | wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, |
206 | _T("toolbar: can't insert NULL control") ); | |
207 | ||
208 | wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL, | |
209 | _T("control must have toolbar as parent") ); | |
210 | ||
211 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
212 | _T("invalid position in wxToolBar::InsertControl()") ); | |
213 | ||
214 | wxToolBarToolBase *tool = CreateTool(control); | |
215 | ||
dd91da4e | 216 | if ( !InsertTool(pos, tool) ) |
8a0681f9 VZ |
217 | { |
218 | delete tool; | |
219 | ||
220 | return NULL; | |
221 | } | |
222 | ||
8a0681f9 | 223 | return tool; |
10b959e3 JS |
224 | } |
225 | ||
fba2d5e6 RR |
226 | wxControl *wxToolBarBase::FindControl( int id ) |
227 | { | |
228 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); | |
229 | node; | |
230 | node = node->GetNext() ) | |
231 | { | |
652ab153 VZ |
232 | const wxToolBarToolBase * const tool = node->GetData(); |
233 | if ( tool->IsControl() ) | |
fba2d5e6 | 234 | { |
652ab153 VZ |
235 | wxControl * const control = tool->GetControl(); |
236 | ||
237 | if ( !control ) | |
238 | { | |
239 | wxFAIL_MSG( _T("NULL control in toolbar?") ); | |
240 | } | |
241 | else if ( control->GetId() == id ) | |
242 | { | |
243 | // found | |
fba2d5e6 | 244 | return control; |
652ab153 | 245 | } |
fba2d5e6 RR |
246 | } |
247 | } | |
248 | ||
249 | return NULL; | |
250 | } | |
251 | ||
8a0681f9 | 252 | wxToolBarToolBase *wxToolBarBase::AddSeparator() |
10b959e3 | 253 | { |
8a0681f9 | 254 | return InsertSeparator(GetToolsCount()); |
10b959e3 JS |
255 | } |
256 | ||
8a0681f9 | 257 | wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) |
10b959e3 | 258 | { |
8a0681f9 VZ |
259 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
260 | _T("invalid position in wxToolBar::InsertSeparator()") ); | |
261 | ||
262 | wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, | |
e76c0b5f | 263 | wxEmptyString, |
8a0681f9 | 264 | wxNullBitmap, wxNullBitmap, |
e76c0b5f | 265 | wxITEM_SEPARATOR, (wxObject *)NULL, |
8a0681f9 VZ |
266 | wxEmptyString, wxEmptyString); |
267 | ||
268 | if ( !tool || !DoInsertTool(pos, tool) ) | |
10b959e3 | 269 | { |
8a0681f9 VZ |
270 | delete tool; |
271 | ||
272 | return NULL; | |
10b959e3 | 273 | } |
8a0681f9 VZ |
274 | |
275 | m_tools.Insert(pos, tool); | |
276 | ||
277 | return tool; | |
10b959e3 JS |
278 | } |
279 | ||
8a0681f9 | 280 | wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) |
10b959e3 | 281 | { |
8a0681f9 VZ |
282 | size_t pos = 0; |
283 | wxToolBarToolsList::Node *node; | |
284 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
10b959e3 | 285 | { |
8a0681f9 VZ |
286 | if ( node->GetData()->GetId() == id ) |
287 | break; | |
288 | ||
289 | pos++; | |
10b959e3 | 290 | } |
10b959e3 | 291 | |
8a0681f9 | 292 | if ( !node ) |
10b959e3 | 293 | { |
8a0681f9 VZ |
294 | // don't give any error messages - sometimes we might call RemoveTool() |
295 | // without knowing whether the tool is or not in the toolbar | |
296 | return (wxToolBarToolBase *)NULL; | |
10b959e3 | 297 | } |
10b959e3 | 298 | |
8a0681f9 VZ |
299 | wxToolBarToolBase *tool = node->GetData(); |
300 | if ( !DoDeleteTool(pos, tool) ) | |
301 | { | |
302 | return (wxToolBarToolBase *)NULL; | |
303 | } | |
10b959e3 | 304 | |
8a0681f9 VZ |
305 | // the node would delete the data, so set it to NULL to avoid this |
306 | node->SetData(NULL); | |
10b959e3 | 307 | |
8a0681f9 | 308 | m_tools.DeleteNode(node); |
10b959e3 | 309 | |
8a0681f9 | 310 | return tool; |
10b959e3 JS |
311 | } |
312 | ||
8a0681f9 | 313 | bool wxToolBarBase::DeleteToolByPos(size_t pos) |
10b959e3 | 314 | { |
8a0681f9 VZ |
315 | wxCHECK_MSG( pos < GetToolsCount(), FALSE, |
316 | _T("invalid position in wxToolBar::DeleteToolByPos()") ); | |
10b959e3 | 317 | |
8a0681f9 | 318 | wxToolBarToolsList::Node *node = m_tools.Item(pos); |
10b959e3 | 319 | |
8a0681f9 VZ |
320 | if ( !DoDeleteTool(pos, node->GetData()) ) |
321 | { | |
322 | return FALSE; | |
323 | } | |
324 | ||
325 | m_tools.DeleteNode(node); | |
326 | ||
327 | return TRUE; | |
10b959e3 JS |
328 | } |
329 | ||
8a0681f9 | 330 | bool wxToolBarBase::DeleteTool(int id) |
10b959e3 | 331 | { |
8a0681f9 VZ |
332 | size_t pos = 0; |
333 | wxToolBarToolsList::Node *node; | |
334 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
335 | { | |
336 | if ( node->GetData()->GetId() == id ) | |
337 | break; | |
338 | ||
339 | pos++; | |
340 | } | |
341 | ||
342 | if ( !node || !DoDeleteTool(pos, node->GetData()) ) | |
343 | { | |
344 | return FALSE; | |
345 | } | |
346 | ||
347 | m_tools.DeleteNode(node); | |
348 | ||
349 | return TRUE; | |
10b959e3 JS |
350 | } |
351 | ||
8a0681f9 | 352 | wxToolBarToolBase *wxToolBarBase::FindById(int id) const |
10b959e3 | 353 | { |
8a0681f9 VZ |
354 | wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; |
355 | ||
356 | for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
357 | node; | |
358 | node = node->GetNext() ) | |
359 | { | |
360 | tool = node->GetData(); | |
361 | if ( tool->GetId() == id ) | |
362 | { | |
363 | // found | |
364 | break; | |
365 | } | |
d9739886 VZ |
366 | |
367 | tool = NULL; | |
8a0681f9 VZ |
368 | } |
369 | ||
370 | return tool; | |
10b959e3 JS |
371 | } |
372 | ||
8a0681f9 | 373 | void wxToolBarBase::ClearTools() |
10b959e3 | 374 | { |
8a0681f9 | 375 | m_tools.Clear(); |
10b959e3 JS |
376 | } |
377 | ||
8a0681f9 | 378 | bool wxToolBarBase::Realize() |
10b959e3 | 379 | { |
8a0681f9 | 380 | return TRUE; |
10b959e3 JS |
381 | } |
382 | ||
8a0681f9 | 383 | wxToolBarBase::~wxToolBarBase() |
10b959e3 | 384 | { |
10b959e3 JS |
385 | } |
386 | ||
8a0681f9 VZ |
387 | // ---------------------------------------------------------------------------- |
388 | // wxToolBarBase tools state | |
389 | // ---------------------------------------------------------------------------- | |
10b959e3 | 390 | |
8a0681f9 | 391 | void wxToolBarBase::EnableTool(int id, bool enable) |
10b959e3 | 392 | { |
8a0681f9 VZ |
393 | wxToolBarToolBase *tool = FindById(id); |
394 | if ( tool ) | |
10b959e3 | 395 | { |
8a0681f9 VZ |
396 | if ( tool->Enable(enable) ) |
397 | { | |
398 | DoEnableTool(tool, enable); | |
399 | } | |
10b959e3 | 400 | } |
8a0681f9 | 401 | } |
10b959e3 | 402 | |
8a0681f9 VZ |
403 | void wxToolBarBase::ToggleTool(int id, bool toggle) |
404 | { | |
405 | wxToolBarToolBase *tool = FindById(id); | |
406 | if ( tool && tool->CanBeToggled() ) | |
10b959e3 | 407 | { |
8a0681f9 VZ |
408 | if ( tool->Toggle(toggle) ) |
409 | { | |
410 | DoToggleTool(tool, toggle); | |
411 | } | |
10b959e3 | 412 | } |
10b959e3 JS |
413 | } |
414 | ||
8a0681f9 VZ |
415 | void wxToolBarBase::SetToggle(int id, bool toggle) |
416 | { | |
417 | wxToolBarToolBase *tool = FindById(id); | |
418 | if ( tool ) | |
10b959e3 | 419 | { |
8a0681f9 VZ |
420 | if ( tool->SetToggle(toggle) ) |
421 | { | |
422 | DoSetToggle(tool, toggle); | |
423 | } | |
10b959e3 | 424 | } |
8a0681f9 VZ |
425 | } |
426 | ||
427 | void wxToolBarBase::SetToolShortHelp(int id, const wxString& help) | |
428 | { | |
429 | wxToolBarToolBase *tool = FindById(id); | |
430 | if ( tool ) | |
10b959e3 | 431 | { |
8a0681f9 | 432 | (void)tool->SetShortHelp(help); |
10b959e3 | 433 | } |
8a0681f9 VZ |
434 | } |
435 | ||
436 | void wxToolBarBase::SetToolLongHelp(int id, const wxString& help) | |
437 | { | |
438 | wxToolBarToolBase *tool = FindById(id); | |
439 | if ( tool ) | |
10b959e3 | 440 | { |
8a0681f9 | 441 | (void)tool->SetLongHelp(help); |
10b959e3 | 442 | } |
10b959e3 JS |
443 | } |
444 | ||
8a0681f9 | 445 | wxObject *wxToolBarBase::GetToolClientData(int id) const |
10b959e3 | 446 | { |
8a0681f9 VZ |
447 | wxToolBarToolBase *tool = FindById(id); |
448 | ||
449 | return tool ? tool->GetClientData() : (wxObject *)NULL; | |
10b959e3 JS |
450 | } |
451 | ||
6fd5fa4f VZ |
452 | void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) |
453 | { | |
454 | wxToolBarToolBase *tool = FindById(id); | |
455 | ||
456 | wxCHECK_RET( tool, _T("no such tool in wxToolBar::SetToolClientData") ); | |
457 | ||
458 | tool->SetClientData(clientData); | |
459 | } | |
460 | ||
8a0681f9 | 461 | bool wxToolBarBase::GetToolState(int id) const |
10b959e3 | 462 | { |
8a0681f9 VZ |
463 | wxToolBarToolBase *tool = FindById(id); |
464 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
465 | ||
466 | return tool->IsToggled(); | |
10b959e3 JS |
467 | } |
468 | ||
8a0681f9 | 469 | bool wxToolBarBase::GetToolEnabled(int id) const |
10b959e3 | 470 | { |
8a0681f9 VZ |
471 | wxToolBarToolBase *tool = FindById(id); |
472 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
473 | ||
474 | return tool->IsEnabled(); | |
10b959e3 JS |
475 | } |
476 | ||
8a0681f9 | 477 | wxString wxToolBarBase::GetToolShortHelp(int id) const |
10b959e3 | 478 | { |
8a0681f9 VZ |
479 | wxToolBarToolBase *tool = FindById(id); |
480 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
481 | ||
482 | return tool->GetShortHelp(); | |
10b959e3 JS |
483 | } |
484 | ||
8a0681f9 | 485 | wxString wxToolBarBase::GetToolLongHelp(int id) const |
10b959e3 | 486 | { |
8a0681f9 VZ |
487 | wxToolBarToolBase *tool = FindById(id); |
488 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
10b959e3 | 489 | |
8a0681f9 | 490 | return tool->GetLongHelp(); |
10b959e3 JS |
491 | } |
492 | ||
8a0681f9 VZ |
493 | // ---------------------------------------------------------------------------- |
494 | // wxToolBarBase geometry | |
495 | // ---------------------------------------------------------------------------- | |
496 | ||
497 | void wxToolBarBase::SetMargins(int x, int y) | |
10b959e3 | 498 | { |
8a0681f9 VZ |
499 | m_xMargin = x; |
500 | m_yMargin = y; | |
10b959e3 JS |
501 | } |
502 | ||
8a0681f9 | 503 | void wxToolBarBase::SetRows(int WXUNUSED(nRows)) |
10b959e3 | 504 | { |
8a0681f9 | 505 | // nothing |
10b959e3 JS |
506 | } |
507 | ||
8a0681f9 VZ |
508 | // ---------------------------------------------------------------------------- |
509 | // event processing | |
510 | // ---------------------------------------------------------------------------- | |
511 | ||
512 | // Only allow toggle if returns TRUE | |
513 | bool wxToolBarBase::OnLeftClick(int id, bool toggleDown) | |
10b959e3 | 514 | { |
8a0681f9 VZ |
515 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id); |
516 | event.SetEventObject(this); | |
6bec54e1 VZ |
517 | |
518 | // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown | |
519 | event.SetInt((int)toggleDown); | |
520 | ||
521 | // and SetExtraLong() for backwards compatibility | |
522 | event.SetExtraLong((long)toggleDown); | |
8a0681f9 VZ |
523 | |
524 | // Send events to this toolbar instead (and thence up the window hierarchy) | |
525 | GetEventHandler()->ProcessEvent(event); | |
526 | ||
527 | return TRUE; | |
10b959e3 JS |
528 | } |
529 | ||
8a0681f9 VZ |
530 | // Call when right button down. |
531 | void wxToolBarBase::OnRightClick(int id, | |
532 | long WXUNUSED(x), | |
533 | long WXUNUSED(y)) | |
10b959e3 | 534 | { |
8a0681f9 VZ |
535 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id); |
536 | event.SetEventObject(this); | |
537 | event.SetInt(id); | |
538 | ||
539 | GetEventHandler()->ProcessEvent(event); | |
540 | } | |
43d811ea | 541 | |
8a0681f9 VZ |
542 | // Called when the mouse cursor enters a tool bitmap (no button pressed). |
543 | // Argument is -1 if mouse is exiting the toolbar. | |
544 | // Note that for this event, the id of the window is used, | |
545 | // and the integer parameter of wxCommandEvent is used to retrieve | |
546 | // the tool id. | |
547 | void wxToolBarBase::OnMouseEnter(int id) | |
548 | { | |
549 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); | |
550 | event.SetEventObject(this); | |
551 | event.SetInt(id); | |
552 | ||
8a0681f9 | 553 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
1f361cdd | 554 | if( frame ) |
66ce9e06 | 555 | { |
1f361cdd MB |
556 | wxToolBarToolBase* tool = id == -1 ? (wxToolBarToolBase*)0 : FindById(id); |
557 | wxString help = tool ? tool->GetLongHelp() : wxString(); | |
558 | frame->DoGiveHelp( help, id != -1 ); | |
66ce9e06 VZ |
559 | } |
560 | ||
1f361cdd | 561 | (void)GetEventHandler()->ProcessEvent(event); |
8a0681f9 VZ |
562 | } |
563 | ||
564 | // ---------------------------------------------------------------------------- | |
565 | // UI updates | |
566 | // ---------------------------------------------------------------------------- | |
567 | ||
568 | void wxToolBarBase::OnIdle(wxIdleEvent& event) | |
569 | { | |
ac91b9d2 | 570 | DoToolbarUpdates(); |
8a0681f9 VZ |
571 | |
572 | event.Skip(); | |
10b959e3 JS |
573 | } |
574 | ||
575 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
ac91b9d2 VZ |
576 | void wxToolBarBase::DoToolbarUpdates() |
577 | { | |
e63fdcd6 JS |
578 | wxWindow* parent = this; |
579 | while (parent->GetParent()) | |
580 | parent = parent->GetParent(); | |
581 | ||
d3734d65 RR |
582 | // This kind of #ifdef is a good way to annoy people. It breaks |
583 | // apps, but only on one platform and due to a hack in officially | |
584 | // platform independent code. It took me hours to fix this. RR. | |
585 | // | |
586 | // #ifdef __WXMSW__ | |
587 | // wxWindow* focusWin = wxFindFocusDescendant(parent); | |
588 | // #else | |
f0e9f0d3 | 589 | wxWindow* focusWin = (wxWindow*) NULL; |
d3734d65 | 590 | // #endif |
e63fdcd6 JS |
591 | |
592 | wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ; | |
e702ff0f | 593 | |
8a0681f9 VZ |
594 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); |
595 | node; | |
596 | node = node->GetNext() ) | |
ac91b9d2 | 597 | { |
8a0681f9 | 598 | int id = node->GetData()->GetId(); |
ac91b9d2 | 599 | |
8a0681f9 | 600 | wxUpdateUIEvent event(id); |
ac91b9d2 VZ |
601 | event.SetEventObject(this); |
602 | ||
8a0681f9 | 603 | if ( evtHandler->ProcessEvent(event) ) |
ac91b9d2 | 604 | { |
8a0681f9 VZ |
605 | if ( event.GetSetEnabled() ) |
606 | EnableTool(id, event.GetEnabled()); | |
607 | if ( event.GetSetChecked() ) | |
608 | ToggleTool(id, event.GetChecked()); | |
609 | #if 0 | |
610 | if ( event.GetSetText() ) | |
ac91b9d2 | 611 | // Set tooltip? |
8a0681f9 | 612 | #endif // 0 |
ac91b9d2 | 613 | } |
ac91b9d2 | 614 | } |
10b959e3 JS |
615 | } |
616 | ||
c229e50d JS |
617 | // Helper function, used by wxCreateGreyedImage |
618 | ||
cee14ca0 VZ |
619 | static void wxGreyOutImage( const wxImage& src, |
620 | wxImage& dest, | |
621 | const wxColour& darkCol, | |
622 | const wxColour& lightCol, | |
623 | const wxColour& bgCol ) | |
c229e50d | 624 | { |
25a14595 JS |
625 | // Second attempt, just making things monochrome |
626 | int width = src.GetWidth(); | |
627 | int height = src.GetHeight(); | |
628 | ||
cee14ca0 VZ |
629 | int redCur, greenCur, blueCur; |
630 | for ( int x = 0; x < width; x++ ) | |
25a14595 | 631 | { |
cee14ca0 VZ |
632 | for ( int y = 1; y < height; y++ ) |
633 | { | |
25a14595 JS |
634 | redCur = src.GetRed(x, y); |
635 | greenCur = src.GetGreen(x, y); | |
cee14ca0 | 636 | blueCur = src.GetBlue(x, y); |
25a14595 | 637 | |
cee14ca0 | 638 | // Change light things to the background colour |
25a14595 JS |
639 | if ( redCur >= (lightCol.Red() - 50) && greenCur >= (lightCol.Green() - 50) && blueCur >= (lightCol.Blue() - 50) ) |
640 | { | |
641 | dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); | |
642 | } | |
643 | else if ( redCur == bgCol.Red() && greenCur == bgCol.Green() && blueCur == bgCol.Blue() ) | |
644 | { | |
cee14ca0 | 645 | // Leave the background colour as-is |
25a14595 JS |
646 | // dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); |
647 | } | |
648 | else // if ( redCur <= darkCol.Red() && greenCur <= darkCol.Green() && blueCur <= darkCol.Blue() ) | |
649 | { | |
cee14ca0 | 650 | // Change dark things to really dark |
c229e50d JS |
651 | dest.SetRGB(x,y, darkCol.Red(), darkCol.Green(), darkCol.Blue()); |
652 | } | |
c229e50d | 653 | } |
cee14ca0 | 654 | } |
c229e50d JS |
655 | } |
656 | ||
657 | /* | |
658 | * Make a greyed-out image suitable for disabled buttons. | |
659 | * This code is adapted from wxNewBitmapButton in FL. | |
660 | */ | |
661 | ||
662 | bool wxCreateGreyedImage(const wxImage& in, wxImage& out) | |
663 | { | |
664 | out = in.Copy(); | |
665 | ||
666 | // assuming the pixels along the edges are of the background color | |
667 | wxColour bgCol(in.GetRed(0, 0), in.GetGreen(0, 0), in.GetBlue(0, 0)); | |
668 | ||
669 | wxColour darkCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ; | |
670 | wxColour lightCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT) ; | |
671 | ||
672 | wxGreyOutImage(in, out, darkCol, lightCol, bgCol); | |
673 | ||
674 | return TRUE; | |
675 | } | |
676 | ||
8a0681f9 | 677 | #endif // wxUSE_TOOLBAR |