From abdeb9e7006488bf917d90048fcd0cbe22f44a71 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 4 May 2004 07:09:32 +0000 Subject: [PATCH] Added wxControl::PostCreation for wxGTK. Moved calls to InheritAttributes and ApplyWidgetStyle there, and added a call to SetInitialBestSize. Also removed calls to Show from Create since PostCreation already does it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/control.h | 2 ++ include/wx/gtk1/control.h | 2 ++ src/gtk/bmpbuttn.cpp | 12 +----------- src/gtk/button.cpp | 14 +------------- src/gtk/checkbox.cpp | 14 +------------- src/gtk/choice.cpp | 8 ++------ src/gtk/combobox.cpp | 25 ++++++------------------ src/gtk/control.cpp | 10 ++++++++++ src/gtk/gauge.cpp | 4 +--- src/gtk/listbox.cpp | 10 ++-------- src/gtk/notebook.cpp | 4 +--- src/gtk/radiobox.cpp | 8 +------- src/gtk/radiobut.cpp | 14 +------------- src/gtk/scrolbar.cpp | 7 +------ src/gtk/slider.cpp | 5 +---- src/gtk/spinbutt.cpp | 5 +---- src/gtk/spinctrl.cpp | 16 +--------------- src/gtk/statbmp.cpp | 6 ++---- src/gtk/statbox.cpp | 6 +----- src/gtk/statline.cpp | 4 +--- src/gtk/stattext.cpp | 30 +++++++---------------------- src/gtk/tbargtk.cpp | 4 +--- src/gtk/textctrl.cpp | 14 +------------- src/gtk/tglbtn.cpp | 40 +++++++++------------------------------ src/gtk1/bmpbuttn.cpp | 12 +----------- src/gtk1/button.cpp | 14 +------------- src/gtk1/checkbox.cpp | 14 +------------- src/gtk1/choice.cpp | 8 ++------ src/gtk1/combobox.cpp | 25 ++++++------------------ src/gtk1/control.cpp | 10 ++++++++++ src/gtk1/gauge.cpp | 4 +--- src/gtk1/listbox.cpp | 10 ++-------- src/gtk1/notebook.cpp | 4 +--- src/gtk1/radiobox.cpp | 8 +------- src/gtk1/radiobut.cpp | 14 +------------- src/gtk1/scrolbar.cpp | 7 +------ src/gtk1/slider.cpp | 5 +---- src/gtk1/spinbutt.cpp | 5 +---- src/gtk1/spinctrl.cpp | 16 +--------------- src/gtk1/statbmp.cpp | 6 ++---- src/gtk1/statbox.cpp | 6 +----- src/gtk1/statline.cpp | 4 +--- src/gtk1/stattext.cpp | 30 +++++++---------------------- src/gtk1/tbargtk.cpp | 4 +--- src/gtk1/textctrl.cpp | 14 +------------- src/gtk1/tglbtn.cpp | 40 +++++++++------------------------------ 46 files changed, 110 insertions(+), 414 deletions(-) diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index 623133c461..38b277a858 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -55,6 +55,8 @@ public: protected: virtual wxSize DoGetBestSize() const; + void PostCreation(const wxSize& size); + #ifdef __WXGTK20__ wxString PrepareLabelMnemonics( const wxString &label ) const; #endif diff --git a/include/wx/gtk1/control.h b/include/wx/gtk1/control.h index 623133c461..38b277a858 100644 --- a/include/wx/gtk1/control.h +++ b/include/wx/gtk1/control.h @@ -55,6 +55,8 @@ public: protected: virtual wxSize DoGetBestSize() const; + void PostCreation(const wxSize& size); + #ifdef __WXGTK20__ wxString PrepareLabelMnemonics( const wxString &label ) const; #endif diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index 2c7762f095..17bc64454f 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -149,13 +149,6 @@ bool wxBitmapButton::Create( wxWindow *parent, if (m_bmpNormal.Ok()) { - wxSize newSize = size; - wxSize bestSize = DoGetBestSize(); - if (newSize.x == -1) - newSize.x = bestSize.x; - if (newSize.y == -1) - newSize.y = bestSize.y; - SetSize( newSize.x, newSize.y ); OnSetBitmap(); } @@ -173,10 +166,7 @@ bool wxBitmapButton::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index bc4dff9768..1fc794b763 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -135,19 +135,7 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize best_size( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = best_size.x; - if (new_size.y == -1) - new_size.y = best_size.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - SetSize( new_size ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index 2a7d0437bf..33437d0b08 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -120,19 +120,7 @@ bool wxCheckBox::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 97eb8e1203..9c63f8502f 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -122,12 +122,8 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - SetBestSize(size); - - Show( TRUE ); + PostCreation(size); + SetBestSize(size); // need this too because this is a wxControlWithItems return TRUE; } diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 7660f4a9fa..2972a0a998 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -171,8 +171,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, m_focusWidget = combo->entry; - PostCreation(); - InheritAttributes(); + PostCreation(size); ConnectWidget( combo->button ); @@ -189,24 +188,12 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, gtk_signal_connect( GTK_OBJECT(combo->list), "select-child", GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this ); - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if (new_size.y > size_best.y) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - { - SetSize( new_size.x, new_size.y ); - - // This is required for tool bar support - gtk_widget_set_usize( m_widget, new_size.x, new_size.y ); - } - - Show( TRUE ); + SetBestSize(size); // need this too because this is a wxControlWithItems + // This is required for tool bar support + wxSize setsize = GetSize(); + gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); + return TRUE; } diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 82f10af912..8e3e23ee57 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -86,6 +86,16 @@ wxSize wxControl::DoGetBestSize() const return wxSize(req.width, req.height); } + +void wxControl::PostCreation(const wxSize& size) +{ + wxWindow::PostCreation(); + InheritAttributes(); + ApplyWidgetStyle(); + SetInitialBestSize(size); +} + + #ifdef __WXGTK20__ wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const { diff --git a/src/gtk/gauge.cpp b/src/gtk/gauge.cpp index accbf86889..54360ce314 100644 --- a/src/gtk/gauge.cpp +++ b/src/gtk/gauge.cpp @@ -55,11 +55,9 @@ bool wxGauge::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); + PostCreation(size); SetBestSize(size); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index a4304cfe01..3436dae156 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -404,16 +404,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, DoAppend(choices[i]); } - // call it after appending the strings to the listbox, otherwise it doesn't - // work correctly - SetBestSize( size ); - m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); + SetBestSize(size); // need this too because this is a wxControlWithItems return TRUE; } diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index ef02dbb756..25edf2c110 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -365,15 +365,13 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event", GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this ); - PostCreation(); + PostCreation(size); SetFont( parent->GetFont() ); gtk_signal_connect( GTK_OBJECT(m_widget), "realize", GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 551fc826aa..37c9f529f2 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -246,16 +246,10 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, bool wasShown = IsShown(); if ( wasShown ) Hide(); // prevent PostCreation() from showing us - PostCreation(); - InheritAttributes(); - - ApplyWidgetStyle(); SetLabel( title ); - SetFont( parent->GetFont() ); - - SetBestSize( size ); + PostCreation(size); if ( wasShown ) Show(); diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index c8c6c53eca..1fd39b77fb 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -128,19 +128,7 @@ bool wxRadioButton::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index edc4f34d71..4aa408af1f 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -179,12 +179,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - SetBestSize(size); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index f3ab24213f..2dcc57d58e 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -141,10 +141,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index 2d5eb9650c..f0db6cb58b 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -150,10 +150,7 @@ bool wxSpinButton::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(new_size); return TRUE; } diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index a15f637dda..e5d32a1f85 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -126,24 +126,10 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if (new_size.y > size_best.y) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); + PostCreation(size); SetValue( value ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk/statbmp.cpp b/src/gtk/statbmp.cpp index 36aba28da0..9d206950ea 100644 --- a/src/gtk/statbmp.cpp +++ b/src/gtk/statbmp.cpp @@ -54,7 +54,7 @@ void wxStaticBitmap::CreatePixmapWidget() m_focusWidget = m_widget; - PostCreation(); + PostCreation(wxDefaultSize); } bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap, @@ -78,8 +78,6 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi if ( m_bitmap.GetMask() ) mask = m_bitmap.GetMask()->GetBitmap(); m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); - - SetBestSize( size ); } else { @@ -87,7 +85,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_focusWidget = m_widget; } - PostCreation(); + PostCreation(size); m_parent->DoAddChild( this ); return TRUE; diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index 6610fad49d..3bf811a25b 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -66,9 +66,7 @@ bool wxStaticBox::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - - InheritAttributes(); + PostCreation(size); // need to set non default alignment? gfloat xalign; @@ -82,8 +80,6 @@ bool wxStaticBox::Create( wxWindow *parent, if ( xalign ) gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.0); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk/statline.cpp b/src/gtk/statline.cpp index d4299aa62e..d10067f6ac 100644 --- a/src/gtk/statline.cpp +++ b/src/gtk/statline.cpp @@ -74,9 +74,7 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 6e0916a79a..7073bcd6cc 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -90,7 +90,7 @@ bool wxStaticText::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); + PostCreation(size); // the bug below only happens with GTK 2 #ifdef __WXGTK20__ @@ -109,27 +109,6 @@ bool wxStaticText::Create(wxWindow *parent, } #endif // __WXGTK20__ - ApplyWidgetStyle(); - - InheritAttributes(); -// wxControl::SetFont( parent->GetFont() ); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - -// if (ShouldInheritColours()) -// { -// SetBackgroundColour( parent->GetBackgroundColour() ); -// SetForegroundColour( parent->GetForegroundColour() ); -// } - Show( TRUE ); - return TRUE; } @@ -168,7 +147,10 @@ void wxStaticText::SetLabel( const wxString &label ) // adjust the label size to the new label unless disabled if (!HasFlag(wxST_NO_AUTORESIZE)) + { SetSize( GetBestSize() ); + SetSizeHints(GetSize()); + } } bool wxStaticText::SetFont( const wxFont &font ) @@ -177,8 +159,10 @@ bool wxStaticText::SetFont( const wxFont &font ) // adjust the label size to the new label unless disabled if (!HasFlag(wxST_NO_AUTORESIZE)) + { SetSize( GetBestSize() ); - + SetSizeHints(GetSize()); + } return ret; } diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 4755e17a0e..61804aa048 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -373,9 +373,7 @@ bool wxToolBar::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 648fdab6a5..815c0c66ac 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -348,17 +348,7 @@ bool wxTextCtrl::Create( wxWindow *parent, m_focusWidget = m_text; - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); + PostCreation(size); if (multi_line) gtk_widget_show(m_text); @@ -461,8 +451,6 @@ bool wxTextCtrl::Create( wxWindow *parent, wxTextAttr attrDef( colFg, m_backgroundColour, parent->GetFont() ); SetDefaultStyle( attrDef ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index f18eb9d04a..4d57e220cf 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -79,13 +79,6 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, if (m_bitmap.Ok()) { - wxSize newSize = size; - int border = (style & wxNO_BORDER) ? 4 : 10; - if (newSize.x == -1) - newSize.x = m_bitmap.GetWidth()+border; - if (newSize.y == -1) - newSize.y = m_bitmap.GetHeight()+border; - SetSize( newSize.x, newSize.y ); OnSetBitmap(); } @@ -95,10 +88,7 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild(this); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } @@ -207,15 +197,15 @@ void wxToggleBitmapButton::OnInternalIdle() // Get the "best" size for this control. wxSize wxToggleBitmapButton::DoGetBestSize() const { - wxSize ret(wxControl::DoGetBestSize()); - - if (!HasFlag(wxBU_EXACTFIT)) + wxSize best; + + if (m_bitmap.Ok()) { - if (ret.x < 80) ret.x = 80; + int border = HasFlag(wxNO_BORDER) ? 4 : 10; + best.x = m_bitmap.GetWidth()+border; + best.y = m_bitmap.GetHeight()+border; } - - - return ret; + return best; } // ------------------------------------------------------------------------ // wxToggleButton @@ -251,19 +241,7 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild(this); - PostCreation(); - InheritAttributes(); - - wxSize size_best(DoGetBestSize()); - wxSize new_size(size); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize(new_size.x, new_size.y); - - Show(TRUE); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index 2c7762f095..17bc64454f 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -149,13 +149,6 @@ bool wxBitmapButton::Create( wxWindow *parent, if (m_bmpNormal.Ok()) { - wxSize newSize = size; - wxSize bestSize = DoGetBestSize(); - if (newSize.x == -1) - newSize.x = bestSize.x; - if (newSize.y == -1) - newSize.y = bestSize.y; - SetSize( newSize.x, newSize.y ); OnSetBitmap(); } @@ -173,10 +166,7 @@ bool wxBitmapButton::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index bc4dff9768..1fc794b763 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -135,19 +135,7 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize best_size( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = best_size.x; - if (new_size.y == -1) - new_size.y = best_size.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - SetSize( new_size ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index 2a7d0437bf..33437d0b08 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -120,19 +120,7 @@ bool wxCheckBox::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 97eb8e1203..9c63f8502f 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -122,12 +122,8 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - SetBestSize(size); - - Show( TRUE ); + PostCreation(size); + SetBestSize(size); // need this too because this is a wxControlWithItems return TRUE; } diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 7660f4a9fa..2972a0a998 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -171,8 +171,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, m_focusWidget = combo->entry; - PostCreation(); - InheritAttributes(); + PostCreation(size); ConnectWidget( combo->button ); @@ -189,24 +188,12 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, gtk_signal_connect( GTK_OBJECT(combo->list), "select-child", GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this ); - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if (new_size.y > size_best.y) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - { - SetSize( new_size.x, new_size.y ); - - // This is required for tool bar support - gtk_widget_set_usize( m_widget, new_size.x, new_size.y ); - } - - Show( TRUE ); + SetBestSize(size); // need this too because this is a wxControlWithItems + // This is required for tool bar support + wxSize setsize = GetSize(); + gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); + return TRUE; } diff --git a/src/gtk1/control.cpp b/src/gtk1/control.cpp index 82f10af912..8e3e23ee57 100644 --- a/src/gtk1/control.cpp +++ b/src/gtk1/control.cpp @@ -86,6 +86,16 @@ wxSize wxControl::DoGetBestSize() const return wxSize(req.width, req.height); } + +void wxControl::PostCreation(const wxSize& size) +{ + wxWindow::PostCreation(); + InheritAttributes(); + ApplyWidgetStyle(); + SetInitialBestSize(size); +} + + #ifdef __WXGTK20__ wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const { diff --git a/src/gtk1/gauge.cpp b/src/gtk1/gauge.cpp index accbf86889..54360ce314 100644 --- a/src/gtk1/gauge.cpp +++ b/src/gtk1/gauge.cpp @@ -55,11 +55,9 @@ bool wxGauge::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); + PostCreation(size); SetBestSize(size); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index a4304cfe01..3436dae156 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -404,16 +404,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, DoAppend(choices[i]); } - // call it after appending the strings to the listbox, otherwise it doesn't - // work correctly - SetBestSize( size ); - m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); + SetBestSize(size); // need this too because this is a wxControlWithItems return TRUE; } diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index ef02dbb756..25edf2c110 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -365,15 +365,13 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event", GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this ); - PostCreation(); + PostCreation(size); SetFont( parent->GetFont() ); gtk_signal_connect( GTK_OBJECT(m_widget), "realize", GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 551fc826aa..37c9f529f2 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -246,16 +246,10 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, bool wasShown = IsShown(); if ( wasShown ) Hide(); // prevent PostCreation() from showing us - PostCreation(); - InheritAttributes(); - - ApplyWidgetStyle(); SetLabel( title ); - SetFont( parent->GetFont() ); - - SetBestSize( size ); + PostCreation(size); if ( wasShown ) Show(); diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index c8c6c53eca..1fd39b77fb 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -128,19 +128,7 @@ bool wxRadioButton::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/scrolbar.cpp b/src/gtk1/scrolbar.cpp index edc4f34d71..4aa408af1f 100644 --- a/src/gtk1/scrolbar.cpp +++ b/src/gtk1/scrolbar.cpp @@ -179,12 +179,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - SetBestSize(size); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index f3ab24213f..2dcc57d58e 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -141,10 +141,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/spinbutt.cpp b/src/gtk1/spinbutt.cpp index 2d5eb9650c..f0db6cb58b 100644 --- a/src/gtk1/spinbutt.cpp +++ b/src/gtk1/spinbutt.cpp @@ -150,10 +150,7 @@ bool wxSpinButton::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(new_size); return TRUE; } diff --git a/src/gtk1/spinctrl.cpp b/src/gtk1/spinctrl.cpp index a15f637dda..e5d32a1f85 100644 --- a/src/gtk1/spinctrl.cpp +++ b/src/gtk1/spinctrl.cpp @@ -126,24 +126,10 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if (new_size.y > size_best.y) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); + PostCreation(size); SetValue( value ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk1/statbmp.cpp b/src/gtk1/statbmp.cpp index 36aba28da0..9d206950ea 100644 --- a/src/gtk1/statbmp.cpp +++ b/src/gtk1/statbmp.cpp @@ -54,7 +54,7 @@ void wxStaticBitmap::CreatePixmapWidget() m_focusWidget = m_widget; - PostCreation(); + PostCreation(wxDefaultSize); } bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap, @@ -78,8 +78,6 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi if ( m_bitmap.GetMask() ) mask = m_bitmap.GetMask()->GetBitmap(); m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); - - SetBestSize( size ); } else { @@ -87,7 +85,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_focusWidget = m_widget; } - PostCreation(); + PostCreation(size); m_parent->DoAddChild( this ); return TRUE; diff --git a/src/gtk1/statbox.cpp b/src/gtk1/statbox.cpp index 6610fad49d..3bf811a25b 100644 --- a/src/gtk1/statbox.cpp +++ b/src/gtk1/statbox.cpp @@ -66,9 +66,7 @@ bool wxStaticBox::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - - InheritAttributes(); + PostCreation(size); // need to set non default alignment? gfloat xalign; @@ -82,8 +80,6 @@ bool wxStaticBox::Create( wxWindow *parent, if ( xalign ) gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.0); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk1/statline.cpp b/src/gtk1/statline.cpp index d4299aa62e..d10067f6ac 100644 --- a/src/gtk1/statline.cpp +++ b/src/gtk1/statline.cpp @@ -74,9 +74,7 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - PostCreation(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 6e0916a79a..7073bcd6cc 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -90,7 +90,7 @@ bool wxStaticText::Create(wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); + PostCreation(size); // the bug below only happens with GTK 2 #ifdef __WXGTK20__ @@ -109,27 +109,6 @@ bool wxStaticText::Create(wxWindow *parent, } #endif // __WXGTK20__ - ApplyWidgetStyle(); - - InheritAttributes(); -// wxControl::SetFont( parent->GetFont() ); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); - -// if (ShouldInheritColours()) -// { -// SetBackgroundColour( parent->GetBackgroundColour() ); -// SetForegroundColour( parent->GetForegroundColour() ); -// } - Show( TRUE ); - return TRUE; } @@ -168,7 +147,10 @@ void wxStaticText::SetLabel( const wxString &label ) // adjust the label size to the new label unless disabled if (!HasFlag(wxST_NO_AUTORESIZE)) + { SetSize( GetBestSize() ); + SetSizeHints(GetSize()); + } } bool wxStaticText::SetFont( const wxFont &font ) @@ -177,8 +159,10 @@ bool wxStaticText::SetFont( const wxFont &font ) // adjust the label size to the new label unless disabled if (!HasFlag(wxST_NO_AUTORESIZE)) + { SetSize( GetBestSize() ); - + SetSizeHints(GetSize()); + } return ret; } diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 4755e17a0e..61804aa048 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -373,9 +373,7 @@ bool wxToolBar::Create( wxWindow *parent, m_parent->DoAddChild( this ); - PostCreation(); - - Show( TRUE ); + PostCreation(size); return TRUE; } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 648fdab6a5..815c0c66ac 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -348,17 +348,7 @@ bool wxTextCtrl::Create( wxWindow *parent, m_focusWidget = m_text; - PostCreation(); - InheritAttributes(); - - wxSize size_best( DoGetBestSize() ); - wxSize new_size( size ); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize( new_size.x, new_size.y ); + PostCreation(size); if (multi_line) gtk_widget_show(m_text); @@ -461,8 +451,6 @@ bool wxTextCtrl::Create( wxWindow *parent, wxTextAttr attrDef( colFg, m_backgroundColour, parent->GetFont() ); SetDefaultStyle( attrDef ); - Show( TRUE ); - return TRUE; } diff --git a/src/gtk1/tglbtn.cpp b/src/gtk1/tglbtn.cpp index f18eb9d04a..4d57e220cf 100644 --- a/src/gtk1/tglbtn.cpp +++ b/src/gtk1/tglbtn.cpp @@ -79,13 +79,6 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, if (m_bitmap.Ok()) { - wxSize newSize = size; - int border = (style & wxNO_BORDER) ? 4 : 10; - if (newSize.x == -1) - newSize.x = m_bitmap.GetWidth()+border; - if (newSize.y == -1) - newSize.y = m_bitmap.GetHeight()+border; - SetSize( newSize.x, newSize.y ); OnSetBitmap(); } @@ -95,10 +88,7 @@ bool wxToggleBitmapButton::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild(this); - PostCreation(); - InheritAttributes(); - - Show( TRUE ); + PostCreation(size); return TRUE; } @@ -207,15 +197,15 @@ void wxToggleBitmapButton::OnInternalIdle() // Get the "best" size for this control. wxSize wxToggleBitmapButton::DoGetBestSize() const { - wxSize ret(wxControl::DoGetBestSize()); - - if (!HasFlag(wxBU_EXACTFIT)) + wxSize best; + + if (m_bitmap.Ok()) { - if (ret.x < 80) ret.x = 80; + int border = HasFlag(wxNO_BORDER) ? 4 : 10; + best.x = m_bitmap.GetWidth()+border; + best.y = m_bitmap.GetHeight()+border; } - - - return ret; + return best; } // ------------------------------------------------------------------------ // wxToggleButton @@ -251,19 +241,7 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild(this); - PostCreation(); - InheritAttributes(); - - wxSize size_best(DoGetBestSize()); - wxSize new_size(size); - if (new_size.x == -1) - new_size.x = size_best.x; - if (new_size.y == -1) - new_size.y = size_best.y; - if ((new_size.x != size.x) || (new_size.y != size.y)) - SetSize(new_size.x, new_size.y); - - Show(TRUE); + PostCreation(size); return TRUE; } -- 2.45.2