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"
49 #include "wx/msw/private.h"
63 #include <wx/msw/gnuwin32/extra.h>
82 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
84 wxMenu
*wxCurrentPopupMenu
= NULL
;
85 extern wxList wxPendingDelete
;
87 void wxRemoveHandleAssociation(wxWindow
*win
);
88 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
89 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
91 #if !USE_SHARED_LIBRARY
92 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
94 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
95 EVT_CHAR(wxWindow::OnChar
)
96 EVT_SIZE(wxWindow::OnSize
)
97 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
98 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
99 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
100 EVT_IDLE(wxWindow::OnIdle
)
105 // Find an item given the MS Windows id
106 wxWindow
*wxWindow::FindItem(const int id
) const
110 wxNode
*current
= GetChildren()->First();
113 wxWindow
*childWin
= (wxWindow
*)current
->Data();
115 wxWindow
*wnd
= childWin
->FindItem(id
) ;
119 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
121 wxControl
*item
= (wxControl
*)childWin
;
122 if (item
->m_windowId
== id
)
126 // In case it's a 'virtual' control (e.g. radiobox)
127 if (item
->GetSubcontrols().Member((wxObject
*)id
))
131 current
= current
->Next();
136 // Find an item given the MS Windows handle
137 wxWindow
*wxWindow::FindItemByHWND(const WXHWND hWnd
, bool controlOnly
) const
141 wxNode
*current
= GetChildren()->First();
144 wxObject
*obj
= (wxObject
*)current
->Data() ;
145 // Do a recursive search.
146 wxWindow
*parent
= (wxWindow
*)obj
;
147 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
151 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
153 wxWindow
*item
= (wxWindow
*)current
->Data();
154 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
158 if ( item
->ContainsHWND(hWnd
) )
162 current
= current
->Next();
167 // Default command handler
168 bool wxWindow::MSWCommand(const WXUINT
WXUNUSED(param
), const WXWORD
WXUNUSED(id
))
173 bool wxWindow::MSWNotify(const WXWPARAM
WXUNUSED(wParam
), const WXLPARAM
WXUNUSED(lParam
))
178 void wxWindow::PreDelete(const WXHDC
WXUNUSED(dc
))
182 WXHWND
wxWindow::GetHWND(void) const
184 return (WXHWND
) m_hWnd
;
187 void wxWindow::SetHWND(WXHWND hWnd
)
193 wxWindow::wxWindow(void)
199 m_windowParent
= NULL
;
200 m_windowEventHandler
= this;
202 m_windowCursor
= *wxSTANDARD_CURSOR
;
203 m_children
= new wxList
;
204 m_doubleClickAllowed
= 0 ;
205 m_winCaptured
= FALSE
;
206 m_constraints
= NULL
;
207 m_constraintsInvolvedIn
= NULL
;
208 m_windowSizer
= NULL
;
209 m_sizerParent
= NULL
;
210 m_autoLayout
= FALSE
;
211 m_windowValidator
= NULL
;
216 m_caretWidth
= 0; m_caretHeight
= 0;
217 m_caretEnabled
= FALSE
;
218 m_caretShown
= FALSE
;
226 m_isBeingDeleted
= FALSE
;
233 m_defaultItem
= NULL
;
235 wxSystemSettings settings
;
237 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
238 m_foregroundColour
= *wxBLACK
;
239 m_defaultForegroundColour
= *wxBLACK
;
240 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
243 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
244 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
251 m_acceleratorTable
= 0;
256 m_backgroundTransparent
= FALSE
;
258 m_lastXPos
= (float)-1.0;
259 m_lastYPos
= (float)-1.0;
263 #if USE_DRAG_AND_DROP
264 m_pDropTarget
= NULL
;
269 wxWindow::~wxWindow(void)
271 m_isBeingDeleted
= TRUE
;
273 // JACS - if behaviour is odd, restore this
274 // to the start of ~wxWindow. Vadim has changed
275 // it to nearer the end. Unsure of side-effects
276 // e.g. when deleting associated global data.
277 // Restore old Window proc, if required
280 // Have to delete constraints/sizer FIRST otherwise
281 // sizers may try to look at deleted windows as they
282 // delete themselves.
284 DeleteRelatedConstraints();
287 // This removes any dangling pointers to this window
288 // in other windows' constraintsInvolvedIn lists.
289 UnsetConstraints(m_constraints
);
290 delete m_constraints
;
291 m_constraints
= NULL
;
295 delete m_windowSizer
;
296 m_windowSizer
= NULL
;
298 // If this is a child of a sizer, remove self from parent
300 m_sizerParent
->RemoveChild((wxWindow
*)this);
304 MSWDetachWindowMenu();
306 // TODO for backward compatibility
311 HWND hWnd
= (HWND
) GetHWND();
312 HDC dc
= ::GetDC(hWnd
);
313 m_windowDC
->SelectOldObjects (dc
);
320 m_windowParent
->RemoveChild(this);
325 ::DestroyWindow((HWND
)m_hWnd
);
327 wxRemoveHandleAssociation(this);
332 GlobalFree((HGLOBAL
) m_globalHandle
);
340 // Just in case the window has been Closed, but
341 // we're then deleting immediately: don't leave
342 // dangling pointers.
343 wxPendingDelete
.DeleteObject(this);
345 // Just in case we've loaded a top-level window via
346 // wxWindow::LoadNativeDialog but we weren't a dialog
348 wxTopLevelWindows
.DeleteObject(this);
350 // if (GetFont() && GetFont()->Ok())
351 // GetFont()->ReleaseResource();
353 if ( m_windowValidator
)
354 delete m_windowValidator
;
356 // Restore old Window proc, if required
357 // and remove hWnd <-> wxWindow association
361 // Destroy the window (delayed, if a managed window)
362 bool wxWindow::Destroy(void)
368 extern char wxCanvasClassName
[];
371 bool wxWindow::Create(wxWindow
*parent
, const wxWindowID id
,
375 const wxString
& name
)
378 m_isBeingDeleted
= FALSE
;
382 m_windowParent
= NULL
;
383 m_windowEventHandler
= this;
384 // m_windowFont = NULL;
385 // We don't wish internal (potentially transient) fonts to be found
387 // wxTheFontList->RemoveFont(& m_windowFont);
389 m_windowCursor
= *wxSTANDARD_CURSOR
;
390 m_doubleClickAllowed
= 0 ;
391 m_winCaptured
= FALSE
;
392 m_constraints
= NULL
;
393 m_constraintsInvolvedIn
= NULL
;
394 m_windowSizer
= NULL
;
395 m_sizerParent
= NULL
;
396 m_autoLayout
= FALSE
;
397 m_windowValidator
= NULL
;
398 #if USE_DRAG_AND_DROP
399 m_pDropTarget
= NULL
;
405 m_caretWidth
= 0; m_caretHeight
= 0;
406 m_caretEnabled
= FALSE
;
407 m_caretShown
= FALSE
;
420 m_defaultItem
= NULL
;
421 m_windowParent
= NULL
;
422 // m_windowDC = NULL;
423 m_mouseInWindow
= FALSE
;
427 if (parent
) parent
->AddChild(this);
433 m_acceleratorTable
= 0;
438 m_backgroundTransparent
= FALSE
;
440 m_lastXPos
= (float)-1.0;
441 m_lastYPos
= (float)-1.0;
448 m_windowId
= (int)NewControlId();
457 wxSystemSettings settings
;
459 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
460 m_foregroundColour
= *wxBLACK
;
461 m_defaultForegroundColour
= *wxBLACK
;
462 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
464 m_defaultBackgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
465 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
468 m_windowStyle
= style
;
471 if (style
& wxBORDER
)
472 msflags
|= WS_BORDER
;
473 if (style
& wxTHICK_FRAME
)
474 msflags
|= WS_THICKFRAME
;
476 msflags
|= WS_CHILD
| WS_VISIBLE
;
477 if (style
& wxCLIP_CHILDREN
)
478 msflags
|= WS_CLIPCHILDREN
;
481 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
483 // Even with extended styles, need to combine with WS_BORDER
484 // for them to look right.
485 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
486 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
487 msflags
|= WS_BORDER
;
489 m_mouseInWindow
= FALSE
;
492 m_windowId
= (int)NewControlId();
496 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
502 void wxWindow::SetFocus(void)
504 HWND hWnd
= (HWND
) GetHWND();
509 void wxWindow::Enable(const bool enable
)
511 m_winEnabled
= enable
;
512 HWND hWnd
= (HWND
) GetHWND();
514 ::EnableWindow(hWnd
, (BOOL
)enable
);
517 void wxWindow::CaptureMouse(void)
519 HWND hWnd
= (HWND
) GetHWND();
520 if (hWnd
&& !m_winCaptured
)
523 m_winCaptured
= TRUE
;
527 void wxWindow::ReleaseMouse(void)
532 m_winCaptured
= FALSE
;
536 // Push/pop event handler (i.e. allow a chain of event handlers
538 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
540 handler
->SetNextHandler(GetEventHandler());
541 SetEventHandler(handler
);
544 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
546 if ( GetEventHandler() )
548 wxEvtHandler
*handlerA
= GetEventHandler();
549 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
550 handlerA
->SetNextHandler(NULL
);
551 SetEventHandler(handlerB
);
564 #if USE_DRAG_AND_DROP
566 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
568 if ( m_pDropTarget
!= 0 ) {
569 m_pDropTarget
->Revoke(m_hWnd
);
570 delete m_pDropTarget
;
573 m_pDropTarget
= pDropTarget
;
574 if ( m_pDropTarget
!= 0 )
575 m_pDropTarget
->Register(m_hWnd
);
580 //old style file-manager drag&drop support
581 // I think we should retain the old-style
582 // DragAcceptFiles in parallel with SetDropTarget.
584 void wxWindow::DragAcceptFiles(const bool accept
)
586 HWND hWnd
= (HWND
) GetHWND();
588 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
592 void wxWindow::GetSize(int *x
, int *y
) const
594 HWND hWnd
= (HWND
) GetHWND();
596 GetWindowRect(hWnd
, &rect
);
597 *x
= rect
.right
- rect
.left
;
598 *y
= rect
.bottom
- rect
.top
;
601 void wxWindow::GetPosition(int *x
, int *y
) const
603 HWND hWnd
= (HWND
) GetHWND();
606 hParentWnd
= (HWND
) GetParent()->GetHWND();
609 GetWindowRect(hWnd
, &rect
);
611 // Since we now have the absolute screen coords,
612 // if there's a parent we must subtract its top left corner
618 ::ScreenToClient(hParentWnd
, &point
);
624 void wxWindow::ScreenToClient(int *x
, int *y
) const
626 HWND hWnd
= (HWND
) GetHWND();
630 ::ScreenToClient(hWnd
, &pt
);
636 void wxWindow::ClientToScreen(int *x
, int *y
) const
638 HWND hWnd
= (HWND
) GetHWND();
642 ::ClientToScreen(hWnd
, &pt
);
648 void wxWindow::SetCursor(const wxCursor
& cursor
)
650 m_windowCursor
= cursor
;
651 if (m_windowCursor
.Ok())
653 HWND hWnd
= (HWND
) GetHWND();
655 // Change the cursor NOW if we're within the correct window
657 ::GetCursorPos(&point
);
660 ::GetWindowRect(hWnd
, &rect
);
662 if (::PtInRect(&rect
, point
) && !wxIsBusy())
663 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
666 // This will cause big reentrancy problems if wxFlushEvents is implemented.
668 // return old_cursor;
672 // Get size *available for subwindows* i.e. excluding menu bar etc.
673 // For XView, this is the same as GetSize
674 void wxWindow::GetClientSize(int *x
, int *y
) const
676 HWND hWnd
= (HWND
) GetHWND();
678 GetClientRect(hWnd
, &rect
);
683 void wxWindow::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
685 int currentX
, currentY
;
686 GetPosition(¤tX
, ¤tY
);
687 int actualWidth
= width
;
688 int actualHeight
= height
;
691 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
693 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
696 int currentW
,currentH
;
697 GetSize(¤tW
, ¤tH
);
699 actualWidth
= currentW
;
701 actualHeight
= currentH
;
703 HWND hWnd
= (HWND
) GetHWND();
705 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
707 /* Not needed? should be called anyway via MoveWindow
708 if (!(width == -1) && (height == -1))
710 #if WXWIN_COMPATIBILITY
711 GetEventHandler()->OldOnSize(width, height);
713 wxSizeEvent event(wxSize(width, height), m_windowId);
714 event.eventObject = this;
715 GetEventHandler()->ProcessEvent(event);
721 void wxWindow::SetClientSize(const int width
, const int height
)
723 wxWindow
*parent
= GetParent();
724 HWND hWnd
= (HWND
) GetHWND();
725 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
728 GetClientRect(hWnd
, &rect
);
731 GetWindowRect(hWnd
, &rect2
);
733 // Find the difference between the entire window (title bar and all)
734 // and the client area; add this to the new client size to move the
736 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
737 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
739 // If there's a parent, must subtract the parent's top left corner
740 // since MoveWindow moves relative to the parent
743 point
.x
= rect2
.left
;
747 ::ScreenToClient(hParentWnd
, &point
);
750 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
751 #if WXWIN_COMPATIBILITY
752 GetEventHandler()->OldOnSize(width
, height
);
754 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
755 event
.m_eventObject
= this;
756 GetEventHandler()->ProcessEvent(event
);
760 bool wxWindow::Show(const bool show
)
762 HWND hWnd
= (HWND
) GetHWND();
768 ShowWindow(hWnd
, (BOOL
)cshow
);
771 BringWindowToTop(hWnd
);
772 // Next line causes a crash on NT, apparently.
773 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
778 bool wxWindow::IsShown(void) const
780 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
783 int wxWindow::GetCharHeight(void) const
785 TEXTMETRIC lpTextMetric
;
786 HWND hWnd
= (HWND
) GetHWND();
787 HDC dc
= ::GetDC(hWnd
);
789 GetTextMetrics(dc
, &lpTextMetric
);
790 ::ReleaseDC(hWnd
, dc
);
792 return lpTextMetric
.tmHeight
;
795 int wxWindow::GetCharWidth(void) const
797 TEXTMETRIC lpTextMetric
;
798 HWND hWnd
= (HWND
) GetHWND();
799 HDC dc
= ::GetDC(hWnd
);
801 GetTextMetrics(dc
, &lpTextMetric
);
802 ::ReleaseDC(hWnd
, dc
);
804 return lpTextMetric
.tmAveCharWidth
;
807 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
808 int *descent
, int *externalLeading
, const wxFont
*theFont
, const bool) const
810 wxFont
*fontToUse
= (wxFont
*)theFont
;
812 fontToUse
= (wxFont
*) & m_windowFont
;
814 HWND hWnd
= (HWND
) GetHWND();
815 HDC dc
= ::GetDC(hWnd
);
819 if (fontToUse
&& fontToUse
->Ok())
821 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
822 was
= SelectObject(dc
,fnt
) ;
827 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
828 GetTextMetrics(dc
, &tm
);
830 if (fontToUse
&& fnt
&& was
)
831 SelectObject(dc
,was
) ;
837 if (descent
) *descent
= tm
.tmDescent
;
838 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
841 // fontToUse->ReleaseResource();
844 #if WXWIN_COMPATIBILITY
845 void wxWindow::GetTextExtent(const wxString
& string
, float *x
, float *y
,
847 float *externalLeading
,
848 const wxFont
*theFont
, const bool use16
) const
850 int x1
, y1
, descent1
, externalLeading1
;
851 GetTextExtent(string
, &x1
, &y1
, &descent1
, &externalLeading1
, theFont
, use16
);
855 if ( externalLeading
)
856 *externalLeading
= externalLeading1
;
860 void wxWindow::Refresh(const bool eraseBack
, const wxRectangle
*rect
)
862 HWND hWnd
= (HWND
) GetHWND();
868 mswRect
.left
= rect
->x
;
869 mswRect
.top
= rect
->y
;
870 mswRect
.right
= rect
->x
+ rect
->width
;
871 mswRect
.bottom
= rect
->y
+ rect
->height
;
873 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
876 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
880 // Hook for new window just as it's being created,
881 // when the window isn't yet associated with the handle
882 wxWindow
*wxWndHook
= NULL
;
885 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
887 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
889 if (!wnd
&& wxWndHook
)
891 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
894 wnd
->m_hWnd
= (WXHWND
) hWnd
;
897 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
899 // Stop right here if we don't have a valid handle
900 // in our wxWnd object.
901 if (wnd
&& !wnd
->m_hWnd
) {
902 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
903 wnd
->m_hWnd
= (WXHWND
) hWnd
;
904 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
910 wnd
->m_lastMsg
= message
;
911 wnd
->m_lastWParam
= wParam
;
912 wnd
->m_lastLParam
= lParam
;
915 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
917 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
920 // Should probably have a test for 'genuine' NT
921 #if defined(__WIN32__)
922 #define DIMENSION_TYPE short
924 #define DIMENSION_TYPE int
927 // Main Windows 3 window proc
928 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
939 case WM_QUERYDRAGICON
:
943 case WM_RBUTTONDBLCLK
:
946 case WM_MBUTTONDBLCLK
:
949 case WM_LBUTTONDBLCLK
:
955 case WM_INITMENUPOPUP
:
960 case WM_CHAR
: // Always an ASCII character
965 case WM_CTLCOLORLISTBOX
:
966 case WM_CTLCOLORMSGBOX
:
967 case WM_CTLCOLORSCROLLBAR
:
968 case WM_CTLCOLORSTATIC
:
969 case WM_CTLCOLOREDIT
:
970 case WM_SYSCOLORCHANGE
:
974 case WM_QUERYENDSESSION
:
976 case WM_GETMINMAXINFO
:
977 return MSWDefWindowProc(message
, wParam
, lParam
);
982 HWND hWnd
= (HWND
)m_hWnd
;
989 WORD state
= LOWORD(wParam
);
990 WORD minimized
= HIWORD(wParam
);
991 HWND hwnd
= (HWND
)lParam
;
993 WORD state
= (WORD
)wParam
;
994 WORD minimized
= LOWORD(lParam
);
995 HWND hwnd
= (HWND
)HIWORD(lParam
);
997 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
1003 HWND hwnd
= (HWND
)wParam
;
1004 // return OnSetFocus(hwnd);
1006 if (MSWOnSetFocus((WXHWND
) hwnd
))
1008 else return MSWDefWindowProc(message
, wParam
, lParam
);
1013 HWND hwnd
= (HWND
)lParam
;
1014 // return OnKillFocus(hwnd);
1015 if (MSWOnKillFocus((WXHWND
) hwnd
))
1018 return MSWDefWindowProc(message
, wParam
, lParam
);
1023 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
1029 MSWOnShow((wParam
!= 0), (int) lParam
);
1036 else return MSWDefWindowProc(message
, wParam
, lParam
);
1039 case WM_QUERYDRAGICON
:
1042 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1044 else return MSWDefWindowProc(message
, wParam
, lParam
);
1050 int width
= LOWORD(lParam
);
1051 int height
= HIWORD(lParam
);
1052 MSWOnSize(width
, height
, wParam
);
1056 case WM_WINDOWPOSCHANGING
:
1058 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1059 MSWOnWindowPosChanging((void *)pos
);
1063 case WM_RBUTTONDOWN
:
1065 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1066 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1067 MSWOnRButtonDown(x
, y
, wParam
);
1072 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1073 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1074 MSWOnRButtonUp(x
, y
, wParam
);
1077 case WM_RBUTTONDBLCLK
:
1079 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1080 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1081 MSWOnRButtonDClick(x
, y
, wParam
);
1084 case WM_MBUTTONDOWN
:
1086 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1087 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1088 MSWOnMButtonDown(x
, y
, wParam
);
1093 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1094 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1095 MSWOnMButtonUp(x
, y
, wParam
);
1098 case WM_MBUTTONDBLCLK
:
1100 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1101 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1102 MSWOnMButtonDClick(x
, y
, wParam
);
1105 case WM_LBUTTONDOWN
:
1107 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1108 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1109 MSWOnLButtonDown(x
, y
, wParam
);
1114 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1115 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1116 MSWOnLButtonUp(x
, y
, wParam
);
1119 case WM_LBUTTONDBLCLK
:
1121 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1122 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1123 MSWOnLButtonDClick(x
, y
, wParam
);
1128 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1129 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1130 MSWOnMouseMove(x
, y
, wParam
);
1133 case MM_JOY1BUTTONDOWN
:
1135 int x
= LOWORD(lParam
);
1136 int y
= HIWORD(lParam
);
1137 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1140 case MM_JOY2BUTTONDOWN
:
1142 int x
= LOWORD(lParam
);
1143 int y
= HIWORD(lParam
);
1144 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1147 case MM_JOY1BUTTONUP
:
1149 int x
= LOWORD(lParam
);
1150 int y
= HIWORD(lParam
);
1151 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1154 case MM_JOY2BUTTONUP
:
1156 int x
= LOWORD(lParam
);
1157 int y
= HIWORD(lParam
);
1158 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1163 int x
= LOWORD(lParam
);
1164 int y
= HIWORD(lParam
);
1165 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1170 int x
= LOWORD(lParam
);
1171 int y
= HIWORD(lParam
);
1172 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1177 int z
= LOWORD(lParam
);
1178 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1183 int z
= LOWORD(lParam
);
1184 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1191 else return MSWDefWindowProc(message
, wParam
, lParam
);
1196 return MSWOnSysCommand(wParam
, lParam
);
1202 WORD id
= LOWORD(wParam
);
1203 HWND hwnd
= (HWND
)lParam
;
1204 WORD cmd
= HIWORD(wParam
);
1206 WORD id
= (WORD
)wParam
;
1207 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1208 WORD cmd
= HIWORD(lParam
);
1210 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1211 return MSWDefWindowProc(message
, wParam
, lParam
);
1214 #if defined(__WIN95__)
1217 if (!MSWOnNotify(wParam
, lParam
))
1218 return MSWDefWindowProc(message
, wParam
, lParam
);
1225 WORD flags
= HIWORD(wParam
);
1226 HMENU sysmenu
= (HMENU
)lParam
;
1228 WORD flags
= LOWORD(lParam
);
1229 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1231 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1234 case WM_INITMENUPOPUP
:
1236 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1241 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1244 case WM_MEASUREITEM
:
1246 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1252 if (wParam
== VK_SHIFT
)
1255 else if (wParam
== VK_CONTROL
)
1258 // Avoid duplicate messages to OnChar
1259 else if ((wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) && (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) && (wParam
!= VK_TAB
))
1261 MSWOnChar((WORD
)wParam
, lParam
);
1262 if (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
)
1272 // VZ: WM_KEYUP not processed
1273 case WM_CHAR
: // Always an ASCII character
1275 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1282 WORD code
= LOWORD(wParam
);
1283 WORD pos
= HIWORD(wParam
);
1284 HWND control
= (HWND
)lParam
;
1286 WORD code
= (WORD
)wParam
;
1287 WORD pos
= LOWORD(lParam
);
1288 HWND control
= (HWND
)HIWORD(lParam
);
1290 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1296 WORD code
= LOWORD(wParam
);
1297 WORD pos
= HIWORD(wParam
);
1298 HWND control
= (HWND
)lParam
;
1300 WORD code
= (WORD
)wParam
;
1301 WORD pos
= LOWORD(lParam
);
1302 HWND control
= (HWND
)HIWORD(lParam
);
1304 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1308 case WM_CTLCOLORBTN
:
1310 int nCtlColor
= CTLCOLOR_BTN
;
1311 HWND control
= (HWND
)lParam
;
1312 HDC pDC
= (HDC
)wParam
;
1313 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1314 message
, wParam
, lParam
);
1317 case WM_CTLCOLORDLG
:
1319 int nCtlColor
= CTLCOLOR_DLG
;
1320 HWND control
= (HWND
)lParam
;
1321 HDC pDC
= (HDC
)wParam
;
1322 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1323 message
, wParam
, lParam
);\
1326 case WM_CTLCOLORLISTBOX
:
1328 int nCtlColor
= CTLCOLOR_LISTBOX
;
1329 HWND control
= (HWND
)lParam
;
1330 HDC pDC
= (HDC
)wParam
;
1331 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1332 message
, wParam
, lParam
);
1335 case WM_CTLCOLORMSGBOX
:
1337 int nCtlColor
= CTLCOLOR_MSGBOX
;
1338 HWND control
= (HWND
)lParam
;
1339 HDC pDC
= (HDC
)wParam
;
1340 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1341 message
, wParam
, lParam
);
1344 case WM_CTLCOLORSCROLLBAR
:
1346 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1347 HWND control
= (HWND
)lParam
;
1348 HDC pDC
= (HDC
)wParam
;
1349 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1350 message
, wParam
, lParam
);
1353 case WM_CTLCOLORSTATIC
:
1355 int nCtlColor
= CTLCOLOR_STATIC
;
1356 HWND control
= (HWND
)lParam
;
1357 HDC pDC
= (HDC
)wParam
;
1358 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1359 message
, wParam
, lParam
);
1362 case WM_CTLCOLOREDIT
:
1364 int nCtlColor
= CTLCOLOR_EDIT
;
1365 HWND control
= (HWND
)lParam
;
1366 HDC pDC
= (HDC
)wParam
;
1367 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1368 message
, wParam
, lParam
);
1374 HWND control
= (HWND
)LOWORD(lParam
);
1375 int nCtlColor
= (int)HIWORD(lParam
);
1376 HDC pDC
= (HDC
)wParam
;
1377 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1378 message
, wParam
, lParam
);
1382 case WM_SYSCOLORCHANGE
:
1384 // Return value of 0 means, we processed it.
1385 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1388 return MSWDefWindowProc(message
, wParam
, lParam
);
1393 // Prevents flicker when dragging
1394 if (IsIconic(hWnd
)) return 1;
1398 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1399 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1403 case WM_MDIACTIVATE
:
1406 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1407 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1408 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1409 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1411 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1412 (HWND
)HIWORD(lParam
));
1417 MSWOnDropFiles(wParam
);
1422 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1425 case WM_QUERYENDSESSION
:
1427 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1428 return MSWOnClose();
1440 case WM_GETMINMAXINFO
:
1442 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1443 if (m_minSizeX
!= -1)
1444 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1445 if (m_minSizeY
!= -1)
1446 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1447 if (m_maxSizeX
!= -1)
1448 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1449 if (m_maxSizeY
!= -1)
1450 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1451 return MSWDefWindowProc(message
, wParam
, lParam
);
1459 __ddeUnblock(hWnd, wParam);
1463 case ASYNC_SELECT_MESSAGE:
1464 return ddeWindowProc(hWnd,message,wParam,lParam);
1469 return MSWDefWindowProc(message
, wParam
, lParam
);
1471 return 0; // Success: we processed this command.
1474 // Dialog window proc
1475 LONG APIENTRY _EXPORT
1476 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1481 wxList
*wxWinHandleList
= NULL
;
1482 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1484 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1487 return (wxWindow
*)node
->Data();
1490 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1492 // adding NULL hWnd is (first) surely a result of an error and
1493 // (secondly) breaks menu command processing
1494 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1496 if ( !wxWinHandleList
->Find((long)hWnd
) )
1497 wxWinHandleList
->Append((long)hWnd
, win
);
1500 void wxRemoveHandleAssociation(wxWindow
*win
)
1502 wxWinHandleList
->DeleteObject(win
);
1505 // Default destroyer - override if you destroy it in some other way
1506 // (e.g. with MDI child windows)
1507 void wxWindow::MSWDestroyWindow(void)
1512 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1514 MSWDetachWindowMenu();
1515 // SetWindowLong(handle, 0, (long)0);
1516 HWND oldHandle
= handle
;
1519 ::DestroyWindow(oldHandle
);
1521 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1522 // or when Windows HWND is deleted if MDI parent or
1527 ::DestroyMenu(m_hMenu);
1534 void wxWindow::MSWCreate(const int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1535 const int x
, const int y
, const int width
, const int height
,
1536 const WXDWORD style
, const char *dialog_template
, const WXDWORD extendedStyle
)
1538 bool is_dialog
= (dialog_template
!= NULL
);
1539 int x1
= CW_USEDEFAULT
;
1541 int width1
= CW_USEDEFAULT
;
1544 // Find parent's size, if it exists, to set up a possible default
1545 // panel size the size of the parent window
1549 // Was GetWindowRect: JACS 5/5/95
1550 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1552 width1
= parent_rect
.right
- parent_rect
.left
;
1553 height1
= parent_rect
.bottom
- parent_rect
.top
;
1558 if (width
> -1) width1
= width
;
1559 if (height
> -1) height1
= height
;
1561 HWND hParent
= NULL
;
1563 hParent
= (HWND
) parent
->GetHWND();
1569 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1570 // other compilers???
1571 // VZ: it's always needed for Win16 and never for Win32
1573 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1574 (DLGPROC
)wxDlgProc
);
1576 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1578 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1583 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1584 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1585 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1590 if (style
& WS_CHILD
)
1595 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1600 // hParent, NULL, wxGetInstance(),
1601 hParent
, (HMENU
)controlId
, wxGetInstance(),
1607 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1610 "Fatal wxWindows Error");
1614 wxWinHandleList
->Append((long)m_hWnd
, this);
1617 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1621 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1625 bool wxWindow::MSWOnClose(void)
1628 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1633 bool wxWindow::MSWOnDestroy(void)
1636 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1638 // delete our drop target if we've got one
1639 #if USE_DRAG_AND_DROP
1640 if ( m_pDropTarget
!= NULL
) {
1641 m_pDropTarget
->Revoke(m_hWnd
);
1643 delete m_pDropTarget
;
1644 m_pDropTarget
= NULL
;
1651 // Deal with child commands from buttons etc.
1653 bool wxWindow::MSWOnNotify(const WXWPARAM wParam
, const WXLPARAM lParam
)
1655 #if defined(__WIN95__)
1656 // Find a child window to send the notification to, e.g. a toolbar.
1657 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1658 // handle of the toolbar; it's probably the handle of the tooltip
1659 // window (anyway, it's parent is also the toolbar's parent).
1660 // So, since we don't know which hWnd or wxWindow originated the
1661 // WM_NOTIFY, we'll need to go through all the children of this window
1662 // trying out MSWNotify.
1663 // This won't work now, though, because any number of controls
1664 // could respond to the same generic messages :-(
1666 /* This doesn't work for toolbars, but try for other controls first.
1668 NMHDR
*hdr
= (NMHDR
*)lParam
;
1669 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1670 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1673 return win
->MSWNotify(wParam
, lParam
);
1676 // Rely on MSWNotify to check whether the message
1677 // belongs to the window or not
1678 wxNode
*node
= GetChildren()->First();
1681 wxWindow
*child
= (wxWindow
*)node
->Data();
1682 if ( child
->MSWNotify(wParam
, lParam
) )
1684 node
= node
->Next();
1694 void wxWindow::MSWOnMenuHighlight(const WXWORD
WXUNUSED(item
), const WXWORD
WXUNUSED(flags
), const WXHMENU
WXUNUSED(sysmenu
))
1697 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1701 void wxWindow::MSWOnInitMenuPopup(const WXHMENU menu
, const int pos
, const bool isSystem
)
1704 OldOnInitMenuPopup(pos
);
1707 bool wxWindow::MSWOnActivate(const int state
, const bool WXUNUSED(minimized
), const WXHWND
WXUNUSED(activate
))
1710 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1713 #if WXWIN_COMPATIBILITY
1714 GetEventHandler()->OldOnActivate(((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)));
1716 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1718 event
.m_eventObject
= this;
1719 GetEventHandler()->ProcessEvent(event
);
1724 bool wxWindow::MSWOnSetFocus(const WXHWND
WXUNUSED(hwnd
))
1727 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1730 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1732 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1734 ::ShowCaret((HWND
) GetHWND());
1737 #if WXWIN_COMPATIBILITY
1738 GetEventHandler()->OldOnSetFocus();
1740 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1741 event
.m_eventObject
= this;
1742 GetEventHandler()->ProcessEvent(event
);
1747 bool wxWindow::MSWOnKillFocus(const WXHWND
WXUNUSED(hwnd
))
1750 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1758 #if WXWIN_COMPATIBILITY
1759 GetEventHandler()->OldOnKillFocus();
1761 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1762 event
.m_eventObject
= this;
1763 GetEventHandler()->ProcessEvent(event
);
1768 void wxWindow::MSWOnDropFiles(const WXWPARAM wParam
)
1771 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1774 HANDLE hFilesInfo
= (HANDLE
)wParam
;
1776 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1778 // Get the total number of files dropped
1779 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1784 wxString
*files
= new wxString
[gwFilesDropped
];
1786 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1788 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1789 files
[wIndex
] = wxBuffer
;
1791 DragFinish (hFilesInfo
);
1793 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1794 event
.m_eventObject
= this;
1795 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1797 GetEventHandler()->ProcessEvent(event
);
1802 bool wxWindow::MSWOnDrawItem(const int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1805 if ( id
== 0 ) { // is it a menu item?
1806 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1807 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1808 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1810 // prepare to call OnDrawItem()
1812 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1813 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1814 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1815 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1816 return pMenuItem
->OnDrawItem(
1818 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1819 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1822 #endif // owner-drawn menus
1824 wxWindow
*item
= FindItem(id
);
1825 #if USE_DYNAMIC_CLASSES
1826 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1828 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1835 bool wxWindow::MSWOnMeasureItem(const int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1838 if ( id
== 0 ) { // is it a menu item?
1839 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1840 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1841 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1843 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1844 &pMeasureStruct
->itemHeight
);
1846 #endif // owner-drawn menus
1848 wxWindow
*item
= FindItem(id
);
1849 #if USE_DYNAMIC_CLASSES
1850 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1852 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1859 WXHBRUSH
wxWindow::MSWOnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
1860 const WXUINT message
, const WXWPARAM wParam
, const WXLPARAM lParam
)
1863 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1865 if (nCtlColor
== CTLCOLOR_DLG
)
1867 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1870 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1872 WXHBRUSH hBrush
= 0;
1875 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1877 // I think that even for dialogs, we may need to call DefWindowProc (?)
1878 // Or maybe just rely on the usual default behaviour.
1880 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1885 // Define for each class of dialog and control
1886 WXHBRUSH
wxWindow::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
1887 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1889 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1892 bool wxWindow::MSWOnColorChange(const WXHWND hWnd
, const WXUINT message
, const WXWPARAM wParam
, const WXLPARAM lParam
)
1894 wxSysColourChangedEvent event
;
1895 event
.m_eventObject
= this;
1897 // Check if app handles this.
1898 if (GetEventHandler()->ProcessEvent(event
))
1901 #if WXWIN_COMPATIBILITY
1902 if (GetEventHandler()->OldOnSysColourChange())
1906 // We didn't process it
1910 // Responds to colour changes: passes event on to children.
1911 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1913 wxNode
*node
= GetChildren()->First();
1916 // Only propagate to non-top-level windows
1917 wxWindow
*win
= (wxWindow
*)node
->Data();
1918 if ( win
->GetParent() )
1920 wxSysColourChangedEvent event2
;
1921 event
.m_eventObject
= win
;
1922 win
->GetEventHandler()->ProcessEvent(event2
);
1925 node
= node
->Next();
1929 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1932 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1934 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1937 long wxWindow::Default()
1939 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1943 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1946 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1952 // Suggestion by Andrew Davison to allow
1953 // a panel to accept character input in user edit mode
1955 // OK, what we probably want to do here for wxWin 2.0
1956 // is have a window style to indicate whether the window
1957 // should process dialog-style input, since we can't
1958 // otherwise tell whether it's supposed to do tab traversal
1960 if (GetWindowStyleFlag() & wxTAB_TRAVERSAL
)
1961 return (::IsDialogMessage((HWND
) m_hWnd
, (MSG
*)pMsg
) != 0);
1967 long wxWindow::MSWOnMDIActivate(const long WXUNUSED(flag
), const WXHWND
WXUNUSED(activate
), const WXHWND
WXUNUSED(deactivate
))
1970 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1975 void wxWindow::MSWDetachWindowMenu(void)
1979 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1981 for (i
= 0; i
< N
; i
++)
1984 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1985 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1987 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
1994 bool wxWindow::MSWOnPaint(void)
1996 #if WXWIN_COMPATIBILITY
1997 GetEventHandler()->OldOnPaint();
1999 wxPaintEvent
event(m_windowId
);
2000 event
.m_eventObject
= this;
2001 GetEventHandler()->ProcessEvent(event
);
2008 wxDebugMsg("wxWindow::MSWOnPaint %d\n", m_hWnd
);
2011 HRGN tRgn
=CreateRectRgn(0,0,0,0); //Dummy call to get a handle!
2012 if (GetUpdateRgn(m_hWnd
, tRgn
, FALSE
))
2015 if (GetUpdateRect((HWND
) m_hWnd
, &tRect
, FALSE
))
2019 // Hold a pointer to the dc so long as the OnPaint() message
2020 // is being processed
2021 HDC dc
= BeginPaint(m_hWnd
, &ps
);
2022 bool isPanel
= IsKindOf(CLASSINFO(wxWindow
));
2023 m_paintHDC
= (WXHDC
) dc
;
2024 RECT updateRect1
= ps
.rcPaint
;
2025 m_updateRect
.x
= updateRect1
.left
;
2026 m_updateRect
.y
= updateRect1
.top
;
2027 m_updateRect
.width
= updateRect1
.right
- updateRect1
.left
;
2028 m_updateRect
.height
= updateRect1
.bottom
- updateRect1
.top
;
2030 GetEventHandler()->OldOnPaint();
2033 EndPaint((HWND
) m_hWnd
, &ps
);
2039 // Do default processing
2051 void wxWindow::MSWOnSize(const int w
, const int h
, const WXUINT
WXUNUSED(flag
))
2057 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2064 #if WXWIN_COMPATIBILITY
2065 GetEventHandler()->OldOnSize(w
, h
);
2067 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2068 event
.m_eventObject
= this;
2069 GetEventHandler()->ProcessEvent(event
);
2075 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2080 // Deal with child commands from buttons etc.
2081 bool wxWindow::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND
WXUNUSED(control
))
2084 wxDebugMsg("wxWindow::MSWOnCommand\n");
2086 if (wxCurrentPopupMenu
)
2088 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2089 wxCurrentPopupMenu
= NULL
;
2090 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2095 sprintf(buf
, "Looking for item %d...\n", id
);
2099 wxWindow
*item
= FindItem(id
);
2102 bool value
= item
->MSWCommand(cmd
, id
);
2105 wxDebugMsg("MSWCommand succeeded\n");
2107 wxDebugMsg("MSWCommand failed\n");
2114 wxDebugMsg("Could not find item!\n");
2116 wxDebugMsg("Item ids for this panel:\n");
2118 wxNode
*current
= GetChildren()->First();
2121 wxObject
*obj
= (wxObject
*)current
->Data() ;
2122 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2124 wxControl
*item
= (wxControl
*)current
->Data();
2125 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2128 current
= current
->Next();
2136 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2142 wxMaximizeEvent
event(m_windowId
);
2143 event
.SetEventObject(this);
2144 if (!GetEventHandler()->ProcessEvent(event
))
2152 wxIconizeEvent
event(m_windowId
);
2153 event
.SetEventObject(this);
2154 if (!GetEventHandler()->ProcessEvent(event
))
2166 void wxWindow::MSWOnLButtonDown(const int x
, const int y
, const WXUINT flags
)
2168 #if 0 // defined(__WIN32__) && !defined(WIN95)
2169 // DClick not clean supported on Win3.1, except if someone know
2170 // how to emulate Sleep()...
2171 // This means that your app will receive Down-Up-Dclick sequences
2172 // rather than Dclick
2173 if (m_doubleClickAllowed
)
2175 UINT time
= GetDoubleClickTime() ;
2178 if (PeekMessage(&dummy
,m_hWnd
,
2179 WM_LBUTTONDBLCLK
,WM_LBUTTONDBLCLK
,
2183 PeekMessage(&dummy
,m_hWnd
,WM_LBUTTONUP
,WM_LBUTTONUP
,PM_REMOVE
);
2189 wxMouseEvent
event(wxEVENT_TYPE_LEFT_DOWN
);
2191 event
.m_x
= x
; event
.m_y
= y
;
2192 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2193 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2194 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2195 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2196 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2197 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2198 event
.m_eventObject
= this;
2200 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2201 GetEventHandler()->OldOnMouseEvent(event
);
2204 void wxWindow::MSWOnLButtonUp(const int x
, const int y
, const WXUINT flags
)
2206 wxMouseEvent
event(wxEVENT_TYPE_LEFT_UP
);
2208 event
.m_x
= x
; event
.m_y
= y
;
2209 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2210 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2211 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2212 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2213 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2214 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2215 event
.m_eventObject
= this;
2217 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_UP
;
2219 GetEventHandler()->OldOnMouseEvent(event
);
2222 void wxWindow::MSWOnLButtonDClick(const int x
, const int y
, const WXUINT flags
)
2224 wxMouseEvent
event(wxEVENT_TYPE_LEFT_DCLICK
);
2226 event
.m_x
= x
; event
.m_y
= y
;
2227 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2228 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2229 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2230 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2231 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2232 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2233 event
.m_eventObject
= this;
2235 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DCLICK
;
2237 // if (m_doubleClickAllowed)
2238 GetEventHandler()->OldOnMouseEvent(event
);
2241 void wxWindow::MSWOnMButtonDown(const int x
, const int y
, const WXUINT flags
)
2243 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2244 // DClick not clean supported on Win3.1, except if someone know
2245 // how to emulate Sleep()...
2246 // This means that your app will receive Down-Up-Dclick sequences
2247 // rather than Dclick
2248 if (m_doubleClickAllowed
)
2250 UINT time
= GetDoubleClickTime() ;
2253 if (PeekMessage(&dummy
,m_hWnd
,
2254 WM_MBUTTONDBLCLK
,WM_MBUTTONDBLCLK
,
2258 PeekMessage(&dummy
,m_hWnd
,WM_MBUTTONUP
,WM_MBUTTONUP
,PM_REMOVE
);
2264 wxMouseEvent
event(wxEVENT_TYPE_MIDDLE_DOWN
);
2266 event
.m_x
= x
; event
.m_y
= y
;
2267 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2268 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2269 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2270 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2271 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2272 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2273 event
.m_eventObject
= this;
2275 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_MIDDLE_DOWN
;
2276 GetEventHandler()->OldOnMouseEvent(event
);
2279 void wxWindow::MSWOnMButtonUp(const int x
, const int y
, const WXUINT flags
)
2281 //wxDebugMsg("MButtonUp\n") ;
2282 wxMouseEvent
event(wxEVENT_TYPE_MIDDLE_UP
);
2284 event
.m_x
= x
; event
.m_y
= y
;
2285 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2286 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2287 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2288 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2289 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2290 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2291 event
.m_eventObject
= this;
2293 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_MIDDLE_UP
;
2294 GetEventHandler()->OldOnMouseEvent(event
);
2297 void wxWindow::MSWOnMButtonDClick(const int x
, const int y
, const WXUINT flags
)
2299 wxMouseEvent
event(wxEVENT_TYPE_MIDDLE_DCLICK
);
2301 event
.m_x
= x
; event
.m_y
= y
;
2302 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2303 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2304 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2305 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2306 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2307 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2308 event
.m_eventObject
= this;
2310 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_MIDDLE_DCLICK
;
2311 // if (m_doubleClickAllowed)
2312 GetEventHandler()->OldOnMouseEvent(event
);
2315 void wxWindow::MSWOnRButtonDown(const int x
, const int y
, const WXUINT flags
)
2317 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2318 // DClick not clean supported on Win3.1, except if someone know
2319 // how to emulate Sleep()...
2320 // This means that your app will receive Down-Up-Dclick sequences
2321 // rather than Dclick
2322 if (m_doubleClickAllowed
)
2324 UINT time
= GetDoubleClickTime() ;
2327 if (PeekMessage(&dummy
,m_hWnd
,
2328 WM_RBUTTONDBLCLK
,WM_RBUTTONDBLCLK
,
2332 PeekMessage(&dummy
,m_hWnd
,WM_RBUTTONUP
,WM_RBUTTONUP
,PM_REMOVE
);
2338 wxMouseEvent
event(wxEVENT_TYPE_RIGHT_DOWN
);
2340 event
.m_x
= x
; event
.m_y
= y
;
2341 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2342 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2343 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2344 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2345 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2346 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2347 event
.m_eventObject
= this;
2349 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_DOWN
;
2350 GetEventHandler()->OldOnMouseEvent(event
);
2353 void wxWindow::MSWOnRButtonUp(const int x
, const int y
, const WXUINT flags
)
2355 wxMouseEvent
event(wxEVENT_TYPE_RIGHT_UP
);
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
.m_eventObject
= this;
2364 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2366 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_UP
;
2367 GetEventHandler()->OldOnMouseEvent(event
);
2370 void wxWindow::MSWOnRButtonDClick(const int x
, const int y
, const WXUINT flags
)
2372 wxMouseEvent
event(wxEVENT_TYPE_RIGHT_DCLICK
);
2374 event
.m_x
= x
; event
.m_y
= y
;
2375 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2376 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2377 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2378 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2379 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2380 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2381 event
.m_eventObject
= this;
2383 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_DCLICK
;
2384 // if (m_doubleClickAllowed)
2385 GetEventHandler()->OldOnMouseEvent(event
);
2388 void wxWindow::MSWOnMouseMove(const int x
, const int y
, const WXUINT flags
)
2390 // 'normal' move event...
2391 // Set cursor, but only if we're not in 'busy' mode
2393 // Trouble with this is that it sets the cursor for controls too :-(
2394 if (m_windowCursor
.Ok() && !wxIsBusy())
2395 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2397 if (!m_mouseInWindow
)
2399 // Generate an ENTER event
2400 m_mouseInWindow
= TRUE
;
2401 MSWOnMouseEnter(x
, y
, flags
);
2404 wxMouseEvent
event(wxEVENT_TYPE_MOTION
);
2406 event
.m_x
= x
; event
.m_y
= y
;
2407 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2408 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2409 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2410 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2411 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2412 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2413 event
.m_eventObject
= this;
2415 // Window gets a click down message followed by a mouse move
2416 // message even if position isn't changed! We want to discard
2417 // the trailing move event if x and y are the same.
2418 if ((m_lastEvent
== wxEVENT_TYPE_RIGHT_DOWN
|| m_lastEvent
== wxEVENT_TYPE_LEFT_DOWN
||
2419 m_lastEvent
== wxEVENT_TYPE_MIDDLE_DOWN
) &&
2420 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2422 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2423 m_lastEvent
= wxEVENT_TYPE_MOTION
;
2427 m_lastEvent
= wxEVENT_TYPE_MOTION
;
2428 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2429 GetEventHandler()->OldOnMouseEvent(event
);
2432 void wxWindow::MSWOnMouseEnter(const int x
, const int y
, const WXUINT flags
)
2434 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2436 event
.m_x
= x
; event
.m_y
= y
;
2437 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2438 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2439 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2440 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2441 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2442 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2443 event
.m_eventObject
= this;
2445 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2446 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2447 // No message - ensure we don't try to call the default behaviour accidentally.
2449 GetEventHandler()->ProcessEvent(event
);
2452 void wxWindow::MSWOnMouseLeave(const int x
, const int y
, const WXUINT flags
)
2454 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2456 event
.m_x
= x
; event
.m_y
= y
;
2457 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2458 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2459 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2460 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2461 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2462 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2463 event
.m_eventObject
= this;
2465 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2466 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2467 // No message - ensure we don't try to call the default behaviour accidentally.
2469 GetEventHandler()->ProcessEvent(event
);
2472 void wxWindow::MSWOnChar(const WXWORD wParam
, const WXLPARAM lParam
, const bool isASCII
)
2475 bool tempControlDown
= FALSE
;
2478 // If 1 -> 26, translate to CTRL plus a letter.
2480 if ((id
> 0) && (id
< 27))
2501 tempControlDown
= TRUE
;
2507 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2508 // it's ASCII and will be processed here only when called from
2509 // WM_CHAR (i.e. when isASCII = TRUE)
2515 wxKeyEvent
event(wxEVT_CHAR
);
2516 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2517 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2518 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2519 event
.m_altDown
= TRUE
;
2521 event
.m_eventObject
= this;
2522 event
.m_keyCode
= id
;
2523 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2528 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2532 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2534 #if WXWIN_COMPATIBILITY
2535 GetEventHandler()->OldOnChar(event
);
2537 if (!GetEventHandler()->ProcessEvent(event
))
2543 void wxWindow::MSWOnJoyDown(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2547 if (flags
& JOY_BUTTON1CHG
)
2548 change
= wxJOY_BUTTON1
;
2549 if (flags
& JOY_BUTTON2CHG
)
2550 change
= wxJOY_BUTTON2
;
2551 if (flags
& JOY_BUTTON3CHG
)
2552 change
= wxJOY_BUTTON3
;
2553 if (flags
& JOY_BUTTON4CHG
)
2554 change
= wxJOY_BUTTON4
;
2556 if (flags
& JOY_BUTTON1
)
2557 buttons
|= wxJOY_BUTTON1
;
2558 if (flags
& JOY_BUTTON2
)
2559 buttons
|= wxJOY_BUTTON2
;
2560 if (flags
& JOY_BUTTON3
)
2561 buttons
|= wxJOY_BUTTON3
;
2562 if (flags
& JOY_BUTTON4
)
2563 buttons
|= wxJOY_BUTTON4
;
2565 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2566 event
.SetPosition(wxPoint(x
, y
));
2567 event
.SetEventObject(this);
2569 GetEventHandler()->ProcessEvent(event
);
2572 void wxWindow::MSWOnJoyUp(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2576 if (flags
& JOY_BUTTON1CHG
)
2577 change
= wxJOY_BUTTON1
;
2578 if (flags
& JOY_BUTTON2CHG
)
2579 change
= wxJOY_BUTTON2
;
2580 if (flags
& JOY_BUTTON3CHG
)
2581 change
= wxJOY_BUTTON3
;
2582 if (flags
& JOY_BUTTON4CHG
)
2583 change
= wxJOY_BUTTON4
;
2585 if (flags
& JOY_BUTTON1
)
2586 buttons
|= wxJOY_BUTTON1
;
2587 if (flags
& JOY_BUTTON2
)
2588 buttons
|= wxJOY_BUTTON2
;
2589 if (flags
& JOY_BUTTON3
)
2590 buttons
|= wxJOY_BUTTON3
;
2591 if (flags
& JOY_BUTTON4
)
2592 buttons
|= wxJOY_BUTTON4
;
2594 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2595 event
.SetPosition(wxPoint(x
, y
));
2596 event
.SetEventObject(this);
2598 GetEventHandler()->ProcessEvent(event
);
2601 void wxWindow::MSWOnJoyMove(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2604 if (flags
& JOY_BUTTON1
)
2605 buttons
|= wxJOY_BUTTON1
;
2606 if (flags
& JOY_BUTTON2
)
2607 buttons
|= wxJOY_BUTTON2
;
2608 if (flags
& JOY_BUTTON3
)
2609 buttons
|= wxJOY_BUTTON3
;
2610 if (flags
& JOY_BUTTON4
)
2611 buttons
|= wxJOY_BUTTON4
;
2613 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2614 event
.SetPosition(wxPoint(x
, y
));
2615 event
.SetEventObject(this);
2617 GetEventHandler()->ProcessEvent(event
);
2620 void wxWindow::MSWOnJoyZMove(const int joystick
, const int z
, const WXUINT flags
)
2623 if (flags
& JOY_BUTTON1
)
2624 buttons
|= wxJOY_BUTTON1
;
2625 if (flags
& JOY_BUTTON2
)
2626 buttons
|= wxJOY_BUTTON2
;
2627 if (flags
& JOY_BUTTON3
)
2628 buttons
|= wxJOY_BUTTON3
;
2629 if (flags
& JOY_BUTTON4
)
2630 buttons
|= wxJOY_BUTTON4
;
2632 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2633 event
.SetZPosition(z
);
2634 event
.SetEventObject(this);
2636 GetEventHandler()->ProcessEvent(event
);
2639 void wxWindow::MSWOnVScroll(const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2643 wxWindow
*child
= wxFindWinFromHandle(control
);
2645 child
->MSWOnVScroll(wParam
, pos
, control
);
2649 wxScrollEvent event
;
2650 event
.SetPosition(pos
);
2651 event
.SetOrientation(wxVERTICAL
);
2652 event
.m_eventObject
= this;
2657 event
.m_eventType
= wxEVENT_TYPE_SCROLL_TOP
;
2661 event
.m_eventType
= wxEVENT_TYPE_SCROLL_BOTTOM
;
2665 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEUP
;
2669 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEDOWN
;
2673 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEUP
;
2677 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEDOWN
;
2681 case SB_THUMBPOSITION
:
2682 event
.m_eventType
= wxEVENT_TYPE_SCROLL_THUMBTRACK
;
2690 if (!GetEventHandler()->ProcessEvent(event
))
2691 #if WXWIN_COMPATIBILITY
2692 GetEventHandler()->OldOnScroll(event
);
2698 void wxWindow::MSWOnHScroll( const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2702 wxWindow
*child
= wxFindWinFromHandle(control
);
2704 child
->MSWOnHScroll(wParam
, pos
, control
);
2708 wxScrollEvent event
;
2709 event
.SetPosition(pos
);
2710 event
.SetOrientation(wxHORIZONTAL
);
2711 event
.m_eventObject
= this;
2716 event
.m_eventType
= wxEVENT_TYPE_SCROLL_TOP
;
2720 event
.m_eventType
= wxEVENT_TYPE_SCROLL_BOTTOM
;
2724 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEUP
;
2728 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEDOWN
;
2732 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEUP
;
2736 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEDOWN
;
2740 case SB_THUMBPOSITION
:
2741 event
.m_eventType
= wxEVENT_TYPE_SCROLL_THUMBTRACK
;
2748 if (!GetEventHandler()->ProcessEvent(event
))
2749 #if WXWIN_COMPATIBILITY
2750 GetEventHandler()->OldOnScroll(event
);
2756 void wxWindow::MSWOnShow(bool show
, int status
)
2758 wxShowEvent
event(GetId(), show
);
2759 event
.m_eventObject
= this;
2760 GetEventHandler()->ProcessEvent(event
);
2763 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2765 wxInitDialogEvent
event(GetId());
2766 event
.m_eventObject
= this;
2767 GetEventHandler()->ProcessEvent(event
);
2771 void wxWindow::InitDialog(void)
2773 wxInitDialogEvent
event(GetId());
2774 event
.SetEventObject( this );
2775 GetEventHandler()->ProcessEvent(event
);
2778 // Default init dialog behaviour is to transfer data to window
2779 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2781 TransferDataToWindow();
2784 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2787 HDC dc
= ::GetDC((HWND
) wnd
);
2793 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2795 // the_font->UseResource();
2796 // the_font->RealizeResource();
2797 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2798 was
= SelectObject(dc
,fnt
) ;
2800 GetTextMetrics(dc
, &tm
);
2801 if (the_font
&& fnt
&& was
)
2804 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2806 SelectObject(dc
,was
) ;
2808 ReleaseDC((HWND
)wnd
, dc
);
2809 *x
= tm
.tmAveCharWidth
;
2810 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2813 // the_font->ReleaseResource();
2816 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2817 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2818 int wxCharCodeMSWToWX(int keySym
)
2823 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2824 case VK_BACK
: id
= WXK_BACK
; break;
2825 case VK_TAB
: id
= WXK_TAB
; break;
2826 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2827 case VK_RETURN
: id
= WXK_RETURN
; break;
2828 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2829 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2830 case VK_MENU
: id
= WXK_MENU
; break;
2831 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2832 case VK_SPACE
: id
= WXK_SPACE
; break;
2833 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2834 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2835 case VK_NEXT
: id
= WXK_NEXT
; break;
2836 case VK_END
: id
= WXK_END
; break;
2837 case VK_HOME
: id
= WXK_HOME
; break;
2838 case VK_LEFT
: id
= WXK_LEFT
; break;
2839 case VK_UP
: id
= WXK_UP
; break;
2840 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2841 case VK_DOWN
: id
= WXK_DOWN
; break;
2842 case VK_SELECT
: id
= WXK_SELECT
; break;
2843 case VK_PRINT
: id
= WXK_PRINT
; break;
2844 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2845 case VK_INSERT
: id
= WXK_INSERT
; break;
2846 case VK_DELETE
: id
= WXK_DELETE
; break;
2847 case VK_HELP
: id
= WXK_HELP
; break;
2848 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2849 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2850 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2851 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2852 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2853 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2854 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2855 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2856 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2857 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2858 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2859 case VK_ADD
: id
= WXK_ADD
; break;
2860 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2861 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2862 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2863 case VK_F1
: id
= WXK_F1
; break;
2864 case VK_F2
: id
= WXK_F2
; break;
2865 case VK_F3
: id
= WXK_F3
; break;
2866 case VK_F4
: id
= WXK_F4
; break;
2867 case VK_F5
: id
= WXK_F5
; break;
2868 case VK_F6
: id
= WXK_F6
; break;
2869 case VK_F7
: id
= WXK_F7
; break;
2870 case VK_F8
: id
= WXK_F8
; break;
2871 case VK_F9
: id
= WXK_F9
; break;
2872 case VK_F10
: id
= WXK_F10
; break;
2873 case VK_F11
: id
= WXK_F11
; break;
2874 case VK_F12
: id
= WXK_F12
; break;
2875 case VK_F13
: id
= WXK_F13
; break;
2876 case VK_F14
: id
= WXK_F14
; break;
2877 case VK_F15
: id
= WXK_F15
; break;
2878 case VK_F16
: id
= WXK_F16
; break;
2879 case VK_F17
: id
= WXK_F17
; break;
2880 case VK_F18
: id
= WXK_F18
; break;
2881 case VK_F19
: id
= WXK_F19
; break;
2882 case VK_F20
: id
= WXK_F20
; break;
2883 case VK_F21
: id
= WXK_F21
; break;
2884 case VK_F22
: id
= WXK_F22
; break;
2885 case VK_F23
: id
= WXK_F23
; break;
2886 case VK_F24
: id
= WXK_F24
; break;
2887 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2888 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2897 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2903 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2904 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2905 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2906 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2907 case WXK_MENU
: keySym
= VK_MENU
; break;
2908 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2909 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2910 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2911 case WXK_END
: keySym
= VK_END
; break;
2912 case WXK_HOME
: keySym
= VK_HOME
; break;
2913 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2914 case WXK_UP
: keySym
= VK_UP
; break;
2915 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2916 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2917 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2918 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2919 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2920 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2921 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2922 case WXK_HELP
: keySym
= VK_HELP
; break;
2923 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2924 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2925 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2926 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2927 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2928 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2929 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2930 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2931 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2932 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2933 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2934 case WXK_ADD
: keySym
= VK_ADD
; break;
2935 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2936 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2937 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2938 case WXK_F1
: keySym
= VK_F1
; break;
2939 case WXK_F2
: keySym
= VK_F2
; break;
2940 case WXK_F3
: keySym
= VK_F3
; break;
2941 case WXK_F4
: keySym
= VK_F4
; break;
2942 case WXK_F5
: keySym
= VK_F5
; break;
2943 case WXK_F6
: keySym
= VK_F6
; break;
2944 case WXK_F7
: keySym
= VK_F7
; break;
2945 case WXK_F8
: keySym
= VK_F8
; break;
2946 case WXK_F9
: keySym
= VK_F9
; break;
2947 case WXK_F10
: keySym
= VK_F10
; break;
2948 case WXK_F11
: keySym
= VK_F11
; break;
2949 case WXK_F12
: keySym
= VK_F12
; break;
2950 case WXK_F13
: keySym
= VK_F13
; break;
2951 case WXK_F14
: keySym
= VK_F14
; break;
2952 case WXK_F15
: keySym
= VK_F15
; break;
2953 case WXK_F16
: keySym
= VK_F16
; break;
2954 case WXK_F17
: keySym
= VK_F17
; break;
2955 case WXK_F18
: keySym
= VK_F18
; break;
2956 case WXK_F19
: keySym
= VK_F19
; break;
2957 case WXK_F20
: keySym
= VK_F20
; break;
2958 case WXK_F21
: keySym
= VK_F21
; break;
2959 case WXK_F22
: keySym
= VK_F22
; break;
2960 case WXK_F23
: keySym
= VK_F23
; break;
2961 case WXK_F24
: keySym
= VK_F24
; break;
2962 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2963 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2974 // Caret manipulation
2975 void wxWindow::CreateCaret(const int w
, const int h
)
2979 m_caretEnabled
= TRUE
;
2982 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2987 void wxWindow::ShowCaret(const bool show
)
2992 ::ShowCaret((HWND
) GetHWND());
2994 ::HideCaret((HWND
) GetHWND());
2995 m_caretShown
= show
;
2999 void wxWindow::DestroyCaret(void)
3001 m_caretEnabled
= FALSE
;
3004 void wxWindow::SetCaretPos(const int x
, const int y
)
3006 ::SetCaretPos(x
, y
);
3009 void wxWindow::GetCaretPos(int *x
, int *y
) const
3012 ::GetCaretPos(&point
);
3018 * Update iterator. Use from within OnPaint.
3021 static RECT gs_UpdateRect
;
3023 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
3025 current
= 0; //start somewhere...
3026 #if defined(__WIN32__) && !defined(__win32s__)
3027 rlist
= NULL
; //make sure I don't free randomly
3028 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
3031 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
3032 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
3033 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
3034 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
3039 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
3040 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
3041 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
3042 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
3044 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
3048 wxUpdateIterator::~wxUpdateIterator(void)
3052 if (rlist
) delete (RGNDATA
*) rlist
;
3057 wxUpdateIterator::operator int (void)
3059 if (current
< rects
)
3069 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
3075 void wxUpdateIterator::GetRect(wxRect
*rect
)
3077 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
3078 rect
->x
= mswRect
->left
;
3079 rect
->y
= mswRect
->top
;
3080 rect
->width
= mswRect
->right
- mswRect
->left
;
3081 rect
->height
= mswRect
->bottom
- mswRect
->top
;
3084 int wxUpdateIterator::GetX()
3086 return ((RECT
*)rp
)[current
].left
;
3089 int wxUpdateIterator::GetY()
3091 return ((RECT
*)rp
)[current
].top
;
3094 int wxUpdateIterator::GetW()
3096 return ((RECT
*)rp
)[current
].right
-GetX();
3099 int wxUpdateIterator::GetH()
3101 return ((RECT
*)rp
)[current
].bottom
-GetY();
3104 wxWindow
*wxGetActiveWindow(void)
3106 HWND hWnd
= GetActiveWindow();
3109 return wxFindWinFromHandle((WXHWND
) hWnd
);
3114 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3115 // in active frames and dialogs, regardless of where the focus is.
3116 static HHOOK wxTheKeyboardHook
= 0;
3117 static FARPROC wxTheKeyboardHookProc
= 0;
3118 int APIENTRY _EXPORT
3119 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
3121 void wxSetKeyboardHook(bool doIt
)
3125 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
3126 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
3128 GetCurrentThreadId());
3129 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3136 UnhookWindowsHookEx(wxTheKeyboardHook
);
3137 FreeProcInstance(wxTheKeyboardHookProc
);
3141 int APIENTRY _EXPORT
3142 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
3144 DWORD hiWord
= HIWORD(lParam
);
3145 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3148 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3150 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3151 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3152 event
.m_altDown
= TRUE
;
3154 event
.m_eventObject
= NULL
;
3155 event
.m_keyCode
= id
;
3156 /* begin Albert's fix for control and shift key 26.5 */
3157 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3158 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3159 /* end Albert's fix for control and shift key 26.5 */
3160 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3162 #if WXWIN_COMPATIBILITY
3163 if ( wxTheApp
&& wxTheApp
->OldOnCharHook(event
) )
3166 wxWindow
*win
= wxGetActiveWindow();
3169 if (win
->GetEventHandler()->ProcessEvent(event
))
3174 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3179 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3182 void wxWindow::SetSizeHints(const int minW
, const int minH
, const int maxW
, const int maxH
, const int WXUNUSED(incW
), const int WXUNUSED(incH
))
3190 void wxWindow::Centre(const int direction
)
3192 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3194 wxWindow
*father
= (wxWindow
*)GetParent();
3198 father
->GetClientSize(&panel_width
, &panel_height
);
3199 GetSize(&width
, &height
);
3200 GetPosition(&x
, &y
);
3205 if (direction
& wxHORIZONTAL
)
3206 new_x
= (int)((panel_width
- width
)/2);
3208 if (direction
& wxVERTICAL
)
3209 new_y
= (int)((panel_height
- height
)/2);
3211 SetSize(new_x
, new_y
, -1, -1);
3216 void wxWindow::OnPaint(void)
3218 PaintSelectionHandles();
3222 void wxWindow::WarpPointer (const int x_pos
, const int y_pos
)
3224 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3225 // pixel coordinates, relatives to the canvas -- So, we first need to
3226 // substract origin of the window, then convert to screen position
3228 int x
= x_pos
; int y
= y_pos
;
3229 /* Leave this to the app to decide (and/or wxScrolledWindow)
3230 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3231 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3234 GetWindowRect ((HWND
) GetHWND(), &rect
);
3239 SetCursorPos (x
, y
);
3242 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3245 // Do we have a SetUserScale in wxWindow too, so we can
3246 // get mouse events scaled?
3250 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3251 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3256 bool wxWindow::MSWOnEraseBkgnd (const WXHDC pDC
)
3264 wxEraseEvent
event(m_windowId
, &dc
);
3265 event
.m_eventObject
= this;
3266 if (!GetEventHandler()->ProcessEvent(event
))
3269 dc
.SelectOldObjects(pDC
);
3275 dc
.SelectOldObjects(pDC
);
3278 dc
.SetHDC((WXHDC
) NULL
);
3282 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3285 ::GetClientRect((HWND
) GetHWND(), &rect
);
3287 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3288 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3290 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3291 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3292 ::DeleteObject(hBrush
);
3293 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3295 // Less efficient version (and doesn't account for scrolling)
3297 GetClientSize(& w, & h);
3298 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3299 event.GetDC()->SetBrush(brush);
3300 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3302 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3306 #if WXWIN_COMPATIBILITY
3307 void wxWindow::SetScrollRange(const int orient
, const int range
, const bool refresh
)
3309 #if defined(__WIN95__)
3313 // Try to adjust the range to cope with page size > 1
3314 // - a Windows API quirk
3315 int pageSize
= GetScrollPage(orient
);
3316 if ( pageSize
> 1 && range
> 0)
3318 range1
+= (pageSize
- 1);
3324 if (orient
== wxHORIZONTAL
) {
3330 info
.cbSize
= sizeof(SCROLLINFO
);
3331 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3335 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3337 HWND hWnd
= (HWND
) GetHWND();
3339 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3342 if (orient
== wxHORIZONTAL
)
3347 HWND hWnd
= (HWND
) GetHWND();
3349 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3353 void wxWindow::SetScrollPage(const int orient
, const int page
, const bool refresh
)
3355 #if defined(__WIN95__)
3359 if (orient
== wxHORIZONTAL
) {
3361 m_xThumbSize
= page
;
3364 m_yThumbSize
= page
;
3367 info
.cbSize
= sizeof(SCROLLINFO
);
3370 info
.fMask
= SIF_PAGE
;
3372 HWND hWnd
= (HWND
) GetHWND();
3374 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3376 if (orient
== wxHORIZONTAL
)
3377 m_xThumbSize
= page
;
3379 m_yThumbSize
= page
;
3383 int wxWindow::OldGetScrollRange(const int orient
) const
3386 if (orient
== wxHORIZONTAL
)
3391 #if __WATCOMC__ && defined(__WINDOWS_386__)
3392 short minPos
, maxPos
;
3396 HWND hWnd
= (HWND
) GetHWND();
3399 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3400 #if defined(__WIN95__)
3401 // Try to adjust the range to cope with page size > 1
3402 // - a Windows API quirk
3403 int pageSize
= GetScrollPage(orient
);
3406 maxPos
-= (pageSize
- 1);
3415 int wxWindow::GetScrollPage(const int orient
) const
3417 if (orient
== wxHORIZONTAL
)
3418 return m_xThumbSize
;
3420 return m_yThumbSize
;
3424 int wxWindow::GetScrollPos(const int orient
) const
3427 if (orient
== wxHORIZONTAL
)
3431 HWND hWnd
= (HWND
) GetHWND();
3434 return ::GetScrollPos(hWnd
, wOrient
);
3440 // This now returns the whole range, not just the number
3441 // of positions that we can scroll.
3442 int wxWindow::GetScrollRange(const int orient
) const
3445 if (orient
== wxHORIZONTAL
)
3450 #if __WATCOMC__ && defined(__WINDOWS_386__)
3451 short minPos
, maxPos
;
3455 HWND hWnd
= (HWND
) GetHWND();
3458 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3459 #if defined(__WIN95__)
3460 // Try to adjust the range to cope with page size > 1
3461 // - a Windows API quirk
3462 int pageSize
= GetScrollPage(orient
);
3465 maxPos
-= (pageSize
- 1);
3467 // October 10th: new range concept.
3477 int wxWindow::GetScrollThumb(const int orient
) const
3479 if (orient
== wxHORIZONTAL
)
3480 return m_xThumbSize
;
3482 return m_yThumbSize
;
3485 void wxWindow::SetScrollPos(const int orient
, const int pos
, const bool refresh
)
3487 #if defined(__WIN95__)
3491 if (orient
== wxHORIZONTAL
) {
3497 info
.cbSize
= sizeof(SCROLLINFO
);
3501 info
.fMask
= SIF_POS
;
3503 HWND hWnd
= (HWND
) GetHWND();
3505 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3508 if (orient
== wxHORIZONTAL
)
3513 HWND hWnd
= (HWND
) GetHWND();
3515 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3519 // New function that will replace some of the above.
3520 void wxWindow::SetScrollbar(const int orient
, const int pos
, const int thumbVisible
,
3521 const int range
, const bool refresh
)
3524 SetScrollPage(orient, thumbVisible, FALSE);
3526 int oldRange = range - thumbVisible ;
3527 SetScrollRange(orient, oldRange, FALSE);
3529 SetScrollPos(orient, pos, refresh);
3531 #if defined(__WIN95__)
3532 int oldRange
= range
- thumbVisible
;
3534 int range1
= oldRange
;
3536 // Try to adjust the range to cope with page size > 1
3537 // - a Windows API quirk
3538 int pageSize
= thumbVisible
;
3539 if ( pageSize
> 1 && range
> 0)
3541 range1
+= (pageSize
- 1);
3547 if (orient
== wxHORIZONTAL
) {
3553 info
.cbSize
= sizeof(SCROLLINFO
);
3554 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3558 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3560 HWND hWnd
= (HWND
) GetHWND();
3562 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3565 if (orient
== wxHORIZONTAL
)
3570 HWND hWnd
= (HWND
) GetHWND();
3573 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3574 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3577 if (orient
== wxHORIZONTAL
) {
3578 m_xThumbSize
= thumbVisible
;
3580 m_yThumbSize
= thumbVisible
;
3584 void wxWindow::ScrollWindow(const int dx
, const int dy
, const wxRectangle
*rect
)
3589 rect2
.left
= rect
->x
;
3590 rect2
.top
= rect
->y
;
3591 rect2
.right
= rect
->x
+ rect
->width
;
3592 rect2
.bottom
= rect
->y
+ rect
->height
;
3596 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3598 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3601 void wxWindow::OnSize(wxSizeEvent
& event
)
3605 if (GetAutoLayout())
3611 void wxWindow::CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const
3617 void wxWindow::CalcUnscrolledPosition(const int x, const int y, float *xx, float *yy) const
3624 void wxWindow::SetFont(const wxFont
& font
)
3626 // Decrement the usage count of the old label font
3627 // (we may be able to free it up)
3628 // if (GetFont()->Ok())
3629 // GetFont()->ReleaseResource();
3631 m_windowFont
= font
;
3633 if (!m_windowFont
.Ok())
3636 // m_windowFont.UseResource();
3638 HWND hWnd
= (HWND
) GetHWND();
3641 // m_windowFont.RealizeResource();
3643 if (m_windowFont
.GetResourceHandle())
3644 SendMessage(hWnd
, WM_SETFONT
,
3645 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3649 void wxWindow::SubclassWin(WXHWND hWnd
)
3651 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3653 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3654 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3657 void wxWindow::UnsubclassWin(void)
3659 wxRemoveHandleAssociation(this);
3661 // Restore old Window proc
3662 if ((HWND
) GetHWND())
3664 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3665 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3667 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3673 // Make a Windows extended style from the given wxWindows window style
3674 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3676 WXDWORD exStyle
= 0;
3677 if ( style
& wxTRANSPARENT_WINDOW
)
3678 exStyle
|= WS_EX_TRANSPARENT
;
3680 if ( !eliminateBorders
)
3682 if ( style
& wxSUNKEN_BORDER
)
3683 exStyle
|= WS_EX_CLIENTEDGE
;
3684 if ( style
& wxDOUBLE_BORDER
)
3685 exStyle
|= WS_EX_DLGMODALFRAME
;
3686 #if defined(__WIN95__)
3687 if ( style
& wxRAISED_BORDER
)
3688 exStyle
|= WS_EX_WINDOWEDGE
;
3689 if ( style
& wxSTATIC_BORDER
)
3690 exStyle
|= WS_EX_STATICEDGE
;
3696 // Determines whether native 3D effects or CTL3D should be used,
3697 // applying a default border style if required, and returning an extended
3698 // style to pass to CreateWindowEx.
3699 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3701 // If matches certain criteria, then assume no 3D effects
3702 // unless specifically requested (dealt with in MakeExtendedStyle)
3703 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3706 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3709 // Determine whether we should be using 3D effects or not.
3710 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3712 // 1) App can specify global 3D effects
3713 *want3D
= wxTheApp
->GetAuto3D();
3715 // 2) If the parent is being drawn with user colours, or simple border specified,
3716 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3717 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3720 // 3) Control can override this global setting by defining
3721 // a border style, e.g. wxSUNKEN_BORDER
3722 if (m_windowStyle
& wxSUNKEN_BORDER
)
3725 // 4) If it's a special border, CTL3D can't cope so we want a native border
3726 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3727 (m_windowStyle
& wxSTATIC_BORDER
) )
3730 nativeBorder
= TRUE
;
3733 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3734 // effects from extended style
3737 nativeBorder
= FALSE
;
3740 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3742 // If we want 3D, but haven't specified a border here,
3743 // apply the default border style specified.
3744 // TODO what about non-Win95 WIN32? Does it have borders?
3745 #if defined(__WIN95__) && !CTL3D
3746 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3747 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3748 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3754 #if WXWIN_COMPATIBILITY
3755 void wxWindow::OldOnPaint(void)
3757 wxPaintEvent
event(m_windowId
);
3758 event
.m_eventObject
= this;
3759 if (!GetEventHandler()->ProcessEvent(event
))
3763 void wxWindow::OldOnSize(int w
, int h
)
3765 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
3766 event
.m_eventObject
= this;
3767 if (!GetEventHandler()->ProcessEvent(event
))
3771 void wxWindow::OldOnMouseEvent(wxMouseEvent
& event
)
3773 if (!GetEventHandler()->ProcessEvent(event
))
3777 void wxWindow::OldOnChar(wxKeyEvent
& event
)
3779 if (!GetEventHandler()->ProcessEvent(event
))
3783 void wxWindow::OldOnSetFocus(void)
3785 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3786 event
.m_eventObject
= this;
3787 if (!GetEventHandler()->ProcessEvent(event
))
3791 void wxWindow::OldOnKillFocus(void)
3793 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3794 event
.m_eventObject
= this;
3795 if (!GetEventHandler()->ProcessEvent(event
))
3800 void wxWindow::OnChar(wxKeyEvent
& event
)
3803 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3808 if ( !event
.ControlDown() )
3809 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3812 void wxWindow::OnPaint(wxPaintEvent
& event
)
3817 bool wxWindow::IsEnabled(void) const
3819 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3822 // Dialog support: override these and call
3823 // base class members to add functionality
3824 // that can't be done using validators.
3825 // NOTE: these functions assume that controls
3826 // are direct children of this window, not grandchildren
3827 // or other levels of descendant.
3829 // Transfer values to controls. If returns FALSE,
3830 // it's an application error (pops up a dialog)
3831 bool wxWindow::TransferDataToWindow(void)
3833 wxNode
*node
= GetChildren()->First();
3836 wxWindow
*child
= (wxWindow
*)node
->Data();
3837 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3838 !child
->GetValidator()->TransferToWindow() )
3840 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3844 node
= node
->Next();
3849 // Transfer values from controls. If returns FALSE,
3850 // validation failed: don't quit
3851 bool wxWindow::TransferDataFromWindow(void)
3853 wxNode
*node
= GetChildren()->First();
3856 wxWindow
*child
= (wxWindow
*)node
->Data();
3857 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3862 node
= node
->Next();
3867 bool wxWindow::Validate(void)
3869 wxNode
*node
= GetChildren()->First();
3872 wxWindow
*child
= (wxWindow
*)node
->Data();
3873 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3878 node
= node
->Next();
3883 // Get the window with the focus
3884 wxWindow
*wxWindow::FindFocus(void)
3886 HWND hWnd
= ::GetFocus();
3889 return wxFindWinFromHandle((WXHWND
) hWnd
);
3894 void wxWindow::AddChild(wxWindow
*child
)
3896 GetChildren()->Append(child
);
3897 child
->m_windowParent
= this;
3900 void wxWindow::RemoveChild(wxWindow
*child
)
3903 GetChildren()->DeleteObject(child
);
3904 child
->m_windowParent
= NULL
;
3907 void wxWindow::DestroyChildren(void)
3909 if (GetChildren()) {
3911 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3913 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3915 if ( GetChildren()->Member(child
) )
3922 void wxWindow::MakeModal(const bool modal
)
3924 // Disable all other windows
3925 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3927 wxNode
*node
= wxTopLevelWindows
.First();
3930 wxWindow
*win
= (wxWindow
*)node
->Data();
3932 win
->Enable(!modal
);
3934 node
= node
->Next();
3939 // If nothing defined for this, try the parent.
3940 // E.g. we may be a button loaded from a resource, with no callback function
3942 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3944 if (GetEventHandler()->ProcessEvent(event
) )
3947 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3950 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3954 UnsetConstraints(m_constraints
);
3955 delete m_constraints
;
3960 // Make sure other windows know they're part of a 'meaningful relationship'
3961 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3962 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3963 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3964 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3965 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3966 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3967 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3968 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3969 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3970 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3971 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3972 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3973 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3974 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3975 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3976 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3980 // This removes any dangling pointers to this window
3981 // in other windows' constraintsInvolvedIn lists.
3982 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3986 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3987 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3988 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3989 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3990 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3991 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3992 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3993 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3994 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3995 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3996 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3997 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3998 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3999 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4000 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
4001 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4005 // Back-pointer to other windows we're involved with, so if we delete
4006 // this window, we must delete any constraints we're involved with.
4007 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
4009 if (!m_constraintsInvolvedIn
)
4010 m_constraintsInvolvedIn
= new wxList
;
4011 if (!m_constraintsInvolvedIn
->Member(otherWin
))
4012 m_constraintsInvolvedIn
->Append(otherWin
);
4015 // REMOVE back-pointer to other windows we're involved with.
4016 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
4018 if (m_constraintsInvolvedIn
)
4019 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
4022 // Reset any constraints that mention this window
4023 void wxWindow::DeleteRelatedConstraints(void)
4025 if (m_constraintsInvolvedIn
)
4027 wxNode
*node
= m_constraintsInvolvedIn
->First();
4030 wxWindow
*win
= (wxWindow
*)node
->Data();
4031 wxNode
*next
= node
->Next();
4032 wxLayoutConstraints
*constr
= win
->GetConstraints();
4034 // Reset any constraints involving this window
4037 constr
->left
.ResetIfWin((wxWindow
*)this);
4038 constr
->top
.ResetIfWin((wxWindow
*)this);
4039 constr
->right
.ResetIfWin((wxWindow
*)this);
4040 constr
->bottom
.ResetIfWin((wxWindow
*)this);
4041 constr
->width
.ResetIfWin((wxWindow
*)this);
4042 constr
->height
.ResetIfWin((wxWindow
*)this);
4043 constr
->centreX
.ResetIfWin((wxWindow
*)this);
4044 constr
->centreY
.ResetIfWin((wxWindow
*)this);
4049 delete m_constraintsInvolvedIn
;
4050 m_constraintsInvolvedIn
= NULL
;
4054 void wxWindow::SetSizer(wxSizer
*sizer
)
4056 m_windowSizer
= sizer
;
4058 sizer
->SetSizerParent((wxWindow
*)this);
4065 bool wxWindow::Layout(void)
4067 if (GetConstraints())
4070 GetClientSize(&w
, &h
);
4071 GetConstraints()->width
.SetValue(w
);
4072 GetConstraints()->height
.SetValue(h
);
4075 // If top level (one sizer), evaluate the sizer's constraints.
4079 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
4080 GetSizer()->LayoutPhase1(&noChanges
);
4081 GetSizer()->LayoutPhase2(&noChanges
);
4082 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
4087 // Otherwise, evaluate child constraints
4088 ResetConstraints(); // Mark all constraints as unevaluated
4089 DoPhase(1); // Just one phase need if no sizers involved
4091 SetConstraintSizes(); // Recursively set the real window sizes
4097 // Do a phase of evaluating constraints:
4098 // the default behaviour. wxSizers may do a similar
4099 // thing, but also impose their own 'constraints'
4100 // and order the evaluation differently.
4101 bool wxWindow::LayoutPhase1(int *noChanges
)
4103 wxLayoutConstraints
*constr
= GetConstraints();
4106 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
4112 bool wxWindow::LayoutPhase2(int *noChanges
)
4122 // Do a phase of evaluating child constraints
4123 bool wxWindow::DoPhase(const int phase
)
4125 int noIterations
= 0;
4126 int maxIterations
= 500;
4130 while ((noChanges
> 0) && (noIterations
< maxIterations
))
4134 wxNode
*node
= GetChildren()->First();
4137 wxWindow
*child
= (wxWindow
*)node
->Data();
4138 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
4140 wxLayoutConstraints
*constr
= child
->GetConstraints();
4143 if (succeeded
.Member(child
))
4148 int tempNoChanges
= 0;
4149 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
4150 noChanges
+= tempNoChanges
;
4153 succeeded
.Append(child
);
4158 node
= node
->Next();
4165 void wxWindow::ResetConstraints(void)
4167 wxLayoutConstraints
*constr
= GetConstraints();
4170 constr
->left
.SetDone(FALSE
);
4171 constr
->top
.SetDone(FALSE
);
4172 constr
->right
.SetDone(FALSE
);
4173 constr
->bottom
.SetDone(FALSE
);
4174 constr
->width
.SetDone(FALSE
);
4175 constr
->height
.SetDone(FALSE
);
4176 constr
->centreX
.SetDone(FALSE
);
4177 constr
->centreY
.SetDone(FALSE
);
4179 wxNode
*node
= GetChildren()->First();
4182 wxWindow
*win
= (wxWindow
*)node
->Data();
4183 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4184 win
->ResetConstraints();
4185 node
= node
->Next();
4189 // Need to distinguish between setting the 'fake' size for
4190 // windows and sizers, and setting the real values.
4191 void wxWindow::SetConstraintSizes(const bool recurse
)
4193 wxLayoutConstraints
*constr
= GetConstraints();
4194 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4195 constr
->width
.GetDone() && constr
->height
.GetDone())
4197 int x
= constr
->left
.GetValue();
4198 int y
= constr
->top
.GetValue();
4199 int w
= constr
->width
.GetValue();
4200 int h
= constr
->height
.GetValue();
4202 // If we don't want to resize this window, just move it...
4203 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4204 (constr
->height
.GetRelationship() != wxAsIs
))
4206 // Calls Layout() recursively. AAAGH. How can we stop that.
4207 // Simply take Layout() out of non-top level OnSizes.
4208 SizerSetSize(x
, y
, w
, h
);
4217 char *windowClass
= this->GetClassInfo()->GetClassName();
4220 if (GetName() == "")
4221 winName
= "unnamed";
4223 winName
= GetName();
4224 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4225 if (!constr
->left
.GetDone())
4226 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4227 if (!constr
->right
.GetDone())
4228 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4229 if (!constr
->width
.GetDone())
4230 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4231 if (!constr
->height
.GetDone())
4232 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4233 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4238 wxNode
*node
= GetChildren()->First();
4241 wxWindow
*win
= (wxWindow
*)node
->Data();
4242 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4243 win
->SetConstraintSizes();
4244 node
= node
->Next();
4249 // This assumes that all sizers are 'on' the same
4250 // window, i.e. the parent of this window.
4251 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4253 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4254 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4258 m_sizerParent
->GetPosition(&xp
, &yp
);
4259 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4264 void wxWindow::SizerSetSize(const int x
, const int y
, const int w
, const int h
)
4268 TransformSizerToActual(&xx
, &yy
);
4269 SetSize(xx
, yy
, w
, h
);
4272 void wxWindow::SizerMove(const int x
, const int y
)
4276 TransformSizerToActual(&xx
, &yy
);
4280 // Only set the size/position of the constraint (if any)
4281 void wxWindow::SetSizeConstraint(const int x
, const int y
, const int w
, const int h
)
4283 wxLayoutConstraints
*constr
= GetConstraints();
4288 constr
->left
.SetValue(x
);
4289 constr
->left
.SetDone(TRUE
);
4293 constr
->top
.SetValue(y
);
4294 constr
->top
.SetDone(TRUE
);
4298 constr
->width
.SetValue(w
);
4299 constr
->width
.SetDone(TRUE
);
4303 constr
->height
.SetValue(h
);
4304 constr
->height
.SetDone(TRUE
);
4309 void wxWindow::MoveConstraint(const int x
, const int y
)
4311 wxLayoutConstraints
*constr
= GetConstraints();
4316 constr
->left
.SetValue(x
);
4317 constr
->left
.SetDone(TRUE
);
4321 constr
->top
.SetValue(y
);
4322 constr
->top
.SetDone(TRUE
);
4327 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4329 wxLayoutConstraints
*constr
= GetConstraints();
4332 *w
= constr
->width
.GetValue();
4333 *h
= constr
->height
.GetValue();
4339 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4341 wxLayoutConstraints
*constr
= GetConstraints();
4344 *w
= constr
->width
.GetValue();
4345 *h
= constr
->height
.GetValue();
4348 GetClientSize(w
, h
);
4351 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4353 wxLayoutConstraints
*constr
= GetConstraints();
4356 *x
= constr
->left
.GetValue();
4357 *y
= constr
->top
.GetValue();
4363 bool wxWindow::Close(const bool force
)
4365 // Let's generalise it to work the same for any window.
4367 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4374 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4375 event
.SetEventObject(this);
4376 event
.SetForce(force
);
4378 return GetEventHandler()->ProcessEvent(event
);
4381 if ( !force && event.GetVeto() )
4386 if (!wxPendingDelete.Member(this))
4387 wxPendingDelete.Append(this);
4393 wxObject
* wxWindow::GetChild(const int number
) const
4395 // Return a pointer to the Nth object in the Panel
4398 wxNode
*node
= GetChildren()->First();
4401 node
= node
->Next() ;
4404 wxObject
*obj
= (wxObject
*)node
->Data();
4411 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4413 if (initiatingItem
->IsKindOf(CLASSINFO(wxListBox
)) && initiatingItem
->GetCallback())
4415 wxListBox
*lbox
= (wxListBox
*)initiatingItem
;
4416 wxCommandEvent
event(wxEVENT_TYPE_LISTBOX_DCLICK_COMMAND
);
4417 event
.m_commandInt
= -1;
4418 if ((lbox
->GetWindowStyleFlag() & wxLB_MULTIPLE
) == 0)
4420 event
.m_commandString
= copystring(lbox
->GetStringSelection());
4421 event
.m_commandInt
= lbox
->GetSelection();
4422 event
.m_clientData
= lbox
->wxListBox::GetClientData(event
.m_commandInt
);
4424 event
.m_eventObject
= lbox
;
4426 lbox
->ProcessCommand(event
);
4428 if (event
.m_commandString
)
4429 delete[] event
.m_commandString
;
4433 wxButton
*but
= GetDefaultItem();
4436 wxCommandEvent
event(wxEVENT_TYPE_BUTTON_COMMAND
);
4437 but
->Command(event
);
4441 void wxWindow::Clear(void)
4443 wxClientDC
dc(this);
4444 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4445 dc
.SetBackground(brush
);
4449 // Fits the panel around the items
4450 void wxWindow::Fit(void)
4454 wxNode
*node
= GetChildren()->First();
4457 wxWindow
*win
= (wxWindow
*)node
->Data();
4459 win
->GetPosition(&wx
, &wy
);
4460 win
->GetSize(&ww
, &wh
);
4461 if ( wx
+ ww
> maxX
)
4463 if ( wy
+ wh
> maxY
)
4466 node
= node
->Next();
4468 SetClientSize(maxX
+ 5, maxY
+ 5);
4471 void wxWindow::SetValidator(const wxValidator
& validator
)
4473 if ( m_windowValidator
)
4474 delete m_windowValidator
;
4475 m_windowValidator
= validator
.Clone();
4477 if ( m_windowValidator
)
4478 m_windowValidator
->SetWindow(this) ;
4481 // Find a window by id or name
4482 wxWindow
*wxWindow::FindWindow(const long id
)
4487 wxNode
*node
= GetChildren()->First();
4490 wxWindow
*child
= (wxWindow
*)node
->Data();
4491 wxWindow
*found
= child
->FindWindow(id
);
4494 node
= node
->Next();
4499 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4501 if ( GetName() == name
)
4504 wxNode
*node
= GetChildren()->First();
4507 wxWindow
*child
= (wxWindow
*)node
->Data();
4508 wxWindow
*found
= child
->FindWindow(name
);
4511 node
= node
->Next();
4517 // Default input behaviour for a scrolling canvas should be to scroll
4518 // according to the cursor keys pressed
4519 void wxWindow::OnChar(wxKeyEvent& event)
4531 GetScrollUnitsPerPage(&x_page, &y_page);
4533 GetVirtualSize(&v_width,&v_height);
4535 ViewStart(&start_x, &start_y);
4538 y_pages = (int)(v_height/vert_units) - y_page;
4546 switch (event.keyCode)
4553 if (start_y - y_page > 0)
4554 Scroll(start_x, start_y - y_page);
4564 if ((y_page > 0) && (start_y <= y_pages-y-1))
4566 if (y_pages + y < start_y + y_page)
4567 Scroll(start_x, y_pages + y);
4569 Scroll(start_x, start_y + y_page);
4576 if ((y_page > 0) && (start_y >= 1))
4577 Scroll(start_x, start_y - 1);
4583 if ((y_page > 0) && (start_y <= y_pages-y-1))
4586 Scroll(start_x, start_y + 1);
4592 if ((x_page > 0) && (start_x >= 1))
4593 Scroll(start_x - 1, start_y);
4599 Scroll(start_x + 1, start_y);
4610 Scroll(start_x, y_pages+y);
4618 // Setup background and foreground colours correctly
4619 void wxWindow::SetupColours(void)
4622 SetBackgroundColour(GetParent()->GetBackgroundColour());
4625 // Do Update UI processing for child controls
4627 // TODO: should this be implemented for the child window rather
4628 // than the parent? Then you can override it e.g. for wxCheckBox
4629 // to do the Right Thing rather than having to assume a fixed number
4630 // of control classes.
4632 void wxWindow::UpdateWindowUI(void)
4634 wxWindowID id
= GetId();
4637 wxUpdateUIEvent
event(id
);
4638 event
.m_eventObject
= this;
4640 if (this->GetEventHandler()->ProcessEvent(event
))
4642 if (event
.GetSetEnabled())
4643 this->Enable(event
.GetEnabled());
4645 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4646 ((wxControl
*)this)->SetLabel(event
.GetText());
4648 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4650 if (event
.GetSetChecked())
4651 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4653 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4655 if (event
.GetSetChecked())
4656 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4663 void wxWindow::OnIdle(wxIdleEvent
& event
)
4665 // Check if we need to send a LEAVE event
4666 if (m_mouseInWindow
)
4669 ::GetCursorPos(&pt
);
4670 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4672 // Generate a LEAVE event
4673 m_mouseInWindow
= FALSE
;
4674 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4680 // Raise the window to the top of the Z order
4681 void wxWindow::Raise(void)
4683 ::BringWindowToTop((HWND
) GetHWND());
4686 // Lower the window to the bottom of the Z order
4687 void wxWindow::Lower(void)
4689 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);