SetWindowVariant implemented

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2004-03-07 12:42:37 +00:00
parent 2367247b6c
commit 69d90995bb
5 changed files with 178 additions and 4 deletions

View File

@@ -57,6 +57,7 @@ public:
virtual bool Enable(bool enable = TRUE) ; virtual bool Enable(bool enable = TRUE) ;
virtual bool Show(bool show = TRUE) ; virtual bool Show(bool show = TRUE) ;
virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
virtual void MacRedrawControl () ; virtual void MacRedrawControl () ;
virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;

View File

@@ -96,6 +96,17 @@ WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
// temporarily switches event handlers). // 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 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
{ {
public: public:
@@ -158,6 +169,11 @@ public:
virtual void SetName( const wxString &name ) { m_windowName = name; } virtual void SetName( const wxString &name ) { m_windowName = name; }
virtual wxString GetName() const { return m_windowName; } 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 // window id uniquely identifies the window among its siblings unless
// it is -1 which means "don't care" // it is -1 which means "don't care"
void SetId( wxWindowID winid ) { m_windowId = winid; } void SetId( wxWindowID winid ) { m_windowId = winid; }
@@ -1035,6 +1051,8 @@ protected:
int m_maxVirtualWidth; int m_maxVirtualWidth;
int m_maxVirtualHeight; int m_maxVirtualHeight;
wxWindowVariant m_windowVariant ;
// override this to change the default (i.e. used when no style is // override this to change the default (i.e. used when no style is
// specified) border for the window class // specified) border for the window class
virtual wxBorder GetDefaultBorder() const; virtual wxBorder GetDefaultBorder() const;
@@ -1132,6 +1150,8 @@ protected:
virtual void AdjustForParentClientOrigin(int& x, int& y, virtual void AdjustForParentClientOrigin(int& x, int& y,
int sizeFlags = 0) const; int sizeFlags = 0) const;
// implements the window variants
virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
private: private:

View File

@@ -192,6 +192,8 @@ wxWindowBase::wxWindowBase()
m_maxVirtualWidth = m_maxVirtualWidth =
m_maxVirtualHeight = -1; m_maxVirtualHeight = -1;
m_windowVariant = wxWINDOW_VARIANT_DEFAULT ;
// Whether we're using the current theme for this window (wxGTK only for now) // Whether we're using the current theme for this window (wxGTK only for now)
m_themeEnabled = false; m_themeEnabled = false;
} }
@@ -621,6 +623,43 @@ void wxWindowBase::SetSizeHints(int minW, int minH,
m_maxHeight = maxH; 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, void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
int maxW, int maxH ) int maxW, int maxH )
{ {

View File

@@ -313,7 +313,8 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
void wxControl::MacPostControlCreate() void wxControl::MacPostControlCreate()
{ {
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
DoSetWindowVariant( m_windowVariant ) ;
/*
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
{ {
// no font // no font
@@ -338,6 +339,7 @@ void wxControl::MacPostControlCreate()
::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
} }
*/
ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( (ControlHandle) m_macControl , container ) ; ::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") ) ; 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 );
}

View File

@@ -313,7 +313,8 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
void wxControl::MacPostControlCreate() void wxControl::MacPostControlCreate()
{ {
wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
DoSetWindowVariant( m_windowVariant ) ;
/*
if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
{ {
// no font // no font
@@ -338,6 +339,7 @@ void wxControl::MacPostControlCreate()
::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
} }
*/
ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( (ControlHandle) m_macControl , container ) ; ::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") ) ; 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 );
}