Re: Re[4]: Mac shortcut keys issue. Keys being sent to parent frame window.
Tony Kennedy <[email protected]> Tue, 1 Apr 2025 22:37:33 -0700 (PDT)
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
ok, the more I look into this and think about it, all is ok and I was just
assuming copy/paste/etc should be handled automatically.
Essentially the copy/paste/etc routines in my app should respond to what is
selected. If focus is on a wxTextCtrl, I need to detect this and call the
wxTextCtrl copy/paste methods. I've seen users select some text in a
control and then click Edit->Copy (as they don't know that shortcut keys
exist) and that should work on a wxTextCtrl if that is what has the focus.
And this is not Mac specific, it's the same for any operating system.
So please ignore this thread. There is nothing wrong. I've now got a new
function that detects if a wxTextCtrl has focus and responds appropriately
(pasted below in case anyone else wants it).
Thanks to all for your comments (and making me think in more detail about
this).
Tony.
void wxMyTopWindow::OnCopy(wxCommandEvent& e)
{
if (OnShortcutKey(e, wxID_COPY))
return;
...........
other code to execute if a wxTextCtrl does not have focus.
...........
}
bool wxMyTopWindow::OnShortcutKey(wxCommandEvent &e, int nID)
{
wxWindow *pWndWithFocus = wxWindow::FindFocus();
if ( pWndWithFocus != NULL )
{
if ( pWndWithFocus->IsKindOf(wxCLASSINFO(wxTextCtrl)) )
{
wxTextCtrl *pTextCtrl = (wxTextCtrl*)(pWndWithFocus);
//int nID = e.GetId();
bool bHandled = false;
switch(nID)
{
case wxID_CUT:
pTextCtrl->Cut();
bHandled = true;
break;
case wxID_COPY:
pTextCtrl->Copy();
bHandled = true;
break;
case wxID_PASTE:
pTextCtrl->Paste();
bHandled = true;
break;
case wxID_CLEAR:
pTextCtrl->Clear();
bHandled = true;
break;
case wxID_SELECTALL:
pTextCtrl->SelectAll();
bHandled = true;
break;
case wxID_DELETE:
pTextCtrl->OnDelete(e);
bHandled = true;
break;
case wxID_UNDO:
pTextCtrl->Undo();
bHandled = true;
break;
case wxID_REDO:
pTextCtrl->Redo();
bHandled = true;
break;
//case wxID_FIND,
//pTextCtrl->Find();
//bHandled = true;
//break;
//wxID_DUPLICATE,
//wxID_REPLACE,
//wxID_REPLACE_ALL,
//wxID_PROPERTIES,
}
if ( bHandled == true)
{
e.Skip();
}
return bHandled;
}
}
return false;
}
On Tuesday, 1 April 2025 at 20:37:21 UTC+1 Tony Kennedy wrote:
> I'm no Mac specialist either.
>
> This has been driven by our users, they are complaining that in a floating
> panel containing a text control, the shortcut keys are not working. And
> they are right, the wxTextCtrl handles copy/paste etc, but if the
> wxTextCtrl is in a floating window, the main window intercepts the key
> presses. If the floating window had it's own menu, then sending the
> shortcut key to the menu would make sense. Maybe things need to be a little
> more complex.
>
> There are two possibilities. Either the current functionality in wx is
> wrong, or my app doesn't implement copy/paste correctly. Copy/paste in my
> app target the main window, not the control with the focus. So maybe the
> correct thing to do is modify the copy/paste code so it works on the
> control with the focus. But that probably would not work for me as a user
> can select things, then change config in another window before hitting
> copy/paste. Maybe the correct thing to do (for my app) is disable the main
> window copy/paste when a wxTextCtrl has focus. I'll experiment with that
> tomorrow to see if it fixes things (implementing that could take a ton of
> work though).
>
> Tony.
>
> PS. I've had some feedback from my first user : I think the shortcuts for
> the comment section are entirely fixed. I could do cmd+c, cmd+v,
> option+delete, command+delete inside the comment section without any
> problems. Also, the shortcuts work perfectly everywhere (not just the
> comment section).
>
>
>
>
>
>
> On Tuesday, 1 April 2025 at 17:52:21 UTC+1 Vadim Zeitlin wrote:
>
>> On Tue, 1 Apr 2025 06:42:34 -0700 (PDT) Tony Kennedy wrote:
>>
>> TK> In the existing wxWidgetCocoaImpl::keyEvent function (window.mm),
>> when a
>> TK> key event happens, it's sent to the menu first. If I re-order the
>> function
>> TK> to what is below (let the control have a go first), copy/paste work.
>> TK>
>> TK> Are there any Mac specialists here that can comment on this change?
>>
>> I'm not a Mac specialist, but I think that Mac applications are supposed
>> to send the events to the menu first, so it probably wouldn't be a good
>> idea to change this for the normal case. Can this be only done if the
>> current window is a floating one?
>>
>> Thanks,
>> VZ
>>
>> --
>> TT-Solutions: wxWidgets consultancy and technical support
>> https://www.tt-solutions.com/
>>
>
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/5f507c19-ebec-4a8c-94bf-41c6a7d3b53an%40googlegroups.com.