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