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