]>
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 /////////////////////////////////////////////////////////////////////////////
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
)
37 bool wxStaticText::Create(wxWindow
*parent
,
39 const wxString
& label
,
45 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
48 if ( !MSWCreateControl(wxT("STATIC"), label
, pos
, size
) )
54 wxBorder
wxStaticText::GetDefaultBorder() const
59 WXDWORD
wxStaticText::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
61 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
63 // translate the alignment flags to the Windows ones
65 // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't
66 // test for them using & operator
67 if ( style
& wxALIGN_CENTRE
)
69 else if ( style
& wxALIGN_RIGHT
)
77 wxSize
wxStaticText::DoGetBestSize() const
79 wxString
text(wxGetWindowText(GetHWND()));
81 int widthTextMax
= 0, widthLine
,
82 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
84 bool lastWasAmpersand
= FALSE
;
87 for ( const wxChar
*pc
= text
; ; pc
++ )
89 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
93 // we can't use GetTextExtent - it will return 0 for both width
94 // and height and an empty line should count in height
96 if ( !heightLineDefault
)
97 heightLineDefault
= heightLine
;
98 if ( !heightLineDefault
)
99 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
101 heightTextTotal
+= heightLineDefault
;
105 GetTextExtent(curLine
, &widthLine
, &heightLine
);
106 if ( widthLine
> widthTextMax
)
107 widthTextMax
= widthLine
;
108 heightTextTotal
+= heightLine
;
111 if ( *pc
== wxT('\n') )
123 // we shouldn't take into account the '&' which just introduces the
124 // mnemonic characters and so are not shown on the screen -- except
125 // when it is preceded by another '&' in which case it stands for a
127 if ( *pc
== _T('&') )
129 if ( !lastWasAmpersand
)
131 lastWasAmpersand
= TRUE
;
133 // skip the statement adding pc to curLine below
137 // it is a literal ampersand
138 lastWasAmpersand
= FALSE
;
145 return wxSize(widthTextMax
, heightTextTotal
);
148 void wxStaticText::DoSetSize(int x
, int y
, int w
, int h
, int sizeFlags
)
150 // we need to refresh the window after changing its size as the standard
151 // control doesn't always update itself properly
152 wxStaticTextBase::DoSetSize(x
, y
, w
, h
, sizeFlags
);
157 void wxStaticText::SetLabel(const wxString
& label
)
159 wxStaticTextBase::SetLabel(label
);
161 // adjust the size of the window to fit to the label unless autoresizing is
163 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
165 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
170 bool wxStaticText::SetFont(const wxFont
& font
)
172 bool ret
= wxControl::SetFont(font
);
174 // adjust the size of the window to fit to the label unless autoresizing is
176 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
178 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
184 #endif // wxUSE_STATTEXT