]>
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( const wxChar
* zClassname
,
97 const wxString
& rsLabel
,
101 // Doesn't do anything at all under OS/2
103 if (dwExstyle
== (WXDWORD
)-1)
106 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
109 // All controls should have these styles (wxWidgets creates all controls
110 // visible by default)
113 dwStyle
|= WS_VISIBLE
;
115 wxWindow
* pParent
= GetParent();
121 if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0)
122 zClass
= WC_COMBOBOX
;
123 else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0)
125 else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0)
127 else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0)
128 zClass
= WC_NOTEBOOK
;
129 else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0)
130 zClass
= WC_CONTAINER
;
131 dwStyle
|= WS_VISIBLE
;
133 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
135 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
136 ,(PSZ
)zClass
// Window class
137 ,(PSZ
)sLabel
.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 colours as their parent dialog by default
168 // All OS/2 ctrls use the small font
170 SetFont(*wxSMALL_FONT
);
180 } // end of wxControl::OS2CreateControl
182 wxSize
wxControl::DoGetBestSize() const
184 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
185 } // end of wxControl::DoGetBestSize
187 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
189 return GetEventHandler()->ProcessEvent(event
);
192 WXHBRUSH
wxControl::OnCtlColor(WXHDC hWxDC
,
193 WXHWND
WXUNUSED(hWnd
),
194 WXUINT
WXUNUSED(uCtlColor
),
195 WXUINT
WXUNUSED(uMessage
),
196 WXWPARAM
WXUNUSED(wParam
),
197 WXLPARAM
WXUNUSED(lParam
))
199 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
200 wxColour vColFore
= GetForegroundColour();
201 wxColour vColBack
= GetBackgroundColour();
203 if (GetParent()->GetTransparentBackground())
204 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
206 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
208 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
209 ::GpiSetColor(hPS
, vColFore
.GetPixel());
211 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
214 return (WXHBRUSH
)pBrush
->GetResourceHandle();
215 } // end of wxControl::OnCtlColor
217 void wxControl::OnEraseBackground(
222 HPS hPS
= rEvent
.GetDC()->GetHPS();
225 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
226 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
227 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
228 } // end of wxControl::OnEraseBackground
230 WXDWORD
wxControl::OS2GetStyle(
232 , WXDWORD
* pdwExstyle
235 long dwStyle
= wxWindow::OS2GetStyle( lStyle
241 dwStyle
|= WS_TABSTOP
;
244 } // end of wxControl::OS2GetStyle
246 void wxControl::SetLabel(
247 const wxString
& rsLabel
250 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
252 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
253 } // end of wxControl::SetLabel
255 // ---------------------------------------------------------------------------
257 // ---------------------------------------------------------------------------
259 // Call this repeatedly for several wnds to find the overall size
261 // Call it initially with -1 for all values in rect.
262 // Keep calling for other widgets, and rect will be modified
263 // to calculate largest bounding rectangle.
269 int nLeft
= pRect
->xLeft
;
270 int nRight
= pRect
->xRight
;
271 int nTop
= pRect
->yTop
;
272 int nBottom
= pRect
->yBottom
;
274 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
279 if (nLeft
< pRect
->xLeft
)
280 pRect
->xLeft
= nLeft
;
282 if (nRight
> pRect
->xRight
)
283 pRect
->xRight
= nRight
;
285 if (nTop
> pRect
->yTop
)
288 if (nBottom
< pRect
->yBottom
)
289 pRect
->yBottom
= nBottom
;
290 } // end of wxFindMaxSize