]>
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 (wxWindows creates all controls
112 // visible by default)
115 dwStyle
|= WS_VISIBLE
;
117 wxWindow
* pParent
= GetParent();
123 if ((strcmp(zClassname
, "COMBOBOX")) == 0)
124 zClass
= WC_COMBOBOX
;
125 else if ((strcmp(zClassname
, "STATIC")) == 0)
127 else if ((strcmp(zClassname
, "BUTTON")) == 0)
129 else if ((strcmp(zClassname
, "NOTEBOOK")) == 0)
130 zClass
= WC_NOTEBOOK
;
131 else if ((strcmp(zClassname
, "CONTAINER")) == 0)
132 zClass
= WC_CONTAINER
;
133 dwStyle
|= WS_VISIBLE
;
135 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
136 ,(PSZ
)zClass
// Window class
137 ,(PSZ
)rsLabel
.c_str() // Initial Text
138 ,(ULONG
)dwStyle
// Style flags
139 ,(LONG
)0 // X pos of origin
140 ,(LONG
)0 // Y pos of origin
141 ,(LONG
)0 // control width
142 ,(LONG
)0 // control height
143 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
144 ,HWND_TOP
// initial z position
145 ,(ULONG
)GetId() // Window identifier
146 ,NULL
// no control data
147 ,NULL
// no Presentation parameters
153 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
159 // Subclass again for purposes of dialog editing mode
164 // Controls use the same font and colours as their parent dialog by default
175 } // end of wxControl::OS2CreateControl
177 wxSize
wxControl::DoGetBestSize() const
179 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
180 } // end of wxControl::DoGetBestSize
182 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
184 return GetEventHandler()->ProcessEvent(event
);
187 WXHBRUSH
wxControl::OnCtlColor(
196 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
197 wxColour vColFore
= GetForegroundColour();
198 wxColour vColBack
= GetBackgroundColour();
200 if (GetParent()->GetTransparentBackground())
201 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
203 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
205 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
206 ::GpiSetColor(hPS
, vColFore
.GetPixel());
208 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
211 return (WXHBRUSH
)pBrush
->GetResourceHandle();
212 } // end of wxControl::OnCtlColor
214 void wxControl::OnEraseBackground(
219 HPS hPS
= rEvent
.GetDC()->GetHPS();
222 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
223 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
224 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
225 } // end of wxControl::OnEraseBackground
227 WXDWORD
wxControl::OS2GetStyle(
229 , WXDWORD
* pdwExstyle
232 long dwStyle
= wxWindow::OS2GetStyle( lStyle
238 dwStyle
|= WS_TABSTOP
;
241 } // end of wxControl::OS2GetStyle
243 void wxControl::SetLabel(
244 const wxString
& rsLabel
247 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
249 ::WinSetWindowText(GetHwnd(), sLabel
.c_str());
250 } // end of wxControl::SetLabel
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