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;
m_hasBgCol =
m_hasFgCol =
m_hasFont = false;
+ m_inheritBgCol =
+ m_inheritFgCol =
+ m_inheritFont = false;
// no style bits
m_exStyle =
{
if ( GetChildren().GetCount() > 0 )
{
- SetClientSize(DoGetBestSize());
+ SetClientSize(GetBestSize());
}
//else: do nothing if we have no children
}
}
}
-void wxWindowBase::SetBestSize(const wxSize& size)
+
+wxSize wxWindowBase::GetBestFittingSize() const
{
- // 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
+ // merge the best size with the min size, giving priority to the min size
+ wxSize min = GetMinSize();
+ if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
{
- sizeBest = size;
+ wxSize best = GetBestSize();
+ if (min.x == wxDefaultCoord) min.x = best.x;
+ if (min.y == wxDefaultCoord) min.y = best.y;
}
+ return min;
+}
+
- // Change the size if needed
- if (GetSize() != sizeBest)
- SetSize(sizeBest);
+void wxWindowBase::SetBestFittingSize(const wxSize& 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);
- // don't shrink the control below its best size
- m_minWidth = sizeBest.x;
- m_minHeight = sizeBest.y;
+ // Merge the size with the best size if needed
+ wxSize best = GetBestFittingSize();
+
+ // 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
{
// which ensures that this only happens if the user really wants it and
// not by default which wouldn't make any sense in modern GUIs where the
// controls don't all use the same fonts (nor colours)
- if ( parent->m_hasFont && !m_hasFont )
+ if ( parent->m_inheritFont && !m_hasFont )
SetFont(parent->GetFont());
// in addition, there is a possibility to explicitly forbid inheriting
// colours at each class level by overriding ShouldInheritColours()
if ( ShouldInheritColours() )
{
- if ( parent->m_hasFgCol && !m_hasFgCol )
+ if ( parent->m_inheritFgCol && !m_hasFgCol )
SetForegroundColour(parent->GetForegroundColour());
- if ( parent->m_hasBgCol && !m_hasBgCol )
+ if ( parent->m_inheritBgCol && !m_hasBgCol )
SetBackgroundColour(parent->GetBackgroundColour());
}
}
if ( !colBg.Ok() )
colBg = GetClassDefaultAttributes().colBg;
- // cache it for the next call
- wxConstCast(this, wxWindowBase)->m_backgroundColour = colBg;
+ return colBg;
}
-
- return m_backgroundColour;
+ else
+ return m_backgroundColour;
}
wxColour wxWindowBase::GetForegroundColour() const
if ( !colFg.Ok() )
colFg = GetClassDefaultAttributes().colFg;
- wxConstCast(this, wxWindowBase)->m_foregroundColour = colFg;
+ return colFg;
}
-
- return m_foregroundColour;
+ else
+ return m_foregroundColour;
}
bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
return false;
m_hasBgCol = colour.Ok();
+ m_inheritBgCol = m_hasBgCol;
m_backgroundColour = colour;
SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
return true;
return false;
m_hasFgCol = colour.Ok();
+ m_inheritFgCol = m_hasFgCol;
m_foregroundColour = colour;
SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
return true;
return true;
}
-wxFont& wxWindowBase::DoGetFont() const
+wxFont wxWindowBase::GetFont() const
{
// logic is the same as in GetBackgroundColour()
if ( !m_font.Ok() )
if ( !font.Ok() )
font = GetClassDefaultAttributes().font;
- wxConstCast(this, wxWindowBase)->m_font = font;
+ return font;
}
-
- // cast is here for non-const GetFont() convenience
- return wxConstCast(this, wxWindowBase)->m_font;
+ else
+ return m_font;
}
bool wxWindowBase::SetFont(const wxFont& font)
{
- if ( !font.Ok() )
- return false;
-
if ( font == m_font )
{
// no change
}
m_font = font;
-
- m_hasFont = true;
+ m_hasFont = font.Ok();
+ m_inheritFont = m_hasFont;
return true;
}
node = node->GetNext();
}
+
+ Refresh();
}
// the default action is to populate dialog with data when it's created,
}
// ----------------------------------------------------------------------------
-// navigation
+// keyboard navigation
// ----------------------------------------------------------------------------
// Navigates in the specified direction.
return false;
}
+void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
+{
+ // check that we're not a top level window
+ wxCHECK_RET( GetParent(),
+ _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
+
+ // find the target window in the siblings list
+ wxWindowList& siblings = GetParent()->GetChildren();
+ wxWindowList::compatibility_iterator i = siblings.Find(win);
+ wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
+
+ // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
+ // can't just move the node around
+ wxWindow *self = (wxWindow *)this;
+ siblings.DeleteObject(self);
+ if ( move == MoveAfter )
+ {
+ i = i->GetNext();
+ }
+
+ if ( i )
+ {
+ siblings.Insert(i, self);
+ }
+ else // MoveAfter and win was the last sibling
+ {
+ siblings.Append(self);
+ }
+}
+
// ----------------------------------------------------------------------------
// global functions
// ----------------------------------------------------------------------------