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