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