* Implemented BestSize cache
* Added calls to InvalidateBestSize where things affecting BestSize are modified. There are probably several other places where this still needs to be done... * Added wxWindowBase::GetBestFittingSize that will merge the BestSize into the MinSize, (if any) and return the result. * SetBestFittingSize will now only set the MinSize to the value that was passed to it, without merging in the BestSize git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
cf82b73a0a
commit
9f88452895
@ -701,6 +701,19 @@ Returns the background colour of the window.
|
||||
\helpref{wxWindow::GetForegroundColour}{wxwindowgetforegroundcolour}
|
||||
|
||||
|
||||
\membersection{wxWindow::GetBestFittingSize}\label{wxwindowgetbestfittingsize}
|
||||
|
||||
\constfunc{wxSize}{GetBestFittingSize}{\void}
|
||||
|
||||
Merges the window's best size into the min size and returns the result.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
|
||||
\helpref{wxWindow::SetBestFittingSize}{wxwindowsetbestfittingsize},\rtfsp
|
||||
\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints}
|
||||
|
||||
|
||||
\membersection{wxWindow::GetBestSize}\label{wxwindowgetbestsize}
|
||||
|
||||
\constfunc{wxSize}{GetBestSize}{\void}
|
||||
@ -2390,18 +2403,23 @@ applications on the system.
|
||||
\helpref{wxWindow::Refresh}{wxwindowrefresh},\rtfsp
|
||||
\helpref{wxEraseEvent}{wxeraseevent}
|
||||
|
||||
|
||||
\membersection{wxWindow::SetBestFittingSize}\label{wxwindowsetbestfittingsize}
|
||||
|
||||
\func{void}{SetBestFittingSize}{\param{const wxSize& }{size = wxDefaultSize}}
|
||||
|
||||
A {\it smart} SetSize that will fill in default size components with the
|
||||
window's {\it best} size values. Also set's the minsize for use with
|
||||
sizers.
|
||||
window's {\it best} size values. Also sets the window's minsize to
|
||||
the value passed in for use with sizers. This means that if a full or
|
||||
partial size is passed to this function then the sizers will use that
|
||||
size instead of the results of GetBestSize to determine the minimum
|
||||
needs of the window for layout.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxWindow::SetSize}{wxwindowsetsize}
|
||||
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize}
|
||||
\helpref{wxWindow::SetSize}{wxwindowsetsize},\rtfsp
|
||||
\helpref{wxWindow::GetBestSize}{wxwindowgetbestsize},\rtfsp
|
||||
\helpref{wxWindow::GetBestFittingSize}{wxwindowgetbestfittingsize},\rtfsp
|
||||
\helpref{wxWindow::SetSizeHints}{wxwindowsetsizehints}
|
||||
|
||||
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
|
||||
protected:
|
||||
// function called when any of the bitmaps changes
|
||||
virtual void OnSetBitmap() { }
|
||||
virtual void OnSetBitmap() { InvalidateBestSize(); }
|
||||
|
||||
// the bitmaps for various states
|
||||
wxBitmap m_bmpNormal,
|
||||
|
@ -63,6 +63,9 @@ public:
|
||||
// if the button was clicked)
|
||||
virtual void Command(wxCommandEvent &event);
|
||||
|
||||
virtual void SetLabel( const wxString &label );
|
||||
virtual bool SetFont(const wxFont& font);
|
||||
|
||||
protected:
|
||||
// creates the control (calls wxWindowBase::CreateBase inside) and adds it
|
||||
// to the list of parents children
|
||||
|
@ -230,9 +230,6 @@ 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;
|
||||
@ -297,17 +294,29 @@ public:
|
||||
}
|
||||
|
||||
// get the size best suited for the window (in fact, minimal
|
||||
// acceptable size using which it will still look "nice")
|
||||
wxSize GetBestSize() const { return DoGetBestSize(); }
|
||||
// acceptable size using which it will still look "nice" in
|
||||
// most situations)
|
||||
wxSize GetBestSize() const
|
||||
{
|
||||
if (m_bestSizeCache.IsFullySpecified())
|
||||
return m_bestSizeCache;
|
||||
return DoGetBestSize();
|
||||
}
|
||||
void GetBestSize(int *w, int *h) const
|
||||
{
|
||||
wxSize s = DoGetBestSize();
|
||||
wxSize s = GetBestSize();
|
||||
if ( w )
|
||||
*w = s.x;
|
||||
if ( h )
|
||||
*h = s.y;
|
||||
}
|
||||
|
||||
// reset the cached best size value so it will be recalculated the
|
||||
// next time it is needed.
|
||||
void InvalidateBestSize() { m_bestSizeCache = wxDefaultSize; }
|
||||
void CacheBestSize(const wxSize& size) const
|
||||
{ wxConstCast(this, wxWindowBase)->m_bestSizeCache = size; }
|
||||
|
||||
// There are times (and windows) where 'Best' size and 'Min' size
|
||||
// are vastly out of sync. This should be remedied somehow, but in
|
||||
// the meantime, this method will return the larger of BestSize
|
||||
@ -315,10 +324,19 @@ public:
|
||||
// MinSize hint.
|
||||
wxSize GetAdjustedBestSize() const
|
||||
{
|
||||
wxSize s( DoGetBestSize() );
|
||||
wxSize s( GetBestSize() );
|
||||
return wxSize( wxMax( s.x, GetMinWidth() ), wxMax( s.y, GetMinHeight() ) );
|
||||
}
|
||||
|
||||
// This function will merge the window's best size into the window's
|
||||
// minimum size, giving priority to the min size components, and
|
||||
// returns the results.
|
||||
wxSize GetBestFittingSize() const;
|
||||
|
||||
// A 'Smart' SetSize that will fill in default size values with 'best'
|
||||
// size. Sets the minsize to what was passed in.
|
||||
void SetBestFittingSize(const wxSize& size=wxDefaultSize);
|
||||
|
||||
// the generic centre function - centers the window on parent by`
|
||||
// default or on screen if it doesn't have parent or
|
||||
// wxCENTER_ON_SCREEN flag is given
|
||||
@ -1137,11 +1155,15 @@ protected:
|
||||
static int WidthDefault(int w) { return w == -1 ? 20 : w; }
|
||||
static int HeightDefault(int h) { return h == -1 ? 20 : h; }
|
||||
|
||||
|
||||
// Used to save the results of DoGetBestSize so it doesn't need to be
|
||||
// recalculated each time the value is needed.
|
||||
wxSize m_bestSizeCache;
|
||||
|
||||
// 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)
|
||||
//
|
||||
@ -1152,6 +1174,7 @@ protected:
|
||||
virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) {}
|
||||
|
||||
|
||||
|
||||
// more pure virtual functions
|
||||
// ---------------------------
|
||||
|
||||
|
@ -130,7 +130,9 @@ wxSize wxBookCtrl::DoGetBestSize() const
|
||||
|
||||
// convert display area to window area, adding the size neccessary for the
|
||||
// tabs
|
||||
return CalcSizeFromPage(bestSize);
|
||||
wxSize best = CalcSizeFromPage(bestSize);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -116,6 +116,19 @@ void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxControlBase::SetLabel( const wxString &label )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
wxWindow::SetLabel(label);
|
||||
}
|
||||
|
||||
bool wxControlBase::SetFont(const wxFont& font)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
return wxWindow::SetFont(font);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStaticBitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -129,12 +142,15 @@ wxStaticBitmapBase::~wxStaticBitmapBase()
|
||||
|
||||
wxSize wxStaticBitmapBase::DoGetBestSize() const
|
||||
{
|
||||
wxSize best;
|
||||
wxBitmap bmp = GetBitmap();
|
||||
if ( bmp.Ok() )
|
||||
return wxSize(bmp.GetWidth(), bmp.GetHeight());
|
||||
|
||||
best = wxSize(bmp.GetWidth(), bmp.GetHeight());
|
||||
else
|
||||
// this is completely arbitrary
|
||||
return wxSize(16, 16);
|
||||
best = wxSize(16, 16);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATBMP
|
||||
|
@ -192,18 +192,9 @@ wxSize wxSizerItem::CalcMin()
|
||||
if ( IsWindow() && !(m_flag & wxFIXED_MINSIZE) )
|
||||
{
|
||||
// Since the size of the window may change during runtime, we
|
||||
// should use the current minimal size. If there is a MinSize,
|
||||
// use it, otherwise use the BestSize.
|
||||
wxSize min = m_window->GetMinSize();
|
||||
if (min.x == -1 || min.y == -1)
|
||||
{
|
||||
wxSize best = m_window->GetBestSize();
|
||||
if (min.x == -1) min.x = best.x;
|
||||
if (min.y == -1) min.y = best.y;
|
||||
// should use the current minimal/best size.
|
||||
m_minSize = m_window->GetBestFittingSize();
|
||||
}
|
||||
m_minSize = min;
|
||||
}
|
||||
|
||||
ret = m_minSize;
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ wxToolBarToolBase *wxToolBarBase::DoAddTool(int id,
|
||||
wxCoord WXUNUSED(xPos),
|
||||
wxCoord WXUNUSED(yPos))
|
||||
{
|
||||
InvalidateBestSize();
|
||||
return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled,
|
||||
kind, shortHelp, longHelp, clientData);
|
||||
}
|
||||
|
@ -125,6 +125,9 @@ wxWindowBase::wxWindowBase()
|
||||
m_minHeight =
|
||||
m_maxHeight = wxDefaultSize.y;
|
||||
|
||||
// invalidiated cache value
|
||||
m_bestSizeCache = wxDefaultSize;
|
||||
|
||||
// window are created enabled and visible by default
|
||||
m_isShown =
|
||||
m_isEnabled = true;
|
||||
@ -482,7 +485,7 @@ void wxWindowBase::Fit()
|
||||
{
|
||||
if ( GetChildren().GetCount() > 0 )
|
||||
{
|
||||
SetClientSize(DoGetBestSize());
|
||||
SetClientSize(GetBestSize());
|
||||
}
|
||||
//else: do nothing if we have no children
|
||||
}
|
||||
@ -620,32 +623,36 @@ wxSize wxWindowBase::DoGetBestSize() const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxSize wxWindowBase::GetBestFittingSize() const
|
||||
{
|
||||
// merge the best size with the min size, giving priority to the min size
|
||||
wxSize min = GetMinSize();
|
||||
if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
|
||||
{
|
||||
wxSize best = GetBestSize();
|
||||
if (min.x == wxDefaultCoord) min.x = best.x;
|
||||
if (min.y == wxDefaultCoord) min.y = best.y;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
|
||||
void wxWindowBase::SetBestFittingSize(const wxSize& size)
|
||||
{
|
||||
// If the given size is incomplete then merge with the best size.
|
||||
wxSize sizeBest;
|
||||
if ( size.x == wxDefaultSize.x || size.y == wxDefaultSize.y )
|
||||
{
|
||||
sizeBest = DoGetBestSize();
|
||||
if ( size.x != wxDefaultSize.x )
|
||||
sizeBest.x = size.x;
|
||||
if ( size.y != wxDefaultSize.y )
|
||||
sizeBest.y = size.y;
|
||||
}
|
||||
else // have complete explicit size
|
||||
{
|
||||
sizeBest = size;
|
||||
}
|
||||
// Set the min size to the size passed in. This will usually either be
|
||||
// wxDefaultSize or the size passed to this window's ctor/Create function.
|
||||
SetMinSize(size);
|
||||
|
||||
// Change the size if needed
|
||||
if (GetSize() != sizeBest)
|
||||
SetSize(sizeBest);
|
||||
// Merge the size with the best size if needed
|
||||
wxSize best = GetBestFittingSize();
|
||||
|
||||
// don't shrink the control below its best size
|
||||
m_minWidth = sizeBest.x;
|
||||
m_minHeight = sizeBest.y;
|
||||
// If the current size doesn't match then change it
|
||||
if (GetSize() != best)
|
||||
SetSize(best);
|
||||
}
|
||||
|
||||
|
||||
// by default the origin is not shifted
|
||||
wxPoint wxWindowBase::GetClientAreaOrigin() const
|
||||
{
|
||||
|
@ -205,6 +205,8 @@ void wxBitmapButton::OnSetBitmap()
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
wxBitmap the_one;
|
||||
if (!m_isEnabled)
|
||||
the_one = m_bmpDisabled;
|
||||
@ -258,6 +260,7 @@ wxSize wxBitmapButton::DoGetBestSize() const
|
||||
best.x = m_bmpNormal.GetWidth()+border;
|
||||
best.y = m_bmpNormal.GetHeight()+border;
|
||||
}
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
|
@ -232,6 +232,7 @@ wxSize wxButton::DoGetBestSize() const
|
||||
if (ret.x < 80) ret.x = 80;
|
||||
}
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -564,6 +564,7 @@ wxSize wxChoice::DoGetBestSize() const
|
||||
if (ret.y <= 18)
|
||||
ret.y = 8 + GetCharHeight();
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,8 @@ wxSize wxComboBox::DoGetBestSize() const
|
||||
// empty combobox should have some reasonable default size too
|
||||
if ( ret.x < 100 )
|
||||
ret.x = 100;
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ void wxControl::SetLabel( const wxString &label )
|
||||
}
|
||||
m_label << *pc;
|
||||
}
|
||||
InvalidateBestSize();
|
||||
}
|
||||
|
||||
wxString wxControl::GetLabel() const
|
||||
@ -85,7 +86,9 @@ wxSize wxControl::DoGetBestSize() const
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
|
||||
(m_widget, &req );
|
||||
|
||||
return wxSize(req.width, req.height);
|
||||
wxSize best(req.width, req.height);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,10 +72,13 @@ void wxGauge::DoSetGauge()
|
||||
|
||||
wxSize wxGauge::DoGetBestSize() const
|
||||
{
|
||||
wxSize best;
|
||||
if (HasFlag(wxGA_VERTICAL))
|
||||
return wxSize(28, 100);
|
||||
best = wxSize(28, 100);
|
||||
else
|
||||
return wxSize(100, 28);
|
||||
best = wxSize(100, 28);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
void wxGauge::SetRange( int range )
|
||||
|
@ -439,6 +439,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
wxASSERT_MSG( m_clientList.GetCount() == (size_t)GetCount(),
|
||||
wxT("bug in client data management") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
GList *children = m_list->children;
|
||||
int length = g_list_length(children);
|
||||
|
||||
@ -495,6 +497,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
|
||||
int wxListBox::DoAppend( const wxString& item )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
|
||||
if (m_strings)
|
||||
{
|
||||
// need to determine the index
|
||||
@ -1076,7 +1080,9 @@ wxSize wxListBox::DoGetBestSize() const
|
||||
// make it too small neither
|
||||
lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
|
||||
|
||||
return wxSize(lbWidth, lbHeight);
|
||||
wxSize best(lbWidth, lbHeight);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y)
|
||||
|
@ -286,6 +286,7 @@ wxSize wxRadioBox::DoGetBestSize() const
|
||||
if (req.width > size.x)
|
||||
size.x = req.width;
|
||||
|
||||
CacheBestSize(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,9 @@ bool wxSpinButton::IsOwnGtkWindow( GdkWindow *window )
|
||||
|
||||
wxSize wxSpinButton::DoGetBestSize() const
|
||||
{
|
||||
return wxSize(15, 26); // FIXME
|
||||
wxSize best(15, 26); // FIXME
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -301,7 +301,9 @@ bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window )
|
||||
wxSize wxSpinCtrl::DoGetBestSize() const
|
||||
{
|
||||
wxSize ret( wxControl::DoGetBestSize() );
|
||||
return wxSize(95, ret.y);
|
||||
wxSize best(95, ret.y);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -113,7 +113,8 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
|
||||
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
|
||||
}
|
||||
|
||||
SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
|
||||
InvalidateBestSize();
|
||||
SetSize(GetBestSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ void wxStaticText::SetLabel( const wxString &label )
|
||||
// adjust the label size to the new label unless disabled
|
||||
if (!HasFlag(wxST_NO_AUTORESIZE))
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +162,8 @@ bool wxStaticText::SetFont( const wxFont &font )
|
||||
// adjust the label size to the new label unless disabled
|
||||
if (!HasFlag(wxST_NO_AUTORESIZE))
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -183,7 +183,9 @@ wxSize wxStaticText::DoGetBestSize() const
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
|
||||
(m_widget, &req );
|
||||
|
||||
return wxSize(req.width, req.height);
|
||||
wxSize best(req.width, req.height);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
bool wxStaticText::SetForegroundColour(const wxColour& colour)
|
||||
|
@ -501,6 +501,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||
(m_widget, &req );
|
||||
m_width = req.width + m_xMargin;
|
||||
m_height = req.height + 2*m_yMargin;
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -522,6 +523,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
//case wxTOOL_STYLE_SEPARATOR: -- nothing to do
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1633,7 +1633,9 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
{
|
||||
// FIXME should be different for multi-line controls...
|
||||
wxSize ret( wxControl::DoGetBestSize() );
|
||||
return wxSize(80, ret.y);
|
||||
wxSize best(80, ret.y);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -123,6 +123,7 @@ void wxToggleBitmapButton::SetLabel(const wxBitmap& label)
|
||||
wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
|
||||
|
||||
m_bitmap = label;
|
||||
InvalidateBestSize();
|
||||
|
||||
OnSetBitmap();
|
||||
}
|
||||
@ -192,7 +193,7 @@ void wxToggleBitmapButton::OnInternalIdle()
|
||||
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
|
||||
}
|
||||
|
||||
// wxSize DoGetBestSize() const
|
||||
|
||||
// Get the "best" size for this control.
|
||||
wxSize wxToggleBitmapButton::DoGetBestSize() const
|
||||
{
|
||||
@ -204,6 +205,7 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const
|
||||
best.x = m_bitmap.GetWidth()+border;
|
||||
best.y = m_bitmap.GetHeight()+border;
|
||||
}
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
@ -332,7 +334,7 @@ void wxToggleButton::OnInternalIdle()
|
||||
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
|
||||
}
|
||||
|
||||
// wxSize DoGetBestSize() const
|
||||
|
||||
// Get the "best" size for this control.
|
||||
wxSize wxToggleButton::DoGetBestSize() const
|
||||
{
|
||||
@ -343,7 +345,7 @@ wxSize wxToggleButton::DoGetBestSize() const
|
||||
if (ret.x < 80) ret.x = 80;
|
||||
}
|
||||
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,8 @@ void wxBitmapButton::OnSetBitmap()
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
wxBitmap the_one;
|
||||
if (!m_isEnabled)
|
||||
the_one = m_bmpDisabled;
|
||||
@ -258,6 +260,7 @@ wxSize wxBitmapButton::DoGetBestSize() const
|
||||
best.x = m_bmpNormal.GetWidth()+border;
|
||||
best.y = m_bmpNormal.GetHeight()+border;
|
||||
}
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
|
@ -232,6 +232,7 @@ wxSize wxButton::DoGetBestSize() const
|
||||
if (ret.x < 80) ret.x = 80;
|
||||
}
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -564,6 +564,7 @@ wxSize wxChoice::DoGetBestSize() const
|
||||
if (ret.y <= 18)
|
||||
ret.y = 8 + GetCharHeight();
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,8 @@ wxSize wxComboBox::DoGetBestSize() const
|
||||
// empty combobox should have some reasonable default size too
|
||||
if ( ret.x < 100 )
|
||||
ret.x = 100;
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ void wxControl::SetLabel( const wxString &label )
|
||||
}
|
||||
m_label << *pc;
|
||||
}
|
||||
InvalidateBestSize();
|
||||
}
|
||||
|
||||
wxString wxControl::GetLabel() const
|
||||
@ -85,7 +86,9 @@ wxSize wxControl::DoGetBestSize() const
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
|
||||
(m_widget, &req );
|
||||
|
||||
return wxSize(req.width, req.height);
|
||||
wxSize best(req.width, req.height);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,10 +72,13 @@ void wxGauge::DoSetGauge()
|
||||
|
||||
wxSize wxGauge::DoGetBestSize() const
|
||||
{
|
||||
wxSize best;
|
||||
if (HasFlag(wxGA_VERTICAL))
|
||||
return wxSize(28, 100);
|
||||
best = wxSize(28, 100);
|
||||
else
|
||||
return wxSize(100, 28);
|
||||
best = wxSize(100, 28);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
void wxGauge::SetRange( int range )
|
||||
|
@ -439,6 +439,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
wxASSERT_MSG( m_clientList.GetCount() == (size_t)GetCount(),
|
||||
wxT("bug in client data management") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
GList *children = m_list->children;
|
||||
int length = g_list_length(children);
|
||||
|
||||
@ -495,6 +497,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
|
||||
int wxListBox::DoAppend( const wxString& item )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
|
||||
if (m_strings)
|
||||
{
|
||||
// need to determine the index
|
||||
@ -1076,7 +1080,9 @@ wxSize wxListBox::DoGetBestSize() const
|
||||
// make it too small neither
|
||||
lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
|
||||
|
||||
return wxSize(lbWidth, lbHeight);
|
||||
wxSize best(lbWidth, lbHeight);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y)
|
||||
|
@ -286,6 +286,7 @@ wxSize wxRadioBox::DoGetBestSize() const
|
||||
if (req.width > size.x)
|
||||
size.x = req.width;
|
||||
|
||||
CacheBestSize(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,9 @@ bool wxSpinButton::IsOwnGtkWindow( GdkWindow *window )
|
||||
|
||||
wxSize wxSpinButton::DoGetBestSize() const
|
||||
{
|
||||
return wxSize(15, 26); // FIXME
|
||||
wxSize best(15, 26); // FIXME
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -301,7 +301,9 @@ bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window )
|
||||
wxSize wxSpinCtrl::DoGetBestSize() const
|
||||
{
|
||||
wxSize ret( wxControl::DoGetBestSize() );
|
||||
return wxSize(95, ret.y);
|
||||
wxSize best(95, ret.y);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -113,7 +113,8 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
|
||||
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
|
||||
}
|
||||
|
||||
SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
|
||||
InvalidateBestSize();
|
||||
SetSize(GetBestSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ void wxStaticText::SetLabel( const wxString &label )
|
||||
// adjust the label size to the new label unless disabled
|
||||
if (!HasFlag(wxST_NO_AUTORESIZE))
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +162,8 @@ bool wxStaticText::SetFont( const wxFont &font )
|
||||
// adjust the label size to the new label unless disabled
|
||||
if (!HasFlag(wxST_NO_AUTORESIZE))
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -183,7 +183,9 @@ wxSize wxStaticText::DoGetBestSize() const
|
||||
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
|
||||
(m_widget, &req );
|
||||
|
||||
return wxSize(req.width, req.height);
|
||||
wxSize best(req.width, req.height);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
bool wxStaticText::SetForegroundColour(const wxColour& colour)
|
||||
|
@ -501,6 +501,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||
(m_widget, &req );
|
||||
m_width = req.width + m_xMargin;
|
||||
m_height = req.height + 2*m_yMargin;
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -522,6 +523,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
||||
//case wxTOOL_STYLE_SEPARATOR: -- nothing to do
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1633,7 +1633,9 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
{
|
||||
// FIXME should be different for multi-line controls...
|
||||
wxSize ret( wxControl::DoGetBestSize() );
|
||||
return wxSize(80, ret.y);
|
||||
wxSize best(80, ret.y);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -123,6 +123,7 @@ void wxToggleBitmapButton::SetLabel(const wxBitmap& label)
|
||||
wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
|
||||
|
||||
m_bitmap = label;
|
||||
InvalidateBestSize();
|
||||
|
||||
OnSetBitmap();
|
||||
}
|
||||
@ -192,7 +193,7 @@ void wxToggleBitmapButton::OnInternalIdle()
|
||||
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
|
||||
}
|
||||
|
||||
// wxSize DoGetBestSize() const
|
||||
|
||||
// Get the "best" size for this control.
|
||||
wxSize wxToggleBitmapButton::DoGetBestSize() const
|
||||
{
|
||||
@ -204,6 +205,7 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const
|
||||
best.x = m_bitmap.GetWidth()+border;
|
||||
best.y = m_bitmap.GetHeight()+border;
|
||||
}
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
@ -332,7 +334,7 @@ void wxToggleButton::OnInternalIdle()
|
||||
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
|
||||
}
|
||||
|
||||
// wxSize DoGetBestSize() const
|
||||
|
||||
// Get the "best" size for this control.
|
||||
wxSize wxToggleButton::DoGetBestSize() const
|
||||
{
|
||||
@ -343,7 +345,7 @@ wxSize wxToggleButton::DoGetBestSize() const
|
||||
if (ret.x < 80) ret.x = 80;
|
||||
}
|
||||
|
||||
|
||||
CacheBestSize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
|
||||
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
|
||||
{
|
||||
m_bmpNormal = bitmap;
|
||||
InvalidateBestSize();
|
||||
|
||||
ControlButtonContentInfo info ;
|
||||
wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
|
||||
|
@ -324,6 +324,8 @@ void wxListBox::Delete(int N)
|
||||
|
||||
int wxListBox::DoAppend(const wxString& item)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
|
||||
int index = m_noItems ;
|
||||
m_stringArray.Add( item ) ;
|
||||
m_dataArray.Add( NULL );
|
||||
@ -511,6 +513,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
wxCHECK_RET( pos >= 0 && pos <= m_noItems,
|
||||
wxT("invalid index in wxListBox::InsertItems") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
int nItems = items.GetCount();
|
||||
|
||||
for ( int i = 0 ; i < nItems ; i++ )
|
||||
|
@ -59,6 +59,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
|
||||
void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
|
||||
{
|
||||
m_bitmap = bitmap;
|
||||
InvalidateBestSize();
|
||||
SetSize(GetBestSize());
|
||||
Refresh() ;
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ void wxStaticText::SetLabel(const wxString& st )
|
||||
|
||||
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() ) ;
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
|
||||
Update() ;
|
||||
@ -109,8 +109,8 @@ bool wxStaticText::SetFont(const wxFont& font)
|
||||
{
|
||||
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -377,6 +377,7 @@ bool wxToolBar::Realize()
|
||||
}
|
||||
|
||||
SetSize( maxWidth, maxHeight );
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -473,6 +474,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
|
||||
{
|
||||
// nothing special to do here - we relayout in Realize() later
|
||||
tool->Attach(this);
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -519,6 +521,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
|
||||
tool2->SetPosition( pt ) ;
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
|
||||
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
|
||||
{
|
||||
m_bmpNormal = bitmap;
|
||||
InvalidateBestSize();
|
||||
|
||||
ControlButtonContentInfo info ;
|
||||
wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
|
||||
|
@ -401,6 +401,8 @@ void wxListBox::Delete(int N)
|
||||
|
||||
int wxListBox::DoAppend(const wxString& item)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
|
||||
int index = m_noItems ;
|
||||
m_stringArray.Add( item ) ;
|
||||
m_dataArray.Add( NULL );
|
||||
@ -595,6 +597,8 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
wxCHECK_RET( pos >= 0 && pos <= m_noItems,
|
||||
wxT("invalid index in wxListBox::InsertItems") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
int nItems = items.GetCount();
|
||||
|
||||
for ( int i = 0 ; i < nItems ; i++ )
|
||||
|
@ -67,6 +67,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
|
||||
void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
|
||||
{
|
||||
m_bitmap = bitmap;
|
||||
InvalidateBestSize();
|
||||
SetSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
|
||||
Refresh() ;
|
||||
}
|
||||
|
@ -236,6 +236,7 @@ void wxStaticText::SetLabel(const wxString& st )
|
||||
{
|
||||
// temporary fix until layout measurement and drawing are in synch again
|
||||
Refresh() ;
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() ) ;
|
||||
}
|
||||
Refresh() ;
|
||||
@ -254,6 +255,7 @@ bool wxStaticText::SetFont(const wxFont& font)
|
||||
{
|
||||
// temporary fix until layout measurement and drawing are in synch again
|
||||
Refresh() ;
|
||||
InvalidateBestSize();
|
||||
SetSize( GetBestSize() );
|
||||
}
|
||||
}
|
||||
|
@ -377,6 +377,7 @@ bool wxToolBar::Realize()
|
||||
}
|
||||
|
||||
SetSize(maxWidth, maxHeight);
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -494,6 +495,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
|
||||
{
|
||||
// nothing special to do here - we relayout in Realize() later
|
||||
tool->Attach(this);
|
||||
InvalidateBestSize();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -540,6 +542,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
|
||||
tool2->SetPosition( pt ) ;
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
|
@ -126,25 +126,11 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
|
||||
m_marginY = wxDEFAULT_BUTTON_MARGIN;
|
||||
}
|
||||
|
||||
int x = pos.x;
|
||||
int y = pos.y;
|
||||
int width = size.x;
|
||||
int height = size.y;
|
||||
|
||||
if (id == -1)
|
||||
m_windowId = NewControlId();
|
||||
else
|
||||
m_windowId = id;
|
||||
|
||||
if ( bitmap.Ok() )
|
||||
{
|
||||
wxSize newSize = DoGetBestSize();
|
||||
if ( width == -1 )
|
||||
width = newSize.x;
|
||||
if ( height == -1 )
|
||||
height = newSize.y;
|
||||
}
|
||||
|
||||
long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ;
|
||||
|
||||
if ( m_windowStyle & wxCLIP_SIBLINGS )
|
||||
@ -176,9 +162,8 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
|
||||
// Subclass again for purposes of dialog editing mode
|
||||
SubclassWin(m_hWnd);
|
||||
|
||||
SetFont(parent->GetFont());
|
||||
|
||||
SetSize(x, y, width, height);
|
||||
SetPosition(pos);
|
||||
SetBestSize(size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -287,6 +287,8 @@ void wxListBox::Delete(int N)
|
||||
|
||||
int wxListBox::DoAppend(const wxString& item)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
|
||||
int index = ListBox_AddString(GetHwnd(), item);
|
||||
m_noItems++;
|
||||
|
||||
@ -522,6 +524,8 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
wxCHECK_RET( pos >= 0 && pos <= m_noItems,
|
||||
wxT("invalid index in wxListBox::InsertItems") );
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
int nItems = items.GetCount();
|
||||
for ( int i = 0; i < nItems; i++ )
|
||||
{
|
||||
|
@ -217,6 +217,7 @@ void wxStaticBitmap::SetImage( const wxGDIImage* image )
|
||||
{
|
||||
wxGDIImage* convertedImage = ConvertImage( *image );
|
||||
SetImageNoCopy( convertedImage );
|
||||
InvalidateBestSize();
|
||||
}
|
||||
|
||||
void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
|
||||
|
@ -215,8 +215,8 @@ void wxStaticText::SetLabel(const wxString& label)
|
||||
// disabled
|
||||
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,8 +229,8 @@ bool wxStaticText::SetFont(const wxFont& font)
|
||||
// disabled
|
||||
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
|
||||
SetSizeHints(GetSize());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -388,6 +388,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
|
||||
// Realize() later
|
||||
tool->Attach(this);
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -465,6 +466,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
|
||||
}
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -922,6 +924,7 @@ bool wxToolBar::Realize()
|
||||
}
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -509,6 +509,21 @@ after calling Fit.", "");
|
||||
GetBestSizeTuple);
|
||||
|
||||
|
||||
DocDeclStr(
|
||||
void , InvalidateBestSize(),
|
||||
"Reset the cached best size value so it will be recalculated the next
|
||||
time it is needed.", "");
|
||||
|
||||
|
||||
|
||||
DocDeclStr(
|
||||
wxSize , GetBestFittingSize() const,
|
||||
"This function will merge the window's best size into the window's
|
||||
minimum size, giving priority to the min size components, and returns
|
||||
the results.
|
||||
", "");
|
||||
|
||||
|
||||
DocDeclStr(
|
||||
wxSize , GetAdjustedBestSize() const,
|
||||
"This method is similar to GetBestSize, except in one
|
||||
@ -1325,7 +1340,7 @@ The cursor may be wx.NullCursor in which case the window cursor will
|
||||
be reset back to default.", "");
|
||||
|
||||
DocDeclStr(
|
||||
wxCursor& , GetCursor(),
|
||||
wxCursor , GetCursor(),
|
||||
"Return the cursor associated with this window.", "");
|
||||
|
||||
|
||||
@ -1341,7 +1356,7 @@ be reset back to default.", "");
|
||||
|
||||
|
||||
DocDeclStr(
|
||||
wxFont& , GetFont(),
|
||||
wxFont , GetFont(),
|
||||
"Returns the default font used for this window.", "");
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user