X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/489468feaa08b8f504735eecca522fb8d0f825d2..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/osx/carbon/toolbar.cpp diff --git a/src/osx/carbon/toolbar.cpp b/src/osx/carbon/toolbar.cpp index f0364473c9..a44e23bbda 100644 --- a/src/osx/carbon/toolbar.cpp +++ b/src/osx/carbon/toolbar.cpp @@ -1,10 +1,9 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/toolbar.cpp +// Name: src/osx/carbon/toolbar.cpp // Purpose: wxToolBar // Author: Stefan Csomor // Modified by: // Created: 04/01/98 -// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -20,7 +19,7 @@ #endif #include "wx/app.h" -#include "wx/mac/uma.h" +#include "wx/osx/private.h" #include "wx/geometry.h" #include "wx/sysopt.h" @@ -32,9 +31,6 @@ const short kwxMacToolBarLeftMargin = 4; const short kwxMacToolBorder = 0; const short kwxMacToolSpacing = 6; - -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) - BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() @@ -43,7 +39,6 @@ END_EVENT_TABLE() #pragma mark - #pragma mark Tool Implementation - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -114,7 +109,7 @@ public: m_controlHandle = NULL ; } -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_toolbarItemRef ) { CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ; @@ -130,7 +125,7 @@ public: CFRelease(m_toolbarItemRef); m_toolbarItemRef = NULL; } -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR } wxSize GetSize() const @@ -149,7 +144,7 @@ public: { // separator size curSize = GetToolBar()->GetToolSize(); - if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetToolBar()->GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) curSize.y /= 4; else curSize.x /= 4; @@ -163,35 +158,85 @@ public: return wxPoint( m_x, m_y ); } - bool DoEnable( bool enable ); + virtual bool Enable( bool enable ); void UpdateToggleImage( bool toggle ); -#if wxMAC_USE_NATIVE_TOOLBAR - void SetToolbarItemRef( HIToolbarItemRef ref ) + virtual bool Toggle(bool toggle) { - if ( m_controlHandle ) - HideControl( m_controlHandle ); - if ( m_toolbarItemRef ) - CFRelease( m_toolbarItemRef ); + if ( wxToolBarToolBase::Toggle( toggle ) == false ) + return false; - m_toolbarItemRef = ref; + UpdateToggleImage(toggle); + return true; + } + + void UpdateHelpStrings() + { +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_toolbarItemRef ) { - wxFont f; - wxFontEncoding enc; - if ( GetToolBar() ) - f = GetToolBar()->GetFont(); - if ( f.IsOk() ) - enc = f.GetEncoding(); - else - enc = wxFont::GetDefaultEncoding(); + wxFontEncoding enc = GetToolBarFontEncoding(); HIToolbarItemSetHelpText( m_toolbarItemRef, wxCFStringRef( GetShortHelp(), enc ), wxCFStringRef( GetLongHelp(), enc ) ); } +#endif + } + + virtual bool SetShortHelp(const wxString& help) + { + if ( wxToolBarToolBase::SetShortHelp( help ) == false ) + return false; + + UpdateHelpStrings(); + return true; + } + + virtual bool SetLongHelp(const wxString& help) + { + if ( wxToolBarToolBase::SetLongHelp( help ) == false ) + return false; + + UpdateHelpStrings(); + return true; + } + + virtual void SetNormalBitmap(const wxBitmap& bmp) + { + wxToolBarToolBase::SetNormalBitmap(bmp); + UpdateToggleImage(CanBeToggled() && IsToggled()); + } + + virtual void SetLabel(const wxString& label) + { + wxToolBarToolBase::SetLabel(label); +#if wxOSX_USE_NATIVE_TOOLBAR + if ( m_toolbarItemRef ) + { + // strip mnemonics from the label for compatibility with the usual + // labels in wxStaticText sense + wxString labelStr = wxStripMenuCodes(label); + + HIToolbarItemSetLabel( + m_toolbarItemRef, + wxCFStringRef(labelStr, GetToolBarFontEncoding()) ); + } +#endif + } + +#if wxOSX_USE_NATIVE_TOOLBAR + void SetToolbarItemRef( HIToolbarItemRef ref ) + { + if ( m_controlHandle ) + HideControl( m_controlHandle ); + if ( m_toolbarItemRef ) + CFRelease( m_toolbarItemRef ); + + m_toolbarItemRef = ref; + UpdateHelpStrings(); } HIToolbarItemRef GetToolbarItemRef() const @@ -208,14 +253,24 @@ public: { return m_index; } -#endif +#endif // wxOSX_USE_NATIVE_TOOLBAR private: +#if wxOSX_USE_NATIVE_TOOLBAR + wxFontEncoding GetToolBarFontEncoding() const + { + wxFont f; + if ( GetToolBar() ) + f = GetToolBar()->GetFont(); + return f.IsOk() ? f.GetEncoding() : wxFont::GetDefaultEncoding(); + } +#endif // wxOSX_USE_NATIVE_TOOLBAR + void Init() { m_controlHandle = NULL; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR m_toolbarItemRef = NULL; m_index = -1; #endif @@ -225,7 +280,7 @@ private: wxCoord m_x; wxCoord m_y; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR HIToolbarItemRef m_toolbarItemRef; // position in its toolbar, -1 means not inserted CFIndex m_index; @@ -307,7 +362,7 @@ static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler ) -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR static const EventTypeSpec toolBarEventList[] = { @@ -369,15 +424,18 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler ) #endif -bool wxToolBarTool::DoEnable( bool enable ) +bool wxToolBarTool::Enable( bool enable ) { + if ( wxToolBarToolBase::Enable( enable ) == false ) + return false; + if ( IsControl() ) { GetControl()->Enable( enable ); } else if ( IsButton() ) { -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_toolbarItemRef != NULL ) HIToolbarItemSetEnabled( m_toolbarItemRef, enable ); #endif @@ -418,7 +476,7 @@ void wxToolBarTool::SetPosition( const wxPoint& position ) else if ( IsControl() ) { // embedded native controls are moved by the OS -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false ) #endif { @@ -442,21 +500,25 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) { if ( toggle ) { - int w = m_bmpNormal.GetWidth(); - int h = m_bmpNormal.GetHeight(); + int w = m_bmpNormal.GetWidth() + 6; + int h = m_bmpNormal.GetHeight() + 6; wxBitmap bmp( w, h ); wxMemoryDC dc; dc.SelectObject( bmp ); - dc.SetPen( wxPen(*wxBLACK) ); - dc.SetBrush( wxBrush( *wxLIGHT_GREY )); - dc.DrawRectangle( 0, 0, w, h ); - dc.DrawBitmap( m_bmpNormal, 0, 0, true ); + wxColour mid_grey_75 = wxColour(128, 128, 128, 196); + wxColour light_grey_75 = wxColour(196, 196, 196, 196); + dc.GradientFillLinear( wxRect(1, 1, w - 1, h-1), + light_grey_75, mid_grey_75, wxNORTH); + wxColour black_50 = wxColour(0, 0, 0, 127); + dc.SetPen( wxPen(black_50) ); + dc.DrawRoundedRectangle( 0, 0, w, h, 1.5 ); + dc.DrawBitmap( m_bmpNormal, 3, 3, true ); dc.SelectObject( wxNullBitmap ); ControlButtonContentInfo info; wxMacCreateBitmapButton( &info, bmp ); SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if (m_toolbarItemRef != NULL) { ControlButtonContentInfo info2; @@ -472,7 +534,7 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) ControlButtonContentInfo info; wxMacCreateBitmapButton( &info, m_bmpNormal ); SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if (m_toolbarItemRef != NULL) { ControlButtonContentInfo info2; @@ -541,8 +603,8 @@ void wxToolBar::Init() m_defaultWidth = kwxMacToolBarToolDefaultWidth; m_defaultHeight = kwxMacToolBarToolDefaultHeight; -#if wxMAC_USE_NATIVE_TOOLBAR - m_macHIToolbarRef = NULL; +#if wxOSX_USE_NATIVE_TOOLBAR + m_macToolbar = NULL; m_macUsesNativeToolbar = false; #endif } @@ -632,8 +694,6 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, CFIndex count = CFGetRetainCount( viewRef ) ; if ( count >= 1 ) { - wxFAIL_MSG("Reference count of native tool was illegal before removal"); - CFRelease( viewRef ) ; } } @@ -664,7 +724,7 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, { case kEventControlGetSizeConstraints: { - wxWindow* wxwindow = wxFindControlFromMacControl(object->viewRef ) ; + wxWindow* wxwindow = wxFindWindowFromWXWidget( (WXWidget) object->viewRef ) ; if ( wxwindow ) { // during toolbar layout the native window sometimes gets negative sizes, @@ -745,7 +805,7 @@ CantCreateEvent : return result ; } -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR static const EventTypeSpec kToolbarEvents[] = { { kEventClassToolbar, kEventToolbarGetDefaultIdentifiers }, @@ -811,7 +871,7 @@ static OSStatus ToolbarDelegateHandler(EventHandlerCallRef WXUNUSED(inCallRef), } return result ; } -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR // also for the toolbar we have the dual implementation: // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar @@ -831,17 +891,17 @@ bool wxToolBar::Create( OSStatus err = noErr; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1) { wxString labelStr = wxString::Format( wxT("%p"), this ); err = HIToolbarCreate( wxCFStringRef( labelStr, wxFont::GetDefaultEncoding() ), 0, - (HIToolbarRef*) &m_macHIToolbarRef ); + (HIToolbarRef*) &m_macToolbar ); - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { - InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler, + InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macToolbar ), ToolbarDelegateHandler, GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL ); HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; @@ -854,37 +914,44 @@ bool wxToolBar::Create( else mode = kHIToolbarDisplayModeIconOnly; - HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); - HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize ); + HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode ); + HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, displaySize ); } } -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR return (err == noErr); } wxToolBar::~wxToolBar() { -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + // We could be not using a native tool bar at all, this happens when we're + // created with something other than the frame as parent for example. + if ( !m_macToolbar ) + return; + + // it might already have been uninstalled due to a previous call to Destroy, but in case + // wasn't, do so now, otherwise redraw events may occur for deleted objects + bool ownToolbarInstalled = false; + MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); + if (ownToolbarInstalled) { - // if this is the installed toolbar, then deinstall it - if (m_macUsesNativeToolbar) - MacInstallNativeToolbar( false ); + MacUninstallNativeToolbar(); + } - CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ; - // Leopard seems to have one refcount more, so we cannot check reliably at the moment - if ( UMAGetSystemVersion() < 0x1050 ) + CFIndex count = CFGetRetainCount( m_macToolbar ) ; + // Leopard seems to have one refcount more, so we cannot check reliably at the moment + if ( UMAGetSystemVersion() < 0x1050 ) + { + if ( count != 1 ) { - if ( count != 1 ) - { - wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor"); - } + wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor"); } - CFRelease( (HIToolbarRef)m_macHIToolbarRef ); - m_macHIToolbarRef = NULL; } -#endif + CFRelease( (HIToolbarRef)m_macToolbar ); + m_macToolbar = NULL; +#endif // wxOSX_USE_NATIVE_TOOLBAR } bool wxToolBar::Show( bool show ) @@ -894,7 +961,7 @@ bool wxToolBar::Show( bool show ) if (bResult) { -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR bool ownToolbarInstalled = false; MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); if (ownToolbarInstalled) @@ -918,7 +985,7 @@ bool wxToolBar::IsShown() const { bool bResult; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR bool ownToolbarInstalled; MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); @@ -939,7 +1006,7 @@ bool wxToolBar::IsShown() const void wxToolBar::DoGetSize( int *width, int *height ) const { -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR Rect boundsR; bool ownToolbarInstalled; @@ -947,7 +1014,7 @@ void wxToolBar::DoGetSize( int *width, int *height ) const if ( ownToolbarInstalled ) { // TODO: is this really a control ? - GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR ); + GetControlBounds( (ControlRef) m_macToolbar, &boundsR ); if ( width != NULL ) *width = boundsR.right - boundsR.left; if ( height != NULL ) @@ -974,8 +1041,8 @@ void wxToolBar::SetWindowStyleFlag( long style ) { wxToolBarBase::SetWindowStyleFlag( style ); -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; @@ -986,12 +1053,12 @@ void wxToolBar::SetWindowStyleFlag( long style ) else mode = kHIToolbarDisplayModeIconOnly; - HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); + HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode ); } #endif } -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR bool wxToolBar::MacWantsNativeToolbar() { return m_macUsesNativeToolbar; @@ -1011,7 +1078,7 @@ bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const OSStatus err = GetWindowToolbar( tlw, &curToolbarRef ); bResultV = ((err == noErr) && (curToolbarRef != NULL)); if (bResultV && (ownToolbarInstalled != NULL)) - *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef); + *ownToolbarInstalled = (curToolbarRef == m_macToolbar); } return bResultV; @@ -1021,10 +1088,10 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bool bResult = false; - if (usesNative && (m_macHIToolbarRef == NULL)) + if (usesNative && (m_macToolbar == NULL)) return bResult; - if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0)) + if (usesNative && ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT|wxTB_BOTTOM)) != 0)) return bResult; WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); @@ -1046,30 +1113,37 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bResult = true; - SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef ); + SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar ); + + // ShowHideWindowToolbar will make the wxFrame grow + // which we don't want in this case + wxSize sz = GetParent()->GetSize(); ShowHideWindowToolbar( tlw, true, false ); + // Restore the original size + GetParent()->SetSize( sz ); + ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 ); + SetAutomaticControlDragTrackingEnabledForWindow( tlw, true ); - Rect r = { 0, 0, 0, 0 }; - m_peer->SetRect( &r ); + GetPeer()->Move(0,0,0,0 ); SetSize( wxSIZE_AUTO_WIDTH, 0 ); - m_peer->SetVisibility( false, true ); + GetPeer()->SetVisibility( false ); wxToolBarBase::Show( false ); } } else { // only deinstall toolbar if this is the installed one - if (m_macHIToolbarRef == curToolbarRef) + if (m_macToolbar == curToolbarRef) { bResult = true; ShowHideWindowToolbar( tlw, false, false ); ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute ); - SetWindowToolbar( tlw, NULL ); + MacUninstallNativeToolbar(); - m_peer->SetVisibility( true, true ); + GetPeer()->SetVisibility( true ); } } @@ -1079,13 +1153,25 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") ); return bResult; } + +void wxToolBar::MacUninstallNativeToolbar() +{ + if (!m_macToolbar) + return; + + WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); + if (tlw) + SetWindowToolbar( tlw, NULL ); +} #endif bool wxToolBar::Realize() { - if (m_tools.GetCount() == 0) + if ( !wxToolBarBase::Realize() ) return false; + wxSize tlw_sz = GetParent()->GetSize(); + int maxWidth = 0; int maxHeight = 0; @@ -1120,11 +1206,18 @@ bool wxToolBar::Realize() bool lastIsRadio = false; bool curIsRadio = false; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR CFIndex currentPosition = 0; bool insertAll = false; - HIToolbarRef refTB = (HIToolbarRef)m_macHIToolbarRef; + HIToolbarRef refTB = (HIToolbarRef)m_macToolbar; + wxFont f; + wxFontEncoding enc; + f = GetFont(); + if ( f.IsOk() ) + enc = f.GetEncoding(); + else + enc = wxFont::GetDefaultEncoding(); #endif node = m_tools.GetFirst(); @@ -1145,7 +1238,7 @@ bool wxToolBar::Realize() if ( y + cursize.y > maxHeight ) maxHeight = y + cursize.y; - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) { int x1 = x + ( maxToolWidth - cursize.x ) / 2; tool->SetPosition( wxPoint(x1, y) ); @@ -1157,18 +1250,20 @@ bool wxToolBar::Realize() } // update the item positioning state - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) y += cursize.y + kwxMacToolSpacing; else x += cursize.x + kwxMacToolSpacing; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR // install in native HIToolbar if ( refTB ) { HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef(); if ( hiItemRef != NULL ) { + // since setting the help texts is non-virtual we have to update + // the strings now if ( insertAll || (tool->GetIndex() != currentPosition) ) { OSStatus err = noErr; @@ -1235,6 +1330,10 @@ bool wxToolBar::Realize() wxFAIL_MSG("Reference count of native tool was illegal before removal"); } wxASSERT( IsValidControlHandle(tool->GetControl()->GetPeer()->GetControlRef() )) ; + + wxString label = tool->GetLabel(); + if ( !label.empty() ) + HIToolbarItemSetLabel( hiItemRef, wxCFStringRef(label, GetFont().GetEncoding()) ); } } @@ -1284,14 +1383,16 @@ bool wxToolBar::Realize() node = node->GetNext(); } - if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + if (m_macUsesNativeToolbar) + GetParent()->SetSize( tlw_sz ); + + if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) ) { // if not set yet, only one row if ( m_maxRows <= 0 ) SetRows( 1 ); m_minWidth = maxWidth; - maxWidth = tw; maxHeight += m_yMargin + kwxMacToolBarTopMargin; m_minHeight = m_maxHeight = maxHeight; } @@ -1302,7 +1403,6 @@ bool wxToolBar::Realize() SetRows( GetToolsCount() ); m_minHeight = maxHeight; - maxHeight = th; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_minWidth = m_maxWidth = maxWidth; } @@ -1313,7 +1413,7 @@ bool wxToolBar::Realize() bool wantNativeToolbar, ownToolbarInstalled; // attempt to install the native toolbar - wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0); + wantNativeToolbar = ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_BOTTOM|wxTB_RIGHT)) == 0); MacInstallNativeToolbar( wantNativeToolbar ); (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); if (!ownToolbarInstalled) @@ -1332,13 +1432,25 @@ bool wxToolBar::Realize() return true; } +void wxToolBar::DoLayout() +{ + // TODO port back osx_cocoa layout solution +} + +void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); + + DoLayout(); +} + void wxToolBar::SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x + kwxMacToolBorder; m_defaultHeight = size.y + kwxMacToolBorder; -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { int maxs = wxMax( size.x, size.y ); HIToolbarDisplaySize sizeSpec; @@ -1349,7 +1461,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) else sizeSpec = kHIToolbarDisplaySizeSmall; - HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec ); + HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, sizeSpec ); } #endif } @@ -1371,7 +1483,7 @@ void wxToolBar::MacSuperChangedPosition() { wxWindow::MacSuperChangedPosition(); -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if (! m_macUsesNativeToolbar ) Realize(); #else @@ -1382,7 +1494,7 @@ void wxToolBar::MacSuperChangedPosition() void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -1396,7 +1508,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -1424,7 +1536,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const node = node->GetNext(); } - return (wxToolBarToolBase*)NULL; + return NULL; } wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) @@ -1436,22 +1548,19 @@ wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) return wxEmptyString; } -void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) +void wxToolBar::DoEnableTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(enable)) { - if ( t != NULL ) - ((wxToolBarTool*)t)->DoEnable( enable ); + // everything already done in the tool's implementation } -void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) +void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(toggle)) { - wxToolBarTool *tool = (wxToolBarTool *)t; - if ( ( tool != NULL ) && tool->IsButton() ) - tool->UpdateToggleImage( toggle ); + // everything already done in the tool's implementation } bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) { - wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase ); + wxToolBarTool *tool = static_cast< wxToolBarTool*>(toolBase ); if (tool == NULL) return false; @@ -1461,15 +1570,15 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) ControlRef controlHandle = NULL; OSStatus err = 0; -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR wxString label = tool->GetLabel(); - if (m_macHIToolbarRef && !label.empty() ) + if (m_macToolbar && !label.empty() ) { // strip mnemonics from the label for compatibility // with the usual labels in wxStaticText sense label = wxStripMenuCodes(label); } -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR switch (tool->GetStyle()) { @@ -1478,14 +1587,14 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) wxASSERT( tool->GetControlHandle() == NULL ); toolSize.x /= 4; toolSize.y /= 4; - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) toolrect.bottom = toolSize.y; else toolrect.right = toolSize.x; // in flat style we need a visual separator -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { HIToolbarItemRef item; err = HIToolbarItemCreate( @@ -1497,7 +1606,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) } else err = noErr; -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR CreateSeparatorControl( window, &toolrect, &controlHandle ); tool->SetControlHandle( controlHandle ); @@ -1528,8 +1637,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) behaviour, &info, 0, 0, 0, &controlHandle ); } -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { HIToolbarItemRef item; wxString labelStr = wxString::Format(wxT("%p"), tool); @@ -1554,7 +1663,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) } else err = noErr; -#endif // wxMAC_USE_NATIVE_TOOLBAR +#endif // wxOSX_USE_NATIVE_TOOLBAR wxMacReleaseBitmapButton( &info ); @@ -1573,14 +1682,14 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) case wxTOOL_STYLE_CONTROL: -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { - wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") ); + wxCHECK_MSG( tool->GetControl(), false, wxT("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, + err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macToolbar,kControlToolbarItemClassID, data , &item ) ; if (err == noErr) @@ -1630,12 +1739,12 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) { - wxFAIL_MSG( wxT("not implemented") ); + // nothing to do } bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) { - wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase ); + wxToolBarTool* tool = static_cast< wxToolBarTool*>(toolbase ); wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -1651,16 +1760,16 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) wxSize sz = ((wxToolBarTool*)tool)->GetSize(); -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR CFIndex removeIndex = tool->GetIndex(); #endif -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { - if ( removeIndex != -1 && m_macHIToolbarRef ) + if ( removeIndex != -1 && m_macToolbar ) { - HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex ); + HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macToolbar, removeIndex ); tool->SetIndex( -1 ); } } @@ -1675,15 +1784,15 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); wxPoint pt = tool2->GetPosition(); - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) pt.y -= sz.y; else pt.x -= sz.x; tool2->SetPosition( pt ); -#if wxMAC_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) +#if wxOSX_USE_NATIVE_TOOLBAR + if (m_macToolbar != NULL) { if ( removeIndex != -1 && tool2->GetIndex() > removeIndex ) tool2->SetIndex( tool2->GetIndex() - 1 ); @@ -1698,7 +1807,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) void wxToolBar::OnPaint(wxPaintEvent& event) { -#if wxMAC_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_macUsesNativeToolbar ) { event.Skip(true); @@ -1711,7 +1820,7 @@ void wxToolBar::OnPaint(wxPaintEvent& event) int w, h; GetSize( &w, &h ); - bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance(); + bool drawMetalTheme = MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL; if ( !drawMetalTheme ) {