// the default initialization
wxWindowBase::wxWindowBase()
+: m_bestSize(wxDefaultSize)
{
// no window yet, no parent nor children
m_parent = (wxWindow *)NULL;
m_maxWidth =
m_maxHeight = -1;
- // window is created enabled but it's not visible yet
- m_isShown = false;
+ // window are created enabled and visible by default
+ m_isShown =
m_isEnabled = true;
// the default event handler is just this window
m_windowValidator = (wxValidator *) NULL;
#endif // wxUSE_VALIDATORS
- // use the system default colours
- m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
- m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
-
- // don't set the font here for wxMSW as we don't call WM_SETFONT here and
- // so the font is *not* really set - but calls to SetFont() later won't do
- // anything because m_font appears to be already set!
-#ifndef __WXMSW__
- m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
-#endif // __WXMSW__
-
- // the colours/fonts are default for now
+ // the colours/fonts are default for now, so leave m_font,
+ // m_backgroundColour and m_foregroundColour uninitialized and set those
m_hasBgCol =
m_hasFgCol =
m_hasFont = false;
- m_isBeingDeleted = false;
-
// no style bits
m_exStyle =
m_windowStyle = 0;
m_maxVirtualWidth =
m_maxVirtualHeight = -1;
+ m_windowVariant = wxWINDOW_VARIANT_NORMAL;
+
// Whether we're using the current theme for this window (wxGTK only for now)
m_themeEnabled = false;
+
+ // VZ: this one shouldn't exist...
+ m_isBeingDeleted = false;
}
// common part of window creation process
}
else
{
- // for a generic window there is no natural best size - just use the
- // current one
- return GetSize();
+ // Windows which don't implement DoGetBestSize and aren't parents.
+ // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
+
+ // If you get the following message you should do one of two things
+ // 1. Do what it says (best)
+ // 2. m_bestSize = GetSize() at end of Create() (hack)
+ if(m_bestSize == wxDefaultSize)
+ {
+ wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
+ wxConstCast(this,wxWindowBase)->m_bestSize = GetSize();
+ }
+ return m_bestSize;
}
}
m_maxHeight = maxH;
}
+void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
+{
+ if ( m_windowVariant != variant )
+ {
+ m_windowVariant = variant;
+
+ DoSetWindowVariant(variant);
+ }
+}
+
+void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
+{
+ // adjust the font height to correspond to our new variant (notice that
+ // we're only called if something really changed)
+ wxFont font = GetFont();
+ int size = font.GetPointSize();
+ switch ( variant )
+ {
+ case wxWINDOW_VARIANT_NORMAL:
+ break;
+
+ case wxWINDOW_VARIANT_SMALL:
+ size *= 3;
+ size /= 4;
+ break;
+
+ case wxWINDOW_VARIANT_MINI:
+ size *= 2;
+ size /= 3;
+ break;
+
+ case wxWINDOW_VARIANT_LARGE:
+ size *= 5;
+ size /= 4;
+ break;
+
+ default:
+ wxFAIL_MSG(_T("unexpected window variant"));
+ break;
+ }
+
+ font.SetPointSize(size);
+ SetFont(font);
+}
+
void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
int maxW, int maxH )
{
}
// ----------------------------------------------------------------------------
-// cursors, fonts &c
+// colours, fonts &c
// ----------------------------------------------------------------------------
+/* static */ wxVisualAttributes
+wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
+{
+ // it is important to return valid values for all attributes from here,
+ // GetXXX() below rely on this
+ wxVisualAttributes attrs;
+ attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+ attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
+ attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
+
+ return attrs;
+}
+
+wxColour wxWindowBase::GetBackgroundColour() const
+{
+ if ( !m_backgroundColour.Ok() )
+ {
+ wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
+
+ // get our default background colour
+ wxColour colBg = GetDefaultAttributes().colBg;
+
+ // we must return some valid colour to avoid redoing this every time
+ // and also to avoid surprizing the applications written for older
+ // wxWindows versions where GetBackgroundColour() always returned
+ // something -- so give them something even if it doesn't make sense
+ // for this window (e.g. it has a themed background)
+ if ( !colBg.Ok() )
+ colBg = GetClassDefaultAttributes().colBg;
+
+ // cache it for the next call
+ wxConstCast(this, wxWindowBase)->m_backgroundColour = colBg;
+ }
+
+ return m_backgroundColour;
+}
+
+wxColour wxWindowBase::GetForegroundColour() const
+{
+ // logic is the same as above
+ if ( !m_hasFgCol && !m_foregroundColour.Ok() )
+ {
+ wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") );
+
+ wxColour colFg = GetDefaultAttributes().colFg;
+
+ if ( !colFg.Ok() )
+ colFg = GetClassDefaultAttributes().colFg;
+
+ wxConstCast(this, wxWindowBase)->m_foregroundColour = colFg;
+ }
+
+ return m_foregroundColour;
+}
+
bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
{
if ( !colour.Ok() || (colour == m_backgroundColour) )
return true;
}
+wxFont& wxWindowBase::DoGetFont() const
+{
+ // logic is the same as in GetBackgroundColour()
+ if ( !m_font.Ok() )
+ {
+ wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
+
+ wxFont font = GetDefaultAttributes().font;
+ if ( !font.Ok() )
+ font = GetClassDefaultAttributes().font;
+
+ wxConstCast(this, wxWindowBase)->m_font = font;
+ }
+
+ // cast is here for non-const GetFont() convenience
+ return wxConstCast(this, wxWindowBase)->m_font;
+}
+
bool wxWindowBase::SetFont(const wxFont& font)
{
- // don't try to set invalid font, always fall back to the default
- const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
+ if ( !font.Ok() )
+ return false;
- if ( fontOk == m_font )
+ if ( font == m_font )
{
// no change
return false;
}
- m_font = fontOk;
+ m_font = font;
m_hasFont = true;
m_windowValidator = (wxValidator *)validator.Clone();
if ( m_windowValidator )
- m_windowValidator->SetWindow(this) ;
+ m_windowValidator->SetWindow(this);
}
#endif // wxUSE_VALIDATORS
void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
{
+ if ( sizer == m_windowSizer)
+ return;
+
if ( deleteOld )
delete m_windowSizer;
int charHeight = GetCharHeight();
wxPoint pt2(-1, -1);
if (pt.x != -1)
- pt2.x = (int) ((pt.x * 4) / charWidth) ;
+ pt2.x = (int) ((pt.x * 4) / charWidth);
if (pt.y != -1)
- pt2.y = (int) ((pt.y * 8) / charHeight) ;
+ pt2.y = (int) ((pt.y * 8) / charHeight);
return pt2;
}
int charHeight = GetCharHeight();
wxPoint pt2(-1, -1);
if (pt.x != -1)
- pt2.x = (int) ((pt.x * charWidth) / 4) ;
+ pt2.x = (int) ((pt.x * charWidth) / 4);
if (pt.y != -1)
- pt2.y = (int) ((pt.y * charHeight) / 8) ;
+ pt2.y = (int) ((pt.y * charHeight) / 8);
return pt2;
}