]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
Removed debug comments
[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 #ifdef __GNUG__
13 #pragma implementation "stattext.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/event.h"
21 #include "wx/app.h"
22 #include "wx/brush.h"
23 #endif
24
25 #include "wx/stattext.h"
26 #include "wx/os2/private.h"
27 #include <stdio.h>
28
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
30
31 bool wxStaticText::Create(
32 wxWindow* pParent
33 , wxWindowID vId
34 , const wxString& rsLabel
35 , const wxPoint& rPos
36 , const wxSize& rSize
37 , long lStyle
38 , const wxString& rsName
39 )
40 {
41 SetName(rsName);
42 if (pParent)
43 pParent->AddChild(this);
44
45 SetBackgroundColour(pParent->GetBackgroundColour()) ;
46 SetForegroundColour(pParent->GetForegroundColour()) ;
47
48 if ( vId == -1 )
49 m_windowId = (int)NewControlId();
50 else
51 m_windowId = vId;
52
53 int nX = rPos.x;
54 int nY = rPos.y;
55 int nWidth = rSize.x;
56 int nHeight = rSize.y;
57
58 m_windowStyle = lStyle;
59
60 long lSstyle = 0L;
61
62 lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER;
63 if (m_windowStyle & wxALIGN_CENTRE)
64 lSstyle |= DT_CENTER;
65 else if (m_windowStyle & wxALIGN_RIGHT)
66 lSstyle |= DT_RIGHT;
67 else
68 lSstyle |= DT_LEFT;
69 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
70 ,WC_STATIC // Window class
71 ,(PSZ)rsLabel.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("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 wxControl::SetFont(pParent->GetFont());
104 SetSize( nX
105 ,nY
106 ,nWidth
107 ,nHeight
108 );
109 return TRUE;
110 } // end of wxStaticText::Create
111
112 wxSize wxStaticText::DoGetBestSize() const
113 {
114 wxString sText(wxGetWindowText(GetHWND()));
115 int nWidthTextMax = 0;
116 int nWidthLine = 0;
117 int nHeightTextTotal = 0;
118 int nHeightLineDefault = 0;
119 int nHeightLine = 0;
120 wxString sCurLine;
121
122 for (const wxChar *pc = sText; ; pc++)
123 {
124 if ( *pc == wxT('\n') || *pc == wxT('\0') )
125 {
126 if (!sCurLine )
127 {
128 //
129 // We can't use GetTextExtent - it will return 0 for both width
130 // and height and an empty line should count in height
131 // calculation
132 //
133 if (!nHeightLineDefault)
134 nHeightLineDefault = nHeightLine;
135 if (!nHeightLineDefault)
136 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
137 nHeightTextTotal += nHeightLineDefault;
138 }
139 else
140 {
141 GetTextExtent( sCurLine
142 ,&nWidthLine
143 ,&nHeightLine
144 );
145 if (nWidthLine > nWidthTextMax)
146 nWidthTextMax = nWidthLine;
147 nHeightTextTotal += nHeightLine;
148 }
149
150 if ( *pc == wxT('\n') )
151 {
152 sCurLine.Empty();
153 }
154 else
155 {
156 break;
157 }
158 }
159 else
160 {
161 sCurLine += *pc;
162 }
163 }
164 return wxSize( nWidthTextMax
165 ,nHeightTextTotal
166 );
167 } // end of wxStaticText::DoGetBestSize
168
169 void wxStaticText::DoSetSize(
170 int nX
171 , int nY
172 , int nWidth
173 , int nHeight
174 , int nSizeFlags
175 )
176 {
177 //
178 // We need to refresh the window after changing its size as the standard
179 // control doesn't always update itself properly.
180 //
181 wxStaticTextBase::DoSetSize( nX
182 ,nY
183 ,nWidth
184 ,nHeight
185 ,nSizeFlags
186 );
187 Refresh();
188 } // end of wxStaticText::DoSetSize
189
190 bool wxStaticText::SetFont(
191 const wxFont& rFont
192 )
193 {
194 bool bRet = wxControl::SetFont(rFont);
195
196 //
197 // Adjust the size of the window to fit to the label unless autoresizing is
198 // disabled
199 //
200 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
201 {
202 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
203 }
204 return bRet;
205 } // end of wxStaticText::SetFont
206
207 void wxStaticText::SetLabel(
208 const wxString& rsLabel
209 )
210 {
211 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
212
213 //
214 // Adjust the size of the window to fit to the label unless autoresizing is
215 // disabled
216 //
217 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
218 {
219 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
220 }
221 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
222 } // end of wxStaticText::SetLabel
223
224 MRESULT wxStaticText::OS2WindowProc(
225 WXUINT uMsg
226 , WXWPARAM wParam
227 , WXLPARAM lParam
228 )
229 {
230 return wxWindow::OS2WindowProc( uMsg
231 ,wParam
232 ,lParam
233 );
234 } // end of wxStaticText::OS2WindowProc
235
236