Opened 3 years ago

Closed 15 months ago

#13748 closed defect (fixed)

wxDataViewCtrl does not correctly implement wxWindow::HasFocus(void) const method

Reported by: hartwigw Owned by:
Priority: normal Milestone: 3.0.0
Component: wxOSX-Cocoa Version: stable-latest
Keywords: wxDataViewCtrl HasFocus Cc:
Blocked By: Blocking: #13749, #13749, #13749
Patch: no

Description

Because of the fact that in the Cocoa version the native control is embedded in a NSScrollView the normal HasFocus method does not work correctly. Actually, wxWindow::HasFocus checks if the NSScrollView has the focus.

Patch attached.

Attachments (1)

wxDataView_16.patch download (2.7 KB) - added by hartwigw 3 years ago.

Download all attachments as: .zip

Change History (16)

Changed 3 years ago by hartwigw

comment:1 Changed 3 years ago by vadz

Can't this be fixed by overriding GetMainWindowOfCompositeControl()? If DoFindFocus() correctly returns some wxWindow* the general logic of FindFocus() and HasFocus() should really work and would be preferable to adding another ad-hoc workaround.

comment:2 Changed 3 years ago by hartwigw

GetMainWindowOfCompositeControl() should return a wxWindow*. But in the current implementation the native window (NSOutlineView) is not associated with a wxWindow (same holds for wxListBox). Therefore, I overloaded HasFocus().
Perhaps Stefan knows if this is easily possible because I did not dig into the deep details of Cocoa's wxWindow implementation. Basically he did the same in wxListBox.

comment:3 Changed 3 years ago by vadz

Sorry, where is this done in wxListBox? I thought wxListBox had the same problem (as per your own #13749), did you mean some other control by chance?

comment:4 Changed 3 years ago by hartwigw

Hi Vadim,

there is a misunderstanding. I meant: wxListBox is also attaching only a native NSOutlineView to the NSScrollView without creating another wxWindow.
Therefore, wxDataViewCtrl and wxListBox are facing the same problem:

wxWindow *wxWindowBase::DoFindFocus()
{
    return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
}

wxWidgetImpl::FindFocus() will find the right native NSView (in this case an NSOutlineView) but wxFindWindowFromWXWidget will not find a wxWindow because the found NSView is a child of an NSScrollView. And the NSScrollView only is linked to a wxWindow object.
The found NSView has no associated wxWindow object!

comment:5 Changed 3 years ago by vadz

  • Milestone changed from 2.9.3 to 2.9.4
  • Patch unset
  • Status changed from new to confirmed

The trouble is that wxWindow::FindFocus() still returns NULL when wxDVC has focus, AFAICS, even with this patch. We really need to ensure that it returns the correct wxWindow.

So the real solution is probably to call wxWidgetImpl::Associate() for the NSOutline widget instead of applying this patch. Unfortunately I won't have time to do this before 2.9.3.

comment:6 Changed 3 years ago by vadz

  • Blocking 13749 added

(In #13749) The same solution should be used here as in #13748.

comment:7 Changed 2 years ago by vadz

  • Milestone changed from 2.9.4 to 3.0

Stefan, I'd really appreciate some advice here. To summarize, the problem is that when NSOutlineView has focus we can't find the corresponding wxWindow as there is no link between the two.

My idea of calling wxWidgetImpl::Associate() doesn't work neither as we not only don't have any wxWindow associated with this NSOutlineView (actually wxCocoaOutlineView) but no wxWidgetImpl neither.

Under MSW there is more or less the same problem we have a map HWND -> wxWindow* there and any HWND can be put into it. In wxOSX it seems like we ought to have NSView* -> wxWindow* map but AFAICS we don't have it. Any idea about how else to handle it?

comment:8 Changed 2 years ago by vadz

  • Blocking

comment:9 Changed 22 months ago by vadz

  • Blocking

We really need to do something about wxWindow::FindFocus(). Making HasFocus() work is better than nothing so this should be done before 3.0 if nothing else can be, but it doesn't solve the real problem.

Stefan, is there any way to associate multiple native widgets to a wxWindow in wxOSX?

comment:10 Changed 18 months ago by Q

Does anyone have any thoughts on this? It seems to have died, and it's quite broken (I thought I was doing something wrong until I finally found these two bug reports.)

comment:11 Changed 18 months ago by vadz

I still don't know how to solve this without maintaining a map between NSViews and wxWindows and don't know all places that would need to be updated in wxOSX code if such a map was added.

comment:12 Changed 15 months ago by csomor

  • Blocking

(In #13749) according to my tests, wxListBox works correctly as of trunk, it has its NSTableView also registered in the wxListWidgetCocoaImpl constructor, at least when testing with the dialog sample and the default action dialog listbox. I'll be changing the code to correctly work if a NSClipView is focused.

comment:13 Changed 15 months ago by csomor

  • Blocking

comment:14 Changed 15 months ago by csomor

  • Status changed from confirmed to infoneeded_new

you were absolutely right Vadim, Associate call is what was missing from the impl's constructor, don't know why it didn't work for you, I'll commit that fix now, and in my tests HasFocus now works correctly

comment:15 Changed 15 months ago by SC

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

(In [74109]) associate the outline view with the impl, fixes #13748

Note: See TracTickets for help on using tickets.