]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
Added style parameter to wxPopupWindow ctors so they match the Create method.
[wxWidgets.git] / src / os2 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: David Webster
5 // Modified by:
6 // Created: 09/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/event.h"
21 #include "wx/app.h"
22 #include "wx/dcclient.h"
23 #endif
24 #include "wx/os2/private.h"
25 #include "wx/control.h"
26
27 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
28
29 BEGIN_EVENT_TABLE(wxControl, wxWindow)
30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
31 END_EVENT_TABLE()
32
33 // Item members
34 wxControl::wxControl()
35 {
36 m_backgroundColour = *wxWHITE;
37 m_foregroundColour = *wxBLACK;
38
39 #if WXWIN_COMPATIBILITY
40 m_callback = 0;
41 #endif // WXWIN_COMPATIBILITY
42 } // end of wxControl::wxControl
43
44 bool wxControl::Create(
45 wxWindow* pParent
46 , wxWindowID vId
47 , const wxPoint& rPos
48 , const wxSize& rSize
49 , long lStyle
50 #if wxUSE_VALIDATORS
51 , const wxValidator& rValidator
52 #endif
53 , const wxString& rsName
54 )
55 {
56 bool bRval = wxWindow::Create( pParent
57 ,vId
58 ,rPos
59 ,rSize
60 ,lStyle
61 ,rsName
62 );
63 if (bRval)
64 {
65 #if wxUSE_VALIDATORS
66 SetValidator(rValidator);
67 #endif
68 }
69 return bRval;
70 } // end of wxControl::Create
71
72 wxControl::~wxControl()
73 {
74 m_isBeingDeleted = TRUE;
75 }
76
77 bool wxControl::OS2CreateControl(
78 const wxChar* zClassname
79 , WXDWORD dwStyle
80 , const wxPoint& rPos
81 , const wxSize& rSize
82 , const wxString& rsLabel
83 , WXDWORD dwExstyle
84 )
85 {
86 //
87 // Doesn't do anything at all under OS/2
88 //
89 if (dwExstyle == (WXDWORD)-1)
90 {
91 dwExstyle = GetExStyle(dwStyle);
92 }
93
94 if ( !m_hWnd )
95 {
96 #ifdef __WXDEBUG__
97 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
98 #endif // DEBUG
99
100 return FALSE;
101 }
102 dwStyle |= WS_VISIBLE;
103 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(GetParent()) // Parent window handle
104 ,(PSZ)zClassname // Window class
105 ,(PSZ)rsLabel.c_str() // Initial Text
106 ,(ULONG)dwStyle // Style flags
107 ,(LONG)rPos.x // X pos of origin
108 ,(LONG)rPos.y // Y pos of origin
109 ,(LONG)rSize.x // control width
110 ,(LONG)rSize.y // control height
111 ,(HWND)GetHwndOf(GetParent()) // owner window handle (same as parent
112 ,HWND_TOP // initial z position
113 ,(ULONG)GetId() // Window identifier
114 ,NULL // no control data
115 ,NULL // no Presentation parameters
116 );
117
118 //
119 // Subclass again for purposes of dialog editing mode
120 //
121 SubclassWin(m_hWnd);
122
123 //
124 // Controls use the same font and colours as their parent dialog by default
125 //
126 InheritAttributes();
127 return TRUE;
128 } // end of wxControl::OS2CreateControl
129
130 wxSize wxControl::DoGetBestSize() const
131 {
132 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
133 } // end of wxControl::DoGetBestSize
134
135 bool wxControl::ProcessCommand(wxCommandEvent& event)
136 {
137 #if WXWIN_COMPATIBILITY
138 if ( m_callback )
139 {
140 (void)(*m_callback)(this, event);
141
142 return TRUE;
143 }
144 else
145 #endif // WXWIN_COMPATIBILITY
146
147 return GetEventHandler()->ProcessEvent(event);
148 }
149
150 WXHBRUSH wxControl::OnCtlColor(
151 WXHDC hWxDC
152 , WXHWND hWnd
153 , WXUINT uCtlColor
154 , WXUINT uMessage
155 , WXWPARAM wParam
156 , WXLPARAM lParam
157 )
158 {
159 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
160 wxColour vColFore = GetForegroundColour();
161 wxColour vColBack = GetBackgroundColour();
162
163 if (GetParent()->GetTransparentBackground())
164 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
165 else
166 ::GpiSetBackMix(hPS, BM_OVERPAINT);
167
168 ::GpiSetBackColor(hPS, vColBack.GetPixel());
169 ::GpiSetColor(hPS, vColFore.GetPixel());
170
171 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
172 ,wxSOLID
173 );
174 return (WXHBRUSH)pBrush->GetResourceHandle();
175 } // end of wxControl::OnCtlColor
176
177 void wxControl::OnEraseBackground(
178 wxEraseEvent& rEvent
179 )
180 {
181 RECTL vRect;
182 HPS hPS = rEvent.GetDC()->GetHPS();
183 SIZEL vSize = {0,0};
184
185 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
186 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
187 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
188 } // end of wxControl::OnEraseBackground
189
190 WXDWORD wxControl::GetExStyle(
191 WXDWORD& rStyle
192 ) const
193 {
194 //
195 // Meaningless under OS/2, just return what was sent
196 //
197 WXDWORD exStyle = rStyle;
198
199 return exStyle;
200 } // end of wxControl::GetExStyle
201
202 // ---------------------------------------------------------------------------
203 // global functions
204 // ---------------------------------------------------------------------------
205
206 // Call this repeatedly for several wnds to find the overall size
207 // of the widget.
208 // Call it initially with -1 for all values in rect.
209 // Keep calling for other widgets, and rect will be modified
210 // to calculate largest bounding rectangle.
211 void wxFindMaxSize(
212 WXHWND hWnd
213 , RECT* pRect
214 )
215 {
216 int nLeft = pRect->xLeft;
217 int nRight = pRect->xRight;
218 int nTop = pRect->yTop;
219 int nBottom = pRect->yBottom;
220
221 ::WinQueryWindowRect((HWND)hWnd, pRect);
222
223 if (nLeft < 0)
224 return;
225
226 if (nLeft < pRect->xLeft)
227 pRect->xLeft = nLeft;
228
229 if (nRight > pRect->xRight)
230 pRect->xRight = nRight;
231
232 if (nTop < pRect->yTop)
233 pRect->yTop = nTop;
234
235 if (nBottom > pRect->yBottom)
236 pRect->yBottom = nBottom;
237 } // end of wxFindMaxSize
238
239