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