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