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