#include "wx/app.h"
#include "wx/mac/uma.h"
#include "wx/geometry.h"
+#include "wx/sysopt.h"
#ifdef __WXMAC_OSX__
if ( m_toolbarItemRef )
{
CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ;
- wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
+ // different behaviour under Leopard
+ if ( UMAGetSystemVersion() < 0x1050 )
+ {
+ wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );
+ }
wxTheApp->MacAddToAutorelease(m_toolbarItemRef);
CFRelease(m_toolbarItemRef);
m_toolbarItemRef = NULL;
#endif
};
-static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
+static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef WXUNUSED(handler), EventRef event, void *data )
{
OSStatus result = eventNotHandledErr;
ControlRef controlRef;
{ kEventClassToolbarItem, kEventToolbarItemPerformAction },
};
-static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
+static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef WXUNUSED(handler), EventRef event, void *data )
{
OSStatus result = eventNotHandledErr;
dc.DrawBitmap( m_bmpNormal, 0, 0, true );
dc.SelectObject( wxNullBitmap );
ControlButtonContentInfo info;
- wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef );
+ wxMacCreateBitmapButton( &info, bmp );
SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
#if wxMAC_USE_NATIVE_TOOLBAR
if (m_toolbarItemRef != NULL)
{
- HIToolbarItemSetIconRef( m_toolbarItemRef, info.u.iconRef );
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, bmp, kControlContentCGImageRef);
+ HIToolbarItemSetImage( m_toolbarItemRef, info2.u.imageRef );
+ wxMacReleaseBitmapButton( &info2 );
}
#endif
wxMacReleaseBitmapButton( &info );
else
{
ControlButtonContentInfo info;
- wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
+ wxMacCreateBitmapButton( &info, m_bmpNormal );
SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
#if wxMAC_USE_NATIVE_TOOLBAR
if (m_toolbarItemRef != NULL)
{
- HIToolbarItemSetIconRef( m_toolbarItemRef, info.u.iconRef );
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, m_bmpNormal, kControlContentCGImageRef);
+ HIToolbarItemSetImage( m_toolbarItemRef, info2.u.imageRef );
+ wxMacReleaseBitmapButton( &info2 );
}
#endif
wxMacReleaseBitmapButton( &info );
sz = wxSize(0,0) ;
}
+ // Extra width to avoid edge of combobox being cut off
+ sz.x += 3;
+
HISize min, max;
min.width = max.width = sz.x ;
min.height = max.height = sz.y ;
{ kEventClassToolbar, kEventToolbarCreateItemWithIdentifier },
};
-static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
+static OSStatus ToolbarDelegateHandler(EventHandlerCallRef WXUNUSED(inCallRef),
+ EventRef inEvent,
+ void* WXUNUSED(inUserData))
{
OSStatus result = eventNotHandledErr;
// Not yet needed
OSStatus err = noErr;
#if wxMAC_USE_NATIVE_TOOLBAR
- wxString labelStr = wxString::Format( wxT("%xd"), (int)this );
- err = HIToolbarCreate(
- wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ), 0,
- (HIToolbarRef*) &m_macHIToolbarRef );
-
- if (m_macHIToolbarRef != NULL)
+ if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
{
- InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler,
- GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL );
+ wxString labelStr = wxString::Format( wxT("%p"), this );
+ err = HIToolbarCreate(
+ wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ), 0,
+ (HIToolbarRef*) &m_macHIToolbarRef );
- HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
- HIToolbarDisplaySize displaySize = kHIToolbarDisplaySizeSmall;
+ if (m_macHIToolbarRef != NULL)
+ {
+ InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler,
+ GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL );
- if ( style & wxTB_NOICONS )
- mode = kHIToolbarDisplayModeLabelOnly;
- else if ( style & wxTB_TEXT )
- mode = kHIToolbarDisplayModeIconAndLabel;
- else
- mode = kHIToolbarDisplayModeIconOnly;
+ HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
+ HIToolbarDisplaySize displaySize = kHIToolbarDisplaySizeSmall;
- HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
- HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
+ if ( style & wxTB_NOICONS )
+ mode = kHIToolbarDisplayModeLabelOnly;
+ else if ( style & wxTB_TEXT )
+ mode = kHIToolbarDisplayModeIconAndLabel;
+ else
+ mode = kHIToolbarDisplayModeIconOnly;
+
+ HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
+ HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
+ }
}
#endif // wxMAC_USE_NATIVE_TOOLBAR
MacInstallNativeToolbar( false );
CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ;
- wxASSERT_MSG( count == 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
-
+ // Leopard seems to have one refcount more, so we cannot check reliably at the moment
+ if ( UMAGetSystemVersion() < 0x1050 )
+ {
+ wxASSERT_MSG( count == 1 , wxT("Reference Count of native control was not 1 in wxToolBar destructor") );
+ }
CFRelease( (HIToolbarRef)m_macHIToolbarRef );
m_macHIToolbarRef = NULL;
}
tool->Attach( this );
#if wxMAC_USE_NATIVE_TOOLBAR
- HIToolbarItemRef item;
-#endif
+ wxString label = tool->GetLabel();
+ if (m_macHIToolbarRef && !label.empty() )
+ {
+ // strip mnemonics from the label for compatibility
+ // with the usual labels in wxStaticText sense
+ label = wxStripMenuCodes(label);
+ }
+#endif // wxMAC_USE_NATIVE_TOOLBAR
switch (tool->GetStyle())
{
// in flat style we need a visual separator
#if wxMAC_USE_NATIVE_TOOLBAR
- err = HIToolbarItemCreate(
- kHIToolbarSeparatorIdentifier,
- kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
- &item );
- if (err == noErr)
- tool->SetToolbarItemRef( item );
+ if (m_macHIToolbarRef != NULL)
+ {
+ err = HIToolbarItemCreate(
+ kHIToolbarSeparatorIdentifier,
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
+ &item );
+ if (err == noErr)
+ tool->SetToolbarItemRef( item );
+ }
+ else
+ err = noErr;
#endif // wxMAC_USE_NATIVE_TOOLBAR
CreateSeparatorControl( window, &toolrect, &controlHandle );
{
wxASSERT( tool->GetControlHandle() == NULL );
ControlButtonContentInfo info;
- wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef );
+ wxMacCreateBitmapButton( &info, tool->GetNormalBitmap() );
if ( UMAGetSystemVersion() >= 0x1000)
{
+ // contrary to the docs this control only works with iconrefs
+ ControlButtonContentInfo info;
+ wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef );
CreateIconControl( window, &toolrect, &info, false, &controlHandle );
+ wxMacReleaseBitmapButton( &info );
}
else
{
}
#if wxMAC_USE_NATIVE_TOOLBAR
- wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
- err = HIToolbarItemCreate(
- wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
- kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
- if (err == noErr)
+ if (m_macHIToolbarRef != NULL)
{
- InstallEventHandler(
- HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
- GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
-
- HIToolbarItemSetIconRef( item, info.u.iconRef );
- HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
- tool->SetToolbarItemRef( item );
+ HIToolbarItemRef item;
+ wxString labelStr = wxString::Format(wxT("%p"), tool);
+ err = HIToolbarItemCreate(
+ wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
+ kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
+ if (err == noErr)
+ {
+ ControlButtonContentInfo info2;
+ wxMacCreateBitmapButton( &info2, tool->GetNormalBitmap(), kControlContentCGImageRef);
+
+ InstallEventHandler(
+ HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
+ GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
+ HIToolbarItemSetLabel( item, wxMacCFStringHolder(label, m_font.GetEncoding()) );
+ HIToolbarItemSetImage( item, info2.u.imageRef );
+ HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
+ tool->SetToolbarItemRef( item );
+
+ wxMacReleaseBitmapButton( &info2 );
+ }
}
+ else
+ err = noErr;
#endif // wxMAC_USE_NATIVE_TOOLBAR
wxMacReleaseBitmapButton( &info );
case wxTOOL_STYLE_CONTROL:
#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
{
wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") );
-
+ HIToolbarItemRef item;
HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID,
}
CFRelease( data ) ;
}
-
+ else
+ {
+ err = noErr;
+ break;
+ }
#else
// right now there's nothing to do here
#endif
break;
}
-#if wxMAC_USE_NATIVE_TOOLBAR
- wxString label = tool->GetLabel();
- if ( !label.empty() )
- {
- // strip mnemonics from the label for compatibility
- // with the usual labels in wxStaticText sense
- label = wxStripMenuCodes(label);
-
- HIToolbarItemSetLabel(item,
- wxMacCFStringHolder(label, m_font.GetEncoding()));
- }
-#endif // wxMAC_USE_NATIVE_TOOLBAR
-
if ( err == noErr )
{
if ( controlHandle )
#endif
#if wxMAC_USE_NATIVE_TOOLBAR
- if ( removeIndex != -1 && m_macHIToolbarRef )
+ if (m_macHIToolbarRef != NULL)
{
- HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
- tool->SetIndex( -1 );
+ if ( removeIndex != -1 && m_macHIToolbarRef )
+ {
+ HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
+ tool->SetIndex( -1 );
+ }
}
#endif
switch ( tool->GetStyle() )
tool2->SetPosition( pt );
#if wxMAC_USE_NATIVE_TOOLBAR
- if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
- tool2->SetIndex( tool2->GetIndex() - 1 );
+ if (m_macHIToolbarRef != NULL)
+ {
+ if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
+ tool2->SetIndex( tool2->GetIndex() - 1 );
+ }
#endif
}