]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
added wxVScrolledWindow
[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
45fcbf3b 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{
45fcbf3b
DW
38
39#if WXWIN_COMPATIBILITY
40 m_callback = 0;
41#endif // WXWIN_COMPATIBILITY
c9cb56f7
DW
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
c9cb56f7 50, const wxValidator& rValidator
c9cb56f7
DW
51, const wxString& rsName
52)
3d62dcb6 53{
c9cb56f7
DW
54 bool bRval = wxWindow::Create( pParent
55 ,vId
56 ,rPos
57 ,rSize
58 ,lStyle
59 ,rsName
60 );
61 if (bRval)
62 {
3d62dcb6 63#if wxUSE_VALIDATORS
c9cb56f7 64 SetValidator(rValidator);
3d62dcb6
DW
65#endif
66 }
c9cb56f7
DW
67 return bRval;
68} // end of wxControl::Create
3d62dcb6 69
0e320a79
DW
70wxControl::~wxControl()
71{
45fcbf3b 72 m_isBeingDeleted = TRUE;
0e320a79
DW
73}
74
0cf6acbf 75bool wxControl::OS2CreateControl(
b9b1d6c8
DW
76 const wxChar* zClassname
77, const wxString& rsLabel
0cf6acbf
DW
78, const wxPoint& rPos
79, const wxSize& rSize
80, long lStyle
0cf6acbf
DW
81)
82{
b9b1d6c8
DW
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 );
0cf6acbf
DW
95} // end of wxControl::OS2CreateControl
96
c9cb56f7
DW
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)
0e320a79 105{
b9b1d6c8 106 bool bWant3D = FALSE;
f289196b 107
c9cb56f7
DW
108 //
109 // Doesn't do anything at all under OS/2
110 //
111 if (dwExstyle == (WXDWORD)-1)
3d62dcb6 112 {
b9b1d6c8 113 dwExstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &bWant3D);
3d62dcb6 114 }
b9b1d6c8
DW
115 //
116 // All controls should have these styles (wxWindows creates all controls
117 // visible by default)
118 //
cfcebdb1
DW
119 if (m_isShown )
120 dwStyle |= WS_VISIBLE;
3d62dcb6 121
5d44b24e
DW
122 wxWindow* pParent = GetParent();
123 PSZ zClass;
45fcbf3b 124
5d44b24e 125 if (!pParent)
45fcbf3b 126 return FALSE;
0cf6acbf
DW
127
128 if ((strcmp(zClassname, "COMBOBOX")) == 0)
129 zClass = WC_COMBOBOX;
3c299c3a
DW
130 else if ((strcmp(zClassname, "STATIC")) == 0)
131 zClass = WC_STATIC;
1b086de1
DW
132 else if ((strcmp(zClassname, "BUTTON")) == 0)
133 zClass = WC_BUTTON;
f289196b
DW
134 else if ((strcmp(zClassname, "NOTEBOOK")) == 0)
135 zClass = WC_NOTEBOOK;
4fd899b6
DW
136 else if ((strcmp(zClassname, "CONTAINER")) == 0)
137 zClass = WC_CONTAINER;
c9cb56f7 138 dwStyle |= WS_VISIBLE;
5d44b24e 139
5d44b24e
DW
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
c9cb56f7
DW
153 );
154
5d44b24e
DW
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 }
c9cb56f7
DW
163 //
164 // Subclass again for purposes of dialog editing mode
165 //
45fcbf3b
DW
166 SubclassWin(m_hWnd);
167
c9cb56f7
DW
168 //
169 // Controls use the same font and colours as their parent dialog by default
170 //
45fcbf3b 171 InheritAttributes();
70a2c656
DW
172 SetXComp(0);
173 SetYComp(0);
f289196b
DW
174 SetSize( rPos.x
175 ,rPos.y
176 ,rSize.x
177 ,rSize.y
178 );
45fcbf3b 179 return TRUE;
c9cb56f7 180} // end of wxControl::OS2CreateControl
0e320a79 181
e78c4d50 182wxSize wxControl::DoGetBestSize() const
0e320a79 183{
45fcbf3b 184 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 185} // end of wxControl::DoGetBestSize
0e320a79 186
45fcbf3b 187bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 188{
45fcbf3b
DW
189#if WXWIN_COMPATIBILITY
190 if ( m_callback )
0e320a79 191 {
45fcbf3b
DW
192 (void)(*m_callback)(this, event);
193
194 return TRUE;
0e320a79
DW
195 }
196 else
45fcbf3b
DW
197#endif // WXWIN_COMPATIBILITY
198
199 return GetEventHandler()->ProcessEvent(event);
200}
201
c9cb56f7
DW
202WXHBRUSH wxControl::OnCtlColor(
203 WXHDC hWxDC
204, WXHWND hWnd
205, WXUINT uCtlColor
206, WXUINT uMessage
207, WXWPARAM wParam
208, WXLPARAM lParam
209)
45fcbf3b 210{
c9cb56f7
DW
211 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
212 wxColour vColFore = GetForegroundColour();
213 wxColour vColBack = GetBackgroundColour();
45fcbf3b 214
c9cb56f7
DW
215 if (GetParent()->GetTransparentBackground())
216 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
217 else
218 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 219
c9cb56f7
DW
220 ::GpiSetBackColor(hPS, vColBack.GetPixel());
221 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 222
c9cb56f7
DW
223 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
224 ,wxSOLID
225 );
226 return (WXHBRUSH)pBrush->GetResourceHandle();
227} // end of wxControl::OnCtlColor
0e320a79 228
c9cb56f7
DW
229void wxControl::OnEraseBackground(
230 wxEraseEvent& rEvent
231)
45fcbf3b 232{
c9cb56f7
DW
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
b9b1d6c8
DW
242WXDWORD wxControl::OS2GetStyle(
243 long lStyle
244, WXDWORD* pdwExstyle
c9cb56f7 245) const
45fcbf3b 246{
b9b1d6c8
DW
247 long dwStyle = wxWindow::OS2GetStyle( lStyle
248 ,pdwExstyle
249 );
45fcbf3b 250
b9b1d6c8
DW
251 if (AcceptsFocus())
252 {
253 dwStyle |= WS_TABSTOP;
254 }
255 return dwStyle;
256} // end of wxControl::OS2GetStyle
45fcbf3b
DW
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.
c9cb56f7
DW
267void wxFindMaxSize(
268 WXHWND hWnd
269, RECT* pRect
270)
0e320a79 271{
c9cb56f7
DW
272 int nLeft = pRect->xLeft;
273 int nRight = pRect->xRight;
274 int nTop = pRect->yTop;
275 int nBottom = pRect->yBottom;
0e320a79 276
c9cb56f7 277 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 278
c9cb56f7 279 if (nLeft < 0)
45fcbf3b 280 return;
0e320a79 281
c9cb56f7
DW
282 if (nLeft < pRect->xLeft)
283 pRect->xLeft = nLeft;
0e320a79 284
c9cb56f7
DW
285 if (nRight > pRect->xRight)
286 pRect->xRight = nRight;
0e320a79 287
c9cb56f7
DW
288 if (nTop < pRect->yTop)
289 pRect->yTop = nTop;
290
291 if (nBottom > pRect->yBottom)
292 pRect->yBottom = nBottom;
293} // end of wxFindMaxSize
0e320a79 294
0e320a79 295