]>
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 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
18 #include "wx/dcclient.h"
19 #include "wx/scrolwin.h"
22 #include "wx/os2/private.h"
23 #include "wx/control.h"
25 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
27 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
28 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
32 wxControl::wxControl()
34 } // end of wxControl::wxControl
36 bool wxControl::Create(
42 , const wxValidator
& rValidator
43 , const wxString
& rsName
46 bool bRval
= wxWindow::Create( pParent
56 SetValidator(rValidator
);
60 } // end of wxControl::Create
62 wxControl::~wxControl()
64 m_isBeingDeleted
= true;
67 bool wxControl::OS2CreateControl(
68 const wxChar
* zClassname
69 , const wxString
& rsLabel
76 WXDWORD dwStyle
= OS2GetStyle( lStyle
80 return OS2CreateControl( zClassname
87 } // end of wxControl::OS2CreateControl
89 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
93 const wxString
& rsLabel
,
97 // Doesn't do anything at all under OS/2
99 if (dwExstyle
== (WXDWORD
)-1)
102 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
105 // All controls should have these styles (wxWidgets creates all controls
106 // visible by default)
109 dwStyle
|= WS_VISIBLE
;
111 wxWindow
* pParent
= GetParent();
117 if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0)
118 zClass
= WC_COMBOBOX
;
119 else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0)
121 else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0)
123 else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0)
124 zClass
= WC_NOTEBOOK
;
125 else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0)
126 zClass
= WC_CONTAINER
;
127 dwStyle
|= WS_VISIBLE
;
129 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
131 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
132 ,(PSZ
)zClass
// Window class
133 ,(PSZ
)sLabel
.c_str() // Initial Text
134 ,(ULONG
)dwStyle
// Style flags
135 ,(LONG
)0 // X pos of origin
136 ,(LONG
)0 // Y pos of origin
137 ,(LONG
)0 // control width
138 ,(LONG
)0 // control height
139 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
140 ,HWND_TOP
// initial z position
141 ,(ULONG
)GetId() // Window identifier
142 ,NULL
// no control data
143 ,NULL
// no Presentation parameters
149 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
155 // Subclass again for purposes of dialog editing mode
160 // Controls use the same colours as their parent dialog by default
164 // All OS/2 ctrls use the small font
166 SetFont(*wxSMALL_FONT
);
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 return GetEventHandler()->ProcessEvent(event
);
188 WXHBRUSH
wxControl::OnCtlColor(WXHDC hWxDC
,
189 WXHWND
WXUNUSED(hWnd
),
190 WXUINT
WXUNUSED(uCtlColor
),
191 WXUINT
WXUNUSED(uMessage
),
192 WXWPARAM
WXUNUSED(wParam
),
193 WXLPARAM
WXUNUSED(lParam
))
195 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
196 wxColour vColFore
= GetForegroundColour();
197 wxColour vColBack
= GetBackgroundColour();
199 if (GetParent()->GetTransparentBackground())
200 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
202 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
204 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
205 ::GpiSetColor(hPS
, vColFore
.GetPixel());
207 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
210 return (WXHBRUSH
)pBrush
->GetResourceHandle();
211 } // end of wxControl::OnCtlColor
213 void wxControl::OnEraseBackground(
218 HPS hPS
= rEvent
.GetDC()->GetHPS();
221 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
222 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
223 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
224 } // end of wxControl::OnEraseBackground
226 WXDWORD
wxControl::OS2GetStyle(
228 , WXDWORD
* pdwExstyle
231 long dwStyle
= wxWindow::OS2GetStyle( lStyle
237 dwStyle
|= WS_TABSTOP
;
240 } // end of wxControl::OS2GetStyle
242 void wxControl::SetLabel(
243 const wxString
& rsLabel
246 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
248 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
249 } // end of wxControl::SetLabel
251 // ---------------------------------------------------------------------------
253 // ---------------------------------------------------------------------------
255 // Call this repeatedly for several wnds to find the overall size
257 // Call it initially with -1 for all values in rect.
258 // Keep calling for other widgets, and rect will be modified
259 // to calculate largest bounding rectangle.
265 int nLeft
= pRect
->xLeft
;
266 int nRight
= pRect
->xRight
;
267 int nTop
= pRect
->yTop
;
268 int nBottom
= pRect
->yBottom
;
270 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
275 if (nLeft
< pRect
->xLeft
)
276 pRect
->xLeft
= nLeft
;
278 if (nRight
> pRect
->xRight
)
279 pRect
->xRight
= nRight
;
281 if (nTop
> pRect
->yTop
)
284 if (nBottom
< pRect
->yBottom
)
285 pRect
->yBottom
= nBottom
;
286 } // end of wxFindMaxSize