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