Ticket #13495 (closed defect: fixed)

Opened 20 months ago

Last modified 6 months ago

wxSpinCtrl value not updated when closing the dialog containing it

Reported by: andrewtrevorrow Owned by:
Priority: normal Milestone: 2.9.5
Component: wxOSX-Cocoa Version: 2.9-svn
Keywords: regression wxSpinCtrl SetFocus Cc:
Blocked By: 14142, 14142 Patch: no
Blocking:

Description

If a dialog is created with a wxSpinCtrl and SetFocus() is called on that control then no focus ring is displayed when the dialog appears.

To see the bug, run the dialogs sample, select Dialogs > Entry dialogs > Numeric entry. The spin ctrl's text box fails to have the focus even though there is a m_spinctrl->SetFocus() call in the wxNumberEntryDialog ctor code. No such problem in wxMac 2.8.12.

Change History

  Changed 18 months ago by vadz

  • milestone changed from 2.9.3 to 2.9.4

2.9.3 is already past

  Changed 16 months ago by disc

  • status changed from new to confirmed

This occurs because wxWidgetCocoaImpl::CanFocus returns false (even if Full Keyboard Access is on). As suggested in  this discussion removing wxWindowMac::AcceptsFocus does fix the problem, but is not a proper solution as mentioned by Stefan. I wanted to change CanFocus to use canBecomeFirstResponder but it's only available in iOS. Another possibility might be to do something like Carbon's wxMacControl::CanFocus which returns true if Full Keyboard Access is enabled.

  Changed 12 months ago by vadz

  • milestone deleted

Not 2.9.4-critical.

  Changed 9 months ago by vadz

  • status changed from confirmed to infoneeded_new

Could you please retest with the latest svn, notably after r72413?

  Changed 9 months ago by andrewtrevorrow

  • status changed from infoneeded_new to new

The focus problem has been fixed, but r72413 seems to have introduced new bugs:

1. Run the dialogs sample, select Dialogs > Entry dialogs > Numeric entry and type in a number like 77, then hit OK. The resulting dialog says "You've entered 50" rather than 77, so something is wrong.

2. The new wxSpinCtrl class no longer has a GetTextValue() method. I know this was only available on wxMac/wxOSX but it was very handy. The GetValue() method is a bit stupid -- it always returns a valid int even if the user has entered an invalid number like "zzz".

  Changed 9 months ago by vadz

  • milestone set to 2.9.5

I'll try to look at (1) next time I debug something under wxOSX.

As for (2), I agree such method would be useful but it really should be implemented for all platforms and not just wxOSX. Implementing it should be pretty simple everywhere...

follow-up: ↓ 8   Changed 7 months ago by vadz

  • status changed from new to confirmed
  • blockedby 14142 added
  • summary changed from wxOSX-Cocoa bug: wxSpinCtrl doesn't get focus if SetFocus() is called in dialog ctor to wxSpinCtrl value not updated when closing the dialog containing it

Unfortunately I don't know how to fix this properly. I could fix the problem with pressing "Enter" but not with clicking the "OK" button with the mouse. We're supposed to get wxEVT_KILL_FOCUS in this case but we don't. I'm afraid we need to wait for Stefan to find time to deal with #14142.

in reply to: ↑ 7   Changed 6 months ago by johnr

Replying to vadz:

Unfortunately I don't know how to fix this properly. I could fix the problem with pressing "Enter" but not with clicking the "OK" button with the mouse. We're supposed to get wxEVT_KILL_FOCUS in this case but we don't. I'm afraid we need to wait for Stefan to find time to deal with #14142.

I worked around this in my code by subclassing wxNumberEntryDialog as NumberEntryDialog and using

In the constructor
Bind( wxEVT_COMMAND_BUTTON_CLICKED, &NumberEntryDialog::OnOKbutt, this );

and 

void NumberEntryDialog::OnOKbutt( wxCommandEvent& event )
{
#ifdef __WXMAC__
    if( event.GetId() == wxID_OK )
    {
        wxWindow* buttOk = FindWindow( wxID_OK );
        if( buttOk )
            buttOk->SetFocus();
    }
#endif
    event.Skip();
}

It doesn't fix the underlying problem but works.

  Changed 6 months ago by vadz

So should we perhaps always set focus to the button being clicked in the code generating wxEVT_COMMAND_BUTTON_CLICKED, i.e. wxButton::OSXHandleClicked()? If your patch works, this should work too but I'm not sure if it's not going to result in some new bad side effects... Stefan, any idea?

  Changed 6 months ago by csomor

  • blockedby

(In #14142) with r73043 at least the window switches now trigger a focus lost as expected

  Changed 6 months ago by SC

(In [73045]) simulating focus events, see #13495

  Changed 6 months ago by vadz

  • status changed from confirmed to closed
  • resolution set to fixed

This does seem to be fixed, at least the numeric entry dialog in the dialogs sample works as expected now, great!

Note: See TracTickets for help on using tickets.