X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/affd2611c569d9d8e60fa542614f6668956b16de..2289dcea2ba6b6c1ef9dd9076fb9c632fe009f89:/src/mac/carbon/toolbar.cpp diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 8014c63119..ef6f7623c4 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -9,14 +9,15 @@ // Licence: The wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "toolbar.h" #endif -#include "wx/wx.h" +#include "wx/wxprec.h" #if wxUSE_TOOLBAR +#include "wx/wx.h" #include "wx/toolbar.h" #include "wx/notebook.h" #include "wx/tabctrl.h" @@ -66,6 +67,7 @@ public: void SetSize(const wxSize& size) ; void SetPosition( const wxPoint& position ) ; + wxSize GetSize() const { if ( IsControl() ) @@ -88,6 +90,7 @@ public: { return wxPoint(m_x, m_y); } + bool DoEnable( bool enable ) ; private : void Init() { @@ -121,10 +124,9 @@ static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef wxToolBarTool* tbartool = (wxToolBarTool*)data ; if ( tbartool->CanBeToggled() ) { - tbartool->Toggle( GetControl32BitValue( (ControlRef) tbartool->GetControlHandle() ) ) ; + ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle())); } ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ; - result = noErr; } break ; @@ -159,6 +161,28 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler ) // wxToolBarTool // ---------------------------------------------------------------------------- +bool wxToolBarTool::DoEnable(bool enable) +{ + if ( IsControl() ) + { + GetControl()->Enable( enable ) ; + } + else if ( IsButton() ) + { +#if TARGET_API_MAC_OSX + if ( enable ) + EnableControl( m_controlHandle ) ; + else + DisableControl( m_controlHandle ) ; +#else + if ( enable ) + ActivateControl( m_controlHandle ) ; + else + DeactivateControl( m_controlHandle ) ; +#endif + } + return true ; +} void wxToolBarTool::SetSize(const wxSize& size) { if ( IsControl() ) @@ -188,7 +212,7 @@ void wxToolBarTool::SetPosition(const wxPoint& position) GetControlBounds( m_controlHandle , &contrlRect ) ; int former_mac_x = contrlRect.left ; int former_mac_y = contrlRect.top ; - wxSize sz = GetToolBar()->GetToolSize() ; + GetToolBar()->GetToolSize() ; if ( mac_x != former_mac_x || mac_y != former_mac_y ) { @@ -240,8 +264,6 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, GetEventTypeCount(eventList), eventList, this,NULL); UMAShowControl( m_controlHandle ) ; - if ( !IsEnabled() ) - DisableControl( m_controlHandle ) ; if ( CanBeToggled() && IsToggled() ) ::SetControl32BitValue( m_controlHandle , 1 ) ; @@ -327,12 +349,32 @@ bool wxToolBar::Realize() node = node->GetNext(); } + bool lastWasRadio = FALSE; node = m_tools.GetFirst(); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize cursize = tool->GetSize() ; + bool isRadio = FALSE; + + if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO ) + { + if ( !lastWasRadio ) + { + if (tool->Toggle(true)) + { + DoToggleTool(tool, true); + } + } + isRadio = TRUE; + } + else + { + isRadio = FALSE; + } + lastWasRadio = isRadio; + // for the moment we just do a single row/column alignement if ( x + cursize.x > maxWidth ) maxWidth = x + cursize.x ; @@ -360,9 +402,10 @@ bool wxToolBar::Realize() // if not set yet, only one row SetRows(1); } + m_minWidth = maxWidth; maxWidth = tw ; maxHeight += m_yMargin + kwxMacToolBarTopMargin; - m_maxHeight = maxHeight ; + m_minHeight = m_maxHeight = maxHeight ; } else { @@ -371,12 +414,14 @@ bool wxToolBar::Realize() // if not set yet, have one column SetRows(GetToolsCount()); } + m_minHeight = maxHeight; maxHeight = th ; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; - m_maxWidth = maxWidth ; + m_minWidth = m_maxWidth = maxWidth ; } SetSize( maxWidth, maxHeight ); + InvalidateBestSize(); return TRUE; } @@ -439,28 +484,11 @@ wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) { - if (!IsShown()) - return ; - - wxToolBarTool *tool = (wxToolBarTool *)t; - if ( tool->IsControl() ) - { - tool->GetControl()->Enable( enable ) ; - } - else if ( tool->IsButton() ) - { - if ( enable ) - UMAActivateControl( (ControlRef) tool->GetControlHandle() ) ; - else - UMADeactivateControl( (ControlRef) tool->GetControlHandle() ) ; - } + ((wxToolBarTool*)t)->DoEnable( enable ) ; } void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { - if (!IsShown()) - return ; - wxToolBarTool *tool = (wxToolBarTool *)t; if ( tool->IsButton() ) { @@ -473,6 +501,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), { // nothing special to do here - we relayout in Realize() later tool->Attach(this); + InvalidateBestSize(); return TRUE; } @@ -519,6 +548,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) tool2->SetPosition( pt ) ; } + InvalidateBestSize(); return TRUE ; } @@ -537,8 +567,41 @@ void wxToolBar::OnPaint(wxPaintEvent& event) if ( toolbarrect.top < 0 ) toolbarrect.top = 0 ; */ - UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() ) + { + UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + } + else + { +#if TARGET_API_MAC_OSX +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + if ( UMAGetSystemVersion() >= 0x1030 ) + { + HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , + dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) ); + CGContextRef cgContext ; + Rect bounds ; + GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ; + QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; + CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; + CGContextScaleCTM( cgContext , 1 , -1 ) ; + { + HIThemeBackgroundDrawInfo drawInfo ; + drawInfo.version = 0 ; + drawInfo.state = kThemeStateActive ; + drawInfo.kind = kThemeBackgroundMetal ; + HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ; + } + QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; + } + else +#endif + { + UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + } +#endif + } event.Skip() ; }