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