]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/stattext.cpp
3 // Purpose: wxStaticText
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "stattext.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
31 #include "wx/stattext.h"
32 #include "wx/msw/private.h"
35 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
41 bool wxStaticText::Create(wxWindow
*parent
,
43 const wxString
& label
,
49 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
52 if ( !MSWCreateControl(wxT("STATIC"), label
, pos
, size
) )
58 wxBorder
wxStaticText::GetDefaultBorder() const
63 WXDWORD
wxStaticText::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
65 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
67 // translate the alignment flags to the Windows ones
69 // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't
70 // test for them using & operator
71 if ( style
& wxALIGN_CENTRE
)
73 else if ( style
& wxALIGN_RIGHT
)
81 wxSize
wxStaticText::DoGetBestSize() const
83 wxString
text(wxGetWindowText(GetHWND()));
85 int widthTextMax
= 0, widthLine
,
86 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
88 bool lastWasAmpersand
= FALSE
;
91 for ( const wxChar
*pc
= text
; ; pc
++ )
93 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
97 // we can't use GetTextExtent - it will return 0 for both width
98 // and height and an empty line should count in height
100 if ( !heightLineDefault
)
101 heightLineDefault
= heightLine
;
102 if ( !heightLineDefault
)
103 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
105 heightTextTotal
+= heightLineDefault
;
109 GetTextExtent(curLine
, &widthLine
, &heightLine
);
110 if ( widthLine
> widthTextMax
)
111 widthTextMax
= widthLine
;
112 heightTextTotal
+= heightLine
;
115 if ( *pc
== wxT('\n') )
127 // we shouldn't take into account the '&' which just introduces the
128 // mnemonic characters and so are not shown on the screen -- except
129 // when it is preceded by another '&' in which case it stands for a
131 if ( *pc
== _T('&') )
133 if ( !lastWasAmpersand
)
135 lastWasAmpersand
= TRUE
;
137 // skip the statement adding pc to curLine below
141 // it is a literal ampersand
142 lastWasAmpersand
= FALSE
;
149 return wxSize(widthTextMax
, heightTextTotal
);
152 void wxStaticText::DoSetSize(int x
, int y
, int w
, int h
, int sizeFlags
)
154 // we need to refresh the window after changing its size as the standard
155 // control doesn't always update itself properly
156 wxStaticTextBase::DoSetSize(x
, y
, w
, h
, sizeFlags
);
161 void wxStaticText::SetLabel(const wxString
& label
)
163 wxStaticTextBase::SetLabel(label
);
165 // adjust the size of the window to fit to the label unless autoresizing is
167 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
169 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
174 bool wxStaticText::SetFont(const wxFont
& font
)
176 bool ret
= wxControl::SetFont(font
);
178 // adjust the size of the window to fit to the label unless autoresizing is
180 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
182 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
188 #endif // wxUSE_STATTEXT