]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
remove sizing controls when being in fullscreen mode
[wxWidgets.git] / src / os2 / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose: wxStaticText
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/event.h"
17 #include "wx/app.h"
18 #include "wx/brush.h"
19 #include "wx/scrolwin.h"
20 #endif
21
22 #include "wx/stattext.h"
23 #include "wx/os2/private.h"
24 #include <stdio.h>
25
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
27
28 bool wxStaticText::Create(
29 wxWindow* pParent
30 , wxWindowID vId
31 , const wxString& rsLabel
32 , const wxPoint& rPos
33 , const wxSize& rSize
34 , long lStyle
35 , const wxString& rsName
36 )
37 {
38 SetName(rsName);
39 if (pParent)
40 pParent->AddChild(this);
41
42 SetBackgroundColour(pParent->GetBackgroundColour()) ;
43 SetForegroundColour(pParent->GetForegroundColour()) ;
44
45 if ( vId == -1 )
46 m_windowId = (int)NewControlId();
47 else
48 m_windowId = vId;
49
50 int nX = rPos.x;
51 int nY = rPos.y;
52 int nWidth = rSize.x;
53 int nHeight = rSize.y;
54
55 m_windowStyle = lStyle;
56
57 long lSstyle = 0L;
58
59 lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER | DT_MNEMONIC;
60 if (m_windowStyle & wxALIGN_CENTRE)
61 lSstyle |= DT_CENTER;
62 else if (m_windowStyle & wxALIGN_RIGHT)
63 lSstyle |= DT_RIGHT;
64 else
65 lSstyle |= DT_LEFT;
66
67 wxString sLabel = ::wxPMTextToLabel(rsLabel);
68
69 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
70 ,WC_STATIC // Window class
71 ,(PSZ)sLabel.c_str() // Initial Text
72 ,(ULONG)lSstyle // Style flags
73 ,0L, 0L, 0L, 0L // Origin -- 0 size
74 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
75 ,HWND_TOP // initial z position
76 ,(ULONG)m_windowId // Window identifier
77 ,NULL // no control data
78 ,NULL // no Presentation parameters
79 );
80
81 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
82
83 wxColour vColour;
84
85 vColour.Set(wxString(wxT("BLACK")));
86
87 LONG lColor = (LONG)vColour.GetPixel();
88
89 ::WinSetPresParam( m_hWnd
90 ,PP_FOREGROUNDCOLOR
91 ,sizeof(LONG)
92 ,(PVOID)&lColor
93 );
94 lColor = (LONG)m_backgroundColour.GetPixel();
95
96 ::WinSetPresParam( m_hWnd
97 ,PP_BACKGROUNDCOLOR
98 ,sizeof(LONG)
99 ,(PVOID)&lColor
100 );
101
102 SubclassWin(m_hWnd);
103 SetFont(*wxSMALL_FONT);
104 SetXComp(0);
105 SetYComp(0);
106 SetSize( nX
107 ,nY
108 ,nWidth
109 ,nHeight
110 );
111 return TRUE;
112 } // end of wxStaticText::Create
113
114 wxSize wxStaticText::DoGetBestSize() const
115 {
116 wxString sText(wxGetWindowText(GetHWND()));
117 int nWidthTextMax = 0;
118 int nWidthLine = 0;
119 int nHeightTextTotal = 0;
120 int nHeightLineDefault = 0;
121 int nHeightLine = 0;
122 wxString sCurLine;
123 bool bLastWasTilde = FALSE;
124
125 for (const wxChar *pc = sText; ; pc++)
126 {
127 if ( *pc == wxT('\n') || *pc == wxT('\0') )
128 {
129 if (!sCurLine )
130 {
131 //
132 // We can't use GetTextExtent - it will return 0 for both width
133 // and height and an empty line should count in height
134 // calculation
135 //
136 if (!nHeightLineDefault)
137 nHeightLineDefault = nHeightLine;
138 if (!nHeightLineDefault)
139 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
140 nHeightTextTotal += nHeightLineDefault;
141 }
142 else
143 {
144 GetTextExtent( sCurLine
145 ,&nWidthLine
146 ,&nHeightLine
147 );
148 if (nWidthLine > nWidthTextMax)
149 nWidthTextMax = nWidthLine;
150 nHeightTextTotal += nHeightLine;
151 }
152
153 if ( *pc == wxT('\n') )
154 {
155 sCurLine.Empty();
156 }
157 else
158 {
159 break;
160 }
161 }
162 else
163 {
164 //
165 // We shouldn't take into account the '~' which just introduces the
166 // mnemonic characters and so are not shown on the screen -- except
167 // when it is preceded by another '~' in which case it stands for a
168 // literal tilde
169 //
170 if (*pc == _T('~'))
171 {
172 if (!bLastWasTilde)
173 {
174 bLastWasTilde = TRUE;
175
176 //
177 // Skip the statement adding pc to curLine below
178 //
179 continue;
180 }
181
182 //
183 // It is a literal tilde
184 //
185 bLastWasTilde = FALSE;
186 }
187 sCurLine += *pc;
188 }
189 }
190 return wxSize( nWidthTextMax
191 ,nHeightTextTotal
192 );
193 } // end of wxStaticText::DoGetBestSize
194
195 void wxStaticText::DoSetSize(
196 int nX
197 , int nY
198 , int nWidth
199 , int nHeight
200 , int nSizeFlags
201 )
202 {
203 //
204 // We need to refresh the window after changing its size as the standard
205 // control doesn't always update itself properly.
206 //
207 wxStaticTextBase::DoSetSize( nX
208 ,nY
209 ,nWidth
210 ,nHeight
211 ,nSizeFlags
212 );
213 Refresh();
214 } // end of wxStaticText::DoSetSize
215
216 bool wxStaticText::SetFont(
217 const wxFont& rFont
218 )
219 {
220 bool bRet = wxControl::SetFont(rFont);
221
222 //
223 // Adjust the size of the window to fit to the label unless autoresizing is
224 // disabled
225 //
226 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
227 {
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
229 }
230 return bRet;
231 } // end of wxStaticText::SetFont
232
233 void wxStaticText::SetLabel(
234 const wxString& rsLabel
235 )
236 {
237 wxString sLabel = ::wxPMTextToLabel(rsLabel);
238 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
239
240 //
241 // Adjust the size of the window to fit to the label unless autoresizing is
242 // disabled
243 //
244 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
245 {
246 wxCoord vX;
247 wxCoord vY;
248 wxCoord vWidth;
249 wxCoord vHeight;
250
251 GetPosition(&vX, &vY);
252 GetSize(&vWidth, &vHeight);
253 if (!(vX == -1 && vY == -1 && vWidth == -1 && vHeight == -1))
254 DoSetSize(vX, vY, vWidth, vHeight, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
255 else
256 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
257 }
258 } // end of wxStaticText::SetLabel
259
260 MRESULT wxStaticText::OS2WindowProc(
261 WXUINT uMsg
262 , WXWPARAM wParam
263 , WXLPARAM lParam
264 )
265 {
266 return wxWindow::OS2WindowProc( uMsg
267 ,wParam
268 ,lParam
269 );
270 } // end of wxStaticText::OS2WindowProc