]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl class
4 // Author: David Webster
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "control.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
22 #include "wx/dcclient.h"
24 #include "wx/os2/private.h"
25 #include "wx/control.h"
27 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
29 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
34 wxControl::wxControl()
37 #if WXWIN_COMPATIBILITY
39 #endif // WXWIN_COMPATIBILITY
40 } // end of wxControl::wxControl
42 bool wxControl::Create(
49 , const wxValidator
& rValidator
51 , const wxString
& rsName
54 bool bRval
= wxWindow::Create( pParent
64 SetValidator(rValidator
);
68 } // end of wxControl::Create
70 wxControl::~wxControl()
72 m_isBeingDeleted
= TRUE
;
75 bool wxControl::OS2CreateControl(
82 , const wxValidator
& rValidator
84 , const wxString
& rsName
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
92 if (!CreateBase( pParent
103 pParent
->AddChild(this);
105 } // end of wxControl::OS2CreateControl
107 bool wxControl::OS2CreateControl(
108 const wxChar
* zClassname
110 , const wxPoint
& rPos
111 , const wxSize
& rSize
112 , const wxString
& rsLabel
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
;
121 // Doesn't do anything at all under OS/2
123 if (dwExstyle
== (WXDWORD
)-1)
125 dwExstyle
= GetExStyle(dwStyle
);
128 wxWindow
* pParent
= GetParent();
134 if ((strcmp(zClassname
, "COMBOBOX")) == 0)
135 zClass
= WC_COMBOBOX
;
136 else if ((strcmp(zClassname
, "STATIC")) == 0)
138 else if ((strcmp(zClassname
, "BUTTON")) == 0)
140 dwStyle
|= WS_VISIBLE
;
143 // If the parent is a scrolled window the controls must
144 // have this style or they will overlap the scrollbars
147 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
148 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
149 dwStyle
|= WS_CLIPSIBLINGS
;
151 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
152 ,(PSZ
)zClass
// Window class
153 ,(PSZ
)rsLabel
.c_str() // Initial Text
154 ,(ULONG
)dwStyle
// Style flags
155 ,(LONG
)0 // X pos of origin
156 ,(LONG
)0 // Y pos of origin
157 ,(LONG
)0 // control width
158 ,(LONG
)0 // control height
159 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
160 ,HWND_TOP
// initial z position
161 ,(ULONG
)GetId() // Window identifier
162 ,NULL
// no control data
163 ,NULL
// no Presentation parameters
169 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
175 // Subclass again for purposes of dialog editing mode
180 // Controls use the same font and colours as their parent dialog by default
183 if (nW
== 0 || nH
== 0)
186 } // end of wxControl::OS2CreateControl
188 wxSize
wxControl::DoGetBestSize() const
190 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
191 } // end of wxControl::DoGetBestSize
193 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
195 #if WXWIN_COMPATIBILITY
198 (void)(*m_callback
)(this, event
);
203 #endif // WXWIN_COMPATIBILITY
205 return GetEventHandler()->ProcessEvent(event
);
208 WXHBRUSH
wxControl::OnCtlColor(
217 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
218 wxColour vColFore
= GetForegroundColour();
219 wxColour vColBack
= GetBackgroundColour();
221 if (GetParent()->GetTransparentBackground())
222 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
224 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
226 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
227 ::GpiSetColor(hPS
, vColFore
.GetPixel());
229 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
232 return (WXHBRUSH
)pBrush
->GetResourceHandle();
233 } // end of wxControl::OnCtlColor
235 void wxControl::OnEraseBackground(
240 HPS hPS
= rEvent
.GetDC()->GetHPS();
243 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
244 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
245 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
246 } // end of wxControl::OnEraseBackground
248 WXDWORD
wxControl::GetExStyle(
253 // Meaningless under OS/2, just return what was sent
255 WXDWORD exStyle
= rStyle
;
258 } // end of wxControl::GetExStyle
260 // ---------------------------------------------------------------------------
262 // ---------------------------------------------------------------------------
264 // Call this repeatedly for several wnds to find the overall size
266 // Call it initially with -1 for all values in rect.
267 // Keep calling for other widgets, and rect will be modified
268 // to calculate largest bounding rectangle.
274 int nLeft
= pRect
->xLeft
;
275 int nRight
= pRect
->xRight
;
276 int nTop
= pRect
->yTop
;
277 int nBottom
= pRect
->yBottom
;
279 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
284 if (nLeft
< pRect
->xLeft
)
285 pRect
->xLeft
= nLeft
;
287 if (nRight
> pRect
->xRight
)
288 pRect
->xRight
= nRight
;
290 if (nTop
< pRect
->yTop
)
293 if (nBottom
> pRect
->yBottom
)
294 pRect
->yBottom
= nBottom
;
295 } // end of wxFindMaxSize