]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
oops, forgot to commit wxFontBase::SetNativeFontInfo implementation
[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
95 SubclassWin(m_hWnd);
96 wxControl::SetFont(pParent->GetFont());
97 SetSize( nX
98 ,nY
99 ,nWidth
100 ,nHeight
101 );
102 return TRUE;
103 } // end of wxStaticText::Create
104
105 wxSize wxStaticText::DoGetBestSize() const
106 {
107 wxString sText(wxGetWindowText(GetHWND()));
108 int nWidthTextMax = 0;
109 int nWidthLine = 0;
110 int nHeightTextTotal = 0;
111 int nHeightLineDefault = 0;
112 int nHeightLine = 0;
113 wxString sCurLine;
114
115 for (const wxChar *pc = sText; ; pc++)
116 {
117 if ( *pc == wxT('\n') || *pc == wxT('\0') )
118 {
119 if (!sCurLine )
120 {
121 //
122 // We can't use GetTextExtent - it will return 0 for both width
123 // and height and an empty line should count in height
124 // calculation
125 //
126 if (!nHeightLineDefault)
127 nHeightLineDefault = nHeightLine;
128 if (!nHeightLineDefault)
129 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
130 nHeightTextTotal += nHeightLineDefault;
131 }
132 else
133 {
134 GetTextExtent( sCurLine
135 ,&nWidthLine
136 ,&nHeightLine
137 );
138 if (nWidthLine > nWidthTextMax)
139 nWidthTextMax = nWidthLine;
140 nHeightTextTotal += nHeightLine;
141 }
142
143 if ( *pc == wxT('\n') )
144 {
145 sCurLine.Empty();
146 }
147 else
148 {
149 break;
150 }
151 }
152 else
153 {
154 sCurLine += *pc;
155 }
156 }
157 return wxSize( nWidthTextMax
158 ,nHeightTextTotal
159 );
160 } // end of wxStaticText::DoGetBestSize
161
162 bool wxStaticText::SetFont(
163 const wxFont& rFont
164 )
165 {
166 bool bRet = wxControl::SetFont(rFont);
167
168 //
169 // Adjust the size of the window to fit to the label unless autoresizing is
170 // disabled
171 //
172 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
173 {
174 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
175 }
176 return bRet;
177 } // end of wxStaticText::SetFont
178
179 void wxStaticText::SetLabel(
180 const wxString& rsLabel
181 )
182 {
183 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
184
185 //
186 // Adjust the size of the window to fit to the label unless autoresizing is
187 // disabled
188 //
189 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
190 {
191 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
192 }
193 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
194 } // end of wxStaticText::SetLabel
195
196 MRESULT wxStaticText::OS2WindowProc(
197 WXUINT uMsg
198 , WXWPARAM wParam
199 , WXLPARAM lParam
200 )
201 {
202 return wxWindow::OS2WindowProc( uMsg
203 ,wParam
204 ,lParam
205 );
206 } // end of wxStaticText::OS2WindowProc
207
208