]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
No res-include for rpmspec wx24dsp
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: toolbar.cpp
3// Purpose: wxToolBar
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
84969af7 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: The wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "toolbar.h"
14#endif
15
3d1a4878 16#include "wx/wxprec.h"
519cb848
SC
17
18#if wxUSE_TOOLBAR
19
3d1a4878 20#include "wx/wx.h"
e9576ca5 21#include "wx/toolbar.h"
2f1ae414
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
72055702 24#include "wx/bitmap.h"
e9576ca5 25
2f1ae414 26#if !USE_SHARED_LIBRARY
2eb10e2a 27IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
e9576ca5
SC
28
29BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
e044f600 30 EVT_PAINT( wxToolBar::OnPaint )
e9576ca5 31END_EVENT_TABLE()
2f1ae414 32#endif
e9576ca5 33
d497dca4 34#include "wx/mac/uma.h"
bfe9ffbc 35#include "wx/geometry.h"
ee799df7
SC
36
37#ifdef __WXMAC_OSX__
abbcdf3f
SC
38const short kwxMacToolBarToolDefaultWidth = 24 ;
39const short kwxMacToolBarToolDefaultHeight = 24 ;
ee799df7
SC
40const short kwxMacToolBarTopMargin = 4 ;
41const short kwxMacToolBarLeftMargin = 4 ;
42const short kwxMacToolBorder = 0 ;
abbcdf3f 43const short kwxMacToolSpacing = 6 ;
ee799df7
SC
44#else
45const short kwxMacToolBarToolDefaultWidth = 24 ;
46const short kwxMacToolBarToolDefaultHeight = 22 ;
47const short kwxMacToolBarTopMargin = 2 ;
48const short kwxMacToolBarLeftMargin = 2 ;
49const short kwxMacToolBorder = 4 ;
abbcdf3f 50const short kwxMacToolSpacing = 0 ;
ee799df7
SC
51#endif
52
37e2cb08
SC
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
57class wxToolBarTool : public wxToolBarToolBase
58{
59public:
60 wxToolBarTool(wxToolBar *tbar,
61 int id,
27e2d606
GD
62 const wxString& label,
63 const wxBitmap& bmpNormal,
64 const wxBitmap& bmpDisabled,
65 wxItemKind kind,
37e2cb08 66 wxObject *clientData,
27e2d606 67 const wxString& shortHelp,
bfe9ffbc
SC
68 const wxString& longHelp) ;
69
37e2cb08
SC
70 wxToolBarTool(wxToolBar *tbar, wxControl *control)
71 : wxToolBarToolBase(tbar, control)
72 {
bfe9ffbc 73 Init() ;
37e2cb08 74 }
bfe9ffbc
SC
75
76 ~wxToolBarTool()
77 {
78 if ( m_controlHandle )
79 DisposeControl( m_controlHandle ) ;
80 }
81
facd6764
SC
82 WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; }
83 void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; }
37e2cb08 84
bfe9ffbc
SC
85 void SetSize(const wxSize& size) ;
86 void SetPosition( const wxPoint& position ) ;
a2fe01c9 87
bfe9ffbc
SC
88 wxSize GetSize() const
89 {
90 if ( IsControl() )
91 {
92 return GetControl()->GetSize() ;
93 }
94 else if ( IsButton() )
95 {
96 return GetToolBar()->GetToolSize() ;
97 }
98 else
99 {
abbcdf3f 100 // separator size
bfe9ffbc 101 wxSize sz = GetToolBar()->GetToolSize() ;
5a904a32
SC
102 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
103 sz.y /= 4 ;
104 else
105 sz.x /= 4 ;
bfe9ffbc
SC
106 return sz ;
107 }
108 }
109 wxPoint GetPosition() const
110 {
111 return wxPoint(m_x, m_y);
112 }
a2fe01c9 113 bool DoEnable( bool enable ) ;
73fd9428
SC
114
115 void UpdateToggleImage( bool toggle ) ;
bfe9ffbc
SC
116private :
117 void Init()
118 {
119 m_controlHandle = NULL ;
120 }
facd6764 121 ControlRef m_controlHandle ;
37e2cb08 122
bfe9ffbc
SC
123 wxCoord m_x;
124 wxCoord m_y;
37e2cb08
SC
125};
126
facd6764
SC
127static const EventTypeSpec eventList[] =
128{
129 { kEventClassControl , kEventControlHit } ,
73fd9428
SC
130#ifdef __WXMAC_OSX__
131 { kEventClassControl , kEventControlHitTest } ,
132#endif
facd6764
SC
133} ;
134
135static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
136{
137 OSStatus result = eventNotHandledErr ;
138
139 wxMacCarbonEvent cEvent( event ) ;
140
141 ControlRef controlRef ;
142
143 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
144
145 switch( GetEventKind( event ) )
146 {
147 case kEventControlHit :
148 {
149 wxToolBarTool* tbartool = (wxToolBarTool*)data ;
150 if ( tbartool->CanBeToggled() )
151 {
64f553a4
SC
152#ifdef __WXMAC_OSX__
153 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), !tbartool->IsToggled() );
154#else
214b9484 155 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
64f553a4 156#endif
facd6764
SC
157 }
158 ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
facd6764
SC
159 result = noErr;
160 }
161 break ;
73fd9428
SC
162#ifdef __WXMAC_OSX__
163 case kEventControlHitTest :
164 {
165 HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
166 HIRect rect ;
167 HIViewGetBounds( controlRef , &rect ) ;
168
169 ControlPartCode pc = kControlNoPart ;
170 if ( CGRectContainsPoint( rect , pt ) )
171 pc = kControlButtonPart ;
172 cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
173 result = noErr ;
174 }
175 break ;
176#endif
facd6764
SC
177 default :
178 break ;
179 }
180 return result ;
181}
182
183pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
184{
185 OSStatus result = eventNotHandledErr ;
186
187 switch ( GetEventClass( event ) )
188 {
189 case kEventClassControl :
190 result = wxMacToolBarToolControlEventHandler( handler, event, data ) ;
191 break ;
192 default :
193 break ;
194 }
195 return result ;
196}
197
198DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
199
37e2cb08
SC
200// ============================================================================
201// implementation
202// ============================================================================
203
204// ----------------------------------------------------------------------------
205// wxToolBarTool
206// ----------------------------------------------------------------------------
207
a2fe01c9
SC
208bool wxToolBarTool::DoEnable(bool enable)
209{
210 if ( IsControl() )
211 {
212 GetControl()->Enable( enable ) ;
213 }
214 else if ( IsButton() )
215 {
216#if TARGET_API_MAC_OSX
217 if ( enable )
218 EnableControl( m_controlHandle ) ;
219 else
220 DisableControl( m_controlHandle ) ;
221#else
222 if ( enable )
223 ActivateControl( m_controlHandle ) ;
224 else
225 DeactivateControl( m_controlHandle ) ;
226#endif
227 }
228 return true ;
229}
bfe9ffbc
SC
230void wxToolBarTool::SetSize(const wxSize& size)
231{
232 if ( IsControl() )
233 {
234 GetControl()->SetSize( size ) ;
235 }
236}
237
238void wxToolBarTool::SetPosition(const wxPoint& position)
239{
240 m_x = position.x;
241 m_y = position.y;
242
789ae0cf
SC
243 int x , y ;
244 x = y = 0 ;
245 int mac_x = position.x ;
246 int mac_y = position.y ;
247
248 if ( ! GetToolBar()->MacGetTopLevelWindow()->MacUsesCompositing() )
bfe9ffbc 249 {
bfe9ffbc 250 GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
facd6764
SC
251 mac_x += x;
252 mac_y += y;
789ae0cf
SC
253 }
254
255 if ( IsButton() )
256 {
bfe9ffbc
SC
257 Rect contrlRect ;
258 GetControlBounds( m_controlHandle , &contrlRect ) ;
259 int former_mac_x = contrlRect.left ;
260 int former_mac_y = contrlRect.top ;
80e3f464 261 GetToolBar()->GetToolSize() ;
bfe9ffbc
SC
262
263 if ( mac_x != former_mac_x || mac_y != former_mac_y )
264 {
bfe9ffbc 265 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
bfe9ffbc
SC
266 }
267 }
268 else if ( IsControl() )
269 {
270 GetControl()->Move( position ) ;
271 }
abbcdf3f
SC
272 else
273 {
274 // separator
275#ifdef __WXMAC_OSX__
abbcdf3f
SC
276 Rect contrlRect ;
277 GetControlBounds( m_controlHandle , &contrlRect ) ;
278 int former_mac_x = contrlRect.left ;
279 int former_mac_y = contrlRect.top ;
280
281 if ( mac_x != former_mac_x || mac_y != former_mac_y )
282 {
283 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
284 }
285#endif
286 }
bfe9ffbc
SC
287}
288
73fd9428
SC
289void wxToolBarTool::UpdateToggleImage( bool toggle )
290{
291#ifdef __WXMAC_OSX__
292 if ( toggle )
293 {
294 int w = m_bmpNormal.GetWidth() ;
295 int h = m_bmpNormal.GetHeight() ;
296 wxBitmap bmp( w , h ) ;
297 wxMemoryDC dc ;
298 dc.SelectObject( bmp ) ;
299 dc.SetPen( wxNullPen ) ;
300 dc.SetBackground( *wxWHITE ) ;
301 dc.DrawRectangle( 0 , 0 , w , h ) ;
302 dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ;
303 dc.SelectObject( wxNullBitmap ) ;
304 ControlButtonContentInfo info ;
305 wxMacCreateBitmapButton( &info , bmp ) ;
306 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
307 (Ptr)&info );
308 wxMacReleaseBitmapButton( &info ) ;
309 }
310 else
311 {
312 ControlButtonContentInfo info ;
313 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
314 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
315 (Ptr)&info );
316 wxMacReleaseBitmapButton( &info ) ;
317 }
318
319 IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
320 SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
321 (Ptr)&transform );
322 HIViewSetNeedsDisplay( m_controlHandle , true ) ;
323
324#else
325 ::SetControl32BitValue( m_controlHandle , toggle ) ;
326#endif
327}
328
bfe9ffbc
SC
329wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
330 int id,
331 const wxString& label,
332 const wxBitmap& bmpNormal,
333 const wxBitmap& bmpDisabled,
334 wxItemKind kind,
335 wxObject *clientData,
336 const wxString& shortHelp,
337 const wxString& longHelp)
338 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
339 clientData, shortHelp, longHelp)
340{
f4e0be4f
RR
341 Init();
342
facd6764 343 WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ;
bfe9ffbc
SC
344 wxSize toolSize = tbar->GetToolSize() ;
345 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
abbcdf3f
SC
346
347 if ( id == wxID_SEPARATOR )
ee799df7 348 {
abbcdf3f
SC
349 toolSize.x /= 4 ;
350 toolSize.y /= 4 ;
351 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
352 {
353 toolrect.bottom = toolSize.y ;
354 }
355 else
356 {
357 toolrect.right = toolSize.x ;
358 }
359#ifdef __WXMAC_OSX__
360 // in flat style we need a visual separator
361 CreateSeparatorControl( window , &toolrect , &m_controlHandle ) ;
362#endif
ee799df7 363 }
abbcdf3f
SC
364 else
365 {
366 ControlButtonContentInfo info ;
d56db55e 367 wxMacCreateBitmapButton( &info , GetNormalBitmap() , kControlContentIconRef ) ;
abbcdf3f
SC
368
369#ifdef __WXMAC_OSX__
abbcdf3f 370 CreateIconControl( window , &toolrect , &info , false , &m_controlHandle ) ;
ee799df7 371#else
abbcdf3f
SC
372 SInt16 behaviour = kControlBehaviorOffsetContents ;
373 if ( CanBeToggled() )
374 behaviour += kControlBehaviorToggles ;
375 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
376 0 , 0 , 0 , &m_controlHandle ) ;
ee799df7 377#endif
abbcdf3f
SC
378
379 wxMacReleaseBitmapButton( &info ) ;
380 /*
381 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
382 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
383 */
4c37f124 384
abbcdf3f
SC
385 InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
386 GetEventTypeCount(eventList), eventList, this,NULL);
4c37f124 387
abbcdf3f 388 }
facd6764 389 ControlRef container = (ControlRef) tbar->GetHandle() ;
bfe9ffbc 390 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
abbcdf3f
SC
391 if ( m_controlHandle )
392 {
393 UMAShowControl( m_controlHandle ) ;
394 ::EmbedControl( m_controlHandle , container ) ;
395 }
73fd9428
SC
396 if ( CanBeToggled() && IsToggled() )
397 {
398 UpdateToggleImage( true ) ;
399 }
bfe9ffbc
SC
400}
401
2f1ae414 402
37e2cb08 403wxToolBarToolBase *wxToolBar::CreateTool(int id,
27e2d606
GD
404 const wxString& label,
405 const wxBitmap& bmpNormal,
406 const wxBitmap& bmpDisabled,
407 wxItemKind kind,
37e2cb08 408 wxObject *clientData,
27e2d606
GD
409 const wxString& shortHelp,
410 const wxString& longHelp)
37e2cb08 411{
27e2d606
GD
412 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
413 clientData, shortHelp, longHelp);
37e2cb08
SC
414}
415
416wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
417{
418 return new wxToolBarTool(this, control);
419}
420
37e2cb08 421void wxToolBar::Init()
e9576ca5 422{
e40298d5
JS
423 m_maxWidth = -1;
424 m_maxHeight = -1;
425 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
426 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
e9576ca5
SC
427}
428
429bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
430 long style, const wxString& name)
e40298d5 431{
ee799df7 432
facd6764
SC
433 if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
434 return FALSE ;
e40298d5
JS
435
436 return TRUE;
e9576ca5
SC
437}
438
439wxToolBar::~wxToolBar()
bfe9ffbc 440{
7810c95b
SC
441 // we must refresh the frame size when the toolbar is deleted but the frame
442 // is not - otherwise toolbar leaves a hole in the place it used to occupy
e9576ca5
SC
443}
444
37e2cb08 445bool wxToolBar::Realize()
e9576ca5 446{
eb22f2a6 447 if (m_tools.GetCount() == 0)
0b7a8cd3
GD
448 return FALSE;
449
bfe9ffbc
SC
450 int x = m_xMargin + kwxMacToolBarLeftMargin ;
451 int y = m_yMargin + kwxMacToolBarTopMargin ;
0b7a8cd3 452
7c551d95
SC
453 int tw, th;
454 GetSize(& tw, & th);
895f5af7
SC
455
456 int maxWidth = 0 ;
457 int maxHeight = 0 ;
458
bfe9ffbc
SC
459 int maxToolWidth = 0;
460 int maxToolHeight = 0;
461
462 // Find the maximum tool width and height
affd2611 463 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc
SC
464 while ( node )
465 {
466 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
467 wxSize sz = tool->GetSize() ;
468
469 if ( sz.x > maxToolWidth )
470 maxToolWidth = sz.x ;
471 if (sz.y> maxToolHeight)
472 maxToolHeight = sz.y;
473
474 node = node->GetNext();
475 }
476
214b9484 477 bool lastWasRadio = FALSE;
bfe9ffbc 478 node = m_tools.GetFirst();
0b7a8cd3 479 while (node)
7810c95b 480 {
eb22f2a6 481 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
bfe9ffbc 482 wxSize cursize = tool->GetSize() ;
0b7a8cd3 483
214b9484
RD
484 bool isRadio = FALSE;
485
486 if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO )
487 {
488 if ( !lastWasRadio )
489 {
490 if (tool->Toggle(true))
491 {
492 DoToggleTool(tool, true);
493 }
494 }
495 isRadio = TRUE;
496 }
497 else
498 {
499 isRadio = FALSE;
500 }
501 lastWasRadio = isRadio;
502
bfe9ffbc
SC
503 // for the moment we just do a single row/column alignement
504 if ( x + cursize.x > maxWidth )
505 maxWidth = x + cursize.x ;
506 if ( y + cursize.y > maxHeight )
507 maxHeight = y + cursize.y ;
0b7a8cd3 508
73fd9428
SC
509 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
510 {
511 int x1 = x + (maxToolWidth - cursize.x)/2 ;
512 tool->SetPosition( wxPoint( x1 , y ) ) ;
513 }
514 else
515 {
516 int y1 = y + (maxToolHeight - cursize.y)/2 ;
517 tool->SetPosition( wxPoint( x , y1 ) ) ;
518 }
bfe9ffbc
SC
519 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
520 {
521 y += cursize.y ;
abbcdf3f 522 y += kwxMacToolSpacing ;
0b7a8cd3
GD
523 }
524 else
525 {
bfe9ffbc 526 x += cursize.x ;
abbcdf3f 527 x += kwxMacToolSpacing ;
0b7a8cd3 528 }
bfe9ffbc 529
eb22f2a6 530 node = node->GetNext();
7810c95b 531 }
0b7a8cd3
GD
532
533 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 534 {
0b7a8cd3
GD
535 if ( m_maxRows == 0 )
536 {
537 // if not set yet, only one row
538 SetRows(1);
539 }
90d3f91a 540 m_minWidth = maxWidth;
0b7a8cd3 541 maxWidth = tw ;
0b7a8cd3 542 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
90d3f91a 543 m_minHeight = m_maxHeight = maxHeight ;
7810c95b 544 }
0b7a8cd3
GD
545 else
546 {
bfe9ffbc 547 if ( GetToolsCount() > 0 && m_maxRows == 0 )
0b7a8cd3
GD
548 {
549 // if not set yet, have one column
bfe9ffbc 550 SetRows(GetToolsCount());
0b7a8cd3 551 }
90d3f91a 552 m_minHeight = maxHeight;
0b7a8cd3 553 maxHeight = th ;
0b7a8cd3 554 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
90d3f91a 555 m_minWidth = m_maxWidth = maxWidth ;
0b7a8cd3
GD
556 }
557
facd6764 558 SetSize( maxWidth, maxHeight );
9f884528 559 InvalidateBestSize();
0b7a8cd3
GD
560
561 return TRUE;
e9576ca5
SC
562}
563
564void wxToolBar::SetToolBitmapSize(const wxSize& size)
565{
ee799df7 566 m_defaultWidth = size.x+kwxMacToolBorder; m_defaultHeight = size.y+kwxMacToolBorder;
e9576ca5
SC
567}
568
e9576ca5
SC
569// The button size is bigger than the bitmap size
570wxSize wxToolBar::GetToolSize() const
571{
ee799df7 572 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
573}
574
37e2cb08 575void wxToolBar::SetRows(int nRows)
e9576ca5 576{
37e2cb08 577 if ( nRows == m_maxRows )
e9576ca5 578 {
37e2cb08
SC
579 // avoid resizing the frame uselessly
580 return;
e9576ca5 581 }
37e2cb08
SC
582
583 m_maxRows = nRows;
e9576ca5
SC
584}
585
c257d44d
SC
586void wxToolBar::MacSuperChangedPosition()
587{
c257d44d 588 wxWindow::MacSuperChangedPosition() ;
bfe9ffbc 589 Realize() ;
c257d44d
SC
590}
591
37e2cb08 592wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 593{
affd2611 594 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc 595 while (node)
e044f600 596 {
bfe9ffbc
SC
597 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
598 wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
599 if ( r.Contains( wxPoint( x , y ) ) )
e044f600 600 {
bfe9ffbc 601 return tool;
e044f600 602 }
bfe9ffbc
SC
603
604 node = node->GetNext();
e044f600 605 }
37e2cb08
SC
606
607 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
608}
609
2f1ae414
SC
610wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
611{
e044f600
RR
612 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
613 if ( tool )
614 {
615 return tool->GetShortHelp() ;
616 }
427ff662 617 return wxEmptyString ;
2f1ae414
SC
618}
619
37e2cb08 620void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 621{
a2fe01c9 622 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
623}
624
37e2cb08 625void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 626{
e044f600 627 wxToolBarTool *tool = (wxToolBarTool *)t;
bfe9ffbc
SC
628 if ( tool->IsButton() )
629 {
73fd9428 630 tool->UpdateToggleImage( toggle ) ;
bfe9ffbc 631 }
37e2cb08 632}
7c551d95 633
37e2cb08
SC
634bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
635 wxToolBarToolBase *tool)
636{
bfe9ffbc 637 // nothing special to do here - we relayout in Realize() later
37e2cb08 638 tool->Attach(this);
9f884528 639 InvalidateBestSize();
7c551d95 640
37e2cb08
SC
641 return TRUE;
642}
e9576ca5 643
5115c51a 644void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 645{
5115c51a 646 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
647}
648
bfe9ffbc 649bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
37e2cb08 650{
affd2611 651 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
652 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
653 {
654 wxToolBarToolBase *tool2 = node->GetData();
655 if ( tool2 == tool )
656 {
657 // let node point to the next node in the list
658 node = node->GetNext();
659
660 break;
661 }
662 }
663
664 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
665
666 tool->Detach();
667
668 // and finally reposition all the controls after this one
669
670 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
671 {
672 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
673 wxPoint pt = tool2->GetPosition() ;
674
675 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
676 {
677 pt.y -= sz.y ;
678 }
679 else
680 {
681 pt.x -= sz.x ;
682 }
683 tool2->SetPosition( pt ) ;
684 }
685
9f884528 686 InvalidateBestSize();
5115c51a 687 return TRUE ;
37e2cb08 688}
2f1ae414
SC
689
690void wxToolBar::OnPaint(wxPaintEvent& event)
691{
e40298d5 692 wxPaintDC dc(this) ;
20b69855 693#if wxMAC_USE_CORE_GRAPHICS
ee799df7 694 // leave the background as it is (striped or metal)
20b69855 695#else
e40298d5 696 wxMacPortSetter helper(&dc) ;
facd6764
SC
697 int w, h ;
698 GetSize( &w , &h ) ;
e40298d5 699
1fd1922a 700 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
701 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
702/*
703 if( toolbarrect.left < 0 )
704 toolbarrect.left = 0 ;
705 if ( toolbarrect.top < 0 )
706 toolbarrect.top = 0 ;
707*/
01ffa8f7
SC
708 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
709 {
710 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
711 }
712 else
713 {
714#if TARGET_API_MAC_OSX
715#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
20b69855
SC
716 if ( UMAGetSystemVersion() >= 0x1030 )
717 {
718 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
719 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
720 CGContextRef cgContext ;
721 Rect bounds ;
722 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
723 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
724 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
725 CGContextScaleCTM( cgContext , 1 , -1 ) ;
785f5eaa 726
20b69855
SC
727 {
728 HIThemeBackgroundDrawInfo drawInfo ;
729 drawInfo.version = 0 ;
730 drawInfo.state = kThemeStateActive ;
731 drawInfo.kind = kThemeBackgroundMetal ;
732 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
733 }
734 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
735 }
736 else
737#endif
01ffa8f7 738 {
20b69855 739 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 740 }
01ffa8f7 741#endif
01ffa8f7
SC
742 }
743#endif
20b69855 744
facd6764 745 event.Skip() ;
2f1ae414 746}
895f5af7 747
519cb848
SC
748#endif // wxUSE_TOOLBAR
749