Controls will readjust their size and minsize when SetLabel or SetFont

are called.  Fixed up wxStaticText to blend the wxST_NO_AUTOSIZE with
this new functionality.  Made SetBestSize public under the
SetBestFittingSize name.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-06-19 01:35:10 +00:00
parent 8de5b24e54
commit fe161a2685
43 changed files with 176 additions and 154 deletions

View File

@@ -32,10 +32,11 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxControlNameStr;
// wxControl is the base class for all controls
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxControlBase : public wxWindow
{
public:
wxControlBase() { }
wxControlBase() { Init(); }
virtual ~wxControlBase();
@@ -63,7 +64,16 @@ public:
// if the button was clicked)
virtual void Command(wxCommandEvent &event);
virtual void SetLabel(const wxString& label);
virtual bool SetFont(const wxFont& font);
virtual bool GetAdjustMinSizeFlag() const { return m_adjustMinSize; }
void SetAdjustMinSizeFlag(bool adjust) { m_adjustMinSize = adjust; }
protected:
void Init();
// creates the control (calls wxWindowBase::CreateBase inside) and adds it
// to the list of parents children
bool CreateControl(wxWindowBase *parent,
@@ -88,6 +98,9 @@ protected:
SetBestSize(size);
}
// should minsize and size be adjusted when font or label change?
bool m_adjustMinSize;
DECLARE_NO_COPY_CLASS(wxControlBase)
};

View File

@@ -52,7 +52,7 @@ public:
// char (the one immediately after '&') into m_chAccel (TODO not yet)
virtual void SetLabel( const wxString &label );
virtual wxString GetLabel() const;
virtual wxVisualAttributes GetDefaultAttributes() const;
protected:
@@ -63,6 +63,7 @@ protected:
virtual wxSize DoGetBestSize() const;
void PostCreation(const wxSize& size);
void PostSetLabel();
#ifdef __WXGTK20__
wxString PrepareLabelMnemonics( const wxString &label ) const;
@@ -93,6 +94,7 @@ protected:
wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on
bool m_createComplete;
private:
DECLARE_DYNAMIC_CLASS(wxControl)

View File

@@ -57,7 +57,8 @@ public:
wxString GetLabel() const;
void SetLabel( const wxString &label );
bool SetFont( const wxFont &font );
bool GetAdjustMinSizeFlag() const { return !HasFlag(wxST_NO_AUTORESIZE); }
bool SetForegroundColour( const wxColour& colour );
static wxVisualAttributes

View File

@@ -52,7 +52,7 @@ public:
// char (the one immediately after '&') into m_chAccel (TODO not yet)
virtual void SetLabel( const wxString &label );
virtual wxString GetLabel() const;
virtual wxVisualAttributes GetDefaultAttributes() const;
protected:
@@ -63,6 +63,7 @@ protected:
virtual wxSize DoGetBestSize() const;
void PostCreation(const wxSize& size);
void PostSetLabel();
#ifdef __WXGTK20__
wxString PrepareLabelMnemonics( const wxString &label ) const;
@@ -93,6 +94,7 @@ protected:
wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on
bool m_createComplete;
private:
DECLARE_DYNAMIC_CLASS(wxControl)

View File

@@ -57,7 +57,8 @@ public:
wxString GetLabel() const;
void SetLabel( const wxString &label );
bool SetFont( const wxFont &font );
bool GetAdjustMinSizeFlag() const { return !HasFlag(wxST_NO_AUTORESIZE); }
bool SetForegroundColour( const wxColour& colour );
static wxVisualAttributes

View File

@@ -40,7 +40,6 @@ public:
// accessors
void SetLabel( const wxString &str ) ;
bool SetFont( const wxFont &font );
protected :

View File

@@ -41,7 +41,6 @@ class WXDLLEXPORT wxStaticText: public wxStaticTextBase
// accessors
void SetLabel( const wxString &str ) ;
bool SetFont( const wxFont &font );
// operations
virtual void Command(wxCommandEvent& WXUNUSED(event)) {};

View File

@@ -45,8 +45,6 @@ public:
virtual void SetValue(bool value);
virtual bool GetValue() const;
virtual void SetLabel(const wxString& label);
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual void Command(wxCommandEvent& event);

View File

@@ -40,10 +40,6 @@ public:
long style = 0,
const wxString& name = wxStaticTextNameStr);
// override some methods to resize the window properly
virtual void SetLabel(const wxString& label);
virtual bool SetFont( const wxFont &font );
protected:
// implement/override some base class virtuals
virtual wxBorder GetDefaultBorder() const;

View File

@@ -45,7 +45,6 @@ public:
virtual bool GetValue() const ;
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual void SetLabel(const wxString& label);
virtual void Command(wxCommandEvent& event);
protected:

View File

@@ -17,6 +17,8 @@ public:
virtual void ApplyParentThemeBackground(const wxColour& bg)
{ SetBackgroundColour(bg); }
bool GetAdjustMinSizeFlag() const { return !HasFlag(wxST_NO_AUTORESIZE); }
private:
DECLARE_NO_COPY_CLASS(wxStaticTextBase)
};

View File

@@ -230,6 +230,9 @@ public:
void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
{ Move(pt.x, pt.y, flags); }
// A 'Smart' SetSize that will fill in default size values with 'best' size
void SetBestFittingSize(const wxSize& size=wxDefaultSize);
// Z-order
virtual void Raise() = 0;
virtual void Lower() = 0;
@@ -1136,15 +1139,10 @@ protected:
static int WidthDefault(int w) { return w == -1 ? 20 : w; }
static int HeightDefault(int h) { return h == -1 ? 20 : h; }
// set the best size for the control if the default size was given:
// replaces the fields of size == -1 with the best values for them and
// calls SetSize() if needed
//
// This function is rather unfortunately named.. it's really just a
// smarter SetSize / convenience function for expanding wxDefaultSize.
// Note that it does not influence the value returned by GetBestSize
// at all.
void SetBestSize(const wxSize& size);
// keep the old name for compatibility, at least until all the internal
// usages of it are changed to SetBestFittingSize
void SetBestSize(const wxSize& size) { SetBestFittingSize(size); }
// set the initial window size if none is given (i.e. at least one of the
// components of the size passed to ctor/Create() is -1)