]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
removed zlib tests
[wxWidgets.git] / src / os2 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: David Webster
5 // Modified by:
6 // Created: 09/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.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/dcclient.h"
23 #include "wx/scrolwin.h"
24 #include "wx/log.h"
25 #endif
26 #include "wx/os2/private.h"
27 #include "wx/control.h"
28
29 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
30
31 BEGIN_EVENT_TABLE(wxControl, wxWindow)
32 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
33 END_EVENT_TABLE()
34
35 // Item members
36 wxControl::wxControl()
37 {
38 } // end of wxControl::wxControl
39
40 bool wxControl::Create(
41 wxWindow* pParent
42 , wxWindowID vId
43 , const wxPoint& rPos
44 , const wxSize& rSize
45 , long lStyle
46 , const wxValidator& rValidator
47 , const wxString& rsName
48 )
49 {
50 bool bRval = wxWindow::Create( pParent
51 ,vId
52 ,rPos
53 ,rSize
54 ,lStyle
55 ,rsName
56 );
57 if (bRval)
58 {
59 #if wxUSE_VALIDATORS
60 SetValidator(rValidator);
61 #endif
62 }
63 return bRval;
64 } // end of wxControl::Create
65
66 wxControl::~wxControl()
67 {
68 m_isBeingDeleted = TRUE;
69 }
70
71 bool wxControl::OS2CreateControl(
72 const wxChar* zClassname
73 , const wxString& rsLabel
74 , const wxPoint& rPos
75 , const wxSize& rSize
76 , long lStyle
77 )
78 {
79 WXDWORD dwExstyle;
80 WXDWORD dwStyle = OS2GetStyle( lStyle
81 ,&dwExstyle
82 );
83
84 return OS2CreateControl( zClassname
85 ,dwStyle
86 ,rPos
87 ,rSize
88 ,rsLabel
89 ,dwExstyle
90 );
91 } // end of wxControl::OS2CreateControl
92
93 bool wxControl::OS2CreateControl(
94 const wxChar* zClassname
95 , WXDWORD dwStyle
96 , const wxPoint& rPos
97 , const wxSize& rSize
98 , const wxString& rsLabel
99 , WXDWORD dwExstyle
100 )
101 {
102 //
103 // Doesn't do anything at all under OS/2
104 //
105 if (dwExstyle == (WXDWORD)-1)
106 {
107 dwExstyle = 0;
108 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle);
109 }
110 //
111 // All controls should have these styles (wxWindows creates all controls
112 // visible by default)
113 //
114 if (m_isShown )
115 dwStyle |= WS_VISIBLE;
116
117 wxWindow* pParent = GetParent();
118 PSZ zClass;
119
120 if (!pParent)
121 return FALSE;
122
123 if ((strcmp(zClassname, "COMBOBOX")) == 0)
124 zClass = WC_COMBOBOX;
125 else if ((strcmp(zClassname, "STATIC")) == 0)
126 zClass = WC_STATIC;
127 else if ((strcmp(zClassname, "BUTTON")) == 0)
128 zClass = WC_BUTTON;
129 else if ((strcmp(zClassname, "NOTEBOOK")) == 0)
130 zClass = WC_NOTEBOOK;
131 else if ((strcmp(zClassname, "CONTAINER")) == 0)
132 zClass = WC_CONTAINER;
133 dwStyle |= WS_VISIBLE;
134
135 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
136 ,(PSZ)zClass // Window class
137 ,(PSZ)rsLabel.c_str() // Initial Text
138 ,(ULONG)dwStyle // Style flags
139 ,(LONG)0 // X pos of origin
140 ,(LONG)0 // Y pos of origin
141 ,(LONG)0 // control width
142 ,(LONG)0 // control height
143 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
144 ,HWND_TOP // initial z position
145 ,(ULONG)GetId() // Window identifier
146 ,NULL // no control data
147 ,NULL // no Presentation parameters
148 );
149
150 if ( !m_hWnd )
151 {
152 #ifdef __WXDEBUG__
153 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
154 #endif // DEBUG
155
156 return FALSE;
157 }
158 //
159 // Subclass again for purposes of dialog editing mode
160 //
161 SubclassWin(m_hWnd);
162
163 //
164 // Controls use the same colours as their parent dialog by default
165 //
166 InheritAttributes();
167 //
168 // All OS/2 ctrls use the small font
169 //
170 SetFont(*wxSMALL_FONT);
171
172 SetXComp(0);
173 SetYComp(0);
174 SetSize( rPos.x
175 ,rPos.y
176 ,rSize.x
177 ,rSize.y
178 );
179 return TRUE;
180 } // end of wxControl::OS2CreateControl
181
182 wxSize wxControl::DoGetBestSize() const
183 {
184 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
185 } // end of wxControl::DoGetBestSize
186
187 bool wxControl::ProcessCommand(wxCommandEvent& event)
188 {
189 return GetEventHandler()->ProcessEvent(event);
190 }
191
192 WXHBRUSH wxControl::OnCtlColor(
193 WXHDC hWxDC
194 , WXHWND hWnd
195 , WXUINT uCtlColor
196 , WXUINT uMessage
197 , WXWPARAM wParam
198 , WXLPARAM lParam
199 )
200 {
201 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
202 wxColour vColFore = GetForegroundColour();
203 wxColour vColBack = GetBackgroundColour();
204
205 if (GetParent()->GetTransparentBackground())
206 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
207 else
208 ::GpiSetBackMix(hPS, BM_OVERPAINT);
209
210 ::GpiSetBackColor(hPS, vColBack.GetPixel());
211 ::GpiSetColor(hPS, vColFore.GetPixel());
212
213 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
214 ,wxSOLID
215 );
216 return (WXHBRUSH)pBrush->GetResourceHandle();
217 } // end of wxControl::OnCtlColor
218
219 void wxControl::OnEraseBackground(
220 wxEraseEvent& rEvent
221 )
222 {
223 RECTL vRect;
224 HPS hPS = rEvent.GetDC()->GetHPS();
225 SIZEL vSize = {0,0};
226
227 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
228 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
229 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
230 } // end of wxControl::OnEraseBackground
231
232 WXDWORD wxControl::OS2GetStyle(
233 long lStyle
234 , WXDWORD* pdwExstyle
235 ) const
236 {
237 long dwStyle = wxWindow::OS2GetStyle( lStyle
238 ,pdwExstyle
239 );
240
241 if (AcceptsFocus())
242 {
243 dwStyle |= WS_TABSTOP;
244 }
245 return dwStyle;
246 } // end of wxControl::OS2GetStyle
247
248 void wxControl::SetLabel(
249 const wxString& rsLabel
250 )
251 {
252 wxString sLabel = ::wxPMTextToLabel(rsLabel);
253
254 ::WinSetWindowText(GetHwnd(), sLabel.c_str());
255 } // end of wxControl::SetLabel
256
257 // ---------------------------------------------------------------------------
258 // global functions
259 // ---------------------------------------------------------------------------
260
261 // Call this repeatedly for several wnds to find the overall size
262 // of the widget.
263 // Call it initially with -1 for all values in rect.
264 // Keep calling for other widgets, and rect will be modified
265 // to calculate largest bounding rectangle.
266 void wxFindMaxSize(
267 WXHWND hWnd
268 , RECT* pRect
269 )
270 {
271 int nLeft = pRect->xLeft;
272 int nRight = pRect->xRight;
273 int nTop = pRect->yTop;
274 int nBottom = pRect->yBottom;
275
276 ::WinQueryWindowRect((HWND)hWnd, pRect);
277
278 if (nLeft < 0)
279 return;
280
281 if (nLeft < pRect->xLeft)
282 pRect->xLeft = nLeft;
283
284 if (nRight > pRect->xRight)
285 pRect->xRight = nRight;
286
287 if (nTop < pRect->yTop)
288 pRect->yTop = nTop;
289
290 if (nBottom > pRect->yBottom)
291 pRect->yBottom = nBottom;
292 } // end of wxFindMaxSize
293
294