Fixed uninstalled toolbars in native toolbar mode, with a method for
specifying non-native if required Added code to toolbar sample for testing uninstalled toolbar git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46558 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "wx/app.h"
|
||||
#include "wx/mac/uma.h"
|
||||
#include "wx/geometry.h"
|
||||
#include "wx/sysopt.h"
|
||||
|
||||
|
||||
#ifdef __WXMAC_OSX__
|
||||
@@ -847,28 +848,31 @@ bool wxToolBar::Create(
|
||||
OSStatus err = noErr;
|
||||
|
||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||
wxString labelStr = wxString::Format( wxT("%p"), 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
|
||||
|
||||
@@ -1471,13 +1475,18 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
#ifdef __WXMAC_OSX__
|
||||
// in flat style we need a visual separator
|
||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||
HIToolbarItemRef item;
|
||||
err = HIToolbarItemCreate(
|
||||
kHIToolbarSeparatorIdentifier,
|
||||
kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
|
||||
&item );
|
||||
if (err == noErr)
|
||||
tool->SetToolbarItemRef( item );
|
||||
if (m_macHIToolbarRef != NULL)
|
||||
{
|
||||
HIToolbarItemRef item;
|
||||
err = HIToolbarItemCreate(
|
||||
kHIToolbarSeparatorIdentifier,
|
||||
kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
|
||||
&item );
|
||||
if (err == noErr)
|
||||
tool->SetToolbarItemRef( item );
|
||||
}
|
||||
else
|
||||
err = noErr;
|
||||
#endif
|
||||
|
||||
CreateSeparatorControl( window, &toolrect, &controlHandle );
|
||||
@@ -1511,24 +1520,29 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
}
|
||||
|
||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||
HIToolbarItemRef item;
|
||||
wxString labelStr = wxString::Format(wxT("%p"), 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 );
|
||||
HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
|
||||
if ( info.contentType == kControlContentIconRef )
|
||||
HIToolbarItemSetIconRef( item, info.u.iconRef );
|
||||
else
|
||||
HIToolbarItemSetImage( item, info.u.imageRef );
|
||||
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)
|
||||
{
|
||||
InstallEventHandler(
|
||||
HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
|
||||
GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
|
||||
HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
|
||||
if ( info.contentType == kControlContentIconRef )
|
||||
HIToolbarItemSetIconRef( item, info.u.iconRef );
|
||||
else
|
||||
HIToolbarItemSetImage( item, info.u.imageRef );
|
||||
HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
|
||||
tool->SetToolbarItemRef( item );
|
||||
}
|
||||
}
|
||||
else
|
||||
err = noErr;
|
||||
#endif
|
||||
|
||||
wxMacReleaseBitmapButton( &info );
|
||||
@@ -1549,6 +1563,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
case wxTOOL_STYLE_CONTROL:
|
||||
|
||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||
if (m_macHIToolbarRef != NULL)
|
||||
{
|
||||
wxASSERT( tool->GetControl() != NULL );
|
||||
HIToolbarItemRef item;
|
||||
@@ -1563,6 +1578,11 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
}
|
||||
CFRelease( data ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = noErr;
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
// right now there's nothing to do here
|
||||
@@ -1629,10 +1649,13 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
|
||||
#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() )
|
||||
@@ -1667,8 +1690,11 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
|
||||
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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user