]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindow | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
a3622daa | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
09914df7 | 20 | #pragma hdrstop |
2bda0e17 KB |
21 | #endif |
22 | ||
23 | #ifndef WX_PRECOMP | |
3a19e16d VZ |
24 | #include "wx/setup.h" |
25 | #include "wx/menu.h" | |
26 | #include "wx/dc.h" | |
27 | #include "wx/dcclient.h" | |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/panel.h" | |
31 | #include "wx/layout.h" | |
32 | #include "wx/dialog.h" | |
33 | #include "wx/frame.h" | |
34 | #include "wx/listbox.h" | |
35 | #include "wx/button.h" | |
36 | #include "wx/settings.h" | |
37 | #include "wx/msgdlg.h" | |
341c92a8 VZ |
38 | |
39 | #include <stdio.h> | |
2bda0e17 KB |
40 | #endif |
41 | ||
47d67540 | 42 | #if wxUSE_OWNER_DRAWN |
09914df7 | 43 | #include "wx/ownerdrw.h" |
2bda0e17 KB |
44 | #endif |
45 | ||
47d67540 | 46 | #if wxUSE_DRAG_AND_DROP |
09914df7 | 47 | #include "wx/msw/ole/droptgt.h" |
2bda0e17 KB |
48 | #endif |
49 | ||
50 | #include "wx/menuitem.h" | |
47cbd6da | 51 | #include "wx/log.h" |
3a19e16d VZ |
52 | #include "wx/tooltip.h" |
53 | ||
2bda0e17 KB |
54 | #include "wx/msw/private.h" |
55 | ||
56 | #include <string.h> | |
57 | ||
58 | #ifndef __GNUWIN32__ | |
3a19e16d VZ |
59 | #include <shellapi.h> |
60 | #include <mmsystem.h> | |
2bda0e17 KB |
61 | #endif |
62 | ||
63 | #ifdef __WIN32__ | |
3a19e16d | 64 | #include <windowsx.h> |
2bda0e17 KB |
65 | #endif |
66 | ||
acbd13a3 | 67 | #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) |
3a19e16d | 68 | #include <commctrl.h> |
acbd13a3 | 69 | #endif |
3a19e16d | 70 | |
57c208c5 | 71 | #ifndef __TWIN32__ |
3a19e16d VZ |
72 | #ifdef __GNUWIN32__ |
73 | #include <wx/msw/gnuwin32/extra.h> | |
74 | #endif | |
57c208c5 | 75 | #endif |
2bda0e17 | 76 | |
3a19e16d | 77 | // all these are defined in <windows.h> |
2bda0e17 KB |
78 | #ifdef GetCharWidth |
79 | #undef GetCharWidth | |
80 | #endif | |
81 | ||
82 | #ifdef FindWindow | |
83 | #undef FindWindow | |
84 | #endif | |
85 | ||
86 | #ifdef GetClassName | |
87 | #undef GetClassName | |
88 | #endif | |
89 | ||
90 | #ifdef GetClassInfo | |
91 | #undef GetClassInfo | |
92 | #endif | |
93 | ||
b2aef89b | 94 | #ifdef __WXDEBUG__ |
09914df7 | 95 | const char *wxGetMessageName(int message); |
ea57084d | 96 | #endif //__WXDEBUG__ |
47cbd6da | 97 | |
f54f3bff | 98 | #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events |
2bda0e17 KB |
99 | |
100 | wxMenu *wxCurrentPopupMenu = NULL; | |
cde9f08e | 101 | extern wxList WXDLLEXPORT wxPendingDelete; |
2bda0e17 KB |
102 | |
103 | void wxRemoveHandleAssociation(wxWindow *win); | |
104 | void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win); | |
105 | wxWindow *wxFindWinFromHandle(WXHWND hWnd); | |
106 | ||
107 | #if !USE_SHARED_LIBRARY | |
3a19e16d | 108 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) |
cf65ad8d | 109 | #endif |
2bda0e17 KB |
110 | |
111 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
cf65ad8d VZ |
112 | EVT_CHAR(wxWindow::OnChar) |
113 | EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) | |
114 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) | |
115 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
116 | EVT_IDLE(wxWindow::OnIdle) | |
2bda0e17 KB |
117 | END_EVENT_TABLE() |
118 | ||
2bda0e17 | 119 | // Find an item given the MS Windows id |
debe6624 | 120 | wxWindow *wxWindow::FindItem(int id) const |
2bda0e17 | 121 | { |
c0ed460c JS |
122 | // if (!GetChildren()) |
123 | // return NULL; | |
124 | wxNode *current = GetChildren().First(); | |
2d0a075d JS |
125 | while (current) |
126 | { | |
127 | wxWindow *childWin = (wxWindow *)current->Data(); | |
2bda0e17 | 128 | |
2d0a075d JS |
129 | wxWindow *wnd = childWin->FindItem(id) ; |
130 | if (wnd) | |
131 | return wnd ; | |
2bda0e17 | 132 | |
2d0a075d JS |
133 | if (childWin->IsKindOf(CLASSINFO(wxControl))) |
134 | { | |
135 | wxControl *item = (wxControl *)childWin; | |
ce3ed50d | 136 | if (item->GetId() == id) |
2d0a075d JS |
137 | return item; |
138 | else | |
139 | { | |
140 | // In case it's a 'virtual' control (e.g. radiobox) | |
141 | if (item->GetSubcontrols().Member((wxObject *)id)) | |
142 | return item; | |
143 | } | |
144 | } | |
145 | current = current->Next(); | |
2bda0e17 | 146 | } |
2d0a075d | 147 | return NULL; |
2bda0e17 KB |
148 | } |
149 | ||
150 | // Find an item given the MS Windows handle | |
debe6624 | 151 | wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const |
2bda0e17 | 152 | { |
c0ed460c JS |
153 | // if (!GetChildren()) |
154 | // return NULL; | |
155 | wxNode *current = GetChildren().First(); | |
2d0a075d | 156 | while (current) |
2bda0e17 | 157 | { |
2d0a075d JS |
158 | wxObject *obj = (wxObject *)current->Data() ; |
159 | // Do a recursive search. | |
160 | wxWindow *parent = (wxWindow *)obj ; | |
161 | wxWindow *wnd = parent->FindItemByHWND(hWnd) ; | |
162 | if (wnd) | |
163 | return wnd ; | |
164 | ||
165 | if ((!controlOnly) || obj->IsKindOf(CLASSINFO(wxControl))) | |
166 | { | |
167 | wxWindow *item = (wxWindow *)current->Data(); | |
168 | if ((HWND)(item->GetHWND()) == (HWND) hWnd) | |
169 | return item; | |
170 | else | |
171 | { | |
172 | if ( item->ContainsHWND(hWnd) ) | |
173 | return item; | |
174 | } | |
175 | } | |
176 | current = current->Next(); | |
2bda0e17 | 177 | } |
2d0a075d | 178 | return NULL; |
2bda0e17 KB |
179 | } |
180 | ||
181 | // Default command handler | |
debe6624 | 182 | bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 183 | { |
2d0a075d | 184 | return FALSE; |
2bda0e17 KB |
185 | } |
186 | ||
fd3f686c | 187 | bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam), |
3a19e16d | 188 | WXLPARAM lParam, |
fd3f686c | 189 | WXLPARAM* WXUNUSED(result)) |
2bda0e17 | 190 | { |
acbd13a3 | 191 | #ifdef __WIN95__ |
cb1a1dc9 | 192 | #if wxUSE_TOOLTIPS |
3a19e16d VZ |
193 | NMHDR* hdr = (NMHDR *)lParam; |
194 | if ( hdr->code == TTN_NEEDTEXT && m_tooltip ) | |
195 | { | |
196 | TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; | |
197 | ttt->lpszText = (char *)m_tooltip->GetTip().c_str(); | |
198 | ||
199 | // processed | |
200 | return TRUE; | |
201 | } | |
cb1a1dc9 | 202 | #endif |
acbd13a3 | 203 | #endif |
3a19e16d | 204 | |
2d0a075d | 205 | return FALSE; |
2bda0e17 KB |
206 | } |
207 | ||
debe6624 | 208 | void wxWindow::PreDelete(WXHDC WXUNUSED(dc)) |
2bda0e17 KB |
209 | { |
210 | } | |
211 | ||
212 | WXHWND wxWindow::GetHWND(void) const | |
213 | { | |
2d0a075d | 214 | return (WXHWND) m_hWnd; |
2bda0e17 KB |
215 | } |
216 | ||
217 | void wxWindow::SetHWND(WXHWND hWnd) | |
218 | { | |
2d0a075d | 219 | m_hWnd = hWnd; |
2bda0e17 KB |
220 | } |
221 | ||
fd3f686c VZ |
222 | // ---------------------------------------------------------------------------- |
223 | // constructors and such | |
224 | // ---------------------------------------------------------------------------- | |
225 | ||
226 | void wxWindow::Init() | |
2bda0e17 | 227 | { |
2d0a075d JS |
228 | // Generic |
229 | m_windowId = 0; | |
230 | m_isShown = TRUE; | |
231 | m_windowStyle = 0; | |
232 | m_windowParent = NULL; | |
233 | m_windowEventHandler = this; | |
2d0a075d JS |
234 | m_windowCursor = *wxSTANDARD_CURSOR; |
235 | m_children = new wxList; | |
236 | m_doubleClickAllowed = 0 ; | |
237 | m_winCaptured = FALSE; | |
238 | m_constraints = NULL; | |
239 | m_constraintsInvolvedIn = NULL; | |
240 | m_windowSizer = NULL; | |
241 | m_sizerParent = NULL; | |
242 | m_autoLayout = FALSE; | |
243 | m_windowValidator = NULL; | |
244 | ||
245 | // MSW-specific | |
246 | m_hWnd = 0; | |
247 | m_winEnabled = TRUE; | |
fd3f686c VZ |
248 | m_caretWidth = m_caretHeight = 0; |
249 | m_caretEnabled = | |
2d0a075d JS |
250 | m_caretShown = FALSE; |
251 | m_inOnSize = FALSE; | |
fd3f686c VZ |
252 | m_minSizeX = |
253 | m_minSizeY = | |
254 | m_maxSizeX = | |
2d0a075d | 255 | m_maxSizeY = -1; |
fd3f686c | 256 | |
2d0a075d JS |
257 | m_isBeingDeleted = FALSE; |
258 | m_oldWndProc = 0; | |
2bda0e17 | 259 | #ifndef __WIN32__ |
2d0a075d | 260 | m_globalHandle = 0; |
2bda0e17 | 261 | #endif |
2d0a075d | 262 | m_useCtl3D = FALSE; |
fd3f686c | 263 | m_mouseInWindow = FALSE; |
2bda0e17 | 264 | |
fd3f686c | 265 | m_windowParent = NULL; |
2d0a075d | 266 | m_defaultItem = NULL; |
2bda0e17 | 267 | |
2d0a075d | 268 | wxSystemSettings settings; |
2bda0e17 | 269 | |
2d0a075d | 270 | m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_3DFACE) ; |
2d0a075d | 271 | m_foregroundColour = *wxBLACK; |
2bda0e17 | 272 | |
2d0a075d JS |
273 | // wxWnd |
274 | m_lastMsg = 0; | |
275 | m_lastWParam = 0; | |
276 | m_lastLParam = 0; | |
2d0a075d | 277 | m_hMenu = 0; |
2bda0e17 | 278 | |
2d0a075d JS |
279 | m_xThumbSize = 0; |
280 | m_yThumbSize = 0; | |
281 | m_backgroundTransparent = FALSE; | |
2bda0e17 | 282 | |
2d0a075d JS |
283 | m_lastXPos = (float)-1.0; |
284 | m_lastYPos = (float)-1.0; | |
285 | m_lastEvent = -1; | |
286 | m_returnCode = 0; | |
2bda0e17 | 287 | |
47d67540 | 288 | #if wxUSE_DRAG_AND_DROP |
2d0a075d | 289 | m_pDropTarget = NULL; |
2bda0e17 | 290 | #endif |
3a19e16d | 291 | |
cb1a1dc9 | 292 | #if wxUSE_TOOLTIPS |
3a19e16d | 293 | m_tooltip = NULL; |
cb1a1dc9 | 294 | #endif |
2bda0e17 KB |
295 | } |
296 | ||
fd3f686c VZ |
297 | wxWindow::wxWindow() |
298 | { | |
299 | Init(); | |
300 | } | |
301 | ||
2bda0e17 | 302 | // Destructor |
fd3f686c | 303 | wxWindow::~wxWindow() |
2bda0e17 | 304 | { |
1f916a19 JS |
305 | // Remove potential dangling pointer |
306 | if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel))) | |
307 | { | |
308 | wxPanel* panel = (wxPanel*) GetParent(); | |
309 | if (panel->GetLastFocus() == this) | |
310 | panel->SetLastFocus((wxWindow*) NULL); | |
311 | } | |
312 | ||
2d0a075d | 313 | m_isBeingDeleted = TRUE; |
2bda0e17 | 314 | |
3a19e16d VZ |
315 | // first of all, delete the things on which nothing else depends |
316 | ||
cb1a1dc9 | 317 | #if wxUSE_TOOLTIPS |
3a19e16d | 318 | wxDELETE(m_tooltip); |
cb1a1dc9 | 319 | #endif |
3a19e16d | 320 | |
2d0a075d JS |
321 | // JACS - if behaviour is odd, restore this |
322 | // to the start of ~wxWindow. Vadim has changed | |
323 | // it to nearer the end. Unsure of side-effects | |
324 | // e.g. when deleting associated global data. | |
325 | // Restore old Window proc, if required | |
326 | // UnsubclassWin(); | |
2bda0e17 | 327 | |
2d0a075d JS |
328 | // Have to delete constraints/sizer FIRST otherwise |
329 | // sizers may try to look at deleted windows as they | |
330 | // delete themselves. | |
47d67540 | 331 | #if wxUSE_CONSTRAINTS |
2d0a075d | 332 | DeleteRelatedConstraints(); |
3a19e16d | 333 | |
2d0a075d JS |
334 | if (m_constraints) |
335 | { | |
336 | // This removes any dangling pointers to this window | |
337 | // in other windows' constraintsInvolvedIn lists. | |
338 | UnsetConstraints(m_constraints); | |
339 | delete m_constraints; | |
340 | m_constraints = NULL; | |
341 | } | |
3a19e16d VZ |
342 | |
343 | wxDELETE(m_windowSizer); | |
344 | ||
2d0a075d JS |
345 | // If this is a child of a sizer, remove self from parent |
346 | if (m_sizerParent) | |
347 | m_sizerParent->RemoveChild((wxWindow *)this); | |
2bda0e17 | 348 | #endif |
c085e333 | 349 | |
2d0a075d JS |
350 | // wxWnd |
351 | MSWDetachWindowMenu(); | |
2bda0e17 | 352 | |
2d0a075d JS |
353 | if (m_windowParent) |
354 | m_windowParent->RemoveChild(this); | |
2bda0e17 | 355 | |
2d0a075d | 356 | DestroyChildren(); |
2bda0e17 | 357 | |
2d0a075d JS |
358 | if (m_hWnd) |
359 | ::DestroyWindow((HWND)m_hWnd); | |
195896c7 | 360 | |
2d0a075d JS |
361 | wxRemoveHandleAssociation(this); |
362 | m_hWnd = 0; | |
2bda0e17 | 363 | #ifndef __WIN32__ |
2d0a075d JS |
364 | if (m_globalHandle) |
365 | { | |
366 | GlobalFree((HGLOBAL) m_globalHandle); | |
367 | m_globalHandle = 0; | |
368 | } | |
2bda0e17 | 369 | #endif |
c085e333 | 370 | |
2d0a075d JS |
371 | delete m_children; |
372 | m_children = NULL; | |
2bda0e17 | 373 | |
2d0a075d JS |
374 | // Just in case the window has been Closed, but |
375 | // we're then deleting immediately: don't leave | |
376 | // dangling pointers. | |
377 | wxPendingDelete.DeleteObject(this); | |
2bda0e17 | 378 | |
2d0a075d JS |
379 | // Just in case we've loaded a top-level window via |
380 | // wxWindow::LoadNativeDialog but we weren't a dialog | |
381 | // class | |
382 | wxTopLevelWindows.DeleteObject(this); | |
2bda0e17 | 383 | |
2d0a075d JS |
384 | if ( m_windowValidator ) |
385 | delete m_windowValidator; | |
2bda0e17 | 386 | |
c085e333 | 387 | // Restore old Window proc, if required |
2d0a075d JS |
388 | // and remove hWnd <-> wxWindow association |
389 | UnsubclassWin(); | |
2bda0e17 KB |
390 | } |
391 | ||
392 | // Destroy the window (delayed, if a managed window) | |
fd3f686c | 393 | bool wxWindow::Destroy() |
2bda0e17 KB |
394 | { |
395 | delete this; | |
396 | return TRUE; | |
397 | } | |
398 | ||
399 | extern char wxCanvasClassName[]; | |
400 | ||
fd3f686c | 401 | // real construction (Init() must have been called before!) |
debe6624 | 402 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, |
2d0a075d JS |
403 | const wxPoint& pos, |
404 | const wxSize& size, | |
405 | long style, | |
406 | const wxString& name) | |
407 | { | |
fd3f686c | 408 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); |
2bda0e17 | 409 | |
fd3f686c | 410 | parent->AddChild(this); |
2bda0e17 | 411 | |
2d0a075d | 412 | SetName(name); |
2bda0e17 | 413 | |
2d0a075d JS |
414 | if ( id == -1 ) |
415 | m_windowId = (int)NewControlId(); | |
416 | else | |
417 | m_windowId = id; | |
2bda0e17 | 418 | |
2d0a075d JS |
419 | int x = pos.x; |
420 | int y = pos.y; | |
421 | int width = size.x; | |
422 | int height = size.y; | |
2bda0e17 | 423 | |
386af6a2 JS |
424 | // To be consistent with wxGTK |
425 | if (width == -1) | |
426 | width = 20; | |
427 | if (height == -1) | |
428 | height = 20; | |
429 | ||
2d0a075d | 430 | wxSystemSettings settings; |
2bda0e17 | 431 | |
2d0a075d | 432 | m_windowStyle = style; |
2bda0e17 | 433 | |
2d0a075d JS |
434 | DWORD msflags = 0; |
435 | if (style & wxBORDER) | |
436 | msflags |= WS_BORDER; | |
437 | if (style & wxTHICK_FRAME) | |
438 | msflags |= WS_THICKFRAME; | |
1c089c47 | 439 | |
2d0a075d JS |
440 | msflags |= WS_CHILD | WS_VISIBLE; |
441 | if (style & wxCLIP_CHILDREN) | |
442 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 | 443 | |
2d0a075d JS |
444 | bool want3D; |
445 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
2bda0e17 | 446 | |
2d0a075d JS |
447 | // Even with extended styles, need to combine with WS_BORDER |
448 | // for them to look right. | |
449 | if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || | |
450 | (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER)) | |
451 | msflags |= WS_BORDER; | |
2bda0e17 | 452 | |
2d0a075d | 453 | MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL, |
fd3f686c | 454 | x, y, width, height, msflags, NULL, exStyle); |
2bda0e17 | 455 | |
2d0a075d | 456 | return TRUE; |
2bda0e17 KB |
457 | } |
458 | ||
fd3f686c | 459 | void wxWindow::SetFocus() |
2bda0e17 | 460 | { |
2d0a075d JS |
461 | HWND hWnd = (HWND) GetHWND(); |
462 | if (hWnd) | |
463 | ::SetFocus(hWnd); | |
2bda0e17 KB |
464 | } |
465 | ||
debe6624 | 466 | void wxWindow::Enable(bool enable) |
2bda0e17 | 467 | { |
2d0a075d JS |
468 | m_winEnabled = enable; |
469 | HWND hWnd = (HWND) GetHWND(); | |
470 | if (hWnd) | |
471 | ::EnableWindow(hWnd, (BOOL)enable); | |
2bda0e17 KB |
472 | } |
473 | ||
fd3f686c | 474 | void wxWindow::CaptureMouse() |
2bda0e17 | 475 | { |
2d0a075d JS |
476 | HWND hWnd = (HWND) GetHWND(); |
477 | if (hWnd && !m_winCaptured) | |
478 | { | |
479 | SetCapture(hWnd); | |
480 | m_winCaptured = TRUE; | |
481 | } | |
2bda0e17 KB |
482 | } |
483 | ||
fd3f686c | 484 | void wxWindow::ReleaseMouse() |
2bda0e17 | 485 | { |
2d0a075d JS |
486 | if (m_winCaptured) |
487 | { | |
488 | ReleaseCapture(); | |
489 | m_winCaptured = FALSE; | |
490 | } | |
2bda0e17 KB |
491 | } |
492 | ||
088a95f5 JS |
493 | void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) |
494 | { | |
495 | m_acceleratorTable = accel; | |
496 | } | |
497 | ||
498 | ||
2bda0e17 KB |
499 | // Push/pop event handler (i.e. allow a chain of event handlers |
500 | // be searched) | |
501 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
502 | { | |
2d0a075d JS |
503 | handler->SetNextHandler(GetEventHandler()); |
504 | SetEventHandler(handler); | |
2bda0e17 KB |
505 | } |
506 | ||
507 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
508 | { | |
2d0a075d | 509 | if ( GetEventHandler() ) |
564b2609 | 510 | { |
2d0a075d JS |
511 | wxEvtHandler *handlerA = GetEventHandler(); |
512 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
513 | handlerA->SetNextHandler(NULL); | |
514 | SetEventHandler(handlerB); | |
515 | if ( deleteHandler ) | |
516 | { | |
517 | delete handlerA; | |
518 | return NULL; | |
519 | } | |
520 | else | |
521 | return handlerA; | |
564b2609 VZ |
522 | } |
523 | else | |
2d0a075d | 524 | return NULL; |
2bda0e17 KB |
525 | } |
526 | ||
47d67540 | 527 | #if wxUSE_DRAG_AND_DROP |
2bda0e17 KB |
528 | |
529 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
530 | { | |
2d0a075d JS |
531 | if ( m_pDropTarget != 0 ) { |
532 | m_pDropTarget->Revoke(m_hWnd); | |
533 | delete m_pDropTarget; | |
534 | } | |
195896c7 | 535 | |
2d0a075d JS |
536 | m_pDropTarget = pDropTarget; |
537 | if ( m_pDropTarget != 0 ) | |
538 | m_pDropTarget->Register(m_hWnd); | |
2bda0e17 KB |
539 | } |
540 | ||
3a19e16d VZ |
541 | #endif // wxUSE_DRAG_AND_DROP |
542 | ||
2bda0e17 KB |
543 | |
544 | //old style file-manager drag&drop support | |
545 | // I think we should retain the old-style | |
546 | // DragAcceptFiles in parallel with SetDropTarget. | |
547 | // JACS | |
debe6624 | 548 | void wxWindow::DragAcceptFiles(bool accept) |
2bda0e17 | 549 | { |
2d0a075d JS |
550 | HWND hWnd = (HWND) GetHWND(); |
551 | if (hWnd) | |
552 | ::DragAcceptFiles(hWnd, (BOOL)accept); | |
2bda0e17 KB |
553 | } |
554 | ||
3a19e16d VZ |
555 | // ---------------------------------------------------------------------------- |
556 | // tooltips | |
557 | // ---------------------------------------------------------------------------- | |
558 | ||
cb1a1dc9 VZ |
559 | #if wxUSE_TOOLTIPS |
560 | ||
3a19e16d VZ |
561 | void wxWindow::SetToolTip(const wxString &tip) |
562 | { | |
563 | SetToolTip(new wxToolTip(tip)); | |
564 | } | |
565 | ||
566 | void wxWindow::SetToolTip(wxToolTip *tooltip) | |
567 | { | |
568 | if ( m_tooltip ) | |
569 | delete m_tooltip; | |
570 | ||
571 | m_tooltip = tooltip; | |
572 | m_tooltip->SetWindow(this); | |
573 | } | |
574 | ||
cb1a1dc9 VZ |
575 | #endif // wxUSE_TOOLTIPS |
576 | ||
2bda0e17 KB |
577 | // Get total size |
578 | void wxWindow::GetSize(int *x, int *y) const | |
579 | { | |
2d0a075d JS |
580 | HWND hWnd = (HWND) GetHWND(); |
581 | RECT rect; | |
582 | GetWindowRect(hWnd, &rect); | |
583 | *x = rect.right - rect.left; | |
584 | *y = rect.bottom - rect.top; | |
2bda0e17 KB |
585 | } |
586 | ||
587 | void wxWindow::GetPosition(int *x, int *y) const | |
588 | { | |
2d0a075d JS |
589 | HWND hWnd = (HWND) GetHWND(); |
590 | HWND hParentWnd = 0; | |
591 | if (GetParent()) | |
592 | hParentWnd = (HWND) GetParent()->GetHWND(); | |
81d66cf3 | 593 | |
2d0a075d JS |
594 | RECT rect; |
595 | GetWindowRect(hWnd, &rect); | |
596 | ||
597 | // Since we now have the absolute screen coords, | |
598 | // if there's a parent we must subtract its top left corner | |
599 | POINT point; | |
600 | point.x = rect.left; | |
601 | point.y = rect.top; | |
602 | if (hParentWnd) | |
603 | { | |
604 | ::ScreenToClient(hParentWnd, &point); | |
605 | } | |
606 | ||
607 | // We may be faking the client origin. | |
608 | // So a window that's really at (0, 30) may appear | |
609 | // (to wxWin apps) to be at (0, 0). | |
610 | if (GetParent()) | |
611 | { | |
612 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
613 | point.x -= pt.x; | |
614 | point.y -= pt.y; | |
615 | } | |
616 | *x = point.x; | |
617 | *y = point.y; | |
2bda0e17 KB |
618 | } |
619 | ||
620 | void wxWindow::ScreenToClient(int *x, int *y) const | |
621 | { | |
2d0a075d JS |
622 | HWND hWnd = (HWND) GetHWND(); |
623 | POINT pt; | |
624 | pt.x = *x; | |
625 | pt.y = *y; | |
2d0a075d | 626 | |
87d1e11f | 627 | ::ScreenToClient(hWnd, &pt); |
0757d27c | 628 | |
2d0a075d JS |
629 | *x = pt.x; |
630 | *y = pt.y; | |
2bda0e17 KB |
631 | } |
632 | ||
633 | void wxWindow::ClientToScreen(int *x, int *y) const | |
634 | { | |
2d0a075d JS |
635 | HWND hWnd = (HWND) GetHWND(); |
636 | POINT pt; | |
637 | pt.x = *x; | |
638 | pt.y = *y; | |
639 | ||
2d0a075d | 640 | ::ClientToScreen(hWnd, &pt); |
2bda0e17 | 641 | |
2d0a075d JS |
642 | *x = pt.x; |
643 | *y = pt.y; | |
2bda0e17 KB |
644 | } |
645 | ||
646 | void wxWindow::SetCursor(const wxCursor& cursor) | |
647 | { | |
2d0a075d JS |
648 | m_windowCursor = cursor; |
649 | if (m_windowCursor.Ok()) | |
650 | { | |
651 | HWND hWnd = (HWND) GetHWND(); | |
2bda0e17 | 652 | |
2d0a075d JS |
653 | // Change the cursor NOW if we're within the correct window |
654 | POINT point; | |
655 | ::GetCursorPos(&point); | |
2bda0e17 | 656 | |
2d0a075d JS |
657 | RECT rect; |
658 | ::GetWindowRect(hWnd, &rect); | |
2bda0e17 | 659 | |
2d0a075d JS |
660 | if (::PtInRect(&rect, point) && !wxIsBusy()) |
661 | ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR()); | |
662 | } | |
2bda0e17 | 663 | |
2d0a075d JS |
664 | // This will cause big reentrancy problems if wxFlushEvents is implemented. |
665 | // wxFlushEvents(); | |
666 | // return old_cursor; | |
2bda0e17 KB |
667 | } |
668 | ||
669 | ||
670 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
2bda0e17 KB |
671 | void wxWindow::GetClientSize(int *x, int *y) const |
672 | { | |
2d0a075d JS |
673 | HWND hWnd = (HWND) GetHWND(); |
674 | RECT rect; | |
675 | GetClientRect(hWnd, &rect); | |
676 | *x = rect.right; | |
677 | *y = rect.bottom; | |
2bda0e17 KB |
678 | } |
679 | ||
debe6624 | 680 | void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) |
2bda0e17 | 681 | { |
2d0a075d JS |
682 | int currentX, currentY; |
683 | GetPosition(¤tX, ¤tY); | |
72fd19a1 JS |
684 | int currentW,currentH; |
685 | GetSize(¤tW, ¤tH); | |
686 | ||
687 | if (x == currentX && y == currentY && width == currentW && height == currentH) | |
688 | return; | |
689 | ||
2d0a075d JS |
690 | int actualWidth = width; |
691 | int actualHeight = height; | |
692 | int actualX = x; | |
693 | int actualY = y; | |
694 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
695 | actualX = currentX; | |
696 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
697 | actualY = currentY; | |
698 | ||
699 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); | |
700 | ||
2d0a075d JS |
701 | if (width == -1) |
702 | actualWidth = currentW ; | |
703 | if (height == -1) | |
704 | actualHeight = currentH ; | |
81d66cf3 | 705 | |
2d0a075d JS |
706 | HWND hWnd = (HWND) GetHWND(); |
707 | if (hWnd) | |
708 | MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE); | |
2bda0e17 KB |
709 | } |
710 | ||
debe6624 | 711 | void wxWindow::SetClientSize(int width, int height) |
2bda0e17 | 712 | { |
2d0a075d JS |
713 | wxWindow *parent = GetParent(); |
714 | HWND hWnd = (HWND) GetHWND(); | |
715 | HWND hParentWnd = (HWND) (HWND) parent->GetHWND(); | |
2bda0e17 | 716 | |
2d0a075d JS |
717 | RECT rect; |
718 | GetClientRect(hWnd, &rect); | |
2bda0e17 | 719 | |
2d0a075d JS |
720 | RECT rect2; |
721 | GetWindowRect(hWnd, &rect2); | |
2bda0e17 | 722 | |
2d0a075d JS |
723 | // Find the difference between the entire window (title bar and all) |
724 | // and the client area; add this to the new client size to move the | |
725 | // window | |
726 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
727 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
2bda0e17 | 728 | |
2d0a075d JS |
729 | // If there's a parent, must subtract the parent's top left corner |
730 | // since MoveWindow moves relative to the parent | |
2bda0e17 | 731 | |
2d0a075d JS |
732 | POINT point; |
733 | point.x = rect2.left; | |
734 | point.y = rect2.top; | |
735 | if (parent) | |
736 | { | |
737 | ::ScreenToClient(hParentWnd, &point); | |
738 | } | |
2bda0e17 | 739 | |
2d0a075d | 740 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); |
debe6624 | 741 | |
2d0a075d JS |
742 | wxSizeEvent event(wxSize(width, height), m_windowId); |
743 | event.SetEventObject(this); | |
744 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
745 | } |
746 | ||
81d66cf3 JS |
747 | // For implementation purposes - sometimes decorations make the client area |
748 | // smaller | |
749 | wxPoint wxWindow::GetClientAreaOrigin() const | |
750 | { | |
751 | return wxPoint(0, 0); | |
752 | } | |
753 | ||
754 | // Makes an adjustment to the window position (for example, a frame that has | |
755 | // a toolbar that it manages itself). | |
756 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
757 | { | |
758 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) | |
759 | { | |
760 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
761 | x += pt.x; y += pt.y; | |
762 | } | |
763 | } | |
764 | ||
debe6624 | 765 | bool wxWindow::Show(bool show) |
2bda0e17 | 766 | { |
2d0a075d JS |
767 | HWND hWnd = (HWND) GetHWND(); |
768 | int cshow; | |
769 | if (show) | |
770 | cshow = SW_SHOW; | |
771 | else | |
772 | cshow = SW_HIDE; | |
773 | ShowWindow(hWnd, (BOOL)cshow); | |
774 | if (show) | |
775 | { | |
776 | BringWindowToTop(hWnd); | |
777 | // Next line causes a crash on NT, apparently. | |
778 | // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency? | |
779 | } | |
780 | return TRUE; | |
2bda0e17 KB |
781 | } |
782 | ||
783 | bool wxWindow::IsShown(void) const | |
784 | { | |
2d0a075d | 785 | return (::IsWindowVisible((HWND) GetHWND()) != 0); |
2bda0e17 KB |
786 | } |
787 | ||
788 | int wxWindow::GetCharHeight(void) const | |
789 | { | |
2d0a075d JS |
790 | TEXTMETRIC lpTextMetric; |
791 | HWND hWnd = (HWND) GetHWND(); | |
792 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 793 | |
2d0a075d JS |
794 | GetTextMetrics(dc, &lpTextMetric); |
795 | ::ReleaseDC(hWnd, dc); | |
2bda0e17 | 796 | |
2d0a075d | 797 | return lpTextMetric.tmHeight; |
2bda0e17 KB |
798 | } |
799 | ||
800 | int wxWindow::GetCharWidth(void) const | |
801 | { | |
2d0a075d JS |
802 | TEXTMETRIC lpTextMetric; |
803 | HWND hWnd = (HWND) GetHWND(); | |
804 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 805 | |
2d0a075d JS |
806 | GetTextMetrics(dc, &lpTextMetric); |
807 | ::ReleaseDC(hWnd, dc); | |
2bda0e17 | 808 | |
2d0a075d | 809 | return lpTextMetric.tmAveCharWidth; |
2bda0e17 KB |
810 | } |
811 | ||
812 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
2d0a075d | 813 | int *descent, int *externalLeading, const wxFont *theFont, bool) const |
2bda0e17 | 814 | { |
2d0a075d JS |
815 | wxFont *fontToUse = (wxFont *)theFont; |
816 | if (!fontToUse) | |
817 | fontToUse = (wxFont *) & m_windowFont; | |
2bda0e17 | 818 | |
2d0a075d JS |
819 | HWND hWnd = (HWND) GetHWND(); |
820 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 821 | |
c085e333 | 822 | HFONT fnt = 0; |
2d0a075d JS |
823 | HFONT was = 0; |
824 | if (fontToUse && fontToUse->Ok()) | |
825 | { | |
fd3f686c VZ |
826 | fnt = (HFONT)fontToUse->GetResourceHandle(); |
827 | if ( fnt ) | |
2d0a075d JS |
828 | was = (HFONT) SelectObject(dc,fnt) ; |
829 | } | |
2bda0e17 | 830 | |
2d0a075d JS |
831 | SIZE sizeRect; |
832 | TEXTMETRIC tm; | |
833 | GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect); | |
834 | GetTextMetrics(dc, &tm); | |
2bda0e17 | 835 | |
c085e333 | 836 | if (fontToUse && fnt && was) |
2d0a075d | 837 | SelectObject(dc,was) ; |
2bda0e17 | 838 | |
2d0a075d | 839 | ReleaseDC(hWnd, dc); |
2bda0e17 | 840 | |
2d0a075d JS |
841 | *x = sizeRect.cx; |
842 | *y = sizeRect.cy; | |
843 | if (descent) *descent = tm.tmDescent; | |
844 | if (externalLeading) *externalLeading = tm.tmExternalLeading; | |
2bda0e17 | 845 | |
2d0a075d JS |
846 | // if (fontToUse) |
847 | // fontToUse->ReleaseResource(); | |
2bda0e17 KB |
848 | } |
849 | ||
16e93305 | 850 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
2bda0e17 | 851 | { |
2d0a075d JS |
852 | HWND hWnd = (HWND) GetHWND(); |
853 | if (hWnd) | |
2bda0e17 | 854 | { |
2d0a075d JS |
855 | if (rect) |
856 | { | |
857 | RECT mswRect; | |
858 | mswRect.left = rect->x; | |
859 | mswRect.top = rect->y; | |
860 | mswRect.right = rect->x + rect->width; | |
861 | mswRect.bottom = rect->y + rect->height; | |
862 | ||
863 | ::InvalidateRect(hWnd, &mswRect, eraseBack); | |
864 | } | |
865 | else | |
866 | ::InvalidateRect(hWnd, NULL, eraseBack); | |
2bda0e17 | 867 | } |
2bda0e17 KB |
868 | } |
869 | ||
a02eb1d2 VZ |
870 | bool wxWindow::ProcessEvent(wxEvent& event) |
871 | { | |
2d0a075d JS |
872 | // we save here the information about the last message because it might be |
873 | // overwritten if the event handler sends any messages to our window (case | |
874 | // in point: wxNotebook::OnSize) - and then if we call Default() later | |
875 | // (which is done quite often if the message is not processed) it will use | |
876 | // incorrect values for m_lastXXX variables | |
877 | WXUINT lastMsg = m_lastMsg; | |
878 | WXWPARAM lastWParam = m_lastWParam; | |
879 | WXLPARAM lastLParam = m_lastLParam; | |
a02eb1d2 | 880 | |
2d0a075d JS |
881 | // call the base version |
882 | bool bProcessed = wxEvtHandler::ProcessEvent(event); | |
a02eb1d2 | 883 | |
2d0a075d JS |
884 | // restore |
885 | m_lastMsg = lastMsg; | |
886 | m_lastWParam = lastWParam; | |
887 | m_lastLParam = lastLParam; | |
a02eb1d2 | 888 | |
2d0a075d | 889 | return bProcessed; |
a02eb1d2 VZ |
890 | } |
891 | ||
2bda0e17 KB |
892 | // Hook for new window just as it's being created, |
893 | // when the window isn't yet associated with the handle | |
894 | wxWindow *wxWndHook = NULL; | |
895 | ||
1c089c47 | 896 | // Main window proc |
2bda0e17 KB |
897 | LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
898 | { | |
2d0a075d | 899 | wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); |
2bda0e17 | 900 | |
2d0a075d JS |
901 | if (!wnd && wxWndHook) |
902 | { | |
903 | wxAssociateWinWithHandle(hWnd, wxWndHook); | |
904 | wnd = wxWndHook; | |
905 | wxWndHook = NULL; | |
906 | wnd->m_hWnd = (WXHWND) hWnd; | |
907 | } | |
ea57084d | 908 | |
341c92a8 | 909 | // Stop right here if we don't have a valid handle in our wxWindow object. |
2d0a075d | 910 | if (wnd && !wnd->m_hWnd) { |
2d0a075d JS |
911 | wnd->m_hWnd = (WXHWND) hWnd; |
912 | long res = wnd->MSWDefWindowProc(message, wParam, lParam ); | |
913 | wnd->m_hWnd = 0; | |
914 | return res; | |
915 | } | |
2bda0e17 | 916 | |
2d0a075d JS |
917 | if (wnd) { |
918 | wnd->m_lastMsg = message; | |
919 | wnd->m_lastWParam = wParam; | |
920 | wnd->m_lastLParam = lParam; | |
921 | } | |
922 | if (wnd) | |
923 | return wnd->MSWWindowProc(message, wParam, lParam); | |
924 | else | |
925 | return DefWindowProc( hWnd, message, wParam, lParam ); | |
2bda0e17 KB |
926 | } |
927 | ||
928 | // Should probably have a test for 'genuine' NT | |
929 | #if defined(__WIN32__) | |
09914df7 | 930 | #define DIMENSION_TYPE short |
2bda0e17 | 931 | #else |
09914df7 | 932 | #define DIMENSION_TYPE int |
2bda0e17 KB |
933 | #endif |
934 | ||
935 | // Main Windows 3 window proc | |
936 | long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
937 | { | |
2d0a075d | 938 | wxASSERT( m_lastMsg == message && |
09914df7 | 939 | m_lastWParam == wParam && m_lastLParam == lParam ); |
5de76427 | 940 | |
2d0a075d | 941 | #ifdef __WXDEBUG__ |
a02eb1d2 | 942 | wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)", |
3a19e16d | 943 | wxGetMessageName(message), wParam, lParam); |
ea57084d | 944 | #endif // __WXDEBUG__ |
c085e333 | 945 | |
2d0a075d | 946 | HWND hWnd = (HWND)m_hWnd; |
2bda0e17 | 947 | |
2d0a075d JS |
948 | switch (message) |
949 | { | |
950 | case WM_ACTIVATE: | |
2bda0e17 KB |
951 | { |
952 | #ifdef __WIN32__ | |
953 | WORD state = LOWORD(wParam); | |
954 | WORD minimized = HIWORD(wParam); | |
955 | HWND hwnd = (HWND)lParam; | |
956 | #else | |
957 | WORD state = (WORD)wParam; | |
958 | WORD minimized = LOWORD(lParam); | |
959 | HWND hwnd = (HWND)HIWORD(lParam); | |
960 | #endif | |
961 | MSWOnActivate(state, (minimized != 0), (WXHWND) hwnd); | |
962 | return 0; | |
963 | break; | |
964 | } | |
2d0a075d | 965 | case WM_SETFOCUS: |
2bda0e17 KB |
966 | { |
967 | HWND hwnd = (HWND)wParam; | |
2d0a075d | 968 | // return OnSetFocus(hwnd); |
2bda0e17 KB |
969 | |
970 | if (MSWOnSetFocus((WXHWND) hwnd)) | |
2d0a075d | 971 | return 0; |
2bda0e17 KB |
972 | else return MSWDefWindowProc(message, wParam, lParam ); |
973 | break; | |
974 | } | |
2d0a075d | 975 | case WM_KILLFOCUS: |
2bda0e17 KB |
976 | { |
977 | HWND hwnd = (HWND)lParam; | |
2d0a075d | 978 | // return OnKillFocus(hwnd); |
2bda0e17 | 979 | if (MSWOnKillFocus((WXHWND) hwnd)) |
2d0a075d | 980 | return 0; |
2bda0e17 | 981 | else |
2d0a075d | 982 | return MSWDefWindowProc(message, wParam, lParam ); |
2bda0e17 KB |
983 | break; |
984 | } | |
2d0a075d | 985 | case WM_CREATE: |
47cbd6da | 986 | { |
2d0a075d JS |
987 | MSWOnCreate((WXLPCREATESTRUCT) (LPCREATESTRUCT)lParam); |
988 | return 0; | |
989 | break; | |
47cbd6da | 990 | } |
2d0a075d | 991 | case WM_SHOWWINDOW: |
47cbd6da | 992 | { |
2d0a075d JS |
993 | MSWOnShow((wParam != 0), (int) lParam); |
994 | break; | |
47cbd6da | 995 | } |
2d0a075d | 996 | case WM_PAINT: |
47cbd6da | 997 | { |
2d0a075d JS |
998 | if (MSWOnPaint()) |
999 | return 0; | |
1000 | else return MSWDefWindowProc(message, wParam, lParam ); | |
1001 | break; | |
2bda0e17 | 1002 | } |
2d0a075d | 1003 | case WM_QUERYDRAGICON: |
47cbd6da | 1004 | { |
fd3f686c VZ |
1005 | HICON hIcon = (HICON)MSWOnQueryDragIcon(); |
1006 | if ( hIcon ) | |
2d0a075d | 1007 | return (long)hIcon; |
fd3f686c VZ |
1008 | else |
1009 | return MSWDefWindowProc(message, wParam, lParam ); | |
2d0a075d | 1010 | break; |
2bda0e17 | 1011 | } |
c085e333 | 1012 | |
2d0a075d | 1013 | case WM_SIZE: |
2bda0e17 | 1014 | { |
2d0a075d JS |
1015 | int width = LOWORD(lParam); |
1016 | int height = HIWORD(lParam); | |
1017 | MSWOnSize(width, height, wParam); | |
1018 | break; | |
2bda0e17 | 1019 | } |
c085e333 | 1020 | |
2d0a075d JS |
1021 | case WM_MOVE: |
1022 | { | |
568cb543 | 1023 | wxMoveEvent event(wxPoint(LOWORD(lParam), HIWORD(lParam)), |
2d0a075d | 1024 | m_windowId); |
568cb543 VZ |
1025 | event.SetEventObject(this); |
1026 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
2d0a075d JS |
1027 | Default(); |
1028 | } | |
1029 | break; | |
568cb543 | 1030 | |
2d0a075d | 1031 | case WM_WINDOWPOSCHANGING: |
2bda0e17 | 1032 | { |
2d0a075d JS |
1033 | MSWOnWindowPosChanging((void *)lParam); |
1034 | break; | |
2bda0e17 | 1035 | } |
c085e333 | 1036 | |
2d0a075d | 1037 | case WM_RBUTTONDOWN: |
2bda0e17 KB |
1038 | { |
1039 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1040 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1041 | MSWOnRButtonDown(x, y, wParam); | |
1042 | break; | |
1043 | } | |
2d0a075d | 1044 | case WM_RBUTTONUP: |
2bda0e17 KB |
1045 | { |
1046 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1047 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1048 | MSWOnRButtonUp(x, y, wParam); | |
1049 | break; | |
1050 | } | |
2d0a075d | 1051 | case WM_RBUTTONDBLCLK: |
2bda0e17 KB |
1052 | { |
1053 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1054 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1055 | MSWOnRButtonDClick(x, y, wParam); | |
1056 | break; | |
1057 | } | |
2d0a075d | 1058 | case WM_MBUTTONDOWN: |
2bda0e17 KB |
1059 | { |
1060 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1061 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1062 | MSWOnMButtonDown(x, y, wParam); | |
1063 | break; | |
1064 | } | |
2d0a075d | 1065 | case WM_MBUTTONUP: |
2bda0e17 KB |
1066 | { |
1067 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1068 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1069 | MSWOnMButtonUp(x, y, wParam); | |
1070 | break; | |
1071 | } | |
2d0a075d | 1072 | case WM_MBUTTONDBLCLK: |
2bda0e17 KB |
1073 | { |
1074 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1075 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1076 | MSWOnMButtonDClick(x, y, wParam); | |
1077 | break; | |
1078 | } | |
2d0a075d | 1079 | case WM_LBUTTONDOWN: |
2bda0e17 KB |
1080 | { |
1081 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1082 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1083 | MSWOnLButtonDown(x, y, wParam); | |
1084 | break; | |
1085 | } | |
2d0a075d | 1086 | case WM_LBUTTONUP: |
2bda0e17 KB |
1087 | { |
1088 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1089 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1090 | MSWOnLButtonUp(x, y, wParam); | |
1091 | break; | |
1092 | } | |
2d0a075d | 1093 | case WM_LBUTTONDBLCLK: |
2bda0e17 KB |
1094 | { |
1095 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1096 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1097 | MSWOnLButtonDClick(x, y, wParam); | |
1098 | break; | |
1099 | } | |
2d0a075d | 1100 | case WM_MOUSEMOVE: |
2bda0e17 KB |
1101 | { |
1102 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1103 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1104 | MSWOnMouseMove(x, y, wParam); | |
1105 | break; | |
1106 | } | |
2d0a075d | 1107 | case MM_JOY1BUTTONDOWN: |
2bda0e17 KB |
1108 | { |
1109 | int x = LOWORD(lParam); | |
1110 | int y = HIWORD(lParam); | |
1111 | MSWOnJoyDown(wxJOYSTICK1, x, y, wParam); | |
1112 | break; | |
1113 | } | |
2d0a075d | 1114 | case MM_JOY2BUTTONDOWN: |
2bda0e17 KB |
1115 | { |
1116 | int x = LOWORD(lParam); | |
1117 | int y = HIWORD(lParam); | |
1118 | MSWOnJoyDown(wxJOYSTICK2, x, y, wParam); | |
1119 | break; | |
1120 | } | |
2d0a075d | 1121 | case MM_JOY1BUTTONUP: |
2bda0e17 KB |
1122 | { |
1123 | int x = LOWORD(lParam); | |
1124 | int y = HIWORD(lParam); | |
1125 | MSWOnJoyUp(wxJOYSTICK1, x, y, wParam); | |
1126 | break; | |
1127 | } | |
2d0a075d | 1128 | case MM_JOY2BUTTONUP: |
2bda0e17 KB |
1129 | { |
1130 | int x = LOWORD(lParam); | |
1131 | int y = HIWORD(lParam); | |
1132 | MSWOnJoyUp(wxJOYSTICK2, x, y, wParam); | |
1133 | break; | |
1134 | } | |
2d0a075d | 1135 | case MM_JOY1MOVE: |
2bda0e17 KB |
1136 | { |
1137 | int x = LOWORD(lParam); | |
1138 | int y = HIWORD(lParam); | |
1139 | MSWOnJoyMove(wxJOYSTICK1, x, y, wParam); | |
1140 | break; | |
1141 | } | |
2d0a075d | 1142 | case MM_JOY2MOVE: |
2bda0e17 KB |
1143 | { |
1144 | int x = LOWORD(lParam); | |
1145 | int y = HIWORD(lParam); | |
1146 | MSWOnJoyMove(wxJOYSTICK2, x, y, wParam); | |
1147 | break; | |
1148 | } | |
2d0a075d | 1149 | case MM_JOY1ZMOVE: |
2bda0e17 KB |
1150 | { |
1151 | int z = LOWORD(lParam); | |
1152 | MSWOnJoyZMove(wxJOYSTICK1, z, wParam); | |
1153 | break; | |
1154 | } | |
2d0a075d | 1155 | case MM_JOY2ZMOVE: |
2bda0e17 KB |
1156 | { |
1157 | int z = LOWORD(lParam); | |
1158 | MSWOnJoyZMove(wxJOYSTICK2, z, wParam); | |
1159 | break; | |
1160 | } | |
2d0a075d | 1161 | case WM_DESTROY: |
2bda0e17 | 1162 | { |
2d0a075d JS |
1163 | if (MSWOnDestroy()) |
1164 | return 0; | |
1165 | else return MSWDefWindowProc(message, wParam, lParam ); | |
1166 | break; | |
2bda0e17 | 1167 | } |
2d0a075d | 1168 | case WM_SYSCOMMAND: |
2bda0e17 KB |
1169 | { |
1170 | return MSWOnSysCommand(wParam, lParam); | |
1171 | break; | |
1172 | } | |
2d0a075d | 1173 | case WM_COMMAND: |
47cbd6da | 1174 | { |
2bda0e17 KB |
1175 | #ifdef __WIN32__ |
1176 | WORD id = LOWORD(wParam); | |
1177 | HWND hwnd = (HWND)lParam; | |
1178 | WORD cmd = HIWORD(wParam); | |
1179 | #else | |
1180 | WORD id = (WORD)wParam; | |
1181 | HWND hwnd = (HWND)LOWORD(lParam) ; | |
1182 | WORD cmd = HIWORD(lParam); | |
1183 | #endif | |
1184 | if (!MSWOnCommand(id, cmd, (WXHWND) hwnd)) | |
2d0a075d | 1185 | return MSWDefWindowProc(message, wParam, lParam ); |
2bda0e17 | 1186 | break; |
47cbd6da | 1187 | } |
2bda0e17 | 1188 | #if defined(__WIN95__) |
2d0a075d | 1189 | case WM_NOTIFY: |
47cbd6da | 1190 | { |
fd3f686c VZ |
1191 | // for some messages (TVN_ITEMEXPANDING for example), the return |
1192 | // value of WM_NOTIFY handler is important, so don't just return 0 | |
1193 | // if we processed the message | |
1194 | return MSWOnNotify(wParam, lParam); | |
2bda0e17 KB |
1195 | } |
1196 | #endif | |
2d0a075d | 1197 | case WM_MENUSELECT: |
2bda0e17 KB |
1198 | { |
1199 | #ifdef __WIN32__ | |
1200 | WORD flags = HIWORD(wParam); | |
1201 | HMENU sysmenu = (HMENU)lParam; | |
1202 | #else | |
1203 | WORD flags = LOWORD(lParam); | |
1204 | HMENU sysmenu = (HMENU)HIWORD(lParam); | |
1205 | #endif | |
1206 | MSWOnMenuHighlight((WORD)wParam, flags, (WXHMENU) sysmenu); | |
1207 | break; | |
1208 | } | |
2d0a075d | 1209 | case WM_INITMENUPOPUP: |
2bda0e17 KB |
1210 | { |
1211 | MSWOnInitMenuPopup((WXHMENU) (HMENU)wParam, (int)LOWORD(lParam), (HIWORD(lParam) != 0)); | |
1212 | break; | |
1213 | } | |
2d0a075d | 1214 | case WM_DRAWITEM: |
2bda0e17 | 1215 | { |
2d0a075d JS |
1216 | return MSWOnDrawItem((int)wParam, (WXDRAWITEMSTRUCT *)lParam); |
1217 | break; | |
2bda0e17 | 1218 | } |
2d0a075d | 1219 | case WM_MEASUREITEM: |
2bda0e17 | 1220 | { |
2d0a075d JS |
1221 | return MSWOnMeasureItem((int)wParam, (WXMEASUREITEMSTRUCT *)lParam); |
1222 | break; | |
2bda0e17 | 1223 | } |
c085e333 | 1224 | |
2d0a075d | 1225 | case WM_KEYDOWN: |
4ce81a75 | 1226 | MSWOnKeyDown((WORD) wParam, lParam); |
2d0a075d JS |
1227 | // we consider these message "not interesting" |
1228 | if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) | |
1229 | return Default(); | |
1230 | ||
341c92a8 VZ |
1231 | // Avoid duplicate messages to OnChar for these special keys |
1232 | switch ( wParam ) | |
2d0a075d | 1233 | { |
341c92a8 VZ |
1234 | case VK_ESCAPE: |
1235 | case VK_SPACE: | |
1236 | case VK_RETURN: | |
1237 | case VK_BACK: | |
1238 | case VK_TAB: | |
1239 | case VK_LEFT: | |
1240 | case VK_RIGHT: | |
1241 | case VK_DOWN: | |
1242 | case VK_UP: | |
1243 | if ( ::GetKeyState(VK_CONTROL) & 0x100 ) | |
1244 | MSWOnChar((WORD)wParam, lParam); | |
1245 | break; | |
1246 | ||
1247 | default: | |
1248 | MSWOnChar((WORD)wParam, lParam); | |
1249 | if ( ::GetKeyState(VK_CONTROL) & 0x100 ) | |
1250 | return Default(); | |
1251 | break; | |
2d0a075d | 1252 | } |
341c92a8 | 1253 | |
2d0a075d | 1254 | break; |
47cbd6da | 1255 | |
4ce81a75 JS |
1256 | case WM_KEYUP: |
1257 | { | |
1258 | MSWOnKeyUp((WORD) wParam, lParam); | |
1259 | break; | |
1260 | } | |
2d0a075d JS |
1261 | case WM_CHAR: // Always an ASCII character |
1262 | { | |
47cbd6da VZ |
1263 | MSWOnChar((WORD)wParam, lParam, TRUE); |
1264 | break; | |
2d0a075d | 1265 | } |
f54f3bff | 1266 | |
2d0a075d | 1267 | case WM_HSCROLL: |
2bda0e17 KB |
1268 | { |
1269 | #ifdef __WIN32__ | |
1270 | WORD code = LOWORD(wParam); | |
1271 | WORD pos = HIWORD(wParam); | |
1272 | HWND control = (HWND)lParam; | |
1273 | #else | |
1274 | WORD code = (WORD)wParam; | |
1275 | WORD pos = LOWORD(lParam); | |
1276 | HWND control = (HWND)HIWORD(lParam); | |
1277 | #endif | |
1278 | MSWOnHScroll(code, pos, (WXHWND) control); | |
1279 | break; | |
1280 | } | |
2d0a075d | 1281 | case WM_VSCROLL: |
2bda0e17 KB |
1282 | { |
1283 | #ifdef __WIN32__ | |
1284 | WORD code = LOWORD(wParam); | |
1285 | WORD pos = HIWORD(wParam); | |
1286 | HWND control = (HWND)lParam; | |
1287 | #else | |
1288 | WORD code = (WORD)wParam; | |
1289 | WORD pos = LOWORD(lParam); | |
1290 | HWND control = (HWND)HIWORD(lParam); | |
1291 | #endif | |
1292 | MSWOnVScroll(code, pos, (WXHWND) control); | |
1293 | break; | |
1294 | } | |
1295 | #ifdef __WIN32__ | |
2d0a075d | 1296 | case WM_CTLCOLORBTN: |
47cbd6da | 1297 | { |
2d0a075d JS |
1298 | int nCtlColor = CTLCOLOR_BTN; |
1299 | HWND control = (HWND)lParam; | |
1300 | HDC pDC = (HDC)wParam; | |
1301 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1302 | message, wParam, lParam); | |
1303 | break; | |
47cbd6da | 1304 | } |
2d0a075d | 1305 | case WM_CTLCOLORDLG: |
47cbd6da | 1306 | { |
2d0a075d JS |
1307 | int nCtlColor = CTLCOLOR_DLG; |
1308 | HWND control = (HWND)lParam; | |
1309 | HDC pDC = (HDC)wParam; | |
1310 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1311 | message, wParam, lParam);\ | |
1312 | break; | |
47cbd6da | 1313 | } |
2d0a075d | 1314 | case WM_CTLCOLORLISTBOX: |
47cbd6da | 1315 | { |
2d0a075d JS |
1316 | int nCtlColor = CTLCOLOR_LISTBOX; |
1317 | HWND control = (HWND)lParam; | |
1318 | HDC pDC = (HDC)wParam; | |
1319 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1320 | message, wParam, lParam); | |
1321 | break; | |
47cbd6da | 1322 | } |
2d0a075d | 1323 | case WM_CTLCOLORMSGBOX: |
47cbd6da | 1324 | { |
2d0a075d JS |
1325 | int nCtlColor = CTLCOLOR_MSGBOX; |
1326 | HWND control = (HWND)lParam; | |
1327 | HDC pDC = (HDC)wParam; | |
1328 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1329 | message, wParam, lParam); | |
1330 | break; | |
47cbd6da | 1331 | } |
2d0a075d | 1332 | case WM_CTLCOLORSCROLLBAR: |
47cbd6da | 1333 | { |
2d0a075d JS |
1334 | int nCtlColor = CTLCOLOR_SCROLLBAR; |
1335 | HWND control = (HWND)lParam; | |
1336 | HDC pDC = (HDC)wParam; | |
1337 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1338 | message, wParam, lParam); | |
1339 | break; | |
47cbd6da | 1340 | } |
2d0a075d | 1341 | case WM_CTLCOLORSTATIC: |
47cbd6da | 1342 | { |
2d0a075d JS |
1343 | int nCtlColor = CTLCOLOR_STATIC; |
1344 | HWND control = (HWND)lParam; | |
1345 | HDC pDC = (HDC)wParam; | |
1346 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1347 | message, wParam, lParam); | |
1348 | break; | |
47cbd6da | 1349 | } |
2d0a075d | 1350 | case WM_CTLCOLOREDIT: |
47cbd6da | 1351 | { |
2d0a075d JS |
1352 | int nCtlColor = CTLCOLOR_EDIT; |
1353 | HWND control = (HWND)lParam; | |
1354 | HDC pDC = (HDC)wParam; | |
1355 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1356 | message, wParam, lParam); | |
1357 | break; | |
47cbd6da | 1358 | } |
2bda0e17 | 1359 | #else |
2d0a075d | 1360 | case WM_CTLCOLOR: |
2bda0e17 | 1361 | { |
2d0a075d JS |
1362 | HWND control = (HWND)LOWORD(lParam); |
1363 | int nCtlColor = (int)HIWORD(lParam); | |
1364 | HDC pDC = (HDC)wParam; | |
1365 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1366 | message, wParam, lParam); | |
1367 | break; | |
2bda0e17 KB |
1368 | } |
1369 | #endif | |
2d0a075d | 1370 | case WM_SYSCOLORCHANGE: |
2bda0e17 | 1371 | { |
2d0a075d JS |
1372 | // Return value of 0 means, we processed it. |
1373 | if (MSWOnColorChange((WXHWND) hWnd, message, wParam, lParam) == 0) | |
1374 | return 0; | |
1375 | else | |
1376 | return MSWDefWindowProc(message, wParam, lParam ); | |
1377 | break; | |
2bda0e17 | 1378 | } |
2d0a075d | 1379 | case WM_PALETTECHANGED: |
f7bd2698 JS |
1380 | { |
1381 | return MSWOnPaletteChanged((WXHWND) (HWND) wParam); | |
1382 | break; | |
1383 | } | |
2d0a075d | 1384 | case WM_QUERYNEWPALETTE: |
f7bd2698 JS |
1385 | { |
1386 | return MSWOnQueryNewPalette(); | |
1387 | break; | |
1388 | } | |
2d0a075d | 1389 | case WM_ERASEBKGND: |
2bda0e17 | 1390 | { |
2d0a075d JS |
1391 | // Prevents flicker when dragging |
1392 | if (IsIconic(hWnd)) return 1; | |
2bda0e17 | 1393 | |
2d0a075d JS |
1394 | if (!MSWOnEraseBkgnd((WXHDC) (HDC)wParam)) |
1395 | return 0; // Default(); MSWDefWindowProc(message, wParam, lParam ); | |
1396 | else return 1; | |
1397 | break; | |
2bda0e17 | 1398 | } |
2d0a075d | 1399 | case WM_MDIACTIVATE: |
2bda0e17 KB |
1400 | { |
1401 | #ifdef __WIN32__ | |
1402 | HWND hWndActivate = GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam,lParam); | |
1403 | HWND hWndDeactivate = GET_WM_MDIACTIVATE_HWNDDEACT(wParam,lParam); | |
1404 | BOOL activate = GET_WM_MDIACTIVATE_FACTIVATE(hWnd,wParam,lParam); | |
1405 | return MSWOnMDIActivate((long) activate, (WXHWND) hWndActivate, (WXHWND) hWndDeactivate); | |
1406 | #else | |
1407 | return MSWOnMDIActivate((BOOL)wParam, (HWND)LOWORD(lParam), | |
2d0a075d | 1408 | (HWND)HIWORD(lParam)); |
2bda0e17 KB |
1409 | #endif |
1410 | } | |
2d0a075d | 1411 | case WM_DROPFILES: |
2bda0e17 KB |
1412 | { |
1413 | MSWOnDropFiles(wParam); | |
1414 | break; | |
47cbd6da | 1415 | } |
2d0a075d | 1416 | case WM_INITDIALOG: |
2bda0e17 KB |
1417 | { |
1418 | return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam); | |
1419 | break; | |
47cbd6da | 1420 | } |
2d0a075d | 1421 | case WM_QUERYENDSESSION: |
2bda0e17 | 1422 | { |
47cbd6da | 1423 | // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) |
2d0a075d | 1424 | // return MSWOnClose(); |
387a3b02 JS |
1425 | |
1426 | return MSWOnQueryEndSession(lParam); | |
1427 | break; | |
1428 | } | |
2d0a075d | 1429 | case WM_ENDSESSION: |
387a3b02 JS |
1430 | { |
1431 | // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) | |
1432 | MSWOnEndSession((wParam != 0), lParam); | |
1433 | return 0L; | |
2bda0e17 KB |
1434 | break; |
1435 | } | |
2d0a075d | 1436 | case WM_CLOSE: |
2bda0e17 KB |
1437 | { |
1438 | if (MSWOnClose()) | |
2d0a075d | 1439 | return 0L; |
2bda0e17 | 1440 | else |
2d0a075d | 1441 | return 1L; |
2bda0e17 KB |
1442 | break; |
1443 | } | |
c085e333 | 1444 | |
2d0a075d | 1445 | case WM_GETMINMAXINFO: |
2bda0e17 | 1446 | { |
2d0a075d JS |
1447 | MINMAXINFO *info = (MINMAXINFO *)lParam; |
1448 | if (m_minSizeX != -1) | |
1449 | info->ptMinTrackSize.x = (int)m_minSizeX; | |
1450 | if (m_minSizeY != -1) | |
1451 | info->ptMinTrackSize.y = (int)m_minSizeY; | |
1452 | if (m_maxSizeX != -1) | |
1453 | info->ptMaxTrackSize.x = (int)m_maxSizeX; | |
1454 | if (m_maxSizeY != -1) | |
1455 | info->ptMaxTrackSize.y = (int)m_maxSizeY; | |
1456 | return MSWDefWindowProc(message, wParam, lParam ); | |
1457 | break; | |
2bda0e17 | 1458 | } |
c085e333 | 1459 | |
2d0a075d JS |
1460 | case WM_GETDLGCODE: |
1461 | return MSWGetDlgCode(); | |
2bda0e17 | 1462 | |
2d0a075d JS |
1463 | default: |
1464 | return MSWDefWindowProc(message, wParam, lParam ); | |
2bda0e17 | 1465 | } |
341c92a8 | 1466 | |
2bda0e17 KB |
1467 | return 0; // Success: we processed this command. |
1468 | } | |
1469 | ||
1470 | // Dialog window proc | |
1471 | LONG APIENTRY _EXPORT | |
2d0a075d | 1472 | wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
2bda0e17 | 1473 | { |
2d0a075d | 1474 | return 0; |
2bda0e17 KB |
1475 | } |
1476 | ||
1477 | wxList *wxWinHandleList = NULL; | |
1478 | wxWindow *wxFindWinFromHandle(WXHWND hWnd) | |
1479 | { | |
2d0a075d JS |
1480 | wxNode *node = wxWinHandleList->Find((long)hWnd); |
1481 | if (!node) | |
1482 | return NULL; | |
1483 | return (wxWindow *)node->Data(); | |
2bda0e17 KB |
1484 | } |
1485 | ||
1486 | void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win) | |
1487 | { | |
2d0a075d JS |
1488 | // adding NULL hWnd is (first) surely a result of an error and |
1489 | // (secondly) breaks menu command processing | |
57c208c5 | 1490 | wxCHECK_RET( hWnd != (HWND) NULL, "attempt to add a NULL hWnd to window list" ); |
195896c7 | 1491 | |
2d0a075d JS |
1492 | if ( !wxWinHandleList->Find((long)hWnd) ) |
1493 | wxWinHandleList->Append((long)hWnd, win); | |
2bda0e17 KB |
1494 | } |
1495 | ||
1496 | void wxRemoveHandleAssociation(wxWindow *win) | |
1497 | { | |
2d0a075d | 1498 | wxWinHandleList->DeleteObject(win); |
2bda0e17 KB |
1499 | } |
1500 | ||
1501 | // Default destroyer - override if you destroy it in some other way | |
1502 | // (e.g. with MDI child windows) | |
fd3f686c | 1503 | void wxWindow::MSWDestroyWindow() |
2bda0e17 | 1504 | { |
2bda0e17 KB |
1505 | } |
1506 | ||
debe6624 | 1507 | void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, |
2d0a075d JS |
1508 | int x, int y, int width, int height, |
1509 | WXDWORD style, const char *dialog_template, WXDWORD extendedStyle) | |
1510 | { | |
1511 | bool is_dialog = (dialog_template != NULL); | |
1512 | int x1 = CW_USEDEFAULT; | |
1513 | int y1 = 0; | |
1514 | int width1 = CW_USEDEFAULT; | |
1515 | int height1 = 100; | |
1516 | ||
1517 | // Find parent's size, if it exists, to set up a possible default | |
1518 | // panel size the size of the parent window | |
1519 | RECT parent_rect; | |
1520 | if (parent) | |
1521 | { | |
1522 | // Was GetWindowRect: JACS 5/5/95 | |
1523 | ::GetClientRect((HWND) parent->GetHWND(), &parent_rect); | |
2bda0e17 | 1524 | |
2d0a075d JS |
1525 | width1 = parent_rect.right - parent_rect.left; |
1526 | height1 = parent_rect.bottom - parent_rect.top; | |
1527 | } | |
2bda0e17 | 1528 | |
2d0a075d JS |
1529 | if (x > -1) x1 = x; |
1530 | if (y > -1) y1 = y; | |
1531 | if (width > -1) width1 = width; | |
1532 | if (height > -1) height1 = height; | |
2bda0e17 | 1533 | |
2d0a075d JS |
1534 | HWND hParent = NULL; |
1535 | if (parent) | |
1536 | hParent = (HWND) parent->GetHWND(); | |
2bda0e17 | 1537 | |
2d0a075d | 1538 | wxWndHook = this; |
2bda0e17 | 1539 | |
2d0a075d JS |
1540 | if (is_dialog) |
1541 | { | |
1542 | // MakeProcInstance doesn't seem to be needed in C7. Is it needed for | |
1543 | // other compilers??? | |
1544 | // VZ: it's always needed for Win16 and never for Win32 | |
2bda0e17 | 1545 | #ifdef __WIN32__ |
2d0a075d JS |
1546 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, |
1547 | (DLGPROC)wxDlgProc); | |
2bda0e17 | 1548 | #else |
f60d0f94 JS |
1549 | // N.B.: if we _don't_ use this form, |
1550 | // then with VC++ 1.5, it crashes horribly. | |
1551 | #if 1 | |
1552 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, | |
1553 | (DLGPROC)wxDlgProc); | |
1554 | #else | |
1555 | // Crashes when we use this. | |
2d0a075d | 1556 | DLGPROC dlgproc = (DLGPROC)MakeProcInstance((DLGPROC)wxWndProc, wxGetInstance()); |
2bda0e17 | 1557 | |
2d0a075d JS |
1558 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, |
1559 | (DLGPROC)dlgproc); | |
f60d0f94 | 1560 | #endif |
2bda0e17 | 1561 | #endif |
c085e333 | 1562 | |
2d0a075d JS |
1563 | if (m_hWnd == 0) |
1564 | MessageBox(NULL, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.", | |
1565 | "wxWindows Error", MB_ICONEXCLAMATION | MB_OK); | |
1566 | else MoveWindow((HWND) m_hWnd, x1, y1, width1, height1, FALSE); | |
1567 | } | |
1568 | else | |
1569 | { | |
1570 | int controlId = 0; | |
1571 | if (style & WS_CHILD) | |
1572 | controlId = id; | |
1573 | if (!title) | |
1574 | title = ""; | |
1575 | ||
1576 | m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass, | |
1577 | title, | |
1578 | style, | |
1579 | x1, y1, | |
1580 | width1, height1, | |
1581 | hParent, (HMENU)controlId, wxGetInstance(), | |
1582 | NULL); | |
1583 | ||
1584 | if ( !m_hWnd ) { | |
1585 | wxLogError("Can't create window of class %s!\n" | |
1586 | "Possible Windows 3.x compatibility problem?", wclass); | |
1587 | } | |
2bda0e17 | 1588 | } |
a02eb1d2 | 1589 | |
2d0a075d JS |
1590 | wxWndHook = NULL; |
1591 | wxWinHandleList->Append((long)m_hWnd, this); | |
2bda0e17 KB |
1592 | } |
1593 | ||
1594 | void wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs)) | |
1595 | { | |
1596 | } | |
1597 | ||
fd3f686c | 1598 | bool wxWindow::MSWOnClose() |
2bda0e17 | 1599 | { |
2d0a075d | 1600 | return FALSE; |
2bda0e17 KB |
1601 | } |
1602 | ||
3572173c JS |
1603 | // Some compilers don't define this |
1604 | #ifndef ENDSESSION_LOGOFF | |
1605 | #define ENDSESSION_LOGOFF 0x80000000 | |
1606 | #endif | |
1607 | ||
387a3b02 JS |
1608 | // Return TRUE to end session, FALSE to veto end session. |
1609 | bool wxWindow::MSWOnQueryEndSession(long logOff) | |
1610 | { | |
1611 | wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1); | |
1612 | event.SetEventObject(wxTheApp); | |
1613 | event.SetCanVeto(TRUE); | |
1614 | event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); | |
1615 | if ((this == wxTheApp->GetTopWindow()) && // Only send once | |
2d0a075d | 1616 | wxTheApp->ProcessEvent(event) && event.GetVeto()) |
387a3b02 JS |
1617 | { |
1618 | return FALSE; // Veto! | |
1619 | } | |
1620 | else | |
1621 | { | |
1622 | return TRUE; // Don't veto | |
1623 | } | |
1624 | } | |
1625 | ||
1626 | bool wxWindow::MSWOnEndSession(bool endSession, long logOff) | |
1627 | { | |
1628 | wxCloseEvent event(wxEVT_END_SESSION, -1); | |
1629 | event.SetEventObject(wxTheApp); | |
1630 | event.SetCanVeto(FALSE); | |
1631 | event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); | |
1632 | if (endSession && // No need to send if the session isn't ending | |
1633 | (this == wxTheApp->GetTopWindow()) && // Only send once | |
2d0a075d | 1634 | wxTheApp->ProcessEvent(event)) |
387a3b02 JS |
1635 | { |
1636 | } | |
1637 | return TRUE; | |
1638 | } | |
1639 | ||
fd3f686c | 1640 | bool wxWindow::MSWOnDestroy() |
2bda0e17 | 1641 | { |
2d0a075d JS |
1642 | // delete our drop target if we've got one |
1643 | #if wxUSE_DRAG_AND_DROP | |
195896c7 | 1644 | if ( m_pDropTarget != NULL ) { |
2d0a075d | 1645 | m_pDropTarget->Revoke(m_hWnd); |
2bda0e17 | 1646 | |
2d0a075d JS |
1647 | delete m_pDropTarget; |
1648 | m_pDropTarget = NULL; | |
2bda0e17 | 1649 | } |
2d0a075d | 1650 | #endif |
c085e333 | 1651 | |
2d0a075d | 1652 | return TRUE; |
2bda0e17 KB |
1653 | } |
1654 | ||
1655 | // Deal with child commands from buttons etc. | |
1656 | ||
fd3f686c | 1657 | long wxWindow::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
1658 | { |
1659 | #if defined(__WIN95__) | |
1660 | // Find a child window to send the notification to, e.g. a toolbar. | |
1661 | // There's a problem here. NMHDR::hwndFrom doesn't give us the | |
1662 | // handle of the toolbar; it's probably the handle of the tooltip | |
1663 | // window (anyway, it's parent is also the toolbar's parent). | |
1664 | // So, since we don't know which hWnd or wxWindow originated the | |
1665 | // WM_NOTIFY, we'll need to go through all the children of this window | |
1666 | // trying out MSWNotify. | |
2d0a075d JS |
1667 | // This won't work now, though, because any number of controls |
1668 | // could respond to the same generic messages :-( | |
2bda0e17 | 1669 | |
2d0a075d JS |
1670 | /* This doesn't work for toolbars, but try for other controls first. |
1671 | */ | |
2bda0e17 KB |
1672 | NMHDR *hdr = (NMHDR *)lParam; |
1673 | HWND hWnd = (HWND)hdr->hwndFrom; | |
1674 | wxWindow *win = wxFindWinFromHandle((WXHWND) hWnd); | |
c085e333 | 1675 | |
fd3f686c VZ |
1676 | WXLPARAM result = 0; |
1677 | ||
2d0a075d | 1678 | if ( win ) |
fd3f686c | 1679 | { |
cf65ad8d VZ |
1680 | if ( win->MSWNotify(wParam, lParam, &result) ) |
1681 | return result; | |
fd3f686c | 1682 | } |
2d0a075d JS |
1683 | else |
1684 | { | |
564b2609 | 1685 | // Rely on MSWNotify to check whether the message |
2d0a075d | 1686 | // belongs to the window or not |
c0ed460c | 1687 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
1688 | while (node) |
1689 | { | |
1690 | wxWindow *child = (wxWindow *)node->Data(); | |
fd3f686c | 1691 | if ( child->MSWNotify(wParam, lParam, &result) ) |
cf65ad8d | 1692 | return result; |
2d0a075d | 1693 | node = node->Next(); |
564b2609 | 1694 | } |
2bda0e17 | 1695 | |
cf65ad8d VZ |
1696 | // finally try this window too (catches toolbar case) |
1697 | if ( MSWNotify(wParam, lParam, &result) ) | |
1698 | return result; | |
1699 | } | |
fd3f686c | 1700 | #endif // Win95 |
c085e333 | 1701 | |
cf65ad8d | 1702 | // not processed |
2d0a075d | 1703 | return FALSE; |
2bda0e17 KB |
1704 | } |
1705 | ||
debe6624 | 1706 | void wxWindow::MSWOnMenuHighlight(WXWORD WXUNUSED(item), WXWORD WXUNUSED(flags), WXHMENU WXUNUSED(sysmenu)) |
2bda0e17 | 1707 | { |
2bda0e17 KB |
1708 | } |
1709 | ||
debe6624 | 1710 | void wxWindow::MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem) |
2bda0e17 | 1711 | { |
2bda0e17 KB |
1712 | } |
1713 | ||
debe6624 | 1714 | bool wxWindow::MSWOnActivate(int state, bool WXUNUSED(minimized), WXHWND WXUNUSED(activate)) |
2bda0e17 | 1715 | { |
2d0a075d JS |
1716 | wxActivateEvent event(wxEVT_ACTIVATE, ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)), |
1717 | m_windowId); | |
1718 | event.SetEventObject(this); | |
1719 | GetEventHandler()->ProcessEvent(event); | |
1720 | return 0; | |
2bda0e17 KB |
1721 | } |
1722 | ||
debe6624 | 1723 | bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd)) |
2bda0e17 | 1724 | { |
2bda0e17 KB |
1725 | // Deal with caret |
1726 | if (m_caretEnabled && (m_caretWidth > 0) && (m_caretHeight > 0)) | |
1727 | { | |
2d0a075d JS |
1728 | ::CreateCaret((HWND) GetHWND(), NULL, m_caretWidth, m_caretHeight); |
1729 | if (m_caretShown) | |
1730 | ::ShowCaret((HWND) GetHWND()); | |
2bda0e17 | 1731 | } |
c085e333 | 1732 | |
341c92a8 VZ |
1733 | // panel wants to track the window which was the last to have focus in it |
1734 | wxWindow *parent = GetParent(); | |
1735 | if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) ) | |
1736 | { | |
1737 | ((wxPanel *)parent)->SetLastFocus(this); | |
1738 | } | |
1739 | ||
2d0a075d JS |
1740 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
1741 | event.SetEventObject(this); | |
1742 | if (!GetEventHandler()->ProcessEvent(event)) | |
1743 | Default(); | |
1744 | return TRUE; | |
2bda0e17 KB |
1745 | } |
1746 | ||
debe6624 | 1747 | bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd)) |
2bda0e17 | 1748 | { |
2bda0e17 KB |
1749 | // Deal with caret |
1750 | if (m_caretEnabled) | |
1751 | { | |
2d0a075d | 1752 | ::DestroyCaret(); |
2bda0e17 | 1753 | } |
c085e333 | 1754 | |
2d0a075d JS |
1755 | wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); |
1756 | event.SetEventObject(this); | |
1757 | if (!GetEventHandler()->ProcessEvent(event)) | |
1758 | Default(); | |
1759 | return TRUE; | |
2bda0e17 KB |
1760 | } |
1761 | ||
debe6624 | 1762 | void wxWindow::MSWOnDropFiles(WXWPARAM wParam) |
2bda0e17 | 1763 | { |
c085e333 | 1764 | |
2d0a075d JS |
1765 | HDROP hFilesInfo = (HDROP) wParam; |
1766 | POINT dropPoint; | |
1767 | DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint); | |
1768 | ||
1769 | // Get the total number of files dropped | |
1770 | WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo, | |
1771 | (UINT)-1, | |
1772 | (LPSTR)0, | |
1773 | (UINT)0); | |
1774 | ||
1775 | wxString *files = new wxString[gwFilesDropped]; | |
1776 | int wIndex; | |
1777 | for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++) | |
1778 | { | |
1779 | DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000); | |
1780 | files[wIndex] = wxBuffer; | |
1781 | } | |
1782 | DragFinish (hFilesInfo); | |
2bda0e17 | 1783 | |
2d0a075d JS |
1784 | wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); |
1785 | event.m_eventObject = this; | |
1786 | event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y; | |
2bda0e17 | 1787 | |
2d0a075d JS |
1788 | if (!GetEventHandler()->ProcessEvent(event)) |
1789 | Default(); | |
2bda0e17 | 1790 | |
2d0a075d | 1791 | delete[] files; |
2bda0e17 KB |
1792 | } |
1793 | ||
debe6624 | 1794 | bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct) |
2bda0e17 | 1795 | { |
47d67540 | 1796 | #if wxUSE_OWNER_DRAWN |
2bda0e17 | 1797 | if ( id == 0 ) { // is it a menu item? |
2d0a075d JS |
1798 | DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct; |
1799 | wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); | |
1800 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
1801 | ||
1802 | // prepare to call OnDrawItem() | |
1803 | wxDC dc; | |
1804 | dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE); | |
1805 | wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, | |
1806 | pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, | |
1807 | pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); | |
1808 | return pMenuItem->OnDrawItem( | |
1809 | dc, rect, | |
1810 | (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, | |
1811 | (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState | |
1812 | ); | |
2bda0e17 KB |
1813 | } |
1814 | #endif // owner-drawn menus | |
c085e333 | 1815 | |
2d0a075d | 1816 | wxWindow *item = FindItem(id); |
47d67540 | 1817 | #if wxUSE_DYNAMIC_CLASSES |
2d0a075d JS |
1818 | if (item && item->IsKindOf(CLASSINFO(wxControl))) |
1819 | { | |
1820 | return ((wxControl *)item)->MSWOnDraw(itemStruct); | |
1821 | } | |
1822 | else | |
2bda0e17 | 1823 | #endif |
2d0a075d | 1824 | return FALSE; |
2bda0e17 KB |
1825 | } |
1826 | ||
debe6624 | 1827 | bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) |
2bda0e17 | 1828 | { |
47d67540 | 1829 | #if wxUSE_OWNER_DRAWN |
2bda0e17 | 1830 | if ( id == 0 ) { // is it a menu item? |
2d0a075d JS |
1831 | MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct; |
1832 | wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); | |
1833 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
2bda0e17 | 1834 | |
c085e333 | 1835 | return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth, |
2d0a075d | 1836 | &pMeasureStruct->itemHeight); |
2bda0e17 KB |
1837 | } |
1838 | #endif // owner-drawn menus | |
c085e333 | 1839 | |
2d0a075d | 1840 | wxWindow *item = FindItem(id); |
47d67540 | 1841 | #if wxUSE_DYNAMIC_CLASSES |
2d0a075d JS |
1842 | if (item && item->IsKindOf(CLASSINFO(wxControl))) |
1843 | { | |
1844 | return ((wxControl *)item)->MSWOnMeasure(itemStruct); | |
1845 | } | |
1846 | else | |
2bda0e17 | 1847 | #endif |
2d0a075d | 1848 | return FALSE; |
2bda0e17 KB |
1849 | } |
1850 | ||
debe6624 | 1851 | WXHBRUSH wxWindow::MSWOnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
2d0a075d | 1852 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 1853 | { |
2d0a075d JS |
1854 | if (nCtlColor == CTLCOLOR_DLG) |
1855 | { | |
1856 | return OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
1857 | } | |
2bda0e17 | 1858 | |
2d0a075d | 1859 | wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE); |
2bda0e17 | 1860 | |
2d0a075d | 1861 | WXHBRUSH hBrush = 0; |
2bda0e17 | 1862 | |
2d0a075d JS |
1863 | if ( item ) |
1864 | hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
2bda0e17 | 1865 | |
2d0a075d JS |
1866 | // I think that even for dialogs, we may need to call DefWindowProc (?) |
1867 | // Or maybe just rely on the usual default behaviour. | |
1868 | if ( !hBrush ) | |
1869 | hBrush = (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); | |
2bda0e17 | 1870 | |
2d0a075d | 1871 | return hBrush ; |
2bda0e17 KB |
1872 | } |
1873 | ||
1874 | // Define for each class of dialog and control | |
debe6624 | 1875 | WXHBRUSH wxWindow::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
2d0a075d | 1876 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
1877 | { |
1878 | return (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); | |
1879 | } | |
1880 | ||
debe6624 | 1881 | bool wxWindow::MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 1882 | { |
2d0a075d JS |
1883 | wxSysColourChangedEvent event; |
1884 | event.SetEventObject(this); | |
2bda0e17 | 1885 | |
2d0a075d JS |
1886 | // Check if app handles this. |
1887 | if (GetEventHandler()->ProcessEvent(event)) | |
1888 | return 0; | |
2bda0e17 | 1889 | |
2d0a075d JS |
1890 | // We didn't process it |
1891 | return 1; | |
2bda0e17 KB |
1892 | } |
1893 | ||
f7bd2698 JS |
1894 | long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange) |
1895 | { | |
1896 | wxPaletteChangedEvent event(GetId()); | |
1897 | event.SetEventObject(this); | |
1898 | event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); | |
1899 | GetEventHandler()->ProcessEvent(event); | |
1900 | return 0; | |
1901 | } | |
1902 | ||
1903 | long wxWindow::MSWOnQueryNewPalette() | |
1904 | { | |
1905 | wxQueryNewPaletteEvent event(GetId()); | |
1906 | event.SetEventObject(this); | |
1907 | if (!GetEventHandler()->ProcessEvent(event) || !event.GetPaletteRealized()) | |
1908 | { | |
1909 | return (long) FALSE; | |
1910 | } | |
1911 | else | |
1912 | return (long) TRUE; | |
1913 | } | |
1914 | ||
2bda0e17 KB |
1915 | // Responds to colour changes: passes event on to children. |
1916 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1917 | { | |
c0ed460c | 1918 | wxNode *node = GetChildren().First(); |
2bda0e17 KB |
1919 | while ( node ) |
1920 | { | |
1921 | // Only propagate to non-top-level windows | |
1922 | wxWindow *win = (wxWindow *)node->Data(); | |
1923 | if ( win->GetParent() ) | |
1924 | { | |
1925 | wxSysColourChangedEvent event2; | |
1926 | event.m_eventObject = win; | |
1927 | win->GetEventHandler()->ProcessEvent(event2); | |
1928 | } | |
c085e333 | 1929 | |
2bda0e17 KB |
1930 | node = node->Next(); |
1931 | } | |
1932 | } | |
1933 | ||
1934 | long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
1935 | { | |
2d0a075d JS |
1936 | if ( m_oldWndProc ) |
1937 | return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); | |
1938 | else | |
1939 | return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam); | |
2bda0e17 KB |
1940 | } |
1941 | ||
1942 | long wxWindow::Default() | |
1943 | { | |
46851318 JS |
1944 | // Ignore 'fake' events (perhaps generated as a result of a separate real event) |
1945 | if (m_lastMsg == 0) | |
1c089c47 | 1946 | return 0; |
c085e333 | 1947 | |
2d0a075d JS |
1948 | #ifdef __WXDEBUG__ |
1949 | wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.", | |
1950 | wxGetMessageName(m_lastMsg)); | |
ea57084d | 1951 | #endif // __WXDEBUG__ |
c085e333 | 1952 | |
46851318 | 1953 | return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam); |
2bda0e17 KB |
1954 | } |
1955 | ||
1956 | bool wxWindow::MSWProcessMessage(WXMSG* pMsg) | |
1957 | { | |
2d0a075d JS |
1958 | if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) { |
1959 | // intercept dialog navigation keys | |
1960 | MSG *msg = (MSG *)pMsg; | |
1961 | bool bProcess = TRUE; | |
1962 | if ( msg->message != WM_KEYDOWN ) | |
1963 | bProcess = FALSE; | |
47cbd6da | 1964 | |
341c92a8 | 1965 | if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN ) |
2d0a075d | 1966 | bProcess = FALSE; |
47cbd6da | 1967 | |
341c92a8 VZ |
1968 | if ( bProcess ) |
1969 | { | |
1970 | bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0; | |
47cbd6da | 1971 | |
341c92a8 VZ |
1972 | // WM_GETDLGCODE: ask the control if it wants the key for itself, |
1973 | // don't process it if it's the case (except for Ctrl-Tab/Enter | |
1974 | // combinations which are always processed) | |
1975 | LONG lDlgCode = 0; | |
1976 | if ( !bCtrlDown ) | |
1977 | { | |
1978 | lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); | |
1979 | } | |
1980 | ||
1981 | bool bForward = TRUE, | |
1982 | bWindowChange = FALSE; | |
47cbd6da | 1983 | |
341c92a8 VZ |
1984 | switch ( msg->wParam ) |
1985 | { | |
fd3f686c | 1986 | case VK_TAB: |
3a19e16d | 1987 | if ( lDlgCode & DLGC_WANTTAB ) { |
fd3f686c | 1988 | bProcess = FALSE; |
3a19e16d VZ |
1989 | } |
1990 | else { | |
1991 | // Ctrl-Tab cycles thru notebook pages | |
1992 | bWindowChange = bCtrlDown; | |
fd3f686c | 1993 | bForward = !(::GetKeyState(VK_SHIFT) & 0x100); |
3a19e16d | 1994 | } |
fd3f686c | 1995 | break; |
47cbd6da | 1996 | |
fd3f686c VZ |
1997 | case VK_UP: |
1998 | case VK_LEFT: | |
1999 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
2000 | bProcess = FALSE; | |
2001 | else | |
2002 | bForward = FALSE; | |
2003 | break; | |
47cbd6da | 2004 | |
fd3f686c VZ |
2005 | case VK_DOWN: |
2006 | case VK_RIGHT: | |
2007 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
2008 | bProcess = FALSE; | |
2009 | break; | |
47cbd6da | 2010 | |
3a19e16d | 2011 | case VK_RETURN: |
341c92a8 VZ |
2012 | { |
2013 | if ( lDlgCode & DLGC_WANTMESSAGE ) | |
5fb9fcfc VZ |
2014 | { |
2015 | // control wants to process Enter itself, don't | |
2016 | // call IsDialogMessage() which would interpret | |
2017 | // it | |
2018 | return FALSE; | |
2019 | } | |
341c92a8 VZ |
2020 | |
2021 | wxButton *btnDefault = GetDefaultItem(); | |
2022 | if ( btnDefault && !bCtrlDown ) | |
2023 | { | |
2024 | // if there is a default button, Enter should | |
2025 | // press it | |
2026 | (void)::SendMessage((HWND)btnDefault->GetHWND(), | |
2027 | BM_CLICK, 0, 0); | |
2028 | return TRUE; | |
2029 | } | |
2030 | // else: but if there is not it makes sense to make it | |
2031 | // work like a TAB - and that's what we do. | |
2032 | // Note that Ctrl-Enter always works this way. | |
3a19e16d | 2033 | } |
341c92a8 | 2034 | break; |
3a19e16d | 2035 | |
fd3f686c VZ |
2036 | default: |
2037 | bProcess = FALSE; | |
2d0a075d | 2038 | } |
47cbd6da | 2039 | |
341c92a8 VZ |
2040 | if ( bProcess ) |
2041 | { | |
2042 | wxNavigationKeyEvent event; | |
2043 | event.SetDirection(bForward); | |
2044 | event.SetWindowChange(bWindowChange); | |
2045 | event.SetEventObject(this); | |
47cbd6da | 2046 | |
341c92a8 VZ |
2047 | if ( GetEventHandler()->ProcessEvent(event) ) |
2048 | return TRUE; | |
2049 | } | |
2d0a075d | 2050 | } |
47cbd6da | 2051 | |
341c92a8 VZ |
2052 | if ( ::IsDialogMessage((HWND)GetHWND(), msg) ) |
2053 | return TRUE; | |
2d0a075d | 2054 | } |
3a19e16d | 2055 | #if wxUSE_TOOLTIPS |
341c92a8 VZ |
2056 | if ( m_tooltip ) |
2057 | { | |
3a19e16d VZ |
2058 | // relay mouse move events to the tooltip control |
2059 | MSG *msg = (MSG *)pMsg; | |
2060 | if ( msg->message == WM_MOUSEMOVE ) | |
2061 | m_tooltip->RelayEvent(pMsg); | |
2062 | } | |
2063 | #endif // wxUSE_TOOLTIPS | |
47cbd6da | 2064 | |
2d0a075d | 2065 | return FALSE; |
2bda0e17 KB |
2066 | } |
2067 | ||
088a95f5 | 2068 | bool wxWindow::MSWTranslateMessage(WXMSG* pMsg) |
57a7b7c1 | 2069 | { |
088a95f5 | 2070 | if (m_acceleratorTable.Ok() && |
2d0a075d | 2071 | ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) |
088a95f5 JS |
2072 | return TRUE; |
2073 | else | |
2074 | return FALSE; | |
57a7b7c1 JS |
2075 | } |
2076 | ||
debe6624 | 2077 | long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate)) |
2bda0e17 | 2078 | { |
2d0a075d | 2079 | return 1; |
2bda0e17 KB |
2080 | } |
2081 | ||
fd3f686c | 2082 | void wxWindow::MSWDetachWindowMenu() |
2bda0e17 | 2083 | { |
2d0a075d | 2084 | if (m_hMenu) |
2bda0e17 | 2085 | { |
2d0a075d JS |
2086 | int N = GetMenuItemCount((HMENU) m_hMenu); |
2087 | int i; | |
2088 | for (i = 0; i < N; i++) | |
2089 | { | |
2090 | char buf[100]; | |
2091 | int chars = GetMenuString((HMENU) m_hMenu, i, buf, 100, MF_BYPOSITION); | |
2092 | if ((chars > 0) && (strcmp(buf, "&Window") == 0)) | |
2093 | { | |
2094 | RemoveMenu((HMENU) m_hMenu, i, MF_BYPOSITION); | |
2095 | break; | |
2096 | } | |
2097 | } | |
2bda0e17 | 2098 | } |
2bda0e17 KB |
2099 | } |
2100 | ||
fd3f686c | 2101 | bool wxWindow::MSWOnPaint() |
2bda0e17 | 2102 | { |
81d66cf3 | 2103 | #ifdef __WIN32__ |
2d0a075d JS |
2104 | HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle |
2105 | ::GetUpdateRgn((HWND) GetHWND(), hRegion, FALSE); | |
81d66cf3 | 2106 | |
2d0a075d | 2107 | m_updateRegion = wxRegion((WXHRGN) hRegion); |
81d66cf3 | 2108 | #else |
2d0a075d JS |
2109 | RECT updateRect; |
2110 | ::GetUpdateRect((HWND) GetHWND(), & updateRect, FALSE); | |
81d66cf3 | 2111 | |
2d0a075d JS |
2112 | m_updateRegion = wxRegion(updateRect.left, updateRect.top, |
2113 | updateRect.right - updateRect.left, updateRect.bottom - updateRect.top); | |
81d66cf3 | 2114 | #endif |
c085e333 | 2115 | |
2d0a075d JS |
2116 | wxPaintEvent event(m_windowId); |
2117 | event.SetEventObject(this); | |
2118 | if (!GetEventHandler()->ProcessEvent(event)) | |
2119 | Default(); | |
2120 | return TRUE; | |
2bda0e17 KB |
2121 | } |
2122 | ||
debe6624 | 2123 | void wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag)) |
2bda0e17 | 2124 | { |
2d0a075d JS |
2125 | if (m_inOnSize) |
2126 | return; | |
2127 | ||
2d0a075d JS |
2128 | if (!m_hWnd) |
2129 | return; | |
2bda0e17 | 2130 | |
2d0a075d | 2131 | m_inOnSize = TRUE; |
2bda0e17 | 2132 | |
2d0a075d JS |
2133 | wxSizeEvent event(wxSize(w, h), m_windowId); |
2134 | event.SetEventObject(this); | |
2135 | if (!GetEventHandler()->ProcessEvent(event)) | |
2136 | Default(); | |
2bda0e17 | 2137 | |
2d0a075d | 2138 | m_inOnSize = FALSE; |
2bda0e17 KB |
2139 | } |
2140 | ||
2141 | void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos)) | |
2142 | { | |
2143 | Default(); | |
2144 | } | |
2145 | ||
2146 | // Deal with child commands from buttons etc. | |
34138703 | 2147 | bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) |
2bda0e17 | 2148 | { |
2d0a075d JS |
2149 | if (wxCurrentPopupMenu) |
2150 | { | |
2151 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
2152 | wxCurrentPopupMenu = NULL; | |
2153 | bool succ = popupMenu->MSWCommand(cmd, id); | |
2154 | return succ; | |
2155 | } | |
c085e333 | 2156 | |
2d0a075d JS |
2157 | wxWindow *item = FindItem(id); |
2158 | if (item) | |
2159 | { | |
2160 | bool value = item->MSWCommand(cmd, id); | |
2d0a075d JS |
2161 | return value; |
2162 | } | |
2163 | else | |
2164 | { | |
2165 | wxWindow *win = wxFindWinFromHandle(control); | |
2166 | if (win) | |
2167 | return win->MSWCommand(cmd, id); | |
2168 | } | |
2169 | return FALSE; | |
2bda0e17 KB |
2170 | } |
2171 | ||
2172 | long wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam) | |
2173 | { | |
2174 | switch (wParam) | |
2175 | { | |
2d0a075d | 2176 | case SC_MAXIMIZE: |
2bda0e17 KB |
2177 | { |
2178 | wxMaximizeEvent event(m_windowId); | |
2179 | event.SetEventObject(this); | |
2180 | if (!GetEventHandler()->ProcessEvent(event)) | |
2181 | return Default(); | |
2182 | else | |
2183 | return 0; | |
2184 | break; | |
2185 | } | |
2d0a075d | 2186 | case SC_MINIMIZE: |
2bda0e17 KB |
2187 | { |
2188 | wxIconizeEvent event(m_windowId); | |
2189 | event.SetEventObject(this); | |
2190 | if (!GetEventHandler()->ProcessEvent(event)) | |
2191 | return Default(); | |
2192 | else | |
2193 | return 0; | |
2194 | break; | |
2195 | } | |
2d0a075d JS |
2196 | default: |
2197 | return Default(); | |
2bda0e17 KB |
2198 | } |
2199 | return 0; | |
2200 | } | |
2201 | ||
debe6624 | 2202 | void wxWindow::MSWOnLButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2203 | { |
2d0a075d | 2204 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
2bda0e17 | 2205 | |
2d0a075d JS |
2206 | event.m_x = x; event.m_y = y; |
2207 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2208 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2209 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2210 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2211 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2212 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2213 | event.m_eventObject = this; | |
2bda0e17 | 2214 | |
f5419957 | 2215 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DOWN; |
debe6624 | 2216 | |
2d0a075d JS |
2217 | if (!GetEventHandler()->ProcessEvent(event)) |
2218 | Default(); | |
2bda0e17 KB |
2219 | } |
2220 | ||
debe6624 | 2221 | void wxWindow::MSWOnLButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2222 | { |
2d0a075d | 2223 | wxMouseEvent event(wxEVT_LEFT_UP); |
2bda0e17 | 2224 | |
2d0a075d JS |
2225 | event.m_x = x; event.m_y = y; |
2226 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2227 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2228 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2229 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2230 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2231 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2232 | event.m_eventObject = this; | |
2bda0e17 | 2233 | |
2d0a075d | 2234 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_UP; |
2bda0e17 | 2235 | |
2d0a075d JS |
2236 | if (!GetEventHandler()->ProcessEvent(event)) |
2237 | Default(); | |
2bda0e17 KB |
2238 | } |
2239 | ||
debe6624 | 2240 | void wxWindow::MSWOnLButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2241 | { |
2d0a075d | 2242 | wxMouseEvent event(wxEVT_LEFT_DCLICK); |
2bda0e17 | 2243 | |
2d0a075d JS |
2244 | event.m_x = x; event.m_y = y; |
2245 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2246 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2247 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2248 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2249 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2250 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2251 | event.m_eventObject = this; | |
2bda0e17 | 2252 | |
2d0a075d | 2253 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DCLICK; |
2bda0e17 | 2254 | |
2d0a075d JS |
2255 | if (!GetEventHandler()->ProcessEvent(event)) |
2256 | Default(); | |
2bda0e17 KB |
2257 | } |
2258 | ||
debe6624 | 2259 | void wxWindow::MSWOnMButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2260 | { |
2d0a075d | 2261 | wxMouseEvent event(wxEVT_MIDDLE_DOWN); |
2bda0e17 | 2262 | |
2d0a075d JS |
2263 | event.m_x = x; event.m_y = y; |
2264 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2265 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2266 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2267 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2268 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2269 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2270 | event.m_eventObject = this; | |
2bda0e17 | 2271 | |
2d0a075d | 2272 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DOWN; |
debe6624 | 2273 | |
2d0a075d JS |
2274 | if (!GetEventHandler()->ProcessEvent(event)) |
2275 | Default(); | |
2bda0e17 KB |
2276 | } |
2277 | ||
debe6624 | 2278 | void wxWindow::MSWOnMButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2279 | { |
2d0a075d | 2280 | wxMouseEvent event(wxEVT_MIDDLE_UP); |
2bda0e17 | 2281 | |
2d0a075d JS |
2282 | event.m_x = x; event.m_y = y; |
2283 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2284 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2285 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2286 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2287 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2288 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2289 | event.m_eventObject = this; | |
2bda0e17 | 2290 | |
2d0a075d | 2291 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_UP; |
debe6624 | 2292 | |
2d0a075d JS |
2293 | if (!GetEventHandler()->ProcessEvent(event)) |
2294 | Default(); | |
2bda0e17 KB |
2295 | } |
2296 | ||
debe6624 | 2297 | void wxWindow::MSWOnMButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2298 | { |
2d0a075d | 2299 | wxMouseEvent event(wxEVT_MIDDLE_DCLICK); |
2bda0e17 | 2300 | |
2d0a075d JS |
2301 | event.m_x = x; event.m_y = y; |
2302 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2303 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2304 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2305 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2306 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2307 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2308 | event.m_eventObject = this; | |
2bda0e17 | 2309 | |
2d0a075d | 2310 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DCLICK; |
debe6624 | 2311 | |
2d0a075d JS |
2312 | if (!GetEventHandler()->ProcessEvent(event)) |
2313 | Default(); | |
2bda0e17 KB |
2314 | } |
2315 | ||
debe6624 | 2316 | void wxWindow::MSWOnRButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2317 | { |
2d0a075d | 2318 | wxMouseEvent event(wxEVT_RIGHT_DOWN); |
2bda0e17 | 2319 | |
2d0a075d JS |
2320 | event.m_x = x; event.m_y = y; |
2321 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2322 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2323 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2324 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2325 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2326 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2327 | event.m_eventObject = this; | |
2bda0e17 | 2328 | |
2d0a075d | 2329 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DOWN; |
debe6624 | 2330 | |
2d0a075d JS |
2331 | if (!GetEventHandler()->ProcessEvent(event)) |
2332 | Default(); | |
2bda0e17 KB |
2333 | } |
2334 | ||
debe6624 | 2335 | void wxWindow::MSWOnRButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2336 | { |
2d0a075d | 2337 | wxMouseEvent event(wxEVT_RIGHT_UP); |
2bda0e17 | 2338 | |
2d0a075d JS |
2339 | event.m_x = x; event.m_y = y; |
2340 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2341 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2342 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2343 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2344 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2345 | event.m_eventObject = this; | |
2346 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2bda0e17 | 2347 | |
2d0a075d | 2348 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_UP; |
debe6624 | 2349 | |
2d0a075d JS |
2350 | if (!GetEventHandler()->ProcessEvent(event)) |
2351 | Default(); | |
2bda0e17 KB |
2352 | } |
2353 | ||
debe6624 | 2354 | void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2355 | { |
2d0a075d | 2356 | wxMouseEvent event(wxEVT_RIGHT_DCLICK); |
2bda0e17 | 2357 | |
2d0a075d JS |
2358 | event.m_x = x; event.m_y = y; |
2359 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2360 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2361 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2362 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2363 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2364 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2365 | event.m_eventObject = this; | |
2bda0e17 | 2366 | |
2d0a075d | 2367 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DCLICK; |
debe6624 | 2368 | |
2d0a075d JS |
2369 | if (!GetEventHandler()->ProcessEvent(event)) |
2370 | Default(); | |
2bda0e17 KB |
2371 | } |
2372 | ||
debe6624 | 2373 | void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags) |
2bda0e17 | 2374 | { |
2d0a075d JS |
2375 | // 'normal' move event... |
2376 | // Set cursor, but only if we're not in 'busy' mode | |
2bda0e17 | 2377 | |
2d0a075d JS |
2378 | // Trouble with this is that it sets the cursor for controls too :-( |
2379 | if (m_windowCursor.Ok() && !wxIsBusy()) | |
2380 | ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR()); | |
2bda0e17 | 2381 | |
2d0a075d JS |
2382 | if (!m_mouseInWindow) |
2383 | { | |
2384 | // Generate an ENTER event | |
2385 | m_mouseInWindow = TRUE; | |
2386 | MSWOnMouseEnter(x, y, flags); | |
2387 | } | |
2bda0e17 | 2388 | |
2d0a075d | 2389 | wxMouseEvent event(wxEVT_MOTION); |
debe6624 | 2390 | |
2d0a075d JS |
2391 | event.m_x = x; event.m_y = y; |
2392 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2393 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2394 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2395 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2396 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2397 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2398 | event.m_eventObject = this; | |
2399 | ||
2400 | // Window gets a click down message followed by a mouse move | |
2401 | // message even if position isn't changed! We want to discard | |
2402 | // the trailing move event if x and y are the same. | |
2403 | if ((m_lastEvent == wxEVT_RIGHT_DOWN || m_lastEvent == wxEVT_LEFT_DOWN || | |
2404 | m_lastEvent == wxEVT_MIDDLE_DOWN) && | |
2405 | (m_lastXPos == event.m_x && m_lastYPos == event.m_y)) | |
2406 | { | |
2407 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2408 | m_lastEvent = wxEVT_MOTION; | |
2409 | return; | |
2410 | } | |
2411 | ||
2412 | m_lastEvent = wxEVT_MOTION; | |
2413 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2414 | ||
2415 | if (!GetEventHandler()->ProcessEvent(event)) | |
2416 | Default(); | |
2bda0e17 | 2417 | } |
2bda0e17 | 2418 | |
debe6624 | 2419 | void wxWindow::MSWOnMouseEnter(int x, int y, WXUINT flags) |
2bda0e17 | 2420 | { |
2d0a075d | 2421 | wxMouseEvent event(wxEVT_ENTER_WINDOW); |
2bda0e17 | 2422 | |
2d0a075d JS |
2423 | event.m_x = x; event.m_y = y; |
2424 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2425 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2426 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2427 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2428 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2429 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2430 | event.m_eventObject = this; | |
2bda0e17 | 2431 | |
2d0a075d JS |
2432 | m_lastEvent = wxEVT_ENTER_WINDOW; |
2433 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2434 | // No message - ensure we don't try to call the default behaviour accidentally. | |
2435 | m_lastMsg = 0; | |
2436 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2437 | } |
2438 | ||
debe6624 | 2439 | void wxWindow::MSWOnMouseLeave(int x, int y, WXUINT flags) |
2bda0e17 | 2440 | { |
2d0a075d | 2441 | wxMouseEvent event(wxEVT_LEAVE_WINDOW); |
2bda0e17 | 2442 | |
2d0a075d JS |
2443 | event.m_x = x; event.m_y = y; |
2444 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2445 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2446 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2447 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2448 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2449 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2450 | event.m_eventObject = this; | |
2bda0e17 | 2451 | |
2d0a075d JS |
2452 | m_lastEvent = wxEVT_LEAVE_WINDOW; |
2453 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2454 | // No message - ensure we don't try to call the default behaviour accidentally. | |
2455 | m_lastMsg = 0; | |
2456 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2457 | } |
2458 | ||
debe6624 | 2459 | void wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII) |
2bda0e17 | 2460 | { |
2d0a075d JS |
2461 | int id; |
2462 | bool tempControlDown = FALSE; | |
2463 | if (isASCII) | |
2bda0e17 | 2464 | { |
2d0a075d JS |
2465 | // If 1 -> 26, translate to CTRL plus a letter. |
2466 | id = wParam; | |
2467 | if ((id > 0) && (id < 27)) | |
2bda0e17 | 2468 | { |
2d0a075d JS |
2469 | switch (id) |
2470 | { | |
2471 | case 13: | |
2472 | { | |
2473 | id = WXK_RETURN; | |
2474 | break; | |
2475 | } | |
2476 | case 8: | |
2477 | { | |
2478 | id = WXK_BACK; | |
2479 | break; | |
2480 | } | |
2481 | case 9: | |
2482 | { | |
2483 | id = WXK_TAB; | |
2484 | break; | |
2485 | } | |
2486 | default: | |
2487 | { | |
2488 | tempControlDown = TRUE; | |
2489 | id = id + 96; | |
2490 | } | |
2491 | } | |
2bda0e17 | 2492 | } |
2bda0e17 | 2493 | } |
2d0a075d JS |
2494 | else if ((id = wxCharCodeMSWToWX(wParam)) == 0) { |
2495 | // it's ASCII and will be processed here only when called from | |
2496 | // WM_CHAR (i.e. when isASCII = TRUE) | |
2497 | id = -1; | |
2498 | } | |
2bda0e17 | 2499 | |
2d0a075d JS |
2500 | if (id != -1) |
2501 | { | |
2502 | wxKeyEvent event(wxEVT_CHAR); | |
2503 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2504 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2505 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2506 | event.m_altDown = TRUE; | |
2507 | ||
2508 | event.m_eventObject = this; | |
2509 | event.m_keyCode = id; | |
2510 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2511 | ||
2512 | POINT pt ; | |
2513 | GetCursorPos(&pt) ; | |
2514 | RECT rect ; | |
2515 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2516 | pt.x -= rect.left ; | |
2517 | pt.y -= rect.top ; | |
2518 | ||
2519 | event.m_x = pt.x; event.m_y = pt.y; | |
2520 | ||
2521 | if (!GetEventHandler()->ProcessEvent(event)) | |
2522 | Default(); | |
2523 | } | |
2bda0e17 KB |
2524 | } |
2525 | ||
4ce81a75 JS |
2526 | void wxWindow::MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam, bool isASCII) |
2527 | { | |
2528 | int id; | |
2529 | ||
2530 | if ((id = wxCharCodeMSWToWX(wParam)) == 0) { | |
2531 | id = wParam; | |
2532 | } | |
2533 | ||
2534 | if (id != -1) | |
2535 | { | |
2536 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
2537 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2538 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2539 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2540 | event.m_altDown = TRUE; | |
2541 | ||
2542 | event.m_eventObject = this; | |
2543 | event.m_keyCode = id; | |
2544 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2545 | ||
2546 | POINT pt ; | |
2547 | GetCursorPos(&pt) ; | |
2548 | RECT rect ; | |
2549 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2550 | pt.x -= rect.left ; | |
2551 | pt.y -= rect.top ; | |
2552 | ||
2553 | event.m_x = pt.x; event.m_y = pt.y; | |
2554 | ||
2555 | if (!GetEventHandler()->ProcessEvent(event)) | |
2556 | Default(); | |
2557 | } | |
2558 | } | |
2559 | ||
2560 | void wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam, bool isASCII) | |
2561 | { | |
2562 | int id; | |
2563 | ||
2564 | if ((id = wxCharCodeMSWToWX(wParam)) == 0) { | |
2565 | id = wParam; | |
2566 | } | |
2567 | ||
2568 | if (id != -1) | |
2569 | { | |
2570 | wxKeyEvent event(wxEVT_KEY_UP); | |
2571 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2572 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2573 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2574 | event.m_altDown = TRUE; | |
2575 | ||
2576 | event.m_eventObject = this; | |
2577 | event.m_keyCode = id; | |
2578 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2579 | ||
2580 | POINT pt ; | |
2581 | GetCursorPos(&pt) ; | |
2582 | RECT rect ; | |
2583 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2584 | pt.x -= rect.left ; | |
2585 | pt.y -= rect.top ; | |
2586 | ||
2587 | event.m_x = pt.x; event.m_y = pt.y; | |
2588 | ||
2589 | if (!GetEventHandler()->ProcessEvent(event)) | |
2590 | Default(); | |
2591 | } | |
2592 | } | |
2593 | ||
debe6624 | 2594 | void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2595 | { |
2596 | int buttons = 0; | |
2597 | int change = 0; | |
2598 | if (flags & JOY_BUTTON1CHG) | |
2599 | change = wxJOY_BUTTON1; | |
2600 | if (flags & JOY_BUTTON2CHG) | |
2601 | change = wxJOY_BUTTON2; | |
2602 | if (flags & JOY_BUTTON3CHG) | |
2603 | change = wxJOY_BUTTON3; | |
2604 | if (flags & JOY_BUTTON4CHG) | |
2605 | change = wxJOY_BUTTON4; | |
c085e333 | 2606 | |
2bda0e17 KB |
2607 | if (flags & JOY_BUTTON1) |
2608 | buttons |= wxJOY_BUTTON1; | |
2609 | if (flags & JOY_BUTTON2) | |
2610 | buttons |= wxJOY_BUTTON2; | |
2611 | if (flags & JOY_BUTTON3) | |
2612 | buttons |= wxJOY_BUTTON3; | |
2613 | if (flags & JOY_BUTTON4) | |
2614 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2615 | |
2bda0e17 KB |
2616 | wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN, buttons, joystick, change); |
2617 | event.SetPosition(wxPoint(x, y)); | |
2618 | event.SetEventObject(this); | |
c085e333 | 2619 | |
2bda0e17 KB |
2620 | GetEventHandler()->ProcessEvent(event); |
2621 | } | |
2622 | ||
debe6624 | 2623 | void wxWindow::MSWOnJoyUp(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2624 | { |
2625 | int buttons = 0; | |
2626 | int change = 0; | |
2627 | if (flags & JOY_BUTTON1CHG) | |
2628 | change = wxJOY_BUTTON1; | |
2629 | if (flags & JOY_BUTTON2CHG) | |
2630 | change = wxJOY_BUTTON2; | |
2631 | if (flags & JOY_BUTTON3CHG) | |
2632 | change = wxJOY_BUTTON3; | |
2633 | if (flags & JOY_BUTTON4CHG) | |
2634 | change = wxJOY_BUTTON4; | |
c085e333 | 2635 | |
2bda0e17 KB |
2636 | if (flags & JOY_BUTTON1) |
2637 | buttons |= wxJOY_BUTTON1; | |
2638 | if (flags & JOY_BUTTON2) | |
2639 | buttons |= wxJOY_BUTTON2; | |
2640 | if (flags & JOY_BUTTON3) | |
2641 | buttons |= wxJOY_BUTTON3; | |
2642 | if (flags & JOY_BUTTON4) | |
2643 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2644 | |
2bda0e17 KB |
2645 | wxJoystickEvent event(wxEVT_JOY_BUTTON_UP, buttons, joystick, change); |
2646 | event.SetPosition(wxPoint(x, y)); | |
2647 | event.SetEventObject(this); | |
c085e333 | 2648 | |
2bda0e17 KB |
2649 | GetEventHandler()->ProcessEvent(event); |
2650 | } | |
2651 | ||
debe6624 | 2652 | void wxWindow::MSWOnJoyMove(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2653 | { |
2654 | int buttons = 0; | |
2655 | if (flags & JOY_BUTTON1) | |
2656 | buttons |= wxJOY_BUTTON1; | |
2657 | if (flags & JOY_BUTTON2) | |
2658 | buttons |= wxJOY_BUTTON2; | |
2659 | if (flags & JOY_BUTTON3) | |
2660 | buttons |= wxJOY_BUTTON3; | |
2661 | if (flags & JOY_BUTTON4) | |
2662 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2663 | |
2bda0e17 KB |
2664 | wxJoystickEvent event(wxEVT_JOY_MOVE, buttons, joystick, 0); |
2665 | event.SetPosition(wxPoint(x, y)); | |
2666 | event.SetEventObject(this); | |
c085e333 | 2667 | |
2bda0e17 KB |
2668 | GetEventHandler()->ProcessEvent(event); |
2669 | } | |
2670 | ||
debe6624 | 2671 | void wxWindow::MSWOnJoyZMove(int joystick, int z, WXUINT flags) |
2bda0e17 KB |
2672 | { |
2673 | int buttons = 0; | |
2674 | if (flags & JOY_BUTTON1) | |
2675 | buttons |= wxJOY_BUTTON1; | |
2676 | if (flags & JOY_BUTTON2) | |
2677 | buttons |= wxJOY_BUTTON2; | |
2678 | if (flags & JOY_BUTTON3) | |
2679 | buttons |= wxJOY_BUTTON3; | |
2680 | if (flags & JOY_BUTTON4) | |
2681 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2682 | |
2bda0e17 KB |
2683 | wxJoystickEvent event(wxEVT_JOY_ZMOVE, buttons, joystick, 0); |
2684 | event.SetZPosition(z); | |
2685 | event.SetEventObject(this); | |
c085e333 | 2686 | |
2bda0e17 KB |
2687 | GetEventHandler()->ProcessEvent(event); |
2688 | } | |
2689 | ||
debe6624 | 2690 | void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) |
2bda0e17 | 2691 | { |
2d0a075d | 2692 | if (control) |
564b2609 | 2693 | { |
2d0a075d JS |
2694 | wxWindow *child = wxFindWinFromHandle(control); |
2695 | if ( child ) | |
2696 | child->MSWOnVScroll(wParam, pos, control); | |
2697 | return; | |
564b2609 | 2698 | } |
2bda0e17 | 2699 | |
564b2609 VZ |
2700 | wxScrollEvent event; |
2701 | event.SetPosition(pos); | |
2d0a075d | 2702 | event.SetOrientation(wxVERTICAL); |
564b2609 | 2703 | event.m_eventObject = this; |
2d0a075d | 2704 | |
564b2609 VZ |
2705 | switch ( wParam ) |
2706 | { | |
2d0a075d | 2707 | case SB_TOP: |
564b2609 VZ |
2708 | event.m_eventType = wxEVT_SCROLL_TOP; |
2709 | break; | |
2d0a075d JS |
2710 | |
2711 | case SB_BOTTOM: | |
564b2609 VZ |
2712 | event.m_eventType = wxEVT_SCROLL_BOTTOM; |
2713 | break; | |
2d0a075d JS |
2714 | |
2715 | case SB_LINEUP: | |
564b2609 VZ |
2716 | event.m_eventType = wxEVT_SCROLL_LINEUP; |
2717 | break; | |
2d0a075d JS |
2718 | |
2719 | case SB_LINEDOWN: | |
564b2609 VZ |
2720 | event.m_eventType = wxEVT_SCROLL_LINEDOWN; |
2721 | break; | |
2d0a075d JS |
2722 | |
2723 | case SB_PAGEUP: | |
564b2609 VZ |
2724 | event.m_eventType = wxEVT_SCROLL_PAGEUP; |
2725 | break; | |
2d0a075d JS |
2726 | |
2727 | case SB_PAGEDOWN: | |
564b2609 VZ |
2728 | event.m_eventType = wxEVT_SCROLL_PAGEDOWN; |
2729 | break; | |
2d0a075d JS |
2730 | |
2731 | case SB_THUMBTRACK: | |
2732 | case SB_THUMBPOSITION: | |
564b2609 VZ |
2733 | event.m_eventType = wxEVT_SCROLL_THUMBTRACK; |
2734 | break; | |
2d0a075d JS |
2735 | |
2736 | default: | |
564b2609 | 2737 | return; |
2d0a075d | 2738 | break; |
564b2609 | 2739 | } |
c085e333 | 2740 | |
2d0a075d JS |
2741 | if (!GetEventHandler()->ProcessEvent(event)) |
2742 | Default(); | |
2743 | } | |
2744 | ||
2745 | void wxWindow::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control) | |
2746 | { | |
2747 | if (control) | |
2748 | { | |
2749 | wxWindow *child = wxFindWinFromHandle(control); | |
2750 | if ( child ) { | |
2751 | child->MSWOnHScroll(wParam, pos, control); | |
2752 | ||
2753 | return; | |
2754 | } | |
2755 | } | |
2756 | else { | |
2757 | wxScrollEvent event; | |
2758 | event.SetPosition(pos); | |
2759 | event.SetOrientation(wxHORIZONTAL); | |
2760 | event.m_eventObject = this; | |
2761 | ||
2762 | switch ( wParam ) | |
2763 | { | |
2764 | case SB_TOP: | |
2765 | event.m_eventType = wxEVT_SCROLL_TOP; | |
2766 | break; | |
2767 | ||
2768 | case SB_BOTTOM: | |
2769 | event.m_eventType = wxEVT_SCROLL_BOTTOM; | |
2770 | break; | |
2771 | ||
2772 | case SB_LINEUP: | |
2773 | event.m_eventType = wxEVT_SCROLL_LINEUP; | |
2774 | break; | |
2bda0e17 | 2775 | |
2d0a075d JS |
2776 | case SB_LINEDOWN: |
2777 | event.m_eventType = wxEVT_SCROLL_LINEDOWN; | |
2778 | break; | |
2779 | ||
2780 | case SB_PAGEUP: | |
2781 | event.m_eventType = wxEVT_SCROLL_PAGEUP; | |
2782 | break; | |
2783 | ||
2784 | case SB_PAGEDOWN: | |
2785 | event.m_eventType = wxEVT_SCROLL_PAGEDOWN; | |
2786 | break; | |
2787 | ||
2788 | case SB_THUMBTRACK: | |
2789 | case SB_THUMBPOSITION: | |
2790 | event.m_eventType = wxEVT_SCROLL_THUMBTRACK; | |
2791 | break; | |
2792 | ||
2793 | default: | |
2794 | return; | |
2795 | } | |
2bda0e17 | 2796 | |
2d0a075d JS |
2797 | if ( GetEventHandler()->ProcessEvent(event) ) |
2798 | return; | |
2799 | } | |
2800 | ||
2801 | // call the default WM_HSCROLL handler: it's non trivial in some common | |
2802 | // controls (up-down control for example) | |
2803 | Default(); | |
2bda0e17 KB |
2804 | } |
2805 | ||
2806 | void wxWindow::MSWOnShow(bool show, int status) | |
2807 | { | |
2d0a075d JS |
2808 | wxShowEvent event(GetId(), show); |
2809 | event.m_eventObject = this; | |
2810 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2811 | } |
2812 | ||
2813 | bool wxWindow::MSWOnInitDialog(WXHWND WXUNUSED(hWndFocus)) | |
2814 | { | |
2d0a075d JS |
2815 | wxInitDialogEvent event(GetId()); |
2816 | event.m_eventObject = this; | |
2817 | GetEventHandler()->ProcessEvent(event); | |
2818 | return TRUE; | |
2bda0e17 KB |
2819 | } |
2820 | ||
fd3f686c | 2821 | void wxWindow::InitDialog() |
2bda0e17 | 2822 | { |
2d0a075d JS |
2823 | wxInitDialogEvent event(GetId()); |
2824 | event.SetEventObject( this ); | |
2825 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2826 | } |
2827 | ||
2828 | // Default init dialog behaviour is to transfer data to window | |
2829 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
2830 | { | |
2d0a075d | 2831 | TransferDataToWindow(); |
2bda0e17 KB |
2832 | } |
2833 | ||
2834 | void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font) | |
2835 | { | |
2d0a075d JS |
2836 | TEXTMETRIC tm; |
2837 | HDC dc = ::GetDC((HWND) wnd); | |
2838 | HFONT fnt =0; | |
2839 | HFONT was = 0; | |
2840 | if (the_font) | |
2841 | { | |
2d0a075d JS |
2842 | // the_font->UseResource(); |
2843 | // the_font->RealizeResource(); | |
fd3f686c VZ |
2844 | fnt = (HFONT)the_font->GetResourceHandle(); |
2845 | if ( fnt ) | |
2d0a075d JS |
2846 | was = (HFONT) SelectObject(dc,fnt) ; |
2847 | } | |
2848 | GetTextMetrics(dc, &tm); | |
2849 | if (the_font && fnt && was) | |
2850 | { | |
2d0a075d JS |
2851 | SelectObject(dc,was) ; |
2852 | } | |
2853 | ReleaseDC((HWND)wnd, dc); | |
2854 | *x = tm.tmAveCharWidth; | |
2855 | *y = tm.tmHeight + tm.tmExternalLeading; | |
2bda0e17 | 2856 | |
2d0a075d JS |
2857 | // if (the_font) |
2858 | // the_font->ReleaseResource(); | |
2bda0e17 KB |
2859 | } |
2860 | ||
2861 | // Returns 0 if was a normal ASCII value, not a special key. This indicates that | |
2862 | // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead. | |
2863 | int wxCharCodeMSWToWX(int keySym) | |
2864 | { | |
2d0a075d JS |
2865 | int id = 0; |
2866 | switch (keySym) | |
2867 | { | |
2868 | case VK_CANCEL: id = WXK_CANCEL; break; | |
2869 | case VK_BACK: id = WXK_BACK; break; | |
2870 | case VK_TAB: id = WXK_TAB; break; | |
564b2609 VZ |
2871 | case VK_CLEAR: id = WXK_CLEAR; break; |
2872 | case VK_RETURN: id = WXK_RETURN; break; | |
2873 | case VK_SHIFT: id = WXK_SHIFT; break; | |
2d0a075d | 2874 | case VK_CONTROL: id = WXK_CONTROL; break; |
564b2609 VZ |
2875 | case VK_MENU : id = WXK_MENU; break; |
2876 | case VK_PAUSE: id = WXK_PAUSE; break; | |
2877 | case VK_SPACE: id = WXK_SPACE; break; | |
2878 | case VK_ESCAPE: id = WXK_ESCAPE; break; | |
2879 | case VK_PRIOR: id = WXK_PRIOR; break; | |
2880 | case VK_NEXT : id = WXK_NEXT; break; | |
2881 | case VK_END: id = WXK_END; break; | |
2882 | case VK_HOME : id = WXK_HOME; break; | |
2883 | case VK_LEFT : id = WXK_LEFT; break; | |
2d0a075d | 2884 | case VK_UP: id = WXK_UP; break; |
564b2609 VZ |
2885 | case VK_RIGHT: id = WXK_RIGHT; break; |
2886 | case VK_DOWN : id = WXK_DOWN; break; | |
2887 | case VK_SELECT: id = WXK_SELECT; break; | |
2888 | case VK_PRINT: id = WXK_PRINT; break; | |
2d0a075d | 2889 | case VK_EXECUTE: id = WXK_EXECUTE; break; |
564b2609 VZ |
2890 | case VK_INSERT: id = WXK_INSERT; break; |
2891 | case VK_DELETE: id = WXK_DELETE; break; | |
2892 | case VK_HELP : id = WXK_HELP; break; | |
2d0a075d JS |
2893 | case VK_NUMPAD0: id = WXK_NUMPAD0; break; |
2894 | case VK_NUMPAD1: id = WXK_NUMPAD1; break; | |
2895 | case VK_NUMPAD2: id = WXK_NUMPAD2; break; | |
2896 | case VK_NUMPAD3: id = WXK_NUMPAD3; break; | |
2897 | case VK_NUMPAD4: id = WXK_NUMPAD4; break; | |
2898 | case VK_NUMPAD5: id = WXK_NUMPAD5; break; | |
2899 | case VK_NUMPAD6: id = WXK_NUMPAD6; break; | |
2900 | case VK_NUMPAD7: id = WXK_NUMPAD7; break; | |
2901 | case VK_NUMPAD8: id = WXK_NUMPAD8; break; | |
2902 | case VK_NUMPAD9: id = WXK_NUMPAD9; break; | |
2903 | case VK_MULTIPLY: id = WXK_MULTIPLY; break; | |
564b2609 | 2904 | case VK_ADD: id = WXK_ADD; break; |
2d0a075d JS |
2905 | case VK_SUBTRACT: id = WXK_SUBTRACT; break; |
2906 | case VK_DECIMAL: id = WXK_DECIMAL; break; | |
564b2609 | 2907 | case VK_DIVIDE: id = WXK_DIVIDE; break; |
2d0a075d JS |
2908 | case VK_F1: id = WXK_F1; break; |
2909 | case VK_F2: id = WXK_F2; break; | |
2910 | case VK_F3: id = WXK_F3; break; | |
2911 | case VK_F4: id = WXK_F4; break; | |
2912 | case VK_F5: id = WXK_F5; break; | |
2913 | case VK_F6: id = WXK_F6; break; | |
2914 | case VK_F7: id = WXK_F7; break; | |
2915 | case VK_F8: id = WXK_F8; break; | |
2916 | case VK_F9: id = WXK_F9; break; | |
564b2609 VZ |
2917 | case VK_F10: id = WXK_F10; break; |
2918 | case VK_F11: id = WXK_F11; break; | |
2919 | case VK_F12: id = WXK_F12; break; | |
2920 | case VK_F13: id = WXK_F13; break; | |
2921 | case VK_F14: id = WXK_F14; break; | |
2922 | case VK_F15: id = WXK_F15; break; | |
2923 | case VK_F16: id = WXK_F16; break; | |
2924 | case VK_F17: id = WXK_F17; break; | |
2925 | case VK_F18: id = WXK_F18; break; | |
2926 | case VK_F19: id = WXK_F19; break; | |
2927 | case VK_F20: id = WXK_F20; break; | |
2928 | case VK_F21: id = WXK_F21; break; | |
2929 | case VK_F22: id = WXK_F22; break; | |
2930 | case VK_F23: id = WXK_F23; break; | |
2931 | case VK_F24: id = WXK_F24; break; | |
2d0a075d | 2932 | case VK_NUMLOCK: id = WXK_NUMLOCK; break; |
564b2609 | 2933 | case VK_SCROLL: id = WXK_SCROLL; break; |
2bda0e17 | 2934 | default: |
2d0a075d JS |
2935 | { |
2936 | return 0; | |
2937 | } | |
2bda0e17 | 2938 | } |
2d0a075d | 2939 | return id; |
2bda0e17 KB |
2940 | } |
2941 | ||
2942 | int wxCharCodeWXToMSW(int id, bool *isVirtual) | |
2943 | { | |
2d0a075d JS |
2944 | *isVirtual = TRUE; |
2945 | int keySym = 0; | |
2946 | switch (id) | |
2947 | { | |
2948 | case WXK_CANCEL: keySym = VK_CANCEL; break; | |
564b2609 VZ |
2949 | case WXK_CLEAR: keySym = VK_CLEAR; break; |
2950 | case WXK_SHIFT: keySym = VK_SHIFT; break; | |
2d0a075d | 2951 | case WXK_CONTROL: keySym = VK_CONTROL; break; |
564b2609 VZ |
2952 | case WXK_MENU : keySym = VK_MENU; break; |
2953 | case WXK_PAUSE: keySym = VK_PAUSE; break; | |
2954 | case WXK_PRIOR: keySym = VK_PRIOR; break; | |
2955 | case WXK_NEXT : keySym = VK_NEXT; break; | |
2956 | case WXK_END: keySym = VK_END; break; | |
2957 | case WXK_HOME : keySym = VK_HOME; break; | |
2958 | case WXK_LEFT : keySym = VK_LEFT; break; | |
2959 | case WXK_UP: keySym = VK_UP; break; | |
2960 | case WXK_RIGHT: keySym = VK_RIGHT; break; | |
2961 | case WXK_DOWN : keySym = VK_DOWN; break; | |
2d0a075d | 2962 | case WXK_SELECT: keySym = VK_SELECT; break; |
564b2609 | 2963 | case WXK_PRINT: keySym = VK_PRINT; break; |
2d0a075d JS |
2964 | case WXK_EXECUTE: keySym = VK_EXECUTE; break; |
2965 | case WXK_INSERT: keySym = VK_INSERT; break; | |
2966 | case WXK_DELETE: keySym = VK_DELETE; break; | |
564b2609 | 2967 | case WXK_HELP : keySym = VK_HELP; break; |
2d0a075d JS |
2968 | case WXK_NUMPAD0: keySym = VK_NUMPAD0; break; |
2969 | case WXK_NUMPAD1: keySym = VK_NUMPAD1; break; | |
2970 | case WXK_NUMPAD2: keySym = VK_NUMPAD2; break; | |
2971 | case WXK_NUMPAD3: keySym = VK_NUMPAD3; break; | |
2972 | case WXK_NUMPAD4: keySym = VK_NUMPAD4; break; | |
2973 | case WXK_NUMPAD5: keySym = VK_NUMPAD5; break; | |
2974 | case WXK_NUMPAD6: keySym = VK_NUMPAD6; break; | |
2975 | case WXK_NUMPAD7: keySym = VK_NUMPAD7; break; | |
2976 | case WXK_NUMPAD8: keySym = VK_NUMPAD8; break; | |
2977 | case WXK_NUMPAD9: keySym = VK_NUMPAD9; break; | |
2978 | case WXK_MULTIPLY: keySym = VK_MULTIPLY; break; | |
564b2609 | 2979 | case WXK_ADD: keySym = VK_ADD; break; |
2d0a075d JS |
2980 | case WXK_SUBTRACT: keySym = VK_SUBTRACT; break; |
2981 | case WXK_DECIMAL: keySym = VK_DECIMAL; break; | |
2982 | case WXK_DIVIDE: keySym = VK_DIVIDE; break; | |
564b2609 VZ |
2983 | case WXK_F1: keySym = VK_F1; break; |
2984 | case WXK_F2: keySym = VK_F2; break; | |
2985 | case WXK_F3: keySym = VK_F3; break; | |
2986 | case WXK_F4: keySym = VK_F4; break; | |
2987 | case WXK_F5: keySym = VK_F5; break; | |
2988 | case WXK_F6: keySym = VK_F6; break; | |
2989 | case WXK_F7: keySym = VK_F7; break; | |
2990 | case WXK_F8: keySym = VK_F8; break; | |
2991 | case WXK_F9: keySym = VK_F9; break; | |
2992 | case WXK_F10: keySym = VK_F10; break; | |
2993 | case WXK_F11: keySym = VK_F11; break; | |
2994 | case WXK_F12: keySym = VK_F12; break; | |
2995 | case WXK_F13: keySym = VK_F13; break; | |
2996 | case WXK_F14: keySym = VK_F14; break; | |
2997 | case WXK_F15: keySym = VK_F15; break; | |
2998 | case WXK_F16: keySym = VK_F16; break; | |
2999 | case WXK_F17: keySym = VK_F17; break; | |
3000 | case WXK_F18: keySym = VK_F18; break; | |
3001 | case WXK_F19: keySym = VK_F19; break; | |
3002 | case WXK_F20: keySym = VK_F20; break; | |
3003 | case WXK_F21: keySym = VK_F21; break; | |
3004 | case WXK_F22: keySym = VK_F22; break; | |
3005 | case WXK_F23: keySym = VK_F23; break; | |
3006 | case WXK_F24: keySym = VK_F24; break; | |
2d0a075d JS |
3007 | case WXK_NUMLOCK: keySym = VK_NUMLOCK; break; |
3008 | case WXK_SCROLL: keySym = VK_SCROLL; break; | |
2bda0e17 | 3009 | default: |
2d0a075d JS |
3010 | { |
3011 | *isVirtual = FALSE; | |
3012 | keySym = id; | |
3013 | break; | |
3014 | } | |
2bda0e17 | 3015 | } |
2d0a075d | 3016 | return keySym; |
2bda0e17 KB |
3017 | } |
3018 | ||
3019 | // Caret manipulation | |
debe6624 | 3020 | void wxWindow::CreateCaret(int w, int h) |
2bda0e17 | 3021 | { |
2d0a075d JS |
3022 | m_caretWidth = w; |
3023 | m_caretHeight = h; | |
3024 | m_caretEnabled = TRUE; | |
2bda0e17 KB |
3025 | } |
3026 | ||
3027 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) | |
3028 | { | |
2d0a075d | 3029 | // Not implemented |
2bda0e17 KB |
3030 | } |
3031 | ||
debe6624 | 3032 | void wxWindow::ShowCaret(bool show) |
2bda0e17 | 3033 | { |
2d0a075d JS |
3034 | if (m_caretEnabled) |
3035 | { | |
3036 | if (show) | |
3037 | ::ShowCaret((HWND) GetHWND()); | |
3038 | else | |
3039 | ::HideCaret((HWND) GetHWND()); | |
3040 | m_caretShown = show; | |
3041 | } | |
2bda0e17 KB |
3042 | } |
3043 | ||
fd3f686c | 3044 | void wxWindow::DestroyCaret() |
2bda0e17 | 3045 | { |
2d0a075d | 3046 | m_caretEnabled = FALSE; |
2bda0e17 KB |
3047 | } |
3048 | ||
debe6624 | 3049 | void wxWindow::SetCaretPos(int x, int y) |
2bda0e17 | 3050 | { |
2d0a075d | 3051 | ::SetCaretPos(x, y); |
2bda0e17 KB |
3052 | } |
3053 | ||
3054 | void wxWindow::GetCaretPos(int *x, int *y) const | |
3055 | { | |
2d0a075d JS |
3056 | POINT point; |
3057 | ::GetCaretPos(&point); | |
3058 | *x = point.x; | |
3059 | *y = point.y; | |
2bda0e17 KB |
3060 | } |
3061 | ||
fd3f686c | 3062 | wxWindow *wxGetActiveWindow() |
2bda0e17 | 3063 | { |
2d0a075d JS |
3064 | HWND hWnd = GetActiveWindow(); |
3065 | if (hWnd != 0) | |
3066 | { | |
3067 | return wxFindWinFromHandle((WXHWND) hWnd); | |
3068 | } | |
3069 | return NULL; | |
2bda0e17 KB |
3070 | } |
3071 | ||
3072 | // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE | |
3073 | // in active frames and dialogs, regardless of where the focus is. | |
3074 | static HHOOK wxTheKeyboardHook = 0; | |
3075 | static FARPROC wxTheKeyboardHookProc = 0; | |
3076 | int APIENTRY _EXPORT | |
2d0a075d | 3077 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam); |
2bda0e17 KB |
3078 | |
3079 | void wxSetKeyboardHook(bool doIt) | |
3080 | { | |
2d0a075d JS |
3081 | if (doIt) |
3082 | { | |
3083 | wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance()); | |
3084 | wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(), | |
57c208c5 | 3085 | #if defined(__WIN32__) && !defined(__TWIN32__) |
2d0a075d JS |
3086 | GetCurrentThreadId()); |
3087 | // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right? | |
2bda0e17 | 3088 | #else |
2d0a075d | 3089 | GetCurrentTask()); |
2bda0e17 | 3090 | #endif |
2d0a075d JS |
3091 | } |
3092 | else | |
3093 | { | |
3094 | UnhookWindowsHookEx(wxTheKeyboardHook); | |
3095 | FreeProcInstance(wxTheKeyboardHookProc); | |
3096 | } | |
2bda0e17 KB |
3097 | } |
3098 | ||
3099 | int APIENTRY _EXPORT | |
2d0a075d | 3100 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) |
2bda0e17 | 3101 | { |
2d0a075d JS |
3102 | DWORD hiWord = HIWORD(lParam); |
3103 | if (nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0)) | |
2bda0e17 | 3104 | { |
2d0a075d JS |
3105 | int id; |
3106 | if ((id = wxCharCodeMSWToWX(wParam)) != 0) | |
564b2609 | 3107 | { |
2d0a075d JS |
3108 | wxKeyEvent event(wxEVT_CHAR_HOOK); |
3109 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
3110 | event.m_altDown = TRUE; | |
3111 | ||
3112 | event.m_eventObject = NULL; | |
3113 | event.m_keyCode = id; | |
3114 | /* begin Albert's fix for control and shift key 26.5 */ | |
3115 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
3116 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
3117 | /* end Albert's fix for control and shift key 26.5 */ | |
3118 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
3119 | ||
3120 | wxWindow *win = wxGetActiveWindow(); | |
3121 | if (win) | |
3122 | { | |
3123 | if (win->GetEventHandler()->ProcessEvent(event)) | |
3124 | return 1; | |
3125 | } | |
3126 | else | |
3127 | { | |
3128 | if ( wxTheApp && wxTheApp->ProcessEvent(event) ) | |
3129 | return 1; | |
3130 | } | |
564b2609 | 3131 | } |
2bda0e17 | 3132 | } |
2d0a075d | 3133 | return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam); |
2bda0e17 KB |
3134 | } |
3135 | ||
debe6624 | 3136 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) |
2bda0e17 | 3137 | { |
2d0a075d JS |
3138 | m_minSizeX = minW; |
3139 | m_minSizeY = minH; | |
3140 | m_maxSizeX = maxW; | |
3141 | m_maxSizeY = maxH; | |
2bda0e17 KB |
3142 | } |
3143 | ||
debe6624 | 3144 | void wxWindow::Centre(int direction) |
2bda0e17 | 3145 | { |
2d0a075d | 3146 | int x, y, width, height, panel_width, panel_height, new_x, new_y; |
2bda0e17 | 3147 | |
2d0a075d JS |
3148 | wxWindow *father = (wxWindow *)GetParent(); |
3149 | if (!father) | |
3150 | return; | |
2bda0e17 | 3151 | |
2d0a075d JS |
3152 | father->GetClientSize(&panel_width, &panel_height); |
3153 | GetSize(&width, &height); | |
3154 | GetPosition(&x, &y); | |
2bda0e17 | 3155 | |
2d0a075d JS |
3156 | new_x = -1; |
3157 | new_y = -1; | |
2bda0e17 | 3158 | |
2d0a075d JS |
3159 | if (direction & wxHORIZONTAL) |
3160 | new_x = (int)((panel_width - width)/2); | |
2bda0e17 | 3161 | |
2d0a075d JS |
3162 | if (direction & wxVERTICAL) |
3163 | new_y = (int)((panel_height - height)/2); | |
2bda0e17 | 3164 | |
2d0a075d | 3165 | SetSize(new_x, new_y, -1, -1); |
2bda0e17 KB |
3166 | |
3167 | } | |
3168 | ||
debe6624 | 3169 | void wxWindow::WarpPointer (int x_pos, int y_pos) |
2bda0e17 | 3170 | { |
5de76427 JS |
3171 | // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in |
3172 | // pixel coordinates, relatives to the canvas -- So, we first need to | |
3173 | // substract origin of the window, then convert to screen position | |
c085e333 | 3174 | |
5de76427 JS |
3175 | int x = x_pos; int y = y_pos; |
3176 | RECT rect; | |
3177 | GetWindowRect ((HWND) GetHWND(), &rect); | |
c085e333 | 3178 | |
5de76427 JS |
3179 | x += rect.left; |
3180 | y += rect.top; | |
c085e333 | 3181 | |
5de76427 | 3182 | SetCursorPos (x, y); |
2bda0e17 KB |
3183 | } |
3184 | ||
3185 | void wxWindow::MSWDeviceToLogical (float *x, float *y) const | |
3186 | { | |
2bda0e17 KB |
3187 | } |
3188 | ||
debe6624 | 3189 | bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC) |
2bda0e17 KB |
3190 | { |
3191 | wxDC dc ; | |
c085e333 | 3192 | |
564b2609 VZ |
3193 | dc.SetHDC(pDC); |
3194 | dc.SetWindow(this); | |
3195 | dc.BeginDrawing(); | |
c085e333 | 3196 | |
2bda0e17 KB |
3197 | wxEraseEvent event(m_windowId, &dc); |
3198 | event.m_eventObject = this; | |
3199 | if (!GetEventHandler()->ProcessEvent(event)) | |
3200 | { | |
564b2609 VZ |
3201 | dc.EndDrawing(); |
3202 | dc.SelectOldObjects(pDC); | |
2bda0e17 KB |
3203 | return FALSE; |
3204 | } | |
3205 | else | |
3206 | { | |
564b2609 VZ |
3207 | dc.EndDrawing(); |
3208 | dc.SelectOldObjects(pDC); | |
2bda0e17 | 3209 | } |
c085e333 | 3210 | |
2bda0e17 KB |
3211 | dc.SetHDC((WXHDC) NULL); |
3212 | return TRUE; | |
3213 | } | |
3214 | ||
3215 | void wxWindow::OnEraseBackground(wxEraseEvent& event) | |
3216 | { | |
ce3ed50d JS |
3217 | if (!GetHWND()) |
3218 | return; | |
3219 | ||
2d0a075d JS |
3220 | RECT rect; |
3221 | ::GetClientRect((HWND) GetHWND(), &rect); | |
2bda0e17 | 3222 | |
ce3ed50d JS |
3223 | COLORREF ref = PALETTERGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()) ; |
3224 | HBRUSH hBrush = ::CreateSolidBrush(ref); | |
2d0a075d | 3225 | int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT); |
2bda0e17 | 3226 | |
2d0a075d JS |
3227 | // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect); |
3228 | ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); | |
3229 | ::DeleteObject(hBrush); | |
3230 | ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); | |
3231 | /* | |
3232 | // Less efficient version (and doesn't account for scrolling) | |
3233 | int w, h; | |
3234 | GetClientSize(& w, & h); | |
3235 | wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID); | |
3236 | event.GetDC()->SetBrush(brush); | |
3237 | event.GetDC()->SetPen(wxTRANSPARENT_PEN); | |
3238 | ||
3239 | event.GetDC()->DrawRectangle(0, 0, w+1, h+1); | |
3240 | */ | |
2bda0e17 KB |
3241 | } |
3242 | ||
3243 | #if WXWIN_COMPATIBILITY | |
debe6624 | 3244 | void wxWindow::SetScrollRange(int orient, int range, bool refresh) |
2bda0e17 KB |
3245 | { |
3246 | #if defined(__WIN95__) | |
c085e333 | 3247 | |
2d0a075d | 3248 | int range1 = range; |
2bda0e17 | 3249 | |
2d0a075d JS |
3250 | // Try to adjust the range to cope with page size > 1 |
3251 | // - a Windows API quirk | |
3252 | int pageSize = GetScrollPage(orient); | |
3253 | if ( pageSize > 1 && range > 0) | |
3254 | { | |
3255 | range1 += (pageSize - 1); | |
3256 | } | |
2bda0e17 | 3257 | |
2d0a075d JS |
3258 | SCROLLINFO info; |
3259 | int dir; | |
2bda0e17 | 3260 | |
2d0a075d JS |
3261 | if (orient == wxHORIZONTAL) { |
3262 | dir = SB_HORZ; | |
3263 | } else { | |
3264 | dir = SB_VERT; | |
3265 | } | |
2bda0e17 | 3266 | |
2d0a075d JS |
3267 | info.cbSize = sizeof(SCROLLINFO); |
3268 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
3269 | info.nMin = 0; | |
3270 | info.nMax = range1; | |
3271 | info.nPos = 0; | |
3272 | info.fMask = SIF_RANGE | SIF_PAGE; | |
2bda0e17 | 3273 | |
2d0a075d JS |
3274 | HWND hWnd = (HWND) GetHWND(); |
3275 | if (hWnd) | |
3276 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3277 | #else |
2d0a075d JS |
3278 | int wOrient ; |
3279 | if (orient == wxHORIZONTAL) | |
3280 | wOrient = SB_HORZ; | |
3281 | else | |
3282 | wOrient = SB_VERT; | |
3283 | ||
3284 | HWND hWnd = (HWND) GetHWND(); | |
3285 | if (hWnd) | |
3286 | ::SetScrollRange(hWnd, wOrient, 0, range, refresh); | |
2bda0e17 KB |
3287 | #endif |
3288 | } | |
3289 | ||
debe6624 | 3290 | void wxWindow::SetScrollPage(int orient, int page, bool refresh) |
2bda0e17 KB |
3291 | { |
3292 | #if defined(__WIN95__) | |
2d0a075d JS |
3293 | SCROLLINFO info; |
3294 | int dir; | |
3295 | ||
3296 | if (orient == wxHORIZONTAL) { | |
3297 | dir = SB_HORZ; | |
3298 | m_xThumbSize = page; | |
3299 | } else { | |
3300 | dir = SB_VERT; | |
3301 | m_yThumbSize = page; | |
3302 | } | |
2bda0e17 | 3303 | |
2d0a075d JS |
3304 | info.cbSize = sizeof(SCROLLINFO); |
3305 | info.nPage = page; | |
3306 | info.nMin = 0; | |
3307 | info.fMask = SIF_PAGE ; | |
2bda0e17 | 3308 | |
2d0a075d JS |
3309 | HWND hWnd = (HWND) GetHWND(); |
3310 | if (hWnd) | |
3311 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3312 | #else |
2d0a075d JS |
3313 | if (orient == wxHORIZONTAL) |
3314 | m_xThumbSize = page; | |
3315 | else | |
3316 | m_yThumbSize = page; | |
2bda0e17 KB |
3317 | #endif |
3318 | } | |
3319 | ||
debe6624 | 3320 | int wxWindow::OldGetScrollRange(int orient) const |
2bda0e17 | 3321 | { |
2d0a075d JS |
3322 | int wOrient ; |
3323 | if (orient == wxHORIZONTAL) | |
3324 | wOrient = SB_HORZ; | |
3325 | else | |
3326 | wOrient = SB_VERT; | |
2bda0e17 KB |
3327 | |
3328 | #if __WATCOMC__ && defined(__WINDOWS_386__) | |
2d0a075d | 3329 | short minPos, maxPos; |
2bda0e17 | 3330 | #else |
2d0a075d | 3331 | int minPos, maxPos; |
2bda0e17 | 3332 | #endif |
2d0a075d JS |
3333 | HWND hWnd = (HWND) GetHWND(); |
3334 | if (hWnd) | |
2bda0e17 | 3335 | { |
2d0a075d JS |
3336 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); |
3337 | #if defined(__WIN95__) | |
3338 | // Try to adjust the range to cope with page size > 1 | |
3339 | // - a Windows API quirk | |
3340 | int pageSize = GetScrollPage(orient); | |
3341 | if ( pageSize > 1 ) | |
3342 | { | |
3343 | maxPos -= (pageSize - 1); | |
3344 | } | |
2bda0e17 | 3345 | #endif |
2d0a075d JS |
3346 | return maxPos; |
3347 | } | |
3348 | else | |
3349 | return 0; | |
2bda0e17 KB |
3350 | } |
3351 | ||
debe6624 | 3352 | int wxWindow::GetScrollPage(int orient) const |
2bda0e17 | 3353 | { |
2d0a075d JS |
3354 | if (orient == wxHORIZONTAL) |
3355 | return m_xThumbSize; | |
3356 | else | |
3357 | return m_yThumbSize; | |
2bda0e17 KB |
3358 | } |
3359 | #endif | |
3360 | ||
debe6624 | 3361 | int wxWindow::GetScrollPos(int orient) const |
2bda0e17 | 3362 | { |
2d0a075d JS |
3363 | int wOrient ; |
3364 | if (orient == wxHORIZONTAL) | |
3365 | wOrient = SB_HORZ; | |
3366 | else | |
3367 | wOrient = SB_VERT; | |
3368 | HWND hWnd = (HWND) GetHWND(); | |
3369 | if (hWnd) | |
3370 | { | |
3371 | return ::GetScrollPos(hWnd, wOrient); | |
3372 | } | |
3373 | else | |
3374 | return 0; | |
2bda0e17 KB |
3375 | } |
3376 | ||
3377 | // This now returns the whole range, not just the number | |
3378 | // of positions that we can scroll. | |
debe6624 | 3379 | int wxWindow::GetScrollRange(int orient) const |
2bda0e17 | 3380 | { |
2d0a075d JS |
3381 | int wOrient ; |
3382 | if (orient == wxHORIZONTAL) | |
3383 | wOrient = SB_HORZ; | |
3384 | else | |
3385 | wOrient = SB_VERT; | |
2bda0e17 KB |
3386 | |
3387 | #if __WATCOMC__ && defined(__WINDOWS_386__) | |
2d0a075d | 3388 | short minPos, maxPos; |
2bda0e17 | 3389 | #else |
2d0a075d | 3390 | int minPos, maxPos; |
2bda0e17 | 3391 | #endif |
2d0a075d JS |
3392 | HWND hWnd = (HWND) GetHWND(); |
3393 | if (hWnd) | |
2bda0e17 | 3394 | { |
2d0a075d JS |
3395 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); |
3396 | #if defined(__WIN95__) | |
3397 | // Try to adjust the range to cope with page size > 1 | |
3398 | // - a Windows API quirk | |
ca5e9f67 | 3399 | int pageSize = GetScrollThumb(orient); |
2d0a075d JS |
3400 | if ( pageSize > 1 ) |
3401 | { | |
3402 | maxPos -= (pageSize - 1); | |
3403 | } | |
3404 | // October 10th: new range concept. | |
3405 | maxPos += pageSize; | |
2bda0e17 | 3406 | #endif |
c085e333 | 3407 | |
2d0a075d JS |
3408 | return maxPos; |
3409 | } | |
3410 | else | |
3411 | return 0; | |
2bda0e17 KB |
3412 | } |
3413 | ||
debe6624 | 3414 | int wxWindow::GetScrollThumb(int orient) const |
2bda0e17 | 3415 | { |
2d0a075d JS |
3416 | if (orient == wxHORIZONTAL) |
3417 | return m_xThumbSize; | |
3418 | else | |
3419 | return m_yThumbSize; | |
2bda0e17 KB |
3420 | } |
3421 | ||
debe6624 | 3422 | void wxWindow::SetScrollPos(int orient, int pos, bool refresh) |
2bda0e17 KB |
3423 | { |
3424 | #if defined(__WIN95__) | |
2d0a075d JS |
3425 | SCROLLINFO info; |
3426 | int dir; | |
2bda0e17 | 3427 | |
2d0a075d JS |
3428 | if (orient == wxHORIZONTAL) { |
3429 | dir = SB_HORZ; | |
3430 | } else { | |
3431 | dir = SB_VERT; | |
3432 | } | |
2bda0e17 | 3433 | |
2d0a075d JS |
3434 | info.cbSize = sizeof(SCROLLINFO); |
3435 | info.nPage = 0; | |
3436 | info.nMin = 0; | |
3437 | info.nPos = pos; | |
3438 | info.fMask = SIF_POS ; | |
2bda0e17 | 3439 | |
2d0a075d JS |
3440 | HWND hWnd = (HWND) GetHWND(); |
3441 | if (hWnd) | |
3442 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3443 | #else |
2d0a075d JS |
3444 | int wOrient ; |
3445 | if (orient == wxHORIZONTAL) | |
3446 | wOrient = SB_HORZ; | |
3447 | else | |
3448 | wOrient = SB_VERT; | |
3449 | ||
3450 | HWND hWnd = (HWND) GetHWND(); | |
3451 | if (hWnd) | |
3452 | ::SetScrollPos(hWnd, wOrient, pos, refresh); | |
2bda0e17 KB |
3453 | #endif |
3454 | } | |
3455 | ||
3456 | // New function that will replace some of the above. | |
debe6624 | 3457 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, |
2d0a075d | 3458 | int range, bool refresh) |
2bda0e17 KB |
3459 | { |
3460 | /* | |
2d0a075d | 3461 | SetScrollPage(orient, thumbVisible, FALSE); |
2bda0e17 | 3462 | |
2d0a075d JS |
3463 | int oldRange = range - thumbVisible ; |
3464 | SetScrollRange(orient, oldRange, FALSE); | |
c085e333 | 3465 | |
2bda0e17 | 3466 | SetScrollPos(orient, pos, refresh); |
2d0a075d | 3467 | */ |
2bda0e17 | 3468 | #if defined(__WIN95__) |
2d0a075d | 3469 | int oldRange = range - thumbVisible ; |
2bda0e17 | 3470 | |
2d0a075d | 3471 | int range1 = oldRange; |
2bda0e17 | 3472 | |
2d0a075d JS |
3473 | // Try to adjust the range to cope with page size > 1 |
3474 | // - a Windows API quirk | |
3475 | int pageSize = thumbVisible; | |
3476 | if ( pageSize > 1 && range > 0) | |
3477 | { | |
3478 | range1 += (pageSize - 1); | |
3479 | } | |
2bda0e17 | 3480 | |
2d0a075d JS |
3481 | SCROLLINFO info; |
3482 | int dir; | |
2bda0e17 | 3483 | |
2d0a075d JS |
3484 | if (orient == wxHORIZONTAL) { |
3485 | dir = SB_HORZ; | |
3486 | } else { | |
3487 | dir = SB_VERT; | |
3488 | } | |
2bda0e17 | 3489 | |
2d0a075d JS |
3490 | info.cbSize = sizeof(SCROLLINFO); |
3491 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
3492 | info.nMin = 0; | |
3493 | info.nMax = range1; | |
3494 | info.nPos = pos; | |
3495 | info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; | |
2bda0e17 | 3496 | |
2d0a075d JS |
3497 | HWND hWnd = (HWND) GetHWND(); |
3498 | if (hWnd) | |
3499 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3500 | #else |
2d0a075d JS |
3501 | int wOrient ; |
3502 | if (orient == wxHORIZONTAL) | |
3503 | wOrient = SB_HORZ; | |
3504 | else | |
3505 | wOrient = SB_VERT; | |
3506 | ||
3507 | HWND hWnd = (HWND) GetHWND(); | |
3508 | if (hWnd) | |
3509 | { | |
3510 | ::SetScrollRange(hWnd, wOrient, 0, range, FALSE); | |
3511 | ::SetScrollPos(hWnd, wOrient, pos, refresh); | |
3512 | } | |
2bda0e17 | 3513 | #endif |
2d0a075d JS |
3514 | if (orient == wxHORIZONTAL) { |
3515 | m_xThumbSize = thumbVisible; | |
3516 | } else { | |
3517 | m_yThumbSize = thumbVisible; | |
3518 | } | |
2bda0e17 KB |
3519 | } |
3520 | ||
16e93305 | 3521 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
2bda0e17 | 3522 | { |
564b2609 VZ |
3523 | RECT rect2; |
3524 | if ( rect ) | |
3525 | { | |
3526 | rect2.left = rect->x; | |
3527 | rect2.top = rect->y; | |
3528 | rect2.right = rect->x + rect->width; | |
3529 | rect2.bottom = rect->y + rect->height; | |
3530 | } | |
c085e333 | 3531 | |
564b2609 VZ |
3532 | if ( rect ) |
3533 | ::ScrollWindow((HWND) GetHWND(), dx, dy, &rect2, NULL); | |
3534 | else | |
3535 | ::ScrollWindow((HWND) GetHWND(), dx, dy, NULL, NULL); | |
2bda0e17 KB |
3536 | } |
3537 | ||
2bda0e17 KB |
3538 | void wxWindow::SetFont(const wxFont& font) |
3539 | { | |
2d0a075d | 3540 | m_windowFont = font; |
2bda0e17 | 3541 | |
2d0a075d JS |
3542 | if (!m_windowFont.Ok()) |
3543 | return; | |
2bda0e17 | 3544 | |
2d0a075d JS |
3545 | HWND hWnd = (HWND) GetHWND(); |
3546 | if (hWnd != 0) | |
3547 | { | |
3548 | if (m_windowFont.GetResourceHandle()) | |
3549 | SendMessage(hWnd, WM_SETFONT, | |
3550 | (WPARAM)m_windowFont.GetResourceHandle(),TRUE); | |
3551 | } | |
2bda0e17 KB |
3552 | } |
3553 | ||
3554 | void wxWindow::SubclassWin(WXHWND hWnd) | |
3555 | { | |
2d0a075d | 3556 | wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" ); |
a02eb1d2 | 3557 | |
2d0a075d | 3558 | wxAssociateWinWithHandle((HWND)hWnd, this); |
2bda0e17 | 3559 | |
2d0a075d JS |
3560 | m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC); |
3561 | SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc); | |
2bda0e17 KB |
3562 | } |
3563 | ||
fd3f686c | 3564 | void wxWindow::UnsubclassWin() |
2bda0e17 | 3565 | { |
564b2609 | 3566 | wxRemoveHandleAssociation(this); |
c085e333 | 3567 | |
2d0a075d JS |
3568 | // Restore old Window proc |
3569 | if ((HWND) GetHWND()) | |
564b2609 | 3570 | { |
2d0a075d JS |
3571 | FARPROC farProc = (FARPROC) GetWindowLong((HWND) GetHWND(), GWL_WNDPROC); |
3572 | if ((m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc)) | |
3573 | { | |
3574 | SetWindowLong((HWND) GetHWND(), GWL_WNDPROC, (LONG) m_oldWndProc); | |
3575 | m_oldWndProc = 0; | |
3576 | } | |
564b2609 | 3577 | } |
2bda0e17 KB |
3578 | } |
3579 | ||
3580 | // Make a Windows extended style from the given wxWindows window style | |
3581 | WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders) | |
3582 | { | |
564b2609 VZ |
3583 | WXDWORD exStyle = 0; |
3584 | if ( style & wxTRANSPARENT_WINDOW ) | |
3585 | exStyle |= WS_EX_TRANSPARENT ; | |
c085e333 | 3586 | |
2d0a075d JS |
3587 | if ( !eliminateBorders ) |
3588 | { | |
3589 | if ( style & wxSUNKEN_BORDER ) | |
3590 | exStyle |= WS_EX_CLIENTEDGE ; | |
3591 | if ( style & wxDOUBLE_BORDER ) | |
3592 | exStyle |= WS_EX_DLGMODALFRAME ; | |
2bda0e17 | 3593 | #if defined(__WIN95__) |
2d0a075d JS |
3594 | if ( style & wxRAISED_BORDER ) |
3595 | exStyle |= WS_EX_WINDOWEDGE ; | |
3596 | if ( style & wxSTATIC_BORDER ) | |
3597 | exStyle |= WS_EX_STATICEDGE ; | |
2bda0e17 | 3598 | #endif |
2d0a075d JS |
3599 | } |
3600 | return exStyle; | |
2bda0e17 KB |
3601 | } |
3602 | ||
3603 | // Determines whether native 3D effects or CTL3D should be used, | |
3604 | // applying a default border style if required, and returning an extended | |
3605 | // style to pass to CreateWindowEx. | |
3606 | WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) | |
3607 | { | |
2d0a075d JS |
3608 | // If matches certain criteria, then assume no 3D effects |
3609 | // unless specifically requested (dealt with in MakeExtendedStyle) | |
3610 | if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) ) | |
3611 | { | |
3612 | *want3D = FALSE; | |
3613 | return MakeExtendedStyle(m_windowStyle, FALSE); | |
3614 | } | |
2bda0e17 | 3615 | |
2d0a075d JS |
3616 | // Determine whether we should be using 3D effects or not. |
3617 | bool nativeBorder = FALSE; // by default, we don't want a Win95 effect | |
2bda0e17 | 3618 | |
2d0a075d JS |
3619 | // 1) App can specify global 3D effects |
3620 | *want3D = wxTheApp->GetAuto3D(); | |
2bda0e17 | 3621 | |
2d0a075d JS |
3622 | // 2) If the parent is being drawn with user colours, or simple border specified, |
3623 | // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D | |
3624 | if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER)) | |
3625 | *want3D = FALSE; | |
2bda0e17 | 3626 | |
2d0a075d JS |
3627 | // 3) Control can override this global setting by defining |
3628 | // a border style, e.g. wxSUNKEN_BORDER | |
3629 | if (m_windowStyle & wxSUNKEN_BORDER ) | |
3630 | *want3D = TRUE; | |
2bda0e17 | 3631 | |
2d0a075d JS |
3632 | // 4) If it's a special border, CTL3D can't cope so we want a native border |
3633 | if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || | |
3634 | (m_windowStyle & wxSTATIC_BORDER) ) | |
3635 | { | |
3636 | *want3D = TRUE; | |
3637 | nativeBorder = TRUE; | |
3638 | } | |
2bda0e17 | 3639 | |
2d0a075d JS |
3640 | // 5) If this isn't a Win95 app, and we are using CTL3D, remove border |
3641 | // effects from extended style | |
1f112209 | 3642 | #if wxUSE_CTL3D |
2d0a075d JS |
3643 | if ( *want3D ) |
3644 | nativeBorder = FALSE; | |
2bda0e17 | 3645 | #endif |
c085e333 | 3646 | |
2d0a075d | 3647 | DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder); |
2bda0e17 | 3648 | |
2d0a075d JS |
3649 | // If we want 3D, but haven't specified a border here, |
3650 | // apply the default border style specified. | |
3651 | // TODO what about non-Win95 WIN32? Does it have borders? | |
1f112209 | 3652 | #if defined(__WIN95__) && !wxUSE_CTL3D |
2d0a075d | 3653 | if (defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || |
2bda0e17 | 3654 | (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) )) |
2d0a075d | 3655 | exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE ; |
2bda0e17 | 3656 | #endif |
c085e333 | 3657 | |
2d0a075d | 3658 | return exStyle; |
2bda0e17 KB |
3659 | } |
3660 | ||
2bda0e17 KB |
3661 | void wxWindow::OnChar(wxKeyEvent& event) |
3662 | { | |
47cbd6da VZ |
3663 | bool isVirtual; |
3664 | int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual); | |
c085e333 | 3665 | |
47cbd6da VZ |
3666 | if ( id == -1 ) |
3667 | id= m_lastWParam; | |
c085e333 | 3668 | |
2bda0e17 | 3669 | if ( !event.ControlDown() ) |
47cbd6da | 3670 | (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam); |
2bda0e17 KB |
3671 | } |
3672 | ||
2bda0e17 KB |
3673 | bool wxWindow::IsEnabled(void) const |
3674 | { | |
564b2609 | 3675 | return (::IsWindowEnabled((HWND) GetHWND()) != 0); |
2bda0e17 KB |
3676 | } |
3677 | ||
3678 | // Dialog support: override these and call | |
3679 | // base class members to add functionality | |
3680 | // that can't be done using validators. | |
3681 | // NOTE: these functions assume that controls | |
3682 | // are direct children of this window, not grandchildren | |
3683 | // or other levels of descendant. | |
3684 | ||
3685 | // Transfer values to controls. If returns FALSE, | |
3686 | // it's an application error (pops up a dialog) | |
fd3f686c | 3687 | bool wxWindow::TransferDataToWindow() |
2bda0e17 | 3688 | { |
c0ed460c | 3689 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3690 | while ( node ) |
3691 | { | |
3692 | wxWindow *child = (wxWindow *)node->Data(); | |
3693 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ | |
2d0a075d | 3694 | !child->GetValidator()->TransferToWindow() ) |
564b2609 | 3695 | { |
341c92a8 | 3696 | wxLogError(_("Could not transfer data to window")); |
564b2609 VZ |
3697 | return FALSE; |
3698 | } | |
c085e333 | 3699 | |
564b2609 VZ |
3700 | node = node->Next(); |
3701 | } | |
3702 | return TRUE; | |
2bda0e17 KB |
3703 | } |
3704 | ||
3705 | // Transfer values from controls. If returns FALSE, | |
3706 | // validation failed: don't quit | |
fd3f686c | 3707 | bool wxWindow::TransferDataFromWindow() |
2bda0e17 | 3708 | { |
c0ed460c | 3709 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3710 | while ( node ) |
3711 | { | |
3712 | wxWindow *child = (wxWindow *)node->Data(); | |
3713 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() ) | |
3714 | { | |
3715 | return FALSE; | |
3716 | } | |
c085e333 | 3717 | |
564b2609 VZ |
3718 | node = node->Next(); |
3719 | } | |
3720 | return TRUE; | |
2bda0e17 KB |
3721 | } |
3722 | ||
fd3f686c | 3723 | bool wxWindow::Validate() |
2bda0e17 | 3724 | { |
c0ed460c | 3725 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3726 | while ( node ) |
3727 | { | |
3728 | wxWindow *child = (wxWindow *)node->Data(); | |
3729 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
3730 | { | |
3731 | return FALSE; | |
3732 | } | |
c085e333 | 3733 | |
564b2609 VZ |
3734 | node = node->Next(); |
3735 | } | |
3736 | return TRUE; | |
2bda0e17 KB |
3737 | } |
3738 | ||
3739 | // Get the window with the focus | |
fd3f686c | 3740 | wxWindow *wxWindow::FindFocus() |
2bda0e17 KB |
3741 | { |
3742 | HWND hWnd = ::GetFocus(); | |
3743 | if ( hWnd ) | |
3744 | { | |
3745 | return wxFindWinFromHandle((WXHWND) hWnd); | |
3746 | } | |
3747 | return NULL; | |
3748 | } | |
3749 | ||
3750 | void wxWindow::AddChild(wxWindow *child) | |
3751 | { | |
c0ed460c | 3752 | GetChildren().Append(child); |
2d0a075d | 3753 | child->m_windowParent = this; |
2bda0e17 KB |
3754 | } |
3755 | ||
3756 | void wxWindow::RemoveChild(wxWindow *child) | |
3757 | { | |
c0ed460c JS |
3758 | // if (GetChildren()) |
3759 | GetChildren().DeleteObject(child); | |
2d0a075d | 3760 | child->m_windowParent = NULL; |
2bda0e17 KB |
3761 | } |
3762 | ||
fd3f686c | 3763 | void wxWindow::DestroyChildren() |
2bda0e17 | 3764 | { |
2d0a075d | 3765 | wxNode *node; |
c0ed460c | 3766 | while ((node = GetChildren().First()) != (wxNode *)NULL) { |
2d0a075d JS |
3767 | wxWindow *child; |
3768 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
3769 | delete child; | |
c0ed460c | 3770 | if ( GetChildren().Member(child) ) |
2d0a075d JS |
3771 | delete node; |
3772 | } | |
3773 | } /* while */ | |
2bda0e17 KB |
3774 | } |
3775 | ||
debe6624 | 3776 | void wxWindow::MakeModal(bool modal) |
2bda0e17 | 3777 | { |
2d0a075d JS |
3778 | // Disable all other windows |
3779 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
2bda0e17 | 3780 | { |
2d0a075d JS |
3781 | wxNode *node = wxTopLevelWindows.First(); |
3782 | while (node) | |
3783 | { | |
3784 | wxWindow *win = (wxWindow *)node->Data(); | |
3785 | if (win != this) | |
3786 | win->Enable(!modal); | |
2bda0e17 | 3787 | |
2d0a075d JS |
3788 | node = node->Next(); |
3789 | } | |
2bda0e17 | 3790 | } |
2bda0e17 KB |
3791 | } |
3792 | ||
3793 | // If nothing defined for this, try the parent. | |
3794 | // E.g. we may be a button loaded from a resource, with no callback function | |
3795 | // defined. | |
3796 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
3797 | { | |
2d0a075d JS |
3798 | if (GetEventHandler()->ProcessEvent(event) ) |
3799 | return; | |
3800 | if (m_windowParent) | |
3801 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
2bda0e17 KB |
3802 | } |
3803 | ||
3804 | void wxWindow::SetConstraints(wxLayoutConstraints *c) | |
3805 | { | |
2d0a075d JS |
3806 | if (m_constraints) |
3807 | { | |
3808 | UnsetConstraints(m_constraints); | |
3809 | delete m_constraints; | |
3810 | } | |
3811 | m_constraints = c; | |
3812 | if (m_constraints) | |
3813 | { | |
3814 | // Make sure other windows know they're part of a 'meaningful relationship' | |
3815 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
3816 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3817 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
3818 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3819 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
3820 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3821 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
3822 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3823 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
3824 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3825 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
3826 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3827 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
3828 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3829 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
3830 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3831 | } | |
2bda0e17 KB |
3832 | } |
3833 | ||
3834 | // This removes any dangling pointers to this window | |
3835 | // in other windows' constraintsInvolvedIn lists. | |
3836 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
3837 | { | |
2d0a075d JS |
3838 | if (c) |
3839 | { | |
3840 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
3841 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3842 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
3843 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3844 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
3845 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3846 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
3847 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3848 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
3849 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3850 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
3851 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3852 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
3853 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3854 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
3855 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3856 | } | |
2bda0e17 KB |
3857 | } |
3858 | ||
3859 | // Back-pointer to other windows we're involved with, so if we delete | |
3860 | // this window, we must delete any constraints we're involved with. | |
3861 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
3862 | { | |
2d0a075d JS |
3863 | if (!m_constraintsInvolvedIn) |
3864 | m_constraintsInvolvedIn = new wxList; | |
3865 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
3866 | m_constraintsInvolvedIn->Append(otherWin); | |
2bda0e17 KB |
3867 | } |
3868 | ||
3869 | // REMOVE back-pointer to other windows we're involved with. | |
3870 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
3871 | { | |
2d0a075d JS |
3872 | if (m_constraintsInvolvedIn) |
3873 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
2bda0e17 KB |
3874 | } |
3875 | ||
3876 | // Reset any constraints that mention this window | |
fd3f686c | 3877 | void wxWindow::DeleteRelatedConstraints() |
2bda0e17 | 3878 | { |
2d0a075d | 3879 | if (m_constraintsInvolvedIn) |
2bda0e17 | 3880 | { |
2d0a075d JS |
3881 | wxNode *node = m_constraintsInvolvedIn->First(); |
3882 | while (node) | |
3883 | { | |
3884 | wxWindow *win = (wxWindow *)node->Data(); | |
3885 | wxNode *next = node->Next(); | |
3886 | wxLayoutConstraints *constr = win->GetConstraints(); | |
3887 | ||
3888 | // Reset any constraints involving this window | |
3889 | if (constr) | |
3890 | { | |
3891 | constr->left.ResetIfWin((wxWindow *)this); | |
3892 | constr->top.ResetIfWin((wxWindow *)this); | |
3893 | constr->right.ResetIfWin((wxWindow *)this); | |
3894 | constr->bottom.ResetIfWin((wxWindow *)this); | |
3895 | constr->width.ResetIfWin((wxWindow *)this); | |
3896 | constr->height.ResetIfWin((wxWindow *)this); | |
3897 | constr->centreX.ResetIfWin((wxWindow *)this); | |
3898 | constr->centreY.ResetIfWin((wxWindow *)this); | |
3899 | } | |
3900 | delete node; | |
3901 | node = next; | |
3902 | } | |
3903 | delete m_constraintsInvolvedIn; | |
3904 | m_constraintsInvolvedIn = NULL; | |
2bda0e17 | 3905 | } |
2bda0e17 KB |
3906 | } |
3907 | ||
3908 | void wxWindow::SetSizer(wxSizer *sizer) | |
3909 | { | |
2d0a075d JS |
3910 | m_windowSizer = sizer; |
3911 | if (sizer) | |
3912 | sizer->SetSizerParent((wxWindow *)this); | |
2bda0e17 KB |
3913 | } |
3914 | ||
3915 | /* | |
2d0a075d JS |
3916 | * New version |
3917 | */ | |
2bda0e17 | 3918 | |
fd3f686c | 3919 | bool wxWindow::Layout() |
2bda0e17 | 3920 | { |
2d0a075d JS |
3921 | if (GetConstraints()) |
3922 | { | |
3923 | int w, h; | |
3924 | GetClientSize(&w, &h); | |
3925 | GetConstraints()->width.SetValue(w); | |
3926 | GetConstraints()->height.SetValue(h); | |
3927 | } | |
3928 | ||
3929 | // If top level (one sizer), evaluate the sizer's constraints. | |
3930 | if (GetSizer()) | |
3931 | { | |
3932 | int noChanges; | |
3933 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
3934 | GetSizer()->LayoutPhase1(&noChanges); | |
3935 | GetSizer()->LayoutPhase2(&noChanges); | |
3936 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
3937 | return TRUE; | |
3938 | } | |
3939 | else | |
3940 | { | |
3941 | // Otherwise, evaluate child constraints | |
3942 | ResetConstraints(); // Mark all constraints as unevaluated | |
3943 | DoPhase(1); // Just one phase need if no sizers involved | |
3944 | DoPhase(2); | |
3945 | SetConstraintSizes(); // Recursively set the real window sizes | |
3946 | } | |
2bda0e17 | 3947 | return TRUE; |
2bda0e17 KB |
3948 | } |
3949 | ||
3950 | ||
3951 | // Do a phase of evaluating constraints: | |
3952 | // the default behaviour. wxSizers may do a similar | |
3953 | // thing, but also impose their own 'constraints' | |
3954 | // and order the evaluation differently. | |
3955 | bool wxWindow::LayoutPhase1(int *noChanges) | |
3956 | { | |
2d0a075d JS |
3957 | wxLayoutConstraints *constr = GetConstraints(); |
3958 | if (constr) | |
3959 | { | |
3960 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
3961 | } | |
3962 | else | |
3963 | return TRUE; | |
2bda0e17 KB |
3964 | } |
3965 | ||
3966 | bool wxWindow::LayoutPhase2(int *noChanges) | |
3967 | { | |
2d0a075d JS |
3968 | *noChanges = 0; |
3969 | ||
3970 | // Layout children | |
3971 | DoPhase(1); | |
3972 | DoPhase(2); | |
3973 | return TRUE; | |
2bda0e17 KB |
3974 | } |
3975 | ||
3976 | // Do a phase of evaluating child constraints | |
debe6624 | 3977 | bool wxWindow::DoPhase(int phase) |
2bda0e17 | 3978 | { |
2d0a075d JS |
3979 | int noIterations = 0; |
3980 | int maxIterations = 500; | |
3981 | int noChanges = 1; | |
3982 | int noFailures = 0; | |
3983 | wxList succeeded; | |
3984 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
2bda0e17 | 3985 | { |
2d0a075d JS |
3986 | noChanges = 0; |
3987 | noFailures = 0; | |
c0ed460c | 3988 | wxNode *node = GetChildren().First(); |
2d0a075d | 3989 | while (node) |
2bda0e17 | 3990 | { |
2d0a075d JS |
3991 | wxWindow *child = (wxWindow *)node->Data(); |
3992 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
2bda0e17 | 3993 | { |
2d0a075d JS |
3994 | wxLayoutConstraints *constr = child->GetConstraints(); |
3995 | if (constr) | |
3996 | { | |
3997 | if (succeeded.Member(child)) | |
3998 | { | |
3999 | } | |
4000 | else | |
4001 | { | |
4002 | int tempNoChanges = 0; | |
4003 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
4004 | noChanges += tempNoChanges; | |
4005 | if (success) | |
4006 | { | |
4007 | succeeded.Append(child); | |
4008 | } | |
4009 | } | |
4010 | } | |
2bda0e17 | 4011 | } |
2d0a075d | 4012 | node = node->Next(); |
2bda0e17 | 4013 | } |
2d0a075d | 4014 | noIterations ++; |
2bda0e17 | 4015 | } |
2d0a075d | 4016 | return TRUE; |
2bda0e17 KB |
4017 | } |
4018 | ||
fd3f686c | 4019 | void wxWindow::ResetConstraints() |
2bda0e17 | 4020 | { |
2d0a075d JS |
4021 | wxLayoutConstraints *constr = GetConstraints(); |
4022 | if (constr) | |
4023 | { | |
4024 | constr->left.SetDone(FALSE); | |
4025 | constr->top.SetDone(FALSE); | |
4026 | constr->right.SetDone(FALSE); | |
4027 | constr->bottom.SetDone(FALSE); | |
4028 | constr->width.SetDone(FALSE); | |
4029 | constr->height.SetDone(FALSE); | |
4030 | constr->centreX.SetDone(FALSE); | |
4031 | constr->centreY.SetDone(FALSE); | |
4032 | } | |
c0ed460c | 4033 | wxNode *node = GetChildren().First(); |
2d0a075d JS |
4034 | while (node) |
4035 | { | |
4036 | wxWindow *win = (wxWindow *)node->Data(); | |
4037 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
4038 | win->ResetConstraints(); | |
4039 | node = node->Next(); | |
4040 | } | |
2bda0e17 KB |
4041 | } |
4042 | ||
4043 | // Need to distinguish between setting the 'fake' size for | |
4044 | // windows and sizers, and setting the real values. | |
debe6624 | 4045 | void wxWindow::SetConstraintSizes(bool recurse) |
2bda0e17 | 4046 | { |
2d0a075d JS |
4047 | wxLayoutConstraints *constr = GetConstraints(); |
4048 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
4049 | constr->width.GetDone() && constr->height.GetDone()) | |
2bda0e17 | 4050 | { |
2d0a075d JS |
4051 | int x = constr->left.GetValue(); |
4052 | int y = constr->top.GetValue(); | |
4053 | int w = constr->width.GetValue(); | |
4054 | int h = constr->height.GetValue(); | |
4055 | ||
4056 | // If we don't want to resize this window, just move it... | |
4057 | if ((constr->width.GetRelationship() != wxAsIs) || | |
4058 | (constr->height.GetRelationship() != wxAsIs)) | |
4059 | { | |
4060 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
4061 | // Simply take Layout() out of non-top level OnSizes. | |
4062 | SizerSetSize(x, y, w, h); | |
4063 | } | |
4064 | else | |
4065 | { | |
4066 | SizerMove(x, y); | |
4067 | } | |
2bda0e17 | 4068 | } |
2d0a075d | 4069 | else if (constr) |
2bda0e17 | 4070 | { |
2d0a075d | 4071 | char *windowClass = this->GetClassInfo()->GetClassName(); |
2bda0e17 | 4072 | |
2d0a075d JS |
4073 | wxString winName; |
4074 | if (GetName() == "") | |
4075 | winName = "unnamed"; | |
4076 | else | |
4077 | winName = GetName(); | |
341c92a8 VZ |
4078 | wxLogDebug("Constraint(s) not satisfied for window of type %s, name %s:", |
4079 | (const char *)windowClass, (const char *)winName); | |
2d0a075d | 4080 | if (!constr->left.GetDone()) |
341c92a8 | 4081 | wxLogDebug(" unsatisfied 'left' constraint."); |
2d0a075d | 4082 | if (!constr->right.GetDone()) |
341c92a8 | 4083 | wxLogDebug(" unsatisfied 'right' constraint."); |
2d0a075d | 4084 | if (!constr->width.GetDone()) |
341c92a8 | 4085 | wxLogDebug(" unsatisfied 'width' constraint."); |
2d0a075d | 4086 | if (!constr->height.GetDone()) |
341c92a8 VZ |
4087 | wxLogDebug(" unsatisfied 'height' constraint."); |
4088 | wxLogDebug("Please check constraints: try adding AsIs() constraints.\n"); | |
2d0a075d | 4089 | } |
2bda0e17 | 4090 | |
2d0a075d | 4091 | if (recurse) |
2bda0e17 | 4092 | { |
c0ed460c | 4093 | wxNode *node = GetChildren().First(); |
2d0a075d JS |
4094 | while (node) |
4095 | { | |
4096 | wxWindow *win = (wxWindow *)node->Data(); | |
4097 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
4098 | win->SetConstraintSizes(); | |
4099 | node = node->Next(); | |
4100 | } | |
2bda0e17 | 4101 | } |
2bda0e17 KB |
4102 | } |
4103 | ||
4104 | // This assumes that all sizers are 'on' the same | |
4105 | // window, i.e. the parent of this window. | |
4106 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
4107 | { | |
2d0a075d JS |
4108 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || |
4109 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) | |
4110 | return; | |
4111 | ||
4112 | int xp, yp; | |
4113 | m_sizerParent->GetPosition(&xp, &yp); | |
4114 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
4115 | *x += xp; | |
4116 | *y += yp; | |
2bda0e17 KB |
4117 | } |
4118 | ||
debe6624 | 4119 | void wxWindow::SizerSetSize(int x, int y, int w, int h) |
2bda0e17 | 4120 | { |
564b2609 VZ |
4121 | int xx = x; |
4122 | int yy = y; | |
2d0a075d JS |
4123 | TransformSizerToActual(&xx, &yy); |
4124 | SetSize(xx, yy, w, h); | |
2bda0e17 KB |
4125 | } |
4126 | ||
debe6624 | 4127 | void wxWindow::SizerMove(int x, int y) |
2bda0e17 | 4128 | { |
564b2609 VZ |
4129 | int xx = x; |
4130 | int yy = y; | |
2d0a075d JS |
4131 | TransformSizerToActual(&xx, &yy); |
4132 | Move(xx, yy); | |
2bda0e17 KB |
4133 | } |
4134 | ||
4135 | // Only set the size/position of the constraint (if any) | |
debe6624 | 4136 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) |
2bda0e17 | 4137 | { |
2d0a075d JS |
4138 | wxLayoutConstraints *constr = GetConstraints(); |
4139 | if (constr) | |
2bda0e17 | 4140 | { |
2d0a075d JS |
4141 | if (x != -1) |
4142 | { | |
4143 | constr->left.SetValue(x); | |
4144 | constr->left.SetDone(TRUE); | |
4145 | } | |
4146 | if (y != -1) | |
4147 | { | |
4148 | constr->top.SetValue(y); | |
4149 | constr->top.SetDone(TRUE); | |
4150 | } | |
4151 | if (w != -1) | |
4152 | { | |
4153 | constr->width.SetValue(w); | |
4154 | constr->width.SetDone(TRUE); | |
4155 | } | |
4156 | if (h != -1) | |
4157 | { | |
4158 | constr->height.SetValue(h); | |
4159 | constr->height.SetDone(TRUE); | |
4160 | } | |
2bda0e17 | 4161 | } |
2bda0e17 KB |
4162 | } |
4163 | ||
debe6624 | 4164 | void wxWindow::MoveConstraint(int x, int y) |
2bda0e17 | 4165 | { |
2d0a075d JS |
4166 | wxLayoutConstraints *constr = GetConstraints(); |
4167 | if (constr) | |
2bda0e17 | 4168 | { |
2d0a075d JS |
4169 | if (x != -1) |
4170 | { | |
4171 | constr->left.SetValue(x); | |
4172 | constr->left.SetDone(TRUE); | |
4173 | } | |
4174 | if (y != -1) | |
4175 | { | |
4176 | constr->top.SetValue(y); | |
4177 | constr->top.SetDone(TRUE); | |
4178 | } | |
2bda0e17 | 4179 | } |
2bda0e17 KB |
4180 | } |
4181 | ||
4182 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
4183 | { | |
2d0a075d JS |
4184 | wxLayoutConstraints *constr = GetConstraints(); |
4185 | if (constr) | |
4186 | { | |
4187 | *w = constr->width.GetValue(); | |
4188 | *h = constr->height.GetValue(); | |
4189 | } | |
4190 | else | |
4191 | GetSize(w, h); | |
2bda0e17 KB |
4192 | } |
4193 | ||
4194 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
4195 | { | |
2d0a075d JS |
4196 | wxLayoutConstraints *constr = GetConstraints(); |
4197 | if (constr) | |
4198 | { | |
4199 | *w = constr->width.GetValue(); | |
4200 | *h = constr->height.GetValue(); | |
4201 | } | |
4202 | else | |
4203 | GetClientSize(w, h); | |
2bda0e17 KB |
4204 | } |
4205 | ||
4206 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
4207 | { | |
2d0a075d JS |
4208 | wxLayoutConstraints *constr = GetConstraints(); |
4209 | if (constr) | |
4210 | { | |
4211 | *x = constr->left.GetValue(); | |
4212 | *y = constr->top.GetValue(); | |
4213 | } | |
4214 | else | |
4215 | GetPosition(x, y); | |
2bda0e17 KB |
4216 | } |
4217 | ||
debe6624 | 4218 | bool wxWindow::Close(bool force) |
2bda0e17 | 4219 | { |
2d0a075d JS |
4220 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); |
4221 | event.SetEventObject(this); | |
e3065973 | 4222 | #if WXWIN_COMPATIBILITY |
2d0a075d | 4223 | event.SetForce(force); |
e3065973 | 4224 | #endif |
2d0a075d | 4225 | event.SetCanVeto(!force); |
2bda0e17 | 4226 | |
2d0a075d | 4227 | return (GetEventHandler()->ProcessEvent(event) && !event.GetVeto()); |
2bda0e17 KB |
4228 | } |
4229 | ||
debe6624 | 4230 | wxObject* wxWindow::GetChild(int number) const |
2bda0e17 | 4231 | { |
2d0a075d | 4232 | // Return a pointer to the Nth object in the Panel |
c0ed460c JS |
4233 | // if (!GetChildren()) |
4234 | // return(NULL) ; | |
4235 | wxNode *node = GetChildren().First(); | |
2d0a075d JS |
4236 | int n = number; |
4237 | while (node && n--) | |
4238 | node = node->Next() ; | |
4239 | if (node) | |
4240 | { | |
4241 | wxObject *obj = (wxObject *)node->Data(); | |
4242 | return(obj) ; | |
4243 | } | |
4244 | else | |
4245 | return NULL ; | |
2bda0e17 KB |
4246 | } |
4247 | ||
4248 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
4249 | { | |
debe6624 | 4250 | /* This is obsolete now; if we wish to intercept listbox double-clicks, |
2d0a075d JS |
4251 | * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED |
4252 | * event. | |
debe6624 JS |
4253 | |
4254 | if (initiatingItem->IsKindOf(CLASSINFO(wxListBox))) | |
2bda0e17 | 4255 | { |
2d0a075d JS |
4256 | wxListBox *lbox = (wxListBox *)initiatingItem; |
4257 | wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK); | |
4258 | event.m_commandInt = -1; | |
4259 | if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0) | |
2bda0e17 | 4260 | { |
2d0a075d JS |
4261 | event.m_commandString = copystring(lbox->GetStringSelection()); |
4262 | event.m_commandInt = lbox->GetSelection(); | |
4263 | event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt); | |
2bda0e17 | 4264 | } |
2d0a075d | 4265 | event.m_eventObject = lbox; |
c085e333 | 4266 | |
2d0a075d | 4267 | lbox->ProcessCommand(event); |
c085e333 | 4268 | |
2d0a075d JS |
4269 | if (event.m_commandString) |
4270 | delete[] event.m_commandString; | |
4271 | return; | |
4272 | } | |
4273 | ||
4274 | wxButton *but = GetDefaultItem(); | |
4275 | if (but) | |
4276 | { | |
4277 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED); | |
4278 | event.SetEventObject(but); | |
4279 | but->Command(event); | |
4280 | } | |
4281 | */ | |
2bda0e17 KB |
4282 | } |
4283 | ||
fd3f686c | 4284 | void wxWindow::Clear() |
2bda0e17 | 4285 | { |
564b2609 | 4286 | wxClientDC dc(this); |
2bda0e17 KB |
4287 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
4288 | dc.SetBackground(brush); | |
4289 | dc.Clear(); | |
4290 | } | |
4291 | ||
4292 | // Fits the panel around the items | |
fd3f686c | 4293 | void wxWindow::Fit() |
2bda0e17 | 4294 | { |
564b2609 VZ |
4295 | int maxX = 0; |
4296 | int maxY = 0; | |
c0ed460c | 4297 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4298 | while ( node ) |
4299 | { | |
4300 | wxWindow *win = (wxWindow *)node->Data(); | |
4301 | int wx, wy, ww, wh; | |
4302 | win->GetPosition(&wx, &wy); | |
4303 | win->GetSize(&ww, &wh); | |
4304 | if ( wx + ww > maxX ) | |
4305 | maxX = wx + ww; | |
4306 | if ( wy + wh > maxY ) | |
4307 | maxY = wy + wh; | |
c085e333 | 4308 | |
564b2609 VZ |
4309 | node = node->Next(); |
4310 | } | |
4311 | SetClientSize(maxX + 5, maxY + 5); | |
2bda0e17 KB |
4312 | } |
4313 | ||
4314 | void wxWindow::SetValidator(const wxValidator& validator) | |
4315 | { | |
564b2609 VZ |
4316 | if ( m_windowValidator ) |
4317 | delete m_windowValidator; | |
4318 | m_windowValidator = validator.Clone(); | |
c085e333 | 4319 | |
564b2609 VZ |
4320 | if ( m_windowValidator ) |
4321 | m_windowValidator->SetWindow(this) ; | |
2bda0e17 KB |
4322 | } |
4323 | ||
4324 | // Find a window by id or name | |
debe6624 | 4325 | wxWindow *wxWindow::FindWindow(long id) |
2bda0e17 | 4326 | { |
564b2609 VZ |
4327 | if ( GetId() == id) |
4328 | return this; | |
c085e333 | 4329 | |
c0ed460c | 4330 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4331 | while ( node ) |
4332 | { | |
4333 | wxWindow *child = (wxWindow *)node->Data(); | |
4334 | wxWindow *found = child->FindWindow(id); | |
4335 | if ( found ) | |
4336 | return found; | |
4337 | node = node->Next(); | |
4338 | } | |
4339 | return NULL; | |
2bda0e17 KB |
4340 | } |
4341 | ||
4342 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
4343 | { | |
564b2609 VZ |
4344 | if ( GetName() == name) |
4345 | return this; | |
c085e333 | 4346 | |
c0ed460c | 4347 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4348 | while ( node ) |
4349 | { | |
4350 | wxWindow *child = (wxWindow *)node->Data(); | |
4351 | wxWindow *found = child->FindWindow(name); | |
4352 | if ( found ) | |
4353 | return found; | |
4354 | node = node->Next(); | |
4355 | } | |
4356 | return NULL; | |
2bda0e17 KB |
4357 | } |
4358 | ||
4359 | /* TODO | |
4360 | // Default input behaviour for a scrolling canvas should be to scroll | |
4361 | // according to the cursor keys pressed | |
4362 | void wxWindow::OnChar(wxKeyEvent& event) | |
4363 | { | |
2d0a075d JS |
4364 | int x_page = 0; |
4365 | int y_page = 0; | |
4366 | int start_x = 0; | |
4367 | int start_y = 0; | |
4368 | // Bugfix Begin | |
4369 | int v_width = 0; | |
4370 | int v_height = 0; | |
4371 | int y_pages = 0; | |
4372 | // Bugfix End | |
2bda0e17 KB |
4373 | |
4374 | GetScrollUnitsPerPage(&x_page, &y_page); | |
4375 | // Bugfix Begin | |
4376 | GetVirtualSize(&v_width,&v_height); | |
4377 | // Bugfix End | |
4378 | ViewStart(&start_x, &start_y); | |
4379 | // Bugfix begin | |
4380 | if (vert_units) | |
2d0a075d | 4381 | y_pages = (int)(v_height/vert_units) - y_page; |
c085e333 | 4382 | |
2d0a075d JS |
4383 | #ifdef __WXMSW__ |
4384 | int y = 0; | |
4385 | #else | |
4386 | int y = y_page-1; | |
4387 | #endif | |
4388 | // Bugfix End | |
4389 | switch (event.keyCode) | |
4390 | { | |
4391 | case WXK_PRIOR: | |
4392 | { | |
4393 | // BugFix Begin | |
4394 | if (y_page > 0) | |
4395 | { | |
4396 | if (start_y - y_page > 0) | |
4397 | Scroll(start_x, start_y - y_page); | |
4398 | else | |
4399 | Scroll(start_x, 0); | |
4400 | } | |
4401 | // Bugfix End | |
4402 | break; | |
4403 | } | |
4404 | case WXK_NEXT: | |
4405 | { | |
4406 | // Bugfix Begin | |
4407 | if ((y_page > 0) && (start_y <= y_pages-y-1)) | |
4408 | { | |
4409 | if (y_pages + y < start_y + y_page) | |
4410 | Scroll(start_x, y_pages + y); | |
4411 | else | |
4412 | Scroll(start_x, start_y + y_page); | |
4413 | } | |
4414 | // Bugfix End | |
4415 | break; | |
4416 | } | |
4417 | case WXK_UP: | |
4418 | { | |
4419 | if ((y_page > 0) && (start_y >= 1)) | |
4420 | Scroll(start_x, start_y - 1); | |
4421 | break; | |
4422 | } | |
4423 | case WXK_DOWN: | |
4424 | { | |
4425 | // Bugfix Begin | |
4426 | if ((y_page > 0) && (start_y <= y_pages-y-1)) | |
4427 | // Bugfix End | |
4428 | { | |
4429 | Scroll(start_x, start_y + 1); | |
4430 | } | |
4431 | break; | |
4432 | } | |
4433 | case WXK_LEFT: | |
4434 | { | |
4435 | if ((x_page > 0) && (start_x >= 1)) | |
4436 | Scroll(start_x - 1, start_y); | |
4437 | break; | |
4438 | } | |
4439 | case WXK_RIGHT: | |
4440 | { | |
4441 | if (x_page > 0) | |
4442 | Scroll(start_x + 1, start_y); | |
4443 | break; | |
4444 | } | |
4445 | case WXK_HOME: | |
4446 | { | |
4447 | Scroll(0, 0); | |
4448 | break; | |
4449 | } | |
4450 | // This is new | |
4451 | case WXK_END: | |
4452 | { | |
4453 | Scroll(start_x, y_pages+y); | |
4454 | break; | |
4455 | } | |
4456 | // end | |
4457 | } | |
4458 | } | |
2bda0e17 KB |
4459 | */ |
4460 | ||
4461 | // Setup background and foreground colours correctly | |
fd3f686c | 4462 | void wxWindow::SetupColours() |
2bda0e17 | 4463 | { |
564b2609 VZ |
4464 | if (GetParent()) |
4465 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
2bda0e17 KB |
4466 | } |
4467 | ||
2bda0e17 KB |
4468 | void wxWindow::OnIdle(wxIdleEvent& event) |
4469 | { | |
43d811ea JS |
4470 | // Check if we need to send a LEAVE event |
4471 | if (m_mouseInWindow) | |
4472 | { | |
4473 | POINT pt; | |
4474 | ::GetCursorPos(&pt); | |
4475 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
4476 | { | |
4477 | // Generate a LEAVE event | |
4478 | m_mouseInWindow = FALSE; | |
c085e333 | 4479 | |
2d524929 | 4480 | int state = 0; |
567da5c6 JS |
4481 | if (::GetKeyState(VK_SHIFT) != 0) |
4482 | state |= MK_SHIFT; | |
4483 | if (::GetKeyState(VK_CONTROL) != 0) | |
4484 | state |= MK_CONTROL; | |
c085e333 | 4485 | |
567da5c6 JS |
4486 | // Unfortunately the mouse button and keyboard state may have changed |
4487 | // by the time the OnIdle function is called, so 'state' may be | |
4488 | // meaningless. | |
c085e333 | 4489 | |
567da5c6 | 4490 | MSWOnMouseLeave(pt.x, pt.y, state); |
43d811ea JS |
4491 | } |
4492 | } | |
564b2609 | 4493 | UpdateWindowUI(); |
2bda0e17 KB |
4494 | } |
4495 | ||
4496 | // Raise the window to the top of the Z order | |
fd3f686c | 4497 | void wxWindow::Raise() |
2bda0e17 KB |
4498 | { |
4499 | ::BringWindowToTop((HWND) GetHWND()); | |
4500 | } | |
4501 | ||
4502 | // Lower the window to the bottom of the Z order | |
fd3f686c | 4503 | void wxWindow::Lower() |
2bda0e17 KB |
4504 | { |
4505 | ::SetWindowPos((HWND) GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); | |
4506 | } | |
4507 | ||
47cbd6da VZ |
4508 | long wxWindow::MSWGetDlgCode() |
4509 | { | |
2d0a075d JS |
4510 | // default: just forward to def window proc (the msg has no parameters) |
4511 | return MSWDefWindowProc(WM_GETDLGCODE, 0, 0); | |
47cbd6da VZ |
4512 | } |
4513 | ||
4514 | bool wxWindow::AcceptsFocus() const | |
4515 | { | |
3a19e16d | 4516 | // invisible and disabled controls don't need focus |
2d0a075d | 4517 | return IsShown() && IsEnabled(); |
47cbd6da VZ |
4518 | } |
4519 | ||
81d66cf3 JS |
4520 | // Update region access |
4521 | wxRegion wxWindow::GetUpdateRegion() const | |
4522 | { | |
4523 | return m_updateRegion; | |
4524 | } | |
4525 | ||
4526 | bool wxWindow::IsExposed(int x, int y, int w, int h) const | |
4527 | { | |
4528 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); | |
4529 | } | |
4530 | ||
4531 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
4532 | { | |
4533 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
4534 | } | |
4535 | ||
4536 | bool wxWindow::IsExposed(const wxRect& rect) const | |
4537 | { | |
4538 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
4539 | } | |
4540 | ||
4fabb575 JS |
4541 | // Set this window to be the child of 'parent'. |
4542 | bool wxWindow::Reparent(wxWindow *parent) | |
4543 | { | |
4544 | if (parent == GetParent()) | |
4545 | return TRUE; | |
4546 | ||
4547 | // Unlink this window from the existing parent. | |
4548 | if (GetParent()) | |
4549 | { | |
4550 | GetParent()->RemoveChild(this); | |
4551 | } | |
4552 | else | |
4553 | wxTopLevelWindows.DeleteObject(this); | |
4554 | ||
4555 | HWND hWndParent = 0; | |
4556 | HWND hWndChild = (HWND) GetHWND(); | |
4557 | if (parent != (wxWindow*) NULL) | |
4558 | { | |
4559 | parent->AddChild(this); | |
4560 | hWndParent = (HWND) parent->GetHWND(); | |
4561 | } | |
4562 | else | |
4563 | wxTopLevelWindows.Append(this); | |
4564 | ||
4565 | ::SetParent(hWndChild, hWndParent); | |
4566 | ||
4567 | return TRUE; | |
4568 | } | |
4569 | ||
b2aef89b | 4570 | #ifdef __WXDEBUG__ |
f449ef69 | 4571 | const char *wxGetMessageName(int message) |
47cbd6da | 4572 | { |
2d0a075d | 4573 | switch ( message ) { |
47cbd6da VZ |
4574 | case 0x0000: return "WM_NULL"; |
4575 | case 0x0001: return "WM_CREATE"; | |
4576 | case 0x0002: return "WM_DESTROY"; | |
4577 | case 0x0003: return "WM_MOVE"; | |
4578 | case 0x0005: return "WM_SIZE"; | |
4579 | case 0x0006: return "WM_ACTIVATE"; | |
4580 | case 0x0007: return "WM_SETFOCUS"; | |
4581 | case 0x0008: return "WM_KILLFOCUS"; | |
4582 | case 0x000A: return "WM_ENABLE"; | |
4583 | case 0x000B: return "WM_SETREDRAW"; | |
4584 | case 0x000C: return "WM_SETTEXT"; | |
4585 | case 0x000D: return "WM_GETTEXT"; | |
4586 | case 0x000E: return "WM_GETTEXTLENGTH"; | |
4587 | case 0x000F: return "WM_PAINT"; | |
4588 | case 0x0010: return "WM_CLOSE"; | |
4589 | case 0x0011: return "WM_QUERYENDSESSION"; | |
4590 | case 0x0012: return "WM_QUIT"; | |
4591 | case 0x0013: return "WM_QUERYOPEN"; | |
4592 | case 0x0014: return "WM_ERASEBKGND"; | |
4593 | case 0x0015: return "WM_SYSCOLORCHANGE"; | |
4594 | case 0x0016: return "WM_ENDSESSION"; | |
4595 | case 0x0017: return "WM_SYSTEMERROR"; | |
4596 | case 0x0018: return "WM_SHOWWINDOW"; | |
4597 | case 0x0019: return "WM_CTLCOLOR"; | |
4598 | case 0x001A: return "WM_WININICHANGE"; | |
4599 | case 0x001B: return "WM_DEVMODECHANGE"; | |
4600 | case 0x001C: return "WM_ACTIVATEAPP"; | |
4601 | case 0x001D: return "WM_FONTCHANGE"; | |
4602 | case 0x001E: return "WM_TIMECHANGE"; | |
4603 | case 0x001F: return "WM_CANCELMODE"; | |
4604 | case 0x0020: return "WM_SETCURSOR"; | |
4605 | case 0x0021: return "WM_MOUSEACTIVATE"; | |
4606 | case 0x0022: return "WM_CHILDACTIVATE"; | |
4607 | case 0x0023: return "WM_QUEUESYNC"; | |
4608 | case 0x0024: return "WM_GETMINMAXINFO"; | |
4609 | case 0x0026: return "WM_PAINTICON"; | |
4610 | case 0x0027: return "WM_ICONERASEBKGND"; | |
4611 | case 0x0028: return "WM_NEXTDLGCTL"; | |
4612 | case 0x002A: return "WM_SPOOLERSTATUS"; | |
4613 | case 0x002B: return "WM_DRAWITEM"; | |
4614 | case 0x002C: return "WM_MEASUREITEM"; | |
4615 | case 0x002D: return "WM_DELETEITEM"; | |
4616 | case 0x002E: return "WM_VKEYTOITEM"; | |
4617 | case 0x002F: return "WM_CHARTOITEM"; | |
4618 | case 0x0030: return "WM_SETFONT"; | |
4619 | case 0x0031: return "WM_GETFONT"; | |
4620 | case 0x0037: return "WM_QUERYDRAGICON"; | |
4621 | case 0x0039: return "WM_COMPAREITEM"; | |
4622 | case 0x0041: return "WM_COMPACTING"; | |
4623 | case 0x0044: return "WM_COMMNOTIFY"; | |
4624 | case 0x0046: return "WM_WINDOWPOSCHANGING"; | |
4625 | case 0x0047: return "WM_WINDOWPOSCHANGED"; | |
4626 | case 0x0048: return "WM_POWER"; | |
c085e333 | 4627 | |
a02eb1d2 VZ |
4628 | #ifdef __WIN32__ |
4629 | case 0x004A: return "WM_COPYDATA"; | |
4630 | case 0x004B: return "WM_CANCELJOURNAL"; | |
4631 | case 0x004E: return "WM_NOTIFY"; | |
4632 | case 0x0050: return "WM_INPUTLANGCHANGEREQUEST"; | |
4633 | case 0x0051: return "WM_INPUTLANGCHANGE"; | |
4634 | case 0x0052: return "WM_TCARD"; | |
4635 | case 0x0053: return "WM_HELP"; | |
4636 | case 0x0054: return "WM_USERCHANGED"; | |
4637 | case 0x0055: return "WM_NOTIFYFORMAT"; | |
4638 | case 0x007B: return "WM_CONTEXTMENU"; | |
4639 | case 0x007C: return "WM_STYLECHANGING"; | |
4640 | case 0x007D: return "WM_STYLECHANGED"; | |
4641 | case 0x007E: return "WM_DISPLAYCHANGE"; | |
4642 | case 0x007F: return "WM_GETICON"; | |
4643 | case 0x0080: return "WM_SETICON"; | |
4644 | #endif //WIN32 | |
c085e333 | 4645 | |
47cbd6da VZ |
4646 | case 0x0081: return "WM_NCCREATE"; |
4647 | case 0x0082: return "WM_NCDESTROY"; | |
4648 | case 0x0083: return "WM_NCCALCSIZE"; | |
4649 | case 0x0084: return "WM_NCHITTEST"; | |
4650 | case 0x0085: return "WM_NCPAINT"; | |
4651 | case 0x0086: return "WM_NCACTIVATE"; | |
4652 | case 0x0087: return "WM_GETDLGCODE"; | |
4653 | case 0x00A0: return "WM_NCMOUSEMOVE"; | |
4654 | case 0x00A1: return "WM_NCLBUTTONDOWN"; | |
4655 | case 0x00A2: return "WM_NCLBUTTONUP"; | |
4656 | case 0x00A3: return "WM_NCLBUTTONDBLCLK"; | |
4657 | case 0x00A4: return "WM_NCRBUTTONDOWN"; | |
4658 | case 0x00A5: return "WM_NCRBUTTONUP"; | |
4659 | case 0x00A6: return "WM_NCRBUTTONDBLCLK"; | |
4660 | case 0x00A7: return "WM_NCMBUTTONDOWN"; | |
4661 | case 0x00A8: return "WM_NCMBUTTONUP"; | |
4662 | case 0x00A9: return "WM_NCMBUTTONDBLCLK"; | |
4663 | case 0x0100: return "WM_KEYDOWN"; | |
4664 | case 0x0101: return "WM_KEYUP"; | |
4665 | case 0x0102: return "WM_CHAR"; | |
4666 | case 0x0103: return "WM_DEADCHAR"; | |
4667 | case 0x0104: return "WM_SYSKEYDOWN"; | |
4668 | case 0x0105: return "WM_SYSKEYUP"; | |
4669 | case 0x0106: return "WM_SYSCHAR"; | |
4670 | case 0x0107: return "WM_SYSDEADCHAR"; | |
4671 | case 0x0108: return "WM_KEYLAST"; | |
c085e333 | 4672 | |
a02eb1d2 VZ |
4673 | #ifdef __WIN32__ |
4674 | case 0x010D: return "WM_IME_STARTCOMPOSITION"; | |
4675 | case 0x010E: return "WM_IME_ENDCOMPOSITION"; | |
4676 | case 0x010F: return "WM_IME_COMPOSITION"; | |
4677 | #endif //WIN32 | |
c085e333 | 4678 | |
47cbd6da VZ |
4679 | case 0x0110: return "WM_INITDIALOG"; |
4680 | case 0x0111: return "WM_COMMAND"; | |
4681 | case 0x0112: return "WM_SYSCOMMAND"; | |
4682 | case 0x0113: return "WM_TIMER"; | |
4683 | case 0x0114: return "WM_HSCROLL"; | |
4684 | case 0x0115: return "WM_VSCROLL"; | |
4685 | case 0x0116: return "WM_INITMENU"; | |
4686 | case 0x0117: return "WM_INITMENUPOPUP"; | |
4687 | case 0x011F: return "WM_MENUSELECT"; | |
4688 | case 0x0120: return "WM_MENUCHAR"; | |
4689 | case 0x0121: return "WM_ENTERIDLE"; | |
4690 | case 0x0200: return "WM_MOUSEMOVE"; | |
4691 | case 0x0201: return "WM_LBUTTONDOWN"; | |
4692 | case 0x0202: return "WM_LBUTTONUP"; | |
4693 | case 0x0203: return "WM_LBUTTONDBLCLK"; | |
4694 | case 0x0204: return "WM_RBUTTONDOWN"; | |
4695 | case 0x0205: return "WM_RBUTTONUP"; | |
4696 | case 0x0206: return "WM_RBUTTONDBLCLK"; | |
4697 | case 0x0207: return "WM_MBUTTONDOWN"; | |
4698 | case 0x0208: return "WM_MBUTTONUP"; | |
4699 | case 0x0209: return "WM_MBUTTONDBLCLK"; | |
4700 | case 0x0210: return "WM_PARENTNOTIFY"; | |
a02eb1d2 VZ |
4701 | case 0x0211: return "WM_ENTERMENULOOP"; |
4702 | case 0x0212: return "WM_EXITMENULOOP"; | |
c085e333 | 4703 | |
a02eb1d2 VZ |
4704 | #ifdef __WIN32__ |
4705 | case 0x0213: return "WM_NEXTMENU"; | |
4706 | case 0x0214: return "WM_SIZING"; | |
4707 | case 0x0215: return "WM_CAPTURECHANGED"; | |
4708 | case 0x0216: return "WM_MOVING"; | |
4709 | case 0x0218: return "WM_POWERBROADCAST"; | |
4710 | case 0x0219: return "WM_DEVICECHANGE"; | |
4711 | #endif //WIN32 | |
c085e333 | 4712 | |
47cbd6da VZ |
4713 | case 0x0220: return "WM_MDICREATE"; |
4714 | case 0x0221: return "WM_MDIDESTROY"; | |
4715 | case 0x0222: return "WM_MDIACTIVATE"; | |
4716 | case 0x0223: return "WM_MDIRESTORE"; | |
4717 | case 0x0224: return "WM_MDINEXT"; | |
4718 | case 0x0225: return "WM_MDIMAXIMIZE"; | |
4719 | case 0x0226: return "WM_MDITILE"; | |
4720 | case 0x0227: return "WM_MDICASCADE"; | |
4721 | case 0x0228: return "WM_MDIICONARRANGE"; | |
4722 | case 0x0229: return "WM_MDIGETACTIVE"; | |
4723 | case 0x0230: return "WM_MDISETMENU"; | |
4724 | case 0x0233: return "WM_DROPFILES"; | |
c085e333 | 4725 | |
a02eb1d2 VZ |
4726 | #ifdef __WIN32__ |
4727 | case 0x0281: return "WM_IME_SETCONTEXT"; | |
4728 | case 0x0282: return "WM_IME_NOTIFY"; | |
4729 | case 0x0283: return "WM_IME_CONTROL"; | |
4730 | case 0x0284: return "WM_IME_COMPOSITIONFULL"; | |
4731 | case 0x0285: return "WM_IME_SELECT"; | |
4732 | case 0x0286: return "WM_IME_CHAR"; | |
4733 | case 0x0290: return "WM_IME_KEYDOWN"; | |
4734 | case 0x0291: return "WM_IME_KEYUP"; | |
4735 | #endif //WIN32 | |
c085e333 | 4736 | |
47cbd6da VZ |
4737 | case 0x0300: return "WM_CUT"; |
4738 | case 0x0301: return "WM_COPY"; | |
4739 | case 0x0302: return "WM_PASTE"; | |
4740 | case 0x0303: return "WM_CLEAR"; | |
4741 | case 0x0304: return "WM_UNDO"; | |
4742 | case 0x0305: return "WM_RENDERFORMAT"; | |
4743 | case 0x0306: return "WM_RENDERALLFORMATS"; | |
4744 | case 0x0307: return "WM_DESTROYCLIPBOARD"; | |
4745 | case 0x0308: return "WM_DRAWCLIPBOARD"; | |
4746 | case 0x0309: return "WM_PAINTCLIPBOARD"; | |
4747 | case 0x030A: return "WM_VSCROLLCLIPBOARD"; | |
4748 | case 0x030B: return "WM_SIZECLIPBOARD"; | |
4749 | case 0x030C: return "WM_ASKCBFORMATNAME"; | |
4750 | case 0x030D: return "WM_CHANGECBCHAIN"; | |
4751 | case 0x030E: return "WM_HSCROLLCLIPBOARD"; | |
4752 | case 0x030F: return "WM_QUERYNEWPALETTE"; | |
4753 | case 0x0310: return "WM_PALETTEISCHANGING"; | |
4754 | case 0x0311: return "WM_PALETTECHANGED"; | |
c085e333 | 4755 | |
a02eb1d2 | 4756 | #ifdef __WIN32__ |
2d0a075d JS |
4757 | // common controls messages - although they're not strictly speaking |
4758 | // standard, it's nice to decode them nevertheless | |
a02eb1d2 | 4759 | |
2d0a075d | 4760 | // listview |
a02eb1d2 VZ |
4761 | case 0x1000 + 0: return "LVM_GETBKCOLOR"; |
4762 | case 0x1000 + 1: return "LVM_SETBKCOLOR"; | |
4763 | case 0x1000 + 2: return "LVM_GETIMAGELIST"; | |
4764 | case 0x1000 + 3: return "LVM_SETIMAGELIST"; | |
4765 | case 0x1000 + 4: return "LVM_GETITEMCOUNT"; | |
4766 | case 0x1000 + 5: return "LVM_GETITEMA"; | |
4767 | case 0x1000 + 75: return "LVM_GETITEMW"; | |
4768 | case 0x1000 + 6: return "LVM_SETITEMA"; | |
4769 | case 0x1000 + 76: return "LVM_SETITEMW"; | |
4770 | case 0x1000 + 7: return "LVM_INSERTITEMA"; | |
4771 | case 0x1000 + 77: return "LVM_INSERTITEMW"; | |
4772 | case 0x1000 + 8: return "LVM_DELETEITEM"; | |
4773 | case 0x1000 + 9: return "LVM_DELETEALLITEMS"; | |
4774 | case 0x1000 + 10: return "LVM_GETCALLBACKMASK"; | |
4775 | case 0x1000 + 11: return "LVM_SETCALLBACKMASK"; | |
4776 | case 0x1000 + 12: return "LVM_GETNEXTITEM"; | |
4777 | case 0x1000 + 13: return "LVM_FINDITEMA"; | |
4778 | case 0x1000 + 83: return "LVM_FINDITEMW"; | |
4779 | case 0x1000 + 14: return "LVM_GETITEMRECT"; | |
4780 | case 0x1000 + 15: return "LVM_SETITEMPOSITION"; | |
4781 | case 0x1000 + 16: return "LVM_GETITEMPOSITION"; | |
4782 | case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA"; | |
4783 | case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW"; | |
4784 | case 0x1000 + 18: return "LVM_HITTEST"; | |
4785 | case 0x1000 + 19: return "LVM_ENSUREVISIBLE"; | |
4786 | case 0x1000 + 20: return "LVM_SCROLL"; | |
4787 | case 0x1000 + 21: return "LVM_REDRAWITEMS"; | |
4788 | case 0x1000 + 22: return "LVM_ARRANGE"; | |
4789 | case 0x1000 + 23: return "LVM_EDITLABELA"; | |
4790 | case 0x1000 + 118: return "LVM_EDITLABELW"; | |
4791 | case 0x1000 + 24: return "LVM_GETEDITCONTROL"; | |
4792 | case 0x1000 + 25: return "LVM_GETCOLUMNA"; | |
4793 | case 0x1000 + 95: return "LVM_GETCOLUMNW"; | |
4794 | case 0x1000 + 26: return "LVM_SETCOLUMNA"; | |
4795 | case 0x1000 + 96: return "LVM_SETCOLUMNW"; | |
4796 | case 0x1000 + 27: return "LVM_INSERTCOLUMNA"; | |
4797 | case 0x1000 + 97: return "LVM_INSERTCOLUMNW"; | |
4798 | case 0x1000 + 28: return "LVM_DELETECOLUMN"; | |
4799 | case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH"; | |
4800 | case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH"; | |
4801 | case 0x1000 + 31: return "LVM_GETHEADER"; | |
4802 | case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE"; | |
4803 | case 0x1000 + 34: return "LVM_GETVIEWRECT"; | |
4804 | case 0x1000 + 35: return "LVM_GETTEXTCOLOR"; | |
4805 | case 0x1000 + 36: return "LVM_SETTEXTCOLOR"; | |
4806 | case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR"; | |
4807 | case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR"; | |
4808 | case 0x1000 + 39: return "LVM_GETTOPINDEX"; | |
4809 | case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE"; | |
4810 | case 0x1000 + 41: return "LVM_GETORIGIN"; | |
4811 | case 0x1000 + 42: return "LVM_UPDATE"; | |
4812 | case 0x1000 + 43: return "LVM_SETITEMSTATE"; | |
4813 | case 0x1000 + 44: return "LVM_GETITEMSTATE"; | |
4814 | case 0x1000 + 45: return "LVM_GETITEMTEXTA"; | |
4815 | case 0x1000 + 115: return "LVM_GETITEMTEXTW"; | |
4816 | case 0x1000 + 46: return "LVM_SETITEMTEXTA"; | |
4817 | case 0x1000 + 116: return "LVM_SETITEMTEXTW"; | |
4818 | case 0x1000 + 47: return "LVM_SETITEMCOUNT"; | |
4819 | case 0x1000 + 48: return "LVM_SORTITEMS"; | |
4820 | case 0x1000 + 49: return "LVM_SETITEMPOSITION32"; | |
4821 | case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT"; | |
4822 | case 0x1000 + 51: return "LVM_GETITEMSPACING"; | |
4823 | case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA"; | |
4824 | case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW"; | |
4825 | case 0x1000 + 53: return "LVM_SETICONSPACING"; | |
4826 | case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE"; | |
4827 | case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE"; | |
4828 | case 0x1000 + 56: return "LVM_GETSUBITEMRECT"; | |
4829 | case 0x1000 + 57: return "LVM_SUBITEMHITTEST"; | |
4830 | case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY"; | |
4831 | case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY"; | |
4832 | case 0x1000 + 60: return "LVM_SETHOTITEM"; | |
4833 | case 0x1000 + 61: return "LVM_GETHOTITEM"; | |
4834 | case 0x1000 + 62: return "LVM_SETHOTCURSOR"; | |
4835 | case 0x1000 + 63: return "LVM_GETHOTCURSOR"; | |
4836 | case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT"; | |
4837 | case 0x1000 + 65: return "LVM_SETWORKAREA"; | |
c085e333 | 4838 | |
2d0a075d | 4839 | // tree view |
a02eb1d2 VZ |
4840 | case 0x1100 + 0: return "TVM_INSERTITEMA"; |
4841 | case 0x1100 + 50: return "TVM_INSERTITEMW"; | |
4842 | case 0x1100 + 1: return "TVM_DELETEITEM"; | |
4843 | case 0x1100 + 2: return "TVM_EXPAND"; | |
4844 | case 0x1100 + 4: return "TVM_GETITEMRECT"; | |
4845 | case 0x1100 + 5: return "TVM_GETCOUNT"; | |
4846 | case 0x1100 + 6: return "TVM_GETINDENT"; | |
4847 | case 0x1100 + 7: return "TVM_SETINDENT"; | |
4848 | case 0x1100 + 8: return "TVM_GETIMAGELIST"; | |
4849 | case 0x1100 + 9: return "TVM_SETIMAGELIST"; | |
4850 | case 0x1100 + 10: return "TVM_GETNEXTITEM"; | |
4851 | case 0x1100 + 11: return "TVM_SELECTITEM"; | |
4852 | case 0x1100 + 12: return "TVM_GETITEMA"; | |
4853 | case 0x1100 + 62: return "TVM_GETITEMW"; | |
4854 | case 0x1100 + 13: return "TVM_SETITEMA"; | |
4855 | case 0x1100 + 63: return "TVM_SETITEMW"; | |
4856 | case 0x1100 + 14: return "TVM_EDITLABELA"; | |
4857 | case 0x1100 + 65: return "TVM_EDITLABELW"; | |
4858 | case 0x1100 + 15: return "TVM_GETEDITCONTROL"; | |
4859 | case 0x1100 + 16: return "TVM_GETVISIBLECOUNT"; | |
4860 | case 0x1100 + 17: return "TVM_HITTEST"; | |
4861 | case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE"; | |
4862 | case 0x1100 + 19: return "TVM_SORTCHILDREN"; | |
4863 | case 0x1100 + 20: return "TVM_ENSUREVISIBLE"; | |
4864 | case 0x1100 + 21: return "TVM_SORTCHILDRENCB"; | |
4865 | case 0x1100 + 22: return "TVM_ENDEDITLABELNOW"; | |
4866 | case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA"; | |
4867 | case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW"; | |
4868 | case 0x1100 + 24: return "TVM_SETTOOLTIPS"; | |
4869 | case 0x1100 + 25: return "TVM_GETTOOLTIPS"; | |
c085e333 | 4870 | |
2d0a075d | 4871 | // header |
a02eb1d2 VZ |
4872 | case 0x1200 + 0: return "HDM_GETITEMCOUNT"; |
4873 | case 0x1200 + 1: return "HDM_INSERTITEMA"; | |
4874 | case 0x1200 + 10: return "HDM_INSERTITEMW"; | |
4875 | case 0x1200 + 2: return "HDM_DELETEITEM"; | |
4876 | case 0x1200 + 3: return "HDM_GETITEMA"; | |
4877 | case 0x1200 + 11: return "HDM_GETITEMW"; | |
4878 | case 0x1200 + 4: return "HDM_SETITEMA"; | |
4879 | case 0x1200 + 12: return "HDM_SETITEMW"; | |
4880 | case 0x1200 + 5: return "HDM_LAYOUT"; | |
4881 | case 0x1200 + 6: return "HDM_HITTEST"; | |
4882 | case 0x1200 + 7: return "HDM_GETITEMRECT"; | |
4883 | case 0x1200 + 8: return "HDM_SETIMAGELIST"; | |
4884 | case 0x1200 + 9: return "HDM_GETIMAGELIST"; | |
4885 | case 0x1200 + 15: return "HDM_ORDERTOINDEX"; | |
4886 | case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE"; | |
4887 | case 0x1200 + 17: return "HDM_GETORDERARRAY"; | |
4888 | case 0x1200 + 18: return "HDM_SETORDERARRAY"; | |
4889 | case 0x1200 + 19: return "HDM_SETHOTDIVIDER"; | |
c085e333 | 4890 | |
2d0a075d | 4891 | // tab control |
a02eb1d2 VZ |
4892 | case 0x1300 + 2: return "TCM_GETIMAGELIST"; |
4893 | case 0x1300 + 3: return "TCM_SETIMAGELIST"; | |
4894 | case 0x1300 + 4: return "TCM_GETITEMCOUNT"; | |
4895 | case 0x1300 + 5: return "TCM_GETITEMA"; | |
4896 | case 0x1300 + 60: return "TCM_GETITEMW"; | |
4897 | case 0x1300 + 6: return "TCM_SETITEMA"; | |
4898 | case 0x1300 + 61: return "TCM_SETITEMW"; | |
4899 | case 0x1300 + 7: return "TCM_INSERTITEMA"; | |
4900 | case 0x1300 + 62: return "TCM_INSERTITEMW"; | |
4901 | case 0x1300 + 8: return "TCM_DELETEITEM"; | |
4902 | case 0x1300 + 9: return "TCM_DELETEALLITEMS"; | |
4903 | case 0x1300 + 10: return "TCM_GETITEMRECT"; | |
4904 | case 0x1300 + 11: return "TCM_GETCURSEL"; | |
4905 | case 0x1300 + 12: return "TCM_SETCURSEL"; | |
4906 | case 0x1300 + 13: return "TCM_HITTEST"; | |
4907 | case 0x1300 + 14: return "TCM_SETITEMEXTRA"; | |
4908 | case 0x1300 + 40: return "TCM_ADJUSTRECT"; | |
4909 | case 0x1300 + 41: return "TCM_SETITEMSIZE"; | |
4910 | case 0x1300 + 42: return "TCM_REMOVEIMAGE"; | |
4911 | case 0x1300 + 43: return "TCM_SETPADDING"; | |
4912 | case 0x1300 + 44: return "TCM_GETROWCOUNT"; | |
4913 | case 0x1300 + 45: return "TCM_GETTOOLTIPS"; | |
4914 | case 0x1300 + 46: return "TCM_SETTOOLTIPS"; | |
4915 | case 0x1300 + 47: return "TCM_GETCURFOCUS"; | |
4916 | case 0x1300 + 48: return "TCM_SETCURFOCUS"; | |
4917 | case 0x1300 + 49: return "TCM_SETMINTABWIDTH"; | |
4918 | case 0x1300 + 50: return "TCM_DESELECTALL"; | |
c085e333 | 4919 | |
2d0a075d | 4920 | // toolbar |
a02eb1d2 VZ |
4921 | case WM_USER+1: return "TB_ENABLEBUTTON"; |
4922 | case WM_USER+2: return "TB_CHECKBUTTON"; | |
4923 | case WM_USER+3: return "TB_PRESSBUTTON"; | |
4924 | case WM_USER+4: return "TB_HIDEBUTTON"; | |
4925 | case WM_USER+5: return "TB_INDETERMINATE"; | |
4926 | case WM_USER+9: return "TB_ISBUTTONENABLED"; | |
4927 | case WM_USER+10: return "TB_ISBUTTONCHECKED"; | |
4928 | case WM_USER+11: return "TB_ISBUTTONPRESSED"; | |
4929 | case WM_USER+12: return "TB_ISBUTTONHIDDEN"; | |
4930 | case WM_USER+13: return "TB_ISBUTTONINDETERMINATE"; | |
4931 | case WM_USER+17: return "TB_SETSTATE"; | |
4932 | case WM_USER+18: return "TB_GETSTATE"; | |
4933 | case WM_USER+19: return "TB_ADDBITMAP"; | |
4934 | case WM_USER+20: return "TB_ADDBUTTONS"; | |
4935 | case WM_USER+21: return "TB_INSERTBUTTON"; | |
4936 | case WM_USER+22: return "TB_DELETEBUTTON"; | |
4937 | case WM_USER+23: return "TB_GETBUTTON"; | |
4938 | case WM_USER+24: return "TB_BUTTONCOUNT"; | |
4939 | case WM_USER+25: return "TB_COMMANDTOINDEX"; | |
4940 | case WM_USER+26: return "TB_SAVERESTOREA"; | |
4941 | case WM_USER+76: return "TB_SAVERESTOREW"; | |
4942 | case WM_USER+27: return "TB_CUSTOMIZE"; | |
4943 | case WM_USER+28: return "TB_ADDSTRINGA"; | |
4944 | case WM_USER+77: return "TB_ADDSTRINGW"; | |
4945 | case WM_USER+29: return "TB_GETITEMRECT"; | |
4946 | case WM_USER+30: return "TB_BUTTONSTRUCTSIZE"; | |
4947 | case WM_USER+31: return "TB_SETBUTTONSIZE"; | |
4948 | case WM_USER+32: return "TB_SETBITMAPSIZE"; | |
4949 | case WM_USER+33: return "TB_AUTOSIZE"; | |
4950 | case WM_USER+35: return "TB_GETTOOLTIPS"; | |
4951 | case WM_USER+36: return "TB_SETTOOLTIPS"; | |
4952 | case WM_USER+37: return "TB_SETPARENT"; | |
4953 | case WM_USER+39: return "TB_SETROWS"; | |
4954 | case WM_USER+40: return "TB_GETROWS"; | |
4955 | case WM_USER+42: return "TB_SETCMDID"; | |
4956 | case WM_USER+43: return "TB_CHANGEBITMAP"; | |
4957 | case WM_USER+44: return "TB_GETBITMAP"; | |
4958 | case WM_USER+45: return "TB_GETBUTTONTEXTA"; | |
4959 | case WM_USER+75: return "TB_GETBUTTONTEXTW"; | |
4960 | case WM_USER+46: return "TB_REPLACEBITMAP"; | |
4961 | case WM_USER+47: return "TB_SETINDENT"; | |
4962 | case WM_USER+48: return "TB_SETIMAGELIST"; | |
4963 | case WM_USER+49: return "TB_GETIMAGELIST"; | |
4964 | case WM_USER+50: return "TB_LOADIMAGES"; | |
4965 | case WM_USER+51: return "TB_GETRECT"; | |
4966 | case WM_USER+52: return "TB_SETHOTIMAGELIST"; | |
4967 | case WM_USER+53: return "TB_GETHOTIMAGELIST"; | |
4968 | case WM_USER+54: return "TB_SETDISABLEDIMAGELIST"; | |
4969 | case WM_USER+55: return "TB_GETDISABLEDIMAGELIST"; | |
4970 | case WM_USER+56: return "TB_SETSTYLE"; | |
4971 | case WM_USER+57: return "TB_GETSTYLE"; | |
4972 | case WM_USER+58: return "TB_GETBUTTONSIZE"; | |
4973 | case WM_USER+59: return "TB_SETBUTTONWIDTH"; | |
4974 | case WM_USER+60: return "TB_SETMAXTEXTROWS"; | |
4975 | case WM_USER+61: return "TB_GETTEXTROWS"; | |
4976 | case WM_USER+41: return "TB_GETBITMAPFLAGS"; | |
c085e333 | 4977 | |
a02eb1d2 | 4978 | #endif //WIN32 |
c085e333 | 4979 | |
47cbd6da | 4980 | default: |
2d0a075d JS |
4981 | static char s_szBuf[128]; |
4982 | sprintf(s_szBuf, "<unknown message = %d>", message); | |
4983 | return s_szBuf; | |
47cbd6da VZ |
4984 | } |
4985 | } | |
ea57084d | 4986 | #endif //__WXDEBUG__ |