]>
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
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"
26 #include "wx/os2/private.h"
27 #include "wx/control.h"
29 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
31 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
32 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
36 wxControl::wxControl()
38 } // end of wxControl::wxControl
40 bool wxControl::Create(
46 , const wxValidator
& rValidator
47 , const wxString
& rsName
50 bool bRval
= wxWindow::Create( pParent
60 SetValidator(rValidator
);
64 } // end of wxControl::Create
66 wxControl::~wxControl()
68 m_isBeingDeleted
= TRUE
;
71 bool wxControl::OS2CreateControl(
72 const wxChar
* zClassname
73 , const wxString
& rsLabel
80 WXDWORD dwStyle
= OS2GetStyle( lStyle
84 return OS2CreateControl( zClassname
91 } // end of wxControl::OS2CreateControl
93 bool wxControl::OS2CreateControl(
94 const wxChar
* zClassname
98 , const wxString
& rsLabel
103 // Doesn't do anything at all under OS/2
105 if (dwExstyle
== (WXDWORD
)-1)
108 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
111 // All controls should have these styles (wxWidgets creates all controls
112 // visible by default)
115 dwStyle
|= WS_VISIBLE
;
117 wxWindow
* pParent
= GetParent();
123 if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0)
124 zClass
= WC_COMBOBOX
;
125 else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0)
127 else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0)
129 else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0)
130 zClass
= WC_NOTEBOOK
;
131 else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0)
132 zClass
= WC_CONTAINER
;
133 dwStyle
|= WS_VISIBLE
;
135 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
137 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
138 ,(PSZ
)zClass
// Window class
139 ,(PSZ
)sLabel
.c_str() // Initial Text
140 ,(ULONG
)dwStyle
// Style flags
141 ,(LONG
)0 // X pos of origin
142 ,(LONG
)0 // Y pos of origin
143 ,(LONG
)0 // control width
144 ,(LONG
)0 // control height
145 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
146 ,HWND_TOP
// initial z position
147 ,(ULONG
)GetId() // Window identifier
148 ,NULL
// no control data
149 ,NULL
// no Presentation parameters
155 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
161 // Subclass again for purposes of dialog editing mode
166 // Controls use the same colours as their parent dialog by default
170 // All OS/2 ctrls use the small font
172 SetFont(*wxSMALL_FONT
);
182 } // end of wxControl::OS2CreateControl
184 wxSize
wxControl::DoGetBestSize() const
186 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
187 } // end of wxControl::DoGetBestSize
189 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
191 return GetEventHandler()->ProcessEvent(event
);
194 WXHBRUSH
wxControl::OnCtlColor(
203 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
204 wxColour vColFore
= GetForegroundColour();
205 wxColour vColBack
= GetBackgroundColour();
207 if (GetParent()->GetTransparentBackground())
208 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
210 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
212 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
213 ::GpiSetColor(hPS
, vColFore
.GetPixel());
215 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
218 return (WXHBRUSH
)pBrush
->GetResourceHandle();
219 } // end of wxControl::OnCtlColor
221 void wxControl::OnEraseBackground(
226 HPS hPS
= rEvent
.GetDC()->GetHPS();
229 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
230 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
231 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
232 } // end of wxControl::OnEraseBackground
234 WXDWORD
wxControl::OS2GetStyle(
236 , WXDWORD
* pdwExstyle
239 long dwStyle
= wxWindow::OS2GetStyle( lStyle
245 dwStyle
|= WS_TABSTOP
;
248 } // end of wxControl::OS2GetStyle
250 void wxControl::SetLabel(
251 const wxString
& rsLabel
254 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
256 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
257 } // end of wxControl::SetLabel
259 // ---------------------------------------------------------------------------
261 // ---------------------------------------------------------------------------
263 // Call this repeatedly for several wnds to find the overall size
265 // Call it initially with -1 for all values in rect.
266 // Keep calling for other widgets, and rect will be modified
267 // to calculate largest bounding rectangle.
273 int nLeft
= pRect
->xLeft
;
274 int nRight
= pRect
->xRight
;
275 int nTop
= pRect
->yTop
;
276 int nBottom
= pRect
->yBottom
;
278 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
283 if (nLeft
< pRect
->xLeft
)
284 pRect
->xLeft
= nLeft
;
286 if (nRight
> pRect
->xRight
)
287 pRect
->xRight
= nRight
;
289 if (nTop
> pRect
->yTop
)
292 if (nBottom
< pRect
->yBottom
)
293 pRect
->yBottom
= nBottom
;
294 } // end of wxFindMaxSize