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
);
2006 void wxWindow::MSWOnSize(const int w
, const int h
, const WXUINT
WXUNUSED(flag
))
2012 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2019 #if WXWIN_COMPATIBILITY
2020 GetEventHandler()->OldOnSize(w
, h
);
2022 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2023 event
.m_eventObject
= this;
2024 GetEventHandler()->ProcessEvent(event
);
2030 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2035 // Deal with child commands from buttons etc.
2036 bool wxWindow::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND
WXUNUSED(control
))
2039 wxDebugMsg("wxWindow::MSWOnCommand\n");
2041 if (wxCurrentPopupMenu
)
2043 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2044 wxCurrentPopupMenu
= NULL
;
2045 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2050 sprintf(buf
, "Looking for item %d...\n", id
);
2054 wxWindow
*item
= FindItem(id
);
2057 bool value
= item
->MSWCommand(cmd
, id
);
2060 wxDebugMsg("MSWCommand succeeded\n");
2062 wxDebugMsg("MSWCommand failed\n");
2069 wxDebugMsg("Could not find item!\n");
2071 wxDebugMsg("Item ids for this panel:\n");
2073 wxNode
*current
= GetChildren()->First();
2076 wxObject
*obj
= (wxObject
*)current
->Data() ;
2077 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2079 wxControl
*item
= (wxControl
*)current
->Data();
2080 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2083 current
= current
->Next();
2091 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2097 wxMaximizeEvent
event(m_windowId
);
2098 event
.SetEventObject(this);
2099 if (!GetEventHandler()->ProcessEvent(event
))
2107 wxIconizeEvent
event(m_windowId
);
2108 event
.SetEventObject(this);
2109 if (!GetEventHandler()->ProcessEvent(event
))
2121 void wxWindow::MSWOnLButtonDown(const int x
, const int y
, const WXUINT flags
)
2123 #if 0 // defined(__WIN32__) && !defined(WIN95)
2124 // DClick not clean supported on Win3.1, except if someone know
2125 // how to emulate Sleep()...
2126 // This means that your app will receive Down-Up-Dclick sequences
2127 // rather than Dclick
2128 if (m_doubleClickAllowed
)
2130 UINT time
= GetDoubleClickTime() ;
2133 if (PeekMessage(&dummy
,m_hWnd
,
2134 WM_LBUTTONDBLCLK
,WM_LBUTTONDBLCLK
,
2138 PeekMessage(&dummy
,m_hWnd
,WM_LBUTTONUP
,WM_LBUTTONUP
,PM_REMOVE
);
2144 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2146 event
.m_x
= x
; event
.m_y
= y
;
2147 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2148 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2149 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2150 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2151 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2152 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2153 event
.m_eventObject
= this;
2155 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2156 GetEventHandler()->OldOnMouseEvent(event
);
2159 void wxWindow::MSWOnLButtonUp(const int x
, const int y
, const WXUINT flags
)
2161 wxMouseEvent
event(wxEVT_LEFT_UP
);
2163 event
.m_x
= x
; event
.m_y
= y
;
2164 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2165 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2166 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2167 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2168 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2169 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2170 event
.m_eventObject
= this;
2172 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2174 GetEventHandler()->OldOnMouseEvent(event
);
2177 void wxWindow::MSWOnLButtonDClick(const int x
, const int y
, const WXUINT flags
)
2179 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2181 event
.m_x
= x
; event
.m_y
= y
;
2182 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2183 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2184 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2185 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2186 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2187 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2188 event
.m_eventObject
= this;
2190 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2192 // if (m_doubleClickAllowed)
2193 GetEventHandler()->OldOnMouseEvent(event
);
2196 void wxWindow::MSWOnMButtonDown(const int x
, const int y
, const WXUINT flags
)
2198 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2199 // DClick not clean supported on Win3.1, except if someone know
2200 // how to emulate Sleep()...
2201 // This means that your app will receive Down-Up-Dclick sequences
2202 // rather than Dclick
2203 if (m_doubleClickAllowed
)
2205 UINT time
= GetDoubleClickTime() ;
2208 if (PeekMessage(&dummy
,m_hWnd
,
2209 WM_MBUTTONDBLCLK
,WM_MBUTTONDBLCLK
,
2213 PeekMessage(&dummy
,m_hWnd
,WM_MBUTTONUP
,WM_MBUTTONUP
,PM_REMOVE
);
2219 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2221 event
.m_x
= x
; event
.m_y
= y
;
2222 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2223 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2224 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2225 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2226 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2227 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2228 event
.m_eventObject
= this;
2230 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2231 GetEventHandler()->OldOnMouseEvent(event
);
2234 void wxWindow::MSWOnMButtonUp(const int x
, const int y
, const WXUINT flags
)
2236 //wxDebugMsg("MButtonUp\n") ;
2237 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2239 event
.m_x
= x
; event
.m_y
= y
;
2240 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2241 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2242 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2243 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2244 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2245 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2246 event
.m_eventObject
= this;
2248 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2249 GetEventHandler()->OldOnMouseEvent(event
);
2252 void wxWindow::MSWOnMButtonDClick(const int x
, const int y
, const WXUINT flags
)
2254 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2256 event
.m_x
= x
; event
.m_y
= y
;
2257 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2258 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2259 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2260 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2261 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2262 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2263 event
.m_eventObject
= this;
2265 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2266 // if (m_doubleClickAllowed)
2267 GetEventHandler()->OldOnMouseEvent(event
);
2270 void wxWindow::MSWOnRButtonDown(const int x
, const int y
, const WXUINT flags
)
2272 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2273 // DClick not clean supported on Win3.1, except if someone know
2274 // how to emulate Sleep()...
2275 // This means that your app will receive Down-Up-Dclick sequences
2276 // rather than Dclick
2277 if (m_doubleClickAllowed
)
2279 UINT time
= GetDoubleClickTime() ;
2282 if (PeekMessage(&dummy
,m_hWnd
,
2283 WM_RBUTTONDBLCLK
,WM_RBUTTONDBLCLK
,
2287 PeekMessage(&dummy
,m_hWnd
,WM_RBUTTONUP
,WM_RBUTTONUP
,PM_REMOVE
);
2293 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2295 event
.m_x
= x
; event
.m_y
= y
;
2296 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2297 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2298 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2299 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2300 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2301 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2302 event
.m_eventObject
= this;
2304 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2305 GetEventHandler()->OldOnMouseEvent(event
);
2308 void wxWindow::MSWOnRButtonUp(const int x
, const int y
, const WXUINT flags
)
2310 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2312 event
.m_x
= x
; event
.m_y
= y
;
2313 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2314 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2315 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2316 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2317 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2318 event
.m_eventObject
= this;
2319 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2321 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2322 GetEventHandler()->OldOnMouseEvent(event
);
2325 void wxWindow::MSWOnRButtonDClick(const int x
, const int y
, const WXUINT flags
)
2327 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2329 event
.m_x
= x
; event
.m_y
= y
;
2330 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2331 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2332 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2333 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2334 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2335 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2336 event
.m_eventObject
= this;
2338 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2339 // if (m_doubleClickAllowed)
2340 GetEventHandler()->OldOnMouseEvent(event
);
2343 void wxWindow::MSWOnMouseMove(const int x
, const int y
, const WXUINT flags
)
2345 // 'normal' move event...
2346 // Set cursor, but only if we're not in 'busy' mode
2348 // Trouble with this is that it sets the cursor for controls too :-(
2349 if (m_windowCursor
.Ok() && !wxIsBusy())
2350 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2352 if (!m_mouseInWindow
)
2354 // Generate an ENTER event
2355 m_mouseInWindow
= TRUE
;
2356 MSWOnMouseEnter(x
, y
, flags
);
2359 wxMouseEvent
event(wxEVT_MOTION
);
2361 event
.m_x
= x
; event
.m_y
= y
;
2362 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2363 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2364 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2365 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2366 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2367 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2368 event
.m_eventObject
= this;
2370 // Window gets a click down message followed by a mouse move
2371 // message even if position isn't changed! We want to discard
2372 // the trailing move event if x and y are the same.
2373 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2374 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2375 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2377 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2378 m_lastEvent
= wxEVT_MOTION
;
2382 m_lastEvent
= wxEVT_MOTION
;
2383 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2384 GetEventHandler()->OldOnMouseEvent(event
);
2387 void wxWindow::MSWOnMouseEnter(const int x
, const int y
, const WXUINT flags
)
2389 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2391 event
.m_x
= x
; event
.m_y
= y
;
2392 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2393 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2394 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2395 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2396 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2397 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2398 event
.m_eventObject
= this;
2400 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2401 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2402 // No message - ensure we don't try to call the default behaviour accidentally.
2404 GetEventHandler()->ProcessEvent(event
);
2407 void wxWindow::MSWOnMouseLeave(const int x
, const int y
, const WXUINT flags
)
2409 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2411 event
.m_x
= x
; event
.m_y
= y
;
2412 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2413 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2414 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2415 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2416 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2417 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2418 event
.m_eventObject
= this;
2420 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2421 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2422 // No message - ensure we don't try to call the default behaviour accidentally.
2424 GetEventHandler()->ProcessEvent(event
);
2427 void wxWindow::MSWOnChar(const WXWORD wParam
, const WXLPARAM lParam
, const bool isASCII
)
2430 bool tempControlDown
= FALSE
;
2433 // If 1 -> 26, translate to CTRL plus a letter.
2435 if ((id
> 0) && (id
< 27))
2456 tempControlDown
= TRUE
;
2462 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2463 // it's ASCII and will be processed here only when called from
2464 // WM_CHAR (i.e. when isASCII = TRUE)
2470 wxKeyEvent
event(wxEVT_CHAR
);
2471 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2472 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2473 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2474 event
.m_altDown
= TRUE
;
2476 event
.m_eventObject
= this;
2477 event
.m_keyCode
= id
;
2478 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2483 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2487 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2489 #if WXWIN_COMPATIBILITY
2490 GetEventHandler()->OldOnChar(event
);
2492 if (!GetEventHandler()->ProcessEvent(event
))
2498 void wxWindow::MSWOnJoyDown(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2502 if (flags
& JOY_BUTTON1CHG
)
2503 change
= wxJOY_BUTTON1
;
2504 if (flags
& JOY_BUTTON2CHG
)
2505 change
= wxJOY_BUTTON2
;
2506 if (flags
& JOY_BUTTON3CHG
)
2507 change
= wxJOY_BUTTON3
;
2508 if (flags
& JOY_BUTTON4CHG
)
2509 change
= wxJOY_BUTTON4
;
2511 if (flags
& JOY_BUTTON1
)
2512 buttons
|= wxJOY_BUTTON1
;
2513 if (flags
& JOY_BUTTON2
)
2514 buttons
|= wxJOY_BUTTON2
;
2515 if (flags
& JOY_BUTTON3
)
2516 buttons
|= wxJOY_BUTTON3
;
2517 if (flags
& JOY_BUTTON4
)
2518 buttons
|= wxJOY_BUTTON4
;
2520 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2521 event
.SetPosition(wxPoint(x
, y
));
2522 event
.SetEventObject(this);
2524 GetEventHandler()->ProcessEvent(event
);
2527 void wxWindow::MSWOnJoyUp(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2531 if (flags
& JOY_BUTTON1CHG
)
2532 change
= wxJOY_BUTTON1
;
2533 if (flags
& JOY_BUTTON2CHG
)
2534 change
= wxJOY_BUTTON2
;
2535 if (flags
& JOY_BUTTON3CHG
)
2536 change
= wxJOY_BUTTON3
;
2537 if (flags
& JOY_BUTTON4CHG
)
2538 change
= wxJOY_BUTTON4
;
2540 if (flags
& JOY_BUTTON1
)
2541 buttons
|= wxJOY_BUTTON1
;
2542 if (flags
& JOY_BUTTON2
)
2543 buttons
|= wxJOY_BUTTON2
;
2544 if (flags
& JOY_BUTTON3
)
2545 buttons
|= wxJOY_BUTTON3
;
2546 if (flags
& JOY_BUTTON4
)
2547 buttons
|= wxJOY_BUTTON4
;
2549 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2550 event
.SetPosition(wxPoint(x
, y
));
2551 event
.SetEventObject(this);
2553 GetEventHandler()->ProcessEvent(event
);
2556 void wxWindow::MSWOnJoyMove(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2559 if (flags
& JOY_BUTTON1
)
2560 buttons
|= wxJOY_BUTTON1
;
2561 if (flags
& JOY_BUTTON2
)
2562 buttons
|= wxJOY_BUTTON2
;
2563 if (flags
& JOY_BUTTON3
)
2564 buttons
|= wxJOY_BUTTON3
;
2565 if (flags
& JOY_BUTTON4
)
2566 buttons
|= wxJOY_BUTTON4
;
2568 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2569 event
.SetPosition(wxPoint(x
, y
));
2570 event
.SetEventObject(this);
2572 GetEventHandler()->ProcessEvent(event
);
2575 void wxWindow::MSWOnJoyZMove(const int joystick
, const int z
, const WXUINT flags
)
2578 if (flags
& JOY_BUTTON1
)
2579 buttons
|= wxJOY_BUTTON1
;
2580 if (flags
& JOY_BUTTON2
)
2581 buttons
|= wxJOY_BUTTON2
;
2582 if (flags
& JOY_BUTTON3
)
2583 buttons
|= wxJOY_BUTTON3
;
2584 if (flags
& JOY_BUTTON4
)
2585 buttons
|= wxJOY_BUTTON4
;
2587 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2588 event
.SetZPosition(z
);
2589 event
.SetEventObject(this);
2591 GetEventHandler()->ProcessEvent(event
);
2594 void wxWindow::MSWOnVScroll(const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2598 wxWindow
*child
= wxFindWinFromHandle(control
);
2600 child
->MSWOnVScroll(wParam
, pos
, control
);
2604 wxScrollEvent event
;
2605 event
.SetPosition(pos
);
2606 event
.SetOrientation(wxVERTICAL
);
2607 event
.m_eventObject
= this;
2612 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2616 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2620 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2624 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2628 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2632 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2636 case SB_THUMBPOSITION
:
2637 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2645 if (!GetEventHandler()->ProcessEvent(event
))
2646 #if WXWIN_COMPATIBILITY
2647 GetEventHandler()->OldOnScroll(event
);
2653 void wxWindow::MSWOnHScroll( const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2657 wxWindow
*child
= wxFindWinFromHandle(control
);
2659 child
->MSWOnHScroll(wParam
, pos
, control
);
2663 wxScrollEvent event
;
2664 event
.SetPosition(pos
);
2665 event
.SetOrientation(wxHORIZONTAL
);
2666 event
.m_eventObject
= this;
2671 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2675 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2679 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2683 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2687 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2691 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2695 case SB_THUMBPOSITION
:
2696 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2703 if (!GetEventHandler()->ProcessEvent(event
))
2704 #if WXWIN_COMPATIBILITY
2705 GetEventHandler()->OldOnScroll(event
);
2711 void wxWindow::MSWOnShow(bool show
, int status
)
2713 wxShowEvent
event(GetId(), show
);
2714 event
.m_eventObject
= this;
2715 GetEventHandler()->ProcessEvent(event
);
2718 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2720 wxInitDialogEvent
event(GetId());
2721 event
.m_eventObject
= this;
2722 GetEventHandler()->ProcessEvent(event
);
2726 void wxWindow::InitDialog(void)
2728 wxInitDialogEvent
event(GetId());
2729 event
.SetEventObject( this );
2730 GetEventHandler()->ProcessEvent(event
);
2733 // Default init dialog behaviour is to transfer data to window
2734 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2736 TransferDataToWindow();
2739 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2742 HDC dc
= ::GetDC((HWND
) wnd
);
2748 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2750 // the_font->UseResource();
2751 // the_font->RealizeResource();
2752 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2753 was
= SelectObject(dc
,fnt
) ;
2755 GetTextMetrics(dc
, &tm
);
2756 if (the_font
&& fnt
&& was
)
2759 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2761 SelectObject(dc
,was
) ;
2763 ReleaseDC((HWND
)wnd
, dc
);
2764 *x
= tm
.tmAveCharWidth
;
2765 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2768 // the_font->ReleaseResource();
2771 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2772 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2773 int wxCharCodeMSWToWX(int keySym
)
2778 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2779 case VK_BACK
: id
= WXK_BACK
; break;
2780 case VK_TAB
: id
= WXK_TAB
; break;
2781 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2782 case VK_RETURN
: id
= WXK_RETURN
; break;
2783 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2784 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2785 case VK_MENU
: id
= WXK_MENU
; break;
2786 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2787 case VK_SPACE
: id
= WXK_SPACE
; break;
2788 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2789 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2790 case VK_NEXT
: id
= WXK_NEXT
; break;
2791 case VK_END
: id
= WXK_END
; break;
2792 case VK_HOME
: id
= WXK_HOME
; break;
2793 case VK_LEFT
: id
= WXK_LEFT
; break;
2794 case VK_UP
: id
= WXK_UP
; break;
2795 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2796 case VK_DOWN
: id
= WXK_DOWN
; break;
2797 case VK_SELECT
: id
= WXK_SELECT
; break;
2798 case VK_PRINT
: id
= WXK_PRINT
; break;
2799 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2800 case VK_INSERT
: id
= WXK_INSERT
; break;
2801 case VK_DELETE
: id
= WXK_DELETE
; break;
2802 case VK_HELP
: id
= WXK_HELP
; break;
2803 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2804 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2805 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2806 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2807 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2808 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2809 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2810 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2811 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2812 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2813 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2814 case VK_ADD
: id
= WXK_ADD
; break;
2815 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2816 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2817 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2818 case VK_F1
: id
= WXK_F1
; break;
2819 case VK_F2
: id
= WXK_F2
; break;
2820 case VK_F3
: id
= WXK_F3
; break;
2821 case VK_F4
: id
= WXK_F4
; break;
2822 case VK_F5
: id
= WXK_F5
; break;
2823 case VK_F6
: id
= WXK_F6
; break;
2824 case VK_F7
: id
= WXK_F7
; break;
2825 case VK_F8
: id
= WXK_F8
; break;
2826 case VK_F9
: id
= WXK_F9
; break;
2827 case VK_F10
: id
= WXK_F10
; break;
2828 case VK_F11
: id
= WXK_F11
; break;
2829 case VK_F12
: id
= WXK_F12
; break;
2830 case VK_F13
: id
= WXK_F13
; break;
2831 case VK_F14
: id
= WXK_F14
; break;
2832 case VK_F15
: id
= WXK_F15
; break;
2833 case VK_F16
: id
= WXK_F16
; break;
2834 case VK_F17
: id
= WXK_F17
; break;
2835 case VK_F18
: id
= WXK_F18
; break;
2836 case VK_F19
: id
= WXK_F19
; break;
2837 case VK_F20
: id
= WXK_F20
; break;
2838 case VK_F21
: id
= WXK_F21
; break;
2839 case VK_F22
: id
= WXK_F22
; break;
2840 case VK_F23
: id
= WXK_F23
; break;
2841 case VK_F24
: id
= WXK_F24
; break;
2842 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2843 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2852 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2858 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2859 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2860 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2861 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2862 case WXK_MENU
: keySym
= VK_MENU
; break;
2863 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2864 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2865 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2866 case WXK_END
: keySym
= VK_END
; break;
2867 case WXK_HOME
: keySym
= VK_HOME
; break;
2868 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2869 case WXK_UP
: keySym
= VK_UP
; break;
2870 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2871 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2872 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2873 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2874 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2875 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2876 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2877 case WXK_HELP
: keySym
= VK_HELP
; break;
2878 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2879 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2880 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2881 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2882 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2883 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2884 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2885 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2886 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2887 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2888 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2889 case WXK_ADD
: keySym
= VK_ADD
; break;
2890 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2891 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2892 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2893 case WXK_F1
: keySym
= VK_F1
; break;
2894 case WXK_F2
: keySym
= VK_F2
; break;
2895 case WXK_F3
: keySym
= VK_F3
; break;
2896 case WXK_F4
: keySym
= VK_F4
; break;
2897 case WXK_F5
: keySym
= VK_F5
; break;
2898 case WXK_F6
: keySym
= VK_F6
; break;
2899 case WXK_F7
: keySym
= VK_F7
; break;
2900 case WXK_F8
: keySym
= VK_F8
; break;
2901 case WXK_F9
: keySym
= VK_F9
; break;
2902 case WXK_F10
: keySym
= VK_F10
; break;
2903 case WXK_F11
: keySym
= VK_F11
; break;
2904 case WXK_F12
: keySym
= VK_F12
; break;
2905 case WXK_F13
: keySym
= VK_F13
; break;
2906 case WXK_F14
: keySym
= VK_F14
; break;
2907 case WXK_F15
: keySym
= VK_F15
; break;
2908 case WXK_F16
: keySym
= VK_F16
; break;
2909 case WXK_F17
: keySym
= VK_F17
; break;
2910 case WXK_F18
: keySym
= VK_F18
; break;
2911 case WXK_F19
: keySym
= VK_F19
; break;
2912 case WXK_F20
: keySym
= VK_F20
; break;
2913 case WXK_F21
: keySym
= VK_F21
; break;
2914 case WXK_F22
: keySym
= VK_F22
; break;
2915 case WXK_F23
: keySym
= VK_F23
; break;
2916 case WXK_F24
: keySym
= VK_F24
; break;
2917 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2918 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2929 // Caret manipulation
2930 void wxWindow::CreateCaret(const int w
, const int h
)
2934 m_caretEnabled
= TRUE
;
2937 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2942 void wxWindow::ShowCaret(const bool show
)
2947 ::ShowCaret((HWND
) GetHWND());
2949 ::HideCaret((HWND
) GetHWND());
2950 m_caretShown
= show
;
2954 void wxWindow::DestroyCaret(void)
2956 m_caretEnabled
= FALSE
;
2959 void wxWindow::SetCaretPos(const int x
, const int y
)
2961 ::SetCaretPos(x
, y
);
2964 void wxWindow::GetCaretPos(int *x
, int *y
) const
2967 ::GetCaretPos(&point
);
2973 * Update iterator. Use from within OnPaint.
2976 static RECT gs_UpdateRect
;
2978 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2980 current
= 0; //start somewhere...
2981 #if defined(__WIN32__) && !defined(__win32s__)
2982 rlist
= NULL
; //make sure I don't free randomly
2983 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2986 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2987 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2988 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2989 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2994 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2995 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2996 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2997 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2999 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
3003 wxUpdateIterator::~wxUpdateIterator(void)
3007 if (rlist
) delete (RGNDATA
*) rlist
;
3012 wxUpdateIterator::operator int (void)
3014 if (current
< rects
)
3024 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
3030 void wxUpdateIterator::GetRect(wxRect
*rect
)
3032 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
3033 rect
->x
= mswRect
->left
;
3034 rect
->y
= mswRect
->top
;
3035 rect
->width
= mswRect
->right
- mswRect
->left
;
3036 rect
->height
= mswRect
->bottom
- mswRect
->top
;
3039 int wxUpdateIterator::GetX()
3041 return ((RECT
*)rp
)[current
].left
;
3044 int wxUpdateIterator::GetY()
3046 return ((RECT
*)rp
)[current
].top
;
3049 int wxUpdateIterator::GetW()
3051 return ((RECT
*)rp
)[current
].right
-GetX();
3054 int wxUpdateIterator::GetH()
3056 return ((RECT
*)rp
)[current
].bottom
-GetY();
3059 wxWindow
*wxGetActiveWindow(void)
3061 HWND hWnd
= GetActiveWindow();
3064 return wxFindWinFromHandle((WXHWND
) hWnd
);
3069 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3070 // in active frames and dialogs, regardless of where the focus is.
3071 static HHOOK wxTheKeyboardHook
= 0;
3072 static FARPROC wxTheKeyboardHookProc
= 0;
3073 int APIENTRY _EXPORT
3074 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
3076 void wxSetKeyboardHook(bool doIt
)
3080 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
3081 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
3083 GetCurrentThreadId());
3084 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3091 UnhookWindowsHookEx(wxTheKeyboardHook
);
3092 FreeProcInstance(wxTheKeyboardHookProc
);
3096 int APIENTRY _EXPORT
3097 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
3099 DWORD hiWord
= HIWORD(lParam
);
3100 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3103 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3105 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3106 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3107 event
.m_altDown
= TRUE
;
3109 event
.m_eventObject
= NULL
;
3110 event
.m_keyCode
= id
;
3111 /* begin Albert's fix for control and shift key 26.5 */
3112 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3113 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3114 /* end Albert's fix for control and shift key 26.5 */
3115 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3117 #if WXWIN_COMPATIBILITY
3118 if ( wxTheApp
&& wxTheApp
->OldOnCharHook(event
) )
3121 wxWindow
*win
= wxGetActiveWindow();
3124 if (win
->GetEventHandler()->ProcessEvent(event
))
3129 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3134 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3137 void wxWindow::SetSizeHints(const int minW
, const int minH
, const int maxW
, const int maxH
, const int WXUNUSED(incW
), const int WXUNUSED(incH
))
3145 void wxWindow::Centre(const int direction
)
3147 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3149 wxWindow
*father
= (wxWindow
*)GetParent();
3153 father
->GetClientSize(&panel_width
, &panel_height
);
3154 GetSize(&width
, &height
);
3155 GetPosition(&x
, &y
);
3160 if (direction
& wxHORIZONTAL
)
3161 new_x
= (int)((panel_width
- width
)/2);
3163 if (direction
& wxVERTICAL
)
3164 new_y
= (int)((panel_height
- height
)/2);
3166 SetSize(new_x
, new_y
, -1, -1);
3171 void wxWindow::OnPaint(void)
3173 PaintSelectionHandles();
3177 void wxWindow::WarpPointer (const int x_pos
, const int y_pos
)
3179 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3180 // pixel coordinates, relatives to the canvas -- So, we first need to
3181 // substract origin of the window, then convert to screen position
3183 int x
= x_pos
; int y
= y_pos
;
3184 /* Leave this to the app to decide (and/or wxScrolledWindow)
3185 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3186 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3189 GetWindowRect ((HWND
) GetHWND(), &rect
);
3194 SetCursorPos (x
, y
);
3197 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3200 // Do we have a SetUserScale in wxWindow too, so we can
3201 // get mouse events scaled?
3205 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3206 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3211 bool wxWindow::MSWOnEraseBkgnd (const WXHDC pDC
)
3219 wxEraseEvent
event(m_windowId
, &dc
);
3220 event
.m_eventObject
= this;
3221 if (!GetEventHandler()->ProcessEvent(event
))
3224 dc
.SelectOldObjects(pDC
);
3230 dc
.SelectOldObjects(pDC
);
3233 dc
.SetHDC((WXHDC
) NULL
);
3237 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3240 ::GetClientRect((HWND
) GetHWND(), &rect
);
3242 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3243 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3245 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3246 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3247 ::DeleteObject(hBrush
);
3248 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3250 // Less efficient version (and doesn't account for scrolling)
3252 GetClientSize(& w, & h);
3253 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3254 event.GetDC()->SetBrush(brush);
3255 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3257 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3261 #if WXWIN_COMPATIBILITY
3262 void wxWindow::SetScrollRange(const int orient
, const int range
, const bool refresh
)
3264 #if defined(__WIN95__)
3268 // Try to adjust the range to cope with page size > 1
3269 // - a Windows API quirk
3270 int pageSize
= GetScrollPage(orient
);
3271 if ( pageSize
> 1 && range
> 0)
3273 range1
+= (pageSize
- 1);
3279 if (orient
== wxHORIZONTAL
) {
3285 info
.cbSize
= sizeof(SCROLLINFO
);
3286 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3290 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3292 HWND hWnd
= (HWND
) GetHWND();
3294 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3297 if (orient
== wxHORIZONTAL
)
3302 HWND hWnd
= (HWND
) GetHWND();
3304 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3308 void wxWindow::SetScrollPage(const int orient
, const int page
, const bool refresh
)
3310 #if defined(__WIN95__)
3314 if (orient
== wxHORIZONTAL
) {
3316 m_xThumbSize
= page
;
3319 m_yThumbSize
= page
;
3322 info
.cbSize
= sizeof(SCROLLINFO
);
3325 info
.fMask
= SIF_PAGE
;
3327 HWND hWnd
= (HWND
) GetHWND();
3329 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3331 if (orient
== wxHORIZONTAL
)
3332 m_xThumbSize
= page
;
3334 m_yThumbSize
= page
;
3338 int wxWindow::OldGetScrollRange(const int orient
) const
3341 if (orient
== wxHORIZONTAL
)
3346 #if __WATCOMC__ && defined(__WINDOWS_386__)
3347 short minPos
, maxPos
;
3351 HWND hWnd
= (HWND
) GetHWND();
3354 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3355 #if defined(__WIN95__)
3356 // Try to adjust the range to cope with page size > 1
3357 // - a Windows API quirk
3358 int pageSize
= GetScrollPage(orient
);
3361 maxPos
-= (pageSize
- 1);
3370 int wxWindow::GetScrollPage(const int orient
) const
3372 if (orient
== wxHORIZONTAL
)
3373 return m_xThumbSize
;
3375 return m_yThumbSize
;
3379 int wxWindow::GetScrollPos(const int orient
) const
3382 if (orient
== wxHORIZONTAL
)
3386 HWND hWnd
= (HWND
) GetHWND();
3389 return ::GetScrollPos(hWnd
, wOrient
);
3395 // This now returns the whole range, not just the number
3396 // of positions that we can scroll.
3397 int wxWindow::GetScrollRange(const int orient
) const
3400 if (orient
== wxHORIZONTAL
)
3405 #if __WATCOMC__ && defined(__WINDOWS_386__)
3406 short minPos
, maxPos
;
3410 HWND hWnd
= (HWND
) GetHWND();
3413 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3414 #if defined(__WIN95__)
3415 // Try to adjust the range to cope with page size > 1
3416 // - a Windows API quirk
3417 int pageSize
= GetScrollPage(orient
);
3420 maxPos
-= (pageSize
- 1);
3422 // October 10th: new range concept.
3432 int wxWindow::GetScrollThumb(const int orient
) const
3434 if (orient
== wxHORIZONTAL
)
3435 return m_xThumbSize
;
3437 return m_yThumbSize
;
3440 void wxWindow::SetScrollPos(const int orient
, const int pos
, const bool refresh
)
3442 #if defined(__WIN95__)
3446 if (orient
== wxHORIZONTAL
) {
3452 info
.cbSize
= sizeof(SCROLLINFO
);
3456 info
.fMask
= SIF_POS
;
3458 HWND hWnd
= (HWND
) GetHWND();
3460 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3463 if (orient
== wxHORIZONTAL
)
3468 HWND hWnd
= (HWND
) GetHWND();
3470 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3474 // New function that will replace some of the above.
3475 void wxWindow::SetScrollbar(const int orient
, const int pos
, const int thumbVisible
,
3476 const int range
, const bool refresh
)
3479 SetScrollPage(orient, thumbVisible, FALSE);
3481 int oldRange = range - thumbVisible ;
3482 SetScrollRange(orient, oldRange, FALSE);
3484 SetScrollPos(orient, pos, refresh);
3486 #if defined(__WIN95__)
3487 int oldRange
= range
- thumbVisible
;
3489 int range1
= oldRange
;
3491 // Try to adjust the range to cope with page size > 1
3492 // - a Windows API quirk
3493 int pageSize
= thumbVisible
;
3494 if ( pageSize
> 1 && range
> 0)
3496 range1
+= (pageSize
- 1);
3502 if (orient
== wxHORIZONTAL
) {
3508 info
.cbSize
= sizeof(SCROLLINFO
);
3509 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3513 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3515 HWND hWnd
= (HWND
) GetHWND();
3517 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3520 if (orient
== wxHORIZONTAL
)
3525 HWND hWnd
= (HWND
) GetHWND();
3528 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3529 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3532 if (orient
== wxHORIZONTAL
) {
3533 m_xThumbSize
= thumbVisible
;
3535 m_yThumbSize
= thumbVisible
;
3539 void wxWindow::ScrollWindow(const int dx
, const int dy
, const wxRectangle
*rect
)
3544 rect2
.left
= rect
->x
;
3545 rect2
.top
= rect
->y
;
3546 rect2
.right
= rect
->x
+ rect
->width
;
3547 rect2
.bottom
= rect
->y
+ rect
->height
;
3551 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3553 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3556 void wxWindow::OnSize(wxSizeEvent
& event
)
3560 if (GetAutoLayout())
3566 void wxWindow::CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const
3572 void wxWindow::CalcUnscrolledPosition(const int x, const int y, float *xx, float *yy) const
3579 void wxWindow::SetFont(const wxFont
& font
)
3581 // Decrement the usage count of the old label font
3582 // (we may be able to free it up)
3583 // if (GetFont()->Ok())
3584 // GetFont()->ReleaseResource();
3586 m_windowFont
= font
;
3588 if (!m_windowFont
.Ok())
3591 // m_windowFont.UseResource();
3593 HWND hWnd
= (HWND
) GetHWND();
3596 // m_windowFont.RealizeResource();
3598 if (m_windowFont
.GetResourceHandle())
3599 SendMessage(hWnd
, WM_SETFONT
,
3600 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3604 void wxWindow::SubclassWin(WXHWND hWnd
)
3606 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3608 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3609 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3612 void wxWindow::UnsubclassWin(void)
3614 wxRemoveHandleAssociation(this);
3616 // Restore old Window proc
3617 if ((HWND
) GetHWND())
3619 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3620 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3622 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3628 // Make a Windows extended style from the given wxWindows window style
3629 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3631 WXDWORD exStyle
= 0;
3632 if ( style
& wxTRANSPARENT_WINDOW
)
3633 exStyle
|= WS_EX_TRANSPARENT
;
3635 if ( !eliminateBorders
)
3637 if ( style
& wxSUNKEN_BORDER
)
3638 exStyle
|= WS_EX_CLIENTEDGE
;
3639 if ( style
& wxDOUBLE_BORDER
)
3640 exStyle
|= WS_EX_DLGMODALFRAME
;
3641 #if defined(__WIN95__)
3642 if ( style
& wxRAISED_BORDER
)
3643 exStyle
|= WS_EX_WINDOWEDGE
;
3644 if ( style
& wxSTATIC_BORDER
)
3645 exStyle
|= WS_EX_STATICEDGE
;
3651 // Determines whether native 3D effects or CTL3D should be used,
3652 // applying a default border style if required, and returning an extended
3653 // style to pass to CreateWindowEx.
3654 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3656 // If matches certain criteria, then assume no 3D effects
3657 // unless specifically requested (dealt with in MakeExtendedStyle)
3658 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3661 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3664 // Determine whether we should be using 3D effects or not.
3665 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3667 // 1) App can specify global 3D effects
3668 *want3D
= wxTheApp
->GetAuto3D();
3670 // 2) If the parent is being drawn with user colours, or simple border specified,
3671 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3672 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3675 // 3) Control can override this global setting by defining
3676 // a border style, e.g. wxSUNKEN_BORDER
3677 if (m_windowStyle
& wxSUNKEN_BORDER
)
3680 // 4) If it's a special border, CTL3D can't cope so we want a native border
3681 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3682 (m_windowStyle
& wxSTATIC_BORDER
) )
3685 nativeBorder
= TRUE
;
3688 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3689 // effects from extended style
3692 nativeBorder
= FALSE
;
3695 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3697 // If we want 3D, but haven't specified a border here,
3698 // apply the default border style specified.
3699 // TODO what about non-Win95 WIN32? Does it have borders?
3700 #if defined(__WIN95__) && !CTL3D
3701 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3702 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3703 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3709 #if WXWIN_COMPATIBILITY
3710 void wxWindow::OldOnPaint(void)
3712 wxPaintEvent
event(m_windowId
);
3713 event
.m_eventObject
= this;
3714 if (!GetEventHandler()->ProcessEvent(event
))
3718 void wxWindow::OldOnSize(int w
, int h
)
3720 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
3721 event
.m_eventObject
= this;
3722 if (!GetEventHandler()->ProcessEvent(event
))
3726 void wxWindow::OldOnMouseEvent(wxMouseEvent
& event
)
3728 if (!GetEventHandler()->ProcessEvent(event
))
3732 void wxWindow::OldOnChar(wxKeyEvent
& event
)
3734 if (!GetEventHandler()->ProcessEvent(event
))
3738 void wxWindow::OldOnSetFocus(void)
3740 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3741 event
.m_eventObject
= this;
3742 if (!GetEventHandler()->ProcessEvent(event
))
3746 void wxWindow::OldOnKillFocus(void)
3748 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3749 event
.m_eventObject
= this;
3750 if (!GetEventHandler()->ProcessEvent(event
))
3755 void wxWindow::OnChar(wxKeyEvent
& event
)
3758 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3763 if ( !event
.ControlDown() )
3764 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3767 void wxWindow::OnPaint(wxPaintEvent
& event
)
3772 bool wxWindow::IsEnabled(void) const
3774 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3777 // Dialog support: override these and call
3778 // base class members to add functionality
3779 // that can't be done using validators.
3780 // NOTE: these functions assume that controls
3781 // are direct children of this window, not grandchildren
3782 // or other levels of descendant.
3784 // Transfer values to controls. If returns FALSE,
3785 // it's an application error (pops up a dialog)
3786 bool wxWindow::TransferDataToWindow(void)
3788 wxNode
*node
= GetChildren()->First();
3791 wxWindow
*child
= (wxWindow
*)node
->Data();
3792 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3793 !child
->GetValidator()->TransferToWindow() )
3795 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3799 node
= node
->Next();
3804 // Transfer values from controls. If returns FALSE,
3805 // validation failed: don't quit
3806 bool wxWindow::TransferDataFromWindow(void)
3808 wxNode
*node
= GetChildren()->First();
3811 wxWindow
*child
= (wxWindow
*)node
->Data();
3812 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3817 node
= node
->Next();
3822 bool wxWindow::Validate(void)
3824 wxNode
*node
= GetChildren()->First();
3827 wxWindow
*child
= (wxWindow
*)node
->Data();
3828 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3833 node
= node
->Next();
3838 // Get the window with the focus
3839 wxWindow
*wxWindow::FindFocus(void)
3841 HWND hWnd
= ::GetFocus();
3844 return wxFindWinFromHandle((WXHWND
) hWnd
);
3849 void wxWindow::AddChild(wxWindow
*child
)
3851 GetChildren()->Append(child
);
3852 child
->m_windowParent
= this;
3855 void wxWindow::RemoveChild(wxWindow
*child
)
3858 GetChildren()->DeleteObject(child
);
3859 child
->m_windowParent
= NULL
;
3862 void wxWindow::DestroyChildren(void)
3864 if (GetChildren()) {
3866 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3868 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3870 if ( GetChildren()->Member(child
) )
3877 void wxWindow::MakeModal(const bool modal
)
3879 // Disable all other windows
3880 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3882 wxNode
*node
= wxTopLevelWindows
.First();
3885 wxWindow
*win
= (wxWindow
*)node
->Data();
3887 win
->Enable(!modal
);
3889 node
= node
->Next();
3894 // If nothing defined for this, try the parent.
3895 // E.g. we may be a button loaded from a resource, with no callback function
3897 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3899 if (GetEventHandler()->ProcessEvent(event
) )
3902 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3905 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3909 UnsetConstraints(m_constraints
);
3910 delete m_constraints
;
3915 // Make sure other windows know they're part of a 'meaningful relationship'
3916 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3917 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3918 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3919 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3920 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3921 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3922 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3923 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3924 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3925 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3926 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3927 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3928 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3929 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3930 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3931 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3935 // This removes any dangling pointers to this window
3936 // in other windows' constraintsInvolvedIn lists.
3937 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3941 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3942 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3943 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3944 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3945 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3946 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3947 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3948 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3949 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3950 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3951 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3952 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3953 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3954 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3955 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3956 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3960 // Back-pointer to other windows we're involved with, so if we delete
3961 // this window, we must delete any constraints we're involved with.
3962 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3964 if (!m_constraintsInvolvedIn
)
3965 m_constraintsInvolvedIn
= new wxList
;
3966 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3967 m_constraintsInvolvedIn
->Append(otherWin
);
3970 // REMOVE back-pointer to other windows we're involved with.
3971 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3973 if (m_constraintsInvolvedIn
)
3974 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3977 // Reset any constraints that mention this window
3978 void wxWindow::DeleteRelatedConstraints(void)
3980 if (m_constraintsInvolvedIn
)
3982 wxNode
*node
= m_constraintsInvolvedIn
->First();
3985 wxWindow
*win
= (wxWindow
*)node
->Data();
3986 wxNode
*next
= node
->Next();
3987 wxLayoutConstraints
*constr
= win
->GetConstraints();
3989 // Reset any constraints involving this window
3992 constr
->left
.ResetIfWin((wxWindow
*)this);
3993 constr
->top
.ResetIfWin((wxWindow
*)this);
3994 constr
->right
.ResetIfWin((wxWindow
*)this);
3995 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3996 constr
->width
.ResetIfWin((wxWindow
*)this);
3997 constr
->height
.ResetIfWin((wxWindow
*)this);
3998 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3999 constr
->centreY
.ResetIfWin((wxWindow
*)this);
4004 delete m_constraintsInvolvedIn
;
4005 m_constraintsInvolvedIn
= NULL
;
4009 void wxWindow::SetSizer(wxSizer
*sizer
)
4011 m_windowSizer
= sizer
;
4013 sizer
->SetSizerParent((wxWindow
*)this);
4020 bool wxWindow::Layout(void)
4022 if (GetConstraints())
4025 GetClientSize(&w
, &h
);
4026 GetConstraints()->width
.SetValue(w
);
4027 GetConstraints()->height
.SetValue(h
);
4030 // If top level (one sizer), evaluate the sizer's constraints.
4034 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
4035 GetSizer()->LayoutPhase1(&noChanges
);
4036 GetSizer()->LayoutPhase2(&noChanges
);
4037 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
4042 // Otherwise, evaluate child constraints
4043 ResetConstraints(); // Mark all constraints as unevaluated
4044 DoPhase(1); // Just one phase need if no sizers involved
4046 SetConstraintSizes(); // Recursively set the real window sizes
4052 // Do a phase of evaluating constraints:
4053 // the default behaviour. wxSizers may do a similar
4054 // thing, but also impose their own 'constraints'
4055 // and order the evaluation differently.
4056 bool wxWindow::LayoutPhase1(int *noChanges
)
4058 wxLayoutConstraints
*constr
= GetConstraints();
4061 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
4067 bool wxWindow::LayoutPhase2(int *noChanges
)
4077 // Do a phase of evaluating child constraints
4078 bool wxWindow::DoPhase(const int phase
)
4080 int noIterations
= 0;
4081 int maxIterations
= 500;
4085 while ((noChanges
> 0) && (noIterations
< maxIterations
))
4089 wxNode
*node
= GetChildren()->First();
4092 wxWindow
*child
= (wxWindow
*)node
->Data();
4093 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
4095 wxLayoutConstraints
*constr
= child
->GetConstraints();
4098 if (succeeded
.Member(child
))
4103 int tempNoChanges
= 0;
4104 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
4105 noChanges
+= tempNoChanges
;
4108 succeeded
.Append(child
);
4113 node
= node
->Next();
4120 void wxWindow::ResetConstraints(void)
4122 wxLayoutConstraints
*constr
= GetConstraints();
4125 constr
->left
.SetDone(FALSE
);
4126 constr
->top
.SetDone(FALSE
);
4127 constr
->right
.SetDone(FALSE
);
4128 constr
->bottom
.SetDone(FALSE
);
4129 constr
->width
.SetDone(FALSE
);
4130 constr
->height
.SetDone(FALSE
);
4131 constr
->centreX
.SetDone(FALSE
);
4132 constr
->centreY
.SetDone(FALSE
);
4134 wxNode
*node
= GetChildren()->First();
4137 wxWindow
*win
= (wxWindow
*)node
->Data();
4138 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4139 win
->ResetConstraints();
4140 node
= node
->Next();
4144 // Need to distinguish between setting the 'fake' size for
4145 // windows and sizers, and setting the real values.
4146 void wxWindow::SetConstraintSizes(const bool recurse
)
4148 wxLayoutConstraints
*constr
= GetConstraints();
4149 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4150 constr
->width
.GetDone() && constr
->height
.GetDone())
4152 int x
= constr
->left
.GetValue();
4153 int y
= constr
->top
.GetValue();
4154 int w
= constr
->width
.GetValue();
4155 int h
= constr
->height
.GetValue();
4157 // If we don't want to resize this window, just move it...
4158 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4159 (constr
->height
.GetRelationship() != wxAsIs
))
4161 // Calls Layout() recursively. AAAGH. How can we stop that.
4162 // Simply take Layout() out of non-top level OnSizes.
4163 SizerSetSize(x
, y
, w
, h
);
4172 char *windowClass
= this->GetClassInfo()->GetClassName();
4175 if (GetName() == "")
4176 winName
= "unnamed";
4178 winName
= GetName();
4179 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4180 if (!constr
->left
.GetDone())
4181 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4182 if (!constr
->right
.GetDone())
4183 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4184 if (!constr
->width
.GetDone())
4185 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4186 if (!constr
->height
.GetDone())
4187 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4188 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4193 wxNode
*node
= GetChildren()->First();
4196 wxWindow
*win
= (wxWindow
*)node
->Data();
4197 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4198 win
->SetConstraintSizes();
4199 node
= node
->Next();
4204 // This assumes that all sizers are 'on' the same
4205 // window, i.e. the parent of this window.
4206 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4208 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4209 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4213 m_sizerParent
->GetPosition(&xp
, &yp
);
4214 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4219 void wxWindow::SizerSetSize(const int x
, const int y
, const int w
, const int h
)
4223 TransformSizerToActual(&xx
, &yy
);
4224 SetSize(xx
, yy
, w
, h
);
4227 void wxWindow::SizerMove(const int x
, const int y
)
4231 TransformSizerToActual(&xx
, &yy
);
4235 // Only set the size/position of the constraint (if any)
4236 void wxWindow::SetSizeConstraint(const int x
, const int y
, const int w
, const int h
)
4238 wxLayoutConstraints
*constr
= GetConstraints();
4243 constr
->left
.SetValue(x
);
4244 constr
->left
.SetDone(TRUE
);
4248 constr
->top
.SetValue(y
);
4249 constr
->top
.SetDone(TRUE
);
4253 constr
->width
.SetValue(w
);
4254 constr
->width
.SetDone(TRUE
);
4258 constr
->height
.SetValue(h
);
4259 constr
->height
.SetDone(TRUE
);
4264 void wxWindow::MoveConstraint(const int x
, const int y
)
4266 wxLayoutConstraints
*constr
= GetConstraints();
4271 constr
->left
.SetValue(x
);
4272 constr
->left
.SetDone(TRUE
);
4276 constr
->top
.SetValue(y
);
4277 constr
->top
.SetDone(TRUE
);
4282 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4284 wxLayoutConstraints
*constr
= GetConstraints();
4287 *w
= constr
->width
.GetValue();
4288 *h
= constr
->height
.GetValue();
4294 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4296 wxLayoutConstraints
*constr
= GetConstraints();
4299 *w
= constr
->width
.GetValue();
4300 *h
= constr
->height
.GetValue();
4303 GetClientSize(w
, h
);
4306 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4308 wxLayoutConstraints
*constr
= GetConstraints();
4311 *x
= constr
->left
.GetValue();
4312 *y
= constr
->top
.GetValue();
4318 bool wxWindow::Close(const bool force
)
4320 // Let's generalise it to work the same for any window.
4322 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4329 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4330 event
.SetEventObject(this);
4331 event
.SetForce(force
);
4333 return GetEventHandler()->ProcessEvent(event
);
4336 if ( !force && event.GetVeto() )
4341 if (!wxPendingDelete.Member(this))
4342 wxPendingDelete.Append(this);
4348 wxObject
* wxWindow::GetChild(const int number
) const
4350 // Return a pointer to the Nth object in the Panel
4353 wxNode
*node
= GetChildren()->First();
4356 node
= node
->Next() ;
4359 wxObject
*obj
= (wxObject
*)node
->Data();
4366 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4368 if (initiatingItem
->IsKindOf(CLASSINFO(wxListBox
)) && initiatingItem
->GetCallback())
4370 wxListBox
*lbox
= (wxListBox
*)initiatingItem
;
4371 wxCommandEvent
event(wxEVT_COMMAND_LEFT_DCLICK
);
4372 event
.m_commandInt
= -1;
4373 if ((lbox
->GetWindowStyleFlag() & wxLB_MULTIPLE
) == 0)
4375 event
.m_commandString
= copystring(lbox
->GetStringSelection());
4376 event
.m_commandInt
= lbox
->GetSelection();
4377 event
.m_clientData
= lbox
->wxListBox::GetClientData(event
.m_commandInt
);
4379 event
.m_eventObject
= lbox
;
4381 lbox
->ProcessCommand(event
);
4383 if (event
.m_commandString
)
4384 delete[] event
.m_commandString
;
4388 wxButton
*but
= GetDefaultItem();
4391 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
);
4392 but
->Command(event
);
4396 void wxWindow::Clear(void)
4398 wxClientDC
dc(this);
4399 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4400 dc
.SetBackground(brush
);
4404 // Fits the panel around the items
4405 void wxWindow::Fit(void)
4409 wxNode
*node
= GetChildren()->First();
4412 wxWindow
*win
= (wxWindow
*)node
->Data();
4414 win
->GetPosition(&wx
, &wy
);
4415 win
->GetSize(&ww
, &wh
);
4416 if ( wx
+ ww
> maxX
)
4418 if ( wy
+ wh
> maxY
)
4421 node
= node
->Next();
4423 SetClientSize(maxX
+ 5, maxY
+ 5);
4426 void wxWindow::SetValidator(const wxValidator
& validator
)
4428 if ( m_windowValidator
)
4429 delete m_windowValidator
;
4430 m_windowValidator
= validator
.Clone();
4432 if ( m_windowValidator
)
4433 m_windowValidator
->SetWindow(this) ;
4436 // Find a window by id or name
4437 wxWindow
*wxWindow::FindWindow(const long id
)
4442 wxNode
*node
= GetChildren()->First();
4445 wxWindow
*child
= (wxWindow
*)node
->Data();
4446 wxWindow
*found
= child
->FindWindow(id
);
4449 node
= node
->Next();
4454 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4456 if ( GetName() == name
)
4459 wxNode
*node
= GetChildren()->First();
4462 wxWindow
*child
= (wxWindow
*)node
->Data();
4463 wxWindow
*found
= child
->FindWindow(name
);
4466 node
= node
->Next();
4472 // Default input behaviour for a scrolling canvas should be to scroll
4473 // according to the cursor keys pressed
4474 void wxWindow::OnChar(wxKeyEvent& event)
4486 GetScrollUnitsPerPage(&x_page, &y_page);
4488 GetVirtualSize(&v_width,&v_height);
4490 ViewStart(&start_x, &start_y);
4493 y_pages = (int)(v_height/vert_units) - y_page;
4501 switch (event.keyCode)
4508 if (start_y - y_page > 0)
4509 Scroll(start_x, start_y - y_page);
4519 if ((y_page > 0) && (start_y <= y_pages-y-1))
4521 if (y_pages + y < start_y + y_page)
4522 Scroll(start_x, y_pages + y);
4524 Scroll(start_x, start_y + y_page);
4531 if ((y_page > 0) && (start_y >= 1))
4532 Scroll(start_x, start_y - 1);
4538 if ((y_page > 0) && (start_y <= y_pages-y-1))
4541 Scroll(start_x, start_y + 1);
4547 if ((x_page > 0) && (start_x >= 1))
4548 Scroll(start_x - 1, start_y);
4554 Scroll(start_x + 1, start_y);
4565 Scroll(start_x, y_pages+y);
4573 // Setup background and foreground colours correctly
4574 void wxWindow::SetupColours(void)
4577 SetBackgroundColour(GetParent()->GetBackgroundColour());
4580 // Do Update UI processing for child controls
4582 // TODO: should this be implemented for the child window rather
4583 // than the parent? Then you can override it e.g. for wxCheckBox
4584 // to do the Right Thing rather than having to assume a fixed number
4585 // of control classes.
4587 void wxWindow::UpdateWindowUI(void)
4589 wxWindowID id
= GetId();
4592 wxUpdateUIEvent
event(id
);
4593 event
.m_eventObject
= this;
4595 if (this->GetEventHandler()->ProcessEvent(event
))
4597 if (event
.GetSetEnabled())
4598 this->Enable(event
.GetEnabled());
4600 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4601 ((wxControl
*)this)->SetLabel(event
.GetText());
4603 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4605 if (event
.GetSetChecked())
4606 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4608 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4610 if (event
.GetSetChecked())
4611 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4618 void wxWindow::OnIdle(wxIdleEvent
& event
)
4620 // Check if we need to send a LEAVE event
4621 if (m_mouseInWindow
)
4624 ::GetCursorPos(&pt
);
4625 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4627 // Generate a LEAVE event
4628 m_mouseInWindow
= FALSE
;
4629 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4635 // Raise the window to the top of the Z order
4636 void wxWindow::Raise(void)
4638 ::BringWindowToTop((HWND
) GetHWND());
4641 // Lower the window to the bottom of the Z order
4642 void wxWindow::Lower(void)
4644 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);