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
This commit is contained in:
Stefan Csomor 2009-01-20 14:27:26 +00:00
parent 9623be70d0
commit 19c7ac3d3b
19 changed files with 408 additions and 299 deletions

View File

@ -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 );

View File

@ -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_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \
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\
{\
return impl;\
}\
WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
- (BOOL) isFlipped\
{\
return NO;\
}\
}
// used for many wxControls

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 );

View File

@ -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;

View File

@ -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 )

View File

@ -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
}

View File

@ -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

View File

@ -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 )
{

View File

@ -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;
};

View File

@ -38,8 +38,29 @@ 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->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
}
}
-(void)mouseDown:(NSEvent *)event
{
if ( !impl->DoHandleMouseEvent(event) )
[super mouseDown:event];
if ( impl )
{
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
@ -48,8 +69,6 @@ WXCOCOAIMPL_COMMON_INTERFACE
}
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION
@end
wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,

View File

@ -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

View File

@ -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)

View File

@ -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 );
}

View File

@ -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;
}

View File

@ -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

View File

@ -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
//