]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
another segfault fix
[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$
45fcbf3b
DW
8// Copyright: (c) Julian Smart and Markus Holzem
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"
23#endif
86de7616 24#include "wx/os2/private.h"
0e320a79
DW
25#include "wx/control.h"
26
0e320a79
DW
27IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
28
29BEGIN_EVENT_TABLE(wxControl, wxWindow)
45fcbf3b 30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
0e320a79 31END_EVENT_TABLE()
0e320a79
DW
32
33// Item members
34wxControl::wxControl()
35{
45fcbf3b
DW
36
37#if WXWIN_COMPATIBILITY
38 m_callback = 0;
39#endif // WXWIN_COMPATIBILITY
c9cb56f7
DW
40} // end of wxControl::wxControl
41
42bool wxControl::Create(
43 wxWindow* pParent
44, wxWindowID vId
45, const wxPoint& rPos
46, const wxSize& rSize
47, long lStyle
3d62dcb6 48#if wxUSE_VALIDATORS
c9cb56f7 49, const wxValidator& rValidator
3d62dcb6 50#endif
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
DW
75bool wxControl::OS2CreateControl(
76 wxWindow* pParent
77, wxWindowID vId
78, const wxPoint& rPos
79, const wxSize& rSize
80, long lStyle
81#if wxUSE_VALIDATORS
82, const wxValidator& rValidator
83#endif
84, const wxString& rsName
85)
86{
87 //
88 // Even if it's possible to create controls without parents in some port,
89 // it should surely be discouraged because it doesn't work at all under
90 // Windows
91 //
92 if (!CreateBase( pParent
93 ,vId
94 ,rPos
95 ,rSize
96 ,lStyle
97#if wxUSE_VALIDATORS
98 ,rValidator
99#endif
100 ,rsName
101 ))
102 return FALSE;
103 pParent->AddChild(this);
104 return TRUE;
105} // end of wxControl::OS2CreateControl
106
c9cb56f7
DW
107bool wxControl::OS2CreateControl(
108 const wxChar* zClassname
109, WXDWORD dwStyle
110, const wxPoint& rPos
111, const wxSize& rSize
112, const wxString& rsLabel
113, WXDWORD dwExstyle
114)
0e320a79 115{
c9cb56f7
DW
116 //
117 // Doesn't do anything at all under OS/2
118 //
119 if (dwExstyle == (WXDWORD)-1)
3d62dcb6 120 {
c9cb56f7 121 dwExstyle = GetExStyle(dwStyle);
3d62dcb6
DW
122 }
123
45fcbf3b
DW
124 if ( !m_hWnd )
125 {
126#ifdef __WXDEBUG__
c9cb56f7 127 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
45fcbf3b
DW
128#endif // DEBUG
129
130 return FALSE;
131 }
0cf6acbf
DW
132
133 PSZ zClass;
134
135 if ((strcmp(zClassname, "COMBOBOX")) == 0)
136 zClass = WC_COMBOBOX;
c9cb56f7
DW
137 dwStyle |= WS_VISIBLE;
138 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(GetParent()) // Parent window handle
139 ,(PSZ)zClassname // Window class
140 ,(PSZ)rsLabel.c_str() // Initial Text
141 ,(ULONG)dwStyle // Style flags
142 ,(LONG)rPos.x // X pos of origin
143 ,(LONG)rPos.y // Y pos of origin
144 ,(LONG)rSize.x // control width
145 ,(LONG)rSize.y // control height
146 ,(HWND)GetHwndOf(GetParent()) // owner window handle (same as parent
147 ,HWND_TOP // initial z position
148 ,(ULONG)GetId() // Window identifier
149 ,NULL // no control data
150 ,NULL // no Presentation parameters
151 );
152
153 //
154 // Subclass again for purposes of dialog editing mode
155 //
45fcbf3b
DW
156 SubclassWin(m_hWnd);
157
c9cb56f7
DW
158 //
159 // Controls use the same font and colours as their parent dialog by default
160 //
45fcbf3b 161 InheritAttributes();
45fcbf3b 162 return TRUE;
c9cb56f7 163} // end of wxControl::OS2CreateControl
0e320a79 164
e78c4d50 165wxSize wxControl::DoGetBestSize() const
0e320a79 166{
45fcbf3b 167 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 168} // end of wxControl::DoGetBestSize
0e320a79 169
45fcbf3b 170bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 171{
45fcbf3b
DW
172#if WXWIN_COMPATIBILITY
173 if ( m_callback )
0e320a79 174 {
45fcbf3b
DW
175 (void)(*m_callback)(this, event);
176
177 return TRUE;
0e320a79
DW
178 }
179 else
45fcbf3b
DW
180#endif // WXWIN_COMPATIBILITY
181
182 return GetEventHandler()->ProcessEvent(event);
183}
184
c9cb56f7
DW
185WXHBRUSH wxControl::OnCtlColor(
186 WXHDC hWxDC
187, WXHWND hWnd
188, WXUINT uCtlColor
189, WXUINT uMessage
190, WXWPARAM wParam
191, WXLPARAM lParam
192)
45fcbf3b 193{
c9cb56f7
DW
194 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
195 wxColour vColFore = GetForegroundColour();
196 wxColour vColBack = GetBackgroundColour();
45fcbf3b 197
c9cb56f7
DW
198 if (GetParent()->GetTransparentBackground())
199 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
200 else
201 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 202
c9cb56f7
DW
203 ::GpiSetBackColor(hPS, vColBack.GetPixel());
204 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 205
c9cb56f7
DW
206 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
207 ,wxSOLID
208 );
209 return (WXHBRUSH)pBrush->GetResourceHandle();
210} // end of wxControl::OnCtlColor
0e320a79 211
c9cb56f7
DW
212void wxControl::OnEraseBackground(
213 wxEraseEvent& rEvent
214)
45fcbf3b 215{
c9cb56f7
DW
216 RECTL vRect;
217 HPS hPS = rEvent.GetDC()->GetHPS();
218 SIZEL vSize = {0,0};
219
220 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
221 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
222 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
223} // end of wxControl::OnEraseBackground
224
225WXDWORD wxControl::GetExStyle(
226 WXDWORD& rStyle
227) const
45fcbf3b 228{
c9cb56f7
DW
229 //
230 // Meaningless under OS/2, just return what was sent
231 //
232 WXDWORD exStyle = rStyle;
45fcbf3b
DW
233
234 return exStyle;
c9cb56f7 235} // end of wxControl::GetExStyle
45fcbf3b
DW
236
237// ---------------------------------------------------------------------------
238// global functions
239// ---------------------------------------------------------------------------
240
241// Call this repeatedly for several wnds to find the overall size
242// of the widget.
243// Call it initially with -1 for all values in rect.
244// Keep calling for other widgets, and rect will be modified
245// to calculate largest bounding rectangle.
c9cb56f7
DW
246void wxFindMaxSize(
247 WXHWND hWnd
248, RECT* pRect
249)
0e320a79 250{
c9cb56f7
DW
251 int nLeft = pRect->xLeft;
252 int nRight = pRect->xRight;
253 int nTop = pRect->yTop;
254 int nBottom = pRect->yBottom;
0e320a79 255
c9cb56f7 256 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 257
c9cb56f7 258 if (nLeft < 0)
45fcbf3b 259 return;
0e320a79 260
c9cb56f7
DW
261 if (nLeft < pRect->xLeft)
262 pRect->xLeft = nLeft;
0e320a79 263
c9cb56f7
DW
264 if (nRight > pRect->xRight)
265 pRect->xRight = nRight;
0e320a79 266
c9cb56f7
DW
267 if (nTop < pRect->yTop)
268 pRect->yTop = nTop;
269
270 if (nBottom > pRect->yBottom)
271 pRect->yBottom = nBottom;
272} // end of wxFindMaxSize
0e320a79 273
0e320a79 274