Get rid of QtCreateControl() from wxQt code base

If possible, all windows should call wxWindow::Create() on creation now,
because among other things:
- It manages generic and non-generic windows uniformly and transparently
- It ensures an appropriate initial size for the window
- AddChild() and PostCreation() are automatically called
- Scrollbar policies are set in one place.
This commit is contained in:
ali kettab 2023-12-17 16:21:30 +01:00
parent 69ec562f16
commit aa562ea2fb
38 changed files with 156 additions and 182 deletions

View file

@ -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);
};

View file

@ -13,7 +13,6 @@
#include "wx/frame.h"
class QMainWindow;
class QAbstractScrollArea;
class WXDLLIMPEXP_CORE wxFrame : public wxFrameBase
{

View file

@ -10,7 +10,6 @@
class QListWidget;
class QModelIndex;
class QAbstractScrollArea;
class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase
{

View file

@ -8,7 +8,6 @@
#ifndef _WX_QT_TEXTCTRL_H_
#define _WX_QT_TEXTCTRL_H_
class QAbstractScrollArea;
class wxQtEdit;
class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase

View file

@ -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

View file

@ -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()

View file

@ -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()

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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;
}

View file

@ -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 );
}
// ----------------------------------------------------------------------------

View file

@ -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()

View file

@ -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)

View file

@ -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 );
}

View file

@ -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 )

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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 )

View file

@ -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 )

View file

@ -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

View file

@ -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

View file

@ -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 );

View file

@ -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)

View file

@ -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 >

View file

@ -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 )

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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)

View file

@ -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 );
}
// ----------------------------------------------------------------------------

View file

@ -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),

View file

@ -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;
}

View file

@ -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()

View file

@ -16,6 +16,7 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QScrollArea>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <QtWidgets/QShortcut>
@ -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<QAbstractScrollArea*>(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<wxQtWidget*>(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();