]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
Minor updates to build scripts
[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 wxFont* pTextFont = new wxFont( 10
105 ,wxMODERN
106 ,wxNORMAL
107 ,wxNORMAL
108 );
109 wxControl::SetFont(*pTextFont);
110 SetSize( nX
111 ,nY
112 ,nWidth
113 ,nHeight
114 );
115 delete pTextFont;
116 return TRUE;
117 } // end of wxStaticText::Create
118
119 wxSize wxStaticText::DoGetBestSize() const
120 {
121 wxString sText(wxGetWindowText(GetHWND()));
122 int nWidthTextMax = 0;
123 int nWidthLine = 0;
124 int nHeightTextTotal = 0;
125 int nHeightLineDefault = 0;
126 int nHeightLine = 0;
127 wxString sCurLine;
128
129 for (const wxChar *pc = sText; ; pc++)
130 {
131 if ( *pc == wxT('\n') || *pc == wxT('\0') )
132 {
133 if (!sCurLine )
134 {
135 //
136 // We can't use GetTextExtent - it will return 0 for both width
137 // and height and an empty line should count in height
138 // calculation
139 //
140 if (!nHeightLineDefault)
141 nHeightLineDefault = nHeightLine;
142 if (!nHeightLineDefault)
143 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
144 nHeightTextTotal += nHeightLineDefault;
145 }
146 else
147 {
148 GetTextExtent( sCurLine
149 ,&nWidthLine
150 ,&nHeightLine
151 );
152 if (nWidthLine > nWidthTextMax)
153 nWidthTextMax = nWidthLine;
154 nHeightTextTotal += nHeightLine;
155 }
156
157 if ( *pc == wxT('\n') )
158 {
159 sCurLine.Empty();
160 }
161 else
162 {
163 break;
164 }
165 }
166 else
167 {
168 sCurLine += *pc;
169 }
170 }
171 return wxSize( nWidthTextMax
172 ,nHeightTextTotal
173 );
174 } // end of wxStaticText::DoGetBestSize
175
176 void wxStaticText::DoSetSize(
177 int nX
178 , int nY
179 , int nWidth
180 , int nHeight
181 , int nSizeFlags
182 )
183 {
184 //
185 // We need to refresh the window after changing its size as the standard
186 // control doesn't always update itself properly.
187 //
188 wxStaticTextBase::DoSetSize( nX
189 ,nY
190 ,nWidth
191 ,nHeight
192 ,nSizeFlags
193 );
194 Refresh();
195 } // end of wxStaticText::DoSetSize
196
197 bool wxStaticText::SetFont(
198 const wxFont& rFont
199 )
200 {
201 bool bRet = wxControl::SetFont(rFont);
202
203 //
204 // Adjust the size of the window to fit to the label unless autoresizing is
205 // disabled
206 //
207 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
208 {
209 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
210 }
211 return bRet;
212 } // end of wxStaticText::SetFont
213
214 void wxStaticText::SetLabel(
215 const wxString& rsLabel
216 )
217 {
218 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
219
220 //
221 // Adjust the size of the window to fit to the label unless autoresizing is
222 // disabled
223 //
224 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
225 {
226 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
227 }
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
229 } // end of wxStaticText::SetLabel
230
231 MRESULT wxStaticText::OS2WindowProc(
232 WXUINT uMsg
233 , WXWPARAM wParam
234 , WXLPARAM lParam
235 )
236 {
237 return wxWindow::OS2WindowProc( uMsg
238 ,wParam
239 ,lParam
240 );
241 } // end of wxStaticText::OS2WindowProc