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