]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
added wxCSConv::IsOk() (patch 1637944)
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
3b6a1179 2// Name: src/mac/carbon/toolbar.cpp
e9576ca5 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
991f71dc 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#include "wx/wxprec.h"
519cb848
SC
13
14#if wxUSE_TOOLBAR
15
e56d2520 16#include "wx/toolbar.h"
e9576ca5 17
4e3e485b
WS
18#ifndef WX_PRECOMP
19 #include "wx/wx.h"
20#endif
21
83f787ba 22#include "wx/app.h"
d497dca4 23#include "wx/mac/uma.h"
bfe9ffbc 24#include "wx/geometry.h"
ee799df7 25
991f71dc 26
ee799df7 27#ifdef __WXMAC_OSX__
3b6a1179
DS
28const short kwxMacToolBarToolDefaultWidth = 16;
29const short kwxMacToolBarToolDefaultHeight = 16;
30const short kwxMacToolBarTopMargin = 4;
31const short kwxMacToolBarLeftMargin = 4;
32const short kwxMacToolBorder = 0;
33const short kwxMacToolSpacing = 6;
ee799df7 34#else
3b6a1179
DS
35const short kwxMacToolBarToolDefaultWidth = 24;
36const short kwxMacToolBarToolDefaultHeight = 22;
37const short kwxMacToolBarTopMargin = 2;
38const short kwxMacToolBarLeftMargin = 2;
39const short kwxMacToolBorder = 4;
40const short kwxMacToolSpacing = 0;
ee799df7
SC
41#endif
42
991f71dc
DS
43
44IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
45
46BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
47 EVT_PAINT( wxToolBar::OnPaint )
48END_EVENT_TABLE()
49
50
e56d2520
SC
51#pragma mark -
52#pragma mark Tool Implementation
53
54
37e2cb08
SC
55// ----------------------------------------------------------------------------
56// private classes
57// ----------------------------------------------------------------------------
58
e56d2520
SC
59// We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
60
37e2cb08
SC
61class wxToolBarTool : public wxToolBarToolBase
62{
63public:
3025abca
DS
64 wxToolBarTool(
65 wxToolBar *tbar,
66 int id,
67 const wxString& label,
68 const wxBitmap& bmpNormal,
69 const wxBitmap& bmpDisabled,
70 wxItemKind kind,
71 wxObject *clientData,
72 const wxString& shortHelp,
73 const wxString& longHelp );
f3a65c3e 74
37e2cb08
SC
75 wxToolBarTool(wxToolBar *tbar, wxControl *control)
76 : wxToolBarToolBase(tbar, control)
77 {
3b6a1179 78 Init();
e56d2520 79 if (control != NULL)
3b6a1179 80 SetControlHandle( (ControlRef) control->GetHandle() );
37e2cb08 81 }
f3a65c3e 82
d3c7fc99 83 virtual ~wxToolBarTool()
bfe9ffbc 84 {
3b6a1179 85 ClearControl();
bfe9ffbc 86 }
f3a65c3e
VZ
87
88 WXWidget GetControlHandle()
89 {
3b6a1179 90 return (WXWidget) m_controlHandle;
e56d2520 91 }
f3a65c3e
VZ
92
93 void SetControlHandle( ControlRef handle )
94 {
3b6a1179 95 m_controlHandle = handle;
e56d2520 96 }
37e2cb08 97
3b6a1179 98 void SetPosition( const wxPoint& position );
f3a65c3e
VZ
99
100 void ClearControl()
101 {
3b6a1179 102 m_control = NULL;
8c07d8b3
SC
103 if ( m_controlHandle )
104 {
9d5ccdd3
SC
105 if ( !IsControl() )
106 DisposeControl( m_controlHandle );
107 else
108 {
109 // the embedded control is not under the responsibility of the tool
110 }
8c07d8b3
SC
111 m_controlHandle = NULL ;
112 }
991f71dc 113
e56d2520 114#if wxMAC_USE_NATIVE_TOOLBAR
507d5748
SC
115 if ( m_toolbarItemRef )
116 {
117 CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ;
118 wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
83f787ba
SC
119 wxTheApp->MacAddToAutorelease(m_toolbarItemRef);
120 CFRelease(m_toolbarItemRef);
507d5748
SC
121 m_toolbarItemRef = NULL;
122 }
f3a65c3e 123#endif
e56d2520 124 }
f3a65c3e 125
bfe9ffbc
SC
126 wxSize GetSize() const
127 {
3025abca
DS
128 wxSize curSize;
129
bfe9ffbc
SC
130 if ( IsControl() )
131 {
3025abca 132 curSize = GetControl()->GetSize();
bfe9ffbc
SC
133 }
134 else if ( IsButton() )
135 {
3025abca 136 curSize = GetToolBar()->GetToolSize();
bfe9ffbc
SC
137 }
138 else
139 {
abbcdf3f 140 // separator size
3025abca 141 curSize = GetToolBar()->GetToolSize();
5a904a32 142 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
3025abca 143 curSize.y /= 4;
5a904a32 144 else
3025abca 145 curSize.x /= 4;
bfe9ffbc 146 }
3025abca
DS
147
148 return curSize;
bfe9ffbc 149 }
991f71dc 150
bfe9ffbc
SC
151 wxPoint GetPosition() const
152 {
3b6a1179 153 return wxPoint( m_x, m_y );
f3a65c3e 154 }
991f71dc 155
3b6a1179 156 bool DoEnable( bool enable );
f3a65c3e 157
3b6a1179 158 void UpdateToggleImage( bool toggle );
f3a65c3e
VZ
159
160#if wxMAC_USE_NATIVE_TOOLBAR
161 void SetToolbarItemRef( HIToolbarItemRef ref )
162 {
e56d2520 163 if ( m_controlHandle )
3b6a1179 164 HideControl( m_controlHandle );
e56d2520 165 if ( m_toolbarItemRef )
3b6a1179 166 CFRelease( m_toolbarItemRef );
991f71dc 167
3b6a1179 168 m_toolbarItemRef = ref;
e56d2520
SC
169 if ( m_toolbarItemRef )
170 {
171 HIToolbarItemSetHelpText(
991f71dc 172 m_toolbarItemRef,
3b6a1179
DS
173 wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ),
174 wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) );
e56d2520
SC
175 }
176 }
991f71dc 177
f3a65c3e
VZ
178 HIToolbarItemRef GetToolbarItemRef() const
179 {
3b6a1179 180 return m_toolbarItemRef;
e56d2520 181 }
df7998fc
VZ
182
183 void SetIndex( CFIndex idx )
2c1dbc95 184 {
3b6a1179 185 m_index = idx;
2c1dbc95
SC
186 }
187
df7998fc 188 CFIndex GetIndex() const
2c1dbc95 189 {
3b6a1179 190 return m_index;
2c1dbc95 191 }
e56d2520 192#endif
5d0bf05a 193
3b6a1179 194private:
f3a65c3e 195 void Init()
bfe9ffbc 196 {
3b6a1179 197 m_controlHandle = NULL;
991f71dc 198
e56d2520 199#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179
DS
200 m_toolbarItemRef = NULL;
201 m_index = -1;
e56d2520 202#endif
bfe9ffbc 203 }
991f71dc 204
3b6a1179 205 ControlRef m_controlHandle;
991f71dc
DS
206 wxCoord m_x;
207 wxCoord m_y;
208
e56d2520 209#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179 210 HIToolbarItemRef m_toolbarItemRef;
2c1dbc95 211 // position in its toolbar, -1 means not inserted
3b6a1179 212 CFIndex m_index;
e56d2520 213#endif
37e2cb08
SC
214};
215
facd6764
SC
216static const EventTypeSpec eventList[] =
217{
3b6a1179 218 { kEventClassControl, kEventControlHit },
73fd9428 219#ifdef __WXMAC_OSX__
3b6a1179 220 { kEventClassControl, kEventControlHitTest },
73fd9428 221#endif
3b6a1179 222};
facd6764 223
3b6a1179 224static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
facd6764 225{
3b6a1179
DS
226 OSStatus result = eventNotHandledErr;
227 ControlRef controlRef;
228 wxMacCarbonEvent cEvent( event );
facd6764 229
3b6a1179 230 cEvent.GetParameter( kEventParamDirectObject, &controlRef );
facd6764 231
991f71dc 232 switch ( GetEventKind( event ) )
facd6764 233 {
3b6a1179 234 case kEventControlHit:
facd6764 235 {
3b6a1179
DS
236 wxToolBarTool *tbartool = (wxToolBarTool*)data;
237 wxToolBar *tbar = tbartool != NULL ? (wxToolBar*) (tbartool->GetToolBar()) : NULL;
991f71dc 238 if ((tbartool != NULL) && tbartool->CanBeToggled())
facd6764 239 {
e56d2520 240 bool shouldToggle;
991f71dc 241
64f553a4 242#ifdef __WXMAC_OSX__
e56d2520 243 shouldToggle = !tbartool->IsToggled();
64f553a4 244#else
3025abca 245 shouldToggle = (GetControl32BitValue( (ControlRef)(tbartool->GetControlHandle()) ) != 0);
64f553a4 246#endif
991f71dc 247
e56d2520 248 tbar->ToggleTool( tbartool->GetId(), shouldToggle );
facd6764 249 }
991f71dc 250
e56d2520
SC
251 if (tbartool != NULL)
252 tbar->OnLeftClick( tbartool->GetId(), tbartool->IsToggled() );
f3a65c3e 253 result = noErr;
facd6764 254 }
3b6a1179 255 break;
5d0bf05a 256
73fd9428 257#ifdef __WXMAC_OSX__
3b6a1179 258 case kEventControlHitTest:
73fd9428 259 {
3b6a1179
DS
260 HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation);
261 HIRect rect;
262 HIViewGetBounds( controlRef, &rect );
263
264 ControlPartCode pc = kControlNoPart;
265 if ( CGRectContainsPoint( rect, pt ) )
266 pc = kControlIconPart;
267 cEvent.SetParameter( kEventParamControlPart, typeControlPartCode, pc );
268 result = noErr;
73fd9428 269 }
3b6a1179 270 break;
73fd9428 271#endif
5d0bf05a 272
3b6a1179
DS
273 default:
274 break;
facd6764 275 }
991f71dc 276
3b6a1179 277 return result;
facd6764
SC
278}
279
3b6a1179 280static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
facd6764 281{
3b6a1179 282 OSStatus result = eventNotHandledErr;
facd6764
SC
283
284 switch ( GetEventClass( event ) )
285 {
3b6a1179
DS
286 case kEventClassControl:
287 result = wxMacToolBarToolControlEventHandler( handler, event, data );
288 break;
5d0bf05a 289
3b6a1179
DS
290 default:
291 break;
facd6764 292 }
991f71dc 293
3b6a1179 294 return result;
facd6764
SC
295}
296
297DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
298
e56d2520
SC
299#if wxMAC_USE_NATIVE_TOOLBAR
300
e56d2520
SC
301static const EventTypeSpec toolBarEventList[] =
302{
3b6a1179
DS
303 { kEventClassToolbarItem, kEventToolbarItemPerformAction },
304};
e56d2520 305
3b6a1179 306static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
e56d2520 307{
3b6a1179 308 OSStatus result = eventNotHandledErr;
f3a65c3e 309
991f71dc 310 switch ( GetEventKind( event ) )
e56d2520 311 {
3b6a1179 312 case kEventToolbarItemPerformAction:
e56d2520 313 {
3b6a1179 314 wxToolBarTool* tbartool = (wxToolBarTool*) data;
e56d2520
SC
315 if ( tbartool != NULL )
316 {
991f71dc
DS
317 wxToolBar *tbar = (wxToolBar*)(tbartool->GetToolBar());
318 int toolID = tbartool->GetId();
319
e56d2520
SC
320 if ( tbartool->CanBeToggled() )
321 {
3025abca 322 if ( tbar != NULL )
2c1dbc95 323 tbar->ToggleTool(toolID, !tbartool->IsToggled() );
e56d2520 324 }
991f71dc 325
3025abca 326 if ( tbar != NULL )
3b6a1179 327 tbar->OnLeftClick( toolID, tbartool->IsToggled() );
f3a65c3e 328 result = noErr;
e56d2520
SC
329 }
330 }
3b6a1179 331 break;
5d0bf05a 332
3b6a1179
DS
333 default:
334 break;
e56d2520 335 }
991f71dc 336
3b6a1179 337 return result;
e56d2520
SC
338}
339
340static pascal OSStatus wxMacToolBarEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
341{
3b6a1179 342 OSStatus result = eventNotHandledErr;
991f71dc
DS
343
344 switch ( GetEventClass( event ) )
e56d2520 345 {
3b6a1179
DS
346 case kEventClassToolbarItem:
347 result = wxMacToolBarCommandEventHandler( handler, event, data );
348 break;
5d0bf05a 349
3b6a1179
DS
350 default:
351 break;
e56d2520 352 }
991f71dc 353
3b6a1179 354 return result;
e56d2520
SC
355}
356
357DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler )
358
359#endif
360
3b6a1179 361bool wxToolBarTool::DoEnable( bool enable )
a2fe01c9
SC
362{
363 if ( IsControl() )
364 {
3b6a1179 365 GetControl()->Enable( enable );
a2fe01c9
SC
366 }
367 else if ( IsButton() )
368 {
f3a65c3e 369#if wxMAC_USE_NATIVE_TOOLBAR
3025abca 370 if ( m_toolbarItemRef != NULL )
3b6a1179 371 HIToolbarItemSetEnabled( m_toolbarItemRef, enable );
e56d2520
SC
372#endif
373
3025abca 374 if ( m_controlHandle != NULL )
e56d2520 375 {
a2fe01c9 376#if TARGET_API_MAC_OSX
e56d2520 377 if ( enable )
3b6a1179 378 EnableControl( m_controlHandle );
e56d2520 379 else
3b6a1179 380 DisableControl( m_controlHandle );
a2fe01c9 381#else
e56d2520 382 if ( enable )
3b6a1179 383 ActivateControl( m_controlHandle );
e56d2520 384 else
3b6a1179 385 DeactivateControl( m_controlHandle );
a2fe01c9 386#endif
e56d2520 387 }
a2fe01c9 388 }
991f71dc 389
3b6a1179 390 return true;
a2fe01c9 391}
bfe9ffbc 392
3b6a1179 393void wxToolBarTool::SetPosition( const wxPoint& position )
bfe9ffbc
SC
394{
395 m_x = position.x;
396 m_y = position.y;
397
3b6a1179
DS
398 int mac_x = position.x;
399 int mac_y = position.y;
789ae0cf 400
789ae0cf
SC
401 if ( IsButton() )
402 {
3b6a1179
DS
403 Rect contrlRect;
404 GetControlBounds( m_controlHandle, &contrlRect );
405 int former_mac_x = contrlRect.left;
406 int former_mac_y = contrlRect.top;
407 GetToolBar()->GetToolSize();
f3a65c3e 408
bfe9ffbc
SC
409 if ( mac_x != former_mac_x || mac_y != former_mac_y )
410 {
3b6a1179 411 UMAMoveControl( m_controlHandle, mac_x, mac_y );
bfe9ffbc
SC
412 }
413 }
414 else if ( IsControl() )
415 {
9d5ccdd3
SC
416 // embedded native controls are moved by the OS
417#if wxMAC_USE_NATIVE_TOOLBAR
418 if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false )
419#endif
420 {
421 GetControl()->Move( position );
422 }
bfe9ffbc 423 }
abbcdf3f
SC
424 else
425 {
f3a65c3e 426 // separator
abbcdf3f 427#ifdef __WXMAC_OSX__
3b6a1179
DS
428 Rect contrlRect;
429 GetControlBounds( m_controlHandle, &contrlRect );
430 int former_mac_x = contrlRect.left;
431 int former_mac_y = contrlRect.top;
f3a65c3e 432
abbcdf3f 433 if ( mac_x != former_mac_x || mac_y != former_mac_y )
3b6a1179 434 UMAMoveControl( m_controlHandle, mac_x, mac_y );
abbcdf3f
SC
435#endif
436 }
bfe9ffbc
SC
437}
438
f3a65c3e 439void wxToolBarTool::UpdateToggleImage( bool toggle )
73fd9428
SC
440{
441#ifdef __WXMAC_OSX__
442 if ( toggle )
443 {
3b6a1179
DS
444 int w = m_bmpNormal.GetWidth();
445 int h = m_bmpNormal.GetHeight();
446 wxBitmap bmp( w, h );
447 wxMemoryDC dc;
448
449 dc.SelectObject( bmp );
ce9da810
RD
450 dc.SetPen( wxPen(*wxBLACK) );
451 dc.SetBrush( wxBrush( *wxLIGHT_GREY ));
3b6a1179
DS
452 dc.DrawRectangle( 0, 0, w, h );
453 dc.DrawBitmap( m_bmpNormal, 0, 0, true );
454 dc.SelectObject( wxNullBitmap );
455 ControlButtonContentInfo info;
456 wxMacCreateBitmapButton( &info, bmp );
991f71dc 457 SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
ce9da810
RD
458#if wxMAC_USE_NATIVE_TOOLBAR
459 if (m_toolbarItemRef != NULL)
460 {
461 HIToolbarItemSetIconRef( m_toolbarItemRef, info.u.iconRef );
462 }
463#endif
3b6a1179 464 wxMacReleaseBitmapButton( &info );
73fd9428
SC
465 }
466 else
467 {
3b6a1179
DS
468 ControlButtonContentInfo info;
469 wxMacCreateBitmapButton( &info, m_bmpNormal );
3025abca 470 SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
ce9da810
RD
471#if wxMAC_USE_NATIVE_TOOLBAR
472 if (m_toolbarItemRef != NULL)
473 {
474 HIToolbarItemSetIconRef( m_toolbarItemRef, info.u.iconRef );
475 }
476#endif
3b6a1179 477 wxMacReleaseBitmapButton( &info );
73fd9428
SC
478 }
479
3b6a1179
DS
480 IconTransformType transform = toggle ? kTransformSelected : kTransformNone;
481 SetControlData(
482 m_controlHandle, 0, kControlIconTransformTag,
3025abca 483 sizeof(transform), (Ptr)&transform );
3b6a1179 484 HIViewSetNeedsDisplay( m_controlHandle, true );
73fd9428
SC
485
486#else
3b6a1179 487 ::SetControl32BitValue( m_controlHandle, toggle );
73fd9428
SC
488#endif
489}
490
3b6a1179
DS
491wxToolBarTool::wxToolBarTool(
492 wxToolBar *tbar,
493 int id,
494 const wxString& label,
495 const wxBitmap& bmpNormal,
496 const wxBitmap& bmpDisabled,
497 wxItemKind kind,
498 wxObject *clientData,
499 const wxString& shortHelp,
500 const wxString& longHelp )
501 :
502 wxToolBarToolBase(
503 tbar, id, label, bmpNormal, bmpDisabled, kind,
504 clientData, shortHelp, longHelp )
bfe9ffbc 505{
f4e0be4f 506 Init();
bfe9ffbc
SC
507}
508
e56d2520
SC
509#pragma mark -
510#pragma mark Toolbar Implementation
2f1ae414 511
3b6a1179
DS
512wxToolBarToolBase *wxToolBar::CreateTool(
513 int id,
514 const wxString& label,
515 const wxBitmap& bmpNormal,
516 const wxBitmap& bmpDisabled,
517 wxItemKind kind,
518 wxObject *clientData,
519 const wxString& shortHelp,
520 const wxString& longHelp )
37e2cb08 521{
3b6a1179
DS
522 return new wxToolBarTool(
523 this, id, label, bmpNormal, bmpDisabled, kind,
524 clientData, shortHelp, longHelp );
37e2cb08
SC
525}
526
3b6a1179 527wxToolBarToolBase * wxToolBar::CreateTool( wxControl *control )
37e2cb08 528{
3025abca 529 return new wxToolBarTool( this, control );
37e2cb08
SC
530}
531
37e2cb08 532void wxToolBar::Init()
e9576ca5 533{
e40298d5
JS
534 m_maxWidth = -1;
535 m_maxHeight = -1;
536 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
537 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
991f71dc 538
e56d2520 539#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179
DS
540 m_macHIToolbarRef = NULL;
541 m_macUsesNativeToolbar = false;
e56d2520 542#endif
e9576ca5
SC
543}
544
0ac091ae 545#define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
6d4835dc
SC
546
547const EventTypeSpec kEvents[] =
548{
0ac091ae
RD
549 { kEventClassHIObject, kEventHIObjectConstruct },
550 { kEventClassHIObject, kEventHIObjectInitialize },
551 { kEventClassHIObject, kEventHIObjectDestruct },
552
553 { kEventClassToolbarItem, kEventToolbarItemCreateCustomView }
6d4835dc
SC
554};
555
556const EventTypeSpec kViewEvents[] =
557{
558 { kEventClassControl, kEventControlGetSizeConstraints }
559};
560
561struct ControlToolbarItem
562{
563 HIToolbarItemRef toolbarItem;
564 HIViewRef viewRef;
565 wxSize lastValidSize ;
566};
567
568static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
569{
0ac091ae
RD
570 OSStatus result = eventNotHandledErr;
571 ControlToolbarItem* object = (ControlToolbarItem*)inUserData;
572
573 switch ( GetEventClass( inEvent ) )
574 {
575 case kEventClassHIObject:
576 switch ( GetEventKind( inEvent ) )
577 {
578 case kEventHIObjectConstruct:
579 {
580 HIObjectRef toolbarItem;
581 ControlToolbarItem* item;
582
583 GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL,
6d4835dc 584 sizeof( HIObjectRef ), NULL, &toolbarItem );
0ac091ae 585
6d4835dc
SC
586 item = (ControlToolbarItem*) malloc(sizeof(ControlToolbarItem)) ;
587 item->toolbarItem = toolbarItem ;
588 item->viewRef = NULL ;
589
0ac091ae 590 SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( void * ), &item );
6d4835dc
SC
591
592 result = noErr ;
0ac091ae
RD
593 }
594 break;
6d4835dc
SC
595
596 case kEventHIObjectInitialize:
597 result = CallNextEventHandler( inCallRef, inEvent );
0ac091ae 598 if ( result == noErr )
6d4835dc
SC
599 {
600 CFDataRef data;
601 GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL,
602 sizeof( CFTypeRef ), NULL, &data );
0ac091ae 603
6d4835dc
SC
604 HIViewRef viewRef ;
605
606 wxASSERT_MSG( CFDataGetLength( data ) == sizeof( viewRef ) , wxT("Illegal Data passed") ) ;
607 memcpy( &viewRef , CFDataGetBytePtr( data ) , sizeof( viewRef ) ) ;
608
609 object->viewRef = (HIViewRef) viewRef ;
610
0ac091ae
RD
611 result = noErr ;
612 }
6d4835dc
SC
613 break;
614
0ac091ae 615 case kEventHIObjectDestruct:
507d5748
SC
616 {
617 // we've increased the ref count when creating this, so we decrease manually again in case
618 // it was never really installed and deinstalled
619 HIViewRef viewRef = object->viewRef ;
83f787ba 620 if( viewRef && IsValidControlHandle( viewRef) )
507d5748 621 {
83f787ba
SC
622 CFIndex count = CFGetRetainCount( viewRef ) ;
623 if ( count >= 1 )
624 CFRelease( viewRef ) ;
507d5748
SC
625 }
626 free( object ) ;
627 result = noErr;
628 }
0ac091ae
RD
629 break;
630 }
631 break;
632
633 case kEventClassToolbarItem:
634 switch ( GetEventKind( inEvent ) )
635 {
636 case kEventToolbarItemCreateCustomView:
637 {
6d4835dc
SC
638 HIViewRef viewRef = object->viewRef ;
639
640 HIViewRemoveFromSuperview( viewRef ) ;
641 HIViewSetVisible(viewRef, true) ;
642 InstallEventHandler( GetControlEventTarget( viewRef ), ControlToolbarItemHandler,
643 GetEventTypeCount( kViewEvents ), kViewEvents, object, NULL );
644
645 result = SetEventParameter( inEvent, kEventParamControlRef, typeControlRef, sizeof( HIViewRef ), &viewRef );
0ac091ae
RD
646 }
647 break;
648 }
649 break;
650
651 case kEventClassControl:
652 switch ( GetEventKind( inEvent ) )
653 {
654 case kEventControlGetSizeConstraints:
655 {
6d4835dc
SC
656 wxWindow* wxwindow = wxFindControlFromMacControl(object->viewRef ) ;
657 if ( wxwindow )
658 {
659 wxSize sz = wxwindow->GetSize() ;
da14a87d
SC
660 sz.x -= wxwindow->MacGetLeftBorderSize() + wxwindow->MacGetRightBorderSize();
661 sz.y -= wxwindow->MacGetTopBorderSize() + wxwindow->MacGetBottomBorderSize();
6d4835dc
SC
662 // during toolbar layout the native window sometimes gets negative sizes
663 // so we always keep the last valid size here, to make sure we survive the
664 // shuffle ...
665 if ( sz.x > 0 && sz.y > 0 )
666 object->lastValidSize = sz ;
667 else
668 sz = object->lastValidSize ;
669
670 HISize min, max;
671 min.width = max.width = sz.x ;
672 min.height = max.height = sz.y ;
673
674 result = SetEventParameter( inEvent, kEventParamMinimumSize, typeHISize,
675 sizeof( HISize ), &min );
676
677 result = SetEventParameter( inEvent, kEventParamMaximumSize, typeHISize,
678 sizeof( HISize ), &max );
679 result = noErr ;
680 }
0ac091ae
RD
681 }
682 break;
683 }
684 break;
685 }
686
687 return result;
6d4835dc
SC
688}
689
690void RegisterControlToolbarItemClass()
691{
0ac091ae
RD
692 static bool sRegistered;
693
694 if ( !sRegistered )
695 {
696 HIObjectRegisterSubclass( kControlToolbarItemClassID, kHIToolbarItemClassID, 0,
697 ControlToolbarItemHandler, GetEventTypeCount( kEvents ), kEvents, 0, NULL );
698
699 sRegistered = true;
700 }
6d4835dc
SC
701}
702
703HIToolbarItemRef CreateControlToolbarItem(CFStringRef inIdentifier, CFTypeRef inConfigData)
704{
0ac091ae
RD
705 RegisterControlToolbarItemClass();
706
707 OSStatus err;
708 EventRef event;
709 UInt32 options = kHIToolbarItemAllowDuplicates;
710 HIToolbarItemRef result = NULL;
711
712 err = CreateEvent( NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), 0, &event );
713 require_noerr( err, CantCreateEvent );
714
715 SetEventParameter( event, kEventParamAttributes, typeUInt32, sizeof( UInt32 ), &options );
716 SetEventParameter( event, kEventParamToolbarItemIdentifier, typeCFStringRef, sizeof( CFStringRef ), &inIdentifier );
717
718 if ( inConfigData )
719 SetEventParameter( event, kEventParamToolbarItemConfigData, typeCFTypeRef, sizeof( CFTypeRef ), &inConfigData );
720
721 err = HIObjectCreate( kControlToolbarItemClassID, event, (HIObjectRef*)&result );
722 check_noerr( err );
6d4835dc 723
0ac091ae
RD
724 ReleaseEvent( event );
725CantCreateEvent :
726 return result ;
6d4835dc
SC
727}
728
716d0327 729#if wxMAC_USE_NATIVE_TOOLBAR
6d4835dc
SC
730static const EventTypeSpec kToolbarEvents[] =
731{
0ac091ae
RD
732 { kEventClassToolbar, kEventToolbarGetDefaultIdentifiers },
733 { kEventClassToolbar, kEventToolbarGetAllowedIdentifiers },
734 { kEventClassToolbar, kEventToolbarCreateItemWithIdentifier },
6d4835dc
SC
735};
736
737static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
738{
0ac091ae 739 OSStatus result = eventNotHandledErr;
9d5ccdd3
SC
740 // Not yet needed
741 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
0ac091ae 742 CFMutableArrayRef array;
6d4835dc 743
0ac091ae
RD
744 switch ( GetEventKind( inEvent ) )
745 {
746 case kEventToolbarGetDefaultIdentifiers:
6d4835dc
SC
747 {
748 GetEventParameter( inEvent, kEventParamMutableArray, typeCFMutableArrayRef, NULL,
0ac091ae 749 sizeof( CFMutableArrayRef ), NULL, &array );
6d4835dc
SC
750 // not implemented yet
751 // GetToolbarDefaultItems( array );
752 result = noErr;
753 }
0ac091ae
RD
754 break;
755
756 case kEventToolbarGetAllowedIdentifiers:
6d4835dc
SC
757 {
758 GetEventParameter( inEvent, kEventParamMutableArray, typeCFMutableArrayRef, NULL,
0ac091ae 759 sizeof( CFMutableArrayRef ), NULL, &array );
6d4835dc
SC
760 // not implemented yet
761 // GetToolbarAllowedItems( array );
762 result = noErr;
763 }
0ac091ae
RD
764 break;
765 case kEventToolbarCreateItemWithIdentifier:
766 {
767 HIToolbarItemRef item = NULL;
768 CFTypeRef data = NULL;
6d4835dc 769 CFStringRef identifier = NULL ;
0ac091ae
RD
770
771 GetEventParameter( inEvent, kEventParamToolbarItemIdentifier, typeCFStringRef, NULL,
772 sizeof( CFStringRef ), NULL, &identifier );
773
774 GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL,
775 sizeof( CFTypeRef ), NULL, &data );
776
6d4835dc
SC
777 if ( CFStringCompare( kControlToolbarItemClassID, identifier, kCFCompareBackwards ) == kCFCompareEqualTo )
778 {
779 item = CreateControlToolbarItem( kControlToolbarItemClassID, data );
780 if ( item )
781 {
782 SetEventParameter( inEvent, kEventParamToolbarItem, typeHIToolbarItemRef,
783 sizeof( HIToolbarItemRef ), &item );
784 result = noErr;
785 }
0ac091ae 786 }
6d4835dc 787
0ac091ae
RD
788 }
789 break;
6d4835dc
SC
790 }
791 return result ;
792}
716d0327 793#endif // wxMAC_USE_NATIVE_TOOLBAR
6d4835dc 794
e56d2520
SC
795// also for the toolbar we have the dual implementation:
796// only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
6d4835dc 797
3b6a1179
DS
798bool wxToolBar::Create(
799 wxWindow *parent,
991f71dc
DS
800 wxWindowID id,
801 const wxPoint& pos,
802 const wxSize& size,
803 long style,
3b6a1179 804 const wxString& name )
5d0bf05a 805{
3b6a1179
DS
806 if ( !wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
807 return false;
e56d2520 808
d408730c
VZ
809 FixupStyle();
810
991f71dc 811 OSStatus err = noErr;
e56d2520
SC
812
813#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179
DS
814 wxString labelStr = wxString::Format( wxT("%xd"), (int)this );
815 err = HIToolbarCreate(
816 wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ), 0,
817 (HIToolbarRef*) &m_macHIToolbarRef );
e56d2520
SC
818
819 if (m_macHIToolbarRef != NULL)
f3a65c3e 820 {
0ac091ae
RD
821 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler,
822 GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL );
6d4835dc 823
3b6a1179
DS
824 HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
825 HIToolbarDisplaySize displaySize = kHIToolbarDisplaySizeSmall;
e56d2520
SC
826
827 if ( style & wxTB_NOICONS )
3b6a1179 828 mode = kHIToolbarDisplayModeLabelOnly;
e56d2520 829 else if ( style & wxTB_TEXT )
3b6a1179 830 mode = kHIToolbarDisplayModeIconAndLabel;
e56d2520 831 else
3b6a1179 832 mode = kHIToolbarDisplayModeIconOnly;
e56d2520 833
3b6a1179
DS
834 HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
835 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
e56d2520
SC
836 }
837#endif
838
991f71dc 839 return (err == noErr);
e9576ca5
SC
840}
841
842wxToolBar::~wxToolBar()
f3a65c3e 843{
e56d2520 844#if wxMAC_USE_NATIVE_TOOLBAR
3025abca 845 if (m_macHIToolbarRef != NULL)
e56d2520
SC
846 {
847 // if this is the installed toolbar, then deinstall it
848 if (m_macUsesNativeToolbar)
849 MacInstallNativeToolbar( false );
850
507d5748
SC
851 CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ;
852 wxASSERT_MSG( count == 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
853
3025abca 854 CFRelease( (HIToolbarRef)m_macHIToolbarRef );
e56d2520
SC
855 m_macHIToolbarRef = NULL;
856 }
857#endif
858}
859
e56d2520
SC
860bool wxToolBar::Show( bool show )
861{
e56d2520 862 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
3025abca 863 bool bResult = (tlw != NULL);
f3a65c3e 864
e56d2520
SC
865 if (bResult)
866 {
867#if wxMAC_USE_NATIVE_TOOLBAR
f3a65c3e 868 bool ownToolbarInstalled = false;
e56d2520
SC
869 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
870 if (ownToolbarInstalled)
871 {
3025abca 872 bResult = (IsWindowToolbarVisible( tlw ) != show);
a749a99f
SC
873 if ( bResult )
874 ShowHideWindowToolbar( tlw, show, false );
e56d2520
SC
875 }
876 else
e56d2520 877 bResult = wxToolBarBase::Show( show );
3025abca
DS
878#else
879
880 bResult = wxToolBarBase::Show( show );
881#endif
e56d2520 882 }
f3a65c3e 883
e56d2520
SC
884 return bResult;
885}
886
887bool wxToolBar::IsShown() const
888{
889 bool bResult;
890
891#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179 892 bool ownToolbarInstalled;
3025abca 893
e56d2520
SC
894 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
895 if (ownToolbarInstalled)
a749a99f
SC
896 {
897 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
3b6a1179 898 bResult = IsWindowToolbarVisible( tlw );
a749a99f 899 }
e56d2520 900 else
e56d2520 901 bResult = wxToolBarBase::IsShown();
3025abca
DS
902#else
903
904 bResult = wxToolBarBase::IsShown();
905#endif
f3a65c3e 906
e56d2520
SC
907 return bResult;
908}
909
e56d2520
SC
910void wxToolBar::DoGetSize( int *width, int *height ) const
911{
912#if wxMAC_USE_NATIVE_TOOLBAR
913 Rect boundsR;
914 bool ownToolbarInstalled;
f3a65c3e 915
e56d2520
SC
916 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
917 if ( ownToolbarInstalled )
918 {
991f71dc 919 // TODO: is this really a control ?
e56d2520
SC
920 GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR );
921 if ( width != NULL )
922 *width = boundsR.right - boundsR.left;
923 if ( height != NULL )
924 *height = boundsR.bottom - boundsR.top;
925 }
926 else
e56d2520 927 wxToolBarBase::DoGetSize( width, height );
3025abca
DS
928
929#else
930 wxToolBarBase::DoGetSize( width, height );
931#endif
e9576ca5
SC
932}
933
b13095df
SC
934wxSize wxToolBar::DoGetBestSize() const
935{
3b6a1179 936 int width, height;
991f71dc 937
3b6a1179 938 DoGetSize( &width, &height );
991f71dc 939
3b6a1179 940 return wxSize( width, height );
b13095df
SC
941}
942
f3a65c3e 943void wxToolBar::SetWindowStyleFlag( long style )
e56d2520
SC
944{
945 wxToolBarBase::SetWindowStyleFlag( style );
991f71dc 946
e56d2520
SC
947#if wxMAC_USE_NATIVE_TOOLBAR
948 if (m_macHIToolbarRef != NULL)
949 {
950 HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
951
952 if ( style & wxTB_NOICONS )
953 mode = kHIToolbarDisplayModeLabelOnly;
954 else if ( style & wxTB_TEXT )
955 mode = kHIToolbarDisplayModeIconAndLabel;
956 else
957 mode = kHIToolbarDisplayModeIconOnly;
f3a65c3e 958
e56d2520
SC
959 HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
960 }
961#endif
962}
963
964#if wxMAC_USE_NATIVE_TOOLBAR
965bool wxToolBar::MacWantsNativeToolbar()
966{
967 return m_macUsesNativeToolbar;
968}
969
970bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const
971{
972 bool bResultV = false;
973
974 if (ownToolbarInstalled != NULL)
975 *ownToolbarInstalled = false;
976
977 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
978 if (tlw != NULL)
979 {
980 HIToolbarRef curToolbarRef = NULL;
981 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
3025abca 982 bResultV = ((err == noErr) && (curToolbarRef != NULL));
e56d2520
SC
983 if (bResultV && (ownToolbarInstalled != NULL))
984 *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
985 }
986
987 return bResultV;
988}
989
f3a65c3e 990bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
e56d2520 991{
df7998fc 992 bool bResult = false;
e56d2520 993
e56d2520
SC
994 if (usesNative && (m_macHIToolbarRef == NULL))
995 return bResult;
f3a65c3e 996
e56d2520
SC
997 if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
998 return bResult;
f3a65c3e 999
3025abca
DS
1000 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
1001 if (tlw == NULL)
1002 return bResult;
1003
e56d2520
SC
1004 // check the existing toolbar
1005 HIToolbarRef curToolbarRef = NULL;
1006 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
991f71dc 1007 if (err != noErr)
e56d2520
SC
1008 curToolbarRef = NULL;
1009
1010 m_macUsesNativeToolbar = usesNative;
1011
1012 if (m_macUsesNativeToolbar)
1013 {
1014 // only install toolbar if there isn't one installed already
1015 if (curToolbarRef == NULL)
1016 {
1017 bResult = true;
1018
1019 SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef );
1020 ShowHideWindowToolbar( tlw, true, false );
1021 ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
1022 SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
f3a65c3e 1023
3b6a1179 1024 Rect r = { 0, 0, 0, 0 };
e56d2520 1025 m_peer->SetRect( &r );
e56d2520 1026 SetSize( wxSIZE_AUTO_WIDTH, 0 );
e56d2520
SC
1027 m_peer->SetVisibility( false, true );
1028 wxToolBarBase::Show( false );
1029 }
1030 }
1031 else
1032 {
1033 // only deinstall toolbar if this is the installed one
1034 if (m_macHIToolbarRef == curToolbarRef)
1035 {
1036 bResult = true;
1037
1038 ShowHideWindowToolbar( tlw, false, false );
3b6a1179 1039 ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute );
e56d2520 1040 SetWindowToolbar( tlw, NULL );
f3a65c3e 1041
e56d2520 1042 m_peer->SetVisibility( true, true );
e56d2520
SC
1043 }
1044 }
1045
1046 if (bResult)
1047 InvalidateBestSize();
1048
1049// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1050 return bResult;
1051}
1052#endif
1053
37e2cb08 1054bool wxToolBar::Realize()
e9576ca5 1055{
eb22f2a6 1056 if (m_tools.GetCount() == 0)
3803c372 1057 return false;
0b7a8cd3 1058
e56d2520
SC
1059 int maxWidth = 0;
1060 int maxHeight = 0;
f3a65c3e 1061
bfe9ffbc
SC
1062 int maxToolWidth = 0;
1063 int maxToolHeight = 0;
f3a65c3e 1064
991f71dc
DS
1065 int x = m_xMargin + kwxMacToolBarLeftMargin;
1066 int y = m_yMargin + kwxMacToolBarTopMargin;
1067
1068 int tw, th;
1069 GetSize( &tw, &th );
1070
e56d2520 1071 // find the maximum tool width and height
3025abca
DS
1072 wxToolBarTool *tool;
1073 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
e56d2520 1074 while ( node != NULL )
bfe9ffbc 1075 {
3025abca 1076 tool = (wxToolBarTool *) node->GetData();
e56d2520
SC
1077 if ( tool != NULL )
1078 {
1079 wxSize sz = tool->GetSize();
f3a65c3e 1080
e56d2520
SC
1081 if ( sz.x > maxToolWidth )
1082 maxToolWidth = sz.x;
1083 if ( sz.y > maxToolHeight )
1084 maxToolHeight = sz.y;
1085 }
f3a65c3e 1086
bfe9ffbc
SC
1087 node = node->GetNext();
1088 }
f3a65c3e 1089
991f71dc
DS
1090 bool lastIsRadio = false;
1091 bool curIsRadio = false;
df7998fc
VZ
1092
1093#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179
DS
1094 CFIndex currentPosition = 0;
1095 bool insertAll = false;
991f71dc 1096#endif
df7998fc 1097
991f71dc 1098 node = m_tools.GetFirst();
e56d2520 1099 while ( node != NULL )
7810c95b 1100 {
3025abca 1101 tool = (wxToolBarTool*) node->GetData();
e56d2520 1102 if ( tool == NULL )
214b9484 1103 {
e56d2520
SC
1104 node = node->GetNext();
1105 continue;
214b9484 1106 }
f3a65c3e 1107
991f71dc 1108 // set tool position:
e56d2520
SC
1109 // for the moment just perform a single row/column alignment
1110 wxSize cursize = tool->GetSize();
bfe9ffbc 1111 if ( x + cursize.x > maxWidth )
e56d2520 1112 maxWidth = x + cursize.x;
bfe9ffbc 1113 if ( y + cursize.y > maxHeight )
e56d2520 1114 maxHeight = y + cursize.y;
f3a65c3e 1115
73fd9428
SC
1116 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
1117 {
e56d2520
SC
1118 int x1 = x + ( maxToolWidth - cursize.x ) / 2;
1119 tool->SetPosition( wxPoint(x1, y) );
73fd9428
SC
1120 }
1121 else
1122 {
e56d2520
SC
1123 int y1 = y + ( maxToolHeight - cursize.y ) / 2;
1124 tool->SetPosition( wxPoint(x, y1) );
1125 }
f3a65c3e 1126
e56d2520 1127 // update the item positioning state
bfe9ffbc 1128 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520
SC
1129 y += cursize.y + kwxMacToolSpacing;
1130 else
1131 x += cursize.x + kwxMacToolSpacing;
f3a65c3e 1132
e56d2520
SC
1133#if wxMAC_USE_NATIVE_TOOLBAR
1134 // install in native HIToolbar
1135 if ( m_macHIToolbarRef != NULL )
bfe9ffbc 1136 {
e56d2520
SC
1137 HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
1138 if ( hiItemRef != NULL )
1139 {
991f71dc 1140 if ( insertAll || (tool->GetIndex() != currentPosition) )
e56d2520 1141 {
dcae64c2 1142 OSStatus err = noErr;
8138cfec
SC
1143 if ( !insertAll )
1144 {
dcae64c2
DS
1145 insertAll = true;
1146
8138cfec
SC
1147 // if this is the first tool that gets newly inserted or repositioned
1148 // first remove all 'old' tools from here to the right, because of this
1149 // all following tools will have to be reinserted (insertAll). i = 100 because there's
1150 // no way to determine how many there are in a toolbar, so just a high number :-(
3b6a1179 1151 for ( CFIndex i = 100; i >= currentPosition; --i )
8138cfec 1152 {
dcae64c2 1153 err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, i );
8138cfec 1154 }
991f71dc 1155
dcae64c2
DS
1156 if (err != noErr)
1157 {
1158 wxString errMsg = wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err );
4362c705 1159 wxFAIL_MSG( errMsg.c_str() );
dcae64c2
DS
1160 }
1161 }
991f71dc 1162
dcae64c2
DS
1163 err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef, currentPosition );
1164 if (err != noErr)
1165 {
1166 wxString errMsg = wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err );
4362c705 1167 wxFAIL_MSG( errMsg.c_str() );
dcae64c2 1168 }
3b6a1179 1169
dcae64c2 1170 tool->SetIndex( currentPosition );
e56d2520 1171 }
991f71dc 1172
dcae64c2 1173 currentPosition++;
e56d2520
SC
1174 }
1175 }
dcae64c2 1176#endif
f3a65c3e 1177
e56d2520
SC
1178 // update radio button (and group) state
1179 lastIsRadio = curIsRadio;
1180 curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) );
f3a65c3e 1181
e56d2520
SC
1182 if ( !curIsRadio )
1183 {
1184 if ( tool->IsToggled() )
1185 DoToggleTool( tool, true );
0b7a8cd3
GD
1186 }
1187 else
1188 {
e56d2520
SC
1189 if ( !lastIsRadio )
1190 {
dcae64c2 1191 if ( tool->Toggle( true ) )
e56d2520
SC
1192 {
1193 DoToggleTool( tool, true );
e56d2520
SC
1194 }
1195 }
1196 else if ( tool->IsToggled() )
1197 {
1198 if ( tool->IsToggled() )
1199 DoToggleTool( tool, true );
f3a65c3e 1200
e56d2520
SC
1201 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
1202 while ( nodePrev != NULL )
1203 {
1204 wxToolBarToolBase *toggleTool = nodePrev->GetData();
1205 if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) )
1206 break;
f3a65c3e 1207
dcae64c2 1208 if ( toggleTool->Toggle( false ) )
e56d2520 1209 DoToggleTool( toggleTool, false );
f3a65c3e 1210
e56d2520
SC
1211 nodePrev = nodePrev->GetPrevious();
1212 }
1213 }
0b7a8cd3 1214 }
f3a65c3e 1215
eb22f2a6 1216 node = node->GetNext();
7810c95b 1217 }
f3a65c3e 1218
0b7a8cd3 1219 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 1220 {
e56d2520
SC
1221 // if not set yet, only one row
1222 if ( m_maxRows <= 0 )
1223 SetRows( 1 );
f3a65c3e 1224
90d3f91a 1225 m_minWidth = maxWidth;
e56d2520 1226 maxWidth = tw;
0b7a8cd3 1227 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
e56d2520 1228 m_minHeight = m_maxHeight = maxHeight;
7810c95b 1229 }
0b7a8cd3
GD
1230 else
1231 {
e56d2520
SC
1232 // if not set yet, have one column
1233 if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
1234 SetRows( GetToolsCount() );
f3a65c3e 1235
90d3f91a 1236 m_minHeight = maxHeight;
e56d2520 1237 maxHeight = th;
0b7a8cd3 1238 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
e56d2520 1239 m_minWidth = m_maxWidth = maxWidth;
0b7a8cd3 1240 }
e56d2520 1241
f3a65c3e 1242#if 0
e56d2520
SC
1243 // FIXME: should this be OSX-only?
1244 {
1245 bool wantNativeToolbar, ownToolbarInstalled;
1246
1247 // attempt to install the native toolbar
1248 wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0);
1249 MacInstallNativeToolbar( wantNativeToolbar );
1250 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
1251 if (!ownToolbarInstalled)
1252 {
1253 SetSize( maxWidth, maxHeight );
1254 InvalidateBestSize();
1255 }
1256 }
f3a65c3e 1257#else
facd6764 1258 SetSize( maxWidth, maxHeight );
9f884528 1259 InvalidateBestSize();
e56d2520 1260#endif
2c1dbc95 1261
170acdc9 1262 SetInitialSize();
2c1dbc95 1263
3803c372 1264 return true;
e9576ca5
SC
1265}
1266
1267void wxToolBar::SetToolBitmapSize(const wxSize& size)
1268{
e56d2520
SC
1269 m_defaultWidth = size.x + kwxMacToolBorder;
1270 m_defaultHeight = size.y + kwxMacToolBorder;
f3a65c3e 1271
e56d2520
SC
1272#if wxMAC_USE_NATIVE_TOOLBAR
1273 if (m_macHIToolbarRef != NULL)
1274 {
1275 int maxs = wxMax( size.x, size.y );
3b6a1179 1276 HIToolbarDisplaySize sizeSpec;
328f4fee 1277 if ( maxs > 32 )
3b6a1179 1278 sizeSpec = kHIToolbarDisplaySizeNormal;
00a7bd85 1279 else if ( maxs > 24 )
3b6a1179 1280 sizeSpec = kHIToolbarDisplaySizeDefault;
328f4fee 1281 else
3b6a1179 1282 sizeSpec = kHIToolbarDisplaySizeSmall;
f3a65c3e 1283
e56d2520
SC
1284 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
1285 }
1286#endif
e9576ca5
SC
1287}
1288
e9576ca5
SC
1289// The button size is bigger than the bitmap size
1290wxSize wxToolBar::GetToolSize() const
1291{
ee799df7 1292 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
1293}
1294
37e2cb08 1295void wxToolBar::SetRows(int nRows)
e9576ca5 1296{
e56d2520
SC
1297 // avoid resizing the frame uselessly
1298 if ( nRows != m_maxRows )
e56d2520 1299 m_maxRows = nRows;
e9576ca5
SC
1300}
1301
f3a65c3e 1302void wxToolBar::MacSuperChangedPosition()
c257d44d 1303{
e56d2520 1304 wxWindow::MacSuperChangedPosition();
991f71dc 1305
e56d2520
SC
1306#if wxMAC_USE_NATIVE_TOOLBAR
1307 if (! m_macUsesNativeToolbar )
e56d2520 1308 Realize();
991f71dc 1309#else
3025abca 1310
991f71dc
DS
1311 Realize();
1312#endif
c257d44d
SC
1313}
1314
37e2cb08 1315wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 1316{
3025abca 1317 wxToolBarTool *tool;
affd2611 1318 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
e56d2520 1319 while ( node != NULL )
e044f600 1320 {
3025abca 1321 tool = (wxToolBarTool *)node->GetData();
e56d2520 1322 if (tool != NULL)
e044f600 1323 {
e56d2520
SC
1324 wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
1325 if ( r.Contains( wxPoint( x, y ) ) )
1326 return tool;
e044f600 1327 }
bfe9ffbc
SC
1328
1329 node = node->GetNext();
e044f600 1330 }
37e2cb08 1331
3025abca 1332 return (wxToolBarToolBase*)NULL;
e9576ca5
SC
1333}
1334
2f1ae414
SC
1335wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
1336{
3b6a1179 1337 wxToolBarToolBase *tool = FindToolForPosition( pt.x, pt.y );
e56d2520 1338 if ( tool != NULL )
3b6a1179 1339 return tool->GetShortHelp();
e56d2520 1340
3b6a1179 1341 return wxEmptyString;
2f1ae414
SC
1342}
1343
37e2cb08 1344void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 1345{
e56d2520 1346 if ( t != NULL )
3b6a1179 1347 ((wxToolBarTool*)t)->DoEnable( enable );
e9576ca5
SC
1348}
1349
37e2cb08 1350void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 1351{
e044f600 1352 wxToolBarTool *tool = (wxToolBarTool *)t;
e56d2520
SC
1353 if ( ( tool != NULL ) && tool->IsButton() )
1354 tool->UpdateToggleImage( toggle );
37e2cb08 1355}
7c551d95 1356
3b6a1179 1357bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
37e2cb08 1358{
3b6a1179 1359 wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase );
e56d2520
SC
1360 if (tool == NULL)
1361 return false;
1362
1363 WindowRef window = (WindowRef) MacGetTopLevelWindowRef();
1364 wxSize toolSize = GetToolSize();
3b6a1179 1365 Rect toolrect = { 0, 0, toolSize.y, toolSize.x };
e56d2520
SC
1366 ControlRef controlHandle = NULL;
1367 OSStatus err = 0;
be5fe3aa 1368
e56d2520 1369 switch (tool->GetStyle())
be5fe3aa 1370 {
3b6a1179 1371 case wxTOOL_STYLE_SEPARATOR:
be5fe3aa 1372 {
e56d2520
SC
1373 wxASSERT( tool->GetControlHandle() == NULL );
1374 toolSize.x /= 4;
1375 toolSize.y /= 4;
be5fe3aa 1376 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520 1377 toolrect.bottom = toolSize.y;
be5fe3aa 1378 else
e56d2520
SC
1379 toolrect.right = toolSize.x;
1380
991f71dc 1381#ifdef __WXMAC_OSX__
be5fe3aa 1382 // in flat style we need a visual separator
991f71dc 1383#if wxMAC_USE_NATIVE_TOOLBAR
e56d2520 1384 HIToolbarItemRef item;
991f71dc
DS
1385 err = HIToolbarItemCreate(
1386 kHIToolbarSeparatorIdentifier,
1387 kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
1388 &item );
e56d2520
SC
1389 if (err == noErr)
1390 tool->SetToolbarItemRef( item );
991f71dc
DS
1391#endif
1392
e56d2520
SC
1393 CreateSeparatorControl( window, &toolrect, &controlHandle );
1394 tool->SetControlHandle( controlHandle );
991f71dc 1395#endif
be5fe3aa 1396 }
e56d2520
SC
1397 break;
1398
3b6a1179 1399 case wxTOOL_STYLE_BUTTON:
be5fe3aa 1400 {
3b6a1179
DS
1401 wxASSERT( tool->GetControlHandle() == NULL );
1402 ControlButtonContentInfo info;
1403 wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef );
f3a65c3e 1404
df7998fc 1405 if ( UMAGetSystemVersion() >= 0x1000)
3b6a1179
DS
1406 {
1407 CreateIconControl( window, &toolrect, &info, false, &controlHandle );
1408 }
df7998fc
VZ
1409 else
1410 {
3b6a1179 1411 SInt16 behaviour = kControlBehaviorOffsetContents;
df7998fc 1412 if ( tool->CanBeToggled() )
3b6a1179
DS
1413 behaviour |= kControlBehaviorToggles;
1414 err = CreateBevelButtonControl( window,
1415 &toolrect, CFSTR(""), kControlBevelButtonNormalBevel,
1416 behaviour, &info, 0, 0, 0, &controlHandle );
df7998fc 1417 }
e56d2520
SC
1418
1419#if wxMAC_USE_NATIVE_TOOLBAR
3b6a1179 1420 HIToolbarItemRef item;
30962327 1421 wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
e56d2520
SC
1422 err = HIToolbarItemCreate(
1423 wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1424 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
1425 if (err == noErr)
1426 {
3025abca
DS
1427 InstallEventHandler(
1428 HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
1429 GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
e56d2520
SC
1430 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1431 HIToolbarItemSetIconRef( item, info.u.iconRef );
2c1dbc95 1432 HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
e56d2520
SC
1433 tool->SetToolbarItemRef( item );
1434 }
991f71dc 1435#endif
e56d2520 1436
3b6a1179 1437 wxMacReleaseBitmapButton( &info );
3025abca 1438
991f71dc 1439#if 0
3b6a1179
DS
1440 SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic );
1441 UMASetControlTitle( m_controlHandle, label, wxFont::GetDefaultEncoding() );
991f71dc 1442#endif
f3a65c3e 1443
3b6a1179
DS
1444 InstallControlEventHandler(
1445 (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
e56d2520 1446 GetEventTypeCount(eventList), eventList, tool, NULL );
be5fe3aa 1447
e56d2520 1448 tool->SetControlHandle( controlHandle );
be5fe3aa 1449 }
e56d2520
SC
1450 break;
1451
3b6a1179 1452 case wxTOOL_STYLE_CONTROL:
3b6a1179 1453
6d4835dc 1454#if wxMAC_USE_NATIVE_TOOLBAR
e56d2520 1455 {
0ac091ae 1456 wxASSERT( tool->GetControl() != NULL );
e56d2520 1457 HIToolbarItemRef item;
6d4835dc 1458 HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
9d5ccdd3
SC
1459 // as this control now is part of both the wxToolBar children and the native toolbar, we have to increase the
1460 // reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views
1461 CFRetain( viewRef ) ;
6d4835dc
SC
1462 CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
1463 err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID,
1464 data , &item ) ;
1465
1466 if (err == noErr)
e56d2520 1467 {
e56d2520 1468 tool->SetToolbarItemRef( item );
e56d2520 1469 }
6d4835dc
SC
1470 CFRelease( data ) ;
1471 }
f3a65c3e 1472
e56d2520 1473#else
6d4835dc 1474 // right now there's nothing to do here
e56d2520
SC
1475#endif
1476 break;
1477
3b6a1179 1478 default:
e56d2520 1479 break;
be5fe3aa 1480 }
f3a65c3e 1481
991f71dc 1482 if ( err == noErr )
be5fe3aa 1483 {
e56d2520
SC
1484 if ( controlHandle )
1485 {
1486 ControlRef container = (ControlRef) GetHandle();
3b6a1179 1487 wxASSERT_MSG( container != NULL, wxT("No valid Mac container control") );
be5fe3aa 1488
e56d2520
SC
1489 UMAShowControl( controlHandle );
1490 ::EmbedControl( controlHandle, container );
1491 }
1492
1493 if ( tool->CanBeToggled() && tool->IsToggled() )
1494 tool->UpdateToggleImage( true );
be5fe3aa 1495
e56d2520 1496 // nothing special to do here - we relayout in Realize() later
3b6a1179 1497 tool->Attach( this );
e56d2520
SC
1498 InvalidateBestSize();
1499 }
1500 else
be5fe3aa 1501 {
3b6a1179 1502 wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err );
4362c705 1503 wxFAIL_MSG( errMsg.c_str() );
be5fe3aa 1504 }
f3a65c3e 1505
991f71dc 1506 return (err == noErr);
37e2cb08 1507}
e9576ca5 1508
5115c51a 1509void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 1510{
3b6a1179 1511 wxFAIL_MSG( wxT("not implemented") );
e9576ca5
SC
1512}
1513
be5fe3aa 1514bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
37e2cb08 1515{
3b6a1179 1516 wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase );
affd2611 1517 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
1518 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1519 {
1520 wxToolBarToolBase *tool2 = node->GetData();
1521 if ( tool2 == tool )
1522 {
1523 // let node point to the next node in the list
1524 node = node->GetNext();
1525
1526 break;
1527 }
1528 }
1529
3b6a1179 1530 wxSize sz = ((wxToolBarTool*)tool)->GetSize();
bfe9ffbc
SC
1531
1532 tool->Detach();
df7998fc
VZ
1533
1534#if wxMAC_USE_NATIVE_TOOLBAR
1535 CFIndex removeIndex = tool->GetIndex();
dcae64c2 1536#endif
bfe9ffbc 1537
507d5748
SC
1538#if wxMAC_USE_NATIVE_TOOLBAR
1539 if ( removeIndex != -1 && m_macHIToolbarRef )
1540 {
1541 HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
1542 tool->SetIndex( -1 );
1543 }
1544#endif
488b2c29
SC
1545 switch ( tool->GetStyle() )
1546 {
1547 case wxTOOL_STYLE_CONTROL:
507d5748 1548 if ( tool->GetControl() )
be5fe3aa 1549 tool->GetControl()->Destroy();
488b2c29
SC
1550 break;
1551
1552 case wxTOOL_STYLE_BUTTON:
1553 case wxTOOL_STYLE_SEPARATOR:
507d5748 1554 // nothing special
488b2c29 1555 break;
e56d2520
SC
1556
1557 default:
1558 break;
488b2c29 1559 }
507d5748 1560 tool->ClearControl();
488b2c29 1561
bfe9ffbc 1562 // and finally reposition all the controls after this one
f3a65c3e 1563
3b6a1179 1564 for ( /* node -> first after deleted */; node; node = node->GetNext() )
bfe9ffbc
SC
1565 {
1566 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
3b6a1179 1567 wxPoint pt = tool2->GetPosition();
bfe9ffbc
SC
1568
1569 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
3b6a1179 1570 pt.y -= sz.y;
bfe9ffbc 1571 else
3b6a1179 1572 pt.x -= sz.x;
e56d2520 1573
3b6a1179 1574 tool2->SetPosition( pt );
df7998fc 1575
2c1dbc95
SC
1576#if wxMAC_USE_NATIVE_TOOLBAR
1577 if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
3b6a1179 1578 tool2->SetIndex( tool2->GetIndex() - 1 );
2c1dbc95 1579#endif
bfe9ffbc 1580 }
f3a65c3e 1581
9f884528 1582 InvalidateBestSize();
991f71dc 1583
3b6a1179 1584 return true;
37e2cb08 1585}
2f1ae414
SC
1586
1587void wxToolBar::OnPaint(wxPaintEvent& event)
1588{
e56d2520
SC
1589#if wxMAC_USE_NATIVE_TOOLBAR
1590 if ( m_macUsesNativeToolbar )
1591 {
dcae64c2
DS
1592 event.Skip(true);
1593 return;
e56d2520
SC
1594 }
1595#endif
f3a65c3e 1596
3b6a1179 1597 wxPaintDC dc(this);
ddc548ec 1598
3b6a1179
DS
1599 int w, h;
1600 GetSize( &w, &h );
991f71dc 1601
dcae64c2
DS
1602 bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance();
1603 bool minimumUmaAvailable = (UMAGetSystemVersion() >= 0x1030);
1604
ddc548ec 1605#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
dcae64c2 1606 if ( !drawMetalTheme && minimumUmaAvailable )
ddc548ec 1607 {
dcae64c2
DS
1608 HIThemePlacardDrawInfo info;
1609 memset( &info, 0, sizeof(info) );
1610 info.version = 0;
1611 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive;
1612
1613 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef();
1614 HIRect rect = CGRectMake( 0, 0, w, h );
1615 HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal );
ddc548ec
SC
1616 }
1617 else
1618 {
1619 // leave the background as it is (striped or metal)
1620 }
991f71dc 1621
ddc548ec 1622#else
dcae64c2
DS
1623
1624 const bool drawBorder = true;
1625
1626 if (drawBorder)
01ffa8f7 1627 {
3b6a1179 1628 wxMacPortSetter helper( &dc );
dcae64c2
DS
1629
1630 if ( !drawMetalTheme || !minimumUmaAvailable )
20b69855 1631 {
3b6a1179
DS
1632 Rect toolbarrect = { dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0),
1633 dc.YLOG2DEVMAC(h), dc.XLOG2DEVMAC(w) };
dcae64c2
DS
1634
1635#if 0
1636 if ( toolbarrect.left < 0 )
3b6a1179 1637 toolbarrect.left = 0;
dcae64c2 1638 if ( toolbarrect.top < 0 )
3b6a1179 1639 toolbarrect.top = 0;
dcae64c2
DS
1640#endif
1641
1642 UMADrawThemePlacard( &toolbarrect, IsEnabled() ? kThemeStateActive : kThemeStateInactive );
1643 }
1644 else
1645 {
1646#if TARGET_API_MAC_OSX
991f71dc 1647 HIRect hiToolbarrect = CGRectMake(
3b6a1179
DS
1648 dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0),
1649 dc.YLOG2DEVREL(h), dc.XLOG2DEVREL(w) );
1650 CGContextRef cgContext;
1651 Rect bounds;
dcae64c2 1652
3b6a1179
DS
1653 GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
1654 QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
dcae64c2 1655
3b6a1179
DS
1656 CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
1657 CGContextScaleCTM( cgContext, 1, -1 );
785f5eaa 1658
3b6a1179
DS
1659 HIThemeBackgroundDrawInfo drawInfo;
1660 drawInfo.version = 0;
1661 drawInfo.state = kThemeStateActive;
1662 drawInfo.kind = kThemeBackgroundMetal;
dcae64c2 1663 HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal );
e56d2520 1664
f387b80e 1665#ifndef __LP64__
3b6a1179 1666 QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
f387b80e 1667#endif
20b69855 1668#endif
01ffa8f7 1669 }
01ffa8f7
SC
1670 }
1671#endif
20b69855 1672
dcae64c2 1673 event.Skip();
2f1ae414 1674}
895f5af7 1675
519cb848 1676#endif // wxUSE_TOOLBAR