X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9154a136d5e1d79a4be2cf012e4a815fdc6df3ff..a738f87caeafd5e51fc029a6228c540e942505b7:/src/mac/carbon/toolbar.cpp diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 8e35a2c831..1b7cef3e5f 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -22,6 +22,7 @@ #include "wx/app.h" #include "wx/mac/uma.h" #include "wx/geometry.h" +#include "wx/sysopt.h" #ifdef __WXMAC_OSX__ @@ -66,7 +67,8 @@ END_EVENT_TABLE() // when this view is removed from the native toolbar its count gets decremented again // and when the HITooolbarItem wrapper object gets destroyed it is decremented as well // so in the end the control lives with a refcount of one and can be disposed of by the -// wxControl code +// wxControl code. For embedded controls on a non-native toolbar this ref count is less +// so we can only test against a range, not a specific value of the refcount. class wxToolBarTool : public wxToolBarToolBase { @@ -642,7 +644,6 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, case kEventHIObjectDestruct: { HIViewRef viewRef = object->viewRef ; - wxASSERT( IsValidControlHandle(viewRef) ) ; if( viewRef && IsValidControlHandle( viewRef) ) { // depending whether the wxControl corresponding to this HIView has already been destroyed or @@ -698,6 +699,9 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, 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 ; @@ -842,28 +846,31 @@ bool wxToolBar::Create( 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("%xd"), (int)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 @@ -1102,7 +1109,7 @@ bool wxToolBar::Realize() // find the maximum tool width and height wxToolBarTool *tool; wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); - while ( node != NULL ) + while ( node ) { tool = (wxToolBarTool *) node->GetData(); if ( tool != NULL ) @@ -1129,7 +1136,7 @@ bool wxToolBar::Realize() #endif node = m_tools.GetFirst(); - while ( node != NULL ) + while ( node ) { tool = (wxToolBarTool*) node->GetData(); if ( tool == NULL ) @@ -1192,7 +1199,7 @@ bool wxToolBar::Realize() if ( tool2->IsControl() ) { CFIndex count = CFGetRetainCount( tool2->GetControl()->GetPeer()->GetControlRef() ) ; - wxASSERT_MSG( count == 3 , wxT("Reference Count of native tool was not 3 before removal") ); + wxASSERT_MSG( count == 3 || count == 2 , wxT("Reference Count of native tool was illegal before removal") ); wxASSERT( IsValidControlHandle(tool2->GetControl()->GetPeer()->GetControlRef() )) ; } err = HIToolbarRemoveItemAtIndex(refTB, idx); @@ -1223,7 +1230,7 @@ bool wxToolBar::Realize() if ( tool->IsControl() ) { CFIndex count = CFGetRetainCount( tool->GetControl()->GetPeer()->GetControlRef() ) ; - wxASSERT_MSG( count == 3 , wxT("Reference Count of native tool was not 3 after insertion") ); + wxASSERT_MSG( count == 3 || count == 2, wxT("Reference Count of native tool was illegal after insertion") ); wxASSERT( IsValidControlHandle(tool->GetControl()->GetPeer()->GetControlRef() )) ; } } @@ -1257,7 +1264,7 @@ bool wxToolBar::Realize() DoToggleTool( tool, true ); wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious(); - while ( nodePrev != NULL ) + while ( nodePrev ) { wxToolBarToolBase *toggleTool = nodePrev->GetData(); if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) ) @@ -1401,7 +1408,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { wxToolBarTool *tool; wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); - while ( node != NULL ) + while ( node ) { tool = (wxToolBarTool *)node->GetData(); if (tool != NULL) @@ -1470,12 +1477,17 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) // 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 ); @@ -1504,20 +1516,25 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) } #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 ); + wxString labelStr = wxString::Format(wxT("%xd"), (int)tool); + err = HIToolbarItemCreate( + wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()), + kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item ); + if (err == noErr) + { + InstallEventHandler( + HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(), + GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL ); - HIToolbarItemSetIconRef( item, info.u.iconRef ); - HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction ); - tool->SetToolbarItemRef( item ); + HIToolbarItemSetIconRef( item, info.u.iconRef ); + HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction ); + tool->SetToolbarItemRef( item ); + } } + else + err = noErr; #endif // wxMAC_USE_NATIVE_TOOLBAR wxMacReleaseBitmapButton( &info ); @@ -1538,6 +1555,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) case wxTOOL_STYLE_CONTROL: #if wxMAC_USE_NATIVE_TOOLBAR + if (m_macHIToolbarRef != NULL) { wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") ); @@ -1552,7 +1570,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 #endif @@ -1564,7 +1586,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) #if wxMAC_USE_NATIVE_TOOLBAR wxString label = tool->GetLabel(); - if ( !label.empty() ) + if (m_macHIToolbarRef && !label.empty() ) { // strip mnemonics from the label for compatibility // with the usual labels in wxStaticText sense @@ -1594,8 +1616,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) } else { - wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err ); - wxFAIL_MSG( errMsg.c_str() ); + wxFAIL_MSG( wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err ) ); } return (err == noErr); @@ -1631,10 +1652,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() ) @@ -1669,8 +1693,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 }