]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
some scrolling&refreshing fixed ; removed wxHtmlWindow::OnKeyDown
[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 }
43
44 bool wxControl::Create(wxWindow *parent, wxWindowID id,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 #if wxUSE_VALIDATORS
48 const wxValidator& validator,
49 #endif
50 const wxString& name)
51 {
52 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
53 if (rval) {
54 #if wxUSE_VALIDATORS
55 SetValidator(validator);
56 #endif
57 }
58 return rval;
59 }
60
61 wxControl::~wxControl()
62 {
63 m_isBeingDeleted = TRUE;
64 }
65
66 bool wxControl::OS2CreateControl(const wxChar *classname,
67 WXDWORD style,
68 const wxPoint& pos,
69 const wxSize& size,
70 const wxString& label,
71 WXDWORD exstyle)
72 {
73 // VZ: if someone could put a comment here explaining what exactly this is
74 // needed for, it would be nice...
75 bool want3D;
76
77 // if no extended style given, determine it ourselves
78 if ( exstyle == (WXDWORD)-1 )
79 {
80 exstyle = GetExStyle(style);
81 }
82
83 // TODO:
84 /*
85 // all controls have these childs (wxWindows creates all controls visible
86 // by default)
87 style |= WS_CHILD | WS_VISIBLE;
88
89 m_hWnd = (WXHWND)::CreateWindowEx
90 (
91 exstyle, // extended style
92 classname, // the kind of control to create
93 label, // the window name
94 style, // the window style
95 pos.x, pos.y, // the window position
96 size.x, size.y, // and size
97 GetHwndOf(GetParent()), // parent
98 (HMENU)GetId(), // child id
99 wxGetInstance(), // app instance
100 NULL // creation parameters
101 );
102
103 if ( !m_hWnd )
104 {
105 #ifdef __WXDEBUG__
106 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
107 #endif // DEBUG
108
109 return FALSE;
110 }
111
112 #if wxUSE_CTL3D
113 if ( want3D )
114 {
115 Ctl3dSubclassCtl(GetHwnd());
116 m_useCtl3D = TRUE;
117 }
118 #endif // wxUSE_CTL3D
119
120 // subclass again for purposes of dialog editing mode
121 SubclassWin(m_hWnd);
122
123 // controls use the same font and colours as their parent dialog by default
124 InheritAttributes();
125 */
126 return TRUE;
127 }
128
129 wxSize wxControl::DoGetBestSize() const
130 {
131 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
132 }
133
134 bool wxControl::ProcessCommand(wxCommandEvent& event)
135 {
136 #if WXWIN_COMPATIBILITY
137 if ( m_callback )
138 {
139 (void)(*m_callback)(this, event);
140
141 return TRUE;
142 }
143 else
144 #endif // WXWIN_COMPATIBILITY
145
146 return GetEventHandler()->ProcessEvent(event);
147 }
148
149 bool wxControl::OS2OnNotify(int idCtrl,
150 WXLPARAM lParam,
151 WXLPARAM* result)
152 {
153 wxCommandEvent event(wxEVT_NULL, m_windowId);
154 wxEventType eventType = wxEVT_NULL;
155 /* TODO:
156 NMHDR *hdr1 = (NMHDR*) lParam;
157 switch ( hdr1->code )
158 {
159 case NM_CLICK:
160 eventType = wxEVT_COMMAND_LEFT_CLICK;
161 break;
162
163 case NM_DBLCLK:
164 eventType = wxEVT_COMMAND_LEFT_DCLICK;
165 break;
166
167 case NM_RCLICK:
168 eventType = wxEVT_COMMAND_RIGHT_CLICK;
169 break;
170
171 case NM_RDBLCLK:
172 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
173 break;
174
175 case NM_SETFOCUS:
176 eventType = wxEVT_COMMAND_SET_FOCUS;
177 break;
178
179 case NM_KILLFOCUS:
180 eventType = wxEVT_COMMAND_KILL_FOCUS;
181 break;
182
183 case NM_RETURN:
184 eventType = wxEVT_COMMAND_ENTER;
185 break;
186
187 default:
188 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
189 }
190 */
191 event.SetEventType(eventType);
192 event.SetEventObject(this);
193
194 return GetEventHandler()->ProcessEvent(event);
195 }
196
197 void wxControl::OnEraseBackground(wxEraseEvent& event)
198 {
199 // In general, you don't want to erase the background of a control,
200 // or you'll get a flicker.
201 // TODO: move this 'null' function into each control that
202 // might flicker.
203
204 RECT rect;
205 /*
206 * below is msw code.
207 * TODO: convert to PM Code
208 * ::GetClientRect((HWND) GetHWND(), &rect);
209 *
210 * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
211 * GetBackgroundColour().Green(),
212 * GetBackgroundColour().Blue()));
213 * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
214 *
215 * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
216 * ::DeleteObject(hBrush);
217 * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
218 */
219 }
220
221 WXDWORD wxControl::GetExStyle(WXDWORD& style) const
222 {
223 bool want3D;
224 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
225
226 // Even with extended styles, need to combine with FS_BORDER
227 // for them to look right. Check it out later, base window style does
228 // not designate BORDERS. Down in Frame and And controls.
229
230 if ( want3D || wxStyleHasBorder(m_windowStyle) )
231 style |= FS_BORDER;
232
233 return exStyle;
234 }
235
236 // ---------------------------------------------------------------------------
237 // global functions
238 // ---------------------------------------------------------------------------
239
240 // Call this repeatedly for several wnds to find the overall size
241 // of the widget.
242 // Call it initially with -1 for all values in rect.
243 // Keep calling for other widgets, and rect will be modified
244 // to calculate largest bounding rectangle.
245 void wxFindMaxSize(WXHWND wnd, RECT *rect)
246 {
247 int left = rect->xLeft;
248 int right = rect->xRight;
249 int top = rect->yTop;
250 int bottom = rect->yBottom;
251
252 ::WinQueryWindowRect((HWND) wnd, rect);
253
254 if (left < 0)
255 return;
256
257 if (left < rect->xLeft)
258 rect->xLeft = left;
259
260 if (right > rect->xRight)
261 rect->xRight = right;
262
263 if (top < rect->yTop)
264 rect->yTop = top;
265
266 if (bottom > rect->yBottom)
267 rect->yBottom = bottom;
268 }
269