]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
(probably) fixed wxLocale::Init with Borland C++
[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"
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;
c9cb56f7 136 dwStyle |= WS_VISIBLE;
5d44b24e 137
5d44b24e
DW
138 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
139 ,(PSZ)zClass // Window class
140 ,(PSZ)rsLabel.c_str() // Initial Text
141 ,(ULONG)dwStyle // Style flags
142 ,(LONG)0 // X pos of origin
143 ,(LONG)0 // Y pos of origin
144 ,(LONG)0 // control width
145 ,(LONG)0 // control height
146 ,(HWND)GetHwndOf(pParent) // 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
c9cb56f7
DW
151 );
152
5d44b24e
DW
153 if ( !m_hWnd )
154 {
155#ifdef __WXDEBUG__
156 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
157#endif // DEBUG
158
159 return FALSE;
160 }
c9cb56f7
DW
161 //
162 // Subclass again for purposes of dialog editing mode
163 //
45fcbf3b
DW
164 SubclassWin(m_hWnd);
165
c9cb56f7
DW
166 //
167 // Controls use the same font and colours as their parent dialog by default
168 //
45fcbf3b 169 InheritAttributes();
70a2c656
DW
170 SetXComp(0);
171 SetYComp(0);
f289196b
DW
172 SetSize( rPos.x
173 ,rPos.y
174 ,rSize.x
175 ,rSize.y
176 );
45fcbf3b 177 return TRUE;
c9cb56f7 178} // end of wxControl::OS2CreateControl
0e320a79 179
e78c4d50 180wxSize wxControl::DoGetBestSize() const
0e320a79 181{
45fcbf3b 182 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 183} // end of wxControl::DoGetBestSize
0e320a79 184
45fcbf3b 185bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 186{
45fcbf3b
DW
187#if WXWIN_COMPATIBILITY
188 if ( m_callback )
0e320a79 189 {
45fcbf3b
DW
190 (void)(*m_callback)(this, event);
191
192 return TRUE;
0e320a79
DW
193 }
194 else
45fcbf3b
DW
195#endif // WXWIN_COMPATIBILITY
196
197 return GetEventHandler()->ProcessEvent(event);
198}
199
c9cb56f7
DW
200WXHBRUSH wxControl::OnCtlColor(
201 WXHDC hWxDC
202, WXHWND hWnd
203, WXUINT uCtlColor
204, WXUINT uMessage
205, WXWPARAM wParam
206, WXLPARAM lParam
207)
45fcbf3b 208{
c9cb56f7
DW
209 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
210 wxColour vColFore = GetForegroundColour();
211 wxColour vColBack = GetBackgroundColour();
45fcbf3b 212
c9cb56f7
DW
213 if (GetParent()->GetTransparentBackground())
214 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
215 else
216 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 217
c9cb56f7
DW
218 ::GpiSetBackColor(hPS, vColBack.GetPixel());
219 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 220
c9cb56f7
DW
221 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
222 ,wxSOLID
223 );
224 return (WXHBRUSH)pBrush->GetResourceHandle();
225} // end of wxControl::OnCtlColor
0e320a79 226
c9cb56f7
DW
227void wxControl::OnEraseBackground(
228 wxEraseEvent& rEvent
229)
45fcbf3b 230{
c9cb56f7
DW
231 RECTL vRect;
232 HPS hPS = rEvent.GetDC()->GetHPS();
233 SIZEL vSize = {0,0};
234
235 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
236 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
237 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
238} // end of wxControl::OnEraseBackground
239
b9b1d6c8
DW
240WXDWORD wxControl::OS2GetStyle(
241 long lStyle
242, WXDWORD* pdwExstyle
c9cb56f7 243) const
45fcbf3b 244{
b9b1d6c8
DW
245 long dwStyle = wxWindow::OS2GetStyle( lStyle
246 ,pdwExstyle
247 );
45fcbf3b 248
b9b1d6c8
DW
249 if (AcceptsFocus())
250 {
251 dwStyle |= WS_TABSTOP;
252 }
253 return dwStyle;
254} // end of wxControl::OS2GetStyle
45fcbf3b
DW
255
256// ---------------------------------------------------------------------------
257// global functions
258// ---------------------------------------------------------------------------
259
260// Call this repeatedly for several wnds to find the overall size
261// of the widget.
262// Call it initially with -1 for all values in rect.
263// Keep calling for other widgets, and rect will be modified
264// to calculate largest bounding rectangle.
c9cb56f7
DW
265void wxFindMaxSize(
266 WXHWND hWnd
267, RECT* pRect
268)
0e320a79 269{
c9cb56f7
DW
270 int nLeft = pRect->xLeft;
271 int nRight = pRect->xRight;
272 int nTop = pRect->yTop;
273 int nBottom = pRect->yBottom;
0e320a79 274
c9cb56f7 275 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 276
c9cb56f7 277 if (nLeft < 0)
45fcbf3b 278 return;
0e320a79 279
c9cb56f7
DW
280 if (nLeft < pRect->xLeft)
281 pRect->xLeft = nLeft;
0e320a79 282
c9cb56f7
DW
283 if (nRight > pRect->xRight)
284 pRect->xRight = nRight;
0e320a79 285
c9cb56f7
DW
286 if (nTop < pRect->yTop)
287 pRect->yTop = nTop;
288
289 if (nBottom > pRect->yBottom)
290 pRect->yBottom = nBottom;
291} // end of wxFindMaxSize
0e320a79 292
0e320a79 293