From 31aac5fac445310c2975eec4220f95ec0f9343bf Mon Sep 17 00:00:00 2001 From: ali kettab Date: Fri, 15 Dec 2023 20:49:02 +0100 Subject: [PATCH] Get rid of QtGetScrollBarsContainer() from wxWindow API under wxQt Because It is simpler to initialize (the inherited) m_qtContainer member directly in derived classes during construction process, and make the API a little bit cleaner. --- include/wx/qt/frame.h | 1 - include/wx/qt/listbox.h | 2 -- include/wx/qt/textctrl.h | 2 -- include/wx/qt/window.h | 8 ++++---- src/qt/frame.cpp | 5 ----- src/qt/listbox.cpp | 6 +----- src/qt/textctrl.cpp | 8 +++----- src/qt/window.cpp | 40 +++++++++++++++++----------------------- 8 files changed, 25 insertions(+), 47 deletions(-) diff --git a/include/wx/qt/frame.h b/include/wx/qt/frame.h index d9b7e6b02c..b538df7ddb 100644 --- a/include/wx/qt/frame.h +++ b/include/wx/qt/frame.h @@ -51,7 +51,6 @@ public: virtual void RemoveChild( wxWindowBase *child ) override; QMainWindow *GetQMainWindow() const; - virtual QAbstractScrollArea *QtGetScrollBarsContainer() const override; protected: virtual wxPoint GetClientAreaOrigin() const override; diff --git a/include/wx/qt/listbox.h b/include/wx/qt/listbox.h index 4a123d712c..6607c95bd1 100644 --- a/include/wx/qt/listbox.h +++ b/include/wx/qt/listbox.h @@ -87,8 +87,6 @@ protected: virtual int DoListHitTest(const wxPoint& point) const override; - virtual QAbstractScrollArea *QtGetScrollBarsContainer() const override; - #if wxUSE_CHECKLISTBOX bool m_hasCheckBoxes; #endif // wxUSE_CHECKLISTBOX diff --git a/include/wx/qt/textctrl.h b/include/wx/qt/textctrl.h index 741f90122e..389421b02e 100644 --- a/include/wx/qt/textctrl.h +++ b/include/wx/qt/textctrl.h @@ -93,8 +93,6 @@ protected: virtual bool DoLoadFile(const wxString& file, int fileType) override; virtual bool DoSaveFile(const wxString& file, int fileType) override; - virtual QAbstractScrollArea *QtGetScrollBarsContainer() const override; - // From wxTextEntry: virtual wxWindow *GetEditableWindow() override { return this; } diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index 62ac510cd0..b631e7172c 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -181,8 +181,6 @@ public: virtual void QtHandleShortcut ( int command ); #endif // wxUSE_ACCEL - virtual QAbstractScrollArea *QtGetScrollBarsContainer() const; - #if wxUSE_TOOLTIPS // applies tooltip to the widget. virtual void QtApplyToolTip(const wxString& text); @@ -228,11 +226,13 @@ protected: // itself. virtual QWidget* QtGetParentWidget() const { return GetHandle(); } - QWidget *m_qtWindow; + QWidget *m_qtWindow; + QAbstractScrollArea *m_qtContainer; // either nullptr or the same as m_qtWindow pointer + // if m_qtWindow derives from QAbstractScrollArea, + // e.g. QListWidget and QTextEdit. private: void Init(); - QAbstractScrollArea *m_qtContainer; // either nullptr or the same as m_qtWindow pointer // Return the viewport of m_qtContainer, if it's used, or just m_qtWindow. // diff --git a/src/qt/frame.cpp b/src/qt/frame.cpp index 6d94f5670e..04688697f9 100644 --- a/src/qt/frame.cpp +++ b/src/qt/frame.cpp @@ -209,11 +209,6 @@ void wxFrame::RemoveChild( wxWindowBase *child ) wxFrameBase::RemoveChild( child ); } -QAbstractScrollArea *wxFrame::QtGetScrollBarsContainer() const -{ - return nullptr; -} - // get the origin of the client area in the client coordinates // excluding any menubar and toolbar if any. wxPoint wxFrame::GetClientAreaOrigin() const diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index 324ae12d6d..4ec9f37936 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -178,6 +178,7 @@ void wxListBox::DoCreate(wxWindow* parent, long style) Init(); m_qtWindow = + m_qtContainer = m_qtListWidget = new wxQtListWidget( parent, this ); if ( style & wxLB_SORT ) @@ -368,11 +369,6 @@ void wxListBox::QtSendEvent(wxEventType evtType, int rowIndex, bool selected) SendEvent(evtType, rowIndex, selected); } -QAbstractScrollArea *wxListBox::QtGetScrollBarsContainer() const -{ - return static_cast(m_qtListWidget); -} - void wxListBox::UnSelectAll() { Q_FOREACH(QListWidgetItem* l, m_qtListWidget->selectedItems()) diff --git a/src/qt/textctrl.cpp b/src/qt/textctrl.cpp index 6ed0428e3d..45ce4d4509 100644 --- a/src/qt/textctrl.cpp +++ b/src/qt/textctrl.cpp @@ -676,6 +676,9 @@ bool wxTextCtrl::Create(wxWindow *parent, m_qtEdit->SetStyleFlags(style); + m_qtWindow = + m_qtContainer = m_qtEdit->ScrollBarsContainer(); + if ( QtCreateControl( parent, id, pos, size, style, validator, name ) ) { // set the initial text value without sending the event: @@ -910,8 +913,3 @@ QWidget *wxTextCtrl::GetHandle() const { return (QWidget *) m_qtEdit->GetHandle(); } - -QAbstractScrollArea *wxTextCtrl::QtGetScrollBarsContainer() const -{ - return m_qtEdit->ScrollBarsContainer(); -} diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 549db5d0e5..f13027b9a2 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -443,8 +443,8 @@ void wxWindowQt::AddChild( wxWindowBase *child ) { // Make sure all children are children of the inner scroll area widget (if any): - if ( QtGetScrollBarsContainer() ) - QtReparent( child->GetHandle(), QtGetScrollBarsContainer()->viewport() ); + if ( m_qtContainer ) + QtReparent( child->GetHandle(), m_qtContainer->viewport() ); wxWindowBase::AddChild( child ); } @@ -548,9 +548,9 @@ void wxWindowQt::Update() { wxLogTrace(TRACE_QT_WINDOW, wxT("wxWindow::Update %s"), GetName()); // send the paint event to the inner widget in scroll areas: - if ( QtGetScrollBarsContainer() ) + if ( m_qtContainer ) { - QtGetScrollBarsContainer()->viewport()->repaint(); + m_qtContainer->viewport()->repaint(); } else { GetHandle()->repaint(); } @@ -561,9 +561,9 @@ void wxWindowQt::Refresh( bool WXUNUSED( eraseBackground ), const wxRect *rect ) QWidget *widget; // get the inner widget in scroll areas: - if ( QtGetScrollBarsContainer() ) + if ( m_qtContainer ) { - widget = QtGetScrollBarsContainer()->viewport(); + widget = m_qtContainer->viewport(); } else { widget = GetHandle(); } @@ -701,15 +701,14 @@ QWidget *wxWindowQt::QtGetClientWidget() const /* Returns a scrollbar for the given orientation */ QScrollBar *wxWindowQt::QtGetScrollBar( int orientation ) const { - QAbstractScrollArea *scrollArea = QtGetScrollBarsContainer(); - wxCHECK_MSG( scrollArea, nullptr, "Window without scrolling area" ); + wxCHECK_MSG( m_qtContainer, nullptr, "Window without scrolling area" ); if ( orientation == wxHORIZONTAL ) { - return scrollArea->horizontalScrollBar(); + return m_qtContainer->horizontalScrollBar(); } - return scrollArea->verticalScrollBar(); + return m_qtContainer->verticalScrollBar(); } @@ -780,8 +779,8 @@ void wxWindowQt::ScrollWindow( int dx, int dy, const wxRect *rect ) { // check if this is a scroll area (scroll only inner viewport) QWidget *widget; - if ( QtGetScrollBarsContainer() ) - widget = QtGetScrollBarsContainer()->viewport(); + if ( m_qtContainer ) + widget = m_qtContainer->viewport(); else widget = GetHandle(); // scroll the widget or the specified rect (not children) @@ -1166,8 +1165,8 @@ bool wxWindowQt::QtSetBackgroundStyle() { QWidget *widget; // if it is a scroll area, don't make transparent (invisible) scroll bars: - if ( QtGetScrollBarsContainer() ) - widget = QtGetScrollBarsContainer()->viewport(); + if ( m_qtContainer ) + widget = m_qtContainer->viewport(); else widget = GetHandle(); // check if the control is created (wxGTK requires calling it before): @@ -1283,8 +1282,8 @@ bool wxWindowQt::QtHandlePaintEvent ( QWidget *handler, QPaintEvent *event ) * for the client area (the scrolled part). Events for the whole window * (including scrollbars and maybe status or menu bars are handled by Qt */ - if ( (QtGetScrollBarsContainer() && - QtGetScrollBarsContainer() != handler) || handler != GetHandle() ) + if ( (m_qtContainer && + m_qtContainer != handler) || handler != GetHandle() ) { return false; } @@ -1294,10 +1293,10 @@ bool wxWindowQt::QtHandlePaintEvent ( QWidget *handler, QPaintEvent *event ) // Prepare the Qt painter for wxWindowDC: bool ok = false; - if ( QtGetScrollBarsContainer() ) + if ( m_qtContainer ) { // QScrollArea can only draw in the viewport: - ok = m_qtPainter->begin( QtGetScrollBarsContainer()->viewport() ); + ok = m_qtPainter->begin( m_qtContainer->viewport() ); } if ( !ok ) { @@ -1774,11 +1773,6 @@ QWidget *wxWindowQt::GetHandle() const return m_qtWindow; } -QAbstractScrollArea *wxWindowQt::QtGetScrollBarsContainer() const -{ - return m_qtContainer; -} - void wxWindowQt::QtSetPicture( QPicture* pict ) { m_qtPicture.reset(pict);