]>
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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/control.h"
19 #include "wx/dcclient.h"
20 #include "wx/scrolwin.h"
24 #include "wx/os2/dc.h"
25 #include "wx/os2/private.h"
27 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
29 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
34 wxControl::wxControl()
36 } // end of wxControl::wxControl
38 bool wxControl::Create( wxWindow
* pParent
,
43 const wxValidator
& rValidator
,
44 const wxString
& rsName
)
46 bool bRval
= wxWindow::Create( pParent
56 SetValidator(rValidator
);
60 } // end of wxControl::Create
62 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
63 const wxString
& rsLabel
,
69 WXDWORD dwStyle
= OS2GetStyle( lStyle
, &dwExstyle
);
71 return OS2CreateControl( zClassname
78 } // end of wxControl::OS2CreateControl
80 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
84 const wxString
& rsLabel
,
88 // Doesn't do anything at all under OS/2
90 if (dwExstyle
== (WXDWORD
)-1)
93 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
96 // All controls should have these styles (wxWidgets creates all controls
97 // visible by default)
100 dwStyle
|= WS_VISIBLE
;
102 wxWindow
* pParent
= GetParent();
108 if ((wxStrcmp(zClassname
, wxT("COMBOBOX"))) == 0)
109 zClass
= WC_COMBOBOX
;
110 else if ((wxStrcmp(zClassname
, wxT("STATIC"))) == 0)
112 else if ((wxStrcmp(zClassname
, wxT("BUTTON"))) == 0)
114 else if ((wxStrcmp(zClassname
, wxT("NOTEBOOK"))) == 0)
115 zClass
= WC_NOTEBOOK
;
116 else if ((wxStrcmp(zClassname
, wxT("CONTAINER"))) == 0)
117 zClass
= WC_CONTAINER
;
118 if ((zClass
== WC_STATIC
) || (zClass
== WC_BUTTON
))
119 dwStyle
|= DT_MNEMONIC
;
124 if (dwStyle
& DT_MNEMONIC
)
125 label
= ::wxPMTextToLabel(m_label
);
129 // clipping siblings does not yet work
130 dwStyle
&= ~WS_CLIPSIBLINGS
;
132 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
133 ,zClass
// Window class
134 ,label
.c_str() // Initial Text
135 ,(ULONG
)dwStyle
// Style flags
136 ,(LONG
)0 // X pos of origin
137 ,(LONG
)0 // Y pos of origin
138 ,(LONG
)0 // control width
139 ,(LONG
)0 // control height
140 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
141 ,HWND_TOP
// initial z position
142 ,(ULONG
)GetId() // Window identifier
143 ,NULL
// no control data
144 ,NULL
// no Presentation parameters
149 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname
);
154 // Subclass again for purposes of dialog editing mode
159 // Controls use the same colours as their parent dialog by default
163 // All OS/2 ctrls use the small font
165 SetFont(*wxSMALL_FONT
);
169 SetSize( rPos
.x
, rPos
.y
, rSize
.x
, rSize
.y
);
171 } // end of wxControl::OS2CreateControl
173 wxSize
wxControl::DoGetBestSize() const
175 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
176 } // end of wxControl::DoGetBestSize
178 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
180 return HandleWindowEvent(event
);
183 WXHBRUSH
wxControl::OnCtlColor(WXHDC hWxDC
,
184 WXHWND
WXUNUSED(hWnd
),
185 WXUINT
WXUNUSED(uCtlColor
),
186 WXUINT
WXUNUSED(uMessage
),
187 WXWPARAM
WXUNUSED(wParam
),
188 WXLPARAM
WXUNUSED(lParam
))
190 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
191 wxColour vColFore
= GetForegroundColour();
192 wxColour vColBack
= GetBackgroundColour();
194 if (GetParent()->GetTransparentBackground())
195 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
197 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
199 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
200 ::GpiSetColor(hPS
, vColFore
.GetPixel());
202 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
205 return (WXHBRUSH
)pBrush
->GetResourceHandle();
206 } // end of wxControl::OnCtlColor
208 void wxControl::OnEraseBackground( wxEraseEvent
& rEvent
)
211 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rEvent
.GetDC()->GetImpl();
212 HPS hPS
= impl
->GetHPS();
215 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
216 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
217 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
218 } // end of wxControl::OnEraseBackground
220 WXDWORD
wxControl::OS2GetStyle( long lStyle
, WXDWORD
* pdwExstyle
) const
222 long dwStyle
= wxWindow::OS2GetStyle( lStyle
, pdwExstyle
);
224 if (AcceptsFocusFromKeyboard())
226 dwStyle
|= WS_TABSTOP
;
229 } // end of wxControl::OS2GetStyle
231 void wxControl::SetLabel( const wxString
& rsLabel
)
233 if(rsLabel
!= m_label
)
237 if (m_dwStyle
& DT_MNEMONIC
)
238 label
= ::wxPMTextToLabel(m_label
);
241 ::WinSetWindowText(GetHwnd(), label
.c_str());
243 } // end of wxControl::SetLabel
245 // ---------------------------------------------------------------------------
247 // ---------------------------------------------------------------------------
249 // Call this repeatedly for several wnds to find the overall size
251 // Call it initially with -1 for all values in rect.
252 // Keep calling for other widgets, and rect will be modified
253 // to calculate largest bounding rectangle.
259 int nLeft
= pRect
->xLeft
;
260 int nRight
= pRect
->xRight
;
261 int nTop
= pRect
->yTop
;
262 int nBottom
= pRect
->yBottom
;
264 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
269 if (nLeft
< pRect
->xLeft
)
270 pRect
->xLeft
= nLeft
;
272 if (nRight
> pRect
->xRight
)
273 pRect
->xRight
= nRight
;
275 if (nTop
> pRect
->yTop
)
278 if (nBottom
< pRect
->yBottom
)
279 pRect
->yBottom
= nBottom
;
280 } // end of wxFindMaxSize