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