]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
backported crash fix for wxFrame::Iconize() from 2.2
[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 m_backgroundColour = *wxWHITE;
37 m_foregroundColour = *wxBLACK;
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
3d62dcb6 50#if wxUSE_VALIDATORS
c9cb56f7 51, const wxValidator& rValidator
3d62dcb6 52#endif
c9cb56f7
DW
53, const wxString& rsName
54)
3d62dcb6 55{
c9cb56f7
DW
56 bool bRval = wxWindow::Create( pParent
57 ,vId
58 ,rPos
59 ,rSize
60 ,lStyle
61 ,rsName
62 );
63 if (bRval)
64 {
3d62dcb6 65#if wxUSE_VALIDATORS
c9cb56f7 66 SetValidator(rValidator);
3d62dcb6
DW
67#endif
68 }
c9cb56f7
DW
69 return bRval;
70} // end of wxControl::Create
3d62dcb6 71
0e320a79
DW
72wxControl::~wxControl()
73{
45fcbf3b 74 m_isBeingDeleted = TRUE;
0e320a79
DW
75}
76
c9cb56f7
DW
77bool wxControl::OS2CreateControl(
78 const wxChar* zClassname
79, WXDWORD dwStyle
80, const wxPoint& rPos
81, const wxSize& rSize
82, const wxString& rsLabel
83, WXDWORD dwExstyle
84)
0e320a79 85{
c9cb56f7
DW
86 //
87 // Doesn't do anything at all under OS/2
88 //
89 if (dwExstyle == (WXDWORD)-1)
3d62dcb6 90 {
c9cb56f7 91 dwExstyle = GetExStyle(dwStyle);
3d62dcb6
DW
92 }
93
45fcbf3b
DW
94 if ( !m_hWnd )
95 {
96#ifdef __WXDEBUG__
c9cb56f7 97 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
45fcbf3b
DW
98#endif // DEBUG
99
100 return FALSE;
101 }
c9cb56f7
DW
102 dwStyle |= WS_VISIBLE;
103 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(GetParent()) // Parent window handle
104 ,(PSZ)zClassname // Window class
105 ,(PSZ)rsLabel.c_str() // Initial Text
106 ,(ULONG)dwStyle // Style flags
107 ,(LONG)rPos.x // X pos of origin
108 ,(LONG)rPos.y // Y pos of origin
109 ,(LONG)rSize.x // control width
110 ,(LONG)rSize.y // control height
111 ,(HWND)GetHwndOf(GetParent()) // owner window handle (same as parent
112 ,HWND_TOP // initial z position
113 ,(ULONG)GetId() // Window identifier
114 ,NULL // no control data
115 ,NULL // no Presentation parameters
116 );
117
118 //
119 // Subclass again for purposes of dialog editing mode
120 //
45fcbf3b
DW
121 SubclassWin(m_hWnd);
122
c9cb56f7
DW
123 //
124 // Controls use the same font and colours as their parent dialog by default
125 //
45fcbf3b 126 InheritAttributes();
45fcbf3b 127 return TRUE;
c9cb56f7 128} // end of wxControl::OS2CreateControl
0e320a79 129
e78c4d50 130wxSize wxControl::DoGetBestSize() const
0e320a79 131{
45fcbf3b 132 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 133} // end of wxControl::DoGetBestSize
0e320a79 134
45fcbf3b 135bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 136{
45fcbf3b
DW
137#if WXWIN_COMPATIBILITY
138 if ( m_callback )
0e320a79 139 {
45fcbf3b
DW
140 (void)(*m_callback)(this, event);
141
142 return TRUE;
0e320a79
DW
143 }
144 else
45fcbf3b
DW
145#endif // WXWIN_COMPATIBILITY
146
147 return GetEventHandler()->ProcessEvent(event);
148}
149
c9cb56f7
DW
150WXHBRUSH wxControl::OnCtlColor(
151 WXHDC hWxDC
152, WXHWND hWnd
153, WXUINT uCtlColor
154, WXUINT uMessage
155, WXWPARAM wParam
156, WXLPARAM lParam
157)
45fcbf3b 158{
c9cb56f7
DW
159 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
160 wxColour vColFore = GetForegroundColour();
161 wxColour vColBack = GetBackgroundColour();
45fcbf3b 162
c9cb56f7
DW
163 if (GetParent()->GetTransparentBackground())
164 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
165 else
166 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 167
c9cb56f7
DW
168 ::GpiSetBackColor(hPS, vColBack.GetPixel());
169 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 170
c9cb56f7
DW
171 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
172 ,wxSOLID
173 );
174 return (WXHBRUSH)pBrush->GetResourceHandle();
175} // end of wxControl::OnCtlColor
0e320a79 176
c9cb56f7
DW
177void wxControl::OnEraseBackground(
178 wxEraseEvent& rEvent
179)
45fcbf3b 180{
c9cb56f7
DW
181 RECTL vRect;
182 HPS hPS = rEvent.GetDC()->GetHPS();
183 SIZEL vSize = {0,0};
184
185 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
186 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
187 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
188} // end of wxControl::OnEraseBackground
189
190WXDWORD wxControl::GetExStyle(
191 WXDWORD& rStyle
192) const
45fcbf3b 193{
c9cb56f7
DW
194 //
195 // Meaningless under OS/2, just return what was sent
196 //
197 WXDWORD exStyle = rStyle;
45fcbf3b
DW
198
199 return exStyle;
c9cb56f7 200} // end of wxControl::GetExStyle
45fcbf3b
DW
201
202// ---------------------------------------------------------------------------
203// global functions
204// ---------------------------------------------------------------------------
205
206// Call this repeatedly for several wnds to find the overall size
207// of the widget.
208// Call it initially with -1 for all values in rect.
209// Keep calling for other widgets, and rect will be modified
210// to calculate largest bounding rectangle.
c9cb56f7
DW
211void wxFindMaxSize(
212 WXHWND hWnd
213, RECT* pRect
214)
0e320a79 215{
c9cb56f7
DW
216 int nLeft = pRect->xLeft;
217 int nRight = pRect->xRight;
218 int nTop = pRect->yTop;
219 int nBottom = pRect->yBottom;
0e320a79 220
c9cb56f7 221 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 222
c9cb56f7 223 if (nLeft < 0)
45fcbf3b 224 return;
0e320a79 225
c9cb56f7
DW
226 if (nLeft < pRect->xLeft)
227 pRect->xLeft = nLeft;
0e320a79 228
c9cb56f7
DW
229 if (nRight > pRect->xRight)
230 pRect->xRight = nRight;
0e320a79 231
c9cb56f7
DW
232 if (nTop < pRect->yTop)
233 pRect->yTop = nTop;
234
235 if (nBottom > pRect->yBottom)
236 pRect->yBottom = nBottom;
237} // end of wxFindMaxSize
0e320a79 238
0e320a79 239