]>
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 | ||
8a0681f9 | 200 | wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) |
10b959e3 | 201 | { |
8a0681f9 | 202 | return InsertControl(GetToolsCount(), control); |
10b959e3 JS |
203 | } |
204 | ||
8a0681f9 | 205 | wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) |
10b959e3 | 206 | { |
8a0681f9 VZ |
207 | wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, |
208 | _T("toolbar: can't insert NULL control") ); | |
209 | ||
210 | wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL, | |
211 | _T("control must have toolbar as parent") ); | |
212 | ||
213 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
214 | _T("invalid position in wxToolBar::InsertControl()") ); | |
215 | ||
216 | wxToolBarToolBase *tool = CreateTool(control); | |
217 | ||
dd91da4e | 218 | if ( !InsertTool(pos, tool) ) |
8a0681f9 VZ |
219 | { |
220 | delete tool; | |
221 | ||
222 | return NULL; | |
223 | } | |
224 | ||
8a0681f9 | 225 | return tool; |
10b959e3 JS |
226 | } |
227 | ||
fba2d5e6 RR |
228 | wxControl *wxToolBarBase::FindControl( int id ) |
229 | { | |
222ed1d6 | 230 | for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
fba2d5e6 RR |
231 | node; |
232 | node = node->GetNext() ) | |
233 | { | |
652ab153 VZ |
234 | const wxToolBarToolBase * const tool = node->GetData(); |
235 | if ( tool->IsControl() ) | |
fba2d5e6 | 236 | { |
652ab153 VZ |
237 | wxControl * const control = tool->GetControl(); |
238 | ||
239 | if ( !control ) | |
240 | { | |
241 | wxFAIL_MSG( _T("NULL control in toolbar?") ); | |
242 | } | |
243 | else if ( control->GetId() == id ) | |
244 | { | |
245 | // found | |
fba2d5e6 | 246 | return control; |
652ab153 | 247 | } |
fba2d5e6 RR |
248 | } |
249 | } | |
250 | ||
251 | return NULL; | |
252 | } | |
253 | ||
8a0681f9 | 254 | wxToolBarToolBase *wxToolBarBase::AddSeparator() |
10b959e3 | 255 | { |
8a0681f9 | 256 | return InsertSeparator(GetToolsCount()); |
10b959e3 JS |
257 | } |
258 | ||
8a0681f9 | 259 | wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) |
10b959e3 | 260 | { |
8a0681f9 VZ |
261 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
262 | _T("invalid position in wxToolBar::InsertSeparator()") ); | |
263 | ||
264 | wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, | |
e76c0b5f | 265 | wxEmptyString, |
8a0681f9 | 266 | wxNullBitmap, wxNullBitmap, |
e76c0b5f | 267 | wxITEM_SEPARATOR, (wxObject *)NULL, |
8a0681f9 VZ |
268 | wxEmptyString, wxEmptyString); |
269 | ||
270 | if ( !tool || !DoInsertTool(pos, tool) ) | |
10b959e3 | 271 | { |
8a0681f9 VZ |
272 | delete tool; |
273 | ||
274 | return NULL; | |
10b959e3 | 275 | } |
8a0681f9 VZ |
276 | |
277 | m_tools.Insert(pos, tool); | |
278 | ||
279 | return tool; | |
10b959e3 JS |
280 | } |
281 | ||
8a0681f9 | 282 | wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) |
10b959e3 | 283 | { |
8a0681f9 | 284 | size_t pos = 0; |
222ed1d6 | 285 | wxToolBarToolsList::compatibility_iterator node; |
8a0681f9 | 286 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
10b959e3 | 287 | { |
8a0681f9 VZ |
288 | if ( node->GetData()->GetId() == id ) |
289 | break; | |
290 | ||
291 | pos++; | |
10b959e3 | 292 | } |
10b959e3 | 293 | |
8a0681f9 | 294 | if ( !node ) |
10b959e3 | 295 | { |
8a0681f9 VZ |
296 | // don't give any error messages - sometimes we might call RemoveTool() |
297 | // without knowing whether the tool is or not in the toolbar | |
298 | return (wxToolBarToolBase *)NULL; | |
10b959e3 | 299 | } |
10b959e3 | 300 | |
8a0681f9 VZ |
301 | wxToolBarToolBase *tool = node->GetData(); |
302 | if ( !DoDeleteTool(pos, tool) ) | |
303 | { | |
304 | return (wxToolBarToolBase *)NULL; | |
305 | } | |
10b959e3 | 306 | |
222ed1d6 | 307 | m_tools.Erase(node); |
10b959e3 | 308 | |
8a0681f9 | 309 | return tool; |
10b959e3 JS |
310 | } |
311 | ||
8a0681f9 | 312 | bool wxToolBarBase::DeleteToolByPos(size_t pos) |
10b959e3 | 313 | { |
331c9f56 | 314 | wxCHECK_MSG( pos < GetToolsCount(), false, |
8a0681f9 | 315 | _T("invalid position in wxToolBar::DeleteToolByPos()") ); |
10b959e3 | 316 | |
222ed1d6 | 317 | wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos); |
10b959e3 | 318 | |
8a0681f9 VZ |
319 | if ( !DoDeleteTool(pos, node->GetData()) ) |
320 | { | |
331c9f56 | 321 | return false; |
8a0681f9 VZ |
322 | } |
323 | ||
222ed1d6 MB |
324 | delete node->GetData(); |
325 | m_tools.Erase(node); | |
8a0681f9 | 326 | |
331c9f56 | 327 | return true; |
10b959e3 JS |
328 | } |
329 | ||
8a0681f9 | 330 | bool wxToolBarBase::DeleteTool(int id) |
10b959e3 | 331 | { |
8a0681f9 | 332 | size_t pos = 0; |
222ed1d6 | 333 | wxToolBarToolsList::compatibility_iterator node; |
8a0681f9 VZ |
334 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
335 | { | |
336 | if ( node->GetData()->GetId() == id ) | |
337 | break; | |
338 | ||
339 | pos++; | |
340 | } | |
341 | ||
342 | if ( !node || !DoDeleteTool(pos, node->GetData()) ) | |
343 | { | |
331c9f56 | 344 | return false; |
8a0681f9 VZ |
345 | } |
346 | ||
222ed1d6 MB |
347 | delete node->GetData(); |
348 | m_tools.Erase(node); | |
8a0681f9 | 349 | |
331c9f56 | 350 | return true; |
10b959e3 JS |
351 | } |
352 | ||
8a0681f9 | 353 | wxToolBarToolBase *wxToolBarBase::FindById(int id) const |
10b959e3 | 354 | { |
8a0681f9 VZ |
355 | wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; |
356 | ||
222ed1d6 | 357 | for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
358 | node; |
359 | node = node->GetNext() ) | |
360 | { | |
361 | tool = node->GetData(); | |
362 | if ( tool->GetId() == id ) | |
363 | { | |
364 | // found | |
365 | break; | |
366 | } | |
d9739886 VZ |
367 | |
368 | tool = NULL; | |
8a0681f9 VZ |
369 | } |
370 | ||
371 | return tool; | |
10b959e3 JS |
372 | } |
373 | ||
331c9f56 VZ |
374 | void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool) |
375 | { | |
376 | wxCHECK_RET( tool, _T("NULL tool in wxToolBarTool::UnToggleRadioGroup") ); | |
377 | ||
378 | if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO ) | |
379 | return; | |
380 | ||
381 | wxToolBarToolsList::compatibility_iterator node = m_tools.Find(tool); | |
382 | wxCHECK_RET( node, _T("invalid tool in wxToolBarTool::UnToggleRadioGroup") ); | |
383 | ||
384 | wxToolBarToolsList::compatibility_iterator nodeNext = node->GetNext(); | |
385 | while ( nodeNext ) | |
386 | { | |
4e115ed2 | 387 | wxToolBarToolBase *toolNext = nodeNext->GetData(); |
331c9f56 | 388 | |
4e115ed2 | 389 | if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO ) |
331c9f56 VZ |
390 | break; |
391 | ||
4e115ed2 | 392 | if ( toolNext->Toggle(false) ) |
214b9484 | 393 | { |
4e115ed2 | 394 | DoToggleTool(toolNext, false); |
214b9484 | 395 | } |
331c9f56 VZ |
396 | |
397 | nodeNext = nodeNext->GetNext(); | |
398 | } | |
399 | ||
400 | wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious(); | |
401 | while ( nodePrev ) | |
402 | { | |
4e115ed2 | 403 | wxToolBarToolBase *toolNext = nodePrev->GetData(); |
331c9f56 | 404 | |
4e115ed2 | 405 | if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO ) |
331c9f56 VZ |
406 | break; |
407 | ||
4e115ed2 | 408 | if ( toolNext->Toggle(false) ) |
214b9484 | 409 | { |
4e115ed2 | 410 | DoToggleTool(toolNext, false); |
214b9484 | 411 | } |
331c9f56 VZ |
412 | |
413 | nodePrev = nodePrev->GetPrevious(); | |
414 | } | |
415 | } | |
416 | ||
8a0681f9 | 417 | void wxToolBarBase::ClearTools() |
10b959e3 | 418 | { |
a3e9caa2 RD |
419 | while ( GetToolsCount() ) |
420 | { | |
421 | DeleteToolByPos(0); | |
422 | } | |
10b959e3 JS |
423 | } |
424 | ||
8a0681f9 | 425 | bool wxToolBarBase::Realize() |
10b959e3 | 426 | { |
331c9f56 | 427 | return true; |
10b959e3 JS |
428 | } |
429 | ||
8a0681f9 | 430 | wxToolBarBase::~wxToolBarBase() |
10b959e3 | 431 | { |
222ed1d6 | 432 | WX_CLEAR_LIST(wxToolBarToolsList, m_tools); |
2ab82214 VZ |
433 | |
434 | // notify the frame that it doesn't have a tool bar any longer to avoid | |
435 | // dangling pointers | |
b2e3be1c | 436 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
2ab82214 VZ |
437 | if ( frame && frame->GetToolBar() == this ) |
438 | { | |
439 | frame->SetToolBar(NULL); | |
440 | } | |
10b959e3 JS |
441 | } |
442 | ||
8a0681f9 VZ |
443 | // ---------------------------------------------------------------------------- |
444 | // wxToolBarBase tools state | |
445 | // ---------------------------------------------------------------------------- | |
10b959e3 | 446 | |
8a0681f9 | 447 | void wxToolBarBase::EnableTool(int id, bool enable) |
10b959e3 | 448 | { |
8a0681f9 VZ |
449 | wxToolBarToolBase *tool = FindById(id); |
450 | if ( tool ) | |
10b959e3 | 451 | { |
8a0681f9 VZ |
452 | if ( tool->Enable(enable) ) |
453 | { | |
454 | DoEnableTool(tool, enable); | |
455 | } | |
10b959e3 | 456 | } |
8a0681f9 | 457 | } |
10b959e3 | 458 | |
8a0681f9 VZ |
459 | void wxToolBarBase::ToggleTool(int id, bool toggle) |
460 | { | |
461 | wxToolBarToolBase *tool = FindById(id); | |
462 | if ( tool && tool->CanBeToggled() ) | |
10b959e3 | 463 | { |
8a0681f9 VZ |
464 | if ( tool->Toggle(toggle) ) |
465 | { | |
331c9f56 | 466 | UnToggleRadioGroup(tool); |
8a0681f9 VZ |
467 | DoToggleTool(tool, toggle); |
468 | } | |
10b959e3 | 469 | } |
10b959e3 JS |
470 | } |
471 | ||
8a0681f9 VZ |
472 | void wxToolBarBase::SetToggle(int id, bool toggle) |
473 | { | |
474 | wxToolBarToolBase *tool = FindById(id); | |
475 | if ( tool ) | |
10b959e3 | 476 | { |
8a0681f9 VZ |
477 | if ( tool->SetToggle(toggle) ) |
478 | { | |
479 | DoSetToggle(tool, toggle); | |
480 | } | |
10b959e3 | 481 | } |
8a0681f9 VZ |
482 | } |
483 | ||
484 | void wxToolBarBase::SetToolShortHelp(int id, const wxString& help) | |
485 | { | |
486 | wxToolBarToolBase *tool = FindById(id); | |
487 | if ( tool ) | |
10b959e3 | 488 | { |
8a0681f9 | 489 | (void)tool->SetShortHelp(help); |
10b959e3 | 490 | } |
8a0681f9 VZ |
491 | } |
492 | ||
493 | void wxToolBarBase::SetToolLongHelp(int id, const wxString& help) | |
494 | { | |
495 | wxToolBarToolBase *tool = FindById(id); | |
496 | if ( tool ) | |
10b959e3 | 497 | { |
8a0681f9 | 498 | (void)tool->SetLongHelp(help); |
10b959e3 | 499 | } |
10b959e3 JS |
500 | } |
501 | ||
8a0681f9 | 502 | wxObject *wxToolBarBase::GetToolClientData(int id) const |
10b959e3 | 503 | { |
8a0681f9 VZ |
504 | wxToolBarToolBase *tool = FindById(id); |
505 | ||
506 | return tool ? tool->GetClientData() : (wxObject *)NULL; | |
10b959e3 JS |
507 | } |
508 | ||
6fd5fa4f VZ |
509 | void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) |
510 | { | |
511 | wxToolBarToolBase *tool = FindById(id); | |
512 | ||
513 | wxCHECK_RET( tool, _T("no such tool in wxToolBar::SetToolClientData") ); | |
514 | ||
515 | tool->SetClientData(clientData); | |
516 | } | |
517 | ||
e6c96a7c JS |
518 | int wxToolBarBase::GetToolPos(int id) const |
519 | { | |
520 | size_t pos = 0; | |
222ed1d6 | 521 | wxToolBarToolsList::compatibility_iterator node; |
e6c96a7c JS |
522 | |
523 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
524 | { | |
525 | if ( node->GetData()->GetId() == id ) | |
526 | return pos; | |
527 | ||
528 | pos++; | |
529 | } | |
530 | ||
531 | return wxNOT_FOUND; | |
532 | } | |
533 | ||
8a0681f9 | 534 | bool wxToolBarBase::GetToolState(int id) const |
10b959e3 | 535 | { |
8a0681f9 | 536 | wxToolBarToolBase *tool = FindById(id); |
331c9f56 | 537 | wxCHECK_MSG( tool, false, _T("no such tool") ); |
8a0681f9 VZ |
538 | |
539 | return tool->IsToggled(); | |
10b959e3 JS |
540 | } |
541 | ||
8a0681f9 | 542 | bool wxToolBarBase::GetToolEnabled(int id) const |
10b959e3 | 543 | { |
8a0681f9 | 544 | wxToolBarToolBase *tool = FindById(id); |
331c9f56 | 545 | wxCHECK_MSG( tool, false, _T("no such tool") ); |
8a0681f9 VZ |
546 | |
547 | return tool->IsEnabled(); | |
10b959e3 JS |
548 | } |
549 | ||
8a0681f9 | 550 | wxString wxToolBarBase::GetToolShortHelp(int id) const |
10b959e3 | 551 | { |
8a0681f9 | 552 | wxToolBarToolBase *tool = FindById(id); |
525d8583 | 553 | wxCHECK_MSG( tool, wxEmptyString, _T("no such tool") ); |
8a0681f9 VZ |
554 | |
555 | return tool->GetShortHelp(); | |
10b959e3 JS |
556 | } |
557 | ||
8a0681f9 | 558 | wxString wxToolBarBase::GetToolLongHelp(int id) const |
10b959e3 | 559 | { |
8a0681f9 | 560 | wxToolBarToolBase *tool = FindById(id); |
525d8583 | 561 | wxCHECK_MSG( tool, wxEmptyString, _T("no such tool") ); |
10b959e3 | 562 | |
8a0681f9 | 563 | return tool->GetLongHelp(); |
10b959e3 JS |
564 | } |
565 | ||
8a0681f9 VZ |
566 | // ---------------------------------------------------------------------------- |
567 | // wxToolBarBase geometry | |
568 | // ---------------------------------------------------------------------------- | |
569 | ||
570 | void wxToolBarBase::SetMargins(int x, int y) | |
10b959e3 | 571 | { |
8a0681f9 VZ |
572 | m_xMargin = x; |
573 | m_yMargin = y; | |
10b959e3 JS |
574 | } |
575 | ||
8a0681f9 | 576 | void wxToolBarBase::SetRows(int WXUNUSED(nRows)) |
10b959e3 | 577 | { |
8a0681f9 | 578 | // nothing |
10b959e3 JS |
579 | } |
580 | ||
8a0681f9 VZ |
581 | // ---------------------------------------------------------------------------- |
582 | // event processing | |
583 | // ---------------------------------------------------------------------------- | |
584 | ||
331c9f56 | 585 | // Only allow toggle if returns true |
8a0681f9 | 586 | bool wxToolBarBase::OnLeftClick(int id, bool toggleDown) |
10b959e3 | 587 | { |
8a0681f9 VZ |
588 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id); |
589 | event.SetEventObject(this); | |
6bec54e1 VZ |
590 | |
591 | // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown | |
592 | event.SetInt((int)toggleDown); | |
593 | ||
594 | // and SetExtraLong() for backwards compatibility | |
595 | event.SetExtraLong((long)toggleDown); | |
8a0681f9 VZ |
596 | |
597 | // Send events to this toolbar instead (and thence up the window hierarchy) | |
598 | GetEventHandler()->ProcessEvent(event); | |
599 | ||
331c9f56 | 600 | return true; |
10b959e3 JS |
601 | } |
602 | ||
8a0681f9 VZ |
603 | // Call when right button down. |
604 | void wxToolBarBase::OnRightClick(int id, | |
605 | long WXUNUSED(x), | |
606 | long WXUNUSED(y)) | |
10b959e3 | 607 | { |
8a0681f9 VZ |
608 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id); |
609 | event.SetEventObject(this); | |
610 | event.SetInt(id); | |
611 | ||
612 | GetEventHandler()->ProcessEvent(event); | |
613 | } | |
43d811ea | 614 | |
8a0681f9 | 615 | // Called when the mouse cursor enters a tool bitmap (no button pressed). |
cb719f2e | 616 | // Argument is wxID_ANY if mouse is exiting the toolbar. |
8a0681f9 VZ |
617 | // Note that for this event, the id of the window is used, |
618 | // and the integer parameter of wxCommandEvent is used to retrieve | |
619 | // the tool id. | |
620 | void wxToolBarBase::OnMouseEnter(int id) | |
621 | { | |
622 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); | |
623 | event.SetEventObject(this); | |
624 | event.SetInt(id); | |
625 | ||
8a0681f9 | 626 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
1f361cdd | 627 | if( frame ) |
66ce9e06 | 628 | { |
326a37f1 WS |
629 | wxString help; |
630 | wxToolBarToolBase* tool = id == wxID_ANY ? (wxToolBarToolBase*)NULL : FindById(id); | |
631 | if(tool) | |
632 | help = tool->GetLongHelp(); | |
cb719f2e | 633 | frame->DoGiveHelp( help, id != wxID_ANY ); |
66ce9e06 VZ |
634 | } |
635 | ||
1f361cdd | 636 | (void)GetEventHandler()->ProcessEvent(event); |
8a0681f9 VZ |
637 | } |
638 | ||
639 | // ---------------------------------------------------------------------------- | |
640 | // UI updates | |
641 | // ---------------------------------------------------------------------------- | |
642 | ||
10b959e3 | 643 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) |
e39af974 | 644 | void wxToolBarBase::UpdateWindowUI(long flags) |
ac91b9d2 | 645 | { |
e39af974 JS |
646 | wxWindowBase::UpdateWindowUI(flags); |
647 | ||
fe5d86ed RR |
648 | // There is no sense in updating the toolbar UI |
649 | // if the parent window is about to get destroyed | |
5ce61d9f RR |
650 | wxWindow *tlw = wxGetTopLevelParent( this ); |
651 | if (tlw && wxPendingDelete.Member( tlw )) | |
fe5d86ed RR |
652 | return; |
653 | ||
65b17727 | 654 | wxEvtHandler* evtHandler = GetEventHandler() ; |
e702ff0f | 655 | |
222ed1d6 | 656 | for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
657 | node; |
658 | node = node->GetNext() ) | |
ac91b9d2 | 659 | { |
8a0681f9 | 660 | int id = node->GetData()->GetId(); |
ac91b9d2 | 661 | |
8a0681f9 | 662 | wxUpdateUIEvent event(id); |
ac91b9d2 VZ |
663 | event.SetEventObject(this); |
664 | ||
8a0681f9 | 665 | if ( evtHandler->ProcessEvent(event) ) |
ac91b9d2 | 666 | { |
8a0681f9 VZ |
667 | if ( event.GetSetEnabled() ) |
668 | EnableTool(id, event.GetEnabled()); | |
669 | if ( event.GetSetChecked() ) | |
670 | ToggleTool(id, event.GetChecked()); | |
671 | #if 0 | |
672 | if ( event.GetSetText() ) | |
ac91b9d2 | 673 | // Set tooltip? |
8a0681f9 | 674 | #endif // 0 |
ac91b9d2 | 675 | } |
ac91b9d2 | 676 | } |
10b959e3 JS |
677 | } |
678 | ||
9ac43913 | 679 | #if WXWIN_COMPATIBILITY_2_8 |
c229e50d | 680 | |
9ac43913 | 681 | bool wxCreateGreyedImage(const wxImage& in, wxImage& out) |
c229e50d | 682 | { |
9ac43913 VZ |
683 | #if wxUSE_IMAGE |
684 | out = in.ConvertToGreyscale(); | |
685 | if ( out.Ok() ) | |
686 | return true; | |
687 | #endif // wxUSE_IMAGE | |
c229e50d | 688 | |
9ac43913 | 689 | return false; |
c229e50d JS |
690 | } |
691 | ||
9ac43913 | 692 | #endif // WXWIN_COMPATIBILITY_2_8 |
434c6c9f | 693 | |
8a0681f9 | 694 | #endif // wxUSE_TOOLBAR |