]> git.saurik.com Git - wxWidgets.git/blob - src/msw/window.cpp
b851ac791943be62824c8d3f396adc56491b602c
[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 break;
1420 }
1421 case WM_CLOSE:
1422 {
1423 if (MSWOnClose())
1424 return 0L;
1425 else
1426 return 1L;
1427 break;
1428 }
1429
1430 case WM_GETMINMAXINFO:
1431 {
1432 MINMAXINFO *info = (MINMAXINFO *)lParam;
1433 if (m_minSizeX != -1)
1434 info->ptMinTrackSize.x = (int)m_minSizeX;
1435 if (m_minSizeY != -1)
1436 info->ptMinTrackSize.y = (int)m_minSizeY;
1437 if (m_maxSizeX != -1)
1438 info->ptMaxTrackSize.x = (int)m_maxSizeX;
1439 if (m_maxSizeY != -1)
1440 info->ptMaxTrackSize.y = (int)m_maxSizeY;
1441 return MSWDefWindowProc(message, wParam, lParam );
1442 break;
1443 }
1444
1445 case WM_GETDLGCODE:
1446 return MSWGetDlgCode();
1447
1448 default:
1449 return MSWDefWindowProc(message, wParam, lParam );
1450 }
1451 return 0; // Success: we processed this command.
1452 }
1453
1454 // Dialog window proc
1455 LONG APIENTRY _EXPORT
1456 wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1457 {
1458 return 0;
1459 }
1460
1461 wxList *wxWinHandleList = NULL;
1462 wxWindow *wxFindWinFromHandle(WXHWND hWnd)
1463 {
1464 wxNode *node = wxWinHandleList->Find((long)hWnd);
1465 if (!node)
1466 return NULL;
1467 return (wxWindow *)node->Data();
1468 }
1469
1470 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
1471 {
1472 // adding NULL hWnd is (first) surely a result of an error and
1473 // (secondly) breaks menu command processing
1474 wxCHECK_RET( hWnd != NULL, "attempt to add a NULL hWnd to window list" );
1475
1476 if ( !wxWinHandleList->Find((long)hWnd) )
1477 wxWinHandleList->Append((long)hWnd, win);
1478 }
1479
1480 void wxRemoveHandleAssociation(wxWindow *win)
1481 {
1482 wxWinHandleList->DeleteObject(win);
1483 }
1484
1485 // Default destroyer - override if you destroy it in some other way
1486 // (e.g. with MDI child windows)
1487 void wxWindow::MSWDestroyWindow(void)
1488 {
1489 }
1490
1491 void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
1492 int x, int y, int width, int height,
1493 WXDWORD style, const char *dialog_template, WXDWORD extendedStyle)
1494 {
1495 bool is_dialog = (dialog_template != NULL);
1496 int x1 = CW_USEDEFAULT;
1497 int y1 = 0;
1498 int width1 = CW_USEDEFAULT;
1499 int height1 = 100;
1500
1501 // Find parent's size, if it exists, to set up a possible default
1502 // panel size the size of the parent window
1503 RECT parent_rect;
1504 if (parent)
1505 {
1506 // Was GetWindowRect: JACS 5/5/95
1507 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect);
1508
1509 width1 = parent_rect.right - parent_rect.left;
1510 height1 = parent_rect.bottom - parent_rect.top;
1511 }
1512
1513 if (x > -1) x1 = x;
1514 if (y > -1) y1 = y;
1515 if (width > -1) width1 = width;
1516 if (height > -1) height1 = height;
1517
1518 HWND hParent = NULL;
1519 if (parent)
1520 hParent = (HWND) parent->GetHWND();
1521
1522 wxWndHook = this;
1523
1524 if (is_dialog)
1525 {
1526 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1527 // other compilers???
1528 // VZ: it's always needed for Win16 and never for Win32
1529 #ifdef __WIN32__
1530 m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent,
1531 (DLGPROC)wxDlgProc);
1532 #else
1533 DLGPROC dlgproc = (DLGPROC)MakeProcInstance((DLGPROC)wxWndProc, wxGetInstance());
1534
1535 m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent,
1536 (DLGPROC)dlgproc);
1537 #endif
1538
1539 if (m_hWnd == 0)
1540 MessageBox(NULL, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1541 "wxWindows Error", MB_ICONEXCLAMATION | MB_OK);
1542 else MoveWindow((HWND) m_hWnd, x1, y1, width1, height1, FALSE);
1543 }
1544 else
1545 {
1546 int controlId = 0;
1547 if (style & WS_CHILD)
1548 controlId = id;
1549 if (!title)
1550 title = "";
1551
1552 m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass,
1553 title,
1554 style,
1555 x1, y1,
1556 width1, height1,
1557 hParent, (HMENU)controlId, wxGetInstance(),
1558 NULL);
1559
1560 if ( !m_hWnd ) {
1561 wxLogError("Can't create window of class %s!\n"
1562 "Possible Windows 3.x compatibility problem?", wclass);
1563 }
1564 }
1565
1566 wxWndHook = NULL;
1567 wxWinHandleList->Append((long)m_hWnd, this);
1568
1569 #if WXDEBUG > 1
1570 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd);
1571 #endif
1572 }
1573
1574 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs))
1575 {
1576 }
1577
1578 bool wxWindow::MSWOnClose(void)
1579 {
1580 #if WXDEBUG > 1
1581 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle);
1582 #endif
1583 return FALSE;
1584 }
1585
1586 bool wxWindow::MSWOnDestroy(void)
1587 {
1588 #if WXDEBUG > 1
1589 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle);
1590 #endif
1591 // delete our drop target if we've got one
1592 #if wxUSE_DRAG_AND_DROP
1593 if ( m_pDropTarget != NULL ) {
1594 m_pDropTarget->Revoke(m_hWnd);
1595
1596 delete m_pDropTarget;
1597 m_pDropTarget = NULL;
1598 }
1599 #endif
1600
1601 return TRUE;
1602 }
1603
1604 // Deal with child commands from buttons etc.
1605
1606 bool wxWindow::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam)
1607 {
1608 #if defined(__WIN95__)
1609 // Find a child window to send the notification to, e.g. a toolbar.
1610 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1611 // handle of the toolbar; it's probably the handle of the tooltip
1612 // window (anyway, it's parent is also the toolbar's parent).
1613 // So, since we don't know which hWnd or wxWindow originated the
1614 // WM_NOTIFY, we'll need to go through all the children of this window
1615 // trying out MSWNotify.
1616 // This won't work now, though, because any number of controls
1617 // could respond to the same generic messages :-(
1618
1619 /* This doesn't work for toolbars, but try for other controls first.
1620 */
1621 NMHDR *hdr = (NMHDR *)lParam;
1622 HWND hWnd = (HWND)hdr->hwndFrom;
1623 wxWindow *win = wxFindWinFromHandle((WXHWND) hWnd);
1624
1625 if ( win )
1626 return win->MSWNotify(wParam, lParam);
1627 else
1628 {
1629 // Rely on MSWNotify to check whether the message
1630 // belongs to the window or not
1631 wxNode *node = GetChildren()->First();
1632 while (node)
1633 {
1634 wxWindow *child = (wxWindow *)node->Data();
1635 if ( child->MSWNotify(wParam, lParam) )
1636 return TRUE;
1637 node = node->Next();
1638 }
1639 }
1640
1641 return FALSE;
1642
1643 #endif
1644 return FALSE;
1645 }
1646
1647 void wxWindow::MSWOnMenuHighlight(WXWORD WXUNUSED(item), WXWORD WXUNUSED(flags), WXHMENU WXUNUSED(sysmenu))
1648 {
1649 #if WXDEBUG > 1
1650 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle);
1651 #endif
1652 }
1653
1654 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem)
1655 {
1656 }
1657
1658 bool wxWindow::MSWOnActivate(int state, bool WXUNUSED(minimized), WXHWND WXUNUSED(activate))
1659 {
1660 #if WXDEBUG > 1
1661 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle);
1662 #endif
1663
1664 wxActivateEvent event(wxEVT_ACTIVATE, ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)),
1665 m_windowId);
1666 event.SetEventObject(this);
1667 GetEventHandler()->ProcessEvent(event);
1668 return 0;
1669 }
1670
1671 bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd))
1672 {
1673 #if WXDEBUG > 1
1674 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd);
1675 #endif
1676 // Deal with caret
1677 if (m_caretEnabled && (m_caretWidth > 0) && (m_caretHeight > 0))
1678 {
1679 ::CreateCaret((HWND) GetHWND(), NULL, m_caretWidth, m_caretHeight);
1680 if (m_caretShown)
1681 ::ShowCaret((HWND) GetHWND());
1682 }
1683
1684 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
1685 event.SetEventObject(this);
1686 if (!GetEventHandler()->ProcessEvent(event))
1687 Default();
1688 return TRUE;
1689 }
1690
1691 bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd))
1692 {
1693 #if WXDEBUG > 1
1694 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd);
1695 #endif
1696 // Deal with caret
1697 if (m_caretEnabled)
1698 {
1699 ::DestroyCaret();
1700 }
1701
1702 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
1703 event.SetEventObject(this);
1704 if (!GetEventHandler()->ProcessEvent(event))
1705 Default();
1706 return TRUE;
1707 }
1708
1709 void wxWindow::MSWOnDropFiles(WXWPARAM wParam)
1710 {
1711 #if WXDEBUG > 1
1712 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd);
1713 #endif
1714
1715 HDROP hFilesInfo = (HDROP) wParam;
1716 POINT dropPoint;
1717 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
1718
1719 // Get the total number of files dropped
1720 WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo,
1721 (UINT)-1,
1722 (LPSTR)0,
1723 (UINT)0);
1724
1725 wxString *files = new wxString[gwFilesDropped];
1726 int wIndex;
1727 for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
1728 {
1729 DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000);
1730 files[wIndex] = wxBuffer;
1731 }
1732 DragFinish (hFilesInfo);
1733
1734 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
1735 event.m_eventObject = this;
1736 event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
1737
1738 if (!GetEventHandler()->ProcessEvent(event))
1739 Default();
1740
1741 delete[] files;
1742 }
1743
1744 bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
1745 {
1746 #if wxUSE_OWNER_DRAWN
1747 if ( id == 0 ) { // is it a menu item?
1748 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
1749 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
1750 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
1751
1752 // prepare to call OnDrawItem()
1753 wxDC dc;
1754 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
1755 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
1756 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
1757 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
1758 return pMenuItem->OnDrawItem(
1759 dc, rect,
1760 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
1761 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
1762 );
1763 }
1764 #endif // owner-drawn menus
1765
1766 wxWindow *item = FindItem(id);
1767 #if wxUSE_DYNAMIC_CLASSES
1768 if (item && item->IsKindOf(CLASSINFO(wxControl)))
1769 {
1770 return ((wxControl *)item)->MSWOnDraw(itemStruct);
1771 }
1772 else
1773 #endif
1774 return FALSE;
1775 }
1776
1777 bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
1778 {
1779 #if wxUSE_OWNER_DRAWN
1780 if ( id == 0 ) { // is it a menu item?
1781 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
1782 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
1783 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
1784
1785 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
1786 &pMeasureStruct->itemHeight);
1787 }
1788 #endif // owner-drawn menus
1789
1790 wxWindow *item = FindItem(id);
1791 #if wxUSE_DYNAMIC_CLASSES
1792 if (item && item->IsKindOf(CLASSINFO(wxControl)))
1793 {
1794 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
1795 }
1796 else
1797 #endif
1798 return FALSE;
1799 }
1800
1801 WXHBRUSH wxWindow::MSWOnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
1802 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1803 {
1804 #if WXDEBUG > 1
1805 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd);
1806 #endif
1807 if (nCtlColor == CTLCOLOR_DLG)
1808 {
1809 return OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
1810 }
1811
1812 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
1813
1814 WXHBRUSH hBrush = 0;
1815
1816 if ( item )
1817 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
1818
1819 // I think that even for dialogs, we may need to call DefWindowProc (?)
1820 // Or maybe just rely on the usual default behaviour.
1821 if ( !hBrush )
1822 hBrush = (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam);
1823
1824 return hBrush ;
1825 }
1826
1827 // Define for each class of dialog and control
1828 WXHBRUSH wxWindow::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
1829 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1830 {
1831 return (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam);
1832 }
1833
1834 bool wxWindow::MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1835 {
1836 wxSysColourChangedEvent event;
1837 event.SetEventObject(this);
1838
1839 // Check if app handles this.
1840 if (GetEventHandler()->ProcessEvent(event))
1841 return 0;
1842
1843 // We didn't process it
1844 return 1;
1845 }
1846
1847 long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange)
1848 {
1849 wxPaletteChangedEvent event(GetId());
1850 event.SetEventObject(this);
1851 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
1852 GetEventHandler()->ProcessEvent(event);
1853 return 0;
1854 }
1855
1856 long wxWindow::MSWOnQueryNewPalette()
1857 {
1858 wxQueryNewPaletteEvent event(GetId());
1859 event.SetEventObject(this);
1860 if (!GetEventHandler()->ProcessEvent(event) || !event.GetPaletteRealized())
1861 {
1862 return (long) FALSE;
1863 }
1864 else
1865 return (long) TRUE;
1866 }
1867
1868 // Responds to colour changes: passes event on to children.
1869 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
1870 {
1871 wxNode *node = GetChildren()->First();
1872 while ( node )
1873 {
1874 // Only propagate to non-top-level windows
1875 wxWindow *win = (wxWindow *)node->Data();
1876 if ( win->GetParent() )
1877 {
1878 wxSysColourChangedEvent event2;
1879 event.m_eventObject = win;
1880 win->GetEventHandler()->ProcessEvent(event2);
1881 }
1882
1883 node = node->Next();
1884 }
1885 }
1886
1887 long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1888 {
1889 if ( m_oldWndProc )
1890 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1891 else
1892 return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam);
1893 }
1894
1895 long wxWindow::Default()
1896 {
1897 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1898 if (m_lastMsg == 0)
1899 return 0;
1900
1901 #ifdef __WXDEBUG__
1902 wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.",
1903 wxGetMessageName(m_lastMsg));
1904 #endif // WXDEBUG
1905
1906 return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam);
1907 }
1908
1909 bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
1910 {
1911 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) {
1912 // intercept dialog navigation keys
1913 MSG *msg = (MSG *)pMsg;
1914 bool bProcess = TRUE;
1915 if ( msg->message != WM_KEYDOWN )
1916 bProcess = FALSE;
1917
1918 if ( (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
1919 bProcess = FALSE;
1920
1921 bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
1922
1923 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1924 // (except for Ctrl-Tab combination which is always processed)
1925 LONG lDlgCode = 0;
1926 if ( bProcess && !bCtrlDown ) {
1927 lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
1928 }
1929
1930 bool bForward;
1931 if ( bProcess ) {
1932 switch ( msg->wParam ) {
1933 case VK_TAB:
1934 if ( lDlgCode & DLGC_WANTTAB ) // this is FALSE for Ctrl-Tab
1935 bProcess = FALSE;
1936 else
1937 bForward = !(::GetKeyState(VK_SHIFT) & 0x100);
1938 break;
1939
1940 case VK_UP:
1941 case VK_LEFT:
1942 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1943 bProcess = FALSE;
1944 else
1945 bForward = FALSE;
1946 break;
1947
1948 case VK_DOWN:
1949 case VK_RIGHT:
1950 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1951 bProcess = FALSE;
1952 else
1953 bForward = TRUE;
1954 break;
1955
1956 default:
1957 bProcess = FALSE;
1958 }
1959 }
1960
1961 if ( bProcess ) {
1962 wxNavigationKeyEvent event;
1963 event.SetDirection(bForward);
1964 event.SetWindowChange(bCtrlDown);
1965 event.SetEventObject(this);
1966
1967 if ( GetEventHandler()->ProcessEvent(event) )
1968 return TRUE;
1969 }
1970
1971 return ::IsDialogMessage((HWND)GetHWND(), msg) != 0;
1972 }
1973
1974 return FALSE;
1975 }
1976
1977 bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
1978 {
1979 if (m_acceleratorTable.Ok() &&
1980 ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg))
1981 return TRUE;
1982 else
1983 return FALSE;
1984 }
1985
1986 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate))
1987 {
1988 #if WXDEBUG > 1
1989 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd);
1990 #endif
1991 return 1;
1992 }
1993
1994 void wxWindow::MSWDetachWindowMenu(void)
1995 {
1996 if (m_hMenu)
1997 {
1998 int N = GetMenuItemCount((HMENU) m_hMenu);
1999 int i;
2000 for (i = 0; i < N; i++)
2001 {
2002 char buf[100];
2003 int chars = GetMenuString((HMENU) m_hMenu, i, buf, 100, MF_BYPOSITION);
2004 if ((chars > 0) && (strcmp(buf, "&Window") == 0))
2005 {
2006 RemoveMenu((HMENU) m_hMenu, i, MF_BYPOSITION);
2007 break;
2008 }
2009 }
2010 }
2011 }
2012
2013 bool wxWindow::MSWOnPaint(void)
2014 {
2015 #ifdef __WIN32__
2016 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2017 ::GetUpdateRgn((HWND) GetHWND(), hRegion, FALSE);
2018
2019 m_updateRegion = wxRegion((WXHRGN) hRegion);
2020 #else
2021 RECT updateRect;
2022 ::GetUpdateRect((HWND) GetHWND(), & updateRect, FALSE);
2023
2024 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
2025 updateRect.right - updateRect.left, updateRect.bottom - updateRect.top);
2026 #endif
2027
2028 wxPaintEvent event(m_windowId);
2029 event.SetEventObject(this);
2030 if (!GetEventHandler()->ProcessEvent(event))
2031 Default();
2032 return TRUE;
2033 }
2034
2035 void wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag))
2036 {
2037 if (m_inOnSize)
2038 return;
2039
2040 #if WXDEBUG > 1
2041 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd);
2042 #endif
2043 if (!m_hWnd)
2044 return;
2045
2046 m_inOnSize = TRUE;
2047
2048 wxSizeEvent event(wxSize(w, h), m_windowId);
2049 event.SetEventObject(this);
2050 if (!GetEventHandler()->ProcessEvent(event))
2051 Default();
2052
2053 m_inOnSize = FALSE;
2054 }
2055
2056 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos))
2057 {
2058 Default();
2059 }
2060
2061 // Deal with child commands from buttons etc.
2062 bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
2063 {
2064 #if WXDEBUG > 1
2065 wxDebugMsg("wxWindow::MSWOnCommand\n");
2066 #endif
2067 if (wxCurrentPopupMenu)
2068 {
2069 wxMenu *popupMenu = wxCurrentPopupMenu;
2070 wxCurrentPopupMenu = NULL;
2071 bool succ = popupMenu->MSWCommand(cmd, id);
2072 return succ;
2073 }
2074 #if WXDEBUG > 1
2075 char buf[80];
2076 sprintf(buf, "Looking for item %d...\n", id);
2077 wxDebugMsg(buf);
2078 #endif
2079
2080 wxWindow *item = FindItem(id);
2081 if (item)
2082 {
2083 bool value = item->MSWCommand(cmd, id);
2084 #if WXDEBUG > 1
2085 if (value)
2086 wxDebugMsg("MSWCommand succeeded\n");
2087 else
2088 wxDebugMsg("MSWCommand failed\n");
2089 #endif
2090 return value;
2091 }
2092 else
2093 {
2094 wxWindow *win = wxFindWinFromHandle(control);
2095 if (win)
2096 return win->MSWCommand(cmd, id);
2097 }
2098 return FALSE;
2099 }
2100
2101 long wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam)
2102 {
2103 switch (wParam)
2104 {
2105 case SC_MAXIMIZE:
2106 {
2107 wxMaximizeEvent event(m_windowId);
2108 event.SetEventObject(this);
2109 if (!GetEventHandler()->ProcessEvent(event))
2110 return Default();
2111 else
2112 return 0;
2113 break;
2114 }
2115 case SC_MINIMIZE:
2116 {
2117 wxIconizeEvent event(m_windowId);
2118 event.SetEventObject(this);
2119 if (!GetEventHandler()->ProcessEvent(event))
2120 return Default();
2121 else
2122 return 0;
2123 break;
2124 }
2125 default:
2126 return Default();
2127 }
2128 return 0;
2129 }
2130
2131 void wxWindow::MSWOnLButtonDown(int x, int y, WXUINT flags)
2132 {
2133 wxMouseEvent event(wxEVT_LEFT_DOWN);
2134
2135 event.m_x = x; event.m_y = y;
2136 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2137 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2138 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2139 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2140 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2141 event.SetTimestamp(wxApp::sm_lastMessageTime);
2142 event.m_eventObject = this;
2143
2144 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_DOWN;
2145
2146 if (!GetEventHandler()->ProcessEvent(event))
2147 Default();
2148 }
2149
2150 void wxWindow::MSWOnLButtonUp(int x, int y, WXUINT flags)
2151 {
2152 wxMouseEvent event(wxEVT_LEFT_UP);
2153
2154 event.m_x = x; event.m_y = y;
2155 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2156 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2157 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2158 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2159 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2160 event.SetTimestamp(wxApp::sm_lastMessageTime);
2161 event.m_eventObject = this;
2162
2163 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_UP;
2164
2165 if (!GetEventHandler()->ProcessEvent(event))
2166 Default();
2167 }
2168
2169 void wxWindow::MSWOnLButtonDClick(int x, int y, WXUINT flags)
2170 {
2171 wxMouseEvent event(wxEVT_LEFT_DCLICK);
2172
2173 event.m_x = x; event.m_y = y;
2174 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2175 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2176 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2177 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2178 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2179 event.SetTimestamp(wxApp::sm_lastMessageTime);
2180 event.m_eventObject = this;
2181
2182 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DCLICK;
2183
2184 if (!GetEventHandler()->ProcessEvent(event))
2185 Default();
2186 }
2187
2188 void wxWindow::MSWOnMButtonDown(int x, int y, WXUINT flags)
2189 {
2190 wxMouseEvent event(wxEVT_MIDDLE_DOWN);
2191
2192 event.m_x = x; event.m_y = y;
2193 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2194 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2195 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2196 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2197 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2198 event.SetTimestamp(wxApp::sm_lastMessageTime);
2199 event.m_eventObject = this;
2200
2201 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DOWN;
2202
2203 if (!GetEventHandler()->ProcessEvent(event))
2204 Default();
2205 }
2206
2207 void wxWindow::MSWOnMButtonUp(int x, int y, WXUINT flags)
2208 {
2209 //wxDebugMsg("MButtonUp\n") ;
2210 wxMouseEvent event(wxEVT_MIDDLE_UP);
2211
2212 event.m_x = x; event.m_y = y;
2213 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2214 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2215 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2216 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2217 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2218 event.SetTimestamp(wxApp::sm_lastMessageTime);
2219 event.m_eventObject = this;
2220
2221 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_UP;
2222
2223 if (!GetEventHandler()->ProcessEvent(event))
2224 Default();
2225 }
2226
2227 void wxWindow::MSWOnMButtonDClick(int x, int y, WXUINT flags)
2228 {
2229 wxMouseEvent event(wxEVT_MIDDLE_DCLICK);
2230
2231 event.m_x = x; event.m_y = y;
2232 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2233 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2234 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2235 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2236 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2237 event.SetTimestamp(wxApp::sm_lastMessageTime);
2238 event.m_eventObject = this;
2239
2240 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DCLICK;
2241
2242 if (!GetEventHandler()->ProcessEvent(event))
2243 Default();
2244 }
2245
2246 void wxWindow::MSWOnRButtonDown(int x, int y, WXUINT flags)
2247 {
2248 wxMouseEvent event(wxEVT_RIGHT_DOWN);
2249
2250 event.m_x = x; event.m_y = y;
2251 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2252 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2253 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2254 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2255 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2256 event.SetTimestamp(wxApp::sm_lastMessageTime);
2257 event.m_eventObject = this;
2258
2259 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DOWN;
2260
2261 if (!GetEventHandler()->ProcessEvent(event))
2262 Default();
2263 }
2264
2265 void wxWindow::MSWOnRButtonUp(int x, int y, WXUINT flags)
2266 {
2267 wxMouseEvent event(wxEVT_RIGHT_UP);
2268
2269 event.m_x = x; event.m_y = y;
2270 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2271 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2272 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2273 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2274 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2275 event.m_eventObject = this;
2276 event.SetTimestamp(wxApp::sm_lastMessageTime);
2277
2278 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_UP;
2279
2280 if (!GetEventHandler()->ProcessEvent(event))
2281 Default();
2282 }
2283
2284 void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags)
2285 {
2286 wxMouseEvent event(wxEVT_RIGHT_DCLICK);
2287
2288 event.m_x = x; event.m_y = y;
2289 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2290 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2291 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2292 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2293 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2294 event.SetTimestamp(wxApp::sm_lastMessageTime);
2295 event.m_eventObject = this;
2296
2297 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DCLICK;
2298
2299 if (!GetEventHandler()->ProcessEvent(event))
2300 Default();
2301 }
2302
2303 void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags)
2304 {
2305 // 'normal' move event...
2306 // Set cursor, but only if we're not in 'busy' mode
2307
2308 // Trouble with this is that it sets the cursor for controls too :-(
2309 if (m_windowCursor.Ok() && !wxIsBusy())
2310 ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
2311
2312 if (!m_mouseInWindow)
2313 {
2314 // Generate an ENTER event
2315 m_mouseInWindow = TRUE;
2316 MSWOnMouseEnter(x, y, flags);
2317 }
2318
2319 wxMouseEvent event(wxEVT_MOTION);
2320
2321 event.m_x = x; event.m_y = y;
2322 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2323 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2324 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2325 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2326 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2327 event.SetTimestamp(wxApp::sm_lastMessageTime);
2328 event.m_eventObject = this;
2329
2330 // Window gets a click down message followed by a mouse move
2331 // message even if position isn't changed! We want to discard
2332 // the trailing move event if x and y are the same.
2333 if ((m_lastEvent == wxEVT_RIGHT_DOWN || m_lastEvent == wxEVT_LEFT_DOWN ||
2334 m_lastEvent == wxEVT_MIDDLE_DOWN) &&
2335 (m_lastXPos == event.m_x && m_lastYPos == event.m_y))
2336 {
2337 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2338 m_lastEvent = wxEVT_MOTION;
2339 return;
2340 }
2341
2342 m_lastEvent = wxEVT_MOTION;
2343 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2344
2345 if (!GetEventHandler()->ProcessEvent(event))
2346 Default();
2347 }
2348
2349 void wxWindow::MSWOnMouseEnter(int x, int y, WXUINT flags)
2350 {
2351 wxMouseEvent event(wxEVT_ENTER_WINDOW);
2352
2353 event.m_x = x; event.m_y = y;
2354 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2355 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2356 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2357 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2358 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2359 event.SetTimestamp(wxApp::sm_lastMessageTime);
2360 event.m_eventObject = this;
2361
2362 m_lastEvent = wxEVT_ENTER_WINDOW;
2363 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2364 // No message - ensure we don't try to call the default behaviour accidentally.
2365 m_lastMsg = 0;
2366 GetEventHandler()->ProcessEvent(event);
2367 }
2368
2369 void wxWindow::MSWOnMouseLeave(int x, int y, WXUINT flags)
2370 {
2371 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
2372
2373 event.m_x = x; event.m_y = y;
2374 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2375 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2376 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2377 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2378 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2379 event.SetTimestamp(wxApp::sm_lastMessageTime);
2380 event.m_eventObject = this;
2381
2382 m_lastEvent = wxEVT_LEAVE_WINDOW;
2383 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2384 // No message - ensure we don't try to call the default behaviour accidentally.
2385 m_lastMsg = 0;
2386 GetEventHandler()->ProcessEvent(event);
2387 }
2388
2389 void wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
2390 {
2391 int id;
2392 bool tempControlDown = FALSE;
2393 if (isASCII)
2394 {
2395 // If 1 -> 26, translate to CTRL plus a letter.
2396 id = wParam;
2397 if ((id > 0) && (id < 27))
2398 {
2399 switch (id)
2400 {
2401 case 13:
2402 {
2403 id = WXK_RETURN;
2404 break;
2405 }
2406 case 8:
2407 {
2408 id = WXK_BACK;
2409 break;
2410 }
2411 case 9:
2412 {
2413 id = WXK_TAB;
2414 break;
2415 }
2416 default:
2417 {
2418 tempControlDown = TRUE;
2419 id = id + 96;
2420 }
2421 }
2422 }
2423 }
2424 else if ((id = wxCharCodeMSWToWX(wParam)) == 0) {
2425 // it's ASCII and will be processed here only when called from
2426 // WM_CHAR (i.e. when isASCII = TRUE)
2427 id = -1;
2428 }
2429
2430 if (id != -1)
2431 {
2432 wxKeyEvent event(wxEVT_CHAR);
2433 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2434 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2435 if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
2436 event.m_altDown = TRUE;
2437
2438 event.m_eventObject = this;
2439 event.m_keyCode = id;
2440 event.SetTimestamp(wxApp::sm_lastMessageTime);
2441
2442 POINT pt ;
2443 GetCursorPos(&pt) ;
2444 RECT rect ;
2445 GetWindowRect((HWND) GetHWND(),&rect) ;
2446 pt.x -= rect.left ;
2447 pt.y -= rect.top ;
2448
2449 event.m_x = pt.x; event.m_y = pt.y;
2450
2451 if (!GetEventHandler()->ProcessEvent(event))
2452 Default();
2453 }
2454 }
2455
2456 void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags)
2457 {
2458 int buttons = 0;
2459 int change = 0;
2460 if (flags & JOY_BUTTON1CHG)
2461 change = wxJOY_BUTTON1;
2462 if (flags & JOY_BUTTON2CHG)
2463 change = wxJOY_BUTTON2;
2464 if (flags & JOY_BUTTON3CHG)
2465 change = wxJOY_BUTTON3;
2466 if (flags & JOY_BUTTON4CHG)
2467 change = wxJOY_BUTTON4;
2468
2469 if (flags & JOY_BUTTON1)
2470 buttons |= wxJOY_BUTTON1;
2471 if (flags & JOY_BUTTON2)
2472 buttons |= wxJOY_BUTTON2;
2473 if (flags & JOY_BUTTON3)
2474 buttons |= wxJOY_BUTTON3;
2475 if (flags & JOY_BUTTON4)
2476 buttons |= wxJOY_BUTTON4;
2477
2478 wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN, buttons, joystick, change);
2479 event.SetPosition(wxPoint(x, y));
2480 event.SetEventObject(this);
2481
2482 GetEventHandler()->ProcessEvent(event);
2483 }
2484
2485 void wxWindow::MSWOnJoyUp(int joystick, int x, int y, WXUINT flags)
2486 {
2487 int buttons = 0;
2488 int change = 0;
2489 if (flags & JOY_BUTTON1CHG)
2490 change = wxJOY_BUTTON1;
2491 if (flags & JOY_BUTTON2CHG)
2492 change = wxJOY_BUTTON2;
2493 if (flags & JOY_BUTTON3CHG)
2494 change = wxJOY_BUTTON3;
2495 if (flags & JOY_BUTTON4CHG)
2496 change = wxJOY_BUTTON4;
2497
2498 if (flags & JOY_BUTTON1)
2499 buttons |= wxJOY_BUTTON1;
2500 if (flags & JOY_BUTTON2)
2501 buttons |= wxJOY_BUTTON2;
2502 if (flags & JOY_BUTTON3)
2503 buttons |= wxJOY_BUTTON3;
2504 if (flags & JOY_BUTTON4)
2505 buttons |= wxJOY_BUTTON4;
2506
2507 wxJoystickEvent event(wxEVT_JOY_BUTTON_UP, buttons, joystick, change);
2508 event.SetPosition(wxPoint(x, y));
2509 event.SetEventObject(this);
2510
2511 GetEventHandler()->ProcessEvent(event);
2512 }
2513
2514 void wxWindow::MSWOnJoyMove(int joystick, int x, int y, WXUINT flags)
2515 {
2516 int buttons = 0;
2517 if (flags & JOY_BUTTON1)
2518 buttons |= wxJOY_BUTTON1;
2519 if (flags & JOY_BUTTON2)
2520 buttons |= wxJOY_BUTTON2;
2521 if (flags & JOY_BUTTON3)
2522 buttons |= wxJOY_BUTTON3;
2523 if (flags & JOY_BUTTON4)
2524 buttons |= wxJOY_BUTTON4;
2525
2526 wxJoystickEvent event(wxEVT_JOY_MOVE, buttons, joystick, 0);
2527 event.SetPosition(wxPoint(x, y));
2528 event.SetEventObject(this);
2529
2530 GetEventHandler()->ProcessEvent(event);
2531 }
2532
2533 void wxWindow::MSWOnJoyZMove(int joystick, int z, WXUINT flags)
2534 {
2535 int buttons = 0;
2536 if (flags & JOY_BUTTON1)
2537 buttons |= wxJOY_BUTTON1;
2538 if (flags & JOY_BUTTON2)
2539 buttons |= wxJOY_BUTTON2;
2540 if (flags & JOY_BUTTON3)
2541 buttons |= wxJOY_BUTTON3;
2542 if (flags & JOY_BUTTON4)
2543 buttons |= wxJOY_BUTTON4;
2544
2545 wxJoystickEvent event(wxEVT_JOY_ZMOVE, buttons, joystick, 0);
2546 event.SetZPosition(z);
2547 event.SetEventObject(this);
2548
2549 GetEventHandler()->ProcessEvent(event);
2550 }
2551
2552 void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control)
2553 {
2554 if (control)
2555 {
2556 wxWindow *child = wxFindWinFromHandle(control);
2557 if ( child )
2558 child->MSWOnVScroll(wParam, pos, control);
2559 return;
2560 }
2561
2562 wxScrollEvent event;
2563 event.SetPosition(pos);
2564 event.SetOrientation(wxVERTICAL);
2565 event.m_eventObject = this;
2566
2567 switch ( wParam )
2568 {
2569 case SB_TOP:
2570 event.m_eventType = wxEVT_SCROLL_TOP;
2571 break;
2572
2573 case SB_BOTTOM:
2574 event.m_eventType = wxEVT_SCROLL_BOTTOM;
2575 break;
2576
2577 case SB_LINEUP:
2578 event.m_eventType = wxEVT_SCROLL_LINEUP;
2579 break;
2580
2581 case SB_LINEDOWN:
2582 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
2583 break;
2584
2585 case SB_PAGEUP:
2586 event.m_eventType = wxEVT_SCROLL_PAGEUP;
2587 break;
2588
2589 case SB_PAGEDOWN:
2590 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
2591 break;
2592
2593 case SB_THUMBTRACK:
2594 case SB_THUMBPOSITION:
2595 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
2596 break;
2597
2598 default:
2599 return;
2600 break;
2601 }
2602
2603 if (!GetEventHandler()->ProcessEvent(event))
2604 Default();
2605 }
2606
2607 void wxWindow::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control)
2608 {
2609 if (control)
2610 {
2611 wxWindow *child = wxFindWinFromHandle(control);
2612 if ( child ) {
2613 child->MSWOnHScroll(wParam, pos, control);
2614
2615 return;
2616 }
2617 }
2618 else {
2619 wxScrollEvent event;
2620 event.SetPosition(pos);
2621 event.SetOrientation(wxHORIZONTAL);
2622 event.m_eventObject = this;
2623
2624 switch ( wParam )
2625 {
2626 case SB_TOP:
2627 event.m_eventType = wxEVT_SCROLL_TOP;
2628 break;
2629
2630 case SB_BOTTOM:
2631 event.m_eventType = wxEVT_SCROLL_BOTTOM;
2632 break;
2633
2634 case SB_LINEUP:
2635 event.m_eventType = wxEVT_SCROLL_LINEUP;
2636 break;
2637
2638 case SB_LINEDOWN:
2639 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
2640 break;
2641
2642 case SB_PAGEUP:
2643 event.m_eventType = wxEVT_SCROLL_PAGEUP;
2644 break;
2645
2646 case SB_PAGEDOWN:
2647 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
2648 break;
2649
2650 case SB_THUMBTRACK:
2651 case SB_THUMBPOSITION:
2652 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
2653 break;
2654
2655 default:
2656 return;
2657 }
2658
2659 if ( GetEventHandler()->ProcessEvent(event) )
2660 return;
2661 }
2662
2663 // call the default WM_HSCROLL handler: it's non trivial in some common
2664 // controls (up-down control for example)
2665 Default();
2666 }
2667
2668 void wxWindow::MSWOnShow(bool show, int status)
2669 {
2670 wxShowEvent event(GetId(), show);
2671 event.m_eventObject = this;
2672 GetEventHandler()->ProcessEvent(event);
2673 }
2674
2675 bool wxWindow::MSWOnInitDialog(WXHWND WXUNUSED(hWndFocus))
2676 {
2677 wxInitDialogEvent event(GetId());
2678 event.m_eventObject = this;
2679 GetEventHandler()->ProcessEvent(event);
2680 return TRUE;
2681 }
2682
2683 void wxWindow::InitDialog(void)
2684 {
2685 wxInitDialogEvent event(GetId());
2686 event.SetEventObject( this );
2687 GetEventHandler()->ProcessEvent(event);
2688 }
2689
2690 // Default init dialog behaviour is to transfer data to window
2691 void wxWindow::OnInitDialog(wxInitDialogEvent& event)
2692 {
2693 TransferDataToWindow();
2694 }
2695
2696 void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
2697 {
2698 TEXTMETRIC tm;
2699 HDC dc = ::GetDC((HWND) wnd);
2700 HFONT fnt =0;
2701 HFONT was = 0;
2702 if (the_font)
2703 {
2704 #if WXDEBUG > 1
2705 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt);
2706 #endif
2707 // the_font->UseResource();
2708 // the_font->RealizeResource();
2709 if ((fnt=(HFONT) the_font->GetResourceHandle()))
2710 was = (HFONT) SelectObject(dc,fnt) ;
2711 }
2712 GetTextMetrics(dc, &tm);
2713 if (the_font && fnt && was)
2714 {
2715 #if WXDEBUG > 1
2716 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was);
2717 #endif
2718 SelectObject(dc,was) ;
2719 }
2720 ReleaseDC((HWND)wnd, dc);
2721 *x = tm.tmAveCharWidth;
2722 *y = tm.tmHeight + tm.tmExternalLeading;
2723
2724 // if (the_font)
2725 // the_font->ReleaseResource();
2726 }
2727
2728 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2729 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2730 int wxCharCodeMSWToWX(int keySym)
2731 {
2732 int id = 0;
2733 switch (keySym)
2734 {
2735 case VK_CANCEL: id = WXK_CANCEL; break;
2736 case VK_BACK: id = WXK_BACK; break;
2737 case VK_TAB: id = WXK_TAB; break;
2738 case VK_CLEAR: id = WXK_CLEAR; break;
2739 case VK_RETURN: id = WXK_RETURN; break;
2740 case VK_SHIFT: id = WXK_SHIFT; break;
2741 case VK_CONTROL: id = WXK_CONTROL; break;
2742 case VK_MENU : id = WXK_MENU; break;
2743 case VK_PAUSE: id = WXK_PAUSE; break;
2744 case VK_SPACE: id = WXK_SPACE; break;
2745 case VK_ESCAPE: id = WXK_ESCAPE; break;
2746 case VK_PRIOR: id = WXK_PRIOR; break;
2747 case VK_NEXT : id = WXK_NEXT; break;
2748 case VK_END: id = WXK_END; break;
2749 case VK_HOME : id = WXK_HOME; break;
2750 case VK_LEFT : id = WXK_LEFT; break;
2751 case VK_UP: id = WXK_UP; break;
2752 case VK_RIGHT: id = WXK_RIGHT; break;
2753 case VK_DOWN : id = WXK_DOWN; break;
2754 case VK_SELECT: id = WXK_SELECT; break;
2755 case VK_PRINT: id = WXK_PRINT; break;
2756 case VK_EXECUTE: id = WXK_EXECUTE; break;
2757 case VK_INSERT: id = WXK_INSERT; break;
2758 case VK_DELETE: id = WXK_DELETE; break;
2759 case VK_HELP : id = WXK_HELP; break;
2760 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
2761 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
2762 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
2763 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
2764 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
2765 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
2766 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
2767 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
2768 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
2769 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
2770 case VK_MULTIPLY: id = WXK_MULTIPLY; break;
2771 case VK_ADD: id = WXK_ADD; break;
2772 case VK_SUBTRACT: id = WXK_SUBTRACT; break;
2773 case VK_DECIMAL: id = WXK_DECIMAL; break;
2774 case VK_DIVIDE: id = WXK_DIVIDE; break;
2775 case VK_F1: id = WXK_F1; break;
2776 case VK_F2: id = WXK_F2; break;
2777 case VK_F3: id = WXK_F3; break;
2778 case VK_F4: id = WXK_F4; break;
2779 case VK_F5: id = WXK_F5; break;
2780 case VK_F6: id = WXK_F6; break;
2781 case VK_F7: id = WXK_F7; break;
2782 case VK_F8: id = WXK_F8; break;
2783 case VK_F9: id = WXK_F9; break;
2784 case VK_F10: id = WXK_F10; break;
2785 case VK_F11: id = WXK_F11; break;
2786 case VK_F12: id = WXK_F12; break;
2787 case VK_F13: id = WXK_F13; break;
2788 case VK_F14: id = WXK_F14; break;
2789 case VK_F15: id = WXK_F15; break;
2790 case VK_F16: id = WXK_F16; break;
2791 case VK_F17: id = WXK_F17; break;
2792 case VK_F18: id = WXK_F18; break;
2793 case VK_F19: id = WXK_F19; break;
2794 case VK_F20: id = WXK_F20; break;
2795 case VK_F21: id = WXK_F21; break;
2796 case VK_F22: id = WXK_F22; break;
2797 case VK_F23: id = WXK_F23; break;
2798 case VK_F24: id = WXK_F24; break;
2799 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
2800 case VK_SCROLL: id = WXK_SCROLL; break;
2801 default:
2802 {
2803 return 0;
2804 }
2805 }
2806 return id;
2807 }
2808
2809 int wxCharCodeWXToMSW(int id, bool *isVirtual)
2810 {
2811 *isVirtual = TRUE;
2812 int keySym = 0;
2813 switch (id)
2814 {
2815 case WXK_CANCEL: keySym = VK_CANCEL; break;
2816 case WXK_CLEAR: keySym = VK_CLEAR; break;
2817 case WXK_SHIFT: keySym = VK_SHIFT; break;
2818 case WXK_CONTROL: keySym = VK_CONTROL; break;
2819 case WXK_MENU : keySym = VK_MENU; break;
2820 case WXK_PAUSE: keySym = VK_PAUSE; break;
2821 case WXK_PRIOR: keySym = VK_PRIOR; break;
2822 case WXK_NEXT : keySym = VK_NEXT; break;
2823 case WXK_END: keySym = VK_END; break;
2824 case WXK_HOME : keySym = VK_HOME; break;
2825 case WXK_LEFT : keySym = VK_LEFT; break;
2826 case WXK_UP: keySym = VK_UP; break;
2827 case WXK_RIGHT: keySym = VK_RIGHT; break;
2828 case WXK_DOWN : keySym = VK_DOWN; break;
2829 case WXK_SELECT: keySym = VK_SELECT; break;
2830 case WXK_PRINT: keySym = VK_PRINT; break;
2831 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
2832 case WXK_INSERT: keySym = VK_INSERT; break;
2833 case WXK_DELETE: keySym = VK_DELETE; break;
2834 case WXK_HELP : keySym = VK_HELP; break;
2835 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
2836 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
2837 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
2838 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
2839 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
2840 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
2841 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
2842 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
2843 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
2844 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
2845 case WXK_MULTIPLY: keySym = VK_MULTIPLY; break;
2846 case WXK_ADD: keySym = VK_ADD; break;
2847 case WXK_SUBTRACT: keySym = VK_SUBTRACT; break;
2848 case WXK_DECIMAL: keySym = VK_DECIMAL; break;
2849 case WXK_DIVIDE: keySym = VK_DIVIDE; break;
2850 case WXK_F1: keySym = VK_F1; break;
2851 case WXK_F2: keySym = VK_F2; break;
2852 case WXK_F3: keySym = VK_F3; break;
2853 case WXK_F4: keySym = VK_F4; break;
2854 case WXK_F5: keySym = VK_F5; break;
2855 case WXK_F6: keySym = VK_F6; break;
2856 case WXK_F7: keySym = VK_F7; break;
2857 case WXK_F8: keySym = VK_F8; break;
2858 case WXK_F9: keySym = VK_F9; break;
2859 case WXK_F10: keySym = VK_F10; break;
2860 case WXK_F11: keySym = VK_F11; break;
2861 case WXK_F12: keySym = VK_F12; break;
2862 case WXK_F13: keySym = VK_F13; break;
2863 case WXK_F14: keySym = VK_F14; break;
2864 case WXK_F15: keySym = VK_F15; break;
2865 case WXK_F16: keySym = VK_F16; break;
2866 case WXK_F17: keySym = VK_F17; break;
2867 case WXK_F18: keySym = VK_F18; break;
2868 case WXK_F19: keySym = VK_F19; break;
2869 case WXK_F20: keySym = VK_F20; break;
2870 case WXK_F21: keySym = VK_F21; break;
2871 case WXK_F22: keySym = VK_F22; break;
2872 case WXK_F23: keySym = VK_F23; break;
2873 case WXK_F24: keySym = VK_F24; break;
2874 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
2875 case WXK_SCROLL: keySym = VK_SCROLL; break;
2876 default:
2877 {
2878 *isVirtual = FALSE;
2879 keySym = id;
2880 break;
2881 }
2882 }
2883 return keySym;
2884 }
2885
2886 // Caret manipulation
2887 void wxWindow::CreateCaret(int w, int h)
2888 {
2889 m_caretWidth = w;
2890 m_caretHeight = h;
2891 m_caretEnabled = TRUE;
2892 }
2893
2894 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
2895 {
2896 // Not implemented
2897 }
2898
2899 void wxWindow::ShowCaret(bool show)
2900 {
2901 if (m_caretEnabled)
2902 {
2903 if (show)
2904 ::ShowCaret((HWND) GetHWND());
2905 else
2906 ::HideCaret((HWND) GetHWND());
2907 m_caretShown = show;
2908 }
2909 }
2910
2911 void wxWindow::DestroyCaret(void)
2912 {
2913 m_caretEnabled = FALSE;
2914 }
2915
2916 void wxWindow::SetCaretPos(int x, int y)
2917 {
2918 ::SetCaretPos(x, y);
2919 }
2920
2921 void wxWindow::GetCaretPos(int *x, int *y) const
2922 {
2923 POINT point;
2924 ::GetCaretPos(&point);
2925 *x = point.x;
2926 *y = point.y;
2927 }
2928
2929 wxWindow *wxGetActiveWindow(void)
2930 {
2931 HWND hWnd = GetActiveWindow();
2932 if (hWnd != 0)
2933 {
2934 return wxFindWinFromHandle((WXHWND) hWnd);
2935 }
2936 return NULL;
2937 }
2938
2939 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2940 // in active frames and dialogs, regardless of where the focus is.
2941 static HHOOK wxTheKeyboardHook = 0;
2942 static FARPROC wxTheKeyboardHookProc = 0;
2943 int APIENTRY _EXPORT
2944 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
2945
2946 void wxSetKeyboardHook(bool doIt)
2947 {
2948 if (doIt)
2949 {
2950 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
2951 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
2952 #ifdef __WIN32__
2953 GetCurrentThreadId());
2954 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2955 #else
2956 GetCurrentTask());
2957 #endif
2958 }
2959 else
2960 {
2961 UnhookWindowsHookEx(wxTheKeyboardHook);
2962 FreeProcInstance(wxTheKeyboardHookProc);
2963 }
2964 }
2965
2966 int APIENTRY _EXPORT
2967 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
2968 {
2969 DWORD hiWord = HIWORD(lParam);
2970 if (nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0))
2971 {
2972 int id;
2973 if ((id = wxCharCodeMSWToWX(wParam)) != 0)
2974 {
2975 wxKeyEvent event(wxEVT_CHAR_HOOK);
2976 if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
2977 event.m_altDown = TRUE;
2978
2979 event.m_eventObject = NULL;
2980 event.m_keyCode = id;
2981 /* begin Albert's fix for control and shift key 26.5 */
2982 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2983 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2984 /* end Albert's fix for control and shift key 26.5 */
2985 event.SetTimestamp(wxApp::sm_lastMessageTime);
2986
2987 wxWindow *win = wxGetActiveWindow();
2988 if (win)
2989 {
2990 if (win->GetEventHandler()->ProcessEvent(event))
2991 return 1;
2992 }
2993 else
2994 {
2995 if ( wxTheApp && wxTheApp->ProcessEvent(event) )
2996 return 1;
2997 }
2998 }
2999 }
3000 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
3001 }
3002
3003 void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH))
3004 {
3005 m_minSizeX = minW;
3006 m_minSizeY = minH;
3007 m_maxSizeX = maxW;
3008 m_maxSizeY = maxH;
3009 }
3010
3011 void wxWindow::Centre(int direction)
3012 {
3013 int x, y, width, height, panel_width, panel_height, new_x, new_y;
3014
3015 wxWindow *father = (wxWindow *)GetParent();
3016 if (!father)
3017 return;
3018
3019 father->GetClientSize(&panel_width, &panel_height);
3020 GetSize(&width, &height);
3021 GetPosition(&x, &y);
3022
3023 new_x = -1;
3024 new_y = -1;
3025
3026 if (direction & wxHORIZONTAL)
3027 new_x = (int)((panel_width - width)/2);
3028
3029 if (direction & wxVERTICAL)
3030 new_y = (int)((panel_height - height)/2);
3031
3032 SetSize(new_x, new_y, -1, -1);
3033
3034 }
3035
3036 /* TODO (maybe)
3037 void wxWindow::OnPaint(void)
3038 {
3039 PaintSelectionHandles();
3040 }
3041 */
3042
3043 void wxWindow::WarpPointer (int x_pos, int y_pos)
3044 {
3045 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3046 // pixel coordinates, relatives to the canvas -- So, we first need to
3047 // substract origin of the window, then convert to screen position
3048
3049 int x = x_pos; int y = y_pos;
3050 RECT rect;
3051 GetWindowRect ((HWND) GetHWND(), &rect);
3052
3053 x += rect.left;
3054 y += rect.top;
3055
3056 SetCursorPos (x, y);
3057 }
3058
3059 void wxWindow::MSWDeviceToLogical (float *x, float *y) const
3060 {
3061 }
3062
3063 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC)
3064 {
3065 wxDC dc ;
3066
3067 dc.SetHDC(pDC);
3068 dc.SetWindow(this);
3069 dc.BeginDrawing();
3070
3071 wxEraseEvent event(m_windowId, &dc);
3072 event.m_eventObject = this;
3073 if (!GetEventHandler()->ProcessEvent(event))
3074 {
3075 dc.EndDrawing();
3076 dc.SelectOldObjects(pDC);
3077 return FALSE;
3078 }
3079 else
3080 {
3081 dc.EndDrawing();
3082 dc.SelectOldObjects(pDC);
3083 }
3084
3085 dc.SetHDC((WXHDC) NULL);
3086 return TRUE;
3087 }
3088
3089 void wxWindow::OnEraseBackground(wxEraseEvent& event)
3090 {
3091 RECT rect;
3092 ::GetClientRect((HWND) GetHWND(), &rect);
3093
3094 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3095 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
3096
3097 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3098 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
3099 ::DeleteObject(hBrush);
3100 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
3101 /*
3102 // Less efficient version (and doesn't account for scrolling)
3103 int w, h;
3104 GetClientSize(& w, & h);
3105 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3106 event.GetDC()->SetBrush(brush);
3107 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3108
3109 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3110 */
3111 }
3112
3113 #if WXWIN_COMPATIBILITY
3114 void wxWindow::SetScrollRange(int orient, int range, bool refresh)
3115 {
3116 #if defined(__WIN95__)
3117
3118 int range1 = range;
3119
3120 // Try to adjust the range to cope with page size > 1
3121 // - a Windows API quirk
3122 int pageSize = GetScrollPage(orient);
3123 if ( pageSize > 1 && range > 0)
3124 {
3125 range1 += (pageSize - 1);
3126 }
3127
3128 SCROLLINFO info;
3129 int dir;
3130
3131 if (orient == wxHORIZONTAL) {
3132 dir = SB_HORZ;
3133 } else {
3134 dir = SB_VERT;
3135 }
3136
3137 info.cbSize = sizeof(SCROLLINFO);
3138 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
3139 info.nMin = 0;
3140 info.nMax = range1;
3141 info.nPos = 0;
3142 info.fMask = SIF_RANGE | SIF_PAGE;
3143
3144 HWND hWnd = (HWND) GetHWND();
3145 if (hWnd)
3146 ::SetScrollInfo(hWnd, dir, &info, refresh);
3147 #else
3148 int wOrient ;
3149 if (orient == wxHORIZONTAL)
3150 wOrient = SB_HORZ;
3151 else
3152 wOrient = SB_VERT;
3153
3154 HWND hWnd = (HWND) GetHWND();
3155 if (hWnd)
3156 ::SetScrollRange(hWnd, wOrient, 0, range, refresh);
3157 #endif
3158 }
3159
3160 void wxWindow::SetScrollPage(int orient, int page, bool refresh)
3161 {
3162 #if defined(__WIN95__)
3163 SCROLLINFO info;
3164 int dir;
3165
3166 if (orient == wxHORIZONTAL) {
3167 dir = SB_HORZ;
3168 m_xThumbSize = page;
3169 } else {
3170 dir = SB_VERT;
3171 m_yThumbSize = page;
3172 }
3173
3174 info.cbSize = sizeof(SCROLLINFO);
3175 info.nPage = page;
3176 info.nMin = 0;
3177 info.fMask = SIF_PAGE ;
3178
3179 HWND hWnd = (HWND) GetHWND();
3180 if (hWnd)
3181 ::SetScrollInfo(hWnd, dir, &info, refresh);
3182 #else
3183 if (orient == wxHORIZONTAL)
3184 m_xThumbSize = page;
3185 else
3186 m_yThumbSize = page;
3187 #endif
3188 }
3189
3190 int wxWindow::OldGetScrollRange(int orient) const
3191 {
3192 int wOrient ;
3193 if (orient == wxHORIZONTAL)
3194 wOrient = SB_HORZ;
3195 else
3196 wOrient = SB_VERT;
3197
3198 #if __WATCOMC__ && defined(__WINDOWS_386__)
3199 short minPos, maxPos;
3200 #else
3201 int minPos, maxPos;
3202 #endif
3203 HWND hWnd = (HWND) GetHWND();
3204 if (hWnd)
3205 {
3206 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
3207 #if defined(__WIN95__)
3208 // Try to adjust the range to cope with page size > 1
3209 // - a Windows API quirk
3210 int pageSize = GetScrollPage(orient);
3211 if ( pageSize > 1 )
3212 {
3213 maxPos -= (pageSize - 1);
3214 }
3215 #endif
3216 return maxPos;
3217 }
3218 else
3219 return 0;
3220 }
3221
3222 int wxWindow::GetScrollPage(int orient) const
3223 {
3224 if (orient == wxHORIZONTAL)
3225 return m_xThumbSize;
3226 else
3227 return m_yThumbSize;
3228 }
3229 #endif
3230
3231 int wxWindow::GetScrollPos(int orient) const
3232 {
3233 int wOrient ;
3234 if (orient == wxHORIZONTAL)
3235 wOrient = SB_HORZ;
3236 else
3237 wOrient = SB_VERT;
3238 HWND hWnd = (HWND) GetHWND();
3239 if (hWnd)
3240 {
3241 return ::GetScrollPos(hWnd, wOrient);
3242 }
3243 else
3244 return 0;
3245 }
3246
3247 // This now returns the whole range, not just the number
3248 // of positions that we can scroll.
3249 int wxWindow::GetScrollRange(int orient) const
3250 {
3251 int wOrient ;
3252 if (orient == wxHORIZONTAL)
3253 wOrient = SB_HORZ;
3254 else
3255 wOrient = SB_VERT;
3256
3257 #if __WATCOMC__ && defined(__WINDOWS_386__)
3258 short minPos, maxPos;
3259 #else
3260 int minPos, maxPos;
3261 #endif
3262 HWND hWnd = (HWND) GetHWND();
3263 if (hWnd)
3264 {
3265 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
3266 #if defined(__WIN95__)
3267 // Try to adjust the range to cope with page size > 1
3268 // - a Windows API quirk
3269 int pageSize = GetScrollPage(orient);
3270 if ( pageSize > 1 )
3271 {
3272 maxPos -= (pageSize - 1);
3273 }
3274 // October 10th: new range concept.
3275 maxPos += pageSize;
3276 #endif
3277
3278 return maxPos;
3279 }
3280 else
3281 return 0;
3282 }
3283
3284 int wxWindow::GetScrollThumb(int orient) const
3285 {
3286 if (orient == wxHORIZONTAL)
3287 return m_xThumbSize;
3288 else
3289 return m_yThumbSize;
3290 }
3291
3292 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
3293 {
3294 #if defined(__WIN95__)
3295 SCROLLINFO info;
3296 int dir;
3297
3298 if (orient == wxHORIZONTAL) {
3299 dir = SB_HORZ;
3300 } else {
3301 dir = SB_VERT;
3302 }
3303
3304 info.cbSize = sizeof(SCROLLINFO);
3305 info.nPage = 0;
3306 info.nMin = 0;
3307 info.nPos = pos;
3308 info.fMask = SIF_POS ;
3309
3310 HWND hWnd = (HWND) GetHWND();
3311 if (hWnd)
3312 ::SetScrollInfo(hWnd, dir, &info, refresh);
3313 #else
3314 int wOrient ;
3315 if (orient == wxHORIZONTAL)
3316 wOrient = SB_HORZ;
3317 else
3318 wOrient = SB_VERT;
3319
3320 HWND hWnd = (HWND) GetHWND();
3321 if (hWnd)
3322 ::SetScrollPos(hWnd, wOrient, pos, refresh);
3323 #endif
3324 }
3325
3326 // New function that will replace some of the above.
3327 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
3328 int range, bool refresh)
3329 {
3330 /*
3331 SetScrollPage(orient, thumbVisible, FALSE);
3332
3333 int oldRange = range - thumbVisible ;
3334 SetScrollRange(orient, oldRange, FALSE);
3335
3336 SetScrollPos(orient, pos, refresh);
3337 */
3338 #if defined(__WIN95__)
3339 int oldRange = range - thumbVisible ;
3340
3341 int range1 = oldRange;
3342
3343 // Try to adjust the range to cope with page size > 1
3344 // - a Windows API quirk
3345 int pageSize = thumbVisible;
3346 if ( pageSize > 1 && range > 0)
3347 {
3348 range1 += (pageSize - 1);
3349 }
3350
3351 SCROLLINFO info;
3352 int dir;
3353
3354 if (orient == wxHORIZONTAL) {
3355 dir = SB_HORZ;
3356 } else {
3357 dir = SB_VERT;
3358 }
3359
3360 info.cbSize = sizeof(SCROLLINFO);
3361 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
3362 info.nMin = 0;
3363 info.nMax = range1;
3364 info.nPos = pos;
3365 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
3366
3367 HWND hWnd = (HWND) GetHWND();
3368 if (hWnd)
3369 ::SetScrollInfo(hWnd, dir, &info, refresh);
3370 #else
3371 int wOrient ;
3372 if (orient == wxHORIZONTAL)
3373 wOrient = SB_HORZ;
3374 else
3375 wOrient = SB_VERT;
3376
3377 HWND hWnd = (HWND) GetHWND();
3378 if (hWnd)
3379 {
3380 ::SetScrollRange(hWnd, wOrient, 0, range, FALSE);
3381 ::SetScrollPos(hWnd, wOrient, pos, refresh);
3382 }
3383 #endif
3384 if (orient == wxHORIZONTAL) {
3385 m_xThumbSize = thumbVisible;
3386 } else {
3387 m_yThumbSize = thumbVisible;
3388 }
3389 }
3390
3391 void wxWindow::ScrollWindow(int dx, int dy, const wxRectangle *rect)
3392 {
3393 RECT rect2;
3394 if ( rect )
3395 {
3396 rect2.left = rect->x;
3397 rect2.top = rect->y;
3398 rect2.right = rect->x + rect->width;
3399 rect2.bottom = rect->y + rect->height;
3400 }
3401
3402 if ( rect )
3403 ::ScrollWindow((HWND) GetHWND(), dx, dy, &rect2, NULL);
3404 else
3405 ::ScrollWindow((HWND) GetHWND(), dx, dy, NULL, NULL);
3406 }
3407
3408 void wxWindow::SetFont(const wxFont& font)
3409 {
3410 m_windowFont = font;
3411
3412 if (!m_windowFont.Ok())
3413 return;
3414
3415 HWND hWnd = (HWND) GetHWND();
3416 if (hWnd != 0)
3417 {
3418 if (m_windowFont.GetResourceHandle())
3419 SendMessage(hWnd, WM_SETFONT,
3420 (WPARAM)m_windowFont.GetResourceHandle(),TRUE);
3421 }
3422 }
3423
3424 void wxWindow::SubclassWin(WXHWND hWnd)
3425 {
3426 wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" );
3427
3428 wxAssociateWinWithHandle((HWND)hWnd, this);
3429
3430 m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC);
3431 SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc);
3432 }
3433
3434 void wxWindow::UnsubclassWin(void)
3435 {
3436 wxRemoveHandleAssociation(this);
3437
3438 // Restore old Window proc
3439 if ((HWND) GetHWND())
3440 {
3441 FARPROC farProc = (FARPROC) GetWindowLong((HWND) GetHWND(), GWL_WNDPROC);
3442 if ((m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc))
3443 {
3444 SetWindowLong((HWND) GetHWND(), GWL_WNDPROC, (LONG) m_oldWndProc);
3445 m_oldWndProc = 0;
3446 }
3447 }
3448 }
3449
3450 // Make a Windows extended style from the given wxWindows window style
3451 WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders)
3452 {
3453 WXDWORD exStyle = 0;
3454 if ( style & wxTRANSPARENT_WINDOW )
3455 exStyle |= WS_EX_TRANSPARENT ;
3456
3457 if ( !eliminateBorders )
3458 {
3459 if ( style & wxSUNKEN_BORDER )
3460 exStyle |= WS_EX_CLIENTEDGE ;
3461 if ( style & wxDOUBLE_BORDER )
3462 exStyle |= WS_EX_DLGMODALFRAME ;
3463 #if defined(__WIN95__)
3464 if ( style & wxRAISED_BORDER )
3465 exStyle |= WS_EX_WINDOWEDGE ;
3466 if ( style & wxSTATIC_BORDER )
3467 exStyle |= WS_EX_STATICEDGE ;
3468 #endif
3469 }
3470 return exStyle;
3471 }
3472
3473 // Determines whether native 3D effects or CTL3D should be used,
3474 // applying a default border style if required, and returning an extended
3475 // style to pass to CreateWindowEx.
3476 WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D)
3477 {
3478 // If matches certain criteria, then assume no 3D effects
3479 // unless specifically requested (dealt with in MakeExtendedStyle)
3480 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) )
3481 {
3482 *want3D = FALSE;
3483 return MakeExtendedStyle(m_windowStyle, FALSE);
3484 }
3485
3486 // Determine whether we should be using 3D effects or not.
3487 bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
3488
3489 // 1) App can specify global 3D effects
3490 *want3D = wxTheApp->GetAuto3D();
3491
3492 // 2) If the parent is being drawn with user colours, or simple border specified,
3493 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3494 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER))
3495 *want3D = FALSE;
3496
3497 // 3) Control can override this global setting by defining
3498 // a border style, e.g. wxSUNKEN_BORDER
3499 if (m_windowStyle & wxSUNKEN_BORDER )
3500 *want3D = TRUE;
3501
3502 // 4) If it's a special border, CTL3D can't cope so we want a native border
3503 if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
3504 (m_windowStyle & wxSTATIC_BORDER) )
3505 {
3506 *want3D = TRUE;
3507 nativeBorder = TRUE;
3508 }
3509
3510 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3511 // effects from extended style
3512 #if CTL3D
3513 if ( *want3D )
3514 nativeBorder = FALSE;
3515 #endif
3516
3517 DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
3518
3519 // If we want 3D, but haven't specified a border here,
3520 // apply the default border style specified.
3521 // TODO what about non-Win95 WIN32? Does it have borders?
3522 #if defined(__WIN95__) && !CTL3D
3523 if (defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
3524 (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
3525 exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE ;
3526 #endif
3527
3528 return exStyle;
3529 }
3530
3531 void wxWindow::OnChar(wxKeyEvent& event)
3532 {
3533 if ( event.KeyCode() == WXK_TAB ) {
3534 // propagate the TABs to the parent - it's up to it to decide what
3535 // to do with it
3536 if ( GetParent() ) {
3537 if ( GetParent()->ProcessEvent(event) )
3538 return;
3539 }
3540 }
3541
3542 bool isVirtual;
3543 int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual);
3544
3545 if ( id == -1 )
3546 id= m_lastWParam;
3547
3548 if ( !event.ControlDown() )
3549 (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam);
3550 }
3551
3552 void wxWindow::OnPaint(wxPaintEvent& event)
3553 {
3554 Default();
3555 }
3556
3557 bool wxWindow::IsEnabled(void) const
3558 {
3559 return (::IsWindowEnabled((HWND) GetHWND()) != 0);
3560 }
3561
3562 // Dialog support: override these and call
3563 // base class members to add functionality
3564 // that can't be done using validators.
3565 // NOTE: these functions assume that controls
3566 // are direct children of this window, not grandchildren
3567 // or other levels of descendant.
3568
3569 // Transfer values to controls. If returns FALSE,
3570 // it's an application error (pops up a dialog)
3571 bool wxWindow::TransferDataToWindow(void)
3572 {
3573 wxNode *node = GetChildren()->First();
3574 while ( node )
3575 {
3576 wxWindow *child = (wxWindow *)node->Data();
3577 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */
3578 !child->GetValidator()->TransferToWindow() )
3579 {
3580 wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION);
3581 return FALSE;
3582 }
3583
3584 node = node->Next();
3585 }
3586 return TRUE;
3587 }
3588
3589 // Transfer values from controls. If returns FALSE,
3590 // validation failed: don't quit
3591 bool wxWindow::TransferDataFromWindow(void)
3592 {
3593 wxNode *node = GetChildren()->First();
3594 while ( node )
3595 {
3596 wxWindow *child = (wxWindow *)node->Data();
3597 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() )
3598 {
3599 return FALSE;
3600 }
3601
3602 node = node->Next();
3603 }
3604 return TRUE;
3605 }
3606
3607 bool wxWindow::Validate(void)
3608 {
3609 wxNode *node = GetChildren()->First();
3610 while ( node )
3611 {
3612 wxWindow *child = (wxWindow *)node->Data();
3613 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
3614 {
3615 return FALSE;
3616 }
3617
3618 node = node->Next();
3619 }
3620 return TRUE;
3621 }
3622
3623 // Get the window with the focus
3624 wxWindow *wxWindow::FindFocus(void)
3625 {
3626 HWND hWnd = ::GetFocus();
3627 if ( hWnd )
3628 {
3629 return wxFindWinFromHandle((WXHWND) hWnd);
3630 }
3631 return NULL;
3632 }
3633
3634 void wxWindow::AddChild(wxWindow *child)
3635 {
3636 GetChildren()->Append(child);
3637 child->m_windowParent = this;
3638 }
3639
3640 void wxWindow::RemoveChild(wxWindow *child)
3641 {
3642 if (GetChildren())
3643 GetChildren()->DeleteObject(child);
3644 child->m_windowParent = NULL;
3645 }
3646
3647 void wxWindow::DestroyChildren(void)
3648 {
3649 if (GetChildren()) {
3650 wxNode *node;
3651 while ((node = GetChildren()->First()) != (wxNode *)NULL) {
3652 wxWindow *child;
3653 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
3654 delete child;
3655 if ( GetChildren()->Member(child) )
3656 delete node;
3657 }
3658 } /* while */
3659 }
3660 }
3661
3662 void wxWindow::MakeModal(bool modal)
3663 {
3664 // Disable all other windows
3665 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
3666 {
3667 wxNode *node = wxTopLevelWindows.First();
3668 while (node)
3669 {
3670 wxWindow *win = (wxWindow *)node->Data();
3671 if (win != this)
3672 win->Enable(!modal);
3673
3674 node = node->Next();
3675 }
3676 }
3677 }
3678
3679 // If nothing defined for this, try the parent.
3680 // E.g. we may be a button loaded from a resource, with no callback function
3681 // defined.
3682 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
3683 {
3684 if (GetEventHandler()->ProcessEvent(event) )
3685 return;
3686 if (m_windowParent)
3687 m_windowParent->GetEventHandler()->OnCommand(win, event);
3688 }
3689
3690 void wxWindow::SetConstraints(wxLayoutConstraints *c)
3691 {
3692 if (m_constraints)
3693 {
3694 UnsetConstraints(m_constraints);
3695 delete m_constraints;
3696 }
3697 m_constraints = c;
3698 if (m_constraints)
3699 {
3700 // Make sure other windows know they're part of a 'meaningful relationship'
3701 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
3702 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3703 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
3704 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3705 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
3706 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3707 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
3708 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3709 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
3710 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3711 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
3712 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3713 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
3714 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3715 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
3716 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3717 }
3718 }
3719
3720 // This removes any dangling pointers to this window
3721 // in other windows' constraintsInvolvedIn lists.
3722 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
3723 {
3724 if (c)
3725 {
3726 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3727 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3728 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3729 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3730 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
3731 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3732 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
3733 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3734 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
3735 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3736 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
3737 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3738 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
3739 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3740 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
3741 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3742 }
3743 }
3744
3745 // Back-pointer to other windows we're involved with, so if we delete
3746 // this window, we must delete any constraints we're involved with.
3747 void wxWindow::AddConstraintReference(wxWindow *otherWin)
3748 {
3749 if (!m_constraintsInvolvedIn)
3750 m_constraintsInvolvedIn = new wxList;
3751 if (!m_constraintsInvolvedIn->Member(otherWin))
3752 m_constraintsInvolvedIn->Append(otherWin);
3753 }
3754
3755 // REMOVE back-pointer to other windows we're involved with.
3756 void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
3757 {
3758 if (m_constraintsInvolvedIn)
3759 m_constraintsInvolvedIn->DeleteObject(otherWin);
3760 }
3761
3762 // Reset any constraints that mention this window
3763 void wxWindow::DeleteRelatedConstraints(void)
3764 {
3765 if (m_constraintsInvolvedIn)
3766 {
3767 wxNode *node = m_constraintsInvolvedIn->First();
3768 while (node)
3769 {
3770 wxWindow *win = (wxWindow *)node->Data();
3771 wxNode *next = node->Next();
3772 wxLayoutConstraints *constr = win->GetConstraints();
3773
3774 // Reset any constraints involving this window
3775 if (constr)
3776 {
3777 constr->left.ResetIfWin((wxWindow *)this);
3778 constr->top.ResetIfWin((wxWindow *)this);
3779 constr->right.ResetIfWin((wxWindow *)this);
3780 constr->bottom.ResetIfWin((wxWindow *)this);
3781 constr->width.ResetIfWin((wxWindow *)this);
3782 constr->height.ResetIfWin((wxWindow *)this);
3783 constr->centreX.ResetIfWin((wxWindow *)this);
3784 constr->centreY.ResetIfWin((wxWindow *)this);
3785 }
3786 delete node;
3787 node = next;
3788 }
3789 delete m_constraintsInvolvedIn;
3790 m_constraintsInvolvedIn = NULL;
3791 }
3792 }
3793
3794 void wxWindow::SetSizer(wxSizer *sizer)
3795 {
3796 m_windowSizer = sizer;
3797 if (sizer)
3798 sizer->SetSizerParent((wxWindow *)this);
3799 }
3800
3801 /*
3802 * New version
3803 */
3804
3805 bool wxWindow::Layout(void)
3806 {
3807 if (GetConstraints())
3808 {
3809 int w, h;
3810 GetClientSize(&w, &h);
3811 GetConstraints()->width.SetValue(w);
3812 GetConstraints()->height.SetValue(h);
3813 }
3814
3815 // If top level (one sizer), evaluate the sizer's constraints.
3816 if (GetSizer())
3817 {
3818 int noChanges;
3819 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3820 GetSizer()->LayoutPhase1(&noChanges);
3821 GetSizer()->LayoutPhase2(&noChanges);
3822 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3823 return TRUE;
3824 }
3825 else
3826 {
3827 // Otherwise, evaluate child constraints
3828 ResetConstraints(); // Mark all constraints as unevaluated
3829 DoPhase(1); // Just one phase need if no sizers involved
3830 DoPhase(2);
3831 SetConstraintSizes(); // Recursively set the real window sizes
3832 }
3833 return TRUE;
3834 }
3835
3836
3837 // Do a phase of evaluating constraints:
3838 // the default behaviour. wxSizers may do a similar
3839 // thing, but also impose their own 'constraints'
3840 // and order the evaluation differently.
3841 bool wxWindow::LayoutPhase1(int *noChanges)
3842 {
3843 wxLayoutConstraints *constr = GetConstraints();
3844 if (constr)
3845 {
3846 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
3847 }
3848 else
3849 return TRUE;
3850 }
3851
3852 bool wxWindow::LayoutPhase2(int *noChanges)
3853 {
3854 *noChanges = 0;
3855
3856 // Layout children
3857 DoPhase(1);
3858 DoPhase(2);
3859 return TRUE;
3860 }
3861
3862 // Do a phase of evaluating child constraints
3863 bool wxWindow::DoPhase(int phase)
3864 {
3865 int noIterations = 0;
3866 int maxIterations = 500;
3867 int noChanges = 1;
3868 int noFailures = 0;
3869 wxList succeeded;
3870 while ((noChanges > 0) && (noIterations < maxIterations))
3871 {
3872 noChanges = 0;
3873 noFailures = 0;
3874 wxNode *node = GetChildren()->First();
3875 while (node)
3876 {
3877 wxWindow *child = (wxWindow *)node->Data();
3878 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
3879 {
3880 wxLayoutConstraints *constr = child->GetConstraints();
3881 if (constr)
3882 {
3883 if (succeeded.Member(child))
3884 {
3885 }
3886 else
3887 {
3888 int tempNoChanges = 0;
3889 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
3890 noChanges += tempNoChanges;
3891 if (success)
3892 {
3893 succeeded.Append(child);
3894 }
3895 }
3896 }
3897 }
3898 node = node->Next();
3899 }
3900 noIterations ++;
3901 }
3902 return TRUE;
3903 }
3904
3905 void wxWindow::ResetConstraints(void)
3906 {
3907 wxLayoutConstraints *constr = GetConstraints();
3908 if (constr)
3909 {
3910 constr->left.SetDone(FALSE);
3911 constr->top.SetDone(FALSE);
3912 constr->right.SetDone(FALSE);
3913 constr->bottom.SetDone(FALSE);
3914 constr->width.SetDone(FALSE);
3915 constr->height.SetDone(FALSE);
3916 constr->centreX.SetDone(FALSE);
3917 constr->centreY.SetDone(FALSE);
3918 }
3919 wxNode *node = GetChildren()->First();
3920 while (node)
3921 {
3922 wxWindow *win = (wxWindow *)node->Data();
3923 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3924 win->ResetConstraints();
3925 node = node->Next();
3926 }
3927 }
3928
3929 // Need to distinguish between setting the 'fake' size for
3930 // windows and sizers, and setting the real values.
3931 void wxWindow::SetConstraintSizes(bool recurse)
3932 {
3933 wxLayoutConstraints *constr = GetConstraints();
3934 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
3935 constr->width.GetDone() && constr->height.GetDone())
3936 {
3937 int x = constr->left.GetValue();
3938 int y = constr->top.GetValue();
3939 int w = constr->width.GetValue();
3940 int h = constr->height.GetValue();
3941
3942 // If we don't want to resize this window, just move it...
3943 if ((constr->width.GetRelationship() != wxAsIs) ||
3944 (constr->height.GetRelationship() != wxAsIs))
3945 {
3946 // Calls Layout() recursively. AAAGH. How can we stop that.
3947 // Simply take Layout() out of non-top level OnSizes.
3948 SizerSetSize(x, y, w, h);
3949 }
3950 else
3951 {
3952 SizerMove(x, y);
3953 }
3954 }
3955 else if (constr)
3956 {
3957 char *windowClass = this->GetClassInfo()->GetClassName();
3958
3959 wxString winName;
3960 if (GetName() == "")
3961 winName = "unnamed";
3962 else
3963 winName = GetName();
3964 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
3965 if (!constr->left.GetDone())
3966 wxDebugMsg(" unsatisfied 'left' constraint.\n");
3967 if (!constr->right.GetDone())
3968 wxDebugMsg(" unsatisfied 'right' constraint.\n");
3969 if (!constr->width.GetDone())
3970 wxDebugMsg(" unsatisfied 'width' constraint.\n");
3971 if (!constr->height.GetDone())
3972 wxDebugMsg(" unsatisfied 'height' constraint.\n");
3973 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
3974 }
3975
3976 if (recurse)
3977 {
3978 wxNode *node = GetChildren()->First();
3979 while (node)
3980 {
3981 wxWindow *win = (wxWindow *)node->Data();
3982 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3983 win->SetConstraintSizes();
3984 node = node->Next();
3985 }
3986 }
3987 }
3988
3989 // This assumes that all sizers are 'on' the same
3990 // window, i.e. the parent of this window.
3991 void wxWindow::TransformSizerToActual(int *x, int *y) const
3992 {
3993 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
3994 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
3995 return;
3996
3997 int xp, yp;
3998 m_sizerParent->GetPosition(&xp, &yp);
3999 m_sizerParent->TransformSizerToActual(&xp, &yp);
4000 *x += xp;
4001 *y += yp;
4002 }
4003
4004 void wxWindow::SizerSetSize(int x, int y, int w, int h)
4005 {
4006 int xx = x;
4007 int yy = y;
4008 TransformSizerToActual(&xx, &yy);
4009 SetSize(xx, yy, w, h);
4010 }
4011
4012 void wxWindow::SizerMove(int x, int y)
4013 {
4014 int xx = x;
4015 int yy = y;
4016 TransformSizerToActual(&xx, &yy);
4017 Move(xx, yy);
4018 }
4019
4020 // Only set the size/position of the constraint (if any)
4021 void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
4022 {
4023 wxLayoutConstraints *constr = GetConstraints();
4024 if (constr)
4025 {
4026 if (x != -1)
4027 {
4028 constr->left.SetValue(x);
4029 constr->left.SetDone(TRUE);
4030 }
4031 if (y != -1)
4032 {
4033 constr->top.SetValue(y);
4034 constr->top.SetDone(TRUE);
4035 }
4036 if (w != -1)
4037 {
4038 constr->width.SetValue(w);
4039 constr->width.SetDone(TRUE);
4040 }
4041 if (h != -1)
4042 {
4043 constr->height.SetValue(h);
4044 constr->height.SetDone(TRUE);
4045 }
4046 }
4047 }
4048
4049 void wxWindow::MoveConstraint(int x, int y)
4050 {
4051 wxLayoutConstraints *constr = GetConstraints();
4052 if (constr)
4053 {
4054 if (x != -1)
4055 {
4056 constr->left.SetValue(x);
4057 constr->left.SetDone(TRUE);
4058 }
4059 if (y != -1)
4060 {
4061 constr->top.SetValue(y);
4062 constr->top.SetDone(TRUE);
4063 }
4064 }
4065 }
4066
4067 void wxWindow::GetSizeConstraint(int *w, int *h) const
4068 {
4069 wxLayoutConstraints *constr = GetConstraints();
4070 if (constr)
4071 {
4072 *w = constr->width.GetValue();
4073 *h = constr->height.GetValue();
4074 }
4075 else
4076 GetSize(w, h);
4077 }
4078
4079 void wxWindow::GetClientSizeConstraint(int *w, int *h) const
4080 {
4081 wxLayoutConstraints *constr = GetConstraints();
4082 if (constr)
4083 {
4084 *w = constr->width.GetValue();
4085 *h = constr->height.GetValue();
4086 }
4087 else
4088 GetClientSize(w, h);
4089 }
4090
4091 void wxWindow::GetPositionConstraint(int *x, int *y) const
4092 {
4093 wxLayoutConstraints *constr = GetConstraints();
4094 if (constr)
4095 {
4096 *x = constr->left.GetValue();
4097 *y = constr->top.GetValue();
4098 }
4099 else
4100 GetPosition(x, y);
4101 }
4102
4103 bool wxWindow::Close(bool force)
4104 {
4105 // Let's generalise it to work the same for any window.
4106 /*
4107 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4108 {
4109 this->Destroy();
4110 return TRUE;
4111 }
4112 */
4113
4114 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
4115 event.SetEventObject(this);
4116 event.SetForce(force);
4117
4118 return GetEventHandler()->ProcessEvent(event);
4119
4120 /*
4121 if ( !force && event.GetVeto() )
4122 return FALSE;
4123
4124 Show(FALSE);
4125
4126 if (!wxPendingDelete.Member(this))
4127 wxPendingDelete.Append(this);
4128
4129 return TRUE;
4130 */
4131 }
4132
4133 wxObject* wxWindow::GetChild(int number) const
4134 {
4135 // Return a pointer to the Nth object in the Panel
4136 if (!GetChildren())
4137 return(NULL) ;
4138 wxNode *node = GetChildren()->First();
4139 int n = number;
4140 while (node && n--)
4141 node = node->Next() ;
4142 if (node)
4143 {
4144 wxObject *obj = (wxObject *)node->Data();
4145 return(obj) ;
4146 }
4147 else
4148 return NULL ;
4149 }
4150
4151 void wxWindow::OnDefaultAction(wxControl *initiatingItem)
4152 {
4153 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4154 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4155 * event.
4156
4157 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4158 {
4159 wxListBox *lbox = (wxListBox *)initiatingItem;
4160 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4161 event.m_commandInt = -1;
4162 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4163 {
4164 event.m_commandString = copystring(lbox->GetStringSelection());
4165 event.m_commandInt = lbox->GetSelection();
4166 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4167 }
4168 event.m_eventObject = lbox;
4169
4170 lbox->ProcessCommand(event);
4171
4172 if (event.m_commandString)
4173 delete[] event.m_commandString;
4174 return;
4175 }
4176
4177 wxButton *but = GetDefaultItem();
4178 if (but)
4179 {
4180 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4181 event.SetEventObject(but);
4182 but->Command(event);
4183 }
4184 */
4185 }
4186
4187 void wxWindow::Clear(void)
4188 {
4189 wxClientDC dc(this);
4190 wxBrush brush(GetBackgroundColour(), wxSOLID);
4191 dc.SetBackground(brush);
4192 dc.Clear();
4193 }
4194
4195 // Fits the panel around the items
4196 void wxWindow::Fit(void)
4197 {
4198 int maxX = 0;
4199 int maxY = 0;
4200 wxNode *node = GetChildren()->First();
4201 while ( node )
4202 {
4203 wxWindow *win = (wxWindow *)node->Data();
4204 int wx, wy, ww, wh;
4205 win->GetPosition(&wx, &wy);
4206 win->GetSize(&ww, &wh);
4207 if ( wx + ww > maxX )
4208 maxX = wx + ww;
4209 if ( wy + wh > maxY )
4210 maxY = wy + wh;
4211
4212 node = node->Next();
4213 }
4214 SetClientSize(maxX + 5, maxY + 5);
4215 }
4216
4217 void wxWindow::SetValidator(const wxValidator& validator)
4218 {
4219 if ( m_windowValidator )
4220 delete m_windowValidator;
4221 m_windowValidator = validator.Clone();
4222
4223 if ( m_windowValidator )
4224 m_windowValidator->SetWindow(this) ;
4225 }
4226
4227 // Find a window by id or name
4228 wxWindow *wxWindow::FindWindow(long id)
4229 {
4230 if ( GetId() == id)
4231 return this;
4232
4233 wxNode *node = GetChildren()->First();
4234 while ( node )
4235 {
4236 wxWindow *child = (wxWindow *)node->Data();
4237 wxWindow *found = child->FindWindow(id);
4238 if ( found )
4239 return found;
4240 node = node->Next();
4241 }
4242 return NULL;
4243 }
4244
4245 wxWindow *wxWindow::FindWindow(const wxString& name)
4246 {
4247 if ( GetName() == name)
4248 return this;
4249
4250 wxNode *node = GetChildren()->First();
4251 while ( node )
4252 {
4253 wxWindow *child = (wxWindow *)node->Data();
4254 wxWindow *found = child->FindWindow(name);
4255 if ( found )
4256 return found;
4257 node = node->Next();
4258 }
4259 return NULL;
4260 }
4261
4262 /* TODO
4263 // Default input behaviour for a scrolling canvas should be to scroll
4264 // according to the cursor keys pressed
4265 void wxWindow::OnChar(wxKeyEvent& event)
4266 {
4267 int x_page = 0;
4268 int y_page = 0;
4269 int start_x = 0;
4270 int start_y = 0;
4271 // Bugfix Begin
4272 int v_width = 0;
4273 int v_height = 0;
4274 int y_pages = 0;
4275 // Bugfix End
4276
4277 GetScrollUnitsPerPage(&x_page, &y_page);
4278 // Bugfix Begin
4279 GetVirtualSize(&v_width,&v_height);
4280 // Bugfix End
4281 ViewStart(&start_x, &start_y);
4282 // Bugfix begin
4283 if (vert_units)
4284 y_pages = (int)(v_height/vert_units) - y_page;
4285
4286 #ifdef __WXMSW__
4287 int y = 0;
4288 #else
4289 int y = y_page-1;
4290 #endif
4291 // Bugfix End
4292 switch (event.keyCode)
4293 {
4294 case WXK_PRIOR:
4295 {
4296 // BugFix Begin
4297 if (y_page > 0)
4298 {
4299 if (start_y - y_page > 0)
4300 Scroll(start_x, start_y - y_page);
4301 else
4302 Scroll(start_x, 0);
4303 }
4304 // Bugfix End
4305 break;
4306 }
4307 case WXK_NEXT:
4308 {
4309 // Bugfix Begin
4310 if ((y_page > 0) && (start_y <= y_pages-y-1))
4311 {
4312 if (y_pages + y < start_y + y_page)
4313 Scroll(start_x, y_pages + y);
4314 else
4315 Scroll(start_x, start_y + y_page);
4316 }
4317 // Bugfix End
4318 break;
4319 }
4320 case WXK_UP:
4321 {
4322 if ((y_page > 0) && (start_y >= 1))
4323 Scroll(start_x, start_y - 1);
4324 break;
4325 }
4326 case WXK_DOWN:
4327 {
4328 // Bugfix Begin
4329 if ((y_page > 0) && (start_y <= y_pages-y-1))
4330 // Bugfix End
4331 {
4332 Scroll(start_x, start_y + 1);
4333 }
4334 break;
4335 }
4336 case WXK_LEFT:
4337 {
4338 if ((x_page > 0) && (start_x >= 1))
4339 Scroll(start_x - 1, start_y);
4340 break;
4341 }
4342 case WXK_RIGHT:
4343 {
4344 if (x_page > 0)
4345 Scroll(start_x + 1, start_y);
4346 break;
4347 }
4348 case WXK_HOME:
4349 {
4350 Scroll(0, 0);
4351 break;
4352 }
4353 // This is new
4354 case WXK_END:
4355 {
4356 Scroll(start_x, y_pages+y);
4357 break;
4358 }
4359 // end
4360 }
4361 }
4362 */
4363
4364 // Setup background and foreground colours correctly
4365 void wxWindow::SetupColours(void)
4366 {
4367 if (GetParent())
4368 SetBackgroundColour(GetParent()->GetBackgroundColour());
4369 }
4370
4371 void wxWindow::OnIdle(wxIdleEvent& event)
4372 {
4373 // Check if we need to send a LEAVE event
4374 if (m_mouseInWindow)
4375 {
4376 POINT pt;
4377 ::GetCursorPos(&pt);
4378 if (::WindowFromPoint(pt) != (HWND) GetHWND())
4379 {
4380 // Generate a LEAVE event
4381 m_mouseInWindow = FALSE;
4382
4383 int state = 0;
4384 if (::GetKeyState(VK_SHIFT) != 0)
4385 state |= MK_SHIFT;
4386 if (::GetKeyState(VK_CONTROL) != 0)
4387 state |= MK_CONTROL;
4388
4389 // Unfortunately the mouse button and keyboard state may have changed
4390 // by the time the OnIdle function is called, so 'state' may be
4391 // meaningless.
4392
4393 MSWOnMouseLeave(pt.x, pt.y, state);
4394 }
4395 }
4396 UpdateWindowUI();
4397 }
4398
4399 // Raise the window to the top of the Z order
4400 void wxWindow::Raise(void)
4401 {
4402 ::BringWindowToTop((HWND) GetHWND());
4403 }
4404
4405 // Lower the window to the bottom of the Z order
4406 void wxWindow::Lower(void)
4407 {
4408 ::SetWindowPos((HWND) GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
4409 }
4410
4411 long wxWindow::MSWGetDlgCode()
4412 {
4413 // default: just forward to def window proc (the msg has no parameters)
4414 return MSWDefWindowProc(WM_GETDLGCODE, 0, 0);
4415 }
4416
4417 bool wxWindow::AcceptsFocus() const
4418 {
4419 return IsShown() && IsEnabled();
4420 }
4421
4422 // Update region access
4423 wxRegion wxWindow::GetUpdateRegion() const
4424 {
4425 return m_updateRegion;
4426 }
4427
4428 bool wxWindow::IsExposed(int x, int y, int w, int h) const
4429 {
4430 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
4431 }
4432
4433 bool wxWindow::IsExposed(const wxPoint& pt) const
4434 {
4435 return (m_updateRegion.Contains(pt) != wxOutRegion);
4436 }
4437
4438 bool wxWindow::IsExposed(const wxRect& rect) const
4439 {
4440 return (m_updateRegion.Contains(rect) != wxOutRegion);
4441 }
4442
4443 #ifdef __WXDEBUG__
4444 const char *wxGetMessageName(int message)
4445 {
4446 switch ( message ) {
4447 case 0x0000: return "WM_NULL";
4448 case 0x0001: return "WM_CREATE";
4449 case 0x0002: return "WM_DESTROY";
4450 case 0x0003: return "WM_MOVE";
4451 case 0x0005: return "WM_SIZE";
4452 case 0x0006: return "WM_ACTIVATE";
4453 case 0x0007: return "WM_SETFOCUS";
4454 case 0x0008: return "WM_KILLFOCUS";
4455 case 0x000A: return "WM_ENABLE";
4456 case 0x000B: return "WM_SETREDRAW";
4457 case 0x000C: return "WM_SETTEXT";
4458 case 0x000D: return "WM_GETTEXT";
4459 case 0x000E: return "WM_GETTEXTLENGTH";
4460 case 0x000F: return "WM_PAINT";
4461 case 0x0010: return "WM_CLOSE";
4462 case 0x0011: return "WM_QUERYENDSESSION";
4463 case 0x0012: return "WM_QUIT";
4464 case 0x0013: return "WM_QUERYOPEN";
4465 case 0x0014: return "WM_ERASEBKGND";
4466 case 0x0015: return "WM_SYSCOLORCHANGE";
4467 case 0x0016: return "WM_ENDSESSION";
4468 case 0x0017: return "WM_SYSTEMERROR";
4469 case 0x0018: return "WM_SHOWWINDOW";
4470 case 0x0019: return "WM_CTLCOLOR";
4471 case 0x001A: return "WM_WININICHANGE";
4472 case 0x001B: return "WM_DEVMODECHANGE";
4473 case 0x001C: return "WM_ACTIVATEAPP";
4474 case 0x001D: return "WM_FONTCHANGE";
4475 case 0x001E: return "WM_TIMECHANGE";
4476 case 0x001F: return "WM_CANCELMODE";
4477 case 0x0020: return "WM_SETCURSOR";
4478 case 0x0021: return "WM_MOUSEACTIVATE";
4479 case 0x0022: return "WM_CHILDACTIVATE";
4480 case 0x0023: return "WM_QUEUESYNC";
4481 case 0x0024: return "WM_GETMINMAXINFO";
4482 case 0x0026: return "WM_PAINTICON";
4483 case 0x0027: return "WM_ICONERASEBKGND";
4484 case 0x0028: return "WM_NEXTDLGCTL";
4485 case 0x002A: return "WM_SPOOLERSTATUS";
4486 case 0x002B: return "WM_DRAWITEM";
4487 case 0x002C: return "WM_MEASUREITEM";
4488 case 0x002D: return "WM_DELETEITEM";
4489 case 0x002E: return "WM_VKEYTOITEM";
4490 case 0x002F: return "WM_CHARTOITEM";
4491 case 0x0030: return "WM_SETFONT";
4492 case 0x0031: return "WM_GETFONT";
4493 case 0x0037: return "WM_QUERYDRAGICON";
4494 case 0x0039: return "WM_COMPAREITEM";
4495 case 0x0041: return "WM_COMPACTING";
4496 case 0x0044: return "WM_COMMNOTIFY";
4497 case 0x0046: return "WM_WINDOWPOSCHANGING";
4498 case 0x0047: return "WM_WINDOWPOSCHANGED";
4499 case 0x0048: return "WM_POWER";
4500
4501 #ifdef __WIN32__
4502 case 0x004A: return "WM_COPYDATA";
4503 case 0x004B: return "WM_CANCELJOURNAL";
4504 case 0x004E: return "WM_NOTIFY";
4505 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
4506 case 0x0051: return "WM_INPUTLANGCHANGE";
4507 case 0x0052: return "WM_TCARD";
4508 case 0x0053: return "WM_HELP";
4509 case 0x0054: return "WM_USERCHANGED";
4510 case 0x0055: return "WM_NOTIFYFORMAT";
4511 case 0x007B: return "WM_CONTEXTMENU";
4512 case 0x007C: return "WM_STYLECHANGING";
4513 case 0x007D: return "WM_STYLECHANGED";
4514 case 0x007E: return "WM_DISPLAYCHANGE";
4515 case 0x007F: return "WM_GETICON";
4516 case 0x0080: return "WM_SETICON";
4517 #endif //WIN32
4518
4519 case 0x0081: return "WM_NCCREATE";
4520 case 0x0082: return "WM_NCDESTROY";
4521 case 0x0083: return "WM_NCCALCSIZE";
4522 case 0x0084: return "WM_NCHITTEST";
4523 case 0x0085: return "WM_NCPAINT";
4524 case 0x0086: return "WM_NCACTIVATE";
4525 case 0x0087: return "WM_GETDLGCODE";
4526 case 0x00A0: return "WM_NCMOUSEMOVE";
4527 case 0x00A1: return "WM_NCLBUTTONDOWN";
4528 case 0x00A2: return "WM_NCLBUTTONUP";
4529 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4530 case 0x00A4: return "WM_NCRBUTTONDOWN";
4531 case 0x00A5: return "WM_NCRBUTTONUP";
4532 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4533 case 0x00A7: return "WM_NCMBUTTONDOWN";
4534 case 0x00A8: return "WM_NCMBUTTONUP";
4535 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4536 case 0x0100: return "WM_KEYDOWN";
4537 case 0x0101: return "WM_KEYUP";
4538 case 0x0102: return "WM_CHAR";
4539 case 0x0103: return "WM_DEADCHAR";
4540 case 0x0104: return "WM_SYSKEYDOWN";
4541 case 0x0105: return "WM_SYSKEYUP";
4542 case 0x0106: return "WM_SYSCHAR";
4543 case 0x0107: return "WM_SYSDEADCHAR";
4544 case 0x0108: return "WM_KEYLAST";
4545
4546 #ifdef __WIN32__
4547 case 0x010D: return "WM_IME_STARTCOMPOSITION";
4548 case 0x010E: return "WM_IME_ENDCOMPOSITION";
4549 case 0x010F: return "WM_IME_COMPOSITION";
4550 #endif //WIN32
4551
4552 case 0x0110: return "WM_INITDIALOG";
4553 case 0x0111: return "WM_COMMAND";
4554 case 0x0112: return "WM_SYSCOMMAND";
4555 case 0x0113: return "WM_TIMER";
4556 case 0x0114: return "WM_HSCROLL";
4557 case 0x0115: return "WM_VSCROLL";
4558 case 0x0116: return "WM_INITMENU";
4559 case 0x0117: return "WM_INITMENUPOPUP";
4560 case 0x011F: return "WM_MENUSELECT";
4561 case 0x0120: return "WM_MENUCHAR";
4562 case 0x0121: return "WM_ENTERIDLE";
4563 case 0x0200: return "WM_MOUSEMOVE";
4564 case 0x0201: return "WM_LBUTTONDOWN";
4565 case 0x0202: return "WM_LBUTTONUP";
4566 case 0x0203: return "WM_LBUTTONDBLCLK";
4567 case 0x0204: return "WM_RBUTTONDOWN";
4568 case 0x0205: return "WM_RBUTTONUP";
4569 case 0x0206: return "WM_RBUTTONDBLCLK";
4570 case 0x0207: return "WM_MBUTTONDOWN";
4571 case 0x0208: return "WM_MBUTTONUP";
4572 case 0x0209: return "WM_MBUTTONDBLCLK";
4573 case 0x0210: return "WM_PARENTNOTIFY";
4574 case 0x0211: return "WM_ENTERMENULOOP";
4575 case 0x0212: return "WM_EXITMENULOOP";
4576
4577 #ifdef __WIN32__
4578 case 0x0213: return "WM_NEXTMENU";
4579 case 0x0214: return "WM_SIZING";
4580 case 0x0215: return "WM_CAPTURECHANGED";
4581 case 0x0216: return "WM_MOVING";
4582 case 0x0218: return "WM_POWERBROADCAST";
4583 case 0x0219: return "WM_DEVICECHANGE";
4584 #endif //WIN32
4585
4586 case 0x0220: return "WM_MDICREATE";
4587 case 0x0221: return "WM_MDIDESTROY";
4588 case 0x0222: return "WM_MDIACTIVATE";
4589 case 0x0223: return "WM_MDIRESTORE";
4590 case 0x0224: return "WM_MDINEXT";
4591 case 0x0225: return "WM_MDIMAXIMIZE";
4592 case 0x0226: return "WM_MDITILE";
4593 case 0x0227: return "WM_MDICASCADE";
4594 case 0x0228: return "WM_MDIICONARRANGE";
4595 case 0x0229: return "WM_MDIGETACTIVE";
4596 case 0x0230: return "WM_MDISETMENU";
4597 case 0x0233: return "WM_DROPFILES";
4598
4599 #ifdef __WIN32__
4600 case 0x0281: return "WM_IME_SETCONTEXT";
4601 case 0x0282: return "WM_IME_NOTIFY";
4602 case 0x0283: return "WM_IME_CONTROL";
4603 case 0x0284: return "WM_IME_COMPOSITIONFULL";
4604 case 0x0285: return "WM_IME_SELECT";
4605 case 0x0286: return "WM_IME_CHAR";
4606 case 0x0290: return "WM_IME_KEYDOWN";
4607 case 0x0291: return "WM_IME_KEYUP";
4608 #endif //WIN32
4609
4610 case 0x0300: return "WM_CUT";
4611 case 0x0301: return "WM_COPY";
4612 case 0x0302: return "WM_PASTE";
4613 case 0x0303: return "WM_CLEAR";
4614 case 0x0304: return "WM_UNDO";
4615 case 0x0305: return "WM_RENDERFORMAT";
4616 case 0x0306: return "WM_RENDERALLFORMATS";
4617 case 0x0307: return "WM_DESTROYCLIPBOARD";
4618 case 0x0308: return "WM_DRAWCLIPBOARD";
4619 case 0x0309: return "WM_PAINTCLIPBOARD";
4620 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4621 case 0x030B: return "WM_SIZECLIPBOARD";
4622 case 0x030C: return "WM_ASKCBFORMATNAME";
4623 case 0x030D: return "WM_CHANGECBCHAIN";
4624 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4625 case 0x030F: return "WM_QUERYNEWPALETTE";
4626 case 0x0310: return "WM_PALETTEISCHANGING";
4627 case 0x0311: return "WM_PALETTECHANGED";
4628
4629 #ifdef __WIN32__
4630 // common controls messages - although they're not strictly speaking
4631 // standard, it's nice to decode them nevertheless
4632
4633 // listview
4634 case 0x1000 + 0: return "LVM_GETBKCOLOR";
4635 case 0x1000 + 1: return "LVM_SETBKCOLOR";
4636 case 0x1000 + 2: return "LVM_GETIMAGELIST";
4637 case 0x1000 + 3: return "LVM_SETIMAGELIST";
4638 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
4639 case 0x1000 + 5: return "LVM_GETITEMA";
4640 case 0x1000 + 75: return "LVM_GETITEMW";
4641 case 0x1000 + 6: return "LVM_SETITEMA";
4642 case 0x1000 + 76: return "LVM_SETITEMW";
4643 case 0x1000 + 7: return "LVM_INSERTITEMA";
4644 case 0x1000 + 77: return "LVM_INSERTITEMW";
4645 case 0x1000 + 8: return "LVM_DELETEITEM";
4646 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
4647 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
4648 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
4649 case 0x1000 + 12: return "LVM_GETNEXTITEM";
4650 case 0x1000 + 13: return "LVM_FINDITEMA";
4651 case 0x1000 + 83: return "LVM_FINDITEMW";
4652 case 0x1000 + 14: return "LVM_GETITEMRECT";
4653 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
4654 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
4655 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
4656 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
4657 case 0x1000 + 18: return "LVM_HITTEST";
4658 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
4659 case 0x1000 + 20: return "LVM_SCROLL";
4660 case 0x1000 + 21: return "LVM_REDRAWITEMS";
4661 case 0x1000 + 22: return "LVM_ARRANGE";
4662 case 0x1000 + 23: return "LVM_EDITLABELA";
4663 case 0x1000 + 118: return "LVM_EDITLABELW";
4664 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
4665 case 0x1000 + 25: return "LVM_GETCOLUMNA";
4666 case 0x1000 + 95: return "LVM_GETCOLUMNW";
4667 case 0x1000 + 26: return "LVM_SETCOLUMNA";
4668 case 0x1000 + 96: return "LVM_SETCOLUMNW";
4669 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
4670 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
4671 case 0x1000 + 28: return "LVM_DELETECOLUMN";
4672 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
4673 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
4674 case 0x1000 + 31: return "LVM_GETHEADER";
4675 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
4676 case 0x1000 + 34: return "LVM_GETVIEWRECT";
4677 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
4678 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
4679 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
4680 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
4681 case 0x1000 + 39: return "LVM_GETTOPINDEX";
4682 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
4683 case 0x1000 + 41: return "LVM_GETORIGIN";
4684 case 0x1000 + 42: return "LVM_UPDATE";
4685 case 0x1000 + 43: return "LVM_SETITEMSTATE";
4686 case 0x1000 + 44: return "LVM_GETITEMSTATE";
4687 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
4688 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
4689 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
4690 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
4691 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
4692 case 0x1000 + 48: return "LVM_SORTITEMS";
4693 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
4694 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
4695 case 0x1000 + 51: return "LVM_GETITEMSPACING";
4696 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
4697 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
4698 case 0x1000 + 53: return "LVM_SETICONSPACING";
4699 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
4700 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
4701 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
4702 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
4703 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
4704 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
4705 case 0x1000 + 60: return "LVM_SETHOTITEM";
4706 case 0x1000 + 61: return "LVM_GETHOTITEM";
4707 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
4708 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
4709 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
4710 case 0x1000 + 65: return "LVM_SETWORKAREA";
4711
4712 // tree view
4713 case 0x1100 + 0: return "TVM_INSERTITEMA";
4714 case 0x1100 + 50: return "TVM_INSERTITEMW";
4715 case 0x1100 + 1: return "TVM_DELETEITEM";
4716 case 0x1100 + 2: return "TVM_EXPAND";
4717 case 0x1100 + 4: return "TVM_GETITEMRECT";
4718 case 0x1100 + 5: return "TVM_GETCOUNT";
4719 case 0x1100 + 6: return "TVM_GETINDENT";
4720 case 0x1100 + 7: return "TVM_SETINDENT";
4721 case 0x1100 + 8: return "TVM_GETIMAGELIST";
4722 case 0x1100 + 9: return "TVM_SETIMAGELIST";
4723 case 0x1100 + 10: return "TVM_GETNEXTITEM";
4724 case 0x1100 + 11: return "TVM_SELECTITEM";
4725 case 0x1100 + 12: return "TVM_GETITEMA";
4726 case 0x1100 + 62: return "TVM_GETITEMW";
4727 case 0x1100 + 13: return "TVM_SETITEMA";
4728 case 0x1100 + 63: return "TVM_SETITEMW";
4729 case 0x1100 + 14: return "TVM_EDITLABELA";
4730 case 0x1100 + 65: return "TVM_EDITLABELW";
4731 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
4732 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
4733 case 0x1100 + 17: return "TVM_HITTEST";
4734 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
4735 case 0x1100 + 19: return "TVM_SORTCHILDREN";
4736 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
4737 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
4738 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
4739 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
4740 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
4741 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
4742 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
4743
4744 // header
4745 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
4746 case 0x1200 + 1: return "HDM_INSERTITEMA";
4747 case 0x1200 + 10: return "HDM_INSERTITEMW";
4748 case 0x1200 + 2: return "HDM_DELETEITEM";
4749 case 0x1200 + 3: return "HDM_GETITEMA";
4750 case 0x1200 + 11: return "HDM_GETITEMW";
4751 case 0x1200 + 4: return "HDM_SETITEMA";
4752 case 0x1200 + 12: return "HDM_SETITEMW";
4753 case 0x1200 + 5: return "HDM_LAYOUT";
4754 case 0x1200 + 6: return "HDM_HITTEST";
4755 case 0x1200 + 7: return "HDM_GETITEMRECT";
4756 case 0x1200 + 8: return "HDM_SETIMAGELIST";
4757 case 0x1200 + 9: return "HDM_GETIMAGELIST";
4758 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
4759 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
4760 case 0x1200 + 17: return "HDM_GETORDERARRAY";
4761 case 0x1200 + 18: return "HDM_SETORDERARRAY";
4762 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
4763
4764 // tab control
4765 case 0x1300 + 2: return "TCM_GETIMAGELIST";
4766 case 0x1300 + 3: return "TCM_SETIMAGELIST";
4767 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
4768 case 0x1300 + 5: return "TCM_GETITEMA";
4769 case 0x1300 + 60: return "TCM_GETITEMW";
4770 case 0x1300 + 6: return "TCM_SETITEMA";
4771 case 0x1300 + 61: return "TCM_SETITEMW";
4772 case 0x1300 + 7: return "TCM_INSERTITEMA";
4773 case 0x1300 + 62: return "TCM_INSERTITEMW";
4774 case 0x1300 + 8: return "TCM_DELETEITEM";
4775 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
4776 case 0x1300 + 10: return "TCM_GETITEMRECT";
4777 case 0x1300 + 11: return "TCM_GETCURSEL";
4778 case 0x1300 + 12: return "TCM_SETCURSEL";
4779 case 0x1300 + 13: return "TCM_HITTEST";
4780 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
4781 case 0x1300 + 40: return "TCM_ADJUSTRECT";
4782 case 0x1300 + 41: return "TCM_SETITEMSIZE";
4783 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
4784 case 0x1300 + 43: return "TCM_SETPADDING";
4785 case 0x1300 + 44: return "TCM_GETROWCOUNT";
4786 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
4787 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
4788 case 0x1300 + 47: return "TCM_GETCURFOCUS";
4789 case 0x1300 + 48: return "TCM_SETCURFOCUS";
4790 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
4791 case 0x1300 + 50: return "TCM_DESELECTALL";
4792
4793 // toolbar
4794 case WM_USER+1: return "TB_ENABLEBUTTON";
4795 case WM_USER+2: return "TB_CHECKBUTTON";
4796 case WM_USER+3: return "TB_PRESSBUTTON";
4797 case WM_USER+4: return "TB_HIDEBUTTON";
4798 case WM_USER+5: return "TB_INDETERMINATE";
4799 case WM_USER+9: return "TB_ISBUTTONENABLED";
4800 case WM_USER+10: return "TB_ISBUTTONCHECKED";
4801 case WM_USER+11: return "TB_ISBUTTONPRESSED";
4802 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
4803 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
4804 case WM_USER+17: return "TB_SETSTATE";
4805 case WM_USER+18: return "TB_GETSTATE";
4806 case WM_USER+19: return "TB_ADDBITMAP";
4807 case WM_USER+20: return "TB_ADDBUTTONS";
4808 case WM_USER+21: return "TB_INSERTBUTTON";
4809 case WM_USER+22: return "TB_DELETEBUTTON";
4810 case WM_USER+23: return "TB_GETBUTTON";
4811 case WM_USER+24: return "TB_BUTTONCOUNT";
4812 case WM_USER+25: return "TB_COMMANDTOINDEX";
4813 case WM_USER+26: return "TB_SAVERESTOREA";
4814 case WM_USER+76: return "TB_SAVERESTOREW";
4815 case WM_USER+27: return "TB_CUSTOMIZE";
4816 case WM_USER+28: return "TB_ADDSTRINGA";
4817 case WM_USER+77: return "TB_ADDSTRINGW";
4818 case WM_USER+29: return "TB_GETITEMRECT";
4819 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
4820 case WM_USER+31: return "TB_SETBUTTONSIZE";
4821 case WM_USER+32: return "TB_SETBITMAPSIZE";
4822 case WM_USER+33: return "TB_AUTOSIZE";
4823 case WM_USER+35: return "TB_GETTOOLTIPS";
4824 case WM_USER+36: return "TB_SETTOOLTIPS";
4825 case WM_USER+37: return "TB_SETPARENT";
4826 case WM_USER+39: return "TB_SETROWS";
4827 case WM_USER+40: return "TB_GETROWS";
4828 case WM_USER+42: return "TB_SETCMDID";
4829 case WM_USER+43: return "TB_CHANGEBITMAP";
4830 case WM_USER+44: return "TB_GETBITMAP";
4831 case WM_USER+45: return "TB_GETBUTTONTEXTA";
4832 case WM_USER+75: return "TB_GETBUTTONTEXTW";
4833 case WM_USER+46: return "TB_REPLACEBITMAP";
4834 case WM_USER+47: return "TB_SETINDENT";
4835 case WM_USER+48: return "TB_SETIMAGELIST";
4836 case WM_USER+49: return "TB_GETIMAGELIST";
4837 case WM_USER+50: return "TB_LOADIMAGES";
4838 case WM_USER+51: return "TB_GETRECT";
4839 case WM_USER+52: return "TB_SETHOTIMAGELIST";
4840 case WM_USER+53: return "TB_GETHOTIMAGELIST";
4841 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
4842 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
4843 case WM_USER+56: return "TB_SETSTYLE";
4844 case WM_USER+57: return "TB_GETSTYLE";
4845 case WM_USER+58: return "TB_GETBUTTONSIZE";
4846 case WM_USER+59: return "TB_SETBUTTONWIDTH";
4847 case WM_USER+60: return "TB_SETMAXTEXTROWS";
4848 case WM_USER+61: return "TB_GETTEXTROWS";
4849 case WM_USER+41: return "TB_GETBITMAPFLAGS";
4850
4851 #endif //WIN32
4852
4853 default:
4854 static char s_szBuf[128];
4855 sprintf(s_szBuf, "<unknown message = %d>", message);
4856 return s_szBuf;
4857 }
4858 }
4859 #endif //WXDEBUG