Opened 2 years ago

Closed 2 years ago

#18243 closed defect (fixed)

Cannot enter text in popup window (MSW)

Reported by: ufospoke Owned by: vadz
Priority: normal Milestone:
Component: wxMSW Version: dev-latest
Keywords: Cc: pbfordev@…
Blocked By: Blocking:
Patch: no

Description

I would like to be able to enter some text in a wxTextCtrl part of a popup window but this does not work on MSW: a click in the text control does not move the focus to it. On OSX it is even worse: the popup is closed whenever we click in the text control. It works very well on GTK3.

Attached is a patch to the popup sample that reproduces the issue.

Attachments (3)

popup.patch download (445 bytes) - added by ufospoke 2 years ago.
patch to the popup sample that reproduces the issue
test-wxpopup.cpp download (2.8 KB) - added by ufospoke 2 years ago.
Another sample that shows the problem
test-wxpopup-scroll.cpp download (4.2 KB) - added by ufospoke 2 years ago.
Show the scrolling issue

Download all attachments as: .zip

Change History (15)

Changed 2 years ago by ufospoke

patch to the popup sample that reproduces the issue

Changed 2 years ago by ufospoke

Another sample that shows the problem

comment:1 Changed 2 years ago by vadz

  • Owner set to vadz
  • Status changed from new to accepted

I do see the problem with the patch to the popup sample but so far I haven't found any way to convince this wxTextCtrl to accept focus.

comment:2 Changed 2 years ago by pb101

  • Cc pbfordev@… added

Sorry if I am confusing this issue for something else but is it even supposed to work?

I know that on MSW in order for controls to work as expected in a wxComboCtrl pop-up in a modal dialog, I had to call UseAltPopupWindow(). The method has this comment

Call with enable as true to use a type of popup window that guarantees ability
to focus the popup control, and normal function of common native controls.
This alternative popup window is usually a wxDialog, and as such it's parent
frame will appear as if the focus has been lost from it.

Additionally, in src/common/combocmn.cpp there is this (please note the value and comment for TRANSIENT_POPUPWIN_IS_PERFECT define)

#if defined(__WXMSW__)
// Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
#include "wx/frame.h"
#define wxCC_GENERIC_TLW_IS_FRAME
#define wxComboCtrlGenericTLW   wxFrame

#define USE_TRANSIENT_POPUP           1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
#define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
                                        // native controls work on it like normal.
#define POPUPWIN_IS_PERFECT           0 // Same, but for non-transient popup window.
#define TEXTCTRL_TEXT_CENTERED        0 // 1 if text in textctrl is vertically centered
#define FOCUS_RING                    0 // No focus ring on wxMSW

//#undef wxUSE_POPUPWIN
//#define wxUSE_POPUPWIN 0

#elif defined(__WXGTK__)



comment:3 Changed 2 years ago by vadz

Sorry if I am confusing this issue for something else but is it even supposed to work?

I'd say it's natural to expect it to work, because why not. I always thought that all the hacks in wxComboCtrl code were just workarounds for the bugs/missing features in wxPopupWindow and I'd like to make them unnecessary.

How to do it is another question, in particular activation loss when showing the dropdown is not great neither... But right now I'm not sure if there is any other way.

comment:4 Changed 2 years ago by vadz

PR 986 fixes this, please test if you use wxPopupWindow in your code to check if it doesn't introduce any regressions. TIA!

comment:5 Changed 2 years ago by ufospoke

  • Cc ufospoke@… added

