]>
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 dwStyle
|= WS_VISIBLE
;
141 // If the parent is a scrolled window the controls must
142 // have this style or they will overlap the scrollbars
145 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
146 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
147 dwStyle
|= WS_CLIPSIBLINGS
;
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
167 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
173 // Subclass again for purposes of dialog editing mode
178 // Controls use the same font and colours as their parent dialog by default
181 if (nW
== 0 || nH
== 0)
184 } // end of wxControl::OS2CreateControl
186 wxSize
wxControl::DoGetBestSize() const
188 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
189 } // end of wxControl::DoGetBestSize
191 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
193 #if WXWIN_COMPATIBILITY
196 (void)(*m_callback
)(this, event
);
201 #endif // WXWIN_COMPATIBILITY
203 return GetEventHandler()->ProcessEvent(event
);
206 WXHBRUSH
wxControl::OnCtlColor(
215 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
216 wxColour vColFore
= GetForegroundColour();
217 wxColour vColBack
= GetBackgroundColour();
219 if (GetParent()->GetTransparentBackground())
220 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
222 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
224 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
225 ::GpiSetColor(hPS
, vColFore
.GetPixel());
227 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
230 return (WXHBRUSH
)pBrush
->GetResourceHandle();
231 } // end of wxControl::OnCtlColor
233 void wxControl::OnEraseBackground(
238 HPS hPS
= rEvent
.GetDC()->GetHPS();
241 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
242 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
243 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
244 } // end of wxControl::OnEraseBackground
246 WXDWORD
wxControl::GetExStyle(
251 // Meaningless under OS/2, just return what was sent
253 WXDWORD exStyle
= rStyle
;
256 } // end of wxControl::GetExStyle
258 // ---------------------------------------------------------------------------
260 // ---------------------------------------------------------------------------
262 // Call this repeatedly for several wnds to find the overall size
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.
272 int nLeft
= pRect
->xLeft
;
273 int nRight
= pRect
->xRight
;
274 int nTop
= pRect
->yTop
;
275 int nBottom
= pRect
->yBottom
;
277 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
282 if (nLeft
< pRect
->xLeft
)
283 pRect
->xLeft
= nLeft
;
285 if (nRight
> pRect
->xRight
)
286 pRect
->xRight
= nRight
;
288 if (nTop
< pRect
->yTop
)
291 if (nBottom
> pRect
->yBottom
)
292 pRect
->yBottom
= nBottom
;
293 } // end of wxFindMaxSize