]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
implemented menu drawing in the GTK theme
[wxWidgets.git] / src / os2 / stattext.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose: wxStaticText
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
aa213887
SN
12#ifdef __GNUG__
13#pragma implementation "stattext.h"
14#endif
15
d90895ac
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
0e320a79 18
d90895ac
DW
19#ifndef WX_PRECOMP
20#include "wx/event.h"
0e320a79 21#include "wx/app.h"
d90895ac 22#include "wx/brush.h"
a4a16252 23#include "wx/scrolwin.h"
d90895ac 24#endif
0e320a79 25
d90895ac
DW
26#include "wx/stattext.h"
27#include "wx/os2/private.h"
0e320a79
DW
28#include <stdio.h>
29
0e320a79 30IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79 31
1f3154c8
DW
32bool 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)
0e320a79 41{
1f3154c8
DW
42 SetName(rsName);
43 if (pParent)
44 pParent->AddChild(this);
d90895ac 45
1f3154c8
DW
46 SetBackgroundColour(pParent->GetBackgroundColour()) ;
47 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 48
f15b4952 49 if ( vId == -1 )
d90895ac
DW
50 m_windowId = (int)NewControlId();
51 else
1f3154c8 52 m_windowId = vId;
0e320a79 53
1f3154c8
DW
54 int nX = rPos.x;
55 int nY = rPos.y;
56 int nWidth = rSize.x;
57 int nHeight = rSize.y;
0e320a79 58
1f3154c8 59 m_windowStyle = lStyle;
0e320a79 60
1f3154c8 61 long lSstyle = 0L;
0e320a79 62
1f3154c8
DW
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"));
d90895ac 83
3c299c3a
DW
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 );
7993e67c
DW
95 lColor = (LONG)m_backgroundColour.GetPixel();
96
97 ::WinSetPresParam( m_hWnd
98 ,PP_BACKGROUNDCOLOR
99 ,sizeof(LONG)
100 ,(PVOID)&lColor
101 );
3c299c3a 102
1f3154c8 103 SubclassWin(m_hWnd);
b3260bce
DW
104 wxFont* pTextFont = new wxFont( 10
105 ,wxMODERN
106 ,wxNORMAL
107 ,wxNORMAL
108 );
109 wxControl::SetFont(*pTextFont);
3c299c3a
DW
110 SetSize( nX
111 ,nY
112 ,nWidth
113 ,nHeight
114 );
b3260bce 115 delete pTextFont;
3c299c3a 116 return TRUE;
1f3154c8 117} // end of wxStaticText::Create
0e320a79 118
e78c4d50 119wxSize wxStaticText::DoGetBestSize() const
0e320a79 120{
1f3154c8
DW
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
3c299c3a 129 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
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
e78c4d50
DW
137 // and height and an empty line should count in height
138 // calculation
1f3154c8
DW
139 //
140 if (!nHeightLineDefault)
141 nHeightLineDefault = nHeightLine;
142 if (!nHeightLineDefault)
143 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
144 nHeightTextTotal += nHeightLineDefault;
e78c4d50 145 }
1f3154c8
DW
146 else
147 {
148 GetTextExtent( sCurLine
149 ,&nWidthLine
150 ,&nHeightLine
151 );
152 if (nWidthLine > nWidthTextMax)
153 nWidthTextMax = nWidthLine;
154 nHeightTextTotal += nHeightLine;
e78c4d50 155 }
d90895ac 156
1f3154c8
DW
157 if ( *pc == wxT('\n') )
158 {
159 sCurLine.Empty();
d90895ac 160 }
1f3154c8
DW
161 else
162 {
d90895ac
DW
163 break;
164 }
165 }
1f3154c8
DW
166 else
167 {
168 sCurLine += *pc;
d90895ac
DW
169 }
170 }
1f3154c8
DW
171 return wxSize( nWidthTextMax
172 ,nHeightTextTotal
173 );
174} // end of wxStaticText::DoGetBestSize
175
7993e67c
DW
176void 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
3c299c3a
DW
197bool wxStaticText::SetFont(
198 const wxFont& rFont
1f3154c8 199)
0e320a79 200{
3c299c3a 201 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
202
203 //
204 // Adjust the size of the window to fit to the label unless autoresizing is
205 // disabled
206 //
3c299c3a 207 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
208 {
209 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
210 }
3c299c3a
DW
211 return bRet;
212} // end of wxStaticText::SetFont
d90895ac 213
3c299c3a
DW
214void wxStaticText::SetLabel(
215 const wxString& rsLabel
1f3154c8 216)
d90895ac 217{
3c299c3a 218 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
1f3154c8
DW
219
220 //
221 // Adjust the size of the window to fit to the label unless autoresizing is
222 // disabled
223 //
3c299c3a 224 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
1f3154c8
DW
225 {
226 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
227 }
3c299c3a
DW
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
229} // end of wxStaticText::SetLabel
1f3154c8
DW
230
231MRESULT wxStaticText::OS2WindowProc(
232 WXUINT uMsg
233, WXWPARAM wParam
234, WXLPARAM lParam
235)
d90895ac 236{
1f3154c8
DW
237 return wxWindow::OS2WindowProc( uMsg
238 ,wParam
239 ,lParam
240 );
241} // end of wxStaticText::OS2WindowProc