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