X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/facd6764872eede45605ba7c9dfa0e1d0c708fa2..143318ddbb005602b600216cca621439b771f889:/src/mac/carbon/toolbar.cpp?ds=sidebyside diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 2dd8872464..0ae7bed16e 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -26,7 +26,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) - EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() #endif @@ -67,6 +66,7 @@ public: void SetSize(const wxSize& size) ; void SetPosition( const wxPoint& position ) ; + wxSize GetSize() const { if ( IsControl() ) @@ -89,6 +89,7 @@ public: { return wxPoint(m_x, m_y); } + bool DoEnable( bool enable ) ; private : void Init() { @@ -160,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() ) @@ -233,34 +256,19 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, SInt16 behaviour = kControlBehaviorOffsetContents ; if ( CanBeToggled() ) behaviour += kControlBehaviorToggles ; - - if ( info.contentType != kControlNoContent ) - { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 , - behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; - ::SetControlData( m_controlHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; - } - else - { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 , - behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; - } + CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info , + 0 , 0 , 0 , &m_controlHandle ) ; + InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this,NULL); + UMAShowControl( m_controlHandle ) ; - if ( !IsEnabled() ) - { - UMADeactivateControl( m_controlHandle ) ; - } + if ( CanBeToggled() && IsToggled() ) - { ::SetControl32BitValue( m_controlHandle , 1 ) ; - } else - { ::SetControl32BitValue( m_controlHandle , 0 ) ; - } ControlRef container = (ControlRef) tbar->GetHandle() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; @@ -327,7 +335,7 @@ bool wxToolBar::Realize() int maxToolHeight = 0; // Find the maximum tool width and height - wxToolBarToolsList::Node *node = m_tools.GetFirst(); + wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); while ( node ) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); @@ -391,6 +399,7 @@ bool wxToolBar::Realize() } SetSize( maxWidth, maxHeight ); + InvalidateBestSize(); return TRUE; } @@ -406,27 +415,6 @@ wxSize wxToolBar::GetToolSize() const return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); } -void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) -{ - wxToolBarToolsList::Node *node; - for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) - { - wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; - if ( tool->IsButton() ) - { - if( tool->GetControlHandle() == control ) - { - if ( tool->CanBeToggled() ) - { - tool->Toggle( GetControl32BitValue( (ControlRef) control ) ) ; - } - OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; - break ; - } - } - } -} - void wxToolBar::SetRows(int nRows) { if ( nRows == m_maxRows ) @@ -446,7 +434,7 @@ void wxToolBar::MacSuperChangedPosition() wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { - wxToolBarToolsList::Node *node = m_tools.GetFirst(); + wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ; @@ -477,18 +465,7 @@ 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) @@ -508,6 +485,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,7 +497,7 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(tog bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) { - wxToolBarToolsList::Node *node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool2 = node->GetData(); @@ -554,6 +532,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) tool2->SetPosition( pt ) ; } + InvalidateBestSize(); return TRUE ; } @@ -572,73 +551,42 @@ void wxToolBar::OnPaint(wxPaintEvent& event) if ( toolbarrect.top < 0 ) toolbarrect.top = 0 ; */ - UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; -/* + if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() ) { - wxToolBarToolsList::Node *node; - for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) - { - wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; - if ( tool->IsButton() ) - { - UMADrawControl( (ControlRef) tool->GetControlHandle() ) ; - } - } + UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; } -*/ - event.Skip() ; -} - -void wxToolBar::OnMouse( wxMouseEvent &event ) -{ - if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) + else { - - int x = event.m_x ; - int y = event.m_y ; - - MacClientToRootWindow( &x , &y ) ; - - ControlRef control ; - Point localwhere ; - SInt16 controlpart ; - WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; - - localwhere.h = x ; - localwhere.v = y ; - - short modifiers = 0; - - if ( !event.m_leftDown && !event.m_rightDown ) - modifiers |= btnState ; - - if ( event.m_shiftDown ) - modifiers |= shiftKey ; - - if ( event.m_controlDown ) - modifiers |= controlKey ; - - if ( event.m_altDown ) - modifiers |= optionKey ; - - if ( event.m_metaDown ) - modifiers |= cmdKey ; - - controlpart = ::FindControl( localwhere , window , &control ) ; +#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 ) ; + { - if ( control && ::IsControlActive( control ) ) - { - { - controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; - wxTheApp->s_lastMouseDown = 0 ; - if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice - { - MacHandleControlClick((WXWidget) control , controlpart , false /* not down anymore */ ) ; - } - } - } + 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() ; } #endif // wxUSE_TOOLBAR