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