]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e3a888e | 2 | // Name: src/msw/stattext.cpp |
2bda0e17 KB |
3 | // Purpose: wxStaticText |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
2bda0e17 KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_STATTEXT |
20 | ||
2bda0e17 | 21 | #ifndef WX_PRECOMP |
ac10c957 VZ |
22 | #include "wx/event.h" |
23 | #include "wx/app.h" | |
24 | #include "wx/brush.h" | |
25 | #include "wx/dcclient.h" | |
26 | #include "wx/settings.h" | |
2bda0e17 KB |
27 | #endif |
28 | ||
29 | #include "wx/stattext.h" | |
30 | #include "wx/msw/private.h" | |
2bda0e17 | 31 | |
51741307 | 32 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
33 | WX_DEFINE_FLAGS( wxStaticTextStyle ) |
34 | ||
3ff066a4 | 35 | wxBEGIN_FLAGS( wxStaticTextStyle ) |
bc9fb572 JS |
36 | // new style border flags, we put them first to |
37 | // use them for streaming out | |
3ff066a4 SC |
38 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
39 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
40 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
41 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
42 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
43 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
57f4f925 | 44 | |
bc9fb572 | 45 | // old style border flags |
3ff066a4 SC |
46 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
47 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
48 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
49 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
50 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 51 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
52 | |
53 | // standard window styles | |
3ff066a4 SC |
54 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
55 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
56 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
57 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 58 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
59 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
60 | wxFLAGS_MEMBER(wxVSCROLL) | |
61 | wxFLAGS_MEMBER(wxHSCROLL) | |
62 | ||
63 | wxFLAGS_MEMBER(wxST_NO_AUTORESIZE) | |
64 | wxFLAGS_MEMBER(wxALIGN_LEFT) | |
65 | wxFLAGS_MEMBER(wxALIGN_RIGHT) | |
66 | wxFLAGS_MEMBER(wxALIGN_CENTRE) | |
67 | ||
68 | wxEND_FLAGS( wxStaticTextStyle ) | |
bc9fb572 | 69 | |
51741307 SC |
70 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticText, wxControl,"wx/stattext.h") |
71 | ||
3ff066a4 | 72 | wxBEGIN_PROPERTIES_TABLE(wxStaticText) |
57f4f925 | 73 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 74 | wxPROPERTY_FLAGS( WindowStyle , wxStaticTextStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 75 | wxEND_PROPERTIES_TABLE() |
51741307 | 76 | |
3ff066a4 SC |
77 | wxBEGIN_HANDLERS_TABLE(wxStaticText) |
78 | wxEND_HANDLERS_TABLE() | |
51741307 | 79 | |
57f4f925 | 80 | wxCONSTRUCTOR_6( wxStaticText , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 | 81 | #else |
2bda0e17 | 82 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
51741307 | 83 | #endif |
2bda0e17 | 84 | |
6dd16e4f VZ |
85 | bool wxStaticText::Create(wxWindow *parent, |
86 | wxWindowID id, | |
87 | const wxString& label, | |
88 | const wxPoint& pos, | |
89 | const wxSize& size, | |
90 | long style, | |
91 | const wxString& name) | |
2bda0e17 | 92 | { |
6dd16e4f | 93 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) |
57f4f925 | 94 | return false; |
2bda0e17 | 95 | |
6dd16e4f | 96 | if ( !MSWCreateControl(wxT("STATIC"), label, pos, size) ) |
57f4f925 | 97 | return false; |
2bda0e17 | 98 | |
57f4f925 | 99 | return true; |
6dd16e4f | 100 | } |
c085e333 | 101 | |
65bc172c VZ |
102 | wxBorder wxStaticText::GetDefaultBorder() const |
103 | { | |
104 | return wxBORDER_NONE; | |
105 | } | |
106 | ||
6dd16e4f VZ |
107 | WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const |
108 | { | |
109 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
110 | ||
111 | // translate the alignment flags to the Windows ones | |
112 | // | |
113 | // note that both wxALIGN_LEFT and SS_LEFT are equal to 0 so we shouldn't | |
114 | // test for them using & operator | |
115 | if ( style & wxALIGN_CENTRE ) | |
116 | msStyle |= SS_CENTER; | |
117 | else if ( style & wxALIGN_RIGHT ) | |
118 | msStyle |= SS_RIGHT; | |
119 | else | |
120 | msStyle |= SS_LEFT; | |
121 | ||
42b1fb63 VZ |
122 | // this style is necessary to receive mouse events |
123 | msStyle |= SS_NOTIFY; | |
124 | ||
6dd16e4f | 125 | return msStyle; |
2bda0e17 KB |
126 | } |
127 | ||
f68586e5 | 128 | wxSize wxStaticText::DoGetBestSize() const |
2bda0e17 | 129 | { |
8812e098 | 130 | wxClientDC dc(wx_const_cast(wxStaticText *, this)); |
008881c3 JS |
131 | wxFont font(GetFont()); |
132 | if (!font.Ok()) | |
133 | font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
7a0e7e55 | 134 | |
008881c3 | 135 | dc.SetFont(font); |
8812e098 VZ |
136 | |
137 | wxCoord widthTextMax, heightTextTotal; | |
138 | dc.GetMultiLineTextExtent(GetLabel(), &widthTextMax, &heightTextTotal); | |
139 | ||
37b53d2a | 140 | #ifdef __WXWINCE__ |
8812e098 VZ |
141 | if ( widthTextMax ) |
142 | widthTextMax += 2; | |
143 | #endif // __WXWINCE__ | |
144 | ||
7a0e7e55 VZ |
145 | // border takes extra space |
146 | // | |
147 | // TODO: this is probably not wxStaticText-specific and should be moved | |
148 | wxCoord border; | |
149 | switch ( GetBorder() ) | |
150 | { | |
151 | case wxBORDER_STATIC: | |
152 | case wxBORDER_SIMPLE: | |
153 | border = 1; | |
154 | break; | |
155 | ||
156 | case wxBORDER_SUNKEN: | |
157 | border = 2; | |
158 | break; | |
159 | ||
160 | case wxBORDER_RAISED: | |
161 | case wxBORDER_DOUBLE: | |
162 | border = 3; | |
163 | break; | |
164 | ||
165 | default: | |
166 | wxFAIL_MSG( _T("unknown border style") ); | |
167 | // fall through | |
168 | ||
169 | case wxBORDER_NONE: | |
170 | border = 0; | |
171 | } | |
172 | ||
173 | widthTextMax += 2*border; | |
174 | heightTextTotal += 2*border; | |
175 | ||
31582e4e RD |
176 | wxSize best(widthTextMax, heightTextTotal); |
177 | CacheBestSize(best); | |
178 | return best; | |
2bda0e17 KB |
179 | } |
180 | ||
1e3a888e VZ |
181 | void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags) |
182 | { | |
183 | // we need to refresh the window after changing its size as the standard | |
184 | // control doesn't always update itself properly | |
185 | wxStaticTextBase::DoSetSize(x, y, w, h, sizeFlags); | |
186 | ||
187 | Refresh(); | |
188 | } | |
189 | ||
c0e6c051 RD |
190 | void wxStaticText::SetLabel(const wxString& label) |
191 | { | |
192 | wxStaticTextBase::SetLabel(label); | |
193 | ||
194 | // adjust the size of the window to fit to the label unless autoresizing is | |
195 | // disabled | |
196 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
197 | { | |
9f884528 | 198 | InvalidateBestSize(); |
57f4f925 WS |
199 | DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, |
200 | wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
c0e6c051 RD |
201 | } |
202 | } | |
203 | ||
204 | ||
205 | bool wxStaticText::SetFont(const wxFont& font) | |
206 | { | |
207 | bool ret = wxControl::SetFont(font); | |
208 | ||
209 | // adjust the size of the window to fit to the label unless autoresizing is | |
210 | // disabled | |
211 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
212 | { | |
9f884528 | 213 | InvalidateBestSize(); |
57f4f925 WS |
214 | DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, |
215 | wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
c0e6c051 RD |
216 | } |
217 | ||
218 | return ret; | |
219 | } | |
486fd225 | 220 | |
1e6feb95 | 221 | #endif // wxUSE_STATTEXT |