1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toolbar.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/toolbar.h"
23 #include "wx/mac/uma.h"
24 #include "wx/geometry.h"
28 const short kwxMacToolBarToolDefaultWidth
= 16;
29 const short kwxMacToolBarToolDefaultHeight
= 16;
30 const short kwxMacToolBarTopMargin
= 4;
31 const short kwxMacToolBarLeftMargin
= 4;
32 const short kwxMacToolBorder
= 0;
33 const short kwxMacToolSpacing
= 6;
35 const short kwxMacToolBarToolDefaultWidth
= 24;
36 const short kwxMacToolBarToolDefaultHeight
= 22;
37 const short kwxMacToolBarTopMargin
= 2;
38 const short kwxMacToolBarLeftMargin
= 2;
39 const short kwxMacToolBorder
= 4;
40 const short kwxMacToolSpacing
= 0;
44 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
46 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
47 EVT_PAINT( wxToolBar::OnPaint
)
52 #pragma mark Tool Implementation
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
61 class wxToolBarTool
: public wxToolBarToolBase
67 const wxString
& label
,
68 const wxBitmap
& bmpNormal
,
69 const wxBitmap
& bmpDisabled
,
72 const wxString
& shortHelp
,
73 const wxString
& longHelp
);
75 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
)
76 : wxToolBarToolBase(tbar
, control
)
80 SetControlHandle( (ControlRef
) control
->GetHandle() );
83 virtual ~wxToolBarTool()
88 WXWidget
GetControlHandle()
90 return (WXWidget
) m_controlHandle
;
93 void SetControlHandle( ControlRef handle
)
95 m_controlHandle
= handle
;
98 void SetPosition( const wxPoint
& position
);
103 if ( m_controlHandle
)
106 DisposeControl( m_controlHandle
);
109 // the embedded control is not under the responsibility of the tool
111 m_controlHandle
= NULL
;
114 #if wxMAC_USE_NATIVE_TOOLBAR
115 if ( m_toolbarItemRef
)
117 CFIndex count
= CFGetRetainCount( m_toolbarItemRef
) ;
118 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
119 wxTheApp
->MacAddToAutorelease(m_toolbarItemRef
);
120 CFRelease(m_toolbarItemRef
);
121 m_toolbarItemRef
= NULL
;
126 wxSize
GetSize() const
132 curSize
= GetControl()->GetSize();
134 else if ( IsButton() )
136 curSize
= GetToolBar()->GetToolSize();
141 curSize
= GetToolBar()->GetToolSize();
142 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
151 wxPoint
GetPosition() const
153 return wxPoint( m_x
, m_y
);
156 bool DoEnable( bool enable
);
158 void UpdateToggleImage( bool toggle
);
160 #if wxMAC_USE_NATIVE_TOOLBAR
161 void SetToolbarItemRef( HIToolbarItemRef ref
)
163 if ( m_controlHandle
)
164 HideControl( m_controlHandle
);
165 if ( m_toolbarItemRef
)
166 CFRelease( m_toolbarItemRef
);
168 m_toolbarItemRef
= ref
;
169 if ( m_toolbarItemRef
)
171 HIToolbarItemSetHelpText(
173 wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ),
174 wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) );
178 HIToolbarItemRef
GetToolbarItemRef() const
180 return m_toolbarItemRef
;
183 void SetIndex( CFIndex idx
)
188 CFIndex
GetIndex() const
197 m_controlHandle
= NULL
;
199 #if wxMAC_USE_NATIVE_TOOLBAR
200 m_toolbarItemRef
= NULL
;
205 ControlRef m_controlHandle
;
209 #if wxMAC_USE_NATIVE_TOOLBAR
210 HIToolbarItemRef m_toolbarItemRef
;
211 // position in its toolbar, -1 means not inserted
216 static const EventTypeSpec eventList
[] =
218 { kEventClassControl
, kEventControlHit
},
220 { kEventClassControl
, kEventControlHitTest
},
224 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
226 OSStatus result
= eventNotHandledErr
;
227 ControlRef controlRef
;
228 wxMacCarbonEvent
cEvent( event
);
230 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
232 switch ( GetEventKind( event
) )
234 case kEventControlHit
:
236 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
237 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
238 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
243 shouldToggle
= !tbartool
->IsToggled();
245 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
248 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
251 if (tbartool
!= NULL
)
252 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
258 case kEventControlHitTest
:
260 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
262 HIViewGetBounds( controlRef
, &rect
);
264 ControlPartCode pc
= kControlNoPart
;
265 if ( CGRectContainsPoint( rect
, pt
) )
266 pc
= kControlIconPart
;
267 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
280 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
282 OSStatus result
= eventNotHandledErr
;
284 switch ( GetEventClass( event
) )
286 case kEventClassControl
:
287 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
297 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
299 #if wxMAC_USE_NATIVE_TOOLBAR
301 static const EventTypeSpec toolBarEventList
[] =
303 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
306 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
308 OSStatus result
= eventNotHandledErr
;
310 switch ( GetEventKind( event
) )
312 case kEventToolbarItemPerformAction
:
314 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
315 if ( tbartool
!= NULL
)
317 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
318 int toolID
= tbartool
->GetId();
320 if ( tbartool
->CanBeToggled() )
323 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
327 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
340 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
342 OSStatus result
= eventNotHandledErr
;
344 switch ( GetEventClass( event
) )
346 case kEventClassToolbarItem
:
347 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
357 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
361 bool wxToolBarTool::DoEnable( bool enable
)
365 GetControl()->Enable( enable
);
367 else if ( IsButton() )
369 #if wxMAC_USE_NATIVE_TOOLBAR
370 if ( m_toolbarItemRef
!= NULL
)
371 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
374 if ( m_controlHandle
!= NULL
)
376 #if TARGET_API_MAC_OSX
378 EnableControl( m_controlHandle
);
380 DisableControl( m_controlHandle
);
383 ActivateControl( m_controlHandle
);
385 DeactivateControl( m_controlHandle
);
393 void wxToolBarTool::SetPosition( const wxPoint
& position
)
398 int mac_x
= position
.x
;
399 int mac_y
= position
.y
;
404 GetControlBounds( m_controlHandle
, &contrlRect
);
405 int former_mac_x
= contrlRect
.left
;
406 int former_mac_y
= contrlRect
.top
;
407 GetToolBar()->GetToolSize();
409 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
411 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
414 else if ( IsControl() )
416 // embedded native controls are moved by the OS
417 #if wxMAC_USE_NATIVE_TOOLBAR
418 if ( ((wxToolBar
*)GetToolBar())->MacWantsNativeToolbar() == false )
421 GetControl()->Move( position
);
429 GetControlBounds( m_controlHandle
, &contrlRect
);
430 int former_mac_x
= contrlRect
.left
;
431 int former_mac_y
= contrlRect
.top
;
433 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
434 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
439 void wxToolBarTool::UpdateToggleImage( bool toggle
)
444 int w
= m_bmpNormal
.GetWidth();
445 int h
= m_bmpNormal
.GetHeight();
446 wxBitmap
bmp( w
, h
);
449 dc
.SelectObject( bmp
);
450 dc
.SetPen( wxPen(*wxBLACK
) );
451 dc
.SetBrush( wxBrush( *wxLIGHT_GREY
));
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
, kControlContentIconRef
);
457 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
458 #if wxMAC_USE_NATIVE_TOOLBAR
459 if (m_toolbarItemRef
!= NULL
)
461 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
464 wxMacReleaseBitmapButton( &info
);
468 ControlButtonContentInfo info
;
469 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
470 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
471 #if wxMAC_USE_NATIVE_TOOLBAR
472 if (m_toolbarItemRef
!= NULL
)
474 HIToolbarItemSetIconRef( m_toolbarItemRef
, info
.u
.iconRef
);
477 wxMacReleaseBitmapButton( &info
);
480 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
482 m_controlHandle
, 0, kControlIconTransformTag
,
483 sizeof(transform
), (Ptr
)&transform
);
484 HIViewSetNeedsDisplay( m_controlHandle
, true );
487 ::SetControl32BitValue( m_controlHandle
, toggle
);
491 wxToolBarTool::wxToolBarTool(
494 const wxString
& label
,
495 const wxBitmap
& bmpNormal
,
496 const wxBitmap
& bmpDisabled
,
498 wxObject
*clientData
,
499 const wxString
& shortHelp
,
500 const wxString
& longHelp
)
503 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
504 clientData
, shortHelp
, longHelp
)
510 #pragma mark Toolbar Implementation
512 wxToolBarToolBase
*wxToolBar::CreateTool(
514 const wxString
& label
,
515 const wxBitmap
& bmpNormal
,
516 const wxBitmap
& bmpDisabled
,
518 wxObject
*clientData
,
519 const wxString
& shortHelp
,
520 const wxString
& longHelp
)
522 return new wxToolBarTool(
523 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
524 clientData
, shortHelp
, longHelp
);
527 wxToolBarToolBase
* wxToolBar::CreateTool( wxControl
*control
)
529 return new wxToolBarTool( this, control
);
532 void wxToolBar::Init()
536 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
537 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
539 #if wxMAC_USE_NATIVE_TOOLBAR
540 m_macHIToolbarRef
= NULL
;
541 m_macUsesNativeToolbar
= false;
545 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
547 const EventTypeSpec kEvents
[] =
549 { kEventClassHIObject
, kEventHIObjectConstruct
},
550 { kEventClassHIObject
, kEventHIObjectInitialize
},
551 { kEventClassHIObject
, kEventHIObjectDestruct
},
553 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
556 const EventTypeSpec kViewEvents
[] =
558 { kEventClassControl
, kEventControlGetSizeConstraints
}
561 struct ControlToolbarItem
563 HIToolbarItemRef toolbarItem
;
565 wxSize lastValidSize
;
568 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
570 OSStatus result
= eventNotHandledErr
;
571 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
573 switch ( GetEventClass( inEvent
) )
575 case kEventClassHIObject
:
576 switch ( GetEventKind( inEvent
) )
578 case kEventHIObjectConstruct
:
580 HIObjectRef toolbarItem
;
581 ControlToolbarItem
* item
;
583 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
584 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
586 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
587 item
->toolbarItem
= toolbarItem
;
588 item
->viewRef
= NULL
;
590 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
596 case kEventHIObjectInitialize
:
597 result
= CallNextEventHandler( inCallRef
, inEvent
);
598 if ( result
== noErr
)
601 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
602 sizeof( CFTypeRef
), NULL
, &data
);
606 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
607 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
609 object
->viewRef
= (HIViewRef
) viewRef
;
615 case kEventHIObjectDestruct
:
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
;
620 if( viewRef
&& IsValidControlHandle( viewRef
) )
622 CFIndex count
= CFGetRetainCount( viewRef
) ;
624 CFRelease( viewRef
) ;
633 case kEventClassToolbarItem
:
634 switch ( GetEventKind( inEvent
) )
636 case kEventToolbarItemCreateCustomView
:
638 HIViewRef viewRef
= object
->viewRef
;
640 HIViewRemoveFromSuperview( viewRef
) ;
641 HIViewSetVisible(viewRef
, true) ;
642 InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
643 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
);
645 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
651 case kEventClassControl
:
652 switch ( GetEventKind( inEvent
) )
654 case kEventControlGetSizeConstraints
:
656 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
659 wxSize sz
= wxwindow
->GetSize() ;
660 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
661 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
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
665 if ( sz
.x
> 0 && sz
.y
> 0 )
666 object
->lastValidSize
= sz
;
668 sz
= object
->lastValidSize
;
671 min
.width
= max
.width
= sz
.x
;
672 min
.height
= max
.height
= sz
.y
;
674 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
675 sizeof( HISize
), &min
);
677 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
678 sizeof( HISize
), &max
);
690 void RegisterControlToolbarItemClass()
692 static bool sRegistered
;
696 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
697 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
703 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
705 RegisterControlToolbarItemClass();
709 UInt32 options
= kHIToolbarItemAllowDuplicates
;
710 HIToolbarItemRef result
= NULL
;
712 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
713 require_noerr( err
, CantCreateEvent
);
715 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
716 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
719 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
721 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
724 ReleaseEvent( event
);
729 #if wxMAC_USE_NATIVE_TOOLBAR
730 static const EventTypeSpec kToolbarEvents
[] =
732 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
733 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
734 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
737 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
739 OSStatus result
= eventNotHandledErr
;
741 // wxToolBar* toolbar = (wxToolBar*) inUserData ;
742 CFMutableArrayRef array
;
744 switch ( GetEventKind( inEvent
) )
746 case kEventToolbarGetDefaultIdentifiers
:
748 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
749 sizeof( CFMutableArrayRef
), NULL
, &array
);
750 // not implemented yet
751 // GetToolbarDefaultItems( array );
756 case kEventToolbarGetAllowedIdentifiers
:
758 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
759 sizeof( CFMutableArrayRef
), NULL
, &array
);
760 // not implemented yet
761 // GetToolbarAllowedItems( array );
765 case kEventToolbarCreateItemWithIdentifier
:
767 HIToolbarItemRef item
= NULL
;
768 CFTypeRef data
= NULL
;
769 CFStringRef identifier
= NULL
;
771 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
772 sizeof( CFStringRef
), NULL
, &identifier
);
774 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
775 sizeof( CFTypeRef
), NULL
, &data
);
777 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
779 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
782 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
783 sizeof( HIToolbarItemRef
), &item
);
793 #endif // wxMAC_USE_NATIVE_TOOLBAR
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
798 bool wxToolBar::Create(
804 const wxString
& name
)
806 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
811 OSStatus err
= noErr
;
813 #if wxMAC_USE_NATIVE_TOOLBAR
814 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
815 err
= HIToolbarCreate(
816 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
817 (HIToolbarRef
*) &m_macHIToolbarRef
);
819 if (m_macHIToolbarRef
!= NULL
)
821 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
822 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
824 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
825 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
827 if ( style
& wxTB_NOICONS
)
828 mode
= kHIToolbarDisplayModeLabelOnly
;
829 else if ( style
& wxTB_TEXT
)
830 mode
= kHIToolbarDisplayModeIconAndLabel
;
832 mode
= kHIToolbarDisplayModeIconOnly
;
834 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
835 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
839 return (err
== noErr
);
842 wxToolBar::~wxToolBar()
844 #if wxMAC_USE_NATIVE_TOOLBAR
845 if (m_macHIToolbarRef
!= NULL
)
847 // if this is the installed toolbar, then deinstall it
848 if (m_macUsesNativeToolbar
)
849 MacInstallNativeToolbar( false );
851 CFIndex count
= CFGetRetainCount( m_macHIToolbarRef
) ;
852 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
854 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
855 m_macHIToolbarRef
= NULL
;
860 bool wxToolBar::Show( bool show
)
862 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
863 bool bResult
= (tlw
!= NULL
);
867 #if wxMAC_USE_NATIVE_TOOLBAR
868 bool ownToolbarInstalled
= false;
869 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
870 if (ownToolbarInstalled
)
872 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
874 ShowHideWindowToolbar( tlw
, show
, false );
877 bResult
= wxToolBarBase::Show( show
);
880 bResult
= wxToolBarBase::Show( show
);
887 bool wxToolBar::IsShown() const
891 #if wxMAC_USE_NATIVE_TOOLBAR
892 bool ownToolbarInstalled
;
894 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
895 if (ownToolbarInstalled
)
897 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
898 bResult
= IsWindowToolbarVisible( tlw
);
901 bResult
= wxToolBarBase::IsShown();
904 bResult
= wxToolBarBase::IsShown();
910 void wxToolBar::DoGetSize( int *width
, int *height
) const
912 #if wxMAC_USE_NATIVE_TOOLBAR
914 bool ownToolbarInstalled
;
916 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
917 if ( ownToolbarInstalled
)
919 // TODO: is this really a control ?
920 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
922 *width
= boundsR
.right
- boundsR
.left
;
923 if ( height
!= NULL
)
924 *height
= boundsR
.bottom
- boundsR
.top
;
927 wxToolBarBase::DoGetSize( width
, height
);
930 wxToolBarBase::DoGetSize( width
, height
);
934 wxSize
wxToolBar::DoGetBestSize() const
938 DoGetSize( &width
, &height
);
940 return wxSize( width
, height
);
943 void wxToolBar::SetWindowStyleFlag( long style
)
945 wxToolBarBase::SetWindowStyleFlag( style
);
947 #if wxMAC_USE_NATIVE_TOOLBAR
948 if (m_macHIToolbarRef
!= NULL
)
950 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
952 if ( style
& wxTB_NOICONS
)
953 mode
= kHIToolbarDisplayModeLabelOnly
;
954 else if ( style
& wxTB_TEXT
)
955 mode
= kHIToolbarDisplayModeIconAndLabel
;
957 mode
= kHIToolbarDisplayModeIconOnly
;
959 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
964 #if wxMAC_USE_NATIVE_TOOLBAR
965 bool wxToolBar::MacWantsNativeToolbar()
967 return m_macUsesNativeToolbar
;
970 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
972 bool bResultV
= false;
974 if (ownToolbarInstalled
!= NULL
)
975 *ownToolbarInstalled
= false;
977 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
980 HIToolbarRef curToolbarRef
= NULL
;
981 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
982 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
983 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
984 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
990 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
992 bool bResult
= false;
994 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
997 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
1000 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
1004 // check the existing toolbar
1005 HIToolbarRef curToolbarRef
= NULL
;
1006 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
1008 curToolbarRef
= NULL
;
1010 m_macUsesNativeToolbar
= usesNative
;
1012 if (m_macUsesNativeToolbar
)
1014 // only install toolbar if there isn't one installed already
1015 if (curToolbarRef
== NULL
)
1019 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1020 ShowHideWindowToolbar( tlw
, true, false );
1021 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1022 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1024 Rect r
= { 0, 0, 0, 0 };
1025 m_peer
->SetRect( &r
);
1026 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1027 m_peer
->SetVisibility( false, true );
1028 wxToolBarBase::Show( false );
1033 // only deinstall toolbar if this is the installed one
1034 if (m_macHIToolbarRef
== curToolbarRef
)
1038 ShowHideWindowToolbar( tlw
, false, false );
1039 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1040 SetWindowToolbar( tlw
, NULL
);
1042 m_peer
->SetVisibility( true, true );
1047 InvalidateBestSize();
1049 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1054 bool wxToolBar::Realize()
1056 if (m_tools
.GetCount() == 0)
1062 int maxToolWidth
= 0;
1063 int maxToolHeight
= 0;
1065 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1066 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1069 GetSize( &tw
, &th
);
1071 // find the maximum tool width and height
1072 wxToolBarTool
*tool
;
1073 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1074 while ( node
!= NULL
)
1076 tool
= (wxToolBarTool
*) node
->GetData();
1079 wxSize sz
= tool
->GetSize();
1081 if ( sz
.x
> maxToolWidth
)
1082 maxToolWidth
= sz
.x
;
1083 if ( sz
.y
> maxToolHeight
)
1084 maxToolHeight
= sz
.y
;
1087 node
= node
->GetNext();
1090 bool lastIsRadio
= false;
1091 bool curIsRadio
= false;
1093 #if wxMAC_USE_NATIVE_TOOLBAR
1094 CFIndex currentPosition
= 0;
1095 bool insertAll
= false;
1098 node
= m_tools
.GetFirst();
1099 while ( node
!= NULL
)
1101 tool
= (wxToolBarTool
*) node
->GetData();
1104 node
= node
->GetNext();
1108 // set tool position:
1109 // for the moment just perform a single row/column alignment
1110 wxSize cursize
= tool
->GetSize();
1111 if ( x
+ cursize
.x
> maxWidth
)
1112 maxWidth
= x
+ cursize
.x
;
1113 if ( y
+ cursize
.y
> maxHeight
)
1114 maxHeight
= y
+ cursize
.y
;
1116 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1118 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1119 tool
->SetPosition( wxPoint(x1
, y
) );
1123 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1124 tool
->SetPosition( wxPoint(x
, y1
) );
1127 // update the item positioning state
1128 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1129 y
+= cursize
.y
+ kwxMacToolSpacing
;
1131 x
+= cursize
.x
+ kwxMacToolSpacing
;
1133 #if wxMAC_USE_NATIVE_TOOLBAR
1134 // install in native HIToolbar
1135 if ( m_macHIToolbarRef
!= NULL
)
1137 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1138 if ( hiItemRef
!= NULL
)
1140 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1142 OSStatus err
= noErr
;
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 :-(
1151 for ( CFIndex i
= 100; i
>= currentPosition
; --i
)
1153 err
= HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, i
);
1158 wxString errMsg
= wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err
);
1159 wxFAIL_MSG( errMsg
.c_str() );
1163 err
= HIToolbarInsertItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, hiItemRef
, currentPosition
);
1166 wxString errMsg
= wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1167 wxFAIL_MSG( errMsg
.c_str() );
1170 tool
->SetIndex( currentPosition
);
1178 // update radio button (and group) state
1179 lastIsRadio
= curIsRadio
;
1180 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1184 if ( tool
->IsToggled() )
1185 DoToggleTool( tool
, true );
1191 if ( tool
->Toggle( true ) )
1193 DoToggleTool( tool
, true );
1196 else if ( tool
->IsToggled() )
1198 if ( tool
->IsToggled() )
1199 DoToggleTool( tool
, true );
1201 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1202 while ( nodePrev
!= NULL
)
1204 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1205 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1208 if ( toggleTool
->Toggle( false ) )
1209 DoToggleTool( toggleTool
, false );
1211 nodePrev
= nodePrev
->GetPrevious();
1216 node
= node
->GetNext();
1219 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1221 // if not set yet, only one row
1222 if ( m_maxRows
<= 0 )
1225 m_minWidth
= maxWidth
;
1227 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1228 m_minHeight
= m_maxHeight
= maxHeight
;
1232 // if not set yet, have one column
1233 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1234 SetRows( GetToolsCount() );
1236 m_minHeight
= maxHeight
;
1238 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1239 m_minWidth
= m_maxWidth
= maxWidth
;
1243 // FIXME: should this be OSX-only?
1245 bool wantNativeToolbar
, ownToolbarInstalled
;
1247 // attempt to install the native toolbar
1248 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1249 MacInstallNativeToolbar( wantNativeToolbar
);
1250 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1251 if (!ownToolbarInstalled
)
1253 SetSize( maxWidth
, maxHeight
);
1254 InvalidateBestSize();
1258 SetSize( maxWidth
, maxHeight
);
1259 InvalidateBestSize();
1267 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1269 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1270 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1272 #if wxMAC_USE_NATIVE_TOOLBAR
1273 if (m_macHIToolbarRef
!= NULL
)
1275 int maxs
= wxMax( size
.x
, size
.y
);
1276 HIToolbarDisplaySize sizeSpec
;
1278 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1279 else if ( maxs
> 24 )
1280 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1282 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1284 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1289 // The button size is bigger than the bitmap size
1290 wxSize
wxToolBar::GetToolSize() const
1292 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1295 void wxToolBar::SetRows(int nRows
)
1297 // avoid resizing the frame uselessly
1298 if ( nRows
!= m_maxRows
)
1302 void wxToolBar::MacSuperChangedPosition()
1304 wxWindow::MacSuperChangedPosition();
1306 #if wxMAC_USE_NATIVE_TOOLBAR
1307 if (! m_macUsesNativeToolbar
)
1315 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1317 wxToolBarTool
*tool
;
1318 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1319 while ( node
!= NULL
)
1321 tool
= (wxToolBarTool
*)node
->GetData();
1324 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1325 if ( r
.Contains( wxPoint( x
, y
) ) )
1329 node
= node
->GetNext();
1332 return (wxToolBarToolBase
*)NULL
;
1335 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1337 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1339 return tool
->GetShortHelp();
1341 return wxEmptyString
;
1344 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1347 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1350 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1352 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1353 if ( ( tool
!= NULL
) && tool
->IsButton() )
1354 tool
->UpdateToggleImage( toggle
);
1357 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1359 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1363 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1364 wxSize toolSize
= GetToolSize();
1365 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1366 ControlRef controlHandle
= NULL
;
1369 switch (tool
->GetStyle())
1371 case wxTOOL_STYLE_SEPARATOR
:
1373 wxASSERT( tool
->GetControlHandle() == NULL
);
1376 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1377 toolrect
.bottom
= toolSize
.y
;
1379 toolrect
.right
= toolSize
.x
;
1381 #ifdef __WXMAC_OSX__
1382 // in flat style we need a visual separator
1383 #if wxMAC_USE_NATIVE_TOOLBAR
1384 HIToolbarItemRef item
;
1385 err
= HIToolbarItemCreate(
1386 kHIToolbarSeparatorIdentifier
,
1387 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1390 tool
->SetToolbarItemRef( item
);
1393 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1394 tool
->SetControlHandle( controlHandle
);
1399 case wxTOOL_STYLE_BUTTON
:
1401 wxASSERT( tool
->GetControlHandle() == NULL
);
1402 ControlButtonContentInfo info
;
1403 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1405 if ( UMAGetSystemVersion() >= 0x1000)
1407 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1411 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1412 if ( tool
->CanBeToggled() )
1413 behaviour
|= kControlBehaviorToggles
;
1414 err
= CreateBevelButtonControl( window
,
1415 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1416 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1419 #if wxMAC_USE_NATIVE_TOOLBAR
1420 HIToolbarItemRef item
;
1421 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1422 err
= HIToolbarItemCreate(
1423 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1424 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1427 InstallEventHandler(
1428 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1429 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1430 HIToolbarItemSetLabel( item
, wxMacCFStringHolder(tool
->GetLabel(), m_font
.GetEncoding()) );
1431 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1432 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1433 tool
->SetToolbarItemRef( item
);
1437 wxMacReleaseBitmapButton( &info
);
1440 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1441 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1444 InstallControlEventHandler(
1445 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1446 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1448 tool
->SetControlHandle( controlHandle
);
1452 case wxTOOL_STYLE_CONTROL
:
1454 #if wxMAC_USE_NATIVE_TOOLBAR
1456 wxASSERT( tool
->GetControl() != NULL
);
1457 HIToolbarItemRef item
;
1458 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
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
) ;
1462 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1463 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1468 tool
->SetToolbarItemRef( item
);
1474 // right now there's nothing to do here
1484 if ( controlHandle
)
1486 ControlRef container
= (ControlRef
) GetHandle();
1487 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1489 UMAShowControl( controlHandle
);
1490 ::EmbedControl( controlHandle
, container
);
1493 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1494 tool
->UpdateToggleImage( true );
1496 // nothing special to do here - we relayout in Realize() later
1497 tool
->Attach( this );
1498 InvalidateBestSize();
1502 wxString errMsg
= wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
);
1503 wxFAIL_MSG( errMsg
.c_str() );
1506 return (err
== noErr
);
1509 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1511 wxFAIL_MSG( wxT("not implemented") );
1514 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1516 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1517 wxToolBarToolsList::compatibility_iterator node
;
1518 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1520 wxToolBarToolBase
*tool2
= node
->GetData();
1521 if ( tool2
== tool
)
1523 // let node point to the next node in the list
1524 node
= node
->GetNext();
1530 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1534 #if wxMAC_USE_NATIVE_TOOLBAR
1535 CFIndex removeIndex
= tool
->GetIndex();
1538 #if wxMAC_USE_NATIVE_TOOLBAR
1539 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1541 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1542 tool
->SetIndex( -1 );
1545 switch ( tool
->GetStyle() )
1547 case wxTOOL_STYLE_CONTROL
:
1548 if ( tool
->GetControl() )
1549 tool
->GetControl()->Destroy();
1552 case wxTOOL_STYLE_BUTTON
:
1553 case wxTOOL_STYLE_SEPARATOR
:
1560 tool
->ClearControl();
1562 // and finally reposition all the controls after this one
1564 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1566 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1567 wxPoint pt
= tool2
->GetPosition();
1569 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1574 tool2
->SetPosition( pt
);
1576 #if wxMAC_USE_NATIVE_TOOLBAR
1577 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1578 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1582 InvalidateBestSize();
1587 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1589 #if wxMAC_USE_NATIVE_TOOLBAR
1590 if ( m_macUsesNativeToolbar
)
1602 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1603 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1605 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1606 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1608 HIThemePlacardDrawInfo info
;
1609 memset( &info
, 0, sizeof(info
) );
1611 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1613 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1614 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1615 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1619 // leave the background as it is (striped or metal)
1624 const bool drawBorder
= true;
1628 wxMacPortSetter
helper( &dc
);
1630 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1632 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1633 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1636 if ( toolbarrect
.left
< 0 )
1637 toolbarrect
.left
= 0;
1638 if ( toolbarrect
.top
< 0 )
1639 toolbarrect
.top
= 0;
1642 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1646 #if TARGET_API_MAC_OSX
1647 HIRect hiToolbarrect
= CGRectMake(
1648 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1649 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1650 CGContextRef cgContext
;
1653 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1654 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1656 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1657 CGContextScaleCTM( cgContext
, 1, -1 );
1659 HIThemeBackgroundDrawInfo drawInfo
;
1660 drawInfo
.version
= 0;
1661 drawInfo
.state
= kThemeStateActive
;
1662 drawInfo
.kind
= kThemeBackgroundMetal
;
1663 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1666 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1676 #endif // wxUSE_TOOLBAR