]>
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"
23 #include "wx/scrolwin.h"
25 #include "wx/os2/private.h"
26 #include "wx/control.h"
28 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
30 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
35 wxControl::wxControl()
38 #if WXWIN_COMPATIBILITY
40 #endif // WXWIN_COMPATIBILITY
41 } // end of wxControl::wxControl
43 bool wxControl::Create(
50 , const wxValidator
& rValidator
52 , const wxString
& rsName
55 bool bRval
= wxWindow::Create( pParent
65 SetValidator(rValidator
);
69 } // end of wxControl::Create
71 wxControl::~wxControl()
73 m_isBeingDeleted
= TRUE
;
76 bool wxControl::OS2CreateControl(
77 const wxChar
* zClassname
78 , const wxString
& rsLabel
85 WXDWORD dwStyle
= OS2GetStyle( lStyle
89 return OS2CreateControl( zClassname
96 } // end of wxControl::OS2CreateControl
98 bool wxControl::OS2CreateControl(
99 const wxChar
* zClassname
101 , const wxPoint
& rPos
102 , const wxSize
& rSize
103 , const wxString
& rsLabel
107 bool bWant3D
= FALSE
;
108 int nX
= rPos
.x
== -1 ? 0 : rPos
.x
;
109 int nY
= rPos
.y
== -1 ? 0 : rPos
.y
;
110 int nW
= rSize
.x
== -1 ? 0 : rSize
.x
;
111 int nH
= rSize
.y
== -1 ? 0 : rSize
.y
;
113 // Doesn't do anything at all under OS/2
115 if (dwExstyle
== (WXDWORD
)-1)
117 dwExstyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &bWant3D
);
120 // All controls should have these styles (wxWindows creates all controls
121 // visible by default)
123 dwStyle
|= WS_VISIBLE
;
125 wxWindow
* pParent
= GetParent();
131 if ((strcmp(zClassname
, "COMBOBOX")) == 0)
132 zClass
= WC_COMBOBOX
;
133 else if ((strcmp(zClassname
, "STATIC")) == 0)
135 else if ((strcmp(zClassname
, "BUTTON")) == 0)
137 dwStyle
|= WS_VISIBLE
;
139 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
140 ,(PSZ
)zClass
// Window class
141 ,(PSZ
)rsLabel
.c_str() // Initial Text
142 ,(ULONG
)dwStyle
// Style flags
143 ,(LONG
)0 // X pos of origin
144 ,(LONG
)0 // Y pos of origin
145 ,(LONG
)0 // control width
146 ,(LONG
)0 // control height
147 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
148 ,HWND_TOP
// initial z position
149 ,(ULONG
)GetId() // Window identifier
150 ,NULL
// no control data
151 ,NULL
// no Presentation parameters
157 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
163 // Subclass again for purposes of dialog editing mode
168 // Controls use the same font and colours as their parent dialog by default
173 if (nW
== 0 || nH
== 0)
176 } // end of wxControl::OS2CreateControl
178 wxSize
wxControl::DoGetBestSize() const
180 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
181 } // end of wxControl::DoGetBestSize
183 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
185 #if WXWIN_COMPATIBILITY
188 (void)(*m_callback
)(this, event
);
193 #endif // WXWIN_COMPATIBILITY
195 return GetEventHandler()->ProcessEvent(event
);
198 WXHBRUSH
wxControl::OnCtlColor(
207 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
208 wxColour vColFore
= GetForegroundColour();
209 wxColour vColBack
= GetBackgroundColour();
211 if (GetParent()->GetTransparentBackground())
212 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
214 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
216 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
217 ::GpiSetColor(hPS
, vColFore
.GetPixel());
219 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
222 return (WXHBRUSH
)pBrush
->GetResourceHandle();
223 } // end of wxControl::OnCtlColor
225 void wxControl::OnEraseBackground(
230 HPS hPS
= rEvent
.GetDC()->GetHPS();
233 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
234 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
235 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
236 } // end of wxControl::OnEraseBackground
238 WXDWORD
wxControl::OS2GetStyle(
240 , WXDWORD
* pdwExstyle
243 long dwStyle
= wxWindow::OS2GetStyle( lStyle
249 dwStyle
|= WS_TABSTOP
;
252 } // end of wxControl::OS2GetStyle
254 // ---------------------------------------------------------------------------
256 // ---------------------------------------------------------------------------
258 // Call this repeatedly for several wnds to find the overall size
260 // Call it initially with -1 for all values in rect.
261 // Keep calling for other widgets, and rect will be modified
262 // to calculate largest bounding rectangle.
268 int nLeft
= pRect
->xLeft
;
269 int nRight
= pRect
->xRight
;
270 int nTop
= pRect
->yTop
;
271 int nBottom
= pRect
->yBottom
;
273 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
278 if (nLeft
< pRect
->xLeft
)
279 pRect
->xLeft
= nLeft
;
281 if (nRight
> pRect
->xRight
)
282 pRect
->xRight
= nRight
;
284 if (nTop
< pRect
->yTop
)
287 if (nBottom
> pRect
->yBottom
)
288 pRect
->yBottom
= nBottom
;
289 } // end of wxFindMaxSize