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