Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement KEY Up/Down events on NSSearchControl/NSTextField on WXWidget. #326

Open
wants to merge 2 commits into
base: slippi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Externals/wxWidgets3/include/wx/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ enum wxKeyModifier
wxMOD_META = 0x0008,
wxMOD_WIN = wxMOD_META,
#if defined(__WXMAC__)
wxMOD_RAW_CONTROL = 0x0010,
wxMOD_RAW_CONTROL = 2,
#else
wxMOD_RAW_CONTROL = wxMOD_CONTROL,
#endif
Expand Down
105 changes: 105 additions & 0 deletions Externals/wxWidgets3/src/osx/cocoa/srchctrl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#import <objc/runtime.h>

#ifdef __BORLANDC__
#pragma hdrstop
Expand All @@ -31,6 +32,7 @@
@interface wxNSSearchField : NSSearchField
{
BOOL m_withinTextDidChange;
NSEvent* lastKeyDownEvent;
}

@end
Expand Down Expand Up @@ -63,6 +65,50 @@ - (void)textDidChange:(NSNotification *)aNotification
m_withinTextDidChange = NO;
}

- (BOOL)textView:(NSTextView *)aTextView
clickedOnLink:(id)link
atIndex:(NSUInteger)charIndex {
wxWidgetCocoaImpl *impl =
(wxWidgetCocoaImpl *)wxWidgetImpl::FindFromWXWidget(aTextView);
if (impl) {
wxWindow *wxpeer = (wxWindow *)impl->GetWXPeer();
if (wxpeer) {
wxMouseEvent evtMouse(wxEVT_LEFT_DOWN);
wxTextUrlEvent event(wxpeer->GetId(), evtMouse, (long int)charIndex,
(long int)charIndex);
event.SetEventObject(wxpeer);
wxpeer->HandleWindowEvent(event);
}
}
return NO;
}

- (BOOL)_handleClipboardEvent:(wxEventType)type {
wxWidgetImpl *impl = wxWidgetImpl::FindFromWXWidget(self);
wxWindow *wxpeer = impl ? impl->GetWXPeer() : NULL;
if (wxpeer) {
wxClipboardTextEvent evt(type, wxpeer->GetId());
evt.SetEventObject(wxpeer);
return wxpeer->HandleWindowEvent(evt);
}
return false;
}

- (void)copy:(id)sender {
if (![self _handleClipboardEvent:wxEVT_TEXT_COPY])
[super copy:sender];
}

- (void)cut:(id)sender {
if (![self _handleClipboardEvent:wxEVT_TEXT_CUT])
[super cut:sender];
}

- (void)paste:(id)sender {
if (![self _handleClipboardEvent:wxEVT_TEXT_PASTE])
[super paste:sender];
}

- (void)controlTextDidChange:(NSNotification *)aNotification
{
wxUnusedVar(aNotification);
Expand Down Expand Up @@ -100,6 +146,65 @@ - (BOOL) isWithinTextDidChange
return m_withinTextDidChange;
}

- (BOOL)control:(NSControl *)control
textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandSelector {
wxUnusedVar(textView);
wxUnusedVar(control);

BOOL handled = NO;

// send back key events wx' common code knows how to handle

wxWidgetCocoaImpl *impl =
(wxWidgetCocoaImpl *)wxWidgetImpl::FindFromWXWidget(self);
if (impl) {
wxWindow *wxpeer = (wxWindow *)impl->GetWXPeer();
if (wxpeer) {
if (commandSelector == @selector(insertNewline:)) {
[textView insertNewlineIgnoringFieldEditor:self];
handled = YES;
} else if (commandSelector == @selector(insertTab:)) {
[textView insertTabIgnoringFieldEditor:self];
handled = YES;
} else if (commandSelector == @selector(insertBacktab:)) {
[textView insertTabIgnoringFieldEditor:self];
handled = YES;
} else if (commandSelector == @selector(paste:)) {
[self paste:self];
handled = YES;
}
}
}

return handled;
}

- (void)keyDown:(NSEvent *)event {
wxWidgetCocoaImpl *impl =
(wxWidgetCocoaImpl *)wxWidgetImpl::FindFromWXWidget(self);
if (impl) {
wxWindow *wxpeer = (wxWindow *)impl->GetWXPeer();
if (wxpeer) {
if (impl == NULL || !impl->DoHandleKeyEvent(event))
[super keyDown:event];
}
}

}

- (void)keyUp:(NSEvent *)event {
wxWidgetCocoaImpl *impl =
(wxWidgetCocoaImpl *)wxWidgetImpl::FindFromWXWidget(self);
if (impl) {
wxWindow *wxpeer = (wxWindow *)impl->GetWXPeer();
if (wxpeer) {
if (impl == NULL || !impl->DoHandleKeyEvent(event))
[super keyUp:event];
}
}
}

@end

// ============================================================================
Expand Down
16 changes: 8 additions & 8 deletions Externals/wxWidgets3/src/osx/cocoa/textctrl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1582,17 +1582,17 @@ wxWindowID WXUNUSED(id),
long WXUNUSED(extraStyle))
{
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxWidgetCocoaImpl* c = NULL;
wxWidgetCocoaImpl*pWxWidgetCocoa = NULL;

if ( style & wxTE_MULTILINE )
{
wxNSTextScrollView* v = nil;
v = [[wxNSTextScrollView alloc] initWithFrame:r];
wxNSTextViewControl* t = new wxNSTextViewControl( wxpeer, v, style );
c = t;
c->SetNeedsFocusRect( true );
wxNSTextViewControl* textVControl = new wxNSTextViewControl( wxpeer, v, style );
pWxWidgetCocoa = textVControl;
pWxWidgetCocoa->SetNeedsFocusRect( true );

t->SetStringValue(str);
textVControl->SetStringValue(str);
}
else
{
Expand All @@ -1616,7 +1616,7 @@ long WXUNUSED(extraStyle))
[cell setScrollable:YES];

wxNSTextFieldControl* t = new wxNSTextFieldControl( wxpeer, wxpeer, v );
c = t;
pWxWidgetCocoa = t;

if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) )
{
Expand All @@ -1629,13 +1629,13 @@ long WXUNUSED(extraStyle))
else
{
// use native border
c->SetNeedsFrame(false);
pWxWidgetCocoa->SetNeedsFrame(false);
}

t->SetStringValue(str);
}

return c;
return pWxWidgetCocoa;
}


Expand Down
1 change: 1 addition & 0 deletions Externals/wxWidgets3/src/osx/srchctrl_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "wx/osx/private.h"

wxBEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
EVT_KEY_UP(wxTextCtrl::OnKeyDown)
wxEND_EVENT_TABLE()

wxIMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase);
Expand Down
19 changes: 17 additions & 2 deletions Externals/wxWidgets3/src/osx/textctrl_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,23 @@ void wxTextCtrl::OnKeyDown(wxKeyEvent& event)
if ( CanCut() )
Cut() ;
return;
default:
case 'Z':
if ( GetTextPeer() && GetTextPeer()->CanUndo() )
GetTextPeer()->Undo() ;
return;
default:
break;
}
} else if (event.GetModifiers() == wxMOD_CONTROL & wxMOD_SHIFT) {
switch( event.GetKeyCode() )
{
case 'Z':
if ( GetTextPeer() && GetTextPeer()->CanRedo() )
GetTextPeer()->Redo() ;
return;
default:
break;
}
}
// no, we didn't process it
event.Skip();
Expand Down Expand Up @@ -672,7 +686,8 @@ void wxTextWidgetImpl::Clear()

bool wxTextWidgetImpl::CanUndo() const
{
return false ;
// printf("CAN UNDO\n");
return false ;
}

void wxTextWidgetImpl::Undo()
Expand Down