From 4c37f1248bda69718bc13e2fdaa1ebb86f3dfc93 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 13 Apr 2004 05:14:14 +0000 Subject: [PATCH] switching to CreateXXX methods for Controls and to Hit Event Processing, thus supporting full keyboard access mode git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26728 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/bmpbuttn.cpp | 18 +++---- src/mac/carbon/button.cpp | 15 +++--- src/mac/carbon/checkbox.cpp | 17 +++--- src/mac/carbon/checklst.cpp | 26 ---------- src/mac/carbon/choice.cpp | 8 +-- src/mac/carbon/combobox.cpp | 3 +- src/mac/carbon/gauge.cpp | 6 +-- src/mac/carbon/notebmac.cpp | 100 ++++++++---------------------------- src/mac/carbon/radiobox.cpp | 4 +- src/mac/carbon/radiobut.cpp | 12 +++-- src/mac/carbon/scrolbar.cpp | 80 +++++++++++++++++++++++------ src/mac/carbon/slider.cpp | 48 +++++++++++------ src/mac/carbon/spinbutt.cpp | 18 +++---- src/mac/carbon/statbox.cpp | 6 +-- src/mac/carbon/statlmac.cpp | 5 +- src/mac/carbon/tabctrl.cpp | 17 +++++- src/mac/carbon/tglbtn.cpp | 20 ++++---- src/mac/carbon/toolbar.cpp | 99 +++-------------------------------- 18 files changed, 200 insertions(+), 302 deletions(-) diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index bfb91977f1..8fba4742c7 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -69,20 +69,16 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit if ( m_bmpNormal.Ok() ) bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; + ControlButtonContentInfo info ; + wxMacCreateBitmapButton( &info , m_bmpNormal ) ; + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , - kControlBehaviorOffsetContents + - ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ? - kControlContentCIconHandle : kControlContentPictHandle ) , 0, - (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; + verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , + (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , + kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - ControlButtonContentInfo info ; - wxMacCreateBitmapButton( &info , m_bmpNormal ) ; - if ( info.contentType != kControlNoContent ) - { - ::SetControlData( (ControlRef) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; - } MacPostControlCreate(pos,size) ; return TRUE; diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 44e13791e2..4bb38feb1e 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -41,8 +41,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) { - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlPushButtonProc , (long) this ) ; + verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , (ControlRef*) &m_macControl ) ) ; } else { @@ -132,13 +131,11 @@ void wxButton::Command (wxCommandEvent & event) ProcessCommand (event); } -void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) +wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { - if ( controlpart != kControlNoPart ) - { - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId ); - event.SetEventObject(this); - ProcessCommand(event); - } + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId ); + event.SetEventObject(this); + ProcessCommand(event); + return noErr ; } diff --git a/src/mac/carbon/checkbox.cpp b/src/mac/carbon/checkbox.cpp index 72993d6081..56284d3ce3 100644 --- a/src/mac/carbon/checkbox.cpp +++ b/src/mac/carbon/checkbox.cpp @@ -38,16 +38,15 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_label = label ; - SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */; + SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */; if (style & wxCHK_3STATE) - { maxValue = 2 /* kControlCheckboxMixedValue */; - } - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , maxValue, - kControlCheckBoxProc , (long) this ) ; + verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , + CFSTR("") , 0 , false , (ControlRef*) &m_macControl ) ) ; + + SetControl32BitMaximum( (ControlRef) m_macControl , maxValue ) ; MacPostControlCreate(pos,size) ; @@ -95,7 +94,7 @@ void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) MacRedrawControl() ; } -void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown) ) +wxInt32 wxCheckBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); wxCheckBoxState state = Get3StateValue(); @@ -122,11 +121,13 @@ void wxCheckBox::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 WXUN { state = wxCHK_UNCHECKED; } - Set3StateValue(state); + Set3StateValue(state); event.SetInt(state); event.SetEventObject(this); ProcessCommand(event); + + return noErr ; } // Bitmap checkbox diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index 855049cb04..a4571422e9 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -244,7 +244,6 @@ bool wxCheckListBox::Create(wxWindow *parent, } listDef.u.userProc = macCheckListDefUPP ; -#if TARGET_CARBON Size asize; @@ -257,32 +256,7 @@ bool wxCheckListBox::Create(wxWindow *parent, SetControlReference( (ControlRef) m_macControl, (long) this); SetControlVisibility( (ControlRef) m_macControl, false, false); -#else - - long result ; - - wxStAppResource resload ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , - kwxMacListWithVerticalScrollbar , 0 , 0, - kControlListBoxProc , (long) this ) ; - ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxListHandleTag , - sizeof( ListHandle ) , (char*) &m_macList , &result ) ; - HLock( (Handle) m_macList ) ; - ldefHandle ldef ; - ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ; - if ( (**(ListHandle)m_macList).listDefProc != NULL ) - { - (**ldef).instruction = 0x4EF9; /* JMP instruction */ - (**ldef).function = (void(*)()) listDef.u.userProc; - (**(ListHandle)m_macList).listDefProc = (Handle) ldef ; - } - - Point pt = (**(ListHandle)m_macList).cellSize ; - pt.v = 14 ; - LCellSize( pt , (ListHandle)m_macList ) ; - LAddColumn( 1 , 0 , (ListHandle)m_macList ) ; -#endif OptionBits options = 0; if ( style & wxLB_MULTIPLE ) { diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index 1a617ef6a5..7f264b39a9 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -66,8 +66,9 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, return false; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , -12345 , 0 , - kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; + + verify_noerr ( CreatePopupButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , + -12345 , false /* no variable width */ , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ; m_macPopUpMenuHandle = NewUniqueMenu() ; SetControlData( (ControlRef) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; @@ -228,7 +229,7 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const return (wxClientData *)DoGetItemClientData(n); } -void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) +wxInt32 wxChoice::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); int n = GetSelection(); @@ -244,6 +245,7 @@ void wxChoice::MacHandleControlClick( WXWidget control , wxInt16 controlpart , b event.SetClientData( GetClientData(n) ); ProcessCommand(event); } + return noErr ; } wxSize wxChoice::DoGetBestSize() const diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index 795874147e..c1fbe261a1 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -531,12 +531,13 @@ void wxComboBox::SetString(int n, const wxString& s) } -void wxComboBox::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown)) +wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event); + return noErr ; } diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp index 19af6c6f41..36abf248dc 100644 --- a/src/mac/carbon/gauge.cpp +++ b/src/mac/carbon/gauge.cpp @@ -45,9 +45,9 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, } Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , range, - kControlProgressBarProc , (long) this ) ; - + verify_noerr ( CreateProgressBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , + m_gaugePos , 0 , m_rangeMax , false /* not indeterminate */ , (ControlRef*) &m_macControl ) ) ; + MacPostControlCreate(pos,size) ; return TRUE; diff --git a/src/mac/carbon/notebmac.cpp b/src/mac/carbon/notebmac.cpp index ae2e636a3a..cee99d8c80 100644 --- a/src/mac/carbon/notebmac.cpp +++ b/src/mac/carbon/notebmac.cpp @@ -44,7 +44,6 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) - EVT_MOUSE_EVENTS(wxNotebook::OnMouse) EVT_SIZE(wxNotebook::OnSize) EVT_SET_FOCUS(wxNotebook::OnSetFocus) @@ -126,7 +125,8 @@ bool wxNotebook::Create(wxWindow *parent, tabsize = kControlSizeSmall; } - ::CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , tabsize , tabstyle, 0, NULL, (ControlRef*) &m_macControl); + verify_noerr ( CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , + tabsize , tabstyle, 0, NULL, (ControlRef*) &m_macControl) ); MacPostControlCreate(pos,size) ; return TRUE ; @@ -567,88 +567,32 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; } - -void wxNotebook::OnMouse( wxMouseEvent &event ) +wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { - if ( (ControlRef) m_macControl == NULL ) - { - event.Skip() ; - return ; - } - - if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) + OSStatus status = eventNotHandledErr ; + + SInt32 newSel = GetControl32BitValue( (ControlRef) m_macControl ) - 1 ; + if ( newSel != m_nSelection ) { - int x = event.m_x ; - int y = event.m_y ; - -#if TARGET_API_MAC_OSX - // OS Needs it in window not client coordinates - wxPoint origin = GetClientAreaOrigin() ; - x += origin.x ; - y += origin.y ; -#else - // OS Needs it in tlw content area coordinates - MacClientToRootWindow( &x , &y ) ; -#endif - - ControlRef control ; - Point localwhere ; - SInt16 controlpart ; - - localwhere.h = x ; - localwhere.v = y ; + wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, + newSel , m_nSelection); + changing.SetEventObject(this); + GetEventHandler()->ProcessEvent(changing); - 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 ; - - control = (ControlRef) m_macControl ; - if ( control && ::IsControlActive( control ) ) + if(changing.IsAllowed()) { - { - wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, - ::GetControl32BitValue(control) - 1, m_nSelection); - changing.SetEventObject(this); - GetEventHandler()->ProcessEvent(changing); + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, + newSel, m_nSelection); + event.SetEventObject(this); - if(changing.IsAllowed()) - { - controlpart = ::HandleControlClick(control, localwhere, modifiers, - (ControlActionUPP) -1); - wxTheApp->s_lastMouseDown = 0 ; - - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, - ::GetControl32BitValue(control) - 1, m_nSelection); - event.SetEventObject(this); - - GetEventHandler()->ProcessEvent(event); - } - } + GetEventHandler()->ProcessEvent(event); + } + else + { + SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; } + status = noErr ; } -} - - -void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) -{ -#if 0 - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlRef)m_macControl) - 1, m_nSelection); - event.SetEventObject(this); - - ProcessEvent(event); -#endif + return status ; } diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp index 83bd0a1f78..cf279d567b 100644 --- a/src/mac/carbon/radiobox.cpp +++ b/src/mac/carbon/radiobox.cpp @@ -137,8 +137,8 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, if ( bounds.bottom <= bounds.top ) bounds.bottom = bounds.top + 100 ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlGroupBoxTextTitleProc , (long) this ) ; + verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , + true /*primary*/ , (ControlRef*)&m_macControl ) ) ; for (i = 0; i < n; i++) { diff --git a/src/mac/carbon/radiobut.cpp b/src/mac/carbon/radiobut.cpp index c7101f60ad..32ad08047e 100644 --- a/src/mac/carbon/radiobut.cpp +++ b/src/mac/carbon/radiobut.cpp @@ -38,10 +38,10 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, m_label = label ; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlRadioButtonProc , (long) this ) ; + verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , + 0 , false /* no autotoggle */ , (ControlRef*) &m_macControl ) ) ; + MacPostControlCreate(pos,size) ; m_cycle = this ; @@ -101,10 +101,11 @@ void wxRadioButton::Command (wxCommandEvent & event) ProcessCommand (event); } -void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) +wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { + // if already set -> no action if ( GetValue() ) - return ; + return noErr; wxRadioButton *cycle, *old = NULL ; cycle=this->NextInCycle(); @@ -130,6 +131,7 @@ void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpar event2.SetEventObject(this); event2.SetInt( true ); ProcessCommand(event2); + return noErr ; } wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) diff --git a/src/mac/carbon/scrolbar.cpp b/src/mac/carbon/scrolbar.cpp index 978292c9ca..08818c0470 100644 --- a/src/mac/carbon/scrolbar.cpp +++ b/src/mac/carbon/scrolbar.cpp @@ -46,13 +46,9 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, return FALSE; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , - &bounds , "\p" , true , 0 , 0 , 100, - kControlScrollBarLiveProc , (long) this) ; - wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - - ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ; + verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , + 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , (ControlRef*) &m_macControl ) ) ; MacPostControlCreate(pos,size) ; @@ -80,19 +76,13 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS m_viewSize = thumbSize; m_objectSize = range; - int range1 = wxMax((m_objectSize - m_viewSize), 0) ; + int range1 = wxMax((m_objectSize - m_viewSize), 0) ; SetControl32BitMaximum( (ControlRef) m_macControl , range1 ) ; SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ; SetControl32BitValue( (ControlRef) m_macControl , position ) ; + SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ; - if ( UMAGetAppearanceVersion() >= 0x0110 ) - { - if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress ) - { - SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ; - } - } if ( refresh ) MacRedrawControl() ; } @@ -106,9 +96,6 @@ void wxScrollBar::Command(wxCommandEvent& event) void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) { - if ( (ControlRef) m_macControl == NULL ) - return ; - int position = GetControl32BitValue( (ControlRef) m_macControl) ; int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ; int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ; @@ -180,3 +167,62 @@ void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart GetEventHandler()->ProcessEvent(event); } +wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) +{ + int position = GetControl32BitValue( (ControlRef) m_macControl) ; + int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ; + int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ; + + wxEventType scrollEvent = wxEVT_NULL; + int nScrollInc = 0; + + wxMacCarbonEvent cEvent( (EventRef) mevent ) ; + ControlPartCode controlpart = cEvent.GetParameter(kEventParamControlPart,typeControlPartCode) ; + + // all events have already been reported during mouse down, except for THUMBRELEASE + if ( controlpart !=kControlIndicatorPart ) + return eventNotHandledErr ; + + switch( controlpart ) + { + case kControlIndicatorPart : + nScrollInc = 0 ; + scrollEvent = wxEVT_SCROLL_THUMBRELEASE; + break ; + default : + wxFAIL_MSG(wxT("illegal scrollbar selector")); + break ; + } + + int new_pos = position + nScrollInc; + + if (new_pos < minPos) + new_pos = minPos; + if (new_pos > maxPos) + new_pos = maxPos; + if ( nScrollInc ) + SetThumbPosition(new_pos); + + wxScrollEvent event(scrollEvent, m_windowId); + if ( m_windowStyle & wxHORIZONTAL ) + { + event.SetOrientation( wxHORIZONTAL ) ; + } + else + { + event.SetOrientation( wxVERTICAL ) ; + } + event.SetPosition(new_pos); + event.SetEventObject( this ); + wxWindow* window = GetParent() ; + if (window && window->MacIsWindowScrollbar(this) ) + { + // this is hardcoded + window->MacOnScroll(event); + } + else + GetEventHandler()->ProcessEvent(event); + return noErr ; +} + + diff --git a/src/mac/carbon/slider.cpp b/src/mac/carbon/slider.cpp index 0ee335f027..b84db95870 100644 --- a/src/mac/carbon/slider.cpp +++ b/src/mac/carbon/slider.cpp @@ -79,18 +79,13 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - procID = kControlSliderProc + kControlSliderLiveFeedback; - if(style & wxSL_AUTOTICKS) { - procID += kControlSliderHasTickMarks; - } - - - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, "\p", true, - value, minValue, maxValue, procID, (long) this); - - wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - - ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ; + UInt16 tickMarks = 0 ; + if ( style & wxSL_AUTOTICKS ) + tickMarks = maxValue - minValue ; + + verify_noerr ( CreateSliderControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , + value , minValue , maxValue , kControlSliderPointsDownOrRight , tickMarks , true /* liveTracking */ , + wxMacLiveScrollbarActionUPP , (ControlRef*) &m_macControl ) ) ; if(style & wxSL_VERTICAL) { SetSizeHints(10, -1, 10, -1); // Forces SetSize to use the proper width @@ -245,10 +240,29 @@ void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bo wxEventType scrollEvent = wxEVT_NULL ; - if ( mouseStillDown ) - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - else - scrollEvent = wxEVT_SCROLL_THUMBRELEASE; + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(value); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + + wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); + cevent.SetInt( value ); + cevent.SetEventObject( this ); + + GetEventHandler()->ProcessEvent( cevent ); +} + +wxInt32 wxSlider::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) +{ + SInt16 value = ::GetControl32BitValue( (ControlRef) m_macControl ) ; + + SetValue( value ) ; + + wxEventType scrollEvent = wxEVT_NULL ; + + scrollEvent = wxEVT_SCROLL_THUMBRELEASE; wxScrollEvent event(scrollEvent, m_windowId); event.SetPosition(value); @@ -260,8 +274,10 @@ void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bo cevent.SetEventObject( this ); GetEventHandler()->ProcessEvent( cevent ); + return noErr ; } + /* This is overloaded in wxSlider so that the proper width/height will always be used * for the slider different values would cause redrawing and mouse detection problems */ void wxSlider::SetSizeHints( int minW, int minH, diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index c9140dc626..30d3076417 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -51,11 +51,9 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c return FALSE; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 100, - kControlLittleArrowsProc , (long) this ) ; - - wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; + + verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 , + (ControlRef*) &m_macControl ) ) ; MacPostControlCreate(pos,size) ; @@ -150,14 +148,12 @@ void wxSpinButton::MacHandleValueChanged( int inc ) } } -void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) +wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event ) { - if ( (ControlRef) m_macControl == NULL ) - return ; - int nScrollInc = 0; + wxMacCarbonEvent cEvent( (EventRef) event ) ; - switch( controlpart ) + switch( cEvent.GetParameter(kEventParamControlPart,typeControlPartCode) ) { case kControlUpButtonPart : nScrollInc = 1; @@ -167,7 +163,7 @@ void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart break ; } MacHandleValueChanged( nScrollInc ) ; - + return noErr ; } // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp index 2f6068ce96..870154ebba 100644 --- a/src/mac/carbon/statbox.cpp +++ b/src/mac/carbon/statbox.cpp @@ -43,9 +43,9 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlGroupBoxTextTitleProc , (long) this ) ; - + verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , + true /*primary*/ , (ControlRef*)&m_macControl ) ) ; + MacPostControlCreate(pos,size) ; return TRUE; diff --git a/src/mac/carbon/statlmac.cpp b/src/mac/carbon/statlmac.cpp index 938aae0715..d13f45e35e 100644 --- a/src/mac/carbon/statlmac.cpp +++ b/src/mac/carbon/statlmac.cpp @@ -56,9 +56,8 @@ bool wxStaticLine::Create( wxWindow *parent, return false; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlSeparatorLineProc , (long) this ) ; - + verify_noerr(CreateSeparatorControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, (ControlRef*)&m_macControl ) ) ; + MacPostControlCreate(pos,size) ; return TRUE; diff --git a/src/mac/carbon/tabctrl.cpp b/src/mac/carbon/tabctrl.cpp index ab984484fd..e96fb25f80 100644 --- a/src/mac/carbon/tabctrl.cpp +++ b/src/mac/carbon/tabctrl.cpp @@ -43,9 +43,22 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons m_imageList = NULL; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, - kControlTabSmallProc , (long) this ) ; + + UInt16 tabstyle = kControlTabDirectionNorth ; + ControlTabSize tabsize = kControlTabSizeLarge ; + if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) + tabsize = kControlTabSizeSmall ; + else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) + { + if (UMAGetSystemVersion() >= 0x1030 ) + tabsize = 3 ; + else + tabsize = kControlSizeSmall; + } + verify_noerr ( CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , + tabsize , tabstyle, 0, NULL, (ControlRef*) &m_macControl) ); + MacPostControlCreate(pos,size) ; return TRUE ; } diff --git a/src/mac/carbon/tglbtn.cpp b/src/mac/carbon/tglbtn.cpp index 25c390aa8f..c41c9610f3 100644 --- a/src/mac/carbon/tglbtn.cpp +++ b/src/mac/carbon/tglbtn.cpp @@ -64,9 +64,9 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, m_label = label ; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , kControlBehaviorToggles , 1, - kControlBevelButtonNormalBevelProc , (long) this ) ; - wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; + + verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , + kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ; MacPostControlCreate(pos,size) ; @@ -101,15 +101,13 @@ void wxToggleButton::Command(wxCommandEvent & event) ProcessCommand(event); } -void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) +wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { - if ( controlpart != kControlNoPart ) - { - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - } + wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); + event.SetInt(GetValue()); + event.SetEventObject(this); + ProcessCommand(event); + return noErr ; } #endif // wxUSE_TOGGLEBTN diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 58b625e7b2..4869227f6c 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 @@ -233,34 +232,21 @@ 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 ) ; - } + DisableControl( 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") ) ; @@ -406,27 +392,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 ) @@ -577,57 +542,5 @@ void wxToolBar::OnPaint(wxPaintEvent& event) event.Skip() ; } -void wxToolBar::OnMouse( wxMouseEvent &event ) -{ - if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) - { - - 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 ( 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 */ ) ; - } - } - } - } - } -} - #endif // wxUSE_TOOLBAR -- 2.45.2