X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc0bffacebe299b312ce7fdf49a8825f466cf73f..f29fe16932ede752589ef9ed34a757342387932f:/include/wx/window.h?ds=sidebyside diff --git a/include/wx/window.h b/include/wx/window.h index 0f1d01072d..bdf6b7cab6 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -73,6 +73,35 @@ class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxAccessible; #endif +// ---------------------------------------------------------------------------- +// helper stuff used by wxWindow +// ---------------------------------------------------------------------------- + +// struct containing all the visual attributes of a control +struct WXDLLEXPORT wxVisualAttributes +{ + // the font used for control label/text inside it + wxFont font; + + // the foreground colour + wxColour colFg; + + // the background colour, may be wxNullColour if the controls background + // colour is not solid + wxColour colBg; +}; + +// different window variants, on platforms like eg mac uses different +// rendering sizes +enum wxWindowVariant +{ + wxWINDOW_VARIANT_NORMAL, // Normal size + wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal) + wxWINDOW_VARIANT_MINI, // Mini size (about 33 % smaller than normal) + wxWINDOW_VARIANT_LARGE, // Large size (about 25 % larger than normal) + wxWINDOW_VARIANT_MAX +}; + // ---------------------------------------------------------------------------- // (pseudo)template list classes // ---------------------------------------------------------------------------- @@ -158,6 +187,11 @@ public: virtual void SetName( const wxString &name ) { m_windowName = name; } virtual wxString GetName() const { return m_windowName; } + // sets the window variant, calls internally DoSetVariant if variant has changed + void SetWindowVariant( wxWindowVariant variant ) ; + wxWindowVariant GetWindowVariant() const { return m_windowVariant ; } + + // window id uniquely identifies the window among its siblings unless // it is -1 which means "don't care" void SetId( wxWindowID winid ) { m_windowId = winid; } @@ -306,9 +340,22 @@ public: virtual void SetSizeHints( int minW, int minH, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1 ); + void SetSizeHints( const wxSize& minSize, + const wxSize& maxSize=wxDefaultSize, + const wxSize& incSize=wxDefaultSize) + { + SetSizeHints(minSize.x, minSize.y, + maxSize.x, maxSize.y, + incSize.x, incSize.y); + } virtual void SetVirtualSizeHints( int minW, int minH, int maxW = -1, int maxH = -1 ); + void SetVirtualSizeHints( const wxSize& minSize, + const wxSize& maxSize=wxDefaultSize) + { + SetVirtualSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y); + } virtual int GetMinWidth() const { return m_minWidth; } virtual int GetMinHeight() const { return m_minHeight; } @@ -317,7 +364,8 @@ public: // Override this method to control the values given to Sizers etc. virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } - + virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); } + // Methods for accessing the virtual size of a window. For most // windows this is just the client area of the window, but for // some like scrolled windows it is more or less independent of @@ -391,6 +439,10 @@ public: // make the window modal (all other windows unresponsive) virtual void MakeModal(bool modal = true); + + // (primitive) theming support + // --------------------------- + virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; } virtual bool GetThemeEnabled() const { return m_themeEnabled; } @@ -402,10 +454,6 @@ public: virtual void ApplyParentThemeBackground(const wxColour& WXUNUSED(bg)) { /* do nothing */ } - // returns true if this window should inherit its parent colours on - // creation - virtual bool ShouldInheritColours() const { return false; } - // focus and keyboard handling // --------------------------- @@ -633,13 +681,51 @@ public: // colours, fonts and cursors // -------------------------- + // get the default attributes for the controls of this class: we + // provide a virtual function which can be used to query the default + // attributes of an existing control and a static function which can + // be used even when no existing object of the given class is + // available, but which won't return any styles specific to this + // particular control, of course (e.g. "Ok" button might have + // different -- bold for example -- font) + virtual wxVisualAttributes GetDefaultAttributes() const + { + return GetClassDefaultAttributes(GetWindowVariant()); + } + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // set/retrieve the window colours (system defaults are used by - // default): Set functions return true if colour was changed - virtual bool SetBackgroundColour( const wxColour &colour ); - virtual bool SetForegroundColour( const wxColour &colour ); + // default): SetXXX() functions return true if colour was changed, + // SetDefaultXXX() reset the "m_hasXXX" flag after setting the value + // to prevent it from being inherited by our children + virtual bool SetBackgroundColour(const wxColour& colour); + void SetDefaultBackgroundColour(const wxColour& colour) + { + if ( SetBackgroundColour(colour) ) + m_hasBgCol = false; + } + wxColour GetBackgroundColour() const; - wxColour GetBackgroundColour() const { return m_backgroundColour; } - wxColour GetForegroundColour() const { return m_foregroundColour; } + virtual bool SetForegroundColour(const wxColour& colour); + void SetDefaultForegroundColour(const wxColour& colour) + { + if ( SetForegroundColour(colour) ) + m_hasFgCol = false; + } + wxColour GetForegroundColour() const; + + // set/retrieve the font for the window (SetFont() returns true if the + // font really changed) + virtual bool SetFont(const wxFont& font) = 0; + void SetDefaultFont(const wxFont& font) + { + if ( SetFont(font) ) + m_hasFont = false; + } + const wxFont& GetFont() const { return DoGetFont(); } + wxFont& GetFont() { return DoGetFont(); } // set/retrieve the cursor for this window (SetCursor() returns true // if the cursor was really changed) @@ -647,12 +733,6 @@ public: const wxCursor& GetCursor() const { return m_cursor; } wxCursor& GetCursor() { return m_cursor; } - // set/retrieve the font for the window (SetFont() returns true if the - // font really changed) - virtual bool SetFont( const wxFont &font ) = 0; - const wxFont& GetFont() const { return m_font; } - wxFont& GetFont() { return m_font; } - #if wxUSE_CARET // associate a caret with the window void SetCaret(wxCaret *caret); @@ -851,17 +931,7 @@ public: wxSizer *GetSizer() const { return m_windowSizer; } // Track if this window is a member of a sizer - void SetContainingSizer(wxSizer* sizer) - { - // adding a window to a sizer twice is going to result in fatal and - // hard to debug problems later because when deleting the second - // associated wxSizerItem we're going to dereference a dangling - // pointer; so try to detect this as early as possible - wxASSERT_MSG( !sizer || m_containingSizer != sizer, - _T("Adding a window to the same sizer twice?") ); - - m_containingSizer = sizer; - } + void SetContainingSizer(wxSizer* sizer); wxSizer *GetContainingSizer() const { return m_containingSizer; } // accessibility @@ -924,6 +994,18 @@ protected: virtual bool TryValidator(wxEvent& event); virtual bool TryParent(wxEvent& event); + // inherit the parents visual attributes if they had been explicitly set + // by the user (i.e. we don't inherit default attributes) and if we don't + // have our own explicitly set + virtual void InheritAttributes(); + + // returns false from here if this window doesn't want to inherit the + // parents colours even if InheritAttributes() would normally do it + // + // this just provides a simple way to customize InheritAttributes() + // behaviour in the most common case + virtual bool ShouldInheritColours() const { return false; } + #if wxUSE_CONSTRAINTS // satisfy the constraints for the windows but don't set the window sizes @@ -964,8 +1046,9 @@ protected: // visual window attributes wxCursor m_cursor; - wxFont m_font; - wxColour m_backgroundColour, m_foregroundColour; + wxFont m_font; // see m_hasFont + wxColour m_backgroundColour, // m_hasBgCol + m_foregroundColour; // m_hasFgCol #if wxUSE_CARET wxCaret *m_caret; @@ -1027,6 +1110,10 @@ protected: #if wxUSE_ACCESSIBILITY wxAccessible* m_accessible; #endif + + // Initial window size, used as minimal size in Sizers + wxSize m_initialSize; + // Virtual size (scrolling) wxSize m_virtualSize; @@ -1034,13 +1121,15 @@ protected: int m_minVirtualHeight; int m_maxVirtualWidth; int m_maxVirtualHeight; + + wxWindowVariant m_windowVariant ; // override this to change the default (i.e. used when no style is // specified) border for the window class virtual wxBorder GetDefaultBorder() const; - // get the default size for the new window if no explicit size given - // FIXME why 20 and not 30, 10 or ...? + // Get the default size for the new window if no explicit size given. TLWs + // have their own default size so this is just for non top-level windows. static int WidthDefault(int w) { return w == -1 ? 20 : w; } static int HeightDefault(int h) { return h == -1 ? 20 : h; } @@ -1131,15 +1220,20 @@ protected: virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags = 0) const; + // implements the window variants + virtual void DoSetWindowVariant( wxWindowVariant variant ) ; private: - // contains the last id generated by NewControlId static int ms_lastControlId; // the stack of windows which have captured the mouse static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; + // implementation of both const and non-const versions of GetFont() + wxFont& DoGetFont() const; + + DECLARE_ABSTRACT_CLASS(wxWindowBase) DECLARE_NO_COPY_CLASS(wxWindowBase) DECLARE_EVENT_TABLE()