diff --git a/include/wx/qt/control.h b/include/wx/qt/control.h index 7483292594..f4ccca7c81 100644 --- a/include/wx/qt/control.h +++ b/include/wx/qt/control.h @@ -24,13 +24,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxControlNameStr)); - virtual wxSize DoGetBestSize() const override; - -protected: - bool QtCreateControl( wxWindow *parent, wxWindowID id, const wxPoint &pos, - const wxSize &size, long style, const wxValidator &validator, - const wxString &name ); - private: wxDECLARE_DYNAMIC_CLASS(wxControl); }; diff --git a/include/wx/qt/frame.h b/include/wx/qt/frame.h index b538df7ddb..ccf652cc38 100644 --- a/include/wx/qt/frame.h +++ b/include/wx/qt/frame.h @@ -13,7 +13,6 @@ #include "wx/frame.h" class QMainWindow; -class QAbstractScrollArea; class WXDLLIMPEXP_CORE wxFrame : public wxFrameBase { diff --git a/include/wx/qt/listbox.h b/include/wx/qt/listbox.h index 6607c95bd1..58e8358111 100644 --- a/include/wx/qt/listbox.h +++ b/include/wx/qt/listbox.h @@ -10,7 +10,6 @@ class QListWidget; class QModelIndex; -class QAbstractScrollArea; class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase { diff --git a/include/wx/qt/textctrl.h b/include/wx/qt/textctrl.h index 389421b02e..48b7ec46a8 100644 --- a/include/wx/qt/textctrl.h +++ b/include/wx/qt/textctrl.h @@ -8,7 +8,6 @@ #ifndef _WX_QT_TEXTCTRL_H_ #define _WX_QT_TEXTCTRL_H_ -class QAbstractScrollArea; class wxQtEdit; class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index 2fb91ee162..b0f55efb33 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -66,7 +66,8 @@ public: long style = 0, const wxString& name = wxASCII_STR(wxPanelNameStr)); - // Used by all window classes in the widget creation process. + // Derived classes have to call PostCreation() explicitly if they don't call + // our Create() method during widget creation process. void PostCreation( bool generic = true ); void AddChild( wxWindowBase *child ) override; @@ -202,6 +203,8 @@ protected: virtual void DoSetClientSize(int width, int height) override; virtual void DoGetClientSize(int *width, int *height) const override; + virtual wxSize DoGetBestSize() const override; + virtual void DoMoveWindow(int x, int y, int width, int height) override; #if wxUSE_TOOLTIPS diff --git a/src/qt/button.cpp b/src/qt/button.cpp index 630b9bf7a4..9262810364 100644 --- a/src/qt/button.cpp +++ b/src/qt/button.cpp @@ -44,7 +44,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, QtCreate(parent); SetLabel( label.IsEmpty() && wxIsStockID( id ) ? wxGetStockLabel( id ) : label ); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxButtonBase::Create( parent, id, pos, size, style, validator, name ); } wxWindow *wxButton::SetDefault() diff --git a/src/qt/calctrl.cpp b/src/qt/calctrl.cpp index d98f38e24b..92e9bcb7c1 100644 --- a/src/qt/calctrl.cpp +++ b/src/qt/calctrl.cpp @@ -96,7 +96,7 @@ bool wxCalendarCtrl::Create(wxWindow *parent, wxWindowID id, const wxDateTime& d if ( date.IsValid() ) SetDate(date); - return QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ); + return wxCalendarCtrlBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); } void wxCalendarCtrl::UpdateStyle() diff --git a/src/qt/checkbox.cpp b/src/qt/checkbox.cpp index 89348045b9..71245afde4 100644 --- a/src/qt/checkbox.cpp +++ b/src/qt/checkbox.cpp @@ -66,7 +66,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_qtCheckBox->setText( wxQtConvertString( label ) ); // Do the initialization here as WXValidateStyle may fail in unit tests - bool ok = QtCreateControl( parent, id, pos, size, style, validator, name ); + bool ok = wxCheckBoxBase::Create( parent, id, pos, size, style, validator, name ); WXValidateStyle(&style); diff --git a/src/qt/choice.cpp b/src/qt/choice.cpp index fc04100d0f..5e66acee00 100644 --- a/src/qt/choice.cpp +++ b/src/qt/choice.cpp @@ -138,7 +138,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, while ( n-- > 0 ) m_qtComboBox->addItem( wxQtConvertString( *choices++ )); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxChoiceBase::Create( parent, id, pos, size, style, validator, name ); } wxSize wxChoice::DoGetBestSize() const diff --git a/src/qt/combobox.cpp b/src/qt/combobox.cpp index 042d383328..ef3366ebea 100644 --- a/src/qt/combobox.cpp +++ b/src/qt/combobox.cpp @@ -149,7 +149,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, m_qtComboBox->addItem( wxQtConvertString( *choices++ )); m_qtComboBox->setCurrentText( wxQtConvertString( value )); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxChoiceBase::Create( parent, id, pos, size, style, validator, name ); } bool wxComboBox::IsReadOnly() const diff --git a/src/qt/control.cpp b/src/qt/control.cpp index 057619ab7a..cb3b60021d 100644 --- a/src/qt/control.cpp +++ b/src/qt/control.cpp @@ -43,37 +43,3 @@ bool wxControl::Create(wxWindow *parent, wxWindowID id, return isCreated; } - -bool wxControl::QtCreateControl( wxWindow *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, long style, - const wxValidator &validator, const wxString &name ) -{ - // The Qt widget has been created without a position/size so move/resize it: - - wxSize bestSize = GetBestSize(); - int width = ( size.GetWidth() == wxDefaultCoord ) ? bestSize.GetWidth() : size.GetWidth(); - int height = ( size.GetHeight() == wxDefaultCoord ) ? bestSize.GetHeight() : size.GetHeight(); - - DoMoveWindow( pos.x, pos.y, width, height ); - - // Let Qt handle the background: - SetBackgroundStyle(wxBG_STYLE_SYSTEM); - - if (!CreateControl( parent, id, pos, size, style, validator, name )) - return false; - - PostCreation(false); - return true; -} - -wxSize wxControl::DoGetBestSize() const -{ - wxSize minsize = wxQtConvertSize( GetHandle()->minimumSizeHint() ); - wxSize size = wxQtConvertSize( GetHandle()->sizeHint() ); - // best effort to ensure a correct size (note that some qt controls implement just one or both size hints) - if (size.GetWidth() < minsize.GetWidth()) - size.SetWidth(minsize.GetWidth()); - if (size.GetHeight() < minsize.GetHeight()) - size.SetHeight(minsize.GetHeight()); - return size; -} diff --git a/src/qt/datectrl.cpp b/src/qt/datectrl.cpp index 7a5bfa9018..81cd9b7faa 100644 --- a/src/qt/datectrl.cpp +++ b/src/qt/datectrl.cpp @@ -74,7 +74,7 @@ wxDatePickerCtrl::Create(wxWindow *parent, m_qtDateEdit->setCalendarPopup(style & wxDP_DROPDOWN); m_qtDateEdit->setDisplayFormat(QLocale::system().dateFormat(QLocale::ShortFormat)); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxDatePickerCtrlBase::Create( parent, id, pos, size, style, validator, name ); } // ---------------------------------------------------------------------------- diff --git a/src/qt/dialog.cpp b/src/qt/dialog.cpp index 7215fe4ed8..e25751435c 100644 --- a/src/qt/dialog.cpp +++ b/src/qt/dialog.cpp @@ -70,12 +70,7 @@ bool wxDialog::Create( wxWindow *parent, wxWindowID id, m_qtWindow->setWindowFlags(qtFlags); } - if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) - return false; - - PostCreation(); - - return true; + return wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ); } int wxDialog::ShowModal() diff --git a/src/qt/frame.cpp b/src/qt/frame.cpp index 04688697f9..b443bc7064 100644 --- a/src/qt/frame.cpp +++ b/src/qt/frame.cpp @@ -60,13 +60,16 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString& title, // QMainWindow takes ownership of the central widget pointer. // Not using QScrollArea or wxPanel is intentional here as it makes the - // implementation simpler and manageable. + // implementation simpler and more manageable. GetQMainWindow()->setCentralWidget( new wxQtCentralWidget( this, this ) ); if ( !wxFrameBase::Create( parent, id, title, pos, size, style, name ) ) + { return false; + } + + SetWindowStyleFlag(style); - PostCreation(); return true; } @@ -97,8 +100,6 @@ void wxFrame::SetStatusBar( wxStatusBar *statusBar ) if ( statusBar != nullptr ) { GetQMainWindow()->setStatusBar( statusBar->GetQStatusBar() ); - // Update statusbar sizes now that it has a size - statusBar->Refresh(); } else { @@ -213,35 +214,12 @@ void wxFrame::RemoveChild( wxWindowBase *child ) // excluding any menubar and toolbar if any. wxPoint wxFrame::GetClientAreaOrigin() const { - wxPoint pt = wxFrameBase::GetClientAreaOrigin(); - -#if wxUSE_MENUBAR - wxMenuBar * const menubar = GetMenuBar(); - if ( menubar && menubar->IsAttached() ) - pt.y += menubar->GetSize().y; -#endif // wxUSE_MENUBAR - - return pt; + return wxQtConvertPoint( GetQMainWindow()->centralWidget()->pos() ); } void wxFrame::DoGetClientSize(int *width, int *height) const { - wxWindow::DoGetClientSize(width, height); - - // Adjust the height, taking the status and menu bars into account, if any: - if ( height ) - { - if ( wxStatusBar *sb = GetStatusBar() ) - { - *height -= sb->GetSize().y; - } - - - if ( QWidget *qmb = GetQMainWindow()->menuWidget() ) - { - *height -= qmb->geometry().height(); - } - } + wxFrameBase::DoGetClientSize(width, height); } void wxFrame::DoSetClientSize(int width, int height) diff --git a/src/qt/gauge.cpp b/src/qt/gauge.cpp index b2852dfbb6..78b46c44b7 100644 --- a/src/qt/gauge.cpp +++ b/src/qt/gauge.cpp @@ -61,7 +61,7 @@ bool wxGauge::Create(wxWindow *parent, m_qtProgressBar->setTextVisible( style & wxGA_TEXT ); m_qtProgressBar->setValue(0); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxControl::Create( parent, id, pos, size, style, validator, name ); } diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index 4ec9f37936..7057a729c3 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -137,7 +137,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, } m_qtListWidget->addItem(item); } - return wxListBoxBase::Create( parent, id, pos, size, style, validator, name ); + return wxListBoxBase::Create( parent, id, pos, size, + style | wxVSCROLL | wxHSCROLL, + validator, name ); } bool wxListBox::Create(wxWindow *parent, wxWindowID id, @@ -170,7 +172,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, m_qtListWidget->addItem(item); } - return wxListBoxBase::Create( parent, id, pos, size, style, validator, name ); + return wxListBoxBase::Create( parent, id, pos, size, + style | wxVSCROLL | wxHSCROLL, + validator, name ); } void wxListBox::DoCreate(wxWindow* parent, long style) @@ -178,7 +182,6 @@ void wxListBox::DoCreate(wxWindow* parent, long style) Init(); m_qtWindow = - m_qtContainer = m_qtListWidget = new wxQtListWidget( parent, this ); if ( style & wxLB_SORT ) diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index 19b32d3228..1308d84789 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -1347,6 +1347,7 @@ bool wxListCtrl::Create(wxWindow *parent, ? new wxQtVirtualListModel(this) : new wxQtListModel(this); + m_qtWindow = m_qtTreeWidget = new wxQtListTreeWidget(parent, this); m_qtTreeWidget->setModel(m_model); m_model->SetView(m_qtTreeWidget); @@ -1355,7 +1356,9 @@ bool wxListCtrl::Create(wxWindow *parent, m_qtTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows); m_qtTreeWidget->setTabKeyNavigation(true); - if ( !QtCreateControl(parent, id, pos, size, style, validator, name) ) + if ( !wxListCtrlBase::Create(parent, id, pos, size, + style | wxVSCROLL | wxHSCROLL, + validator, name) ) return false; SetWindowStyleFlag(style); diff --git a/src/qt/menu.cpp b/src/qt/menu.cpp index 8907faed67..4e577fc884 100644 --- a/src/qt/menu.cpp +++ b/src/qt/menu.cpp @@ -213,23 +213,25 @@ QMenu *wxMenu::GetHandle() const wxMenuBar::wxMenuBar() { m_qtMenuBar = new QMenuBar(); - PostCreation(false); + + wxMenuBarBase::Create(nullptr, wxID_ANY); } -wxMenuBar::wxMenuBar( long WXUNUSED( style )) +wxMenuBar::wxMenuBar( long style ) { m_qtMenuBar = new QMenuBar(); - PostCreation(false); + + wxMenuBarBase::Create(nullptr, wxID_ANY, wxDefaultPosition, wxDefaultSize, style); } -wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED( style )) +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long style) { m_qtMenuBar = new QMenuBar(); for ( size_t i = 0; i < count; ++i ) Append( menus[ i ], titles[ i ] ); - PostCreation(false); + wxMenuBarBase::Create(nullptr, wxID_ANY, wxDefaultPosition, wxDefaultSize, style); } diff --git a/src/qt/msgdlg.cpp b/src/qt/msgdlg.cpp index 803c78205b..22251b0533 100644 --- a/src/qt/msgdlg.cpp +++ b/src/qt/msgdlg.cpp @@ -109,7 +109,7 @@ wxMessageDialog::wxMessageDialog( wxWindow *parent, const wxString& message, if ( style & wxSTAY_ON_TOP ) dlg->setWindowModality( Qt::ApplicationModal ); - PostCreation(); + PostCreation(false); Centre(wxBOTH | wxCENTER_FRAME); } diff --git a/src/qt/notebook.cpp b/src/qt/notebook.cpp index dbd3fc601f..9e111cf8f3 100644 --- a/src/qt/notebook.cpp +++ b/src/qt/notebook.cpp @@ -75,7 +75,7 @@ bool wxNotebook::Create(wxWindow *parent, { m_qtTabWidget = new wxQtTabWidget( parent, this ); - if ( !QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) + if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; if ( m_windowStyle & wxBK_RIGHT ) diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 756c0d06e5..c9e473b80d 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -196,7 +196,7 @@ bool wxRadioBox::Create(wxWindow *parent, m_qtGroupBox->setLayout(horzLayout); SetMajorDim(majorDim == 0 ? n : majorDim, style); - return QtCreateControl( parent, id, pos, size, style, val, name ); + return wxControl::Create( parent, id, pos, size, style, val, name ); } static QAbstractButton *GetButtonAt( const QButtonGroup *group, unsigned int n ) diff --git a/src/qt/radiobut.cpp b/src/qt/radiobut.cpp index de48011eda..8621d5760b 100644 --- a/src/qt/radiobut.cpp +++ b/src/qt/radiobut.cpp @@ -127,7 +127,7 @@ bool wxRadioButton::Create( wxWindow *parent, m_qtRadioButton = new wxQtRadioButton( parent, this ); m_qtRadioButton->setText( wxQtConvertString( label )); - if ( !QtCreateControl(parent, id, pos, size, style, validator, name) ) + if ( !wxRadioButtonBase::Create(parent, id, pos, size, style, validator, name) ) return false; // Check if we need to create a new button group: this must be done when diff --git a/src/qt/scrolbar.cpp b/src/qt/scrolbar.cpp index 44caa965b6..111a551c1c 100644 --- a/src/qt/scrolbar.cpp +++ b/src/qt/scrolbar.cpp @@ -52,7 +52,7 @@ bool wxScrollBar::Create( wxWindow *parent, wxWindowID id, m_qtScrollBar = new wxQtScrollBar( parent, this ); m_qtScrollBar->setOrientation( wxQtConvertOrientation( style, wxSB_HORIZONTAL )); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxScrollBarBase::Create( parent, id, pos, size, style, validator, name ); } int wxScrollBar::GetThumbPosition() const diff --git a/src/qt/slider.cpp b/src/qt/slider.cpp index 8396d969b5..c9be3c40d0 100644 --- a/src/qt/slider.cpp +++ b/src/qt/slider.cpp @@ -174,10 +174,10 @@ bool wxSlider::Create(wxWindow *parent, SetValue( value ); SetPageSize(wxMax(1, (maxValue - minValue) / 10)); - if ( !QtCreateControl( parent, id, pos, size, style, validator, name ) ) + if ( !wxSliderBase::Create( parent, id, pos, size, style, validator, name ) ) return false; - // SetTick() needs the window style which is normally set after QtCreateControl() + // SetTick() needs the window style which is normally set after wxSliderBase::Create() // is called. Pass 0 as tickPos parameter is not used by Qt anyhow. SetTick( 0 ); diff --git a/src/qt/spinbutt.cpp b/src/qt/spinbutt.cpp index 7cd44195af..d866acca68 100644 --- a/src/qt/spinbutt.cpp +++ b/src/qt/spinbutt.cpp @@ -91,7 +91,7 @@ bool wxSpinButton::Create(wxWindow *parent, wxSize newSize( size ); newSize.SetWidth( 18 ); - return QtCreateControl( parent, id, pos, newSize, style, wxDefaultValidator, name ); + return wxSpinButtonBase::Create( parent, id, pos, newSize, style, wxDefaultValidator, name ); } void wxSpinButton::SetRange(int min, int max) diff --git a/src/qt/spinctrl.cpp b/src/qt/spinctrl.cpp index ef8f58b317..e38339572f 100644 --- a/src/qt/spinctrl.cpp +++ b/src/qt/spinctrl.cpp @@ -56,7 +56,7 @@ bool wxSpinCtrlQt< T, Widget >::Create( wxWindow *parent, wxWindowID id, if ( !value.IsEmpty() ) SetValue( value ); - return QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ); + return wxSpinCtrlBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); } template< typename T, typename Widget > diff --git a/src/qt/statbmp.cpp b/src/qt/statbmp.cpp index fdca00d07f..68860043ba 100644 --- a/src/qt/statbmp.cpp +++ b/src/qt/statbmp.cpp @@ -52,7 +52,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, m_qtLabel = new wxQtStaticBmp( parent, this ); SetBitmap( label ); - return QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ); + return wxStaticBitmapBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); } static void SetPixmap( QLabel *label, const QPixmap *pixMap ) diff --git a/src/qt/statbox.cpp b/src/qt/statbox.cpp index 9fb44e6f1b..d4e8af0944 100644 --- a/src/qt/statbox.cpp +++ b/src/qt/statbox.cpp @@ -48,7 +48,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, m_qtGroupBox = new wxQtGroupBox( parent, this ); m_qtGroupBox->setTitle( wxQtConvertString( label ) ); - return QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ); + return wxStaticBoxBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); } QWidget *wxStaticBox::GetHandle() const diff --git a/src/qt/statline.cpp b/src/qt/statline.cpp index 0e427a939a..07a8ff3a0a 100644 --- a/src/qt/statline.cpp +++ b/src/qt/statline.cpp @@ -40,7 +40,7 @@ bool wxStaticLine::Create( wxWindow *parent, else if ( style & wxLI_VERTICAL ) m_qtFrame->setFrameStyle( QFrame::VLine ); - return QtCreateControl( parent, id, pos, size, style, wxDefaultValidator, name ); + return wxStaticLineBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); } QWidget *wxStaticLine::GetHandle() const diff --git a/src/qt/stattext.cpp b/src/qt/stattext.cpp index 5b30c56e47..54224088ff 100644 --- a/src/qt/stattext.cpp +++ b/src/qt/stattext.cpp @@ -63,12 +63,9 @@ bool wxStaticText::Create(wxWindow *parent, else m_qtLabel->setAlignment(Qt::AlignLeft); - if ( !QtCreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) - return false; - SetLabel(label); - return true; + return wxStaticTextBase::Create(parent, id, pos, size, style, wxDefaultValidator, name); } void wxStaticText::SetLabel(const wxString& label) diff --git a/src/qt/statusbar.cpp b/src/qt/statusbar.cpp index 750b323ec3..82450d2419 100644 --- a/src/qt/statusbar.cpp +++ b/src/qt/statusbar.cpp @@ -43,15 +43,13 @@ bool wxStatusBar::Create(wxWindow *parent, wxWindowID id, { m_qtStatusBar = new wxQtStatusBar( parent, this ); - if ( !QtCreateControl( parent, id, wxDefaultPosition, wxDefaultSize, + if ( !wxStatusBarBase::Create( parent, id, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, name ) ) return false; if ( style & wxSTB_SIZEGRIP ) m_qtStatusBar->setSizeGripEnabled(true); - PostCreation(); - SetFieldsCount(1); // Notice that child controls, if any, will be added using addWidget() in diff --git a/src/qt/textctrl.cpp b/src/qt/textctrl.cpp index 45ce4d4509..4a75ea647b 100644 --- a/src/qt/textctrl.cpp +++ b/src/qt/textctrl.cpp @@ -676,19 +676,12 @@ bool wxTextCtrl::Create(wxWindow *parent, m_qtEdit->SetStyleFlags(style); - m_qtWindow = - m_qtContainer = m_qtEdit->ScrollBarsContainer(); + m_qtWindow = m_qtEdit->ScrollBarsContainer(); - if ( QtCreateControl( parent, id, pos, size, style, validator, name ) ) - { - // set the initial text value without sending the event: - // (done here as needs CreateBase called to set flags for IsMultiLine) - ChangeValue( value ); - // set the default inner color (white), as it is replaced by PostCreation - SetBackgroundColour( wxSystemSettingsNative::GetColour( wxSYS_COLOUR_LISTBOX ) ); - return true; - } - return false; + // set the initial text value without sending the event + ChangeValue( value ); + + return wxTextCtrlBase::Create( parent, id, pos, size, style, validator, name ); } wxTextCtrl::~wxTextCtrl() diff --git a/src/qt/tglbtn.cpp b/src/qt/tglbtn.cpp index ad48b089e0..b873d014b7 100644 --- a/src/qt/tglbtn.cpp +++ b/src/qt/tglbtn.cpp @@ -101,7 +101,7 @@ bool wxToggleButton::Create(wxWindow *parent, // this button is toggleable and has a text label SetLabel( wxIsStockID( id ) ? wxGetStockLabel( id ) : label ); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxToggleButtonBase::Create( parent, id, pos, size, style, validator, name ); } void wxToggleButton::SetValue(bool state) diff --git a/src/qt/timectrl.cpp b/src/qt/timectrl.cpp index 0b990e2571..9abb579dc0 100644 --- a/src/qt/timectrl.cpp +++ b/src/qt/timectrl.cpp @@ -75,7 +75,7 @@ wxTimePickerCtrl::Create(wxWindow *parent, wxQtConvertTime(wxDateTime::Now()) ); m_qtTimeEdit->setDisplayFormat(QLocale::system().timeFormat(QLocale::ShortFormat)); - return QtCreateControl( parent, id, pos, size, style, validator, name ); + return wxTimePickerCtrlBase::Create( parent, id, pos, size, style, validator, name ); } // ---------------------------------------------------------------------------- diff --git a/src/qt/toolbar.cpp b/src/qt/toolbar.cpp index ebcf301b88..e1aaa729b0 100644 --- a/src/qt/toolbar.cpp +++ b/src/qt/toolbar.cpp @@ -167,15 +167,14 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, m_qtToolBar = new wxQtToolbar( parent, this ); m_qtToolBar->setWindowTitle( wxQtConvertString( name ) ); + if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) + { + return false; + } + SetWindowStyleFlag(style); - // not calling to wxWindow::Create, so do the rest of initialization: - if (parent) - parent->AddChild( this ); - - PostCreation(); - - return wxWindowBase::CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ); + return true; } wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), diff --git a/src/qt/toplevel.cpp b/src/qt/toplevel.cpp index 33a0666b5a..5a702c8e9a 100644 --- a/src/qt/toplevel.cpp +++ b/src/qt/toplevel.cpp @@ -29,35 +29,23 @@ wxTopLevelWindowQt::wxTopLevelWindowQt(wxWindow *parent, } bool wxTopLevelWindowQt::Create( wxWindow *parent, wxWindowID winId, - const wxString &title, const wxPoint &pos, const wxSize &sizeOrig, + const wxString &title, const wxPoint &pos, const wxSize &size, long style, const wxString &name ) { - wxSize size(sizeOrig); - if ( !size.IsFullySpecified() ) - size.SetDefaults( GetDefaultSize() ); - wxTopLevelWindows.Append( this ); - if (!CreateBase( parent, winId, pos, size, style, wxDefaultValidator, name )) + if (!wxWindow::Create( parent, winId, pos, size, style, name )) { wxFAIL_MSG( wxT("wxTopLevelWindowNative creation failed") ); return false; } - SetTitle( title ); - SetWindowStyleFlag( style ); - - if (pos != wxDefaultPosition) - m_qtWindow->move( pos.x, pos.y ); - - m_qtWindow->resize( wxQtConvertSize( size ) ); - // Prevent automatic deletion of Qt main window on close // (this should be the default, but left just fo enforce it) GetHandle()->setAttribute(Qt::WA_DeleteOnClose, false); - // not calling to wxWindow::Create, so do the rest of initialization: - if (parent) parent->AddChild( this ); + SetTitle( title ); + SetWindowStyleFlag( style ); return true; } diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp index 15a2f80c3e..a45afe6a8e 100644 --- a/src/qt/treectrl.cpp +++ b/src/qt/treectrl.cpp @@ -573,14 +573,20 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_qtWindow = m_qtTreeWidget = new wxQTreeWidget(parent, this); m_qtTreeWidget->header()->hide(); - SetWindowStyleFlag(style); - Bind(wxEVT_KEY_DOWN, &wxTreeCtrl::OnKeyDown, this); - return QtCreateControl(parent, id, pos, size, style, validator, name); + if ( !wxTreeCtrlBase::Create(parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, validator, name) ) + { + return false; + } + + SetWindowStyleFlag(style); + + return true; } wxTreeCtrl::~wxTreeCtrl() diff --git a/src/qt/window.cpp b/src/qt/window.cpp index c21440f87e..481c21080d 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,15 @@ inline QWidget* wxQtGetDrawingWidget(QAbstractScrollArea* qtContainer, return qtWidget; } + +inline wxSize wxQtGetBestSize(QWidget* qtWidget) +{ + auto size = qtWidget->sizeHint(); + // best effort to ensure a correct size (note that some qt controls + // implement just one or both size hints) + size = size.expandedTo(qtWidget->minimumSizeHint()); + return wxQtConvertSize(size); +} } // Base Widget helper (no scrollbar, used by wxWindow) @@ -56,6 +66,19 @@ class wxQtWidget : public wxQtEventSignalHandler< QWidget, wxWindowQt > { public: wxQtWidget( wxWindowQt *parent, wxWindowQt *handler ); + + virtual QSize sizeHint() const override + { + // Make sure the window has a valid initial size because the default size of a + // generic control (e.g. wxPanel) is (0, 0) when created. Quoting the Qt docs: + // + // "Setting the size to QSize(0, 0) will cause the widget + // to not appear on screen. This also applies to windows." + // + // The value 20 seems to be the default for wxPanel under wxMSW. + return QSize(20, 20); + } + }; wxQtWidget::wxQtWidget( wxWindowQt *parent, wxWindowQt *handler ) @@ -361,55 +384,64 @@ bool wxWindowQt::Create( wxWindowQt * parent, wxWindowID id, const wxPoint & pos // that a generic control, like wxPanel, is being created, so we need a very // simple control as a base: - wxSize initialSize = size; + bool isGeneric = false; if ( GetHandle() == nullptr ) { + isGeneric = true; + if ( style & (wxHSCROLL | wxVSCROLL) ) { m_qtWindow = m_qtContainer = new wxQtScrollArea( parent, this ); - - // If wx[HV]SCROLL is not given, the corresponding scrollbar is not shown - // at all. Otherwise it may be shown only on demand (default) or always, if - // the wxALWAYS_SHOW_SB is specified. - Qt::ScrollBarPolicy horzPolicy = (style & wxHSCROLL) - ? HasFlag(wxALWAYS_SHOW_SB) - ? Qt::ScrollBarAlwaysOn - : Qt::ScrollBarAsNeeded - : Qt::ScrollBarAlwaysOff; - Qt::ScrollBarPolicy vertPolicy = (style & wxVSCROLL) - ? HasFlag(wxALWAYS_SHOW_SB) - ? Qt::ScrollBarAlwaysOn - : Qt::ScrollBarAsNeeded - : Qt::ScrollBarAlwaysOff; - - m_qtContainer->setHorizontalScrollBarPolicy( horzPolicy ); - m_qtContainer->setVerticalScrollBarPolicy( vertPolicy ); } else + { m_qtWindow = new wxQtWidget( parent, this ); + } + } + else + { + m_qtContainer = dynamic_cast(m_qtWindow); + } - // The default size of a generic control (e.g. wxPanel) is (0, 0) when created and - // is ignored by Qt unless the widget is already assigned a valid size or is added - // to a QLayout to be managed with. The value 20 seems to be the default under wxMSW. - // Do not pass 'initialSize' to CreateBase() below, as it will be taken as the minimum - // size of the control, which is not the intention here. - initialSize.SetDefaults(wxSize(20, 20)); + if ( m_qtContainer ) + { + // If wx[HV]SCROLL is not given, the corresponding scrollbar is not shown + // at all. Otherwise it may be shown only on demand (default) or always, if + // the wxALWAYS_SHOW_SB is specified. + Qt::ScrollBarPolicy horzPolicy = (style & wxHSCROLL) + ? HasFlag(wxALWAYS_SHOW_SB) + ? Qt::ScrollBarAlwaysOn + : Qt::ScrollBarAsNeeded + : Qt::ScrollBarAlwaysOff; + Qt::ScrollBarPolicy vertPolicy = (style & wxVSCROLL) + ? HasFlag(wxALWAYS_SHOW_SB) + ? Qt::ScrollBarAlwaysOn + : Qt::ScrollBarAsNeeded + : Qt::ScrollBarAlwaysOff; + + m_qtContainer->setHorizontalScrollBarPolicy( horzPolicy ); + m_qtContainer->setVerticalScrollBarPolicy( vertPolicy ); } if ( !wxWindowBase::CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) return false; - parent->AddChild( this ); + if ( parent ) + parent->AddChild( this ); wxPoint p; if ( pos != wxDefaultPosition ) p = pos; + wxSize initialSize = size; + initialSize.SetDefaults( IsTopLevel() ? wxTopLevelWindowBase::GetDefaultSize() + : wxQtGetBestSize( GetHandle() ) ); + DoMoveWindow( p.x, p.y, initialSize.GetWidth(), initialSize.GetHeight() ); - PostCreation(); + PostCreation( isGeneric ); return true; } @@ -644,7 +676,6 @@ bool wxWindowQt::SetFont( const wxFont &font ) if (GetHandle()) { GetHandle()->setFont( font.GetHandle() ); - return true; } return wxWindowBase::SetFont(font); @@ -697,6 +728,10 @@ void wxWindowQt::DoGetTextExtent(const wxString& string, int *x, int *y, int *de QWidget *wxWindowQt::QtGetClientWidget() const { + auto frame = wxDynamicCast(this, wxFrame); + if ( frame ) + return frame->GetQMainWindow()->centralWidget(); + return wxQtGetDrawingWidget(m_qtContainer, GetHandle()); } @@ -1086,6 +1121,24 @@ void wxWindowQt::DoSetClientSize(int width, int height) } } +wxSize wxWindowQt::DoGetBestSize() const +{ + const wxSize size = wxWindowBase::DoGetBestSize(); + + if ( dynamic_cast(GetHandle()) ) + { + return size; + } + + wxSize bestSize = wxQtGetBestSize( GetHandle() ); + if ( size.IsFullySpecified() ) + { + bestSize.IncTo(size); + } + + return bestSize; +} + void wxWindowQt::DoMoveWindow(int x, int y, int width, int height) { QWidget *qtWidget = GetHandle();