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