]> git.saurik.com Git - wxWidgets.git/blame - src/common/tbarbase.cpp
Split wxLocale into wxLocale and wxTranslations.
[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
88046bda 457 // make sure tool size is large enough for all bitmaps to fit in
bb2212e6
VZ
458 AdjustToolBitmapSize();
459
331c9f56 460 return true;
10b959e3
JS
461}
462
8a0681f9 463wxToolBarBase::~wxToolBarBase()
10b959e3 464{
222ed1d6 465 WX_CLEAR_LIST(wxToolBarToolsList, m_tools);
2ab82214
VZ
466
467 // notify the frame that it doesn't have a tool bar any longer to avoid
468 // dangling pointers
b2e3be1c 469 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2ab82214
VZ
470 if ( frame && frame->GetToolBar() == this )
471 {
472 frame->SetToolBar(NULL);
473 }
10b959e3
JS
474}
475
8a0681f9
VZ
476// ----------------------------------------------------------------------------
477// wxToolBarBase tools state
478// ----------------------------------------------------------------------------
10b959e3 479
8a0681f9 480void wxToolBarBase::EnableTool(int id, bool enable)
10b959e3 481{
8a0681f9
VZ
482 wxToolBarToolBase *tool = FindById(id);
483 if ( tool )
10b959e3 484 {
8a0681f9
VZ
485 if ( tool->Enable(enable) )
486 {
487 DoEnableTool(tool, enable);
488 }
10b959e3 489 }
8a0681f9 490}
10b959e3 491
8a0681f9
VZ
492void wxToolBarBase::ToggleTool(int id, bool toggle)
493{
494 wxToolBarToolBase *tool = FindById(id);
495 if ( tool && tool->CanBeToggled() )
10b959e3 496 {
8a0681f9
VZ
497 if ( tool->Toggle(toggle) )
498 {
331c9f56 499 UnToggleRadioGroup(tool);
8a0681f9
VZ
500 DoToggleTool(tool, toggle);
501 }
10b959e3 502 }
10b959e3
JS
503}
504
8a0681f9
VZ
505void wxToolBarBase::SetToggle(int id, bool toggle)
506{
507 wxToolBarToolBase *tool = FindById(id);
508 if ( tool )
10b959e3 509 {
8a0681f9
VZ
510 if ( tool->SetToggle(toggle) )
511 {
512 DoSetToggle(tool, toggle);
513 }
10b959e3 514 }
8a0681f9
VZ
515}
516
517void wxToolBarBase::SetToolShortHelp(int id, const wxString& help)
518{
519 wxToolBarToolBase *tool = FindById(id);
520 if ( tool )
10b959e3 521 {
8a0681f9 522 (void)tool->SetShortHelp(help);
10b959e3 523 }
8a0681f9
VZ
524}
525
526void wxToolBarBase::SetToolLongHelp(int id, const wxString& help)
527{
528 wxToolBarToolBase *tool = FindById(id);
529 if ( tool )
10b959e3 530 {
8a0681f9 531 (void)tool->SetLongHelp(help);
10b959e3 532 }
10b959e3
JS
533}
534
8a0681f9 535wxObject *wxToolBarBase::GetToolClientData(int id) const
10b959e3 536{
8a0681f9
VZ
537 wxToolBarToolBase *tool = FindById(id);
538
d3b9f782 539 return tool ? tool->GetClientData() : NULL;
10b959e3
JS
540}
541
6fd5fa4f
VZ
542void wxToolBarBase::SetToolClientData(int id, wxObject *clientData)
543{
544 wxToolBarToolBase *tool = FindById(id);
545
9a83f860 546 wxCHECK_RET( tool, wxT("no such tool in wxToolBar::SetToolClientData") );
6fd5fa4f
VZ
547
548 tool->SetClientData(clientData);
549}
550
e6c96a7c
JS
551int wxToolBarBase::GetToolPos(int id) const
552{
553 size_t pos = 0;
222ed1d6 554 wxToolBarToolsList::compatibility_iterator node;
e6c96a7c
JS
555
556 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
557 {
558 if ( node->GetData()->GetId() == id )
559 return pos;
560
561 pos++;
562 }
563
564 return wxNOT_FOUND;
565}
566
8a0681f9 567bool wxToolBarBase::GetToolState(int id) const
10b959e3 568{
8a0681f9 569 wxToolBarToolBase *tool = FindById(id);
9a83f860 570 wxCHECK_MSG( tool, false, wxT("no such tool") );
8a0681f9
VZ
571
572 return tool->IsToggled();
10b959e3
JS
573}
574
8a0681f9 575bool wxToolBarBase::GetToolEnabled(int id) const
10b959e3 576{
8a0681f9 577 wxToolBarToolBase *tool = FindById(id);
9a83f860 578 wxCHECK_MSG( tool, false, wxT("no such tool") );
8a0681f9
VZ
579
580 return tool->IsEnabled();
10b959e3
JS
581}
582
8a0681f9 583wxString wxToolBarBase::GetToolShortHelp(int id) const
10b959e3 584{
8a0681f9 585 wxToolBarToolBase *tool = FindById(id);
9a83f860 586 wxCHECK_MSG( tool, wxEmptyString, wxT("no such tool") );
8a0681f9
VZ
587
588 return tool->GetShortHelp();
10b959e3
JS
589}
590
8a0681f9 591wxString wxToolBarBase::GetToolLongHelp(int id) const
10b959e3 592{
8a0681f9 593 wxToolBarToolBase *tool = FindById(id);
9a83f860 594 wxCHECK_MSG( tool, wxEmptyString, wxT("no such tool") );
10b959e3 595
8a0681f9 596 return tool->GetLongHelp();
10b959e3
JS
597}
598
8a0681f9
VZ
599// ----------------------------------------------------------------------------
600// wxToolBarBase geometry
601// ----------------------------------------------------------------------------
602
603void wxToolBarBase::SetMargins(int x, int y)
10b959e3 604{
8a0681f9
VZ
605 m_xMargin = x;
606 m_yMargin = y;
10b959e3
JS
607}
608
8a0681f9 609void wxToolBarBase::SetRows(int WXUNUSED(nRows))
10b959e3 610{
8a0681f9 611 // nothing
10b959e3
JS
612}
613
25af884d
FM
614bool wxToolBarBase::IsVertical() const
615{
616 return HasFlag(wxTB_LEFT | wxTB_RIGHT);
617}
618
619
8a0681f9
VZ
620// ----------------------------------------------------------------------------
621// event processing
622// ----------------------------------------------------------------------------
623
331c9f56 624// Only allow toggle if returns true
8a0681f9 625bool wxToolBarBase::OnLeftClick(int id, bool toggleDown)
10b959e3 626{
8a0681f9
VZ
627 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id);
628 event.SetEventObject(this);
6bec54e1
VZ
629
630 // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown
631 event.SetInt((int)toggleDown);
632
633 // and SetExtraLong() for backwards compatibility
634 event.SetExtraLong((long)toggleDown);
8a0681f9
VZ
635
636 // Send events to this toolbar instead (and thence up the window hierarchy)
8a012034 637 HandleWindowEvent(event);
8a0681f9 638
331c9f56 639 return true;
10b959e3
JS
640}
641
8a0681f9
VZ
642// Call when right button down.
643void wxToolBarBase::OnRightClick(int id,
644 long WXUNUSED(x),
645 long WXUNUSED(y))
10b959e3 646{
8a0681f9
VZ
647 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id);
648 event.SetEventObject(this);
649 event.SetInt(id);
650
651 GetEventHandler()->ProcessEvent(event);
652}
43d811ea 653
8a0681f9 654// Called when the mouse cursor enters a tool bitmap (no button pressed).
cb719f2e 655// Argument is wxID_ANY if mouse is exiting the toolbar.
8a0681f9
VZ
656// Note that for this event, the id of the window is used,
657// and the integer parameter of wxCommandEvent is used to retrieve
658// the tool id.
659void wxToolBarBase::OnMouseEnter(int id)
660{
661 wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId());
662 event.SetEventObject(this);
663 event.SetInt(id);
664
8a0681f9 665 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
6d99eb3e 666 if ( frame )
66ce9e06 667 {
326a37f1 668 wxString help;
fa36fe36
VZ
669 if ( id != wxID_ANY )
670 {
671 const wxToolBarToolBase * const tool = FindById(id);
672 if ( tool )
673 help = tool->GetLongHelp();
674 }
675
6d99eb3e
VZ
676 // call DoGiveHelp() even if help string is empty to avoid showing the
677 // help for the previously selected tool when another one is selected
678 frame->DoGiveHelp(help, id != wxID_ANY);
66ce9e06
VZ
679 }
680
1f361cdd 681 (void)GetEventHandler()->ProcessEvent(event);
8a0681f9
VZ
682}
683
684// ----------------------------------------------------------------------------
685// UI updates
686// ----------------------------------------------------------------------------
687
10b959e3 688// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
e39af974 689void wxToolBarBase::UpdateWindowUI(long flags)
ac91b9d2 690{
e39af974
JS
691 wxWindowBase::UpdateWindowUI(flags);
692
632e5b63
VZ
693 // don't waste time updating state of tools in a hidden toolbar
694 if ( !IsShown() )
695 return;
696
fe5d86ed
RR
697 // There is no sense in updating the toolbar UI
698 // if the parent window is about to get destroyed
5ce61d9f
RR
699 wxWindow *tlw = wxGetTopLevelParent( this );
700 if (tlw && wxPendingDelete.Member( tlw ))
fe5d86ed
RR
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
713 int id = tool->GetId();
ac91b9d2 714
8a0681f9 715 wxUpdateUIEvent event(id);
ac91b9d2
VZ
716 event.SetEventObject(this);
717
8a0681f9 718 if ( evtHandler->ProcessEvent(event) )
ac91b9d2 719 {
8a0681f9
VZ
720 if ( event.GetSetEnabled() )
721 EnableTool(id, event.GetEnabled());
722 if ( event.GetSetChecked() )
723 ToggleTool(id, event.GetChecked());
724#if 0
725 if ( event.GetSetText() )
ac91b9d2 726 // Set tooltip?
8a0681f9 727#endif // 0
ac91b9d2 728 }
ac91b9d2 729 }
10b959e3
JS
730}
731
a9a0ceca
VZ
732bool wxToolBarBase::SetDropdownMenu(int toolid, wxMenu* menu)
733{
734 wxToolBarToolBase * const tool = FindById(toolid);
9a83f860 735 wxCHECK_MSG( tool, false, wxT("invalid tool id") );
a9a0ceca
VZ
736
737 wxCHECK_MSG( tool->GetKind() == wxITEM_DROPDOWN, false,
9a83f860 738 wxT("menu can be only associated with drop down tools") );
a9a0ceca
VZ
739
740 tool->SetDropdownMenu(menu);
741
742 return true;
743}
744
9ac43913 745#if WXWIN_COMPATIBILITY_2_8
c229e50d 746
9ac43913 747bool wxCreateGreyedImage(const wxImage& in, wxImage& out)
c229e50d 748{
9ac43913
VZ
749#if wxUSE_IMAGE
750 out = in.ConvertToGreyscale();
751 if ( out.Ok() )
752 return true;
753#endif // wxUSE_IMAGE
9ac43913 754 return false;
c229e50d
JS
755}
756
9ac43913 757#endif // WXWIN_COMPATIBILITY_2_8
434c6c9f 758
8a0681f9 759#endif // wxUSE_TOOLBAR