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