From: Stefan Csomor Date: Sun, 7 Mar 2004 12:42:37 +0000 (+0000) Subject: SetWindowVariant implemented X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/69d90995bb90845723261e29b3895f3004887881 SetWindowVariant implemented git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/mac/control.h b/include/wx/mac/control.h index 679d13755f..cc588f3861 100644 --- a/include/wx/mac/control.h +++ b/include/wx/mac/control.h @@ -57,7 +57,8 @@ public: virtual bool Enable(bool enable = TRUE) ; virtual bool Show(bool show = TRUE) ; - + virtual void DoSetWindowVariant( wxWindowVariant variant ) ; + virtual void MacRedrawControl () ; virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; virtual void MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , diff --git a/include/wx/window.h b/include/wx/window.h index 75134e6892..795fe59b75 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -96,6 +96,17 @@ WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows; // temporarily switches event handlers). // ---------------------------------------------------------------------------- +// different window variants, on platforms like eg mac uses different rendering sizes + +enum wxWindowVariant +{ + wxWINDOW_VARIANT_DEFAULT, // Default size (usually == normal, may be set by a wxSystemOptions entry) + 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 ) +}; + class WXDLLEXPORT wxWindowBase : public wxEvtHandler { public: @@ -158,6 +169,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; } @@ -1034,6 +1050,8 @@ 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 @@ -1132,6 +1150,8 @@ protected: virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags = 0) const; + // implements the window variants + virtual void DoSetWindowVariant( wxWindowVariant variant ) ; private: diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index dc9f440925..1f80f28ee9 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -186,12 +186,14 @@ wxWindowBase::wxWindowBase() #endif m_virtualSize = wxDefaultSize; - + m_minVirtualWidth = m_minVirtualHeight = m_maxVirtualWidth = m_maxVirtualHeight = -1; + m_windowVariant = wxWINDOW_VARIANT_DEFAULT ; + // Whether we're using the current theme for this window (wxGTK only for now) m_themeEnabled = false; } @@ -621,6 +623,43 @@ void wxWindowBase::SetSizeHints(int minW, int minH, m_maxHeight = maxH; } +void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) +{ + if ( m_windowVariant == variant ) + return ; + + m_windowVariant = variant ; + + DoSetWindowVariant( variant ) ; + return ; +} + +void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant ) +{ + wxFont font = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) ; + int size = font.GetPointSize() ; + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + break ; + case wxWINDOW_VARIANT_SMALL : + font.SetPointSize( size * 3 / 4 ) ; + break ; + case wxWINDOW_VARIANT_MINI : + font.SetPointSize( size * 2 / 3 ) ; + break ; + case wxWINDOW_VARIANT_LARGE : + font.SetPointSize( size * 5 / 4 ) ; + break ; + case wxWINDOW_VARIANT_DEFAULT : + break ; + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + SetFont( font ) ; +} + void wxWindowBase::SetVirtualSizeHints( int minW, int minH, int maxW, int maxH ) { diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 033c3bde05..f44ff6bc7f 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -313,7 +313,8 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l void wxControl::MacPostControlCreate() { wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; - + DoSetWindowVariant( m_windowVariant ) ; + /* if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) { // no font @@ -338,6 +339,7 @@ void wxControl::MacPostControlCreate() ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; } + */ ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; ::EmbedControl( (ControlHandle) m_macControl , container ) ; @@ -750,3 +752,58 @@ void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; } +void wxControl::DoSetWindowVariant( wxWindowVariant variant ) +{ + if ( m_macControl == NULL ) + { + wxWindow::SetWindowVariant( variant ) ; + return ; + + } + m_windowVariant = variant ; + + ControlSize size ; + ControlFontStyleRec fontStyle; + fontStyle.flags = kControlUseFontMask ; + + // we will get that from the settings later + // and make this NORMAL later, but first + // we have a few calculations that we must fix + + if ( variant == wxWINDOW_VARIANT_DEFAULT ) + variant = wxWINDOW_VARIANT_SMALL ; + + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + size = kControlSizeNormal; + fontStyle.font = kControlFontBigSystemFont; + break ; + case wxWINDOW_VARIANT_SMALL : + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; + break ; + case wxWINDOW_VARIANT_MINI : + if (UMAGetSystemVersion() >= 0x1030 ) + { + size = 3 ; // not always defined in the header + fontStyle.font = -5 ; // not always defined in the header + } + else + { + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; + } + break; + break ; + case wxWINDOW_VARIANT_LARGE : + size = kControlSizeLarge; + fontStyle.font = kControlFontBigSystemFont; + break ; + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); + ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle ); +} diff --git a/src/mac/control.cpp b/src/mac/control.cpp index 033c3bde05..f44ff6bc7f 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -313,7 +313,8 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l void wxControl::MacPostControlCreate() { wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; - + DoSetWindowVariant( m_windowVariant ) ; + /* if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) { // no font @@ -338,6 +339,7 @@ void wxControl::MacPostControlCreate() ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; } + */ ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; ::EmbedControl( (ControlHandle) m_macControl , container ) ; @@ -750,3 +752,58 @@ void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; } +void wxControl::DoSetWindowVariant( wxWindowVariant variant ) +{ + if ( m_macControl == NULL ) + { + wxWindow::SetWindowVariant( variant ) ; + return ; + + } + m_windowVariant = variant ; + + ControlSize size ; + ControlFontStyleRec fontStyle; + fontStyle.flags = kControlUseFontMask ; + + // we will get that from the settings later + // and make this NORMAL later, but first + // we have a few calculations that we must fix + + if ( variant == wxWINDOW_VARIANT_DEFAULT ) + variant = wxWINDOW_VARIANT_SMALL ; + + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + size = kControlSizeNormal; + fontStyle.font = kControlFontBigSystemFont; + break ; + case wxWINDOW_VARIANT_SMALL : + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; + break ; + case wxWINDOW_VARIANT_MINI : + if (UMAGetSystemVersion() >= 0x1030 ) + { + size = 3 ; // not always defined in the header + fontStyle.font = -5 ; // not always defined in the header + } + else + { + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; + } + break; + break ; + case wxWINDOW_VARIANT_LARGE : + size = kControlSizeLarge; + fontStyle.font = kControlFontBigSystemFont; + break ; + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); + ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle ); +}