Improve native keyDown handling in wxOSX
Provide API for dealing with m_lastKeyDownEvent instead of using it directly and extend it to avoid sending duplicate events for keys which are mapped to multiple selectors, such as Ctrl-O with the default key bindings. Closes https://github.com/wxWidgets/wxWidgets/pull/1928
This commit is contained in:
committed by
Vadim Zeitlin
parent
de56f99c5a
commit
9be2c3717d
@@ -48,6 +48,26 @@ WXWindow WXDLLIMPEXP_CORE wxOSXGetKeyWindow();
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDialog;
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxWidgetCocoaImpl;
|
||||
|
||||
// a class which disables sending wx keydown events useful when adding text programmatically, for wx-internal use only
|
||||
class wxWidgetCocoaNativeKeyDownSuspender
|
||||
{
|
||||
public:
|
||||
// stops sending keydown events for text inserted into this widget
|
||||
explicit wxWidgetCocoaNativeKeyDownSuspender(wxWidgetCocoaImpl *target);
|
||||
|
||||
// resumes sending keydown events
|
||||
~wxWidgetCocoaNativeKeyDownSuspender();
|
||||
|
||||
private:
|
||||
wxWidgetCocoaImpl *m_target;
|
||||
NSEvent* m_nsevent;
|
||||
bool m_wxsent;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWidgetCocoaNativeKeyDownSuspender);
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
|
||||
{
|
||||
public :
|
||||
@@ -203,7 +223,24 @@ public :
|
||||
|
||||
protected:
|
||||
WXWidget m_osxView;
|
||||
|
||||
// begins processing of native key down event, storing the native event for later wx event generation
|
||||
void BeginNativeKeyDownEvent( NSEvent* event );
|
||||
// done with the current native key down event
|
||||
void EndNativeKeyDownEvent();
|
||||
// allow executing text changes without triggering key down events
|
||||
|
||||
// is currently processing a native key down event
|
||||
bool IsInNativeKeyDown() const;
|
||||
// the native key event
|
||||
NSEvent* GetLastNativeKeyDownEvent();
|
||||
// did send the wx event for the current native key down event
|
||||
void SetKeyDownSent();
|
||||
// was the wx event for the current native key down event sent
|
||||
bool WasKeyDownSent() const;
|
||||
|
||||
NSEvent* m_lastKeyDownEvent;
|
||||
bool m_lastKeyDownWXSent;
|
||||
#if !wxOSX_USE_NATIVE_FLIPPED
|
||||
bool m_isFlipped;
|
||||
#endif
|
||||
@@ -211,6 +248,8 @@ protected:
|
||||
// events, don't resend them
|
||||
bool m_hasEditor;
|
||||
|
||||
friend class wxWidgetCocoaNativeKeyDownSuspender;
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl);
|
||||
};
|
||||
|
||||
@@ -534,4 +573,3 @@ private:
|
||||
|
||||
#endif
|
||||
// _WX_PRIVATE_COCOA_H_
|
||||
|
||||
|
Reference in New Issue
Block a user