It took me a while to check your PR because although it became evident that it fixed the issue that prevented text to be entered in the text control of the popup window, at the same time, I could not see the popup window in my own code where I use to click on a base control to trigger the popop.
The fact is that I called Popup(this) (focus == this) which used to work and do not work anymore.
Nevertheless, I removed this and call Popup() which removes the focus from the base control (I preferred the old behaviour but that's not critical).

One thing does not work however: if my base control is close to the bottom of the frame and the text control at the bottom of the popup (with some other control at the top), when I click in the text control of the popup, the scrolled window where the base control is in scrolls down as if I had clicked in the scrolled window and not in the text control of the popup window... I will try to make a sample to show that.

Changed 2 years ago by ufospoke

Show the scrolling issue

comment:6 Changed 2 years ago by ufospoke

  • Cc ufospoke@… removed

File test-wxpopup-scroll.cpp shows the issue with the interaction of the click in the popup windows with the scrolled window that is below:
Scroll to put the text control at the bottom of your frame. Then click in the text control to make the popup appear. When you then click in the text control of the popup, the scrolled window scrolls down.

comment:7 follow-up: Changed 2 years ago by vadz

Concerning the Popup(this) issue: what is this? It must be a child of popup (including the popup itself), otherwise we can't set focus to it without dismissing the popup immediately after showing it.

As for the unwanted scrolling issue, this is due to propagating child focus events to wxScrolled which, by default, tries to scroll its focused child fully into view. The solution here is to not let have these events as popup children are not really its children, and I've updated PR 986 with the commit doing just this.

Please let me know if you see anything else still wrong, thanks!

comment:8 in reply to: ↑ 7 Changed 2 years ago by ufospoke

  • Cc ufospoke@… added

Concerning the Popup(this) issue: what is this? It must be a child of popup (including the popup itself), otherwise we can't set focus to it without dismissing the popup immediately after showing it.

OK, I didn't understand it like that. I used the address of the parent control so I could keep the selection on that control which apparently worked.

Here is what the doc says which seems to imply that it can be the parent and not a child of the popup:
"If winFocus is non-NULL, it will be kept focused while this window is shown, otherwise this window itself will receive focus. In any case, the popup will disappear automatically if it loses focus because of a user action."

As for the unwanted scrolling issue, this is due to propagating child focus events to wxScrolled which, by default, tries to scroll its focused child fully into view. The solution here is to not let have these events as popup children are not really its children, and I've updated PR 986 with the commit doing just this.

Great that works. I had to move some keyboard binding from the main window to the popup (which looks better in fact) and now it works.

Thanks a lot. I think you can push that.

Now here are the issues left but it can be another ticket as it is not MSW related:

  • not cursor is seen in the text control of the popup on GTK3
  • no mouse interaction in the popup window in OSX which makes is useless!

comment:9 Changed 2 years ago by vadz

Hmm, you're right about the focus parameter, I had forgotten it was supposed to work like this. Not sure if I can really make it happen and even if the focus is not on the popup initially, clicking inside the popup will still give focus to it. I'll think a bit more about it, but I'd be surprised if this could be made to work.

As for the other platforms, let's indeed have different tickets for them. I might look at the GTK problem but, as usual, I very much doubt I could do anything about the Mac one.

comment:10 Changed 2 years ago by ufospoke

  • Cc ufospoke@… removed

Ticket for issues on MSW:
https://trac.wxwidgets.org/ticket/18261

comment:11 Changed 2 years ago by Vadim Zeitlin <vadim@…>

In 9562ca2b/git-wxWidgets:

Block child window events propagation beyond wxPopupWindow

Set wxWS_EX_BLOCK_EVENTS to prevent events bubbling up to the popup
parent as it doesn't make much sense.

See #18243.

comment:12 Changed 2 years ago by Vadim Zeitlin <vadim@…>

  • Resolution set to fixed
  • Status changed from accepted to closed

In 5d565474/git-wxWidgets:

Merge branch 'msw-popup'

Reimplement wxPopupWindow using WS_POPUP instead of WS_CHILD window in
wxMSW as the new approach allows using the controls inside the popup
normally, unlike the old one.

See https://github.com/wxWidgets/wxWidgets/pull/986

Closes #18243.

Note: See TracTickets for help on using tickets.