[Git][wxwidgets/wxwidgets][master] 6 commits: Add wxDPIChangedEvent::Scale() overloads for wxPoint and wxRect

6 views
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
May 2, 2023, 1:27:48 PM5/2/23
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • b2bb68dc
    by Vadim Zeitlin at 2023-05-01T17:21:03+01:00
    Add wxDPIChangedEvent::Scale() overloads for wxPoint and wxRect
    
    Allow scaling positions, in addition to the sizes, and, also, entire
    rectangles.
    
  • 7cee6d59
    by Vadim Zeitlin at 2023-05-01T17:21:03+01:00
    Fix updating wxFrame client size in wxEVT_DPI_CHANGED handler
    
    This didn't work correctly when switching from higher to lower DPI if
    the frame had a status bar because this status bar still had its old,
    bigger height, by the time SetClientSize() was called from the event
    handler, resulting in the frame size becoming too big.
    
    It notably resulted in having an unwanted gap between the frame contents
    and the status bar if the event handler called GetSizer()->Fit().
    
    Fix this by calling PositionStatusBar(), which also updates the status
    bar height to correspond to the new DPI as a side effect, from a new
    virtual MSWBeforeDPIChangedEvent() function which had to be added to
    allow wxFrame to customize DPI handling.
    
    Adding this new virtual function just for this isn't great, but the only
    alternatives seem even worse.
    
  • 0f19c0a0
    by Vadim Zeitlin at 2023-05-01T17:21:03+01:00
    Pass wxDPIChangedEvent to the just added MSWBeforeDPIChangedEvent()
    
    This is unusual, but this function may need to rescale some coordinates
    and it's convenient to just call event.Scale() then.
    
    So pass it the event that we are preparing to process to it instead of
    passing it new and old DPI separately and forcing it to deal with them
    itself (instead of using Scale()).
    
  • 0329dfec
    by Vadim Zeitlin at 2023-05-01T17:23:09+01:00
    Update wxSlider thumb before processing wxEVT_DPI_CHANGED
    
    This changes of 4713301cf5 (Fix font and thumb size of wxSlider after
    DPI change, 2019-08-27) fixed updating the slider thumb length on DPI
    change, but this happened too late because it was done after executing
    the user-defined handler for this event which could have updated the
    slider size, which led to a call to its overridden DoMoveWindow() which
    would use the old thumb length, resulting in the size remaining too big
    when switching from higher to lower DPI and, worse, too small (and not
    showing the thumb entirely) when switching in the other direction.
    
    Fix this by updating the thumb length earlier, by using the just added
    MSWBeforeDPIChangedEvent() for doing it instead of doing it in the event
    handler.
    
  • 79fa7536
    by Kvaz1r at 2023-05-02T18:58:36+02:00
    Fix showing hint in wxUniv wxTextCtrl
    
    Correctly remove the hint when the text control is focused.
    
    Closes #23511.
    
  • 26d342cb
    by Vadim Zeitlin at 2023-05-02T18:01:06+01:00
    Merge branch 'msw-dpi-handling-fixes'
    
    Fixes to make processing wxEVT_DPI_CHANGED work better.
    
    See #23510.
    

10 changed files:

Changes:

  • include/wx/event.h
    ... ... @@ -3129,7 +3129,12 @@ public:
    3129 3129
     
    
    3130 3130
         // Scale the value by the ratio between new and old DPIs carried by this
    
    3131 3131
         // event.
    
    3132
    +    wxPoint Scale(wxPoint pt) const;
    
    3132 3133
         wxSize Scale(wxSize sz) const;
    
    3134
    +    wxRect Scale(wxRect r) const
    
    3135
    +    {
    
    3136
    +        return wxRect(Scale(r.GetPosition()), Scale(r.GetSize()));
    
    3137
    +    }
    
    3133 3138
     
    
    3134 3139
         int ScaleX(int x) const { return Scale(wxSize(x, -1)).x; }
    
    3135 3140
         int ScaleY(int y) const { return Scale(wxSize(-1, y)).y; }
    

  • include/wx/msw/frame.h
    ... ... @@ -131,6 +131,8 @@ protected:
    131 131
         virtual void DoGetClientSize(int *width, int *height) const override;
    
    132 132
         virtual void DoSetClientSize(int width, int height) override;
    
    133 133
     
    
    134
    +    virtual void MSWBeforeDPIChangedEvent(const wxDPIChangedEvent& event) override;
    
    135
    +
    
    134 136
     #if wxUSE_MENUS_NATIVE
    
    135 137
         // perform MSW-specific action when menubar is changed
    
    136 138
         virtual void AttachMenuBar(wxMenuBar *menubar) override;
    

  • include/wx/msw/slider.h
    ... ... @@ -123,8 +123,8 @@ protected:
    123 123
         WXHBRUSH DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) override;
    
    124 124
     
    
    125 125
         virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) override;
    
    126
    +    virtual void MSWBeforeDPIChangedEvent(const wxDPIChangedEvent& event) override;
    
    126 127
     
    
    127
    -    void OnDPIChanged(wxDPIChangedEvent& event);
    
    128 128
     
    
    129 129
         // the labels windows, if any
    
    130 130
         wxSubwindows  *m_labels;
    

  • include/wx/msw/window.h
    ... ... @@ -605,6 +605,15 @@ protected:
    605 605
         // controls. The default version updates m_font of this window.
    
    606 606
         virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI);
    
    607 607
     
    
    608
    +    // Also called from MSWUpdateOnDPIChange() but, unlike the function above,
    
    609
    +    // this one is called after updating all the children and just before
    
    610
    +    // letting the application handle the given wxDPIChangedEvent (whose
    
    611
    +    // Scale() functions may be useful for the overridden versions).
    
    612
    +    virtual void
    
    613
    +    MSWBeforeDPIChangedEvent(const wxDPIChangedEvent& WXUNUSED(event))
    
    614
    +    {
    
    615
    +    }
    
    616
    +
    
    608 617
         // this allows you to implement standard control borders without
    
    609 618
         // repeating the code in different classes that are not derived from
    
    610 619
         // wxControl
    

  • interface/wx/event.h
    ... ... @@ -3475,10 +3475,19 @@ public:
    3475 3475
             For example, the returned value will be twice bigger than the original
    
    3476 3476
             one when switching from normal (96) DPI to high (2x, 192) DPI.
    
    3477 3477
     
    
    3478
    +        The overloads taking wxPoint and wxRect are only available in wxWidgets
    
    3479
    +        3.3.0 and later.
    
    3480
    +
    
    3478 3481
             @since 3.1.6
    
    3479 3482
          */
    
    3480 3483
         wxSize Scale(wxSize sz) const;
    
    3481 3484
     
    
    3485
    +    /// @overload
    
    3486
    +    wxPoint Scale(wxPoint pt) const;
    
    3487
    +
    
    3488
    +    /// @overload
    
    3489
    +    wxRect Scale(wxRect rect) const;
    
    3490
    +
    
    3482 3491
         /**
    
    3483 3492
             Rescale horizontal component to match the new DPI.
    
    3484 3493
     
    

  • src/common/event.cpp
    ... ... @@ -915,6 +915,11 @@ wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin)
    915 915
     // wxDPIChangedEvent
    
    916 916
     // ----------------------------------------------------------------------------
    
    917 917
     
    
    918
    +wxPoint wxDPIChangedEvent::Scale(wxPoint pt) const
    
    919
    +{
    
    920
    +    return wxRescaleCoord(pt).From(m_oldDPI).To(m_newDPI);
    
    921
    +}
    
    922
    +
    
    918 923
     wxSize wxDPIChangedEvent::Scale(wxSize sz) const
    
    919 924
     {
    
    920 925
         return wxRescaleCoord(sz).From(m_oldDPI).To(m_newDPI);
    

  • src/msw/frame.cpp
    ... ... @@ -947,3 +947,15 @@ wxPoint wxFrame::GetClientAreaOrigin() const
    947 947
     
    
    948 948
         return pt;
    
    949 949
     }
    
    950
    +
    
    951
    +void wxFrame::MSWBeforeDPIChangedEvent(const wxDPIChangedEvent& WXUNUSED(event))
    
    952
    +{
    
    953
    +#if wxUSE_STATUSBAR
    
    954
    +    // If this frame uses a status bar, we need to adjust its height here
    
    955
    +    // before executing the user-defined wxEVT_DPI_CHANGED handler which may
    
    956
    +    // want to change the client size of the frame (e.g. using wxSizer::Fit()),
    
    957
    +    // because otherwise this wouldn't work correctly because the status bar
    
    958
    +    // would still have its old height, corresponding to the old DPI.
    
    959
    +    PositionStatusBar();
    
    960
    +#endif // wxUSE_STATUSBAR
    
    961
    +}

  • src/msw/slider.cpp
    ... ... @@ -184,8 +184,6 @@ bool wxSlider::Create(wxWindow *parent,
    184 184
             SetSize(size);
    
    185 185
         }
    
    186 186
     
    
    187
    -    Bind(wxEVT_DPI_CHANGED, &wxSlider::OnDPIChanged, this);
    
    188
    -
    
    189 187
         return true;
    
    190 188
     }
    
    191 189
     
    
    ... ... @@ -649,13 +647,14 @@ void wxSlider::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
    649 647
         }
    
    650 648
     }
    
    651 649
     
    
    652
    -void wxSlider::OnDPIChanged(wxDPIChangedEvent& event)
    
    650
    +void wxSlider::MSWBeforeDPIChangedEvent(const wxDPIChangedEvent& event)
    
    653 651
     {
    
    652
    +    // We need to update the thumb before processing wxEVT_DPI_CHANGED in the
    
    653
    +    // user code, as it may update the slider size, which wouldn't work
    
    654
    +    // correctly if it still used the old thumb length.
    
    654 655
         int thumbLen = GetThumbLength();
    
    655 656
     
    
    656 657
         SetThumbLength(event.ScaleX(thumbLen));
    
    657
    -
    
    658
    -    event.Skip();
    
    659 658
     }
    
    660 659
     
    
    661 660
     // ----------------------------------------------------------------------------
    

  • src/msw/window.cpp
    ... ... @@ -5030,6 +5030,11 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
    5030 5030
     
    
    5031 5031
         wxDPIChangedEvent event(oldDPI, newDPI);
    
    5032 5032
         event.SetEventObject(this);
    
    5033
    +
    
    5034
    +    // Another hook to give the derived window a chance to update itself after
    
    5035
    +    // updating all the children, but before the user-defined event handler.
    
    5036
    +    MSWBeforeDPIChangedEvent(event);
    
    5037
    +
    
    5033 5038
         return HandleWindowEvent(event);
    
    5034 5039
     }
    
    5035 5040
     
    

  • src/univ/textctrl.cpp
    ... ... @@ -783,7 +783,7 @@ wxTextCtrl::~wxTextCtrl()
    783 783
     
    
    784 784
     void wxTextCtrl::DoSetValue(const wxString& value, int flags)
    
    785 785
     {
    
    786
    -    if ( value != GetValue() )
    
    786
    +    if ( value != DoGetValue() )
    
    787 787
         {
    
    788 788
             EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
    
    789 789
     
    


View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help

Reply all
Reply to author
Forward
0 new messages