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