]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
fix typo in drawing slider ticks; added assert to check for it (slightly modified...
[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 #include "wx/scrolwin.h"
24 #include "wx/log.h"
25 #endif
26 #include "wx/os2/private.h"
27 #include "wx/control.h"
28
29 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
30
31 BEGIN_EVENT_TABLE(wxControl, wxWindow)
32 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
33 END_EVENT_TABLE()
34
35 // Item members
36 wxControl::wxControl()
37 {
38
39 #if WXWIN_COMPATIBILITY
40 m_callback = 0;
41 #endif // WXWIN_COMPATIBILITY
42 } // end of wxControl::wxControl
43
44 bool wxControl::Create(
45 wxWindow* pParent
46 , wxWindowID vId
47 , const wxPoint& rPos
48 , const wxSize& rSize
49 , long lStyle
50 #if wxUSE_VALIDATORS
51 , const wxValidator& rValidator
52 #endif
53 , const wxString& rsName
54 )
55 {
56 bool bRval = wxWindow::Create( pParent
57 ,vId
58 ,rPos
59 ,rSize
60 ,lStyle
61 ,rsName
62 );
63 if (bRval)
64 {
65 #if wxUSE_VALIDATORS
66 SetValidator(rValidator);
67 #endif
68 }
69 return bRval;
70 } // end of wxControl::Create
71
72 wxControl::~wxControl()
73 {
74 m_isBeingDeleted = TRUE;
75 }
76
77 bool wxControl::OS2CreateControl(
78 const wxChar* zClassname
79 , const wxString& rsLabel
80 , const wxPoint& rPos
81 , const wxSize& rSize
82 , long lStyle
83 )
84 {
85 WXDWORD dwExstyle;
86 WXDWORD dwStyle = OS2GetStyle( lStyle
87 ,&dwExstyle
88 );
89
90 return OS2CreateControl( zClassname
91 ,dwStyle
92 ,rPos
93 ,rSize
94 ,rsLabel
95 ,dwExstyle
96 );
97 } // end of wxControl::OS2CreateControl
98
99 bool wxControl::OS2CreateControl(
100 const wxChar* zClassname
101 , WXDWORD dwStyle
102 , const wxPoint& rPos
103 , const wxSize& rSize
104 , const wxString& rsLabel
105 , WXDWORD dwExstyle
106 )
107 {
108 bool bWant3D = FALSE;
109
110 //
111 // Doesn't do anything at all under OS/2
112 //
113 if (dwExstyle == (WXDWORD)-1)
114 {
115 dwExstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &bWant3D);
116 }
117 //
118 // All controls should have these styles (wxWindows creates all controls
119 // visible by default)
120 //
121 if (m_isShown )
122 dwStyle |= WS_VISIBLE;
123
124 wxWindow* pParent = GetParent();
125 PSZ zClass;
126
127 if (!pParent)
128 return FALSE;
129
130 if ((strcmp(zClassname, "COMBOBOX")) == 0)
131 zClass = WC_COMBOBOX;
132 else if ((strcmp(zClassname, "STATIC")) == 0)
133 zClass = WC_STATIC;
134 else if ((strcmp(zClassname, "BUTTON")) == 0)
135 zClass = WC_BUTTON;
136 else if ((strcmp(zClassname, "NOTEBOOK")) == 0)
137 zClass = WC_NOTEBOOK;
138 dwStyle |= WS_VISIBLE;
139
140 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
141 ,(PSZ)zClass // Window class
142 ,(PSZ)rsLabel.c_str() // Initial Text
143 ,(ULONG)dwStyle // Style flags
144 ,(LONG)0 // X pos of origin
145 ,(LONG)0 // Y pos of origin
146 ,(LONG)0 // control width
147 ,(LONG)0 // control height
148 ,(HWND)GetHwndOf(pParent) // 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 if ( !m_hWnd )
156 {
157 #ifdef __WXDEBUG__
158 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
159 #endif // DEBUG
160
161 return FALSE;
162 }
163 //
164 // Subclass again for purposes of dialog editing mode
165 //
166 SubclassWin(m_hWnd);
167
168 //
169 // Controls use the same font and colours as their parent dialog by default
170 //
171 InheritAttributes();
172 SetXComp(0);
173 SetYComp(0);
174 SetSize( rPos.x
175 ,rPos.y
176 ,rSize.x
177 ,rSize.y
178 );
179 return TRUE;
180 } // end of wxControl::OS2CreateControl
181
182 wxSize wxControl::DoGetBestSize() const
183 {
184 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
185 } // end of wxControl::DoGetBestSize
186
187 bool wxControl::ProcessCommand(wxCommandEvent& event)
188 {
189 #if WXWIN_COMPATIBILITY
190 if ( m_callback )
191 {
192 (void)(*m_callback)(this, event);
193
194 return TRUE;
195 }
196 else
197 #endif // WXWIN_COMPATIBILITY
198
199 return GetEventHandler()->ProcessEvent(event);
200 }
201
202 WXHBRUSH wxControl::OnCtlColor(
203 WXHDC hWxDC
204 , WXHWND hWnd
205 , WXUINT uCtlColor
206 , WXUINT uMessage
207 , WXWPARAM wParam
208 , WXLPARAM lParam
209 )
210 {
211 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
212 wxColour vColFore = GetForegroundColour();
213 wxColour vColBack = GetBackgroundColour();
214
215 if (GetParent()->GetTransparentBackground())
216 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
217 else
218 ::GpiSetBackMix(hPS, BM_OVERPAINT);
219
220 ::GpiSetBackColor(hPS, vColBack.GetPixel());
221 ::GpiSetColor(hPS, vColFore.GetPixel());
222
223 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
224 ,wxSOLID
225 );
226 return (WXHBRUSH)pBrush->GetResourceHandle();
227 } // end of wxControl::OnCtlColor
228
229 void wxControl::OnEraseBackground(
230 wxEraseEvent& rEvent
231 )
232 {
233 RECTL vRect;
234 HPS hPS = rEvent.GetDC()->GetHPS();
235 SIZEL vSize = {0,0};
236
237 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
238 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
239 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
240 } // end of wxControl::OnEraseBackground
241
242 WXDWORD wxControl::OS2GetStyle(
243 long lStyle
244 , WXDWORD* pdwExstyle
245 ) const
246 {
247 long dwStyle = wxWindow::OS2GetStyle( lStyle
248 ,pdwExstyle
249 );
250
251 if (AcceptsFocus())
252 {
253 dwStyle |= WS_TABSTOP;
254 }
255 return dwStyle;
256 } // end of wxControl::OS2GetStyle
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