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