From: Stefan Csomor Date: Tue, 20 Jan 2009 14:27:26 +0000 (+0000) Subject: streamlining slider, scroller, spinbutton for osx carbon and cocoa X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/19c7ac3d3bf1ac2113505a805a79c40ce3db1f5b streamlining slider, scroller, spinbutton for osx carbon and cocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58243 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index 11d00c8ccc..5b36ffe55a 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -365,7 +365,8 @@ public : virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ); - virtual SInt32 GetMaximum() const; + virtual wxInt32 GetMaximum() const; + virtual wxInt32 GetMinimum() const; virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ); virtual void SetRange( SInt32 minimum , SInt32 maximum ); diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index d1b4c83962..d1c7059d7e 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -114,6 +114,8 @@ public : bool ButtonClickDidStateChange() { return true ;} void SetMinimum( wxInt32 v ); void SetMaximum( wxInt32 v ); + wxInt32 GetMinimum() const; + wxInt32 GetMaximum() const; void PulseGauge(); void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ); @@ -219,16 +221,14 @@ protected : - (void)mouseExited:(NSEvent *)event;\ - (void)keyDown:(NSEvent *)event;\ - (void)keyUp:(NSEvent *)event;\ + - (BOOL)performKeyEquivalent:(NSEvent *)event;\ - (void)flagsChanged:(NSEvent *)event;\ - - (BOOL) becomeFirstResponder;\ - - (BOOL) resignFirstResponder; + - (BOOL)becomeFirstResponder;\ + - (BOOL)resignFirstResponder;\ + - (void)resetCursorRects; - #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \ - {\ - if ( !impl->DoHandleMouseEvent(event) )\ - [super mouseDown:event];\ - }\ - -(void)rightMouseDown:(NSEvent *)event\ + + #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN -(void)rightMouseDown:(NSEvent *)event\ {\ if ( !impl->DoHandleMouseEvent(event) )\ [super rightMouseDown:event];\ @@ -288,6 +288,12 @@ protected : if ( !impl->DoHandleMouseEvent(event) )\ [super mouseExited:event];\ }\ + -(BOOL)performKeyEquivalent:(NSEvent *)event\ + {\ + if ( !impl->DoHandleKeyEvent(event) )\ + return [super performKeyEquivalent:event];\ + return YES;\ + }\ -(void)keyDown:(NSEvent *)event\ {\ if ( !impl->DoHandleKeyEvent(event) )\ @@ -316,8 +322,31 @@ protected : if ( r )\ impl->DoNotifyFocusEvent( false );\ return r;\ + }\ + - (void) resetCursorRects\ + {\ + if ( impl )\ + {\ + wxWindow* wxpeer = impl->GetWXPeer();\ + if ( wxpeer )\ + {\ + NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\ + if (cursor == NULL)\ + [super resetCursorRects];\ + else\ + [self addCursorRect: [self bounds]\ + cursor: cursor];\ + }\ + }\ } - + + #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \ + {\ + if ( !impl->DoHandleMouseEvent(event) )\ + [super mouseDown:event];\ + }\ + WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN + #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl; #define WXCOCOAIMPL_COMMON_INTERFACE \ @@ -326,8 +355,7 @@ protected : - (BOOL) isFlipped;\ WXCOCOAIMPL_COMMON_EVENTS_INTERFACE - #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ - - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\ + #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\ {\ impl = theImplementation;\ }\ @@ -335,24 +363,28 @@ protected : {\ return impl;\ }\ + + #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ + WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ - (BOOL) isFlipped\ {\ return YES;\ - }\ + } - #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ - - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\ - {\ - impl = theImplementation;\ - }\ - - (wxWidgetCocoaImpl*) implementation\ + #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \ + WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ + - (BOOL) isFlipped\ {\ - return impl;\ - }\ + return YES;\ + } + + + #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \ + WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \ - (BOOL) isFlipped\ {\ return NO;\ - }\ + } // used for many wxControls diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 7a70f84fcf..f6ed9b27ec 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -233,6 +233,8 @@ public : virtual void Enable( bool enable ) = 0; virtual void SetMinimum( wxInt32 v ) = 0; virtual void SetMaximum( wxInt32 v ) = 0; + virtual wxInt32 GetMinimum() const = 0; + virtual wxInt32 GetMaximum() const = 0; virtual void PulseGauge() = 0; virtual void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0; diff --git a/include/wx/osx/scrolbar.h b/include/wx/osx/scrolbar.h index cd32595315..9d0a3568f6 100644 --- a/include/wx/osx/scrolbar.h +++ b/include/wx/osx/scrolbar.h @@ -48,11 +48,7 @@ public: // implementation only from now on void Command(wxCommandEvent& event); -#if wxOSX_USE_CARBON - virtual void MacHandleControlClick( WXWidget control , - wxInt16 controlpart , - bool mouseStillDown ) ; -#endif + virtual void TriggerScrollEvent( wxEventType scrollEvent ) ; virtual bool HandleClicked( double timestampsec ); protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/osx/slider.h b/include/wx/osx/slider.h index f2f40043e4..f0b416e11f 100644 --- a/include/wx/osx/slider.h +++ b/include/wx/osx/slider.h @@ -77,8 +77,8 @@ public: void Command(wxCommandEvent& event); // osx specific event handling common for all osx-ports - virtual bool HandleClicked( double timestampsec ); - void MacHandleControlClick(WXWidget control, wxInt16 controlpart, bool mouseStillDown); + virtual bool HandleClicked( double timestampsec ); + virtual void TriggerScrollEvent( wxEventType scrollEvent ) ; protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/osx/spinbutt.h b/include/wx/osx/spinbutt.h index 5c34e911d8..56025a11d2 100644 --- a/include/wx/osx/spinbutt.h +++ b/include/wx/osx/spinbutt.h @@ -58,9 +58,8 @@ public: // implementation -#if wxOSX_USE_CARBON - virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; -#endif + virtual void TriggerScrollEvent( wxEventType scrollEvent ) ; + // osx specific event handling common for all osx-ports virtual bool HandleClicked( double timestampsec ); diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 133b6d8fc9..a0ac8a1921 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -162,7 +162,7 @@ public: wxWindowMac *FindItem(long id) const; wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const; - virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; + virtual void TriggerScrollEvent( wxEventType scrollEvent ) ; virtual bool MacDoRedraw( void* updatergn , long time ) ; // this should not be overriden in classes above wxWindowMac @@ -252,6 +252,7 @@ public: // osx specific event handling common for all osx-ports virtual bool HandleClicked( double timestampsec ); + virtual bool HandleKeyEvent( wxKeyEvent& event ); protected: // For controls like radio buttons which are genuinely composite wxList m_subControls; diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index 944b22fd16..41469e71ab 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -1377,47 +1377,10 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi if ( !focus ) return false ; - bool handled; wxKeyEvent event(wxEVT_KEY_DOWN) ; MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ; - handled = focus->HandleWindowEvent( event ) ; - if ( handled && event.GetSkipped() ) - handled = false ; - -#if wxUSE_ACCEL - if ( !handled ) - { - wxWindow *ancestor = focus; - while (ancestor) - { - int command = ancestor->GetAcceleratorTable()->GetCommand( event ); - if (command != -1) - { - wxEvtHandler * const handler = ancestor->GetEventHandler(); - - wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); - handled = handler->ProcessEvent( command_event ); - - if ( !handled ) - { - // accelerators can also be used with buttons, try them too - command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED); - handled = handler->ProcessEvent( command_event ); - } - - break; - } - - if (ancestor->IsTopLevel()) - break; - - ancestor = ancestor->GetParent(); - } - } -#endif // wxUSE_ACCEL - - return handled ; + return focus->HandleKeyEvent(event); } bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) @@ -1428,9 +1391,8 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier bool handled; wxKeyEvent event( wxEVT_KEY_UP ) ; MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ; - handled = focus->HandleWindowEvent( event ) ; - return handled ; + return focus->HandleKeyEvent(event) ; } bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) diff --git a/src/osx/carbon/scrolbar.cpp b/src/osx/carbon/scrolbar.cpp index 7fc53b8ae5..6b9f0fc37c 100644 --- a/src/osx/carbon/scrolbar.cpp +++ b/src/osx/carbon/scrolbar.cpp @@ -55,81 +55,3 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, verify_noerr( err ); return peer; } - -void wxScrollBar::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 controlpart, bool mouseStillDown ) -{ -#if wxOSX_USE_CARBON - - int position = m_peer->GetValue(); - int minPos = 0 ; - int maxPos = m_peer->GetMaximum(); - - wxEventType scrollEvent = wxEVT_NULL; - int nScrollInc = 0; - - // all events have already been reported during mouse down, except for THUMBRELEASE - if ( !mouseStillDown && controlpart != kControlIndicatorPart ) - return; - - switch ( controlpart ) - { - case kControlUpButtonPart: - nScrollInc = -1; - scrollEvent = wxEVT_SCROLL_LINEUP; - break; - - case kControlDownButtonPart: - nScrollInc = 1; - scrollEvent = wxEVT_SCROLL_LINEDOWN; - break; - - case kControlPageUpPart: - nScrollInc = -m_pageSize; - scrollEvent = wxEVT_SCROLL_PAGEUP; - break; - - case kControlPageDownPart: - nScrollInc = m_pageSize; - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - break; - - case kControlIndicatorPart: - nScrollInc = 0; - if ( mouseStillDown ) - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - else - scrollEvent = wxEVT_SCROLL_THUMBRELEASE; - break; - - default: - wxFAIL_MSG(wxT("unknown scrollbar selector")); - break; - } - - int new_pos = position + nScrollInc; - - if (new_pos < minPos) - new_pos = minPos; - else 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 - HandleWindowEvent( event ); -#endif -} \ No newline at end of file diff --git a/src/osx/carbon/spinbutt.cpp b/src/osx/carbon/spinbutt.cpp index 2f6fc34266..219d9f5c1b 100644 --- a/src/osx/carbon/spinbutt.cpp +++ b/src/osx/carbon/spinbutt.cpp @@ -40,75 +40,4 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, return peer ; } -void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 controlpart, - bool WXUNUSED(mouseStillDown)) -{ - int inc = 0; - - switch ( controlpart ) - { - case kControlUpButtonPart : - inc = 1; - break; - - case kControlDownButtonPart : - inc = -1; - break; - - default: - break; - } - - // trigger scroll events - - wxEventType scrollEvent = wxEVT_NULL; - int oldValue = GetValue() ; - - int newValue = oldValue + inc; - - if (newValue < m_min) - { - if ( m_windowStyle & wxSP_WRAP ) - newValue = m_max; - else - newValue = m_min; - } - - if (newValue > m_max) - { - if ( m_windowStyle & wxSP_WRAP ) - newValue = m_min; - else - newValue = m_max; - } - - if ( newValue - oldValue == -1 ) - scrollEvent = wxEVT_SCROLL_LINEDOWN; - else if ( newValue - oldValue == 1 ) - scrollEvent = wxEVT_SCROLL_LINEUP; - else - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - - // Do not send an event if the value has not actually changed - // (Also works for wxSpinCtrl) - if ( newValue == oldValue ) - return; - - if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK ) - { - wxSpinEvent event( scrollEvent, m_windowId ); - - event.SetPosition( newValue ); - event.SetEventObject( this ); - if ((HandleWindowEvent( event )) && !event.IsAllowed()) - newValue = oldValue; - } - - m_peer->SetValue( newValue ); - - // always send a thumbtrack event - SendThumbTrackEvent() ; -} - #endif // wxUSE_SPINBTN diff --git a/src/osx/carbon/window.cpp b/src/osx/carbon/window.cpp index 392c061792..67227916f3 100644 --- a/src/osx/carbon/window.cpp +++ b/src/osx/carbon/window.cpp @@ -770,7 +770,35 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p { wxWindow* wx = wxFindWindowFromWXWidget( (WXWidget) control ) ; if ( wx ) - wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; + { + wxEventType scrollEvent = wxEVT_NULL; + switch ( partCode ) + { + case kControlUpButtonPart: + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case kControlDownButtonPart: + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case kControlPageUpPart: + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case kControlPageDownPart: + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case kControlIndicatorPart: + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + // when this is called as a live proc, mouse is always still down + // so no need for thumbrelease + // scrollEvent = wxEVT_SCROLL_THUMBRELEASE; + break; + } + wx->TriggerScrollEvent(scrollEvent) ; + } } } wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ; @@ -1132,17 +1160,15 @@ wxInt32 wxMacControl::GetValue() const return ::GetControl32BitValue( m_controlRef ); } -SInt32 wxMacControl::GetMaximum() const +wxInt32 wxMacControl::GetMaximum() const { return ::GetControl32BitMaximum( m_controlRef ); } -/* wxInt32 wxMacControl::GetMinimum() const { return ::GetControl32BitMinimum( m_controlRef ); } -*/ void wxMacControl::SetValue( wxInt32 v ) { diff --git a/src/osx/cocoa/scrolbar.mm b/src/osx/cocoa/scrolbar.mm index 804c5df533..74168cf6e0 100644 --- a/src/osx/cocoa/scrolbar.mm +++ b/src/osx/cocoa/scrolbar.mm @@ -43,17 +43,62 @@ WXCOCOAIMPL_COMMON_INTERFACE return self; } +WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN + +// we will have a mouseDown, then in the native +// implementation of mouseDown the tracking code +// is calling clickedAction, therefore we wire this +// to thumbtrack and only after super mouseDown +// returns we will call the thumbrelease + - (void) clickedAction: (id) sender { if ( impl ) { + wxEventType scrollEvent = wxEVT_NULL; + switch ([self hitPart]) + { + case NSScrollerIncrementLine: + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + case NSScrollerIncrementPage: + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + case NSScrollerDecrementLine: + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + case NSScrollerDecrementPage: + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + case NSScrollerKnob: + case NSScrollerKnobSlot: + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + case NSScrollerNoPart: + default: + return; + } + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); if ( wxpeer ) - wxpeer->HandleClicked(0); + wxpeer->TriggerScrollEvent(scrollEvent); } } -WXCOCOAIMPL_COMMON_IMPLEMENTATION +-(void)mouseDown:(NSEvent *)event +{ + if ( !impl->DoHandleMouseEvent(event) ) + [super mouseDown:event]; + + // send a release event in case we've been tracking the thumb + NSScrollerPart hit = [self hitPart]; + if ( impl && (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE); + } +} @end @@ -86,6 +131,11 @@ public : { return [(wxNSScroller*) m_osxView floatValue] * m_maximum; } + + wxInt32 GetMaximum() const + { + return m_maximum; + } protected: wxInt32 m_maximum; }; diff --git a/src/osx/cocoa/slider.mm b/src/osx/cocoa/slider.mm index a56acbeadd..2316dece5d 100644 --- a/src/osx/cocoa/slider.mm +++ b/src/osx/cocoa/slider.mm @@ -38,17 +38,36 @@ WXCOCOAIMPL_COMMON_INTERFACE return self; } +WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN + +// we will have a mouseDown, then in the native +// implementation of mouseDown the tracking code +// is calling clickedAction, therefore we wire this +// to thumbtrack and only after super mouseDown +// returns we will call the thumbrelease + - (void) clickedAction: (id) sender { if ( impl ) { wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); if ( wxpeer ) - wxpeer->HandleClicked(0); + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK); } } -WXCOCOAIMPL_COMMON_IMPLEMENTATION +-(void)mouseDown:(NSEvent *)event +{ + if ( !impl->DoHandleMouseEvent(event) ) + [super mouseDown:event]; + + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) + wxpeer->HandleClicked(0); + } +} @end diff --git a/src/osx/cocoa/spinbutt.mm b/src/osx/cocoa/spinbutt.mm index 872bef97a8..da57bbea78 100644 --- a/src/osx/cocoa/spinbutt.mm +++ b/src/osx/cocoa/spinbutt.mm @@ -19,6 +19,7 @@ @interface wxNSStepper : NSStepper { WXCOCOAIMPL_COMMON_MEMBERS + int formerValue; } WXCOCOAIMPL_COMMON_INTERFACE @@ -33,6 +34,7 @@ WXCOCOAIMPL_COMMON_INTERFACE { [super initWithFrame:frame]; impl = NULL; + formerValue = 0; [self setTarget: self]; [self setAction: @selector(clickedAction:)]; return self; @@ -44,11 +46,38 @@ WXCOCOAIMPL_COMMON_INTERFACE { wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); if ( wxpeer ) - wxpeer->HandleClicked(0); + { + // because wx expects to be able to veto + // a change we must revert the value change + // and expose it + int currentValue = [self intValue]; + [self setIntValue:formerValue]; + int inc = currentValue-formerValue; + + // adjust for wrap arounds + if ( inc > 1 ) + inc = -1; + else if (inc < -1 ) + inc = 1; + + if ( inc == 1 ) + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP); + else if ( inc == -1 ) + wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN); + + formerValue = [self intValue]; + } } } -WXCOCOAIMPL_COMMON_IMPLEMENTATION +-(void)mouseDown:(NSEvent *)event +{ + formerValue = [self intValue]; + if ( !impl->DoHandleMouseEvent(event) ) + [super mouseDown:event]; +} + +WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN @end diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 9c03ed54fe..027f3e9812 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -41,8 +41,6 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const } - (void)drawRect: (NSRect) rect; -// TODO should the be moved to COMMON ? -- (void)resetCursorRects; WXCOCOAIMPL_COMMON_INTERFACE @@ -58,6 +56,8 @@ WXCOCOAIMPL_COMMON_INTERFACE - (void)setFloatValue:(float)aFloat; - (void)setDoubleValue:(double)aDouble; +- (double)minValue; +- (double)maxValue; - (void)setMinValue:(double)aDouble; - (void)setMaxValue:(double)aDouble; @@ -72,9 +72,9 @@ WXCOCOAIMPL_COMMON_INTERFACE - (id)contentView; @end -long wxOSXTranslateCocoaKey(unsigned short code, int unichar ) +long wxOSXTranslateCocoaKey( int unichar ) { - long retval = code; + long retval = unichar; switch( unichar ) { case NSUpArrowFunctionKey : @@ -131,25 +131,8 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent ) wxevent.m_controlDown = modifiers & NSControlKeyMask; wxevent.m_altDown = modifiers & NSAlternateKeyMask; wxevent.m_metaDown = modifiers & NSCommandKeyMask; - - wxString chars; - if ( eventType != NSFlagsChanged ) - { - NSString* nschars = [nsEvent characters]; - if ( nschars ) - { - wxCFStringRef cfchars((CFStringRef)[nschars retain]); - chars = cfchars.AsString(); - } - } - - int unichar = chars.Length() > 0 ? chars[0] : 0; -#if wxUSE_UNICODE - wxevent.m_uniChar = unichar; -#endif - wxevent.m_keyCode = wxOSXTranslateCocoaKey( [nsEvent keyCode], unichar ) ; -// wxevent.m_rawCode = keymessage; + wxevent.m_rawCode = [nsEvent keyCode]; wxevent.m_rawFlags = modifiers; wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ; @@ -167,6 +150,27 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent ) default : break ; } + + wxString chars; + if ( eventType != NSFlagsChanged ) + { + NSString* nschars = [nsEvent characters]; + if ( nschars ) + { + wxCFStringRef cfchars((CFStringRef)[nschars retain]); + chars = cfchars.AsString(); + } + } + + int unichar = chars.Length() > 0 ? chars[0] : 0; + long keyval = wxOSXTranslateCocoaKey(unichar) ; + if ( keyval == unichar && ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN ) ) + keyval = wxToupper( keyval ) ; + +#if wxUSE_UNICODE + wxevent.m_uniChar = unichar; +#endif + wxevent.m_keyCode = keyval; } UInt32 g_lastButton = 0 ; @@ -384,15 +388,6 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) } } -- (void) resetCursorRects -{ - [super resetCursorRects]; - wxWindow* wxpeer = impl->GetWXPeer(); - NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR(); - [self addCursorRect: [self bounds] - cursor: cursor]; -} - WXCOCOAIMPL_COMMON_IMPLEMENTATION - (BOOL) canBecomeKeyView @@ -623,6 +618,24 @@ void wxWidgetCocoaImpl::SetMaximum( wxInt32 v ) } } +wxInt32 wxWidgetCocoaImpl::GetMinimum() const +{ + if ( [m_osxView respondsToSelector:@selector(getMinValue:)] ) + { + return [m_osxView minValue]; + } + return 0; +} + +wxInt32 wxWidgetCocoaImpl::GetMaximum() const +{ + if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] ) + { + return [m_osxView maxValue]; + } + return 0; +} + void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap ) { if ( [m_osxView respondsToSelector:@selector(setImage:)] ) @@ -715,7 +728,8 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) { wxKeyEvent wxevent(wxEVT_KEY_DOWN); SetupKeyEvent( wxevent, event ); - return GetWXPeer()->HandleWindowEvent(wxevent); + + return GetWXPeer()->HandleKeyEvent(wxevent); } bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) diff --git a/src/osx/scrolbar_osx.cpp b/src/osx/scrolbar_osx.cpp index f9e695b48b..ab81178d22 100644 --- a/src/osx/scrolbar_osx.cpp +++ b/src/osx/scrolbar_osx.cpp @@ -124,3 +124,54 @@ wxSize wxScrollBar::DoGetBestSize() const CacheBestSize(best); return best; } + +void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent ) +{ + int position = m_peer->GetValue(); + int minPos = 0 ; + int maxPos = m_peer->GetMaximum(); + int nScrollInc = 0; + + if ( scrollEvent == wxEVT_SCROLL_LINEUP ) + { + nScrollInc = -1; + } + else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN ) + { + nScrollInc = 1; + } + else if ( scrollEvent == wxEVT_SCROLL_PAGEUP ) + { + nScrollInc = -m_pageSize; + } + else if ( scrollEvent == wxEVT_SCROLL_PAGEDOWN ) + { + nScrollInc = m_pageSize; + } + + int new_pos = position + nScrollInc; + + if (new_pos < minPos) + new_pos = minPos; + else 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 + HandleWindowEvent( event ); +} \ No newline at end of file diff --git a/src/osx/slider_osx.cpp b/src/osx/slider_osx.cpp index c0e980c376..9452df9bad 100644 --- a/src/osx/slider_osx.cpp +++ b/src/osx/slider_osx.cpp @@ -23,7 +23,7 @@ END_EVENT_TABLE() // The dimensions of the different styles of sliders (from Aqua document) #ifdef wxOSX_USE_COCOA - #define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 25 + #define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 28 #define wxSLIDER_DIMENSIONACROSS_ARROW 21 #else #define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24 @@ -277,9 +277,7 @@ void wxSlider::Command(wxCommandEvent &event) ProcessCommand(event); } -void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 WXUNUSED(controlpart), - bool WXUNUSED(mouseStillDown)) +void wxSlider::TriggerScrollEvent( wxEventType scrollEvent) { // Whatever the native value is, we may need to invert it for calling // SetValue and putting the possibly inverted value in the event @@ -287,7 +285,7 @@ void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), SetValue( value ); - wxScrollEvent event( wxEVT_SCROLL_THUMBTRACK, m_windowId ); + wxScrollEvent event( scrollEvent, m_windowId ); event.SetPosition( value ); event.SetEventObject( this ); HandleWindowEvent( event ); @@ -300,23 +298,8 @@ void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), bool wxSlider::HandleClicked( double timestampsec ) { - // Whatever the native value is, we may need to invert it for calling - // SetValue and putting the possibly inverted value in the event - int value = ValueInvertOrNot( m_peer->GetValue() ) ; - - SetValue( value ) ; - - wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId ); - event.SetPosition( value ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); - cevent.SetInt( value ); - cevent.SetEventObject( this ); - - HandleWindowEvent( cevent ); - + TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE); + return true; } diff --git a/src/osx/spinbutt_osx.cpp b/src/osx/spinbutt_osx.cpp index 340678c273..15ea37ef37 100644 --- a/src/osx/spinbutt_osx.cpp +++ b/src/osx/spinbutt_osx.cpp @@ -81,12 +81,7 @@ void wxSpinButton::SendThumbTrackEvent() bool wxSpinButton::HandleClicked( double timestampsec ) { -#if wxOSX_USE_CARBON - // these have been handled by the live action proc already -#else - SendThumbTrackEvent() ; -#endif - + // all events have already been processed return true; } @@ -95,4 +90,67 @@ wxSize wxSpinButton::DoGetBestSize() const return wxSize( 16, 24 ); } +void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent) +{ + int inc = 0; + + if ( scrollEvent == wxEVT_SCROLL_LINEUP ) + { + inc = 1; + } + else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN ) + { + inc = -1; + } + + // trigger scroll events + + int oldValue = GetValue() ; + + int newValue = oldValue + inc; + + if (newValue < m_min) + { + if ( m_windowStyle & wxSP_WRAP ) + newValue = m_max; + else + newValue = m_min; + } + + if (newValue > m_max) + { + if ( m_windowStyle & wxSP_WRAP ) + newValue = m_min; + else + newValue = m_max; + } + + if ( newValue - oldValue == -1 ) + scrollEvent = wxEVT_SCROLL_LINEDOWN; + else if ( newValue - oldValue == 1 ) + scrollEvent = wxEVT_SCROLL_LINEUP; + else + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + + // Do not send an event if the value has not actually changed + // (Also works for wxSpinCtrl) + if ( newValue == oldValue ) + return; + + if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK ) + { + wxSpinEvent event( scrollEvent, m_windowId ); + + event.SetPosition( newValue ); + event.SetEventObject( this ); + if ((HandleWindowEvent( event )) && !event.IsAllowed()) + newValue = oldValue; + } + + m_peer->SetValue( newValue ); + + // always send a thumbtrack event + SendThumbTrackEvent() ; +} + #endif // wxUSE_SPINBTN diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index dc830c5116..ee64a56198 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -459,10 +459,6 @@ void wxWindowMac::SetFocus() void wxWindowMac::DoCaptureMouse() { wxApp::s_captureWindow = (wxWindow*) this ; -#ifdef wxOSX_USE_COCOA - // TODO do we really need this ? - m_peer->SetFocus() ; -#endif m_peer->CaptureMouse() ; } @@ -2214,9 +2210,7 @@ void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) ) #endif } -void wxWindowMac::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 WXUNUSED(controlpart), - bool WXUNUSED(mouseStillDown)) +void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) ) { } @@ -2304,6 +2298,47 @@ bool wxWindowMac::IsShownOnScreen() const return wxWindowBase::IsShownOnScreen(); } +bool wxWindowMac::HandleKeyEvent( wxKeyEvent& event ) +{ + bool handled = HandleWindowEvent( event ) ; + if ( handled && event.GetSkipped() ) + handled = false ; + +#if wxUSE_ACCEL + if ( !handled && event.GetEventType() == wxEVT_KEY_DOWN) + { + wxWindow *ancestor = this; + while (ancestor) + { + int command = ancestor->GetAcceleratorTable()->GetCommand( event ); + if (command != -1) + { + wxEvtHandler * const handler = ancestor->GetEventHandler(); + + wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); + handled = handler->ProcessEvent( command_event ); + + if ( !handled ) + { + // accelerators can also be used with buttons, try them too + command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED); + handled = handler->ProcessEvent( command_event ); + } + + break; + } + + if (ancestor->IsTopLevel()) + break; + + ancestor = ancestor->GetParent(); + } + } +#endif // wxUSE_ACCEL + + return handled ; +} + // // wxWidgetImpl //