Ticket #14902 (closed defect: fixed)
Double wxEVT_LEFT_UP events for clicks on native controls in wxOSX
| Reported by: | vadz | Owned by: | csomor |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9.5 |
| Component: | wxOSX-Cocoa | Version: | 2.9-svn |
| Keywords: | events | Cc: | |
| Blocked By: | Patch: | no | |
| Blocking: |
Description
There is some code in src/osx/cocoa/window.mm which synthesizes artificial wxEVT_LEFT_UP events when clicking on standard controls. This is clearly done on purpose and was added by r69886 but I have no idea why is it necessary and removing it does not result in #12363 reappearing, at least not with the stuff tested in the scroll sample under 10.8. OTOH removing it does fix the duplicate events as can be tested with the following change in the sample:
-
samples/minimal/minimal.cpp
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index a78e462..5261d94 100644
a b 141 141 // main frame 142 142 // ---------------------------------------------------------------------------- 143 143 144 static wxListBox* g_lbox; 145 146 static void OnLabelClick(wxMouseEvent& event) 147 { 148 event.Skip(); 149 150 g_lbox->Append(wxString::Format("Clicked at %s", 151 wxDateTime::Now().Format("%H:%M:%S.%l"))); 152 } 153 144 154 // frame constructor 145 155 MyFrame::MyFrame(const wxString& title) 146 156 : wxFrame(NULL, wxID_ANY, title) … … 167 177 SetMenuBar(menuBar); 168 178 #endif // wxUSE_MENUS 169 179 180 wxStaticText* st = new wxStaticText(this, wxID_ANY, "Click me", wxPoint(5, 5)); 181 g_lbox = new wxListBox(this, wxID_ANY, wxPoint(5, 30), wxSize(200, 200)); 182 st->Bind(wxEVT_LEFT_UP, OnLabelClick); 183 170 184 #if wxUSE_STATUSBAR 171 185 // create a status bar just for fun (by default with 1 pane only) 172 186 CreateStatusBar(2);
With current svn you get 2 lines for each click (under both 10.7 and 10.8 but I didn't test other versions). With
-
src/osx/cocoa/window.mm
diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 166388b..7f9de34 100644
a b 1147 1147 { 1148 1148 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd]; 1149 1149 superimpl(slf, (SEL)_cmd, event); 1150 1151 // super of built-ins keeps the mouse up, as wx expects this event, we have to synthesize it1152 1153 if ( [ event type] == NSLeftMouseDown )1154 {1155 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);1156 SetupMouseEvent(wxevent , event) ;1157 wxevent.SetEventType(wxEVT_LEFT_UP);1158 1159 GetWXPeer()->HandleWindowEvent(wxevent);1160 }1161 1150 } 1162 1151 } 1163 1152 }
you only get one, as expected.
So why do we do this and what's going to happen if we don't?
