]>
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 dwStyle
|= WS_VISIBLE
;
126 wxString label
= ::wxPMTextToLabel(m_label
);
128 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
129 ,(PSZ
)zClass
// Window class
130 ,(PSZ
)label
.c_str() // Initial Text
131 ,(ULONG
)dwStyle
// Style flags
132 ,(LONG
)0 // X pos of origin
133 ,(LONG
)0 // Y pos of origin
134 ,(LONG
)0 // control width
135 ,(LONG
)0 // control height
136 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
137 ,HWND_TOP
// initial z position
138 ,(ULONG
)GetId() // Window identifier
139 ,NULL
// no control data
140 ,NULL
// no Presentation parameters
146 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
152 // Subclass again for purposes of dialog editing mode
157 // Controls use the same colours as their parent dialog by default
161 // All OS/2 ctrls use the small font
163 SetFont(*wxSMALL_FONT
);
167 SetSize( rPos
.x
, rPos
.y
, rSize
.x
, rSize
.y
);
169 } // end of wxControl::OS2CreateControl
171 wxSize
wxControl::DoGetBestSize() const
173 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
174 } // end of wxControl::DoGetBestSize
176 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
178 return GetEventHandler()->ProcessEvent(event
);
181 WXHBRUSH
wxControl::OnCtlColor(WXHDC hWxDC
,
182 WXHWND
WXUNUSED(hWnd
),
183 WXUINT
WXUNUSED(uCtlColor
),
184 WXUINT
WXUNUSED(uMessage
),
185 WXWPARAM
WXUNUSED(wParam
),
186 WXLPARAM
WXUNUSED(lParam
))
188 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
189 wxColour vColFore
= GetForegroundColour();
190 wxColour vColBack
= GetBackgroundColour();
192 if (GetParent()->GetTransparentBackground())
193 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
195 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
197 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
198 ::GpiSetColor(hPS
, vColFore
.GetPixel());
200 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
203 return (WXHBRUSH
)pBrush
->GetResourceHandle();
204 } // end of wxControl::OnCtlColor
206 void wxControl::OnEraseBackground( wxEraseEvent
& rEvent
)
209 HPS hPS
= rEvent
.GetDC()->GetHPS();
212 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
213 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
214 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
215 } // end of wxControl::OnEraseBackground
217 WXDWORD
wxControl::OS2GetStyle( long lStyle
, WXDWORD
* pdwExstyle
) const
219 long dwStyle
= wxWindow::OS2GetStyle( lStyle
, pdwExstyle
);
223 dwStyle
|= WS_TABSTOP
;
226 } // end of wxControl::OS2GetStyle
228 void wxControl::SetLabel( const wxString
& rsLabel
)
230 if(rsLabel
!= m_label
)
233 wxString label
= ::wxPMTextToLabel(rsLabel
);
234 ::WinSetWindowText(GetHwnd(), (PSZ
)label
.c_str());
236 } // end of wxControl::SetLabel
238 // ---------------------------------------------------------------------------
240 // ---------------------------------------------------------------------------
242 // Call this repeatedly for several wnds to find the overall size
244 // Call it initially with -1 for all values in rect.
245 // Keep calling for other widgets, and rect will be modified
246 // to calculate largest bounding rectangle.
252 int nLeft
= pRect
->xLeft
;
253 int nRight
= pRect
->xRight
;
254 int nTop
= pRect
->yTop
;
255 int nBottom
= pRect
->yBottom
;
257 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
262 if (nLeft
< pRect
->xLeft
)
263 pRect
->xLeft
= nLeft
;
265 if (nRight
> pRect
->xRight
)
266 pRect
->xRight
= nRight
;
268 if (nTop
> pRect
->yTop
)
271 if (nBottom
< pRect
->yBottom
)
272 pRect
->yBottom
= nBottom
;
273 } // end of wxFindMaxSize