Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#15812 closed defect (fixed)

mouse-wheel coordinates are wrong

Reported by: LtJax Owned by: vadz
Priority: high Milestone:
Component: wxMSW Version: 3.0.0
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

Mouse wheel coordinates are wrong when the window returns a non-zero
GetClientAreaOrigin() because it is subtracted twice. For example, this happens when the window has a toolbar.

In wxWindowMSW::HandleMouseWheel, it is first subtracted in wxTopLevelWindowBase::DoScreenToClient which is called through wxWindowBase::ScreenToClient.

It is then again subtracted in wxWindowMSW::InitMouseEvent.

I'll attach a small patch that fixes the problem for me.

Attachments (1)

mouswheel_fix.patch download (719 bytes) - added by LtJax 8 months ago.

Download all attachments as: .zip

Change History (4)

Changed 8 months ago by LtJax

comment:1 Changed 8 months ago by vadz

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

Thanks, this looks a bit hackish but I don't see any better fix right now so I'll apply it.

Here is a test case allowing to reproduce the problem (the button is needed to prevent the event from being consumed by the text control, it needs to be focused to see the problem):

  • samples/toolbar/toolbar.cpp

    diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp
    index 81698c3..18cf715 100644
    a b class MyFrame: public wxFrame 
    142142    void OnUpdateToggleRadioBtn(wxUpdateUIEvent& event) 
    143143        { event.Enable( m_tbar != NULL ); } 
    144144 
     145    void OnWheel(wxMouseEvent& ev) 
     146    { 
     147        m_textWindow->AppendText(wxString::Format("Wheel at (%d, %d)\n", ev.m_x, ev.m_y)); 
     148        ev.Skip(); 
     149    } 
     150 
    145151private: 
    146152    void DoEnablePrint(); 
    147153    void DoDeletePrint(); 
    enum 
    278284                        MyFrame::OnUpdateToggleRadioBtn) 
    279285    EVT_UPDATE_UI(IDM_TOOLBAR_TOGGLE_HORIZONTAL_TEXT, 
    280286                  MyFrame::OnUpdateToggleHorzText) 
     287    EVT_MOUSEWHEEL(MyFrame::OnWheel) 
    281288END_EVENT_TABLE() 
    282289 
    283290// ============================================================================ 
    void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) 
    646653        sizer->Add(m_extraToolBar, 0, wxEXPAND, 0); 
    647654#endif 
    648655    sizer->Add(m_textWindow, 1, wxEXPAND, 0); 
     656    sizer->Add(new wxButton(m_panel, wxID_OK), 1); 
    649657} 
    650658 
    651659MyFrame::~MyFrame() 

comment:2 Changed 8 months ago by VZ

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

(In [75559]) Fix mouse wheel event coordinates in wxFrame in wxMSW.

The screen to client conversion for this event coordinates took the toolbar
height into account twice, resulting in a wrong value if the event was handled
in a frame that did have a toolbar.

Closes #15812.

comment:3 Changed 8 months ago by VZ

(In [75563]) Fix mouse wheel event coordinates in wxFrame in wxMSW.

The screen to client conversion for this event coordinates took the toolbar
height into account twice, resulting in a wrong value if the event was handled
in a frame that did have a toolbar.

Closes #15812.

Note: See TracTickets for help on using tickets.