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