]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/control.cpp
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( const wxChar
* zClassname
,
68 const wxString
& rsLabel
,
74 WXDWORD dwStyle
= OS2GetStyle( lStyle
, &dwExstyle
);
76 return OS2CreateControl( zClassname
83 } // end of wxControl::OS2CreateControl
85 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
89 const wxString
& rsLabel
,
93 // Doesn't do anything at all under OS/2
95 if (dwExstyle
== (WXDWORD
)-1)
98 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
101 // All controls should have these styles (wxWidgets creates all controls
102 // visible by default)
105 dwStyle
|= WS_VISIBLE
;
107 wxWindow
* pParent
= GetParent();
113 if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0)
114 zClass
= WC_COMBOBOX
;
115 else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0)
117 else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0)
119 else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0)
120 zClass
= WC_NOTEBOOK
;
121 else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0)
122 zClass
= WC_CONTAINER
;
123 if ((zClass
== WC_STATIC
) || (zClass
== WC_BUTTON
))
124 dwStyle
|= DT_MNEMONIC
;
129 if (dwStyle
& DT_MNEMONIC
)
130 label
= ::wxPMTextToLabel(m_label
);
134 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
135 ,(PSZ
)zClass
// Window class
136 ,(PSZ
)label
.c_str() // Initial Text
137 ,(ULONG
)dwStyle
// Style flags
138 ,(LONG
)0 // X pos of origin
139 ,(LONG
)0 // Y pos of origin
140 ,(LONG
)0 // control width
141 ,(LONG
)0 // control height
142 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
143 ,HWND_TOP
// initial z position
144 ,(ULONG
)GetId() // Window identifier
145 ,NULL
// no control data
146 ,NULL
// no Presentation parameters
152 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
158 // Subclass again for purposes of dialog editing mode
163 // Controls use the same colours as their parent dialog by default
167 // All OS/2 ctrls use the small font
169 SetFont(*wxSMALL_FONT
);
173 SetSize( rPos
.x
, rPos
.y
, rSize
.x
, rSize
.y
);
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(WXHDC hWxDC
,
188 WXHWND
WXUNUSED(hWnd
),
189 WXUINT
WXUNUSED(uCtlColor
),
190 WXUINT
WXUNUSED(uMessage
),
191 WXWPARAM
WXUNUSED(wParam
),
192 WXLPARAM
WXUNUSED(lParam
))
194 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
195 wxColour vColFore
= GetForegroundColour();
196 wxColour vColBack
= GetBackgroundColour();
198 if (GetParent()->GetTransparentBackground())
199 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
201 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
203 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
204 ::GpiSetColor(hPS
, vColFore
.GetPixel());
206 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
209 return (WXHBRUSH
)pBrush
->GetResourceHandle();
210 } // end of wxControl::OnCtlColor
212 void wxControl::OnEraseBackground( wxEraseEvent
& rEvent
)
215 HPS hPS
= rEvent
.GetDC()->GetHPS();
218 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
219 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
220 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
221 } // end of wxControl::OnEraseBackground
223 WXDWORD
wxControl::OS2GetStyle( long lStyle
, WXDWORD
* pdwExstyle
) const
225 long dwStyle
= wxWindow::OS2GetStyle( lStyle
, pdwExstyle
);
229 dwStyle
|= WS_TABSTOP
;
232 } // end of wxControl::OS2GetStyle
234 void wxControl::SetLabel( const wxString
& rsLabel
)
236 if(rsLabel
!= m_label
)
240 if (m_dwStyle
& DT_MNEMONIC
)
241 label
= ::wxPMTextToLabel(m_label
);
244 ::WinSetWindowText(GetHwnd(), (PSZ
)label
.c_str());
246 } // end of wxControl::SetLabel
248 // ---------------------------------------------------------------------------
250 // ---------------------------------------------------------------------------
252 // Call this repeatedly for several wnds to find the overall size
254 // Call it initially with -1 for all values in rect.
255 // Keep calling for other widgets, and rect will be modified
256 // to calculate largest bounding rectangle.
262 int nLeft
= pRect
->xLeft
;
263 int nRight
= pRect
->xRight
;
264 int nTop
= pRect
->yTop
;
265 int nBottom
= pRect
->yBottom
;
267 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
272 if (nLeft
< pRect
->xLeft
)
273 pRect
->xLeft
= nLeft
;
275 if (nRight
> pRect
->xRight
)
276 pRect
->xRight
= nRight
;
278 if (nTop
> pRect
->yTop
)
281 if (nBottom
< pRect
->yBottom
)
282 pRect
->yBottom
= nBottom
;
283 } // end of wxFindMaxSize