]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
New code for Update() under GTK 2.0. Added
[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 #include "wx/scrolwin.h"
24 #endif
25
26 #include "wx/stattext.h"
27 #include "wx/os2/private.h"
28 #include <stdio.h>
29
30 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
31
32 bool wxStaticText::Create(
33 wxWindow* pParent
34 , wxWindowID vId
35 , const wxString& rsLabel
36 , const wxPoint& rPos
37 , const wxSize& rSize
38 , long lStyle
39 , const wxString& rsName
40 )
41 {
42 SetName(rsName);
43 if (pParent)
44 pParent->AddChild(this);
45
46 SetBackgroundColour(pParent->GetBackgroundColour()) ;
47 SetForegroundColour(pParent->GetForegroundColour()) ;
48
49 if ( vId == -1 )
50 m_windowId = (int)NewControlId();
51 else
52 m_windowId = vId;
53
54 int nX = rPos.x;
55 int nY = rPos.y;
56 int nWidth = rSize.x;
57 int nHeight = rSize.y;
58
59 m_windowStyle = lStyle;
60
61 long lSstyle = 0L;
62
63 lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER;
64 if (m_windowStyle & wxALIGN_CENTRE)
65 lSstyle |= DT_CENTER;
66 else if (m_windowStyle & wxALIGN_RIGHT)
67 lSstyle |= DT_RIGHT;
68 else
69 lSstyle |= DT_LEFT;
70 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
71 ,WC_STATIC // Window class
72 ,(PSZ)rsLabel.c_str() // Initial Text
73 ,(ULONG)lSstyle // Style flags
74 ,0L, 0L, 0L, 0L // Origin -- 0 size
75 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
76 ,HWND_TOP // initial z position
77 ,(ULONG)m_windowId // Window identifier
78 ,NULL // no control data
79 ,NULL // no Presentation parameters
80 );
81
82 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl"));
83
84 wxColour vColour;
85
86 vColour.Set(wxString("BLACK"));
87
88 LONG lColor = (LONG)vColour.GetPixel();
89
90 ::WinSetPresParam( m_hWnd
91 ,PP_FOREGROUNDCOLOR
92 ,sizeof(LONG)
93 ,(PVOID)&lColor
94 );
95 lColor = (LONG)m_backgroundColour.GetPixel();
96
97 ::WinSetPresParam( m_hWnd
98 ,PP_BACKGROUNDCOLOR
99 ,sizeof(LONG)
100 ,(PVOID)&lColor
101 );
102
103 SubclassWin(m_hWnd);
104 SetFont(*wxSMALL_FONT);
105 SetXComp(0);
106 SetYComp(0);
107 SetSize( nX
108 ,nY
109 ,nWidth
110 ,nHeight
111 );
112 return TRUE;
113 } // end of wxStaticText::Create
114
115 wxSize wxStaticText::DoGetBestSize() const
116 {
117 wxString sText(wxGetWindowText(GetHWND()));
118 int nWidthTextMax = 0;
119 int nWidthLine = 0;
120 int nHeightTextTotal = 0;
121 int nHeightLineDefault = 0;
122 int nHeightLine = 0;
123 wxString sCurLine;
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 sCurLine += *pc;
165 }
166 }
167 return wxSize( nWidthTextMax
168 ,nHeightTextTotal
169 );
170 } // end of wxStaticText::DoGetBestSize
171
172 void wxStaticText::DoSetSize(
173 int nX
174 , int nY
175 , int nWidth
176 , int nHeight
177 , int nSizeFlags
178 )
179 {
180 //
181 // We need to refresh the window after changing its size as the standard
182 // control doesn't always update itself properly.
183 //
184 wxStaticTextBase::DoSetSize( nX
185 ,nY
186 ,nWidth
187 ,nHeight
188 ,nSizeFlags
189 );
190 Refresh();
191 } // end of wxStaticText::DoSetSize
192
193 bool wxStaticText::SetFont(
194 const wxFont& rFont
195 )
196 {
197 bool bRet = wxControl::SetFont(rFont);
198
199 //
200 // Adjust the size of the window to fit to the label unless autoresizing is
201 // disabled
202 //
203 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
204 {
205 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
206 }
207 return bRet;
208 } // end of wxStaticText::SetFont
209
210 void wxStaticText::SetLabel(
211 const wxString& rsLabel
212 )
213 {
214 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
215
216 //
217 // Adjust the size of the window to fit to the label unless autoresizing is
218 // disabled
219 //
220 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
221 {
222 wxCoord vX;
223 wxCoord vY;
224 wxCoord vWidth;
225 wxCoord vHeight;
226
227 GetPosition(&vX, &vY);
228 GetSize(&vWidth, &vHeight);
229 if (!(vX == -1 && vY == -1 && vWidth == -1 && vHeight == -1))
230 DoSetSize(vX, vY, vWidth, vHeight, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
231 else
232 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
233 }
234 } // end of wxStaticText::SetLabel
235
236 MRESULT wxStaticText::OS2WindowProc(
237 WXUINT uMsg
238 , WXWPARAM wParam
239 , WXLPARAM lParam
240 )
241 {
242 return wxWindow::OS2WindowProc( uMsg
243 ,wParam
244 ,lParam
245 );
246 } // end of wxStaticText::OS2WindowProc