]>
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"
15 #include "wx/control.h"
20 #include "wx/dcclient.h"
21 #include "wx/scrolwin.h"
25 #include "wx/os2/dc.h"
26 #include "wx/os2/private.h"
28 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
30 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
35 wxControl::wxControl()
37 } // end of wxControl::wxControl
39 bool wxControl::Create( wxWindow
* pParent
,
44 const wxValidator
& rValidator
,
45 const wxString
& rsName
)
47 bool bRval
= wxWindow::Create( pParent
57 SetValidator(rValidator
);
61 } // end of wxControl::Create
63 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
64 const wxString
& rsLabel
,
70 WXDWORD dwStyle
= OS2GetStyle( lStyle
, &dwExstyle
);
72 return OS2CreateControl( zClassname
79 } // end of wxControl::OS2CreateControl
81 bool wxControl::OS2CreateControl( const wxChar
* zClassname
,
85 const wxString
& rsLabel
,
89 // Doesn't do anything at all under OS/2
91 if (dwExstyle
== (WXDWORD
)-1)
94 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle
);
97 // All controls should have these styles (wxWidgets creates all controls
98 // visible by default)
101 dwStyle
|= WS_VISIBLE
;
103 wxWindow
* pParent
= GetParent();
109 if ((wxStrcmp(zClassname
, _T("COMBOBOX"))) == 0)
110 zClass
= WC_COMBOBOX
;
111 else if ((wxStrcmp(zClassname
, _T("STATIC"))) == 0)
113 else if ((wxStrcmp(zClassname
, _T("BUTTON"))) == 0)
115 else if ((wxStrcmp(zClassname
, _T("NOTEBOOK"))) == 0)
116 zClass
= WC_NOTEBOOK
;
117 else if ((wxStrcmp(zClassname
, _T("CONTAINER"))) == 0)
118 zClass
= WC_CONTAINER
;
119 if ((zClass
== WC_STATIC
) || (zClass
== WC_BUTTON
))
120 dwStyle
|= DT_MNEMONIC
;
125 if (dwStyle
& DT_MNEMONIC
)
126 label
= ::wxPMTextToLabel(m_label
);
130 // clipping siblings does not yet work
131 dwStyle
&= ~WS_CLIPSIBLINGS
;
133 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
134 ,zClass
// Window class
135 ,label
.c_str() // Initial Text
136 ,(ULONG
)dwStyle
// Style flags
137 ,(LONG
)0 // X pos of origin
138 ,(LONG
)0 // Y pos of origin
139 ,(LONG
)0 // control width
140 ,(LONG
)0 // control height
141 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
142 ,HWND_TOP
// initial z position
143 ,(ULONG
)GetId() // Window identifier
144 ,NULL
// no control data
145 ,NULL
// no Presentation parameters
150 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
);
170 SetSize( rPos
.x
, rPos
.y
, rSize
.x
, rSize
.y
);
172 } // end of wxControl::OS2CreateControl
174 wxSize
wxControl::DoGetBestSize() const
176 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
177 } // end of wxControl::DoGetBestSize
179 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
181 return HandleWindowEvent(event
);
184 WXHBRUSH
wxControl::OnCtlColor(WXHDC hWxDC
,
185 WXHWND
WXUNUSED(hWnd
),
186 WXUINT
WXUNUSED(uCtlColor
),
187 WXUINT
WXUNUSED(uMessage
),
188 WXWPARAM
WXUNUSED(wParam
),
189 WXLPARAM
WXUNUSED(lParam
))
191 HPS hPS
= (HPS
)hWxDC
; // pass in a PS handle in OS/2
192 wxColour vColFore
= GetForegroundColour();
193 wxColour vColBack
= GetBackgroundColour();
195 if (GetParent()->GetTransparentBackground())
196 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
198 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
200 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
201 ::GpiSetColor(hPS
, vColFore
.GetPixel());
203 wxBrush
* pBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
206 return (WXHBRUSH
)pBrush
->GetResourceHandle();
207 } // end of wxControl::OnCtlColor
209 void wxControl::OnEraseBackground( wxEraseEvent
& rEvent
)
212 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rEvent
.GetDC()->GetImpl();
213 HPS hPS
= impl
->GetHPS();
216 ::GpiSetPS(hPS
, &vSize
, PU_PELS
| GPIF_DEFAULT
);
217 ::WinQueryWindowRect((HWND
)GetHwnd(), &vRect
);
218 ::WinFillRect(hPS
, &vRect
, GetBackgroundColour().GetPixel());
219 } // end of wxControl::OnEraseBackground
221 WXDWORD
wxControl::OS2GetStyle( long lStyle
, WXDWORD
* pdwExstyle
) const
223 long dwStyle
= wxWindow::OS2GetStyle( lStyle
, pdwExstyle
);
225 if (AcceptsFocusFromKeyboard())
227 dwStyle
|= WS_TABSTOP
;
230 } // end of wxControl::OS2GetStyle
232 void wxControl::SetLabel( const wxString
& rsLabel
)
234 if(rsLabel
!= m_label
)
238 if (m_dwStyle
& DT_MNEMONIC
)
239 label
= ::wxPMTextToLabel(m_label
);
242 ::WinSetWindowText(GetHwnd(), label
.c_str());
244 } // end of wxControl::SetLabel
246 // ---------------------------------------------------------------------------
248 // ---------------------------------------------------------------------------
250 // Call this repeatedly for several wnds to find the overall size
252 // Call it initially with -1 for all values in rect.
253 // Keep calling for other widgets, and rect will be modified
254 // to calculate largest bounding rectangle.
260 int nLeft
= pRect
->xLeft
;
261 int nRight
= pRect
->xRight
;
262 int nTop
= pRect
->yTop
;
263 int nBottom
= pRect
->yBottom
;
265 ::WinQueryWindowRect((HWND
)hWnd
, pRect
);
270 if (nLeft
< pRect
->xLeft
)
271 pRect
->xLeft
= nLeft
;
273 if (nRight
> pRect
->xRight
)
274 pRect
->xRight
= nRight
;
276 if (nTop
> pRect
->yTop
)
279 if (nBottom
< pRect
->yBottom
)
280 pRect
->yBottom
= nBottom
;
281 } // end of wxFindMaxSize