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