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"
22 #include "wx/mac/uma.h"
23 #include "wx/geometry.h"
27 const short kwxMacToolBarToolDefaultWidth
= 16;
28 const short kwxMacToolBarToolDefaultHeight
= 16;
29 const short kwxMacToolBarTopMargin
= 4;
30 const short kwxMacToolBarLeftMargin
= 4;
31 const short kwxMacToolBorder
= 0;
32 const short kwxMacToolSpacing
= 6;
34 const short kwxMacToolBarToolDefaultWidth
= 24;
35 const short kwxMacToolBarToolDefaultHeight
= 22;
36 const short kwxMacToolBarTopMargin
= 2;
37 const short kwxMacToolBarLeftMargin
= 2;
38 const short kwxMacToolBorder
= 4;
39 const short kwxMacToolSpacing
= 0;
43 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
45 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
46 EVT_PAINT( wxToolBar::OnPaint
)
51 #pragma mark Tool Implementation
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
60 class wxToolBarTool
: public wxToolBarToolBase
66 const wxString
& label
,
67 const wxBitmap
& bmpNormal
,
68 const wxBitmap
& bmpDisabled
,
71 const wxString
& shortHelp
,
72 const wxString
& longHelp
);
74 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
)
75 : wxToolBarToolBase(tbar
, control
)
79 SetControlHandle( (ControlRef
) control
->GetHandle() );
86 #if wxMAC_USE_NATIVE_TOOLBAR
87 if ( m_toolbarItemRef
)
88 CFRelease( m_toolbarItemRef
);
92 WXWidget
GetControlHandle()
94 return (WXWidget
) m_controlHandle
;
97 void SetControlHandle( ControlRef handle
)
99 m_controlHandle
= handle
;
102 void SetPosition( const wxPoint
& position
);
107 if ( m_controlHandle
)
109 DisposeControl( m_controlHandle
);
110 m_controlHandle
= NULL
;
113 #if wxMAC_USE_NATIVE_TOOLBAR
114 m_toolbarItemRef
= NULL
;
118 wxSize
GetSize() const
124 curSize
= GetControl()->GetSize();
126 else if ( IsButton() )
128 curSize
= GetToolBar()->GetToolSize();
133 curSize
= GetToolBar()->GetToolSize();
134 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
143 wxPoint
GetPosition() const
145 return wxPoint( m_x
, m_y
);
148 bool DoEnable( bool enable
);
150 void UpdateToggleImage( bool toggle
);
152 #if wxMAC_USE_NATIVE_TOOLBAR
153 void SetToolbarItemRef( HIToolbarItemRef ref
)
155 if ( m_controlHandle
)
156 HideControl( m_controlHandle
);
157 if ( m_toolbarItemRef
)
158 CFRelease( m_toolbarItemRef
);
160 m_toolbarItemRef
= ref
;
161 if ( m_toolbarItemRef
)
163 HIToolbarItemSetHelpText(
165 wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ),
166 wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) );
170 HIToolbarItemRef
GetToolbarItemRef() const
172 return m_toolbarItemRef
;
175 void SetIndex( CFIndex idx
)
180 CFIndex
GetIndex() const
189 m_controlHandle
= NULL
;
191 #if wxMAC_USE_NATIVE_TOOLBAR
192 m_toolbarItemRef
= NULL
;
197 ControlRef m_controlHandle
;
201 #if wxMAC_USE_NATIVE_TOOLBAR
202 HIToolbarItemRef m_toolbarItemRef
;
203 // position in its toolbar, -1 means not inserted
208 static const EventTypeSpec eventList
[] =
210 { kEventClassControl
, kEventControlHit
},
212 { kEventClassControl
, kEventControlHitTest
},
216 static pascal OSStatus
wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
218 OSStatus result
= eventNotHandledErr
;
219 ControlRef controlRef
;
220 wxMacCarbonEvent
cEvent( event
);
222 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
);
224 switch ( GetEventKind( event
) )
226 case kEventControlHit
:
228 wxToolBarTool
*tbartool
= (wxToolBarTool
*)data
;
229 wxToolBar
*tbar
= tbartool
!= NULL
? (wxToolBar
*) (tbartool
->GetToolBar()) : NULL
;
230 if ((tbartool
!= NULL
) && tbartool
->CanBeToggled())
235 shouldToggle
= !tbartool
->IsToggled();
237 shouldToggle
= (GetControl32BitValue( (ControlRef
)(tbartool
->GetControlHandle()) ) != 0);
240 tbar
->ToggleTool( tbartool
->GetId(), shouldToggle
);
243 if (tbartool
!= NULL
)
244 tbar
->OnLeftClick( tbartool
->GetId(), tbartool
->IsToggled() );
250 case kEventControlHitTest
:
252 HIPoint pt
= cEvent
.GetParameter
<HIPoint
>(kEventParamMouseLocation
);
254 HIViewGetBounds( controlRef
, &rect
);
256 ControlPartCode pc
= kControlNoPart
;
257 if ( CGRectContainsPoint( rect
, pt
) )
258 pc
= kControlIconPart
;
259 cEvent
.SetParameter( kEventParamControlPart
, typeControlPartCode
, pc
);
272 static pascal OSStatus
wxMacToolBarToolEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
274 OSStatus result
= eventNotHandledErr
;
276 switch ( GetEventClass( event
) )
278 case kEventClassControl
:
279 result
= wxMacToolBarToolControlEventHandler( handler
, event
, data
);
289 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler
)
291 #if wxMAC_USE_NATIVE_TOOLBAR
293 static const EventTypeSpec toolBarEventList
[] =
295 { kEventClassToolbarItem
, kEventToolbarItemPerformAction
},
298 static pascal OSStatus
wxMacToolBarCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
300 OSStatus result
= eventNotHandledErr
;
302 switch ( GetEventKind( event
) )
304 case kEventToolbarItemPerformAction
:
306 wxToolBarTool
* tbartool
= (wxToolBarTool
*) data
;
307 if ( tbartool
!= NULL
)
309 wxToolBar
*tbar
= (wxToolBar
*)(tbartool
->GetToolBar());
310 int toolID
= tbartool
->GetId();
312 if ( tbartool
->CanBeToggled() )
315 tbar
->ToggleTool(toolID
, !tbartool
->IsToggled() );
319 tbar
->OnLeftClick( toolID
, tbartool
->IsToggled() );
332 static pascal OSStatus
wxMacToolBarEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
334 OSStatus result
= eventNotHandledErr
;
336 switch ( GetEventClass( event
) )
338 case kEventClassToolbarItem
:
339 result
= wxMacToolBarCommandEventHandler( handler
, event
, data
);
349 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler
)
353 bool wxToolBarTool::DoEnable( bool enable
)
357 GetControl()->Enable( enable
);
359 else if ( IsButton() )
361 #if wxMAC_USE_NATIVE_TOOLBAR
362 if ( m_toolbarItemRef
!= NULL
)
363 HIToolbarItemSetEnabled( m_toolbarItemRef
, enable
);
366 if ( m_controlHandle
!= NULL
)
368 #if TARGET_API_MAC_OSX
370 EnableControl( m_controlHandle
);
372 DisableControl( m_controlHandle
);
375 ActivateControl( m_controlHandle
);
377 DeactivateControl( m_controlHandle
);
385 void wxToolBarTool::SetPosition( const wxPoint
& position
)
392 int mac_x
= position
.x
;
393 int mac_y
= position
.y
;
398 GetControlBounds( m_controlHandle
, &contrlRect
);
399 int former_mac_x
= contrlRect
.left
;
400 int former_mac_y
= contrlRect
.top
;
401 GetToolBar()->GetToolSize();
403 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
405 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
408 else if ( IsControl() )
410 GetControl()->Move( position
);
417 GetControlBounds( m_controlHandle
, &contrlRect
);
418 int former_mac_x
= contrlRect
.left
;
419 int former_mac_y
= contrlRect
.top
;
421 if ( mac_x
!= former_mac_x
|| mac_y
!= former_mac_y
)
422 UMAMoveControl( m_controlHandle
, mac_x
, mac_y
);
427 void wxToolBarTool::UpdateToggleImage( bool toggle
)
429 #if wxMAC_USE_NATIVE_TOOLBAR
431 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
432 #define kHIToolbarItemSelected (1 << 7)
435 // FIXME: this should be a OSX v10.4 runtime check
436 if (m_toolbarItemRef
!= NULL
)
438 OptionBits addAttrs
, removeAttrs
;
443 addAttrs
= kHIToolbarItemSelected
;
444 removeAttrs
= kHIToolbarItemNoAttributes
;
448 addAttrs
= kHIToolbarItemNoAttributes
;
449 removeAttrs
= kHIToolbarItemSelected
;
452 result
= HIToolbarItemChangeAttributes( m_toolbarItemRef
, addAttrs
, removeAttrs
);
459 int w
= m_bmpNormal
.GetWidth();
460 int h
= m_bmpNormal
.GetHeight();
461 wxBitmap
bmp( w
, h
);
464 dc
.SelectObject( bmp
);
465 dc
.SetPen( wxNullPen
);
466 dc
.SetBackground( *wxWHITE
);
467 dc
.DrawRectangle( 0, 0, w
, h
);
468 dc
.DrawBitmap( m_bmpNormal
, 0, 0, true );
469 dc
.SelectObject( wxNullBitmap
);
470 ControlButtonContentInfo info
;
471 wxMacCreateBitmapButton( &info
, bmp
);
472 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
473 wxMacReleaseBitmapButton( &info
);
477 ControlButtonContentInfo info
;
478 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
479 SetControlData( m_controlHandle
, 0, kControlIconContentTag
, sizeof(info
), (Ptr
)&info
);
480 wxMacReleaseBitmapButton( &info
);
483 IconTransformType transform
= toggle
? kTransformSelected
: kTransformNone
;
485 m_controlHandle
, 0, kControlIconTransformTag
,
486 sizeof(transform
), (Ptr
)&transform
);
487 HIViewSetNeedsDisplay( m_controlHandle
, true );
490 ::SetControl32BitValue( m_controlHandle
, toggle
);
494 wxToolBarTool::wxToolBarTool(
497 const wxString
& label
,
498 const wxBitmap
& bmpNormal
,
499 const wxBitmap
& bmpDisabled
,
501 wxObject
*clientData
,
502 const wxString
& shortHelp
,
503 const wxString
& longHelp
)
506 tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
507 clientData
, shortHelp
, longHelp
)
513 #pragma mark Toolbar Implementation
515 wxToolBarToolBase
*wxToolBar::CreateTool(
517 const wxString
& label
,
518 const wxBitmap
& bmpNormal
,
519 const wxBitmap
& bmpDisabled
,
521 wxObject
*clientData
,
522 const wxString
& shortHelp
,
523 const wxString
& longHelp
)
525 return new wxToolBarTool(
526 this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
527 clientData
, shortHelp
, longHelp
);
530 wxToolBarToolBase
* wxToolBar::CreateTool( wxControl
*control
)
532 return new wxToolBarTool( this, control
);
535 void wxToolBar::Init()
539 m_defaultWidth
= kwxMacToolBarToolDefaultWidth
;
540 m_defaultHeight
= kwxMacToolBarToolDefaultHeight
;
542 #if wxMAC_USE_NATIVE_TOOLBAR
543 m_macHIToolbarRef
= NULL
;
544 m_macUsesNativeToolbar
= false;
548 #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
550 const EventTypeSpec kEvents
[] =
552 { kEventClassHIObject
, kEventHIObjectConstruct
},
553 { kEventClassHIObject
, kEventHIObjectInitialize
},
554 { kEventClassHIObject
, kEventHIObjectDestruct
},
556 { kEventClassToolbarItem
, kEventToolbarItemCreateCustomView
}
559 const EventTypeSpec kViewEvents
[] =
561 { kEventClassControl
, kEventControlGetSizeConstraints
}
564 struct ControlToolbarItem
566 HIToolbarItemRef toolbarItem
;
568 wxSize lastValidSize
;
571 static pascal OSStatus
ControlToolbarItemHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
573 OSStatus result
= eventNotHandledErr
;
574 ControlToolbarItem
* object
= (ControlToolbarItem
*)inUserData
;
576 switch ( GetEventClass( inEvent
) )
578 case kEventClassHIObject
:
579 switch ( GetEventKind( inEvent
) )
581 case kEventHIObjectConstruct
:
583 HIObjectRef toolbarItem
;
584 ControlToolbarItem
* item
;
586 GetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeHIObjectRef
, NULL
,
587 sizeof( HIObjectRef
), NULL
, &toolbarItem
);
589 item
= (ControlToolbarItem
*) malloc(sizeof(ControlToolbarItem
)) ;
590 item
->toolbarItem
= toolbarItem
;
591 item
->viewRef
= NULL
;
593 SetEventParameter( inEvent
, kEventParamHIObjectInstance
, typeVoidPtr
, sizeof( void * ), &item
);
599 case kEventHIObjectInitialize
:
600 result
= CallNextEventHandler( inCallRef
, inEvent
);
601 if ( result
== noErr
)
604 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
605 sizeof( CFTypeRef
), NULL
, &data
);
609 wxASSERT_MSG( CFDataGetLength( data
) == sizeof( viewRef
) , wxT("Illegal Data passed") ) ;
610 memcpy( &viewRef
, CFDataGetBytePtr( data
) , sizeof( viewRef
) ) ;
612 object
->viewRef
= (HIViewRef
) viewRef
;
618 case kEventHIObjectDestruct
:
625 case kEventClassToolbarItem
:
626 switch ( GetEventKind( inEvent
) )
628 case kEventToolbarItemCreateCustomView
:
630 HIViewRef viewRef
= object
->viewRef
;
632 HIViewRemoveFromSuperview( viewRef
) ;
633 HIViewSetVisible(viewRef
, true) ;
634 InstallEventHandler( GetControlEventTarget( viewRef
), ControlToolbarItemHandler
,
635 GetEventTypeCount( kViewEvents
), kViewEvents
, object
, NULL
);
637 result
= SetEventParameter( inEvent
, kEventParamControlRef
, typeControlRef
, sizeof( HIViewRef
), &viewRef
);
643 case kEventClassControl
:
644 switch ( GetEventKind( inEvent
) )
646 case kEventControlGetSizeConstraints
:
648 wxWindow
* wxwindow
= wxFindControlFromMacControl(object
->viewRef
) ;
651 wxSize sz
= wxwindow
->GetSize() ;
652 sz
.x
-= wxwindow
->MacGetLeftBorderSize() + wxwindow
->MacGetRightBorderSize();
653 sz
.y
-= wxwindow
->MacGetTopBorderSize() + wxwindow
->MacGetBottomBorderSize();
654 // during toolbar layout the native window sometimes gets negative sizes
655 // so we always keep the last valid size here, to make sure we survive the
657 if ( sz
.x
> 0 && sz
.y
> 0 )
658 object
->lastValidSize
= sz
;
660 sz
= object
->lastValidSize
;
663 min
.width
= max
.width
= sz
.x
;
664 min
.height
= max
.height
= sz
.y
;
666 result
= SetEventParameter( inEvent
, kEventParamMinimumSize
, typeHISize
,
667 sizeof( HISize
), &min
);
669 result
= SetEventParameter( inEvent
, kEventParamMaximumSize
, typeHISize
,
670 sizeof( HISize
), &max
);
682 void RegisterControlToolbarItemClass()
684 static bool sRegistered
;
688 HIObjectRegisterSubclass( kControlToolbarItemClassID
, kHIToolbarItemClassID
, 0,
689 ControlToolbarItemHandler
, GetEventTypeCount( kEvents
), kEvents
, 0, NULL
);
695 HIToolbarItemRef
CreateControlToolbarItem(CFStringRef inIdentifier
, CFTypeRef inConfigData
)
697 RegisterControlToolbarItemClass();
701 UInt32 options
= kHIToolbarItemAllowDuplicates
;
702 HIToolbarItemRef result
= NULL
;
704 err
= CreateEvent( NULL
, kEventClassHIObject
, kEventHIObjectInitialize
, GetCurrentEventTime(), 0, &event
);
705 require_noerr( err
, CantCreateEvent
);
707 SetEventParameter( event
, kEventParamAttributes
, typeUInt32
, sizeof( UInt32
), &options
);
708 SetEventParameter( event
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, sizeof( CFStringRef
), &inIdentifier
);
711 SetEventParameter( event
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, sizeof( CFTypeRef
), &inConfigData
);
713 err
= HIObjectCreate( kControlToolbarItemClassID
, event
, (HIObjectRef
*)&result
);
716 ReleaseEvent( event
);
721 static const EventTypeSpec kToolbarEvents
[] =
723 { kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
724 { kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
725 { kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
},
728 static OSStatus
ToolbarDelegateHandler( EventHandlerCallRef inCallRef
, EventRef inEvent
, void* inUserData
)
730 OSStatus result
= eventNotHandledErr
;
731 wxToolBar
* toolbar
= (wxToolBar
*) inUserData
;
732 CFMutableArrayRef array
;
734 switch ( GetEventKind( inEvent
) )
736 case kEventToolbarGetDefaultIdentifiers
:
738 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
739 sizeof( CFMutableArrayRef
), NULL
, &array
);
740 // not implemented yet
741 // GetToolbarDefaultItems( array );
746 case kEventToolbarGetAllowedIdentifiers
:
748 GetEventParameter( inEvent
, kEventParamMutableArray
, typeCFMutableArrayRef
, NULL
,
749 sizeof( CFMutableArrayRef
), NULL
, &array
);
750 // not implemented yet
751 // GetToolbarAllowedItems( array );
755 case kEventToolbarCreateItemWithIdentifier
:
757 HIToolbarItemRef item
= NULL
;
758 CFTypeRef data
= NULL
;
759 CFStringRef identifier
= NULL
;
761 GetEventParameter( inEvent
, kEventParamToolbarItemIdentifier
, typeCFStringRef
, NULL
,
762 sizeof( CFStringRef
), NULL
, &identifier
);
764 GetEventParameter( inEvent
, kEventParamToolbarItemConfigData
, typeCFTypeRef
, NULL
,
765 sizeof( CFTypeRef
), NULL
, &data
);
767 if ( CFStringCompare( kControlToolbarItemClassID
, identifier
, kCFCompareBackwards
) == kCFCompareEqualTo
)
769 item
= CreateControlToolbarItem( kControlToolbarItemClassID
, data
);
772 SetEventParameter( inEvent
, kEventParamToolbarItem
, typeHIToolbarItemRef
,
773 sizeof( HIToolbarItemRef
), &item
);
784 // also for the toolbar we have the dual implementation:
785 // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
787 bool wxToolBar::Create(
793 const wxString
& name
)
795 if ( !wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
798 OSStatus err
= noErr
;
800 #if wxMAC_USE_NATIVE_TOOLBAR
801 wxString labelStr
= wxString::Format( wxT("%xd"), (int)this );
802 err
= HIToolbarCreate(
803 wxMacCFStringHolder( labelStr
, wxFont::GetDefaultEncoding() ), 0,
804 (HIToolbarRef
*) &m_macHIToolbarRef
);
806 if (m_macHIToolbarRef
!= NULL
)
808 InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef
)m_macHIToolbarRef
), ToolbarDelegateHandler
,
809 GetEventTypeCount( kToolbarEvents
), kToolbarEvents
, this, NULL
);
811 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
812 HIToolbarDisplaySize displaySize
= kHIToolbarDisplaySizeSmall
;
814 if ( style
& wxTB_NOICONS
)
815 mode
= kHIToolbarDisplayModeLabelOnly
;
816 else if ( style
& wxTB_TEXT
)
817 mode
= kHIToolbarDisplayModeIconAndLabel
;
819 mode
= kHIToolbarDisplayModeIconOnly
;
821 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
822 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, displaySize
);
826 return (err
== noErr
);
829 wxToolBar::~wxToolBar()
831 #if wxMAC_USE_NATIVE_TOOLBAR
832 if (m_macHIToolbarRef
!= NULL
)
834 // if this is the installed toolbar, then deinstall it
835 if (m_macUsesNativeToolbar
)
836 MacInstallNativeToolbar( false );
838 CFRelease( (HIToolbarRef
)m_macHIToolbarRef
);
839 m_macHIToolbarRef
= NULL
;
844 bool wxToolBar::Show( bool show
)
846 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
847 bool bResult
= (tlw
!= NULL
);
851 #if wxMAC_USE_NATIVE_TOOLBAR
852 bool ownToolbarInstalled
= false;
853 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
854 if (ownToolbarInstalled
)
856 bResult
= (IsWindowToolbarVisible( tlw
) != show
);
858 ShowHideWindowToolbar( tlw
, show
, false );
861 bResult
= wxToolBarBase::Show( show
);
864 bResult
= wxToolBarBase::Show( show
);
871 bool wxToolBar::IsShown() const
875 #if wxMAC_USE_NATIVE_TOOLBAR
876 bool ownToolbarInstalled
;
878 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
879 if (ownToolbarInstalled
)
881 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
882 bResult
= IsWindowToolbarVisible( tlw
);
885 bResult
= wxToolBarBase::IsShown();
888 bResult
= wxToolBarBase::IsShown();
894 void wxToolBar::DoGetSize( int *width
, int *height
) const
896 #if wxMAC_USE_NATIVE_TOOLBAR
898 bool ownToolbarInstalled
;
900 MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
901 if ( ownToolbarInstalled
)
903 // TODO: is this really a control ?
904 GetControlBounds( (ControlRef
) m_macHIToolbarRef
, &boundsR
);
906 *width
= boundsR
.right
- boundsR
.left
;
907 if ( height
!= NULL
)
908 *height
= boundsR
.bottom
- boundsR
.top
;
911 wxToolBarBase::DoGetSize( width
, height
);
914 wxToolBarBase::DoGetSize( width
, height
);
918 wxSize
wxToolBar::DoGetBestSize() const
922 DoGetSize( &width
, &height
);
924 return wxSize( width
, height
);
927 void wxToolBar::SetWindowStyleFlag( long style
)
929 wxToolBarBase::SetWindowStyleFlag( style
);
931 #if wxMAC_USE_NATIVE_TOOLBAR
932 if (m_macHIToolbarRef
!= NULL
)
934 HIToolbarDisplayMode mode
= kHIToolbarDisplayModeDefault
;
936 if ( style
& wxTB_NOICONS
)
937 mode
= kHIToolbarDisplayModeLabelOnly
;
938 else if ( style
& wxTB_TEXT
)
939 mode
= kHIToolbarDisplayModeIconAndLabel
;
941 mode
= kHIToolbarDisplayModeIconOnly
;
943 HIToolbarSetDisplayMode( (HIToolbarRef
) m_macHIToolbarRef
, mode
);
948 #if wxMAC_USE_NATIVE_TOOLBAR
949 bool wxToolBar::MacWantsNativeToolbar()
951 return m_macUsesNativeToolbar
;
954 bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled
) const
956 bool bResultV
= false;
958 if (ownToolbarInstalled
!= NULL
)
959 *ownToolbarInstalled
= false;
961 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
964 HIToolbarRef curToolbarRef
= NULL
;
965 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
966 bResultV
= ((err
== noErr
) && (curToolbarRef
!= NULL
));
967 if (bResultV
&& (ownToolbarInstalled
!= NULL
))
968 *ownToolbarInstalled
= (curToolbarRef
== m_macHIToolbarRef
);
974 bool wxToolBar::MacInstallNativeToolbar(bool usesNative
)
976 bool bResult
= false;
978 if (usesNative
&& (m_macHIToolbarRef
== NULL
))
981 if (usesNative
&& ((GetWindowStyleFlag() & wxTB_VERTICAL
) != 0))
984 WindowRef tlw
= MAC_WXHWND(MacGetTopLevelWindowRef());
988 // check the existing toolbar
989 HIToolbarRef curToolbarRef
= NULL
;
990 OSStatus err
= GetWindowToolbar( tlw
, &curToolbarRef
);
992 curToolbarRef
= NULL
;
994 m_macUsesNativeToolbar
= usesNative
;
996 if (m_macUsesNativeToolbar
)
998 // only install toolbar if there isn't one installed already
999 if (curToolbarRef
== NULL
)
1003 SetWindowToolbar( tlw
, (HIToolbarRef
) m_macHIToolbarRef
);
1004 ShowHideWindowToolbar( tlw
, true, false );
1005 ChangeWindowAttributes( tlw
, kWindowToolbarButtonAttribute
, 0 );
1006 SetAutomaticControlDragTrackingEnabledForWindow( tlw
, true );
1008 Rect r
= { 0, 0, 0, 0 };
1009 m_peer
->SetRect( &r
);
1010 SetSize( wxSIZE_AUTO_WIDTH
, 0 );
1011 m_peer
->SetVisibility( false, true );
1012 wxToolBarBase::Show( false );
1017 // only deinstall toolbar if this is the installed one
1018 if (m_macHIToolbarRef
== curToolbarRef
)
1022 ShowHideWindowToolbar( tlw
, false, false );
1023 ChangeWindowAttributes( tlw
, 0, kWindowToolbarButtonAttribute
);
1024 SetWindowToolbar( tlw
, NULL
);
1026 m_peer
->SetVisibility( true, true );
1031 InvalidateBestSize();
1033 // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
1038 bool wxToolBar::Realize()
1040 if (m_tools
.GetCount() == 0)
1046 int maxToolWidth
= 0;
1047 int maxToolHeight
= 0;
1049 int x
= m_xMargin
+ kwxMacToolBarLeftMargin
;
1050 int y
= m_yMargin
+ kwxMacToolBarTopMargin
;
1053 GetSize( &tw
, &th
);
1055 // find the maximum tool width and height
1056 wxToolBarTool
*tool
;
1057 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1058 while ( node
!= NULL
)
1060 tool
= (wxToolBarTool
*) node
->GetData();
1063 wxSize sz
= tool
->GetSize();
1065 if ( sz
.x
> maxToolWidth
)
1066 maxToolWidth
= sz
.x
;
1067 if ( sz
.y
> maxToolHeight
)
1068 maxToolHeight
= sz
.y
;
1071 node
= node
->GetNext();
1074 bool lastIsRadio
= false;
1075 bool curIsRadio
= false;
1076 bool setChoiceInGroup
= false;
1078 #if wxMAC_USE_NATIVE_TOOLBAR
1079 CFIndex currentPosition
= 0;
1080 bool insertAll
= false;
1083 node
= m_tools
.GetFirst();
1084 while ( node
!= NULL
)
1086 tool
= (wxToolBarTool
*) node
->GetData();
1089 node
= node
->GetNext();
1093 // set tool position:
1094 // for the moment just perform a single row/column alignment
1095 wxSize cursize
= tool
->GetSize();
1096 if ( x
+ cursize
.x
> maxWidth
)
1097 maxWidth
= x
+ cursize
.x
;
1098 if ( y
+ cursize
.y
> maxHeight
)
1099 maxHeight
= y
+ cursize
.y
;
1101 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1103 int x1
= x
+ ( maxToolWidth
- cursize
.x
) / 2;
1104 tool
->SetPosition( wxPoint(x1
, y
) );
1108 int y1
= y
+ ( maxToolHeight
- cursize
.y
) / 2;
1109 tool
->SetPosition( wxPoint(x
, y1
) );
1112 // update the item positioning state
1113 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1114 y
+= cursize
.y
+ kwxMacToolSpacing
;
1116 x
+= cursize
.x
+ kwxMacToolSpacing
;
1118 #if wxMAC_USE_NATIVE_TOOLBAR
1119 // install in native HIToolbar
1120 if ( m_macHIToolbarRef
!= NULL
)
1122 HIToolbarItemRef hiItemRef
= tool
->GetToolbarItemRef();
1123 if ( hiItemRef
!= NULL
)
1125 if ( insertAll
|| (tool
->GetIndex() != currentPosition
) )
1127 OSStatus err
= noErr
;
1132 // if this is the first tool that gets newly inserted or repositioned
1133 // first remove all 'old' tools from here to the right, because of this
1134 // all following tools will have to be reinserted (insertAll). i = 100 because there's
1135 // no way to determine how many there are in a toolbar, so just a high number :-(
1136 for ( CFIndex i
= 100; i
>= currentPosition
; --i
)
1138 err
= HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, i
);
1143 wxString errMsg
= wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err
);
1144 wxFAIL_MSG( errMsg
.c_str() );
1148 err
= HIToolbarInsertItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, hiItemRef
, currentPosition
);
1151 wxString errMsg
= wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err
);
1152 wxFAIL_MSG( errMsg
.c_str() );
1155 tool
->SetIndex( currentPosition
);
1163 // update radio button (and group) state
1164 lastIsRadio
= curIsRadio
;
1165 curIsRadio
= ( tool
->IsButton() && (tool
->GetKind() == wxITEM_RADIO
) );
1169 if ( tool
->IsToggled() )
1170 DoToggleTool( tool
, true );
1172 setChoiceInGroup
= false;
1178 if ( tool
->Toggle( true ) )
1180 DoToggleTool( tool
, true );
1181 setChoiceInGroup
= true;
1184 else if ( tool
->IsToggled() )
1186 if ( tool
->IsToggled() )
1187 DoToggleTool( tool
, true );
1189 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
1190 while ( nodePrev
!= NULL
)
1192 wxToolBarToolBase
*toggleTool
= nodePrev
->GetData();
1193 if ( (toggleTool
== NULL
) || !toggleTool
->IsButton() || (toggleTool
->GetKind() != wxITEM_RADIO
) )
1196 if ( toggleTool
->Toggle( false ) )
1197 DoToggleTool( toggleTool
, false );
1199 nodePrev
= nodePrev
->GetPrevious();
1204 node
= node
->GetNext();
1207 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
1209 // if not set yet, only one row
1210 if ( m_maxRows
<= 0 )
1213 m_minWidth
= maxWidth
;
1215 maxHeight
+= m_yMargin
+ kwxMacToolBarTopMargin
;
1216 m_minHeight
= m_maxHeight
= maxHeight
;
1220 // if not set yet, have one column
1221 if ( (GetToolsCount() > 0) && (m_maxRows
<= 0) )
1222 SetRows( GetToolsCount() );
1224 m_minHeight
= maxHeight
;
1226 maxWidth
+= m_xMargin
+ kwxMacToolBarLeftMargin
;
1227 m_minWidth
= m_maxWidth
= maxWidth
;
1231 // FIXME: should this be OSX-only?
1233 bool wantNativeToolbar
, ownToolbarInstalled
;
1235 // attempt to install the native toolbar
1236 wantNativeToolbar
= ((GetWindowStyleFlag() & wxTB_VERTICAL
) == 0);
1237 MacInstallNativeToolbar( wantNativeToolbar
);
1238 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled
);
1239 if (!ownToolbarInstalled
)
1241 SetSize( maxWidth
, maxHeight
);
1242 InvalidateBestSize();
1246 SetSize( maxWidth
, maxHeight
);
1247 InvalidateBestSize();
1250 SetBestFittingSize();
1255 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1257 m_defaultWidth
= size
.x
+ kwxMacToolBorder
;
1258 m_defaultHeight
= size
.y
+ kwxMacToolBorder
;
1260 #if wxMAC_USE_NATIVE_TOOLBAR
1261 if (m_macHIToolbarRef
!= NULL
)
1263 int maxs
= wxMax( size
.x
, size
.y
);
1264 HIToolbarDisplaySize sizeSpec
;
1266 sizeSpec
= kHIToolbarDisplaySizeNormal
;
1267 else if ( maxs
> 24 )
1268 sizeSpec
= kHIToolbarDisplaySizeDefault
;
1270 sizeSpec
= kHIToolbarDisplaySizeSmall
;
1272 HIToolbarSetDisplaySize( (HIToolbarRef
) m_macHIToolbarRef
, sizeSpec
);
1277 // The button size is bigger than the bitmap size
1278 wxSize
wxToolBar::GetToolSize() const
1280 return wxSize(m_defaultWidth
+ kwxMacToolBorder
, m_defaultHeight
+ kwxMacToolBorder
);
1283 void wxToolBar::SetRows(int nRows
)
1285 // avoid resizing the frame uselessly
1286 if ( nRows
!= m_maxRows
)
1290 void wxToolBar::MacSuperChangedPosition()
1292 wxWindow::MacSuperChangedPosition();
1294 #if wxMAC_USE_NATIVE_TOOLBAR
1295 if (! m_macUsesNativeToolbar
)
1303 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1305 wxToolBarTool
*tool
;
1306 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
1307 while ( node
!= NULL
)
1309 tool
= (wxToolBarTool
*)node
->GetData();
1312 wxRect2DInt
r( tool
->GetPosition(), tool
->GetSize() );
1313 if ( r
.Contains( wxPoint( x
, y
) ) )
1317 node
= node
->GetNext();
1320 return (wxToolBarToolBase
*)NULL
;
1323 wxString
wxToolBar::MacGetToolTipString( wxPoint
&pt
)
1325 wxToolBarToolBase
*tool
= FindToolForPosition( pt
.x
, pt
.y
);
1327 return tool
->GetShortHelp();
1329 return wxEmptyString
;
1332 void wxToolBar::DoEnableTool(wxToolBarToolBase
*t
, bool enable
)
1335 ((wxToolBarTool
*)t
)->DoEnable( enable
);
1338 void wxToolBar::DoToggleTool(wxToolBarToolBase
*t
, bool toggle
)
1340 wxToolBarTool
*tool
= (wxToolBarTool
*)t
;
1341 if ( ( tool
!= NULL
) && tool
->IsButton() )
1342 tool
->UpdateToggleImage( toggle
);
1345 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolBase
)
1347 wxToolBarTool
*tool
= wx_static_cast( wxToolBarTool
*, toolBase
);
1351 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef();
1352 wxSize toolSize
= GetToolSize();
1353 Rect toolrect
= { 0, 0, toolSize
.y
, toolSize
.x
};
1354 ControlRef controlHandle
= NULL
;
1357 switch (tool
->GetStyle())
1359 case wxTOOL_STYLE_SEPARATOR
:
1361 wxASSERT( tool
->GetControlHandle() == NULL
);
1364 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1365 toolrect
.bottom
= toolSize
.y
;
1367 toolrect
.right
= toolSize
.x
;
1369 #ifdef __WXMAC_OSX__
1370 // in flat style we need a visual separator
1371 #if wxMAC_USE_NATIVE_TOOLBAR
1372 HIToolbarItemRef item
;
1373 err
= HIToolbarItemCreate(
1374 kHIToolbarSeparatorIdentifier
,
1375 kHIToolbarItemCantBeRemoved
| kHIToolbarItemIsSeparator
| kHIToolbarItemAllowDuplicates
,
1378 tool
->SetToolbarItemRef( item
);
1381 CreateSeparatorControl( window
, &toolrect
, &controlHandle
);
1382 tool
->SetControlHandle( controlHandle
);
1387 case wxTOOL_STYLE_BUTTON
:
1389 wxASSERT( tool
->GetControlHandle() == NULL
);
1390 ControlButtonContentInfo info
;
1391 wxMacCreateBitmapButton( &info
, tool
->GetNormalBitmap(), kControlContentIconRef
);
1393 if ( UMAGetSystemVersion() >= 0x1000)
1395 CreateIconControl( window
, &toolrect
, &info
, false, &controlHandle
);
1399 SInt16 behaviour
= kControlBehaviorOffsetContents
;
1400 if ( tool
->CanBeToggled() )
1401 behaviour
|= kControlBehaviorToggles
;
1402 err
= CreateBevelButtonControl( window
,
1403 &toolrect
, CFSTR(""), kControlBevelButtonNormalBevel
,
1404 behaviour
, &info
, 0, 0, 0, &controlHandle
);
1407 #if wxMAC_USE_NATIVE_TOOLBAR
1408 HIToolbarItemRef item
;
1409 wxString labelStr
= wxString::Format(wxT("%xd"), (int)tool
);
1410 err
= HIToolbarItemCreate(
1411 wxMacCFStringHolder(labelStr
, wxFont::GetDefaultEncoding()),
1412 kHIToolbarItemCantBeRemoved
| kHIToolbarItemAnchoredLeft
| kHIToolbarItemAllowDuplicates
, &item
);
1415 InstallEventHandler(
1416 HIObjectGetEventTarget(item
), GetwxMacToolBarEventHandlerUPP(),
1417 GetEventTypeCount(toolBarEventList
), toolBarEventList
, tool
, NULL
);
1418 HIToolbarItemSetLabel( item
, wxMacCFStringHolder(tool
->GetLabel(), m_font
.GetEncoding()) );
1419 HIToolbarItemSetIconRef( item
, info
.u
.iconRef
);
1420 HIToolbarItemSetCommandID( item
, kHIToolbarCommandPressAction
);
1421 tool
->SetToolbarItemRef( item
);
1425 wxMacReleaseBitmapButton( &info
);
1428 SetBevelButtonTextPlacement( m_controlHandle
, kControlBevelButtonPlaceBelowGraphic
);
1429 UMASetControlTitle( m_controlHandle
, label
, wxFont::GetDefaultEncoding() );
1432 InstallControlEventHandler(
1433 (ControlRef
) controlHandle
, GetwxMacToolBarToolEventHandlerUPP(),
1434 GetEventTypeCount(eventList
), eventList
, tool
, NULL
);
1436 tool
->SetControlHandle( controlHandle
);
1440 case wxTOOL_STYLE_CONTROL
:
1442 #if wxMAC_USE_NATIVE_TOOLBAR
1444 wxASSERT( tool
->GetControl() != NULL
);
1445 HIToolbarItemRef item
;
1446 HIViewRef viewRef
= (HIViewRef
) tool
->GetControl()->GetHandle() ;
1447 CFDataRef data
= CFDataCreate( kCFAllocatorDefault
, (UInt8
*) &viewRef
, sizeof(viewRef
) ) ;
1448 err
= HIToolbarCreateItemWithIdentifier((HIToolbarRef
) m_macHIToolbarRef
,kControlToolbarItemClassID
,
1453 tool
->SetToolbarItemRef( item
);
1459 // right now there's nothing to do here
1469 if ( controlHandle
)
1471 ControlRef container
= (ControlRef
) GetHandle();
1472 wxASSERT_MSG( container
!= NULL
, wxT("No valid Mac container control") );
1474 UMAShowControl( controlHandle
);
1475 ::EmbedControl( controlHandle
, container
);
1478 if ( tool
->CanBeToggled() && tool
->IsToggled() )
1479 tool
->UpdateToggleImage( true );
1481 // nothing special to do here - we relayout in Realize() later
1482 tool
->Attach( this );
1483 InvalidateBestSize();
1487 wxString errMsg
= wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err
);
1488 wxFAIL_MSG( errMsg
.c_str() );
1491 return (err
== noErr
);
1494 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1496 wxFAIL_MSG( wxT("not implemented") );
1499 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*toolbase
)
1501 wxToolBarTool
* tool
= wx_static_cast( wxToolBarTool
*, toolbase
);
1502 wxToolBarToolsList::compatibility_iterator node
;
1503 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1505 wxToolBarToolBase
*tool2
= node
->GetData();
1506 if ( tool2
== tool
)
1508 // let node point to the next node in the list
1509 node
= node
->GetNext();
1515 wxSize sz
= ((wxToolBarTool
*)tool
)->GetSize();
1519 #if wxMAC_USE_NATIVE_TOOLBAR
1520 CFIndex removeIndex
= tool
->GetIndex();
1523 switch ( tool
->GetStyle() )
1525 case wxTOOL_STYLE_CONTROL
:
1527 tool
->GetControl()->Destroy();
1528 tool
->ClearControl();
1532 case wxTOOL_STYLE_BUTTON
:
1533 case wxTOOL_STYLE_SEPARATOR
:
1534 if ( tool
->GetControlHandle() )
1536 #if wxMAC_USE_NATIVE_TOOLBAR
1537 if ( removeIndex
!= -1 && m_macHIToolbarRef
)
1539 HIToolbarRemoveItemAtIndex( (HIToolbarRef
) m_macHIToolbarRef
, removeIndex
);
1540 tool
->SetIndex( -1 );
1544 tool
->ClearControl();
1552 // and finally reposition all the controls after this one
1554 for ( /* node -> first after deleted */; node
; node
= node
->GetNext() )
1556 wxToolBarTool
*tool2
= (wxToolBarTool
*) node
->GetData();
1557 wxPoint pt
= tool2
->GetPosition();
1559 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
1564 tool2
->SetPosition( pt
);
1566 #if wxMAC_USE_NATIVE_TOOLBAR
1567 if ( removeIndex
!= -1 && tool2
->GetIndex() > removeIndex
)
1568 tool2
->SetIndex( tool2
->GetIndex() - 1 );
1572 InvalidateBestSize();
1577 void wxToolBar::OnPaint(wxPaintEvent
& event
)
1579 #if wxMAC_USE_NATIVE_TOOLBAR
1580 if ( m_macUsesNativeToolbar
)
1592 bool drawMetalTheme
= MacGetTopLevelWindow()->MacGetMetalAppearance();
1593 bool minimumUmaAvailable
= (UMAGetSystemVersion() >= 0x1030);
1595 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1596 if ( !drawMetalTheme
&& minimumUmaAvailable
)
1598 HIThemePlacardDrawInfo info
;
1599 memset( &info
, 0, sizeof(info
) );
1601 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1603 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef();
1604 HIRect rect
= CGRectMake( 0, 0, w
, h
);
1605 HIThemeDrawPlacard( &rect
, &info
, cgContext
, kHIThemeOrientationNormal
);
1609 // leave the background as it is (striped or metal)
1614 const bool drawBorder
= true;
1618 wxMacPortSetter
helper( &dc
);
1620 if ( !drawMetalTheme
|| !minimumUmaAvailable
)
1622 Rect toolbarrect
= { dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1623 dc
.YLOG2DEVMAC(h
), dc
.XLOG2DEVMAC(w
) };
1626 if ( toolbarrect
.left
< 0 )
1627 toolbarrect
.left
= 0;
1628 if ( toolbarrect
.top
< 0 )
1629 toolbarrect
.top
= 0;
1632 UMADrawThemePlacard( &toolbarrect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
);
1636 #if TARGET_API_MAC_OSX
1637 HIRect hiToolbarrect
= CGRectMake(
1638 dc
.YLOG2DEVMAC(0), dc
.XLOG2DEVMAC(0),
1639 dc
.YLOG2DEVREL(h
), dc
.XLOG2DEVREL(w
) );
1640 CGContextRef cgContext
;
1643 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
1644 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1646 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
1647 CGContextScaleCTM( cgContext
, 1, -1 );
1649 HIThemeBackgroundDrawInfo drawInfo
;
1650 drawInfo
.version
= 0;
1651 drawInfo
.state
= kThemeStateActive
;
1652 drawInfo
.kind
= kThemeBackgroundMetal
;
1653 HIThemeApplyBackground( &hiToolbarrect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
1655 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
1664 #endif // wxUSE_TOOLBAR