]>
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
171 if (nW
== 0 || nH
== 0)
174 } // end of wxControl::OS2CreateControl
176 wxSize
wxControl::DoGetBestSize() const
178 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
179 } // end of wxControl::DoGetBestSize
181 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
183 #if WXWIN_COMPATIBILITY
186 (void)(*m_callback
)(this, event
);
191 #endif // WXWIN_COMPATIBILITY
193 return GetEventHandler()->ProcessEvent(event
);
196 WXHBRUSH
wxControl::OnCtlColor(
205 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
206 wxColour vColFore
= GetForegroundColour();
207 wxColour vColBack
= GetBackgroundColour();
209 if (GetParent()->GetTransparentBackground())
210 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
212 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
214 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
215 ::GpiSetColor(hPS
, vColFore
.GetPixel());
217 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
220 return (WXHBRUSH
)pBrush
->GetResourceHandle();
221 } // end of wxControl::OnCtlColor
223 void wxControl::OnEraseBackground(
228 HPS hPS
= rEvent
.GetDC()->GetHPS();
231 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
232 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
233 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
234 } // end of wxControl::OnEraseBackground
236 WXDWORD
wxControl::OS2GetStyle(
238 , WXDWORD
* pdwExstyle
241 long dwStyle
= wxWindow::OS2GetStyle( lStyle
247 dwStyle
|= WS_TABSTOP
;
250 } // end of wxControl::OS2GetStyle
252 // ---------------------------------------------------------------------------
254 // ---------------------------------------------------------------------------
256 // Call this repeatedly for several wnds to find the overall size
258 // Call it initially with -1 for all values in rect.
259 // Keep calling for other widgets, and rect will be modified
260 // to calculate largest bounding rectangle.
266 int nLeft
= pRect
->xLeft
;
267 int nRight
= pRect
->xRight
;
268 int nTop
= pRect
->yTop
;
269 int nBottom
= pRect
->yBottom
;
271 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
276 if (nLeft
< pRect
->xLeft
)
277 pRect
->xLeft
= nLeft
;
279 if (nRight
> pRect
->xRight
)
280 pRect
->xRight
= nRight
;
282 if (nTop
< pRect
->yTop
)
285 if (nBottom
> pRect
->yBottom
)
286 pRect
->yBottom
= nBottom
;
287 } // end of wxFindMaxSize