]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
use the new wxSystemSettings API everywhere
[wxWidgets.git] / src / os2 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: David Webster
5 // Modified by:
6 // Created: 09/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
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
24 #include "wx/os2/private.h"
25 #include "wx/control.h"
26
27 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
28
29 BEGIN_EVENT_TABLE(wxControl, wxWindow)
30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
31 END_EVENT_TABLE()
32
33 // Item members
34 wxControl::wxControl()
35 {
36
37 #if WXWIN_COMPATIBILITY
38 m_callback = 0;
39 #endif // WXWIN_COMPATIBILITY
40 } // end of wxControl::wxControl
41
42 bool wxControl::Create(
43 wxWindow* pParent
44 , wxWindowID vId
45 , const wxPoint& rPos
46 , const wxSize& rSize
47 , long lStyle
48 #if wxUSE_VALIDATORS
49 , const wxValidator& rValidator
50 #endif
51 , const wxString& rsName
52 )
53 {
54 bool bRval = wxWindow::Create( pParent
55 ,vId
56 ,rPos
57 ,rSize
58 ,lStyle
59 ,rsName
60 );
61 if (bRval)
62 {
63 #if wxUSE_VALIDATORS
64 SetValidator(rValidator);
65 #endif
66 }
67 return bRval;
68 } // end of wxControl::Create
69
70 wxControl::~wxControl()
71 {
72 m_isBeingDeleted = TRUE;
73 }
74
75 bool 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
107 bool 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 )
115 {
116 int nX = rPos.x == -1 ? 0 : rPos.x;
117 int nY = rPos.y == -1 ? 0 : rPos.y;
118 int nW = rSize.x == -1 ? 0 : rSize.x;
119 int nH = rSize.y == -1 ? 0 : rSize.y;
120 //
121 // Doesn't do anything at all under OS/2
122 //
123 if (dwExstyle == (WXDWORD)-1)
124 {
125 dwExstyle = GetExStyle(dwStyle);
126 }
127
128 wxWindow* pParent = GetParent();
129 PSZ zClass;
130
131 if (!pParent)
132 return FALSE;
133
134 if ((strcmp(zClassname, "COMBOBOX")) == 0)
135 zClass = WC_COMBOBOX;
136 else if ((strcmp(zClassname, "STATIC")) == 0)
137 zClass = WC_STATIC;
138 dwStyle |= WS_VISIBLE;
139
140 //
141 // If the parent is a scrolled window the controls must
142 // have this style or they will overlap the scrollbars
143 //
144 if (pParent)
145 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
146 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
147 dwStyle |= WS_CLIPSIBLINGS;
148
149 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
150 ,(PSZ)zClass // Window class
151 ,(PSZ)rsLabel.c_str() // Initial Text
152 ,(ULONG)dwStyle // Style flags
153 ,(LONG)0 // X pos of origin
154 ,(LONG)0 // Y pos of origin
155 ,(LONG)0 // control width
156 ,(LONG)0 // control height
157 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
158 ,HWND_TOP // initial z position
159 ,(ULONG)GetId() // Window identifier
160 ,NULL // no control data
161 ,NULL // no Presentation parameters
162 );
163
164 if ( !m_hWnd )
165 {
166 #ifdef __WXDEBUG__
167 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
168 #endif // DEBUG
169
170 return FALSE;
171 }
172 //
173 // Subclass again for purposes of dialog editing mode
174 //
175 SubclassWin(m_hWnd);
176
177 //
178 // Controls use the same font and colours as their parent dialog by default
179 //
180 InheritAttributes();
181 if (nW == 0 || nH == 0)
182 SetBestSize(rSize);
183 return TRUE;
184 } // end of wxControl::OS2CreateControl
185
186 wxSize wxControl::DoGetBestSize() const
187 {
188 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
189 } // end of wxControl::DoGetBestSize
190
191 bool wxControl::ProcessCommand(wxCommandEvent& event)
192 {
193 #if WXWIN_COMPATIBILITY
194 if ( m_callback )
195 {
196 (void)(*m_callback)(this, event);
197
198 return TRUE;
199 }
200 else
201 #endif // WXWIN_COMPATIBILITY
202
203 return GetEventHandler()->ProcessEvent(event);
204 }
205
206 WXHBRUSH wxControl::OnCtlColor(
207 WXHDC hWxDC
208 , WXHWND hWnd
209 , WXUINT uCtlColor
210 , WXUINT uMessage
211 , WXWPARAM wParam
212 , WXLPARAM lParam
213 )
214 {
215 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
216 wxColour vColFore = GetForegroundColour();
217 wxColour vColBack = GetBackgroundColour();
218
219 if (GetParent()->GetTransparentBackground())
220 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
221 else
222 ::GpiSetBackMix(hPS, BM_OVERPAINT);
223
224 ::GpiSetBackColor(hPS, vColBack.GetPixel());
225 ::GpiSetColor(hPS, vColFore.GetPixel());
226
227 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
228 ,wxSOLID
229 );
230 return (WXHBRUSH)pBrush->GetResourceHandle();
231 } // end of wxControl::OnCtlColor
232
233 void wxControl::OnEraseBackground(
234 wxEraseEvent& rEvent
235 )
236 {
237 RECTL vRect;
238 HPS hPS = rEvent.GetDC()->GetHPS();
239 SIZEL vSize = {0,0};
240
241 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
242 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
243 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
244 } // end of wxControl::OnEraseBackground
245
246 WXDWORD wxControl::GetExStyle(
247 WXDWORD& rStyle
248 ) const
249 {
250 //
251 // Meaningless under OS/2, just return what was sent
252 //
253 WXDWORD exStyle = rStyle;
254
255 return exStyle;
256 } // end of wxControl::GetExStyle
257
258 // ---------------------------------------------------------------------------
259 // global functions
260 // ---------------------------------------------------------------------------
261
262 // Call this repeatedly for several wnds to find the overall size
263 // of the widget.
264 // Call it initially with -1 for all values in rect.
265 // Keep calling for other widgets, and rect will be modified
266 // to calculate largest bounding rectangle.
267 void wxFindMaxSize(
268 WXHWND hWnd
269 , RECT* pRect
270 )
271 {
272 int nLeft = pRect->xLeft;
273 int nRight = pRect->xRight;
274 int nTop = pRect->yTop;
275 int nBottom = pRect->yBottom;
276
277 ::WinQueryWindowRect((HWND)hWnd, pRect);
278
279 if (nLeft < 0)
280 return;
281
282 if (nLeft < pRect->xLeft)
283 pRect->xLeft = nLeft;
284
285 if (nRight > pRect->xRight)
286 pRect->xRight = nRight;
287
288 if (nTop < pRect->yTop)
289 pRect->yTop = nTop;
290
291 if (nBottom > pRect->yBottom)
292 pRect->yBottom = nBottom;
293 } // end of wxFindMaxSize
294
295