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