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