1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/dcclient.h"
32 #include "wx/layout.h"
33 #include "wx/dialog.h"
34 #include "wx/listbox.h"
35 #include "wx/button.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
41 #include "wx/ownerdrw.h"
45 #include "wx/msw/ole/droptgt.h"
48 #include "wx/menuitem.h"
50 #include "wx/msw/private.h"
64 #include <wx/msw/gnuwin32/extra.h>
84 const char *wxGetMessageName(int message
);
87 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
89 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 extern wxList wxPendingDelete
;
92 void wxRemoveHandleAssociation(wxWindow
*win
);
93 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
94 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
99 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
100 EVT_CHAR(wxWindow::OnChar
)
101 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
102 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
104 EVT_IDLE(wxWindow::OnIdle
)
109 // Find an item given the MS Windows id
110 wxWindow
*wxWindow::FindItem(int id
) const
114 wxNode
*current
= GetChildren()->First();
117 wxWindow
*childWin
= (wxWindow
*)current
->Data();
119 wxWindow
*wnd
= childWin
->FindItem(id
) ;
123 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
125 wxControl
*item
= (wxControl
*)childWin
;
126 if (item
->m_windowId
== id
)
130 // In case it's a 'virtual' control (e.g. radiobox)
131 if (item
->GetSubcontrols().Member((wxObject
*)id
))
135 current
= current
->Next();
140 // Find an item given the MS Windows handle
141 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
145 wxNode
*current
= GetChildren()->First();
148 wxObject
*obj
= (wxObject
*)current
->Data() ;
149 // Do a recursive search.
150 wxWindow
*parent
= (wxWindow
*)obj
;
151 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
155 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
157 wxWindow
*item
= (wxWindow
*)current
->Data();
158 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
162 if ( item
->ContainsHWND(hWnd
) )
166 current
= current
->Next();
171 // Default command handler
172 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
177 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
182 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
186 WXHWND
wxWindow::GetHWND(void) const
188 return (WXHWND
) m_hWnd
;
191 void wxWindow::SetHWND(WXHWND hWnd
)
197 wxWindow::wxWindow(void)
203 m_windowParent
= NULL
;
204 m_windowEventHandler
= this;
206 m_windowCursor
= *wxSTANDARD_CURSOR
;
207 m_children
= new wxList
;
208 m_doubleClickAllowed
= 0 ;
209 m_winCaptured
= FALSE
;
210 m_constraints
= NULL
;
211 m_constraintsInvolvedIn
= NULL
;
212 m_windowSizer
= NULL
;
213 m_sizerParent
= NULL
;
214 m_autoLayout
= FALSE
;
215 m_windowValidator
= NULL
;
220 m_caretWidth
= 0; m_caretHeight
= 0;
221 m_caretEnabled
= FALSE
;
222 m_caretShown
= FALSE
;
230 m_isBeingDeleted
= FALSE
;
237 m_defaultItem
= NULL
;
239 wxSystemSettings settings
;
241 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
242 m_foregroundColour
= *wxBLACK
;
243 m_defaultForegroundColour
= *wxBLACK
;
244 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
247 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
248 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
255 // m_acceleratorTable = 0;
260 m_backgroundTransparent
= FALSE
;
262 m_lastXPos
= (float)-1.0;
263 m_lastYPos
= (float)-1.0;
267 #if USE_DRAG_AND_DROP
268 m_pDropTarget
= NULL
;
273 wxWindow::~wxWindow(void)
275 m_isBeingDeleted
= TRUE
;
277 // JACS - if behaviour is odd, restore this
278 // to the start of ~wxWindow. Vadim has changed
279 // it to nearer the end. Unsure of side-effects
280 // e.g. when deleting associated global data.
281 // Restore old Window proc, if required
284 // Have to delete constraints/sizer FIRST otherwise
285 // sizers may try to look at deleted windows as they
286 // delete themselves.
288 DeleteRelatedConstraints();
291 // This removes any dangling pointers to this window
292 // in other windows' constraintsInvolvedIn lists.
293 UnsetConstraints(m_constraints
);
294 delete m_constraints
;
295 m_constraints
= NULL
;
299 delete m_windowSizer
;
300 m_windowSizer
= NULL
;
302 // If this is a child of a sizer, remove self from parent
304 m_sizerParent
->RemoveChild((wxWindow
*)this);
308 MSWDetachWindowMenu();
311 m_windowParent
->RemoveChild(this);
316 ::DestroyWindow((HWND
)m_hWnd
);
318 wxRemoveHandleAssociation(this);
323 GlobalFree((HGLOBAL
) m_globalHandle
);
331 // Just in case the window has been Closed, but
332 // we're then deleting immediately: don't leave
333 // dangling pointers.
334 wxPendingDelete
.DeleteObject(this);
336 // Just in case we've loaded a top-level window via
337 // wxWindow::LoadNativeDialog but we weren't a dialog
339 wxTopLevelWindows
.DeleteObject(this);
341 if ( m_windowValidator
)
342 delete m_windowValidator
;
344 // Restore old Window proc, if required
345 // and remove hWnd <-> wxWindow association
349 // Destroy the window (delayed, if a managed window)
350 bool wxWindow::Destroy(void)
356 extern char wxCanvasClassName
[];
359 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
363 const wxString
& name
)
366 m_isBeingDeleted
= FALSE
;
370 m_windowParent
= NULL
;
371 m_windowEventHandler
= this;
373 m_windowCursor
= *wxSTANDARD_CURSOR
;
374 m_doubleClickAllowed
= 0 ;
375 m_winCaptured
= FALSE
;
376 m_constraints
= NULL
;
377 m_constraintsInvolvedIn
= NULL
;
378 m_windowSizer
= NULL
;
379 m_sizerParent
= NULL
;
380 m_autoLayout
= FALSE
;
381 m_windowValidator
= NULL
;
382 #if USE_DRAG_AND_DROP
383 m_pDropTarget
= NULL
;
389 m_caretWidth
= 0; m_caretHeight
= 0;
390 m_caretEnabled
= FALSE
;
391 m_caretShown
= FALSE
;
402 m_defaultItem
= NULL
;
403 m_windowParent
= NULL
;
404 m_mouseInWindow
= FALSE
;
408 if (parent
) parent
->AddChild(this);
418 m_backgroundTransparent
= FALSE
;
420 m_lastXPos
= (float)-1.0;
421 m_lastYPos
= (float)-1.0;
428 m_windowId
= (int)NewControlId();
437 wxSystemSettings settings
;
439 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
440 m_foregroundColour
= *wxBLACK
;
441 m_defaultForegroundColour
= *wxBLACK
;
442 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
444 m_windowStyle
= style
;
447 if (style
& wxBORDER
)
448 msflags
|= WS_BORDER
;
449 if (style
& wxTHICK_FRAME
)
450 msflags
|= WS_THICKFRAME
;
452 msflags
|= WS_CHILD
| WS_VISIBLE
;
453 if (style
& wxCLIP_CHILDREN
)
454 msflags
|= WS_CLIPCHILDREN
;
457 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
459 // Even with extended styles, need to combine with WS_BORDER
460 // for them to look right.
461 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
462 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
463 msflags
|= WS_BORDER
;
465 m_mouseInWindow
= FALSE
;
468 m_windowId
= (int)NewControlId();
472 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
478 void wxWindow::SetFocus(void)
480 HWND hWnd
= (HWND
) GetHWND();
485 void wxWindow::Enable(bool enable
)
487 m_winEnabled
= enable
;
488 HWND hWnd
= (HWND
) GetHWND();
490 ::EnableWindow(hWnd
, (BOOL
)enable
);
493 void wxWindow::CaptureMouse(void)
495 HWND hWnd
= (HWND
) GetHWND();
496 if (hWnd
&& !m_winCaptured
)
499 m_winCaptured
= TRUE
;
503 void wxWindow::ReleaseMouse(void)
508 m_winCaptured
= FALSE
;
512 // Push/pop event handler (i.e. allow a chain of event handlers
514 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
516 handler
->SetNextHandler(GetEventHandler());
517 SetEventHandler(handler
);
520 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
522 if ( GetEventHandler() )
524 wxEvtHandler
*handlerA
= GetEventHandler();
525 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
526 handlerA
->SetNextHandler(NULL
);
527 SetEventHandler(handlerB
);
540 #if USE_DRAG_AND_DROP
542 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
544 if ( m_pDropTarget
!= 0 ) {
545 m_pDropTarget
->Revoke(m_hWnd
);
546 delete m_pDropTarget
;
549 m_pDropTarget
= pDropTarget
;
550 if ( m_pDropTarget
!= 0 )
551 m_pDropTarget
->Register(m_hWnd
);
556 //old style file-manager drag&drop support
557 // I think we should retain the old-style
558 // DragAcceptFiles in parallel with SetDropTarget.
560 void wxWindow::DragAcceptFiles(bool accept
)
562 HWND hWnd
= (HWND
) GetHWND();
564 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
568 void wxWindow::GetSize(int *x
, int *y
) const
570 HWND hWnd
= (HWND
) GetHWND();
572 GetWindowRect(hWnd
, &rect
);
573 *x
= rect
.right
- rect
.left
;
574 *y
= rect
.bottom
- rect
.top
;
577 void wxWindow::GetPosition(int *x
, int *y
) const
579 HWND hWnd
= (HWND
) GetHWND();
582 hParentWnd
= (HWND
) GetParent()->GetHWND();
585 GetWindowRect(hWnd
, &rect
);
587 // Since we now have the absolute screen coords,
588 // if there's a parent we must subtract its top left corner
594 ::ScreenToClient(hParentWnd
, &point
);
597 // We may be faking the client origin.
598 // So a window that's really at (0, 30) may appear
599 // (to wxWin apps) to be at (0, 0).
602 wxPoint
pt(GetParent()->GetClientAreaOrigin());
610 void wxWindow::ScreenToClient(int *x
, int *y
) const
612 HWND hWnd
= (HWND
) GetHWND();
616 ::ScreenToClient(hWnd
, &pt
);
619 // We may be faking the client origin.
620 // So a window that's really at (0, 30) may appear
621 // (to wxWin apps) to be at (0, 0).
624 wxPoint pt1(GetParent()->GetClientAreaOrigin());
634 void wxWindow::ClientToScreen(int *x
, int *y
) const
636 HWND hWnd
= (HWND
) GetHWND();
642 // We may be faking the client origin.
643 // So a window that's really at (0, 30) may appear
644 // (to wxWin apps) to be at (0, 0).
647 wxPoint pt1(GetParent()->GetClientAreaOrigin());
653 ::ClientToScreen(hWnd
, &pt
);
659 void wxWindow::SetCursor(const wxCursor
& cursor
)
661 m_windowCursor
= cursor
;
662 if (m_windowCursor
.Ok())
664 HWND hWnd
= (HWND
) GetHWND();
666 // Change the cursor NOW if we're within the correct window
668 ::GetCursorPos(&point
);
671 ::GetWindowRect(hWnd
, &rect
);
673 if (::PtInRect(&rect
, point
) && !wxIsBusy())
674 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
677 // This will cause big reentrancy problems if wxFlushEvents is implemented.
679 // return old_cursor;
683 // Get size *available for subwindows* i.e. excluding menu bar etc.
684 void wxWindow::GetClientSize(int *x
, int *y
) const
686 HWND hWnd
= (HWND
) GetHWND();
688 GetClientRect(hWnd
, &rect
);
693 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
695 int currentX
, currentY
;
696 GetPosition(¤tX
, ¤tY
);
697 int actualWidth
= width
;
698 int actualHeight
= height
;
701 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
703 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
706 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
708 int currentW
,currentH
;
709 GetSize(¤tW
, ¤tH
);
711 actualWidth
= currentW
;
713 actualHeight
= currentH
;
715 HWND hWnd
= (HWND
) GetHWND();
717 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
720 void wxWindow::SetClientSize(int width
, int height
)
722 wxWindow
*parent
= GetParent();
723 HWND hWnd
= (HWND
) GetHWND();
724 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
727 GetClientRect(hWnd
, &rect
);
730 GetWindowRect(hWnd
, &rect2
);
732 // Find the difference between the entire window (title bar and all)
733 // and the client area; add this to the new client size to move the
735 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
736 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
738 // If there's a parent, must subtract the parent's top left corner
739 // since MoveWindow moves relative to the parent
742 point
.x
= rect2
.left
;
746 ::ScreenToClient(hParentWnd
, &point
);
749 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
751 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
752 event
.SetEventObject(this);
753 GetEventHandler()->ProcessEvent(event
);
756 // For implementation purposes - sometimes decorations make the client area
758 wxPoint
wxWindow::GetClientAreaOrigin() const
760 return wxPoint(0, 0);
763 // Makes an adjustment to the window position (for example, a frame that has
764 // a toolbar that it manages itself).
765 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
767 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
769 wxPoint
pt(GetParent()->GetClientAreaOrigin());
770 x
+= pt
.x
; y
+= pt
.y
;
774 bool wxWindow::Show(bool show
)
776 HWND hWnd
= (HWND
) GetHWND();
782 ShowWindow(hWnd
, (BOOL
)cshow
);
785 BringWindowToTop(hWnd
);
786 // Next line causes a crash on NT, apparently.
787 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
792 bool wxWindow::IsShown(void) const
794 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
797 int wxWindow::GetCharHeight(void) const
799 TEXTMETRIC lpTextMetric
;
800 HWND hWnd
= (HWND
) GetHWND();
801 HDC dc
= ::GetDC(hWnd
);
803 GetTextMetrics(dc
, &lpTextMetric
);
804 ::ReleaseDC(hWnd
, dc
);
806 return lpTextMetric
.tmHeight
;
809 int wxWindow::GetCharWidth(void) const
811 TEXTMETRIC lpTextMetric
;
812 HWND hWnd
= (HWND
) GetHWND();
813 HDC dc
= ::GetDC(hWnd
);
815 GetTextMetrics(dc
, &lpTextMetric
);
816 ::ReleaseDC(hWnd
, dc
);
818 return lpTextMetric
.tmAveCharWidth
;
821 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
822 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
824 wxFont
*fontToUse
= (wxFont
*)theFont
;
826 fontToUse
= (wxFont
*) & m_windowFont
;
828 HWND hWnd
= (HWND
) GetHWND();
829 HDC dc
= ::GetDC(hWnd
);
833 if (fontToUse
&& fontToUse
->Ok())
835 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
836 was
= (HFONT
) SelectObject(dc
,fnt
) ;
841 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
842 GetTextMetrics(dc
, &tm
);
844 if (fontToUse
&& fnt
&& was
)
845 SelectObject(dc
,was
) ;
851 if (descent
) *descent
= tm
.tmDescent
;
852 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
855 // fontToUse->ReleaseResource();
858 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
860 HWND hWnd
= (HWND
) GetHWND();
866 mswRect
.left
= rect
->x
;
867 mswRect
.top
= rect
->y
;
868 mswRect
.right
= rect
->x
+ rect
->width
;
869 mswRect
.bottom
= rect
->y
+ rect
->height
;
871 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
874 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
878 // Hook for new window just as it's being created,
879 // when the window isn't yet associated with the handle
880 wxWindow
*wxWndHook
= NULL
;
883 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
885 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
887 if (!wnd
&& wxWndHook
)
889 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
892 wnd
->m_hWnd
= (WXHWND
) hWnd
;
895 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
897 // Stop right here if we don't have a valid handle
898 // in our wxWnd object.
899 if (wnd
&& !wnd
->m_hWnd
) {
900 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
901 wnd
->m_hWnd
= (WXHWND
) hWnd
;
902 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
908 wnd
->m_lastMsg
= message
;
909 wnd
->m_lastWParam
= wParam
;
910 wnd
->m_lastLParam
= lParam
;
913 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
915 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
918 // Should probably have a test for 'genuine' NT
919 #if defined(__WIN32__)
920 #define DIMENSION_TYPE short
922 #define DIMENSION_TYPE int
925 // Main Windows 3 window proc
926 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
937 case WM_QUERYDRAGICON
:
941 case WM_RBUTTONDBLCLK
:
944 case WM_MBUTTONDBLCLK
:
947 case WM_LBUTTONDBLCLK
:
953 case WM_INITMENUPOPUP
:
958 case WM_CHAR
: // Always an ASCII character
963 case WM_CTLCOLORLISTBOX
:
964 case WM_CTLCOLORMSGBOX
:
965 case WM_CTLCOLORSCROLLBAR
:
966 case WM_CTLCOLORSTATIC
:
967 case WM_CTLCOLOREDIT
:
968 case WM_SYSCOLORCHANGE
:
972 case WM_QUERYENDSESSION
:
974 case WM_GETMINMAXINFO
:
976 return MSWDefWindowProc(message
, wParam
, lParam
);
982 wxLogTrace(wxTraceMessages
, "Processing %s", wxGetMessageName(message
));
985 HWND hWnd
= (HWND
)m_hWnd
;
992 WORD state
= LOWORD(wParam
);
993 WORD minimized
= HIWORD(wParam
);
994 HWND hwnd
= (HWND
)lParam
;
996 WORD state
= (WORD
)wParam
;
997 WORD minimized
= LOWORD(lParam
);
998 HWND hwnd
= (HWND
)HIWORD(lParam
);
1000 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
1006 HWND hwnd
= (HWND
)wParam
;
1007 // return OnSetFocus(hwnd);
1009 if (MSWOnSetFocus((WXHWND
) hwnd
))
1011 else return MSWDefWindowProc(message
, wParam
, lParam
);
1016 HWND hwnd
= (HWND
)lParam
;
1017 // return OnKillFocus(hwnd);
1018 if (MSWOnKillFocus((WXHWND
) hwnd
))
1021 return MSWDefWindowProc(message
, wParam
, lParam
);
1026 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
1032 MSWOnShow((wParam
!= 0), (int) lParam
);
1039 else return MSWDefWindowProc(message
, wParam
, lParam
);
1042 case WM_QUERYDRAGICON
:
1045 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1047 else return MSWDefWindowProc(message
, wParam
, lParam
);
1053 int width
= LOWORD(lParam
);
1054 int height
= HIWORD(lParam
);
1055 MSWOnSize(width
, height
, wParam
);
1059 case WM_WINDOWPOSCHANGING
:
1061 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1062 MSWOnWindowPosChanging((void *)pos
);
1066 case WM_RBUTTONDOWN
:
1068 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1069 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1070 MSWOnRButtonDown(x
, y
, wParam
);
1075 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1076 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1077 MSWOnRButtonUp(x
, y
, wParam
);
1080 case WM_RBUTTONDBLCLK
:
1082 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1083 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1084 MSWOnRButtonDClick(x
, y
, wParam
);
1087 case WM_MBUTTONDOWN
:
1089 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1090 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1091 MSWOnMButtonDown(x
, y
, wParam
);
1096 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1097 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1098 MSWOnMButtonUp(x
, y
, wParam
);
1101 case WM_MBUTTONDBLCLK
:
1103 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1104 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1105 MSWOnMButtonDClick(x
, y
, wParam
);
1108 case WM_LBUTTONDOWN
:
1110 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1111 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1112 MSWOnLButtonDown(x
, y
, wParam
);
1117 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1118 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1119 MSWOnLButtonUp(x
, y
, wParam
);
1122 case WM_LBUTTONDBLCLK
:
1124 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1125 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1126 MSWOnLButtonDClick(x
, y
, wParam
);
1131 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1132 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1133 MSWOnMouseMove(x
, y
, wParam
);
1136 case MM_JOY1BUTTONDOWN
:
1138 int x
= LOWORD(lParam
);
1139 int y
= HIWORD(lParam
);
1140 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1143 case MM_JOY2BUTTONDOWN
:
1145 int x
= LOWORD(lParam
);
1146 int y
= HIWORD(lParam
);
1147 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1150 case MM_JOY1BUTTONUP
:
1152 int x
= LOWORD(lParam
);
1153 int y
= HIWORD(lParam
);
1154 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1157 case MM_JOY2BUTTONUP
:
1159 int x
= LOWORD(lParam
);
1160 int y
= HIWORD(lParam
);
1161 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1166 int x
= LOWORD(lParam
);
1167 int y
= HIWORD(lParam
);
1168 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1173 int x
= LOWORD(lParam
);
1174 int y
= HIWORD(lParam
);
1175 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1180 int z
= LOWORD(lParam
);
1181 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1186 int z
= LOWORD(lParam
);
1187 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1194 else return MSWDefWindowProc(message
, wParam
, lParam
);
1199 return MSWOnSysCommand(wParam
, lParam
);
1205 WORD id
= LOWORD(wParam
);
1206 HWND hwnd
= (HWND
)lParam
;
1207 WORD cmd
= HIWORD(wParam
);
1209 WORD id
= (WORD
)wParam
;
1210 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1211 WORD cmd
= HIWORD(lParam
);
1213 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1214 return MSWDefWindowProc(message
, wParam
, lParam
);
1217 #if defined(__WIN95__)
1220 if (!MSWOnNotify(wParam
, lParam
))
1221 return MSWDefWindowProc(message
, wParam
, lParam
);
1228 WORD flags
= HIWORD(wParam
);
1229 HMENU sysmenu
= (HMENU
)lParam
;
1231 WORD flags
= LOWORD(lParam
);
1232 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1234 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1237 case WM_INITMENUPOPUP
:
1239 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1244 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1247 case WM_MEASUREITEM
:
1249 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1254 // we consider these message "not interesting"
1255 if ( wParam
== VK_SHIFT
|| wParam
== VK_CONTROL
)
1258 // Avoid duplicate messages to OnChar
1259 if ( (wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) &&
1260 (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) &&
1261 (wParam
!= VK_TAB
) )
1263 MSWOnChar((WORD
)wParam
, lParam
);
1264 if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1267 else if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1268 MSWOnChar((WORD
)wParam
, lParam
);
1276 case WM_CHAR
: // Always an ASCII character
1278 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1285 WORD code
= LOWORD(wParam
);
1286 WORD pos
= HIWORD(wParam
);
1287 HWND control
= (HWND
)lParam
;
1289 WORD code
= (WORD
)wParam
;
1290 WORD pos
= LOWORD(lParam
);
1291 HWND control
= (HWND
)HIWORD(lParam
);
1293 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1299 WORD code
= LOWORD(wParam
);
1300 WORD pos
= HIWORD(wParam
);
1301 HWND control
= (HWND
)lParam
;
1303 WORD code
= (WORD
)wParam
;
1304 WORD pos
= LOWORD(lParam
);
1305 HWND control
= (HWND
)HIWORD(lParam
);
1307 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1311 case WM_CTLCOLORBTN
:
1313 int nCtlColor
= CTLCOLOR_BTN
;
1314 HWND control
= (HWND
)lParam
;
1315 HDC pDC
= (HDC
)wParam
;
1316 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1317 message
, wParam
, lParam
);
1320 case WM_CTLCOLORDLG
:
1322 int nCtlColor
= CTLCOLOR_DLG
;
1323 HWND control
= (HWND
)lParam
;
1324 HDC pDC
= (HDC
)wParam
;
1325 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1326 message
, wParam
, lParam
);\
1329 case WM_CTLCOLORLISTBOX
:
1331 int nCtlColor
= CTLCOLOR_LISTBOX
;
1332 HWND control
= (HWND
)lParam
;
1333 HDC pDC
= (HDC
)wParam
;
1334 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1335 message
, wParam
, lParam
);
1338 case WM_CTLCOLORMSGBOX
:
1340 int nCtlColor
= CTLCOLOR_MSGBOX
;
1341 HWND control
= (HWND
)lParam
;
1342 HDC pDC
= (HDC
)wParam
;
1343 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1344 message
, wParam
, lParam
);
1347 case WM_CTLCOLORSCROLLBAR
:
1349 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1350 HWND control
= (HWND
)lParam
;
1351 HDC pDC
= (HDC
)wParam
;
1352 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1353 message
, wParam
, lParam
);
1356 case WM_CTLCOLORSTATIC
:
1358 int nCtlColor
= CTLCOLOR_STATIC
;
1359 HWND control
= (HWND
)lParam
;
1360 HDC pDC
= (HDC
)wParam
;
1361 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1362 message
, wParam
, lParam
);
1365 case WM_CTLCOLOREDIT
:
1367 int nCtlColor
= CTLCOLOR_EDIT
;
1368 HWND control
= (HWND
)lParam
;
1369 HDC pDC
= (HDC
)wParam
;
1370 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1371 message
, wParam
, lParam
);
1377 HWND control
= (HWND
)LOWORD(lParam
);
1378 int nCtlColor
= (int)HIWORD(lParam
);
1379 HDC pDC
= (HDC
)wParam
;
1380 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1381 message
, wParam
, lParam
);
1385 case WM_SYSCOLORCHANGE
:
1387 // Return value of 0 means, we processed it.
1388 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1391 return MSWDefWindowProc(message
, wParam
, lParam
);
1394 case WM_PALETTECHANGED
:
1396 return MSWOnPaletteChanged((WXHWND
) (HWND
) wParam
);
1399 case WM_QUERYNEWPALETTE
:
1401 return MSWOnQueryNewPalette();
1406 // Prevents flicker when dragging
1407 if (IsIconic(hWnd
)) return 1;
1409 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1410 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1414 case WM_MDIACTIVATE
:
1417 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1418 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1419 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1420 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1422 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1423 (HWND
)HIWORD(lParam
));
1428 MSWOnDropFiles(wParam
);
1433 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1436 case WM_QUERYENDSESSION
:
1438 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1439 return MSWOnClose();
1451 case WM_GETMINMAXINFO
:
1453 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1454 if (m_minSizeX
!= -1)
1455 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1456 if (m_minSizeY
!= -1)
1457 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1458 if (m_maxSizeX
!= -1)
1459 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1460 if (m_maxSizeY
!= -1)
1461 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1462 return MSWDefWindowProc(message
, wParam
, lParam
);
1467 return MSWGetDlgCode();
1470 return MSWDefWindowProc(message
, wParam
, lParam
);
1472 return 0; // Success: we processed this command.
1475 // Dialog window proc
1476 LONG APIENTRY _EXPORT
1477 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1482 wxList
*wxWinHandleList
= NULL
;
1483 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1485 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1488 return (wxWindow
*)node
->Data();
1491 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1493 // adding NULL hWnd is (first) surely a result of an error and
1494 // (secondly) breaks menu command processing
1495 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1497 if ( !wxWinHandleList
->Find((long)hWnd
) )
1498 wxWinHandleList
->Append((long)hWnd
, win
);
1501 void wxRemoveHandleAssociation(wxWindow
*win
)
1503 wxWinHandleList
->DeleteObject(win
);
1506 // Default destroyer - override if you destroy it in some other way
1507 // (e.g. with MDI child windows)
1508 void wxWindow::MSWDestroyWindow(void)
1512 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1513 int x
, int y
, int width
, int height
,
1514 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1516 bool is_dialog
= (dialog_template
!= NULL
);
1517 int x1
= CW_USEDEFAULT
;
1519 int width1
= CW_USEDEFAULT
;
1522 // Find parent's size, if it exists, to set up a possible default
1523 // panel size the size of the parent window
1527 // Was GetWindowRect: JACS 5/5/95
1528 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1530 width1
= parent_rect
.right
- parent_rect
.left
;
1531 height1
= parent_rect
.bottom
- parent_rect
.top
;
1536 if (width
> -1) width1
= width
;
1537 if (height
> -1) height1
= height
;
1539 HWND hParent
= NULL
;
1541 hParent
= (HWND
) parent
->GetHWND();
1547 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1548 // other compilers???
1549 // VZ: it's always needed for Win16 and never for Win32
1551 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1552 (DLGPROC
)wxDlgProc
);
1554 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1556 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1561 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1562 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1563 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1568 if (style
& WS_CHILD
)
1573 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1578 hParent
, (HMENU
)controlId
, wxGetInstance(),
1584 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1587 "Fatal wxWindows Error");
1591 wxWinHandleList
->Append((long)m_hWnd
, this);
1594 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1598 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1602 bool wxWindow::MSWOnClose(void)
1605 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1610 bool wxWindow::MSWOnDestroy(void)
1613 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1615 // delete our drop target if we've got one
1616 #if USE_DRAG_AND_DROP
1617 if ( m_pDropTarget
!= NULL
) {
1618 m_pDropTarget
->Revoke(m_hWnd
);
1620 delete m_pDropTarget
;
1621 m_pDropTarget
= NULL
;
1628 // Deal with child commands from buttons etc.
1630 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1632 #if defined(__WIN95__)
1633 // Find a child window to send the notification to, e.g. a toolbar.
1634 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1635 // handle of the toolbar; it's probably the handle of the tooltip
1636 // window (anyway, it's parent is also the toolbar's parent).
1637 // So, since we don't know which hWnd or wxWindow originated the
1638 // WM_NOTIFY, we'll need to go through all the children of this window
1639 // trying out MSWNotify.
1640 // This won't work now, though, because any number of controls
1641 // could respond to the same generic messages :-(
1643 /* This doesn't work for toolbars, but try for other controls first.
1645 NMHDR
*hdr
= (NMHDR
*)lParam
;
1646 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1647 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1650 return win
->MSWNotify(wParam
, lParam
);
1653 // Rely on MSWNotify to check whether the message
1654 // belongs to the window or not
1655 wxNode
*node
= GetChildren()->First();
1658 wxWindow
*child
= (wxWindow
*)node
->Data();
1659 if ( child
->MSWNotify(wParam
, lParam
) )
1661 node
= node
->Next();
1671 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1674 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1678 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1682 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1685 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1688 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1690 event
.SetEventObject(this);
1691 GetEventHandler()->ProcessEvent(event
);
1695 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1698 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1701 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1703 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1705 ::ShowCaret((HWND
) GetHWND());
1708 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1709 event
.SetEventObject(this);
1710 if (!GetEventHandler()->ProcessEvent(event
))
1715 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1718 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1726 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1727 event
.SetEventObject(this);
1728 if (!GetEventHandler()->ProcessEvent(event
))
1733 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1736 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1739 HDROP hFilesInfo
= (HDROP
) wParam
;
1741 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1743 // Get the total number of files dropped
1744 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1749 wxString
*files
= new wxString
[gwFilesDropped
];
1751 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1753 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1754 files
[wIndex
] = wxBuffer
;
1756 DragFinish (hFilesInfo
);
1758 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1759 event
.m_eventObject
= this;
1760 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1762 if (!GetEventHandler()->ProcessEvent(event
))
1768 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1771 if ( id
== 0 ) { // is it a menu item?
1772 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1773 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1774 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1776 // prepare to call OnDrawItem()
1778 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1779 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1780 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1781 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1782 return pMenuItem
->OnDrawItem(
1784 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1785 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1788 #endif // owner-drawn menus
1790 wxWindow
*item
= FindItem(id
);
1791 #if USE_DYNAMIC_CLASSES
1792 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1794 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1801 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1804 if ( id
== 0 ) { // is it a menu item?
1805 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1806 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1807 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1809 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1810 &pMeasureStruct
->itemHeight
);
1812 #endif // owner-drawn menus
1814 wxWindow
*item
= FindItem(id
);
1815 #if USE_DYNAMIC_CLASSES
1816 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1818 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1825 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1826 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1829 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1831 if (nCtlColor
== CTLCOLOR_DLG
)
1833 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1836 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1838 WXHBRUSH hBrush
= 0;
1841 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1843 // I think that even for dialogs, we may need to call DefWindowProc (?)
1844 // Or maybe just rely on the usual default behaviour.
1846 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1851 // Define for each class of dialog and control
1852 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1853 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1855 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1858 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1860 wxSysColourChangedEvent event
;
1861 event
.SetEventObject(this);
1863 // Check if app handles this.
1864 if (GetEventHandler()->ProcessEvent(event
))
1867 // We didn't process it
1871 long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange
)
1873 wxPaletteChangedEvent
event(GetId());
1874 event
.SetEventObject(this);
1875 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
1876 GetEventHandler()->ProcessEvent(event
);
1880 long wxWindow::MSWOnQueryNewPalette()
1882 wxQueryNewPaletteEvent
event(GetId());
1883 event
.SetEventObject(this);
1884 if (!GetEventHandler()->ProcessEvent(event
) || !event
.GetPaletteRealized())
1886 return (long) FALSE
;
1892 // Responds to colour changes: passes event on to children.
1893 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1895 wxNode
*node
= GetChildren()->First();
1898 // Only propagate to non-top-level windows
1899 wxWindow
*win
= (wxWindow
*)node
->Data();
1900 if ( win
->GetParent() )
1902 wxSysColourChangedEvent event2
;
1903 event
.m_eventObject
= win
;
1904 win
->GetEventHandler()->ProcessEvent(event2
);
1907 node
= node
->Next();
1911 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1914 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1916 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1919 long wxWindow::Default()
1921 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1926 wxLogTrace(wxTraceMessages
, "Forwarding %s to DefWindowProc.",
1927 wxGetMessageName(m_lastMsg
));
1930 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1933 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1935 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) ) {
1936 // intercept dialog navigation keys
1937 MSG
*msg
= (MSG
*)pMsg
;
1938 bool bProcess
= TRUE
;
1939 if ( msg
->message
!= WM_KEYDOWN
)
1942 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1945 bool bCtrlDown
= (::GetKeyState(VK_CONTROL
) & 0x100) != 0;
1947 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1948 // (except for Ctrl-Tab combination which is always processed)
1950 if ( bProcess
&& !bCtrlDown
) {
1951 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1956 switch ( msg
->wParam
) {
1958 if ( lDlgCode
& DLGC_WANTTAB
)
1961 bForward
= !(::GetKeyState(VK_SHIFT
) & 0x100);
1966 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1974 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1986 wxNavigationKeyEvent event
;
1987 event
.SetDirection(bForward
);
1988 event
.SetWindowChange(bCtrlDown
);
1989 event
.SetEventObject(this);
1991 if ( GetEventHandler()->ProcessEvent(event
) )
1995 return ::IsDialogMessage((HWND
)GetHWND(), msg
) != 0;
2001 bool wxWindow::MSWTranslateMessage(WXMSG
* WXUNUSED(pMsg
))
2006 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
2009 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
2014 void wxWindow::MSWDetachWindowMenu(void)
2018 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
2020 for (i
= 0; i
< N
; i
++)
2023 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
2024 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
2026 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
2033 bool wxWindow::MSWOnPaint(void)
2036 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2037 ::GetUpdateRgn((HWND
) GetHWND(), hRegion
, FALSE
);
2039 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
2042 ::GetUpdateRect((HWND
) GetHWND(), & updateRect
, FALSE
);
2044 m_updateRegion
= wxRegion(updateRect
.left
, updateRect
.top
,
2045 updateRect
.right
- updateRect
.left
, updateRect
.bottom
- updateRect
.top
);
2048 wxPaintEvent
event(m_windowId
);
2049 event
.SetEventObject(this);
2050 if (!GetEventHandler()->ProcessEvent(event
))
2055 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
2061 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2068 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2069 event
.SetEventObject(this);
2070 if (!GetEventHandler()->ProcessEvent(event
))
2076 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2081 // Deal with child commands from buttons etc.
2082 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
2085 wxDebugMsg("wxWindow::MSWOnCommand\n");
2087 if (wxCurrentPopupMenu
)
2089 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2090 wxCurrentPopupMenu
= NULL
;
2091 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2096 sprintf(buf
, "Looking for item %d...\n", id
);
2100 wxWindow
*item
= FindItem(id
);
2103 bool value
= item
->MSWCommand(cmd
, id
);
2106 wxDebugMsg("MSWCommand succeeded\n");
2108 wxDebugMsg("MSWCommand failed\n");
2115 wxDebugMsg("Could not find item!\n");
2117 wxDebugMsg("Item ids for this panel:\n");
2119 wxNode
*current
= GetChildren()->First();
2122 wxObject
*obj
= (wxObject
*)current
->Data() ;
2123 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2125 wxControl
*item
= (wxControl
*)current
->Data();
2126 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2129 current
= current
->Next();
2137 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2143 wxMaximizeEvent
event(m_windowId
);
2144 event
.SetEventObject(this);
2145 if (!GetEventHandler()->ProcessEvent(event
))
2153 wxIconizeEvent
event(m_windowId
);
2154 event
.SetEventObject(this);
2155 if (!GetEventHandler()->ProcessEvent(event
))
2167 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2169 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2171 event
.m_x
= x
; event
.m_y
= y
;
2172 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2173 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2174 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2175 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2176 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2177 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2178 event
.m_eventObject
= this;
2180 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2182 if (!GetEventHandler()->ProcessEvent(event
))
2186 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2188 wxMouseEvent
event(wxEVT_LEFT_UP
);
2190 event
.m_x
= x
; event
.m_y
= y
;
2191 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2192 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2193 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2194 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2195 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2196 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2197 event
.m_eventObject
= this;
2199 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2201 if (!GetEventHandler()->ProcessEvent(event
))
2205 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2207 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2209 event
.m_x
= x
; event
.m_y
= y
;
2210 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2211 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2212 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2213 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2214 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2215 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2216 event
.m_eventObject
= this;
2218 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2220 if (!GetEventHandler()->ProcessEvent(event
))
2224 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2226 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2228 event
.m_x
= x
; event
.m_y
= y
;
2229 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2230 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2231 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2232 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2233 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2234 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2235 event
.m_eventObject
= this;
2237 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2239 if (!GetEventHandler()->ProcessEvent(event
))
2243 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2245 //wxDebugMsg("MButtonUp\n") ;
2246 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2248 event
.m_x
= x
; event
.m_y
= y
;
2249 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2250 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2251 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2252 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2253 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2254 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2255 event
.m_eventObject
= this;
2257 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2259 if (!GetEventHandler()->ProcessEvent(event
))
2263 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2265 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2267 event
.m_x
= x
; event
.m_y
= y
;
2268 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2269 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2270 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2271 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2272 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2273 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2274 event
.m_eventObject
= this;
2276 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2278 if (!GetEventHandler()->ProcessEvent(event
))
2282 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2284 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2286 event
.m_x
= x
; event
.m_y
= y
;
2287 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2288 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2289 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2290 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2291 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2292 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2293 event
.m_eventObject
= this;
2295 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2297 if (!GetEventHandler()->ProcessEvent(event
))
2301 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2303 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2305 event
.m_x
= x
; event
.m_y
= y
;
2306 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2307 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2308 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2309 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2310 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2311 event
.m_eventObject
= this;
2312 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2314 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2316 if (!GetEventHandler()->ProcessEvent(event
))
2320 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2322 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2324 event
.m_x
= x
; event
.m_y
= y
;
2325 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2326 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2327 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2328 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2329 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2330 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2331 event
.m_eventObject
= this;
2333 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2335 if (!GetEventHandler()->ProcessEvent(event
))
2339 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2341 // 'normal' move event...
2342 // Set cursor, but only if we're not in 'busy' mode
2344 // Trouble with this is that it sets the cursor for controls too :-(
2345 if (m_windowCursor
.Ok() && !wxIsBusy())
2346 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2348 if (!m_mouseInWindow
)
2350 // Generate an ENTER event
2351 m_mouseInWindow
= TRUE
;
2352 MSWOnMouseEnter(x
, y
, flags
);
2355 wxMouseEvent
event(wxEVT_MOTION
);
2357 event
.m_x
= x
; event
.m_y
= y
;
2358 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2359 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2360 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2361 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2362 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2363 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2364 event
.m_eventObject
= this;
2366 // Window gets a click down message followed by a mouse move
2367 // message even if position isn't changed! We want to discard
2368 // the trailing move event if x and y are the same.
2369 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2370 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2371 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2373 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2374 m_lastEvent
= wxEVT_MOTION
;
2378 m_lastEvent
= wxEVT_MOTION
;
2379 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2381 if (!GetEventHandler()->ProcessEvent(event
))
2385 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2387 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2389 event
.m_x
= x
; event
.m_y
= y
;
2390 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2391 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2392 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2393 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2394 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2395 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2396 event
.m_eventObject
= this;
2398 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2399 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2400 // No message - ensure we don't try to call the default behaviour accidentally.
2402 GetEventHandler()->ProcessEvent(event
);
2405 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2407 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2409 event
.m_x
= x
; event
.m_y
= y
;
2410 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2411 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2412 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2413 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2414 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2415 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2416 event
.m_eventObject
= this;
2418 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2419 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2420 // No message - ensure we don't try to call the default behaviour accidentally.
2422 GetEventHandler()->ProcessEvent(event
);
2425 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2428 bool tempControlDown
= FALSE
;
2431 // If 1 -> 26, translate to CTRL plus a letter.
2433 if ((id
> 0) && (id
< 27))
2454 tempControlDown
= TRUE
;
2460 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2461 // it's ASCII and will be processed here only when called from
2462 // WM_CHAR (i.e. when isASCII = TRUE)
2468 wxKeyEvent
event(wxEVT_CHAR
);
2469 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2470 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2471 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2472 event
.m_altDown
= TRUE
;
2474 event
.m_eventObject
= this;
2475 event
.m_keyCode
= id
;
2476 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2481 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2485 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2487 if (!GetEventHandler()->ProcessEvent(event
))
2492 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2496 if (flags
& JOY_BUTTON1CHG
)
2497 change
= wxJOY_BUTTON1
;
2498 if (flags
& JOY_BUTTON2CHG
)
2499 change
= wxJOY_BUTTON2
;
2500 if (flags
& JOY_BUTTON3CHG
)
2501 change
= wxJOY_BUTTON3
;
2502 if (flags
& JOY_BUTTON4CHG
)
2503 change
= wxJOY_BUTTON4
;
2505 if (flags
& JOY_BUTTON1
)
2506 buttons
|= wxJOY_BUTTON1
;
2507 if (flags
& JOY_BUTTON2
)
2508 buttons
|= wxJOY_BUTTON2
;
2509 if (flags
& JOY_BUTTON3
)
2510 buttons
|= wxJOY_BUTTON3
;
2511 if (flags
& JOY_BUTTON4
)
2512 buttons
|= wxJOY_BUTTON4
;
2514 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2515 event
.SetPosition(wxPoint(x
, y
));
2516 event
.SetEventObject(this);
2518 GetEventHandler()->ProcessEvent(event
);
2521 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2525 if (flags
& JOY_BUTTON1CHG
)
2526 change
= wxJOY_BUTTON1
;
2527 if (flags
& JOY_BUTTON2CHG
)
2528 change
= wxJOY_BUTTON2
;
2529 if (flags
& JOY_BUTTON3CHG
)
2530 change
= wxJOY_BUTTON3
;
2531 if (flags
& JOY_BUTTON4CHG
)
2532 change
= wxJOY_BUTTON4
;
2534 if (flags
& JOY_BUTTON1
)
2535 buttons
|= wxJOY_BUTTON1
;
2536 if (flags
& JOY_BUTTON2
)
2537 buttons
|= wxJOY_BUTTON2
;
2538 if (flags
& JOY_BUTTON3
)
2539 buttons
|= wxJOY_BUTTON3
;
2540 if (flags
& JOY_BUTTON4
)
2541 buttons
|= wxJOY_BUTTON4
;
2543 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2544 event
.SetPosition(wxPoint(x
, y
));
2545 event
.SetEventObject(this);
2547 GetEventHandler()->ProcessEvent(event
);
2550 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2553 if (flags
& JOY_BUTTON1
)
2554 buttons
|= wxJOY_BUTTON1
;
2555 if (flags
& JOY_BUTTON2
)
2556 buttons
|= wxJOY_BUTTON2
;
2557 if (flags
& JOY_BUTTON3
)
2558 buttons
|= wxJOY_BUTTON3
;
2559 if (flags
& JOY_BUTTON4
)
2560 buttons
|= wxJOY_BUTTON4
;
2562 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2563 event
.SetPosition(wxPoint(x
, y
));
2564 event
.SetEventObject(this);
2566 GetEventHandler()->ProcessEvent(event
);
2569 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2572 if (flags
& JOY_BUTTON1
)
2573 buttons
|= wxJOY_BUTTON1
;
2574 if (flags
& JOY_BUTTON2
)
2575 buttons
|= wxJOY_BUTTON2
;
2576 if (flags
& JOY_BUTTON3
)
2577 buttons
|= wxJOY_BUTTON3
;
2578 if (flags
& JOY_BUTTON4
)
2579 buttons
|= wxJOY_BUTTON4
;
2581 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2582 event
.SetZPosition(z
);
2583 event
.SetEventObject(this);
2585 GetEventHandler()->ProcessEvent(event
);
2588 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2592 wxWindow
*child
= wxFindWinFromHandle(control
);
2594 child
->MSWOnVScroll(wParam
, pos
, control
);
2598 wxScrollEvent event
;
2599 event
.SetPosition(pos
);
2600 event
.SetOrientation(wxVERTICAL
);
2601 event
.m_eventObject
= this;
2606 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2610 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2614 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2618 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2622 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2626 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2630 case SB_THUMBPOSITION
:
2631 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2639 if (!GetEventHandler()->ProcessEvent(event
))
2643 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2647 wxWindow
*child
= wxFindWinFromHandle(control
);
2649 child
->MSWOnHScroll(wParam
, pos
, control
);
2653 wxScrollEvent event
;
2654 event
.SetPosition(pos
);
2655 event
.SetOrientation(wxHORIZONTAL
);
2656 event
.m_eventObject
= this;
2661 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2665 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2669 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2673 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2677 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2681 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2685 case SB_THUMBPOSITION
:
2686 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2693 if (!GetEventHandler()->ProcessEvent(event
))
2697 void wxWindow::MSWOnShow(bool show
, int status
)
2699 wxShowEvent
event(GetId(), show
);
2700 event
.m_eventObject
= this;
2701 GetEventHandler()->ProcessEvent(event
);
2704 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2706 wxInitDialogEvent
event(GetId());
2707 event
.m_eventObject
= this;
2708 GetEventHandler()->ProcessEvent(event
);
2712 void wxWindow::InitDialog(void)
2714 wxInitDialogEvent
event(GetId());
2715 event
.SetEventObject( this );
2716 GetEventHandler()->ProcessEvent(event
);
2719 // Default init dialog behaviour is to transfer data to window
2720 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2722 TransferDataToWindow();
2725 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2728 HDC dc
= ::GetDC((HWND
) wnd
);
2734 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2736 // the_font->UseResource();
2737 // the_font->RealizeResource();
2738 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2739 was
= (HFONT
) SelectObject(dc
,fnt
) ;
2741 GetTextMetrics(dc
, &tm
);
2742 if (the_font
&& fnt
&& was
)
2745 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2747 SelectObject(dc
,was
) ;
2749 ReleaseDC((HWND
)wnd
, dc
);
2750 *x
= tm
.tmAveCharWidth
;
2751 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2754 // the_font->ReleaseResource();
2757 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2758 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2759 int wxCharCodeMSWToWX(int keySym
)
2764 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2765 case VK_BACK
: id
= WXK_BACK
; break;
2766 case VK_TAB
: id
= WXK_TAB
; break;
2767 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2768 case VK_RETURN
: id
= WXK_RETURN
; break;
2769 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2770 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2771 case VK_MENU
: id
= WXK_MENU
; break;
2772 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2773 case VK_SPACE
: id
= WXK_SPACE
; break;
2774 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2775 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2776 case VK_NEXT
: id
= WXK_NEXT
; break;
2777 case VK_END
: id
= WXK_END
; break;
2778 case VK_HOME
: id
= WXK_HOME
; break;
2779 case VK_LEFT
: id
= WXK_LEFT
; break;
2780 case VK_UP
: id
= WXK_UP
; break;
2781 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2782 case VK_DOWN
: id
= WXK_DOWN
; break;
2783 case VK_SELECT
: id
= WXK_SELECT
; break;
2784 case VK_PRINT
: id
= WXK_PRINT
; break;
2785 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2786 case VK_INSERT
: id
= WXK_INSERT
; break;
2787 case VK_DELETE
: id
= WXK_DELETE
; break;
2788 case VK_HELP
: id
= WXK_HELP
; break;
2789 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2790 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2791 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2792 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2793 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2794 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2795 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2796 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2797 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2798 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2799 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2800 case VK_ADD
: id
= WXK_ADD
; break;
2801 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2802 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2803 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2804 case VK_F1
: id
= WXK_F1
; break;
2805 case VK_F2
: id
= WXK_F2
; break;
2806 case VK_F3
: id
= WXK_F3
; break;
2807 case VK_F4
: id
= WXK_F4
; break;
2808 case VK_F5
: id
= WXK_F5
; break;
2809 case VK_F6
: id
= WXK_F6
; break;
2810 case VK_F7
: id
= WXK_F7
; break;
2811 case VK_F8
: id
= WXK_F8
; break;
2812 case VK_F9
: id
= WXK_F9
; break;
2813 case VK_F10
: id
= WXK_F10
; break;
2814 case VK_F11
: id
= WXK_F11
; break;
2815 case VK_F12
: id
= WXK_F12
; break;
2816 case VK_F13
: id
= WXK_F13
; break;
2817 case VK_F14
: id
= WXK_F14
; break;
2818 case VK_F15
: id
= WXK_F15
; break;
2819 case VK_F16
: id
= WXK_F16
; break;
2820 case VK_F17
: id
= WXK_F17
; break;
2821 case VK_F18
: id
= WXK_F18
; break;
2822 case VK_F19
: id
= WXK_F19
; break;
2823 case VK_F20
: id
= WXK_F20
; break;
2824 case VK_F21
: id
= WXK_F21
; break;
2825 case VK_F22
: id
= WXK_F22
; break;
2826 case VK_F23
: id
= WXK_F23
; break;
2827 case VK_F24
: id
= WXK_F24
; break;
2828 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2829 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2838 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2844 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2845 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2846 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2847 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2848 case WXK_MENU
: keySym
= VK_MENU
; break;
2849 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2850 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2851 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2852 case WXK_END
: keySym
= VK_END
; break;
2853 case WXK_HOME
: keySym
= VK_HOME
; break;
2854 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2855 case WXK_UP
: keySym
= VK_UP
; break;
2856 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2857 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2858 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2859 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2860 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2861 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2862 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2863 case WXK_HELP
: keySym
= VK_HELP
; break;
2864 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2865 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2866 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2867 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2868 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2869 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2870 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2871 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2872 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2873 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2874 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2875 case WXK_ADD
: keySym
= VK_ADD
; break;
2876 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2877 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2878 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2879 case WXK_F1
: keySym
= VK_F1
; break;
2880 case WXK_F2
: keySym
= VK_F2
; break;
2881 case WXK_F3
: keySym
= VK_F3
; break;
2882 case WXK_F4
: keySym
= VK_F4
; break;
2883 case WXK_F5
: keySym
= VK_F5
; break;
2884 case WXK_F6
: keySym
= VK_F6
; break;
2885 case WXK_F7
: keySym
= VK_F7
; break;
2886 case WXK_F8
: keySym
= VK_F8
; break;
2887 case WXK_F9
: keySym
= VK_F9
; break;
2888 case WXK_F10
: keySym
= VK_F10
; break;
2889 case WXK_F11
: keySym
= VK_F11
; break;
2890 case WXK_F12
: keySym
= VK_F12
; break;
2891 case WXK_F13
: keySym
= VK_F13
; break;
2892 case WXK_F14
: keySym
= VK_F14
; break;
2893 case WXK_F15
: keySym
= VK_F15
; break;
2894 case WXK_F16
: keySym
= VK_F16
; break;
2895 case WXK_F17
: keySym
= VK_F17
; break;
2896 case WXK_F18
: keySym
= VK_F18
; break;
2897 case WXK_F19
: keySym
= VK_F19
; break;
2898 case WXK_F20
: keySym
= VK_F20
; break;
2899 case WXK_F21
: keySym
= VK_F21
; break;
2900 case WXK_F22
: keySym
= VK_F22
; break;
2901 case WXK_F23
: keySym
= VK_F23
; break;
2902 case WXK_F24
: keySym
= VK_F24
; break;
2903 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2904 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2915 // Caret manipulation
2916 void wxWindow::CreateCaret(int w
, int h
)
2920 m_caretEnabled
= TRUE
;
2923 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2928 void wxWindow::ShowCaret(bool show
)
2933 ::ShowCaret((HWND
) GetHWND());
2935 ::HideCaret((HWND
) GetHWND());
2936 m_caretShown
= show
;
2940 void wxWindow::DestroyCaret(void)
2942 m_caretEnabled
= FALSE
;
2945 void wxWindow::SetCaretPos(int x
, int y
)
2947 ::SetCaretPos(x
, y
);
2950 void wxWindow::GetCaretPos(int *x
, int *y
) const
2953 ::GetCaretPos(&point
);
2958 wxWindow
*wxGetActiveWindow(void)
2960 HWND hWnd
= GetActiveWindow();
2963 return wxFindWinFromHandle((WXHWND
) hWnd
);
2968 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2969 // in active frames and dialogs, regardless of where the focus is.
2970 static HHOOK wxTheKeyboardHook
= 0;
2971 static FARPROC wxTheKeyboardHookProc
= 0;
2972 int APIENTRY _EXPORT
2973 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
2975 void wxSetKeyboardHook(bool doIt
)
2979 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
2980 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
2982 GetCurrentThreadId());
2983 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2990 UnhookWindowsHookEx(wxTheKeyboardHook
);
2991 FreeProcInstance(wxTheKeyboardHookProc
);
2995 int APIENTRY _EXPORT
2996 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
2998 DWORD hiWord
= HIWORD(lParam
);
2999 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3002 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3004 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3005 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3006 event
.m_altDown
= TRUE
;
3008 event
.m_eventObject
= NULL
;
3009 event
.m_keyCode
= id
;
3010 /* begin Albert's fix for control and shift key 26.5 */
3011 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3012 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3013 /* end Albert's fix for control and shift key 26.5 */
3014 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3016 wxWindow
*win
= wxGetActiveWindow();
3019 if (win
->GetEventHandler()->ProcessEvent(event
))
3024 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3029 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3032 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3040 void wxWindow::Centre(int direction
)
3042 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3044 wxWindow
*father
= (wxWindow
*)GetParent();
3048 father
->GetClientSize(&panel_width
, &panel_height
);
3049 GetSize(&width
, &height
);
3050 GetPosition(&x
, &y
);
3055 if (direction
& wxHORIZONTAL
)
3056 new_x
= (int)((panel_width
- width
)/2);
3058 if (direction
& wxVERTICAL
)
3059 new_y
= (int)((panel_height
- height
)/2);
3061 SetSize(new_x
, new_y
, -1, -1);
3066 void wxWindow::OnPaint(void)
3068 PaintSelectionHandles();
3072 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3074 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3075 // pixel coordinates, relatives to the canvas -- So, we first need to
3076 // substract origin of the window, then convert to screen position
3078 int x
= x_pos
; int y
= y_pos
;
3080 GetWindowRect ((HWND
) GetHWND(), &rect
);
3085 SetCursorPos (x
, y
);
3088 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3092 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3100 wxEraseEvent
event(m_windowId
, &dc
);
3101 event
.m_eventObject
= this;
3102 if (!GetEventHandler()->ProcessEvent(event
))
3105 dc
.SelectOldObjects(pDC
);
3111 dc
.SelectOldObjects(pDC
);
3114 dc
.SetHDC((WXHDC
) NULL
);
3118 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3121 ::GetClientRect((HWND
) GetHWND(), &rect
);
3123 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3124 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3126 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3127 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3128 ::DeleteObject(hBrush
);
3129 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3131 // Less efficient version (and doesn't account for scrolling)
3133 GetClientSize(& w, & h);
3134 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3135 event.GetDC()->SetBrush(brush);
3136 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3138 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3142 #if WXWIN_COMPATIBILITY
3143 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3145 #if defined(__WIN95__)
3149 // Try to adjust the range to cope with page size > 1
3150 // - a Windows API quirk
3151 int pageSize
= GetScrollPage(orient
);
3152 if ( pageSize
> 1 && range
> 0)
3154 range1
+= (pageSize
- 1);
3160 if (orient
== wxHORIZONTAL
) {
3166 info
.cbSize
= sizeof(SCROLLINFO
);
3167 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3171 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3173 HWND hWnd
= (HWND
) GetHWND();
3175 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3178 if (orient
== wxHORIZONTAL
)
3183 HWND hWnd
= (HWND
) GetHWND();
3185 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3189 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3191 #if defined(__WIN95__)
3195 if (orient
== wxHORIZONTAL
) {
3197 m_xThumbSize
= page
;
3200 m_yThumbSize
= page
;
3203 info
.cbSize
= sizeof(SCROLLINFO
);
3206 info
.fMask
= SIF_PAGE
;
3208 HWND hWnd
= (HWND
) GetHWND();
3210 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3212 if (orient
== wxHORIZONTAL
)
3213 m_xThumbSize
= page
;
3215 m_yThumbSize
= page
;
3219 int wxWindow::OldGetScrollRange(int orient
) const
3222 if (orient
== wxHORIZONTAL
)
3227 #if __WATCOMC__ && defined(__WINDOWS_386__)
3228 short minPos
, maxPos
;
3232 HWND hWnd
= (HWND
) GetHWND();
3235 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3236 #if defined(__WIN95__)
3237 // Try to adjust the range to cope with page size > 1
3238 // - a Windows API quirk
3239 int pageSize
= GetScrollPage(orient
);
3242 maxPos
-= (pageSize
- 1);
3251 int wxWindow::GetScrollPage(int orient
) const
3253 if (orient
== wxHORIZONTAL
)
3254 return m_xThumbSize
;
3256 return m_yThumbSize
;
3260 int wxWindow::GetScrollPos(int orient
) const
3263 if (orient
== wxHORIZONTAL
)
3267 HWND hWnd
= (HWND
) GetHWND();
3270 return ::GetScrollPos(hWnd
, wOrient
);
3276 // This now returns the whole range, not just the number
3277 // of positions that we can scroll.
3278 int wxWindow::GetScrollRange(int orient
) const
3281 if (orient
== wxHORIZONTAL
)
3286 #if __WATCOMC__ && defined(__WINDOWS_386__)
3287 short minPos
, maxPos
;
3291 HWND hWnd
= (HWND
) GetHWND();
3294 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3295 #if defined(__WIN95__)
3296 // Try to adjust the range to cope with page size > 1
3297 // - a Windows API quirk
3298 int pageSize
= GetScrollPage(orient
);
3301 maxPos
-= (pageSize
- 1);
3303 // October 10th: new range concept.
3313 int wxWindow::GetScrollThumb(int orient
) const
3315 if (orient
== wxHORIZONTAL
)
3316 return m_xThumbSize
;
3318 return m_yThumbSize
;
3321 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3323 #if defined(__WIN95__)
3327 if (orient
== wxHORIZONTAL
) {
3333 info
.cbSize
= sizeof(SCROLLINFO
);
3337 info
.fMask
= SIF_POS
;
3339 HWND hWnd
= (HWND
) GetHWND();
3341 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3344 if (orient
== wxHORIZONTAL
)
3349 HWND hWnd
= (HWND
) GetHWND();
3351 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3355 // New function that will replace some of the above.
3356 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3357 int range
, bool refresh
)
3360 SetScrollPage(orient, thumbVisible, FALSE);
3362 int oldRange = range - thumbVisible ;
3363 SetScrollRange(orient, oldRange, FALSE);
3365 SetScrollPos(orient, pos, refresh);
3367 #if defined(__WIN95__)
3368 int oldRange
= range
- thumbVisible
;
3370 int range1
= oldRange
;
3372 // Try to adjust the range to cope with page size > 1
3373 // - a Windows API quirk
3374 int pageSize
= thumbVisible
;
3375 if ( pageSize
> 1 && range
> 0)
3377 range1
+= (pageSize
- 1);
3383 if (orient
== wxHORIZONTAL
) {
3389 info
.cbSize
= sizeof(SCROLLINFO
);
3390 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3394 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3396 HWND hWnd
= (HWND
) GetHWND();
3398 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3401 if (orient
== wxHORIZONTAL
)
3406 HWND hWnd
= (HWND
) GetHWND();
3409 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3410 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3413 if (orient
== wxHORIZONTAL
) {
3414 m_xThumbSize
= thumbVisible
;
3416 m_yThumbSize
= thumbVisible
;
3420 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3425 rect2
.left
= rect
->x
;
3426 rect2
.top
= rect
->y
;
3427 rect2
.right
= rect
->x
+ rect
->width
;
3428 rect2
.bottom
= rect
->y
+ rect
->height
;
3432 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3434 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3437 void wxWindow::SetFont(const wxFont
& font
)
3439 m_windowFont
= font
;
3441 if (!m_windowFont
.Ok())
3444 HWND hWnd
= (HWND
) GetHWND();
3447 if (m_windowFont
.GetResourceHandle())
3448 SendMessage(hWnd
, WM_SETFONT
,
3449 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3453 void wxWindow::SubclassWin(WXHWND hWnd
)
3455 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3457 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3458 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3461 void wxWindow::UnsubclassWin(void)
3463 wxRemoveHandleAssociation(this);
3465 // Restore old Window proc
3466 if ((HWND
) GetHWND())
3468 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3469 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3471 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3477 // Make a Windows extended style from the given wxWindows window style
3478 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3480 WXDWORD exStyle
= 0;
3481 if ( style
& wxTRANSPARENT_WINDOW
)
3482 exStyle
|= WS_EX_TRANSPARENT
;
3484 if ( !eliminateBorders
)
3486 if ( style
& wxSUNKEN_BORDER
)
3487 exStyle
|= WS_EX_CLIENTEDGE
;
3488 if ( style
& wxDOUBLE_BORDER
)
3489 exStyle
|= WS_EX_DLGMODALFRAME
;
3490 #if defined(__WIN95__)
3491 if ( style
& wxRAISED_BORDER
)
3492 exStyle
|= WS_EX_WINDOWEDGE
;
3493 if ( style
& wxSTATIC_BORDER
)
3494 exStyle
|= WS_EX_STATICEDGE
;
3500 // Determines whether native 3D effects or CTL3D should be used,
3501 // applying a default border style if required, and returning an extended
3502 // style to pass to CreateWindowEx.
3503 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3505 // If matches certain criteria, then assume no 3D effects
3506 // unless specifically requested (dealt with in MakeExtendedStyle)
3507 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3510 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3513 // Determine whether we should be using 3D effects or not.
3514 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3516 // 1) App can specify global 3D effects
3517 *want3D
= wxTheApp
->GetAuto3D();
3519 // 2) If the parent is being drawn with user colours, or simple border specified,
3520 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3521 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3524 // 3) Control can override this global setting by defining
3525 // a border style, e.g. wxSUNKEN_BORDER
3526 if (m_windowStyle
& wxSUNKEN_BORDER
)
3529 // 4) If it's a special border, CTL3D can't cope so we want a native border
3530 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3531 (m_windowStyle
& wxSTATIC_BORDER
) )
3534 nativeBorder
= TRUE
;
3537 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3538 // effects from extended style
3541 nativeBorder
= FALSE
;
3544 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3546 // If we want 3D, but haven't specified a border here,
3547 // apply the default border style specified.
3548 // TODO what about non-Win95 WIN32? Does it have borders?
3549 #if defined(__WIN95__) && !CTL3D
3550 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3551 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3552 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3558 void wxWindow::OnChar(wxKeyEvent
& event
)
3560 if ( event
.KeyCode() == WXK_TAB
) {
3561 // propagate the TABs to the parent - it's up to it to decide what
3563 if ( GetParent() ) {
3564 if ( GetParent()->ProcessEvent(event
) )
3570 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3575 if ( !event
.ControlDown() )
3576 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3579 void wxWindow::OnPaint(wxPaintEvent
& event
)
3584 bool wxWindow::IsEnabled(void) const
3586 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3589 // Dialog support: override these and call
3590 // base class members to add functionality
3591 // that can't be done using validators.
3592 // NOTE: these functions assume that controls
3593 // are direct children of this window, not grandchildren
3594 // or other levels of descendant.
3596 // Transfer values to controls. If returns FALSE,
3597 // it's an application error (pops up a dialog)
3598 bool wxWindow::TransferDataToWindow(void)
3600 wxNode
*node
= GetChildren()->First();
3603 wxWindow
*child
= (wxWindow
*)node
->Data();
3604 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3605 !child
->GetValidator()->TransferToWindow() )
3607 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3611 node
= node
->Next();
3616 // Transfer values from controls. If returns FALSE,
3617 // validation failed: don't quit
3618 bool wxWindow::TransferDataFromWindow(void)
3620 wxNode
*node
= GetChildren()->First();
3623 wxWindow
*child
= (wxWindow
*)node
->Data();
3624 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3629 node
= node
->Next();
3634 bool wxWindow::Validate(void)
3636 wxNode
*node
= GetChildren()->First();
3639 wxWindow
*child
= (wxWindow
*)node
->Data();
3640 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3645 node
= node
->Next();
3650 // Get the window with the focus
3651 wxWindow
*wxWindow::FindFocus(void)
3653 HWND hWnd
= ::GetFocus();
3656 return wxFindWinFromHandle((WXHWND
) hWnd
);
3661 void wxWindow::AddChild(wxWindow
*child
)
3663 GetChildren()->Append(child
);
3664 child
->m_windowParent
= this;
3667 void wxWindow::RemoveChild(wxWindow
*child
)
3670 GetChildren()->DeleteObject(child
);
3671 child
->m_windowParent
= NULL
;
3674 void wxWindow::DestroyChildren(void)
3676 if (GetChildren()) {
3678 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3680 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3682 if ( GetChildren()->Member(child
) )
3689 void wxWindow::MakeModal(bool modal
)
3691 // Disable all other windows
3692 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3694 wxNode
*node
= wxTopLevelWindows
.First();
3697 wxWindow
*win
= (wxWindow
*)node
->Data();
3699 win
->Enable(!modal
);
3701 node
= node
->Next();
3706 // If nothing defined for this, try the parent.
3707 // E.g. we may be a button loaded from a resource, with no callback function
3709 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3711 if (GetEventHandler()->ProcessEvent(event
) )
3714 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3717 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3721 UnsetConstraints(m_constraints
);
3722 delete m_constraints
;
3727 // Make sure other windows know they're part of a 'meaningful relationship'
3728 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3729 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3730 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3731 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3732 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3733 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3734 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3735 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3736 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3737 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3738 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3739 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3740 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3741 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3742 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3743 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3747 // This removes any dangling pointers to this window
3748 // in other windows' constraintsInvolvedIn lists.
3749 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3753 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3754 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3755 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3756 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3757 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3758 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3759 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3760 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3761 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3762 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3763 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3764 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3765 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3766 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3767 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3768 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3772 // Back-pointer to other windows we're involved with, so if we delete
3773 // this window, we must delete any constraints we're involved with.
3774 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3776 if (!m_constraintsInvolvedIn
)
3777 m_constraintsInvolvedIn
= new wxList
;
3778 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3779 m_constraintsInvolvedIn
->Append(otherWin
);
3782 // REMOVE back-pointer to other windows we're involved with.
3783 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3785 if (m_constraintsInvolvedIn
)
3786 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3789 // Reset any constraints that mention this window
3790 void wxWindow::DeleteRelatedConstraints(void)
3792 if (m_constraintsInvolvedIn
)
3794 wxNode
*node
= m_constraintsInvolvedIn
->First();
3797 wxWindow
*win
= (wxWindow
*)node
->Data();
3798 wxNode
*next
= node
->Next();
3799 wxLayoutConstraints
*constr
= win
->GetConstraints();
3801 // Reset any constraints involving this window
3804 constr
->left
.ResetIfWin((wxWindow
*)this);
3805 constr
->top
.ResetIfWin((wxWindow
*)this);
3806 constr
->right
.ResetIfWin((wxWindow
*)this);
3807 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3808 constr
->width
.ResetIfWin((wxWindow
*)this);
3809 constr
->height
.ResetIfWin((wxWindow
*)this);
3810 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3811 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3816 delete m_constraintsInvolvedIn
;
3817 m_constraintsInvolvedIn
= NULL
;
3821 void wxWindow::SetSizer(wxSizer
*sizer
)
3823 m_windowSizer
= sizer
;
3825 sizer
->SetSizerParent((wxWindow
*)this);
3832 bool wxWindow::Layout(void)
3834 if (GetConstraints())
3837 GetClientSize(&w
, &h
);
3838 GetConstraints()->width
.SetValue(w
);
3839 GetConstraints()->height
.SetValue(h
);
3842 // If top level (one sizer), evaluate the sizer's constraints.
3846 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3847 GetSizer()->LayoutPhase1(&noChanges
);
3848 GetSizer()->LayoutPhase2(&noChanges
);
3849 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3854 // Otherwise, evaluate child constraints
3855 ResetConstraints(); // Mark all constraints as unevaluated
3856 DoPhase(1); // Just one phase need if no sizers involved
3858 SetConstraintSizes(); // Recursively set the real window sizes
3864 // Do a phase of evaluating constraints:
3865 // the default behaviour. wxSizers may do a similar
3866 // thing, but also impose their own 'constraints'
3867 // and order the evaluation differently.
3868 bool wxWindow::LayoutPhase1(int *noChanges
)
3870 wxLayoutConstraints
*constr
= GetConstraints();
3873 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3879 bool wxWindow::LayoutPhase2(int *noChanges
)
3889 // Do a phase of evaluating child constraints
3890 bool wxWindow::DoPhase(int phase
)
3892 int noIterations
= 0;
3893 int maxIterations
= 500;
3897 while ((noChanges
> 0) && (noIterations
< maxIterations
))
3901 wxNode
*node
= GetChildren()->First();
3904 wxWindow
*child
= (wxWindow
*)node
->Data();
3905 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
3907 wxLayoutConstraints
*constr
= child
->GetConstraints();
3910 if (succeeded
.Member(child
))
3915 int tempNoChanges
= 0;
3916 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
3917 noChanges
+= tempNoChanges
;
3920 succeeded
.Append(child
);
3925 node
= node
->Next();
3932 void wxWindow::ResetConstraints(void)
3934 wxLayoutConstraints
*constr
= GetConstraints();
3937 constr
->left
.SetDone(FALSE
);
3938 constr
->top
.SetDone(FALSE
);
3939 constr
->right
.SetDone(FALSE
);
3940 constr
->bottom
.SetDone(FALSE
);
3941 constr
->width
.SetDone(FALSE
);
3942 constr
->height
.SetDone(FALSE
);
3943 constr
->centreX
.SetDone(FALSE
);
3944 constr
->centreY
.SetDone(FALSE
);
3946 wxNode
*node
= GetChildren()->First();
3949 wxWindow
*win
= (wxWindow
*)node
->Data();
3950 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
3951 win
->ResetConstraints();
3952 node
= node
->Next();
3956 // Need to distinguish between setting the 'fake' size for
3957 // windows and sizers, and setting the real values.
3958 void wxWindow::SetConstraintSizes(bool recurse
)
3960 wxLayoutConstraints
*constr
= GetConstraints();
3961 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
3962 constr
->width
.GetDone() && constr
->height
.GetDone())
3964 int x
= constr
->left
.GetValue();
3965 int y
= constr
->top
.GetValue();
3966 int w
= constr
->width
.GetValue();
3967 int h
= constr
->height
.GetValue();
3969 // If we don't want to resize this window, just move it...
3970 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
3971 (constr
->height
.GetRelationship() != wxAsIs
))
3973 // Calls Layout() recursively. AAAGH. How can we stop that.
3974 // Simply take Layout() out of non-top level OnSizes.
3975 SizerSetSize(x
, y
, w
, h
);
3984 char *windowClass
= this->GetClassInfo()->GetClassName();
3987 if (GetName() == "")
3988 winName
= "unnamed";
3990 winName
= GetName();
3991 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
3992 if (!constr
->left
.GetDone())
3993 wxDebugMsg(" unsatisfied 'left' constraint.\n");
3994 if (!constr
->right
.GetDone())
3995 wxDebugMsg(" unsatisfied 'right' constraint.\n");
3996 if (!constr
->width
.GetDone())
3997 wxDebugMsg(" unsatisfied 'width' constraint.\n");
3998 if (!constr
->height
.GetDone())
3999 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4000 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4005 wxNode
*node
= GetChildren()->First();
4008 wxWindow
*win
= (wxWindow
*)node
->Data();
4009 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4010 win
->SetConstraintSizes();
4011 node
= node
->Next();
4016 // This assumes that all sizers are 'on' the same
4017 // window, i.e. the parent of this window.
4018 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4020 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4021 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4025 m_sizerParent
->GetPosition(&xp
, &yp
);
4026 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4031 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4035 TransformSizerToActual(&xx
, &yy
);
4036 SetSize(xx
, yy
, w
, h
);
4039 void wxWindow::SizerMove(int x
, int y
)
4043 TransformSizerToActual(&xx
, &yy
);
4047 // Only set the size/position of the constraint (if any)
4048 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4050 wxLayoutConstraints
*constr
= GetConstraints();
4055 constr
->left
.SetValue(x
);
4056 constr
->left
.SetDone(TRUE
);
4060 constr
->top
.SetValue(y
);
4061 constr
->top
.SetDone(TRUE
);
4065 constr
->width
.SetValue(w
);
4066 constr
->width
.SetDone(TRUE
);
4070 constr
->height
.SetValue(h
);
4071 constr
->height
.SetDone(TRUE
);
4076 void wxWindow::MoveConstraint(int x
, int y
)
4078 wxLayoutConstraints
*constr
= GetConstraints();
4083 constr
->left
.SetValue(x
);
4084 constr
->left
.SetDone(TRUE
);
4088 constr
->top
.SetValue(y
);
4089 constr
->top
.SetDone(TRUE
);
4094 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4096 wxLayoutConstraints
*constr
= GetConstraints();
4099 *w
= constr
->width
.GetValue();
4100 *h
= constr
->height
.GetValue();
4106 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4108 wxLayoutConstraints
*constr
= GetConstraints();
4111 *w
= constr
->width
.GetValue();
4112 *h
= constr
->height
.GetValue();
4115 GetClientSize(w
, h
);
4118 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4120 wxLayoutConstraints
*constr
= GetConstraints();
4123 *x
= constr
->left
.GetValue();
4124 *y
= constr
->top
.GetValue();
4130 bool wxWindow::Close(bool force
)
4132 // Let's generalise it to work the same for any window.
4134 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4141 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4142 event
.SetEventObject(this);
4143 event
.SetForce(force
);
4145 return GetEventHandler()->ProcessEvent(event
);
4148 if ( !force && event.GetVeto() )
4153 if (!wxPendingDelete.Member(this))
4154 wxPendingDelete.Append(this);
4160 wxObject
* wxWindow::GetChild(int number
) const
4162 // Return a pointer to the Nth object in the Panel
4165 wxNode
*node
= GetChildren()->First();
4168 node
= node
->Next() ;
4171 wxObject
*obj
= (wxObject
*)node
->Data();
4178 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4180 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4181 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4184 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4186 wxListBox *lbox = (wxListBox *)initiatingItem;
4187 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4188 event.m_commandInt = -1;
4189 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4191 event.m_commandString = copystring(lbox->GetStringSelection());
4192 event.m_commandInt = lbox->GetSelection();
4193 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4195 event.m_eventObject = lbox;
4197 lbox->ProcessCommand(event);
4199 if (event.m_commandString)
4200 delete[] event.m_commandString;
4204 wxButton *but = GetDefaultItem();
4207 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4208 event.SetEventObject(but);
4209 but->Command(event);
4214 void wxWindow::Clear(void)
4216 wxClientDC
dc(this);
4217 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4218 dc
.SetBackground(brush
);
4222 // Fits the panel around the items
4223 void wxWindow::Fit(void)
4227 wxNode
*node
= GetChildren()->First();
4230 wxWindow
*win
= (wxWindow
*)node
->Data();
4232 win
->GetPosition(&wx
, &wy
);
4233 win
->GetSize(&ww
, &wh
);
4234 if ( wx
+ ww
> maxX
)
4236 if ( wy
+ wh
> maxY
)
4239 node
= node
->Next();
4241 SetClientSize(maxX
+ 5, maxY
+ 5);
4244 void wxWindow::SetValidator(const wxValidator
& validator
)
4246 if ( m_windowValidator
)
4247 delete m_windowValidator
;
4248 m_windowValidator
= validator
.Clone();
4250 if ( m_windowValidator
)
4251 m_windowValidator
->SetWindow(this) ;
4254 // Find a window by id or name
4255 wxWindow
*wxWindow::FindWindow(long id
)
4260 wxNode
*node
= GetChildren()->First();
4263 wxWindow
*child
= (wxWindow
*)node
->Data();
4264 wxWindow
*found
= child
->FindWindow(id
);
4267 node
= node
->Next();
4272 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4274 if ( GetName() == name
)
4277 wxNode
*node
= GetChildren()->First();
4280 wxWindow
*child
= (wxWindow
*)node
->Data();
4281 wxWindow
*found
= child
->FindWindow(name
);
4284 node
= node
->Next();
4290 // Default input behaviour for a scrolling canvas should be to scroll
4291 // according to the cursor keys pressed
4292 void wxWindow::OnChar(wxKeyEvent& event)
4304 GetScrollUnitsPerPage(&x_page, &y_page);
4306 GetVirtualSize(&v_width,&v_height);
4308 ViewStart(&start_x, &start_y);
4311 y_pages = (int)(v_height/vert_units) - y_page;
4319 switch (event.keyCode)
4326 if (start_y - y_page > 0)
4327 Scroll(start_x, start_y - y_page);
4337 if ((y_page > 0) && (start_y <= y_pages-y-1))
4339 if (y_pages + y < start_y + y_page)
4340 Scroll(start_x, y_pages + y);
4342 Scroll(start_x, start_y + y_page);
4349 if ((y_page > 0) && (start_y >= 1))
4350 Scroll(start_x, start_y - 1);
4356 if ((y_page > 0) && (start_y <= y_pages-y-1))
4359 Scroll(start_x, start_y + 1);
4365 if ((x_page > 0) && (start_x >= 1))
4366 Scroll(start_x - 1, start_y);
4372 Scroll(start_x + 1, start_y);
4383 Scroll(start_x, y_pages+y);
4391 // Setup background and foreground colours correctly
4392 void wxWindow::SetupColours(void)
4395 SetBackgroundColour(GetParent()->GetBackgroundColour());
4398 void wxWindow::OnIdle(wxIdleEvent
& event
)
4401 // Check if we need to send a LEAVE event
4402 if (m_mouseInWindow
)
4405 ::GetCursorPos(&pt
);
4406 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4408 // Generate a LEAVE event
4409 m_mouseInWindow
= FALSE
;
4410 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4417 // Raise the window to the top of the Z order
4418 void wxWindow::Raise(void)
4420 ::BringWindowToTop((HWND
) GetHWND());
4423 // Lower the window to the bottom of the Z order
4424 void wxWindow::Lower(void)
4426 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
4429 long wxWindow::MSWGetDlgCode()
4431 // default: just forward to def window proc (the msg has no parameters)
4432 return MSWDefWindowProc(WM_GETDLGCODE
, 0, 0);
4435 bool wxWindow::AcceptsFocus() const
4437 return IsShown() && IsEnabled();
4440 // Update region access
4441 wxRegion
wxWindow::GetUpdateRegion() const
4443 return m_updateRegion
;
4446 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
4448 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
4451 bool wxWindow::IsExposed(const wxPoint
& pt
) const
4453 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
4456 bool wxWindow::IsExposed(const wxRect
& rect
) const
4458 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
4462 const char *wxGetMessageName(int message
)
4464 switch ( message
) {
4465 case 0x0000: return "WM_NULL";
4466 case 0x0001: return "WM_CREATE";
4467 case 0x0002: return "WM_DESTROY";
4468 case 0x0003: return "WM_MOVE";
4469 case 0x0005: return "WM_SIZE";
4470 case 0x0006: return "WM_ACTIVATE";
4471 case 0x0007: return "WM_SETFOCUS";
4472 case 0x0008: return "WM_KILLFOCUS";
4473 case 0x000A: return "WM_ENABLE";
4474 case 0x000B: return "WM_SETREDRAW";
4475 case 0x000C: return "WM_SETTEXT";
4476 case 0x000D: return "WM_GETTEXT";
4477 case 0x000E: return "WM_GETTEXTLENGTH";
4478 case 0x000F: return "WM_PAINT";
4479 case 0x0010: return "WM_CLOSE";
4480 case 0x0011: return "WM_QUERYENDSESSION";
4481 case 0x0012: return "WM_QUIT";
4482 case 0x0013: return "WM_QUERYOPEN";
4483 case 0x0014: return "WM_ERASEBKGND";
4484 case 0x0015: return "WM_SYSCOLORCHANGE";
4485 case 0x0016: return "WM_ENDSESSION";
4486 case 0x0017: return "WM_SYSTEMERROR";
4487 case 0x0018: return "WM_SHOWWINDOW";
4488 case 0x0019: return "WM_CTLCOLOR";
4489 case 0x001A: return "WM_WININICHANGE";
4490 case 0x001B: return "WM_DEVMODECHANGE";
4491 case 0x001C: return "WM_ACTIVATEAPP";
4492 case 0x001D: return "WM_FONTCHANGE";
4493 case 0x001E: return "WM_TIMECHANGE";
4494 case 0x001F: return "WM_CANCELMODE";
4495 case 0x0020: return "WM_SETCURSOR";
4496 case 0x0021: return "WM_MOUSEACTIVATE";
4497 case 0x0022: return "WM_CHILDACTIVATE";
4498 case 0x0023: return "WM_QUEUESYNC";
4499 case 0x0024: return "WM_GETMINMAXINFO";
4500 case 0x0026: return "WM_PAINTICON";
4501 case 0x0027: return "WM_ICONERASEBKGND";
4502 case 0x0028: return "WM_NEXTDLGCTL";
4503 case 0x002A: return "WM_SPOOLERSTATUS";
4504 case 0x002B: return "WM_DRAWITEM";
4505 case 0x002C: return "WM_MEASUREITEM";
4506 case 0x002D: return "WM_DELETEITEM";
4507 case 0x002E: return "WM_VKEYTOITEM";
4508 case 0x002F: return "WM_CHARTOITEM";
4509 case 0x0030: return "WM_SETFONT";
4510 case 0x0031: return "WM_GETFONT";
4511 case 0x0037: return "WM_QUERYDRAGICON";
4512 case 0x0039: return "WM_COMPAREITEM";
4513 case 0x0041: return "WM_COMPACTING";
4514 case 0x0044: return "WM_COMMNOTIFY";
4515 case 0x0046: return "WM_WINDOWPOSCHANGING";
4516 case 0x0047: return "WM_WINDOWPOSCHANGED";
4517 case 0x0048: return "WM_POWER";
4518 case 0x0081: return "WM_NCCREATE";
4519 case 0x0082: return "WM_NCDESTROY";
4520 case 0x0083: return "WM_NCCALCSIZE";
4521 case 0x0084: return "WM_NCHITTEST";
4522 case 0x0085: return "WM_NCPAINT";
4523 case 0x0086: return "WM_NCACTIVATE";
4524 case 0x0087: return "WM_GETDLGCODE";
4525 case 0x00A0: return "WM_NCMOUSEMOVE";
4526 case 0x00A1: return "WM_NCLBUTTONDOWN";
4527 case 0x00A2: return "WM_NCLBUTTONUP";
4528 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4529 case 0x00A4: return "WM_NCRBUTTONDOWN";
4530 case 0x00A5: return "WM_NCRBUTTONUP";
4531 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4532 case 0x00A7: return "WM_NCMBUTTONDOWN";
4533 case 0x00A8: return "WM_NCMBUTTONUP";
4534 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4535 case 0x0100: return "WM_KEYDOWN";
4536 case 0x0101: return "WM_KEYUP";
4537 case 0x0102: return "WM_CHAR";
4538 case 0x0103: return "WM_DEADCHAR";
4539 case 0x0104: return "WM_SYSKEYDOWN";
4540 case 0x0105: return "WM_SYSKEYUP";
4541 case 0x0106: return "WM_SYSCHAR";
4542 case 0x0107: return "WM_SYSDEADCHAR";
4543 case 0x0108: return "WM_KEYLAST";
4544 case 0x0110: return "WM_INITDIALOG";
4545 case 0x0111: return "WM_COMMAND";
4546 case 0x0112: return "WM_SYSCOMMAND";
4547 case 0x0113: return "WM_TIMER";
4548 case 0x0114: return "WM_HSCROLL";
4549 case 0x0115: return "WM_VSCROLL";
4550 case 0x0116: return "WM_INITMENU";
4551 case 0x0117: return "WM_INITMENUPOPUP";
4552 case 0x011F: return "WM_MENUSELECT";
4553 case 0x0120: return "WM_MENUCHAR";
4554 case 0x0121: return "WM_ENTERIDLE";
4555 case 0x0200: return "WM_MOUSEMOVE";
4556 case 0x0201: return "WM_LBUTTONDOWN";
4557 case 0x0202: return "WM_LBUTTONUP";
4558 case 0x0203: return "WM_LBUTTONDBLCLK";
4559 case 0x0204: return "WM_RBUTTONDOWN";
4560 case 0x0205: return "WM_RBUTTONUP";
4561 case 0x0206: return "WM_RBUTTONDBLCLK";
4562 case 0x0207: return "WM_MBUTTONDOWN";
4563 case 0x0208: return "WM_MBUTTONUP";
4564 case 0x0209: return "WM_MBUTTONDBLCLK";
4565 case 0x0210: return "WM_PARENTNOTIFY";
4566 case 0x0220: return "WM_MDICREATE";
4567 case 0x0221: return "WM_MDIDESTROY";
4568 case 0x0222: return "WM_MDIACTIVATE";
4569 case 0x0223: return "WM_MDIRESTORE";
4570 case 0x0224: return "WM_MDINEXT";
4571 case 0x0225: return "WM_MDIMAXIMIZE";
4572 case 0x0226: return "WM_MDITILE";
4573 case 0x0227: return "WM_MDICASCADE";
4574 case 0x0228: return "WM_MDIICONARRANGE";
4575 case 0x0229: return "WM_MDIGETACTIVE";
4576 case 0x0230: return "WM_MDISETMENU";
4577 case 0x0233: return "WM_DROPFILES";
4578 case 0x0300: return "WM_CUT";
4579 case 0x0301: return "WM_COPY";
4580 case 0x0302: return "WM_PASTE";
4581 case 0x0303: return "WM_CLEAR";
4582 case 0x0304: return "WM_UNDO";
4583 case 0x0305: return "WM_RENDERFORMAT";
4584 case 0x0306: return "WM_RENDERALLFORMATS";
4585 case 0x0307: return "WM_DESTROYCLIPBOARD";
4586 case 0x0308: return "WM_DRAWCLIPBOARD";
4587 case 0x0309: return "WM_PAINTCLIPBOARD";
4588 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4589 case 0x030B: return "WM_SIZECLIPBOARD";
4590 case 0x030C: return "WM_ASKCBFORMATNAME";
4591 case 0x030D: return "WM_CHANGECBCHAIN";
4592 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4593 case 0x030F: return "WM_QUERYNEWPALETTE";
4594 case 0x0310: return "WM_PALETTEISCHANGING";
4595 case 0x0311: return "WM_PALETTECHANGED";
4597 static char s_szBuf
[128];
4598 sprintf(s_szBuf
, "<unknown message = %d>", message
);