]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
wxRichTextCtrl native caret now flashes, for wxMac/Core Graphics mode
[wxWidgets.git] / src / os2 / control.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
743e24aa 2// Name: src/os2/control.cpp
0e320a79 3// Purpose: wxControl class
45fcbf3b 4// Author: David Webster
0e320a79 5// Modified by:
45fcbf3b 6// Created: 09/17/99
0e320a79 7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
45fcbf3b
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
93fbbe07
WS
15#include "wx/control.h"
16
45fcbf3b 17#ifndef WX_PRECOMP
d5da0ce7
WS
18 #include "wx/event.h"
19 #include "wx/app.h"
20 #include "wx/dcclient.h"
21 #include "wx/scrolwin.h"
22 #include "wx/log.h"
45fcbf3b 23#endif
d5da0ce7 24
7c71eb6a 25#include "wx/os2/dc.h"
86de7616 26#include "wx/os2/private.h"
0e320a79 27
0e320a79
DW
28IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30BEGIN_EVENT_TABLE(wxControl, wxWindow)
45fcbf3b 31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
0e320a79 32END_EVENT_TABLE()
0e320a79
DW
33
34// Item members
35wxControl::wxControl()
36{
c9cb56f7
DW
37} // end of wxControl::wxControl
38
d5da0ce7
WS
39bool wxControl::Create( wxWindow* pParent,
40 wxWindowID vId,
41 const wxPoint& rPos,
42 const wxSize& rSize,
43 long lStyle,
44 const wxValidator& rValidator,
45 const wxString& rsName )
3d62dcb6 46{
c9cb56f7
DW
47 bool bRval = wxWindow::Create( pParent
48 ,vId
49 ,rPos
50 ,rSize
51 ,lStyle
52 ,rsName
53 );
54 if (bRval)
55 {
3d62dcb6 56#if wxUSE_VALIDATORS
c9cb56f7 57 SetValidator(rValidator);
3d62dcb6
DW
58#endif
59 }
c9cb56f7
DW
60 return bRval;
61} // end of wxControl::Create
3d62dcb6 62
743e24aa
WS
63bool wxControl::OS2CreateControl( const wxChar* zClassname,
64 const wxString& rsLabel,
65 const wxPoint& rPos,
66 const wxSize& rSize,
67 long lStyle )
0cf6acbf 68{
743e24aa
WS
69 WXDWORD dwExstyle;
70 WXDWORD dwStyle = OS2GetStyle( lStyle, &dwExstyle );
b9b1d6c8
DW
71
72 return OS2CreateControl( zClassname
73 ,dwStyle
74 ,rPos
75 ,rSize
76 ,rsLabel
77 ,dwExstyle
78 );
0cf6acbf
DW
79} // end of wxControl::OS2CreateControl
80
6670f564
WS
81bool wxControl::OS2CreateControl( const wxChar* zClassname,
82 WXDWORD dwStyle,
83 const wxPoint& rPos,
84 const wxSize& rSize,
85 const wxString& rsLabel,
86 WXDWORD dwExstyle )
0e320a79 87{
c9cb56f7
DW
88 //
89 // Doesn't do anything at all under OS/2
90 //
91 if (dwExstyle == (WXDWORD)-1)
3d62dcb6 92 {
0093fe11 93 dwExstyle = 0;
6670f564 94 (void) OS2GetStyle(GetWindowStyle(), &dwExstyle);
3d62dcb6 95 }
b9b1d6c8 96 //
77ffb593 97 // All controls should have these styles (wxWidgets creates all controls
b9b1d6c8
DW
98 // visible by default)
99 //
cfcebdb1
DW
100 if (m_isShown )
101 dwStyle |= WS_VISIBLE;
3d62dcb6 102
743e24aa
WS
103 wxWindow* pParent = GetParent();
104 PSZ zClass = "";
45fcbf3b 105
5d44b24e 106 if (!pParent)
743e24aa 107 return false;
0cf6acbf 108
0fba44b4 109 if ((wxStrcmp(zClassname, _T("COMBOBOX"))) == 0)
0cf6acbf 110 zClass = WC_COMBOBOX;
0fba44b4 111 else if ((wxStrcmp(zClassname, _T("STATIC"))) == 0)
3c299c3a 112 zClass = WC_STATIC;
0fba44b4 113 else if ((wxStrcmp(zClassname, _T("BUTTON"))) == 0)
1b086de1 114 zClass = WC_BUTTON;
0fba44b4 115 else if ((wxStrcmp(zClassname, _T("NOTEBOOK"))) == 0)
f289196b 116 zClass = WC_NOTEBOOK;
0fba44b4 117 else if ((wxStrcmp(zClassname, _T("CONTAINER"))) == 0)
4fd899b6 118 zClass = WC_CONTAINER;
37ac8a5f
SN
119 if ((zClass == WC_STATIC) || (zClass == WC_BUTTON))
120 dwStyle |= DT_MNEMONIC;
5d44b24e 121
37ac8a5f 122 m_dwStyle = dwStyle;
743e24aa 123 m_label = rsLabel;
37ac8a5f
SN
124 wxString label;
125 if (dwStyle & DT_MNEMONIC)
126 label = ::wxPMTextToLabel(m_label);
127 else
128 label = m_label;
e94d504d 129
2fbb8fbb
SN
130 // clipping siblings does not yet work
131 dwStyle &= ~WS_CLIPSIBLINGS;
132
5d44b24e 133 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
65f3f920
SN
134 ,zClass // Window class
135 ,label.c_str() // Initial Text
5d44b24e
DW
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
c9cb56f7
DW
146 );
147
5d44b24e
DW
148 if ( !m_hWnd )
149 {
5d44b24e 150 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
5d44b24e 151
743e24aa 152 return false;
5d44b24e 153 }
c9cb56f7
DW
154 //
155 // Subclass again for purposes of dialog editing mode
156 //
45fcbf3b
DW
157 SubclassWin(m_hWnd);
158
c9cb56f7 159 //
31d7fc0f 160 // Controls use the same colours as their parent dialog by default
c9cb56f7 161 //
45fcbf3b 162 InheritAttributes();
31d7fc0f
VZ
163 //
164 // All OS/2 ctrls use the small font
165 //
166 SetFont(*wxSMALL_FONT);
167
70a2c656
DW
168 SetXComp(0);
169 SetYComp(0);
743e24aa 170 SetSize( rPos.x, rPos.y, rSize.x, rSize.y );
6670f564 171 return true;
c9cb56f7 172} // end of wxControl::OS2CreateControl
0e320a79 173
e78c4d50 174wxSize wxControl::DoGetBestSize() const
0e320a79 175{
45fcbf3b 176 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 177} // end of wxControl::DoGetBestSize
0e320a79 178
45fcbf3b 179bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 180{
937013e0 181 return HandleWindowEvent(event);
45fcbf3b
DW
182}
183
6670f564
WS
184WXHBRUSH wxControl::OnCtlColor(WXHDC hWxDC,
185 WXHWND WXUNUSED(hWnd),
186 WXUINT WXUNUSED(uCtlColor),
187 WXUINT WXUNUSED(uMessage),
188 WXWPARAM WXUNUSED(wParam),
189 WXLPARAM WXUNUSED(lParam))
45fcbf3b 190{
6670f564
WS
191 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
192 wxColour vColFore = GetForegroundColour();
193 wxColour vColBack = GetBackgroundColour();
45fcbf3b 194
c9cb56f7
DW
195 if (GetParent()->GetTransparentBackground())
196 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
197 else
198 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 199
c9cb56f7
DW
200 ::GpiSetBackColor(hPS, vColBack.GetPixel());
201 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 202
6670f564
WS
203 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
204 ,wxSOLID
205 );
c9cb56f7
DW
206 return (WXHBRUSH)pBrush->GetResourceHandle();
207} // end of wxControl::OnCtlColor
0e320a79 208
743e24aa 209void wxControl::OnEraseBackground( wxEraseEvent& rEvent )
45fcbf3b 210{
c9cb56f7 211 RECTL vRect;
7c71eb6a
SN
212 wxPMDCImpl *impl = (wxPMDCImpl*) rEvent.GetDC()->GetImpl();
213 HPS hPS = impl->GetHPS();
c9cb56f7
DW
214 SIZEL vSize = {0,0};
215
216 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
217 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
218 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
219} // end of wxControl::OnEraseBackground
220
743e24aa 221WXDWORD wxControl::OS2GetStyle( long lStyle, WXDWORD* pdwExstyle ) const
45fcbf3b 222{
743e24aa 223 long dwStyle = wxWindow::OS2GetStyle( lStyle, pdwExstyle );
45fcbf3b 224
ad02525d 225 if (AcceptsFocusFromKeyboard())
b9b1d6c8
DW
226 {
227 dwStyle |= WS_TABSTOP;
228 }
229 return dwStyle;
230} // end of wxControl::OS2GetStyle
45fcbf3b 231
743e24aa 232void wxControl::SetLabel( const wxString& rsLabel )
d37bb826 233{
743e24aa
WS
234 if(rsLabel != m_label)
235 {
236 m_label = rsLabel;
37ac8a5f
SN
237 wxString label;
238 if (m_dwStyle & DT_MNEMONIC)
239 label = ::wxPMTextToLabel(m_label);
240 else
241 label = m_label;
65f3f920 242 ::WinSetWindowText(GetHwnd(), label.c_str());
743e24aa 243 }
d37bb826
SN
244} // end of wxControl::SetLabel
245
45fcbf3b
DW
246// ---------------------------------------------------------------------------
247// global functions
248// ---------------------------------------------------------------------------
249
250// Call this repeatedly for several wnds to find the overall size
251// of the widget.
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.
c9cb56f7
DW
255void wxFindMaxSize(
256 WXHWND hWnd
257, RECT* pRect
258)
0e320a79 259{
c9cb56f7
DW
260 int nLeft = pRect->xLeft;
261 int nRight = pRect->xRight;
262 int nTop = pRect->yTop;
263 int nBottom = pRect->yBottom;
0e320a79 264
c9cb56f7 265 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 266
c9cb56f7 267 if (nLeft < 0)
45fcbf3b 268 return;
0e320a79 269
c9cb56f7
DW
270 if (nLeft < pRect->xLeft)
271 pRect->xLeft = nLeft;
0e320a79 272
c9cb56f7
DW
273 if (nRight > pRect->xRight)
274 pRect->xRight = nRight;
0e320a79 275
09990d5a 276 if (nTop > pRect->yTop)
c9cb56f7
DW
277 pRect->yTop = nTop;
278
09990d5a 279 if (nBottom < pRect->yBottom)
c9cb56f7
DW
280 pRect->yBottom = nBottom;
281} // end of wxFindMaxSize