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