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
;
475 // TODO: probably make WS_CLIPCHILDREN this a setting in wx/setup.h,
476 // to reduce flicker with the trade-off that groupboxes must paint in a solid
477 // colour (so your control order must be correct, and you can't easily draw a
478 // transparent group).
479 msflags
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPCHILDREN
;
482 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
484 // Even with extended styles, need to combine with WS_BORDER
485 // for them to look right.
486 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
487 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
488 msflags
|= WS_BORDER
;
490 m_mouseInWindow
= FALSE
;
493 m_windowId
= (int)NewControlId();
497 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
503 void wxWindow::SetFocus(void)
505 HWND hWnd
= (HWND
) GetHWND();
510 void wxWindow::Enable(const bool enable
)
512 m_winEnabled
= enable
;
513 HWND hWnd
= (HWND
) GetHWND();
515 ::EnableWindow(hWnd
, (BOOL
)enable
);
518 void wxWindow::CaptureMouse(void)
520 HWND hWnd
= (HWND
) GetHWND();
521 if (hWnd
&& !m_winCaptured
)
524 m_winCaptured
= TRUE
;
528 void wxWindow::ReleaseMouse(void)
533 m_winCaptured
= FALSE
;
537 // Push/pop event handler (i.e. allow a chain of event handlers
539 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
541 handler
->SetNextHandler(GetEventHandler());
542 SetEventHandler(handler
);
545 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
547 if ( GetEventHandler() )
549 wxEvtHandler
*handlerA
= GetEventHandler();
550 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
551 handlerA
->SetNextHandler(NULL
);
552 SetEventHandler(handlerB
);
565 #if USE_DRAG_AND_DROP
567 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
569 if ( m_pDropTarget
!= 0 ) {
570 m_pDropTarget
->Revoke(m_hWnd
);
571 delete m_pDropTarget
;
574 m_pDropTarget
= pDropTarget
;
575 if ( m_pDropTarget
!= 0 )
576 m_pDropTarget
->Register(m_hWnd
);
581 //old style file-manager drag&drop support
582 // I think we should retain the old-style
583 // DragAcceptFiles in parallel with SetDropTarget.
585 void wxWindow::DragAcceptFiles(const bool accept
)
587 HWND hWnd
= (HWND
) GetHWND();
589 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
593 void wxWindow::GetSize(int *x
, int *y
) const
595 HWND hWnd
= (HWND
) GetHWND();
597 GetWindowRect(hWnd
, &rect
);
598 *x
= rect
.right
- rect
.left
;
599 *y
= rect
.bottom
- rect
.top
;
602 void wxWindow::GetPosition(int *x
, int *y
) const
604 HWND hWnd
= (HWND
) GetHWND();
607 hParentWnd
= (HWND
) GetParent()->GetHWND();
610 GetWindowRect(hWnd
, &rect
);
612 // Since we now have the absolute screen coords,
613 // if there's a parent we must subtract its top left corner
619 ::ScreenToClient(hParentWnd
, &point
);
625 void wxWindow::ScreenToClient(int *x
, int *y
) const
627 HWND hWnd
= (HWND
) GetHWND();
631 ::ScreenToClient(hWnd
, &pt
);
637 void wxWindow::ClientToScreen(int *x
, int *y
) const
639 HWND hWnd
= (HWND
) GetHWND();
643 ::ClientToScreen(hWnd
, &pt
);
649 void wxWindow::SetCursor(const wxCursor
& cursor
)
651 m_windowCursor
= cursor
;
652 if (m_windowCursor
.Ok())
654 HWND hWnd
= (HWND
) GetHWND();
656 // Change the cursor NOW if we're within the correct window
658 ::GetCursorPos(&point
);
661 ::GetWindowRect(hWnd
, &rect
);
663 if (::PtInRect(&rect
, point
) && !wxIsBusy())
664 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
667 // This will cause big reentrancy problems if wxFlushEvents is implemented.
669 // return old_cursor;
673 // Get size *available for subwindows* i.e. excluding menu bar etc.
674 // For XView, this is the same as GetSize
675 void wxWindow::GetClientSize(int *x
, int *y
) const
677 HWND hWnd
= (HWND
) GetHWND();
679 GetClientRect(hWnd
, &rect
);
684 void wxWindow::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
686 int currentX
, currentY
;
687 GetPosition(¤tX
, ¤tY
);
688 int actualWidth
= width
;
689 int actualHeight
= height
;
692 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
694 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
697 int currentW
,currentH
;
698 GetSize(¤tW
, ¤tH
);
700 actualWidth
= currentW
;
702 actualHeight
= currentH
;
704 HWND hWnd
= (HWND
) GetHWND();
706 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
708 /* Not needed? should be called anyway via MoveWindow
709 if (!(width == -1) && (height == -1))
711 #if WXWIN_COMPATIBILITY
712 GetEventHandler()->OldOnSize(width, height);
714 wxSizeEvent event(wxSize(width, height), m_windowId);
715 event.eventObject = this;
716 GetEventHandler()->ProcessEvent(event);
722 void wxWindow::SetClientSize(const int width
, const int height
)
724 wxWindow
*parent
= GetParent();
725 HWND hWnd
= (HWND
) GetHWND();
726 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
729 GetClientRect(hWnd
, &rect
);
732 GetWindowRect(hWnd
, &rect2
);
734 // Find the difference between the entire window (title bar and all)
735 // and the client area; add this to the new client size to move the
737 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
738 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
740 // If there's a parent, must subtract the parent's top left corner
741 // since MoveWindow moves relative to the parent
744 point
.x
= rect2
.left
;
748 ::ScreenToClient(hParentWnd
, &point
);
751 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
752 #if WXWIN_COMPATIBILITY
753 GetEventHandler()->OldOnSize(width
, height
);
755 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
756 event
.m_eventObject
= this;
757 GetEventHandler()->ProcessEvent(event
);
761 bool wxWindow::Show(const bool show
)
763 HWND hWnd
= (HWND
) GetHWND();
769 ShowWindow(hWnd
, (BOOL
)cshow
);
772 BringWindowToTop(hWnd
);
773 // Next line causes a crash on NT, apparently.
774 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
779 bool wxWindow::IsShown(void) const
781 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
784 int wxWindow::GetCharHeight(void) const
786 TEXTMETRIC lpTextMetric
;
787 HWND hWnd
= (HWND
) GetHWND();
788 HDC dc
= ::GetDC(hWnd
);
790 GetTextMetrics(dc
, &lpTextMetric
);
791 ::ReleaseDC(hWnd
, dc
);
793 return lpTextMetric
.tmHeight
;
796 int wxWindow::GetCharWidth(void) const
798 TEXTMETRIC lpTextMetric
;
799 HWND hWnd
= (HWND
) GetHWND();
800 HDC dc
= ::GetDC(hWnd
);
802 GetTextMetrics(dc
, &lpTextMetric
);
803 ::ReleaseDC(hWnd
, dc
);
805 return lpTextMetric
.tmAveCharWidth
;
808 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
809 int *descent
, int *externalLeading
, const wxFont
*theFont
, const bool) const
811 wxFont
*fontToUse
= (wxFont
*)theFont
;
813 fontToUse
= (wxFont
*) & m_windowFont
;
815 HWND hWnd
= (HWND
) GetHWND();
816 HDC dc
= ::GetDC(hWnd
);
820 if (fontToUse
&& fontToUse
->Ok())
822 // fontToUse->UseResource();
824 // fontToUse->RealizeResource();
825 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
826 was
= SelectObject(dc
,fnt
) ;
831 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
832 GetTextMetrics(dc
, &tm
);
834 if (fontToUse
&& fnt
&& was
)
835 SelectObject(dc
,was
) ;
841 if (descent
) *descent
= tm
.tmDescent
;
842 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
845 // fontToUse->ReleaseResource();
848 #if WXWIN_COMPATIBILITY
849 void wxWindow::GetTextExtent(const wxString
& string
, float *x
, float *y
,
851 float *externalLeading
,
852 const wxFont
*theFont
, const bool use16
) const
854 int x1
, y1
, descent1
, externalLeading1
;
855 GetTextExtent(string
, &x1
, &y1
, &descent1
, &externalLeading1
, theFont
, use16
);
859 if ( externalLeading
)
860 *externalLeading
= externalLeading1
;
864 void wxWindow::Refresh(const bool eraseBack
, const wxRectangle
*rect
)
866 HWND hWnd
= (HWND
) GetHWND();
872 mswRect
.left
= rect
->x
;
873 mswRect
.top
= rect
->y
;
874 mswRect
.right
= rect
->x
+ rect
->width
;
875 mswRect
.bottom
= rect
->y
+ rect
->height
;
877 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
880 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
884 // TODO: Are these really necessary now?
886 WXHDC wxWindow::GetHDC(void) const
888 wxWindow *nonConst = (wxWindow *)this;
891 nonConst->m_tempHDC = (WXHDC) ::GetDC((HWND) GetHWND()) ;
895 void wxWindow::ReleaseHDC(void)
897 // We're within an OnPaint: it'll be released.
901 ::ReleaseDC((HWND) GetHWND(),(HDC) m_tempHDC) ;
905 // Hook for new window just as it's being created,
906 // when the window isn't yet associated with the handle
907 wxWindow
*wxWndHook
= NULL
;
911 // DDE Interface Handler
913 long ddeWindowProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);
914 void __ddeUnblock(HWND hWnd, WPARAM wParam);
919 // Main Windows 3 window proc
920 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
922 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
924 if (!wnd
&& wxWndHook
)
926 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
929 wnd
->m_hWnd
= (WXHWND
) hWnd
;
932 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
934 // Stop right here if we don't have a valid handle
935 // in our wxWnd object.
936 if (wnd
&& !wnd
->m_hWnd
) {
937 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
938 wnd
->m_hWnd
= (WXHWND
) hWnd
;
939 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
945 wnd
->m_lastMsg
= message
;
946 wnd
->m_lastWParam
= wParam
;
947 wnd
->m_lastLParam
= lParam
;
948 /* Don't know why this was here
949 if (message == WM_SETFONT)
951 else if (message == WM_INITDIALOG)
956 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
958 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
961 // Should probably have a test for 'genuine' NT
962 #if defined(__WIN32__)
963 #define DIMENSION_TYPE short
965 #define DIMENSION_TYPE int
968 // Main Windows 3 window proc
969 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
980 case WM_QUERYDRAGICON
:
984 case WM_RBUTTONDBLCLK
:
987 case WM_MBUTTONDBLCLK
:
990 case WM_LBUTTONDBLCLK
:
996 case WM_INITMENUPOPUP
:
1001 case WM_CHAR
: // Always an ASCII character
1004 case WM_CTLCOLORBTN
:
1005 case WM_CTLCOLORDLG
:
1006 case WM_CTLCOLORLISTBOX
:
1007 case WM_CTLCOLORMSGBOX
:
1008 case WM_CTLCOLORSCROLLBAR
:
1009 case WM_CTLCOLORSTATIC
:
1010 case WM_CTLCOLOREDIT
:
1011 case WM_SYSCOLORCHANGE
:
1013 case WM_MDIACTIVATE
:
1015 case WM_QUERYENDSESSION
:
1017 case WM_GETMINMAXINFO
:
1018 return MSWDefWindowProc(message
, wParam
, lParam
);
1023 HWND hWnd
= (HWND
)m_hWnd
;
1036 WORD state
= LOWORD(wParam
);
1037 WORD minimized
= HIWORD(wParam
);
1038 HWND hwnd
= (HWND
)lParam
;
1040 WORD state
= (WORD
)wParam
;
1041 WORD minimized
= LOWORD(lParam
);
1042 HWND hwnd
= (HWND
)HIWORD(lParam
);
1044 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
1050 HWND hwnd
= (HWND
)wParam
;
1051 // return OnSetFocus(hwnd);
1053 if (MSWOnSetFocus((WXHWND
) hwnd
))
1055 else return MSWDefWindowProc(message
, wParam
, lParam
);
1060 HWND hwnd
= (HWND
)lParam
;
1061 // return OnKillFocus(hwnd);
1062 if (MSWOnKillFocus((WXHWND
) hwnd
))
1065 return MSWDefWindowProc(message
, wParam
, lParam
);
1070 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
1076 MSWOnShow((wParam
!= 0), (int) lParam
);
1083 else return MSWDefWindowProc(message
, wParam
, lParam
);
1086 case WM_QUERYDRAGICON
:
1089 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1091 else return MSWDefWindowProc(message
, wParam
, lParam
);
1097 int width
= LOWORD(lParam
);
1098 int height
= HIWORD(lParam
);
1099 MSWOnSize(width
, height
, wParam
);
1103 case WM_WINDOWPOSCHANGING
:
1105 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1106 MSWOnWindowPosChanging((void *)pos
);
1110 case WM_RBUTTONDOWN
:
1112 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1113 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1114 MSWOnRButtonDown(x
, y
, wParam
);
1119 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1120 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1121 MSWOnRButtonUp(x
, y
, wParam
);
1124 case WM_RBUTTONDBLCLK
:
1126 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1127 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1128 MSWOnRButtonDClick(x
, y
, wParam
);
1131 case WM_MBUTTONDOWN
:
1133 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1134 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1135 MSWOnMButtonDown(x
, y
, wParam
);
1140 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1141 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1142 MSWOnMButtonUp(x
, y
, wParam
);
1145 case WM_MBUTTONDBLCLK
:
1147 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1148 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1149 MSWOnMButtonDClick(x
, y
, wParam
);
1152 case WM_LBUTTONDOWN
:
1154 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1155 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1156 MSWOnLButtonDown(x
, y
, wParam
);
1161 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1162 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1163 MSWOnLButtonUp(x
, y
, wParam
);
1166 case WM_LBUTTONDBLCLK
:
1168 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1169 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1170 MSWOnLButtonDClick(x
, y
, wParam
);
1175 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1176 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1177 MSWOnMouseMove(x
, y
, wParam
);
1180 case MM_JOY1BUTTONDOWN
:
1182 int x
= LOWORD(lParam
);
1183 int y
= HIWORD(lParam
);
1184 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1187 case MM_JOY2BUTTONDOWN
:
1189 int x
= LOWORD(lParam
);
1190 int y
= HIWORD(lParam
);
1191 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1194 case MM_JOY1BUTTONUP
:
1196 int x
= LOWORD(lParam
);
1197 int y
= HIWORD(lParam
);
1198 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1201 case MM_JOY2BUTTONUP
:
1203 int x
= LOWORD(lParam
);
1204 int y
= HIWORD(lParam
);
1205 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1210 int x
= LOWORD(lParam
);
1211 int y
= HIWORD(lParam
);
1212 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1217 int x
= LOWORD(lParam
);
1218 int y
= HIWORD(lParam
);
1219 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1224 int z
= LOWORD(lParam
);
1225 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1230 int z
= LOWORD(lParam
);
1231 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1238 else return MSWDefWindowProc(message
, wParam
, lParam
);
1243 return MSWOnSysCommand(wParam
, lParam
);
1249 WORD id
= LOWORD(wParam
);
1250 HWND hwnd
= (HWND
)lParam
;
1251 WORD cmd
= HIWORD(wParam
);
1253 WORD id
= (WORD
)wParam
;
1254 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1255 WORD cmd
= HIWORD(lParam
);
1257 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1258 return MSWDefWindowProc(message
, wParam
, lParam
);
1261 #if defined(__WIN95__)
1264 if (!MSWOnNotify(wParam
, lParam
))
1265 return MSWDefWindowProc(message
, wParam
, lParam
);
1272 WORD flags
= HIWORD(wParam
);
1273 HMENU sysmenu
= (HMENU
)lParam
;
1275 WORD flags
= LOWORD(lParam
);
1276 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1278 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1281 case WM_INITMENUPOPUP
:
1283 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1288 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1291 case WM_MEASUREITEM
:
1293 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1298 // return Default();
1300 if (wParam
== VK_SHIFT
)
1303 else if (wParam
== VK_CONTROL
)
1306 // Avoid duplicate messages to OnChar
1307 else if ((wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) && (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) && (wParam
!= VK_TAB
))
1309 MSWOnChar((WORD
)wParam
, lParam
);
1310 if (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
)
1320 if (wParam == VK_SHIFT)
1321 wxShiftDown = FALSE;
1322 else if (wParam == VK_CONTROL)
1323 wxControlDown = FALSE;
1327 case WM_CHAR
: // Always an ASCII character
1329 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1335 WORD code
= LOWORD(wParam
);
1336 WORD pos
= HIWORD(wParam
);
1337 HWND control
= (HWND
)lParam
;
1339 WORD code
= (WORD
)wParam
;
1340 WORD pos
= LOWORD(lParam
);
1341 HWND control
= (HWND
)HIWORD(lParam
);
1343 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1349 WORD code
= LOWORD(wParam
);
1350 WORD pos
= HIWORD(wParam
);
1351 HWND control
= (HWND
)lParam
;
1353 WORD code
= (WORD
)wParam
;
1354 WORD pos
= LOWORD(lParam
);
1355 HWND control
= (HWND
)HIWORD(lParam
);
1357 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1361 case WM_CTLCOLORBTN
:
1363 int nCtlColor
= CTLCOLOR_BTN
;
1364 HWND control
= (HWND
)lParam
;
1365 HDC pDC
= (HDC
)wParam
;
1366 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1367 message
, wParam
, lParam
);
1370 case WM_CTLCOLORDLG
:
1372 int nCtlColor
= CTLCOLOR_DLG
;
1373 HWND control
= (HWND
)lParam
;
1374 HDC pDC
= (HDC
)wParam
;
1375 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1376 message
, wParam
, lParam
);\
1379 case WM_CTLCOLORLISTBOX
:
1381 int nCtlColor
= CTLCOLOR_LISTBOX
;
1382 HWND control
= (HWND
)lParam
;
1383 HDC pDC
= (HDC
)wParam
;
1384 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1385 message
, wParam
, lParam
);
1388 case WM_CTLCOLORMSGBOX
:
1390 int nCtlColor
= CTLCOLOR_MSGBOX
;
1391 HWND control
= (HWND
)lParam
;
1392 HDC pDC
= (HDC
)wParam
;
1393 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1394 message
, wParam
, lParam
);
1397 case WM_CTLCOLORSCROLLBAR
:
1399 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1400 HWND control
= (HWND
)lParam
;
1401 HDC pDC
= (HDC
)wParam
;
1402 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1403 message
, wParam
, lParam
);
1406 case WM_CTLCOLORSTATIC
:
1408 int nCtlColor
= CTLCOLOR_STATIC
;
1409 HWND control
= (HWND
)lParam
;
1410 HDC pDC
= (HDC
)wParam
;
1411 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1412 message
, wParam
, lParam
);
1415 case WM_CTLCOLOREDIT
:
1417 int nCtlColor
= CTLCOLOR_EDIT
;
1418 HWND control
= (HWND
)lParam
;
1419 HDC pDC
= (HDC
)wParam
;
1420 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1421 message
, wParam
, lParam
);
1427 HWND control
= (HWND
)LOWORD(lParam
);
1428 int nCtlColor
= (int)HIWORD(lParam
);
1429 HDC pDC
= (HDC
)wParam
;
1430 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1431 message
, wParam
, lParam
);
1435 case WM_SYSCOLORCHANGE
:
1437 // Return value of 0 means, we processed it.
1438 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1441 return MSWDefWindowProc(message
, wParam
, lParam
);
1446 // Prevents flicker when dragging
1447 if (IsIconic(hWnd
)) return 1;
1451 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1452 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1456 case WM_MDIACTIVATE
:
1459 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1460 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1461 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1462 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1464 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1465 (HWND
)HIWORD(lParam
));
1470 MSWOnDropFiles(wParam
);
1475 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1478 case WM_QUERYENDSESSION
:
1480 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1481 return MSWOnClose();
1493 case WM_GETMINMAXINFO
:
1495 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1496 if (m_minSizeX
!= -1)
1497 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1498 if (m_minSizeY
!= -1)
1499 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1500 if (m_maxSizeX
!= -1)
1501 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1502 if (m_maxSizeY
!= -1)
1503 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1504 return MSWDefWindowProc(message
, wParam
, lParam
);
1512 __ddeUnblock(hWnd, wParam);
1516 case ASYNC_SELECT_MESSAGE:
1517 return ddeWindowProc(hWnd,message,wParam,lParam);
1522 return MSWDefWindowProc(message
, wParam
, lParam
);
1524 return 0; // Success: we processed this command.
1527 // Dialog window proc
1528 LONG APIENTRY _EXPORT
1529 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1534 wxList
*wxWinHandleList
= NULL
;
1535 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1537 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1540 return (wxWindow
*)node
->Data();
1543 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1545 // adding NULL hWnd is (first) surely a result of an error and
1546 // (secondly) breaks menu command processing
1547 wxCHECK( hWnd
!= NULL
);
1549 if ( !wxWinHandleList
->Find((long)hWnd
) )
1550 wxWinHandleList
->Append((long)hWnd
, win
);
1553 void wxRemoveHandleAssociation(wxWindow
*win
)
1555 wxWinHandleList
->DeleteObject(win
);
1558 // Default destroyer - override if you destroy it in some other way
1559 // (e.g. with MDI child windows)
1560 void wxWindow::MSWDestroyWindow(void)
1565 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1567 MSWDetachWindowMenu();
1568 // SetWindowLong(handle, 0, (long)0);
1569 HWND oldHandle
= handle
;
1572 ::DestroyWindow(oldHandle
);
1574 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1575 // or when Windows HWND is deleted if MDI parent or
1580 ::DestroyMenu(m_hMenu);
1587 void wxWindow::MSWCreate(const int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1588 const int x
, const int y
, const int width
, const int height
,
1589 const WXDWORD style
, const char *dialog_template
, const WXDWORD extendedStyle
)
1591 bool is_dialog
= (dialog_template
!= NULL
);
1592 int x1
= CW_USEDEFAULT
;
1594 int width1
= CW_USEDEFAULT
;
1597 // Find parent's size, if it exists, to set up a possible default
1598 // panel size the size of the parent window
1602 // Was GetWindowRect: JACS 5/5/95
1603 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1605 width1
= parent_rect
.right
- parent_rect
.left
;
1606 height1
= parent_rect
.bottom
- parent_rect
.top
;
1611 if (width
> -1) width1
= width
;
1612 if (height
> -1) height1
= height
;
1614 HWND hParent
= NULL
;
1616 hParent
= (HWND
) parent
->GetHWND();
1622 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1623 // other compilers???
1624 // VZ: it's always needed for Win16 and never for Win32
1626 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1627 (DLGPROC
)wxDlgProc
);
1629 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1631 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1636 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1637 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1638 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1643 if (style
& WS_CHILD
)
1648 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1653 // hParent, NULL, wxGetInstance(),
1654 hParent
, (HMENU
)controlId
, wxGetInstance(),
1660 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1663 "Fatal wxWindows Error");
1667 wxWinHandleList
->Append((long)m_hWnd
, this);
1670 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1674 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1678 bool wxWindow::MSWOnClose(void)
1681 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1686 bool wxWindow::MSWOnDestroy(void)
1689 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1691 // delete our drop target if we've got one
1692 #if USE_DRAG_AND_DROP
1693 if ( m_pDropTarget
!= NULL
) {
1694 m_pDropTarget
->Revoke(m_hWnd
);
1696 delete m_pDropTarget
;
1697 m_pDropTarget
= NULL
;
1704 // Deal with child commands from buttons etc.
1706 bool wxWindow::MSWOnNotify(const WXWPARAM wParam
, const WXLPARAM lParam
)
1708 #if defined(__WIN95__)
1709 // Find a child window to send the notification to, e.g. a toolbar.
1710 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1711 // handle of the toolbar; it's probably the handle of the tooltip
1712 // window (anyway, it's parent is also the toolbar's parent).
1713 // So, since we don't know which hWnd or wxWindow originated the
1714 // WM_NOTIFY, we'll need to go through all the children of this window
1715 // trying out MSWNotify.
1716 // This won't work now, though, because any number of controls
1717 // could respond to the same generic messages :-(
1719 /* This doesn't work for toolbars, but try for other controls first.
1721 NMHDR
*hdr
= (NMHDR
*)lParam
;
1722 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1723 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1726 return win
->MSWNotify(wParam
, lParam
);
1729 // Rely on MSWNotify to check whether the message
1730 // belongs to the window or not
1731 wxNode
*node
= GetChildren()->First();
1734 wxWindow
*child
= (wxWindow
*)node
->Data();
1735 if ( child
->MSWNotify(wParam
, lParam
) )
1737 node
= node
->Next();
1747 void wxWindow::MSWOnMenuHighlight(const WXWORD
WXUNUSED(item
), const WXWORD
WXUNUSED(flags
), const WXHMENU
WXUNUSED(sysmenu
))
1750 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1754 void wxWindow::MSWOnInitMenuPopup(const WXHMENU menu
, const int pos
, const bool isSystem
)
1757 OldOnInitMenuPopup(pos
);
1760 bool wxWindow::MSWOnActivate(const int state
, const bool WXUNUSED(minimized
), const WXHWND
WXUNUSED(activate
))
1763 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1766 #if WXWIN_COMPATIBILITY
1767 GetEventHandler()->OldOnActivate(((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)));
1769 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1771 event
.m_eventObject
= this;
1772 GetEventHandler()->ProcessEvent(event
);
1777 bool wxWindow::MSWOnSetFocus(const WXHWND
WXUNUSED(hwnd
))
1780 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1783 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1785 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1787 ::ShowCaret((HWND
) GetHWND());
1790 #if WXWIN_COMPATIBILITY
1791 GetEventHandler()->OldOnSetFocus();
1793 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1794 event
.m_eventObject
= this;
1795 GetEventHandler()->ProcessEvent(event
);
1800 bool wxWindow::MSWOnKillFocus(const WXHWND
WXUNUSED(hwnd
))
1803 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1811 #if WXWIN_COMPATIBILITY
1812 GetEventHandler()->OldOnKillFocus();
1814 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1815 event
.m_eventObject
= this;
1816 GetEventHandler()->ProcessEvent(event
);
1821 void wxWindow::MSWOnDropFiles(const WXWPARAM wParam
)
1824 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1827 HANDLE hFilesInfo
= (HANDLE
)wParam
;
1829 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1831 // Get the total number of files dropped
1832 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1837 wxString
*files
= new wxString
[gwFilesDropped
];
1839 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1841 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1842 files
[wIndex
] = wxBuffer
;
1844 DragFinish (hFilesInfo
);
1846 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1847 event
.m_eventObject
= this;
1848 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1850 GetEventHandler()->ProcessEvent(event
);
1855 bool wxWindow::MSWOnDrawItem(const int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1858 if ( id
== 0 ) { // is it a menu item?
1859 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1860 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1861 wxCHECK_RET( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1863 // prepare to call OnDrawItem()
1865 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1866 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1867 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1868 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1869 return pMenuItem
->OnDrawItem(
1871 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1872 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1875 #endif // owner-drawn menus
1877 wxWindow
*item
= FindItem(id
);
1878 #if USE_DYNAMIC_CLASSES
1879 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1881 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1888 bool wxWindow::MSWOnMeasureItem(const int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1891 if ( id
== 0 ) { // is it a menu item?
1892 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1893 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1894 wxCHECK_RET( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1896 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1897 &pMeasureStruct
->itemHeight
);
1899 #endif // owner-drawn menus
1901 wxWindow
*item
= FindItem(id
);
1902 #if USE_DYNAMIC_CLASSES
1903 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1905 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1912 WXHBRUSH
wxWindow::MSWOnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
1913 const WXUINT message
, const WXWPARAM wParam
, const WXLPARAM lParam
)
1916 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1918 if (nCtlColor
== CTLCOLOR_DLG
)
1920 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1923 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1925 WXHBRUSH hBrush
= 0;
1928 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1930 // I think that even for dialogs, we may need to call DefWindowProc (?)
1931 // Or maybe just rely on the usual default behaviour.
1933 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1938 // Define for each class of dialog and control
1939 WXHBRUSH
wxWindow::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
1940 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1942 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1945 bool wxWindow::MSWOnColorChange(const WXHWND hWnd
, const WXUINT message
, const WXWPARAM wParam
, const WXLPARAM lParam
)
1947 wxSysColourChangedEvent event
;
1948 event
.m_eventObject
= this;
1950 // Check if app handles this.
1951 if (GetEventHandler()->ProcessEvent(event
))
1954 #if WXWIN_COMPATIBILITY
1955 if (GetEventHandler()->OldOnSysColourChange())
1959 // We didn't process it
1963 // Responds to colour changes: passes event on to children.
1964 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1966 wxNode
*node
= GetChildren()->First();
1969 // Only propagate to non-top-level windows
1970 wxWindow
*win
= (wxWindow
*)node
->Data();
1971 if ( win
->GetParent() )
1973 wxSysColourChangedEvent event2
;
1974 event
.m_eventObject
= win
;
1975 win
->GetEventHandler()->ProcessEvent(event2
);
1978 node
= node
->Next();
1982 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1985 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1987 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1990 long wxWindow::Default()
1992 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1995 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
2001 // Suggestion by Andrew Davison to allow
2002 // a panel to accept character input in user edit mode
2004 // OK, what we probably want to do here for wxWin 2.0
2005 // is have a window style to indicate whether the window
2006 // should process dialog-style input, since we can't
2007 // otherwise tell whether it's supposed to do tab traversal
2009 if (GetWindowStyleFlag() & wxTAB_TRAVERSAL
)
2010 return (::IsDialogMessage((HWND
) m_hWnd
, (MSG
*)pMsg
) != 0);
2016 long wxWindow::MSWOnMDIActivate(const long WXUNUSED(flag
), const WXHWND
WXUNUSED(activate
), const WXHWND
WXUNUSED(deactivate
))
2019 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
2024 void wxWindow::MSWDetachWindowMenu(void)
2028 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
2030 for (i
= 0; i
< N
; i
++)
2033 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
2034 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
2036 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
2043 bool wxWindow::MSWOnPaint(void)
2045 #if WXWIN_COMPATIBILITY
2046 GetEventHandler()->OldOnPaint();
2048 wxPaintEvent
event(m_windowId
);
2049 event
.m_eventObject
= this;
2050 GetEventHandler()->ProcessEvent(event
);
2057 wxDebugMsg("wxWindow::MSWOnPaint %d\n", m_hWnd
);
2060 HRGN tRgn
=CreateRectRgn(0,0,0,0); //Dummy call to get a handle!
2061 if (GetUpdateRgn(m_hWnd
, tRgn
, FALSE
))
2064 if (GetUpdateRect((HWND
) m_hWnd
, &tRect
, FALSE
))
2068 // Hold a pointer to the dc so long as the OnPaint() message
2069 // is being processed
2070 HDC dc
= BeginPaint(m_hWnd
, &ps
);
2071 bool isPanel
= IsKindOf(CLASSINFO(wxWindow
));
2072 m_paintHDC
= (WXHDC
) dc
;
2073 RECT updateRect1
= ps
.rcPaint
;
2074 m_updateRect
.x
= updateRect1
.left
;
2075 m_updateRect
.y
= updateRect1
.top
;
2076 m_updateRect
.width
= updateRect1
.right
- updateRect1
.left
;
2077 m_updateRect
.height
= updateRect1
.bottom
- updateRect1
.top
;
2079 GetEventHandler()->OldOnPaint();
2082 EndPaint((HWND
) m_hWnd
, &ps
);
2088 // Do default processing
2100 void wxWindow::MSWOnSize(const int w
, const int h
, const WXUINT
WXUNUSED(flag
))
2106 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2113 #if WXWIN_COMPATIBILITY
2114 GetEventHandler()->OldOnSize(w
, h
);
2116 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2117 event
.m_eventObject
= this;
2118 GetEventHandler()->ProcessEvent(event
);
2124 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2129 // Deal with child commands from buttons etc.
2130 bool wxWindow::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND
WXUNUSED(control
))
2133 wxDebugMsg("wxWindow::MSWOnCommand\n");
2135 if (wxCurrentPopupMenu
)
2137 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2138 wxCurrentPopupMenu
= NULL
;
2139 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2144 sprintf(buf
, "Looking for item %d...\n", id
);
2148 wxWindow
*item
= FindItem(id
);
2151 bool value
= item
->MSWCommand(cmd
, id
);
2154 wxDebugMsg("MSWCommand succeeded\n");
2156 wxDebugMsg("MSWCommand failed\n");
2163 wxDebugMsg("Could not find item!\n");
2165 wxDebugMsg("Item ids for this panel:\n");
2167 wxNode
*current
= GetChildren()->First();
2170 wxObject
*obj
= (wxObject
*)current
->Data() ;
2171 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2173 wxControl
*item
= (wxControl
*)current
->Data();
2174 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2177 current
= current
->Next();
2185 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2191 wxMaximizeEvent
event(m_windowId
);
2192 event
.SetEventObject(this);
2193 if (!GetEventHandler()->ProcessEvent(event
))
2201 wxIconizeEvent
event(m_windowId
);
2202 event
.SetEventObject(this);
2203 if (!GetEventHandler()->ProcessEvent(event
))
2215 void wxWindow::MSWOnLButtonDown(const int x
, const int y
, const WXUINT flags
)
2217 #if 0 // defined(__WIN32__) && !defined(WIN95)
2218 // DClick not clean supported on Win3.1, except if someone know
2219 // how to emulate Sleep()...
2220 // This means that your app will receive Down-Up-Dclick sequences
2221 // rather than Dclick
2222 if (m_doubleClickAllowed
)
2224 UINT time
= GetDoubleClickTime() ;
2227 if (PeekMessage(&dummy
,m_hWnd
,
2228 WM_LBUTTONDBLCLK
,WM_LBUTTONDBLCLK
,
2232 PeekMessage(&dummy
,m_hWnd
,WM_LBUTTONUP
,WM_LBUTTONUP
,PM_REMOVE
);
2238 wxMouseEvent
event(wxEVENT_TYPE_LEFT_DOWN
);
2240 event
.m_x
= x
; event
.m_y
= y
;
2241 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2242 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2243 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2244 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2245 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2246 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2247 event
.m_eventObject
= this;
2249 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2250 GetEventHandler()->OldOnMouseEvent(event
);
2253 void wxWindow::MSWOnLButtonUp(const int x
, const int y
, const WXUINT flags
)
2255 wxMouseEvent
event(wxEVENT_TYPE_LEFT_UP
);
2257 event
.m_x
= x
; event
.m_y
= y
;
2258 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2259 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2260 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2261 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2262 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2263 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2264 event
.m_eventObject
= this;
2266 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_UP
;
2268 GetEventHandler()->OldOnMouseEvent(event
);
2271 void wxWindow::MSWOnLButtonDClick(const int x
, const int y
, const WXUINT flags
)
2273 /* MATTHEW: If dclick not allowed, generate another single-click */
2274 wxMouseEvent
event(m_doubleClickAllowed
?
2275 wxEVENT_TYPE_LEFT_DCLICK
: wxEVENT_TYPE_LEFT_DOWN
);
2277 event
.m_x
= x
; event
.m_y
= y
;
2278 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2279 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2280 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2281 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2282 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2283 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2284 event
.m_eventObject
= this;
2286 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DCLICK
;
2288 // if (m_doubleClickAllowed)
2289 GetEventHandler()->OldOnMouseEvent(event
);
2292 void wxWindow::MSWOnMButtonDown(const int x
, const int y
, const WXUINT flags
)
2294 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2295 // DClick not clean supported on Win3.1, except if someone know
2296 // how to emulate Sleep()...
2297 // This means that your app will receive Down-Up-Dclick sequences
2298 // rather than Dclick
2299 if (m_doubleClickAllowed
)
2301 UINT time
= GetDoubleClickTime() ;
2304 if (PeekMessage(&dummy
,m_hWnd
,
2305 WM_MBUTTONDBLCLK
,WM_MBUTTONDBLCLK
,
2309 PeekMessage(&dummy
,m_hWnd
,WM_MBUTTONUP
,WM_MBUTTONUP
,PM_REMOVE
);
2315 wxMouseEvent
event(wxEVENT_TYPE_MIDDLE_DOWN
);
2317 event
.m_x
= x
; event
.m_y
= y
;
2318 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2319 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2320 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2321 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2322 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2323 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2324 event
.m_eventObject
= this;
2326 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2327 GetEventHandler()->OldOnMouseEvent(event
);
2330 void wxWindow::MSWOnMButtonUp(const int x
, const int y
, const WXUINT flags
)
2332 //wxDebugMsg("MButtonUp\n") ;
2333 wxMouseEvent
event(wxEVENT_TYPE_MIDDLE_UP
);
2335 event
.m_x
= x
; event
.m_y
= y
;
2336 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2337 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2338 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2339 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2340 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2341 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2342 event
.m_eventObject
= this;
2344 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_UP
;
2345 GetEventHandler()->OldOnMouseEvent(event
);
2348 void wxWindow::MSWOnMButtonDClick(const int x
, const int y
, const WXUINT flags
)
2350 //wxDebugMsg("MButtonDClick\n") ;
2351 /* MATTHEW: If dclick not allowed, generate another single-click */
2352 wxMouseEvent
event((m_doubleClickAllowed
) ?
2353 wxEVENT_TYPE_MIDDLE_DCLICK
: wxEVENT_TYPE_MIDDLE_DOWN
);
2355 event
.m_x
= x
; event
.m_y
= y
;
2356 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2357 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2358 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2359 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2360 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2361 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2362 event
.m_eventObject
= this;
2364 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DCLICK
;
2365 // if (m_doubleClickAllowed)
2366 GetEventHandler()->OldOnMouseEvent(event
);
2369 void wxWindow::MSWOnRButtonDown(const int x
, const int y
, const WXUINT flags
)
2371 #if 0 // defined(__WIN32__) && !defined(__WIN95__)
2372 // DClick not clean supported on Win3.1, except if someone know
2373 // how to emulate Sleep()...
2374 // This means that your app will receive Down-Up-Dclick sequences
2375 // rather than Dclick
2376 if (m_doubleClickAllowed
)
2378 UINT time
= GetDoubleClickTime() ;
2381 if (PeekMessage(&dummy
,m_hWnd
,
2382 WM_RBUTTONDBLCLK
,WM_RBUTTONDBLCLK
,
2386 PeekMessage(&dummy
,m_hWnd
,WM_RBUTTONUP
,WM_RBUTTONUP
,PM_REMOVE
);
2392 wxMouseEvent
event(wxEVENT_TYPE_RIGHT_DOWN
);
2394 event
.m_x
= x
; event
.m_y
= y
;
2395 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2396 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2397 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2398 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2399 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2400 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2401 event
.m_eventObject
= this;
2403 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_DOWN
;
2404 GetEventHandler()->OldOnMouseEvent(event
);
2407 void wxWindow::MSWOnRButtonUp(const int x
, const int y
, const WXUINT flags
)
2409 wxMouseEvent
event(wxEVENT_TYPE_RIGHT_UP
);
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
.m_eventObject
= this;
2418 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2420 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_UP
;
2421 GetEventHandler()->OldOnMouseEvent(event
);
2424 void wxWindow::MSWOnRButtonDClick(const int x
, const int y
, const WXUINT flags
)
2426 /* MATTHEW: If dclick not allowed, generate another single-click */
2427 wxMouseEvent
event((m_doubleClickAllowed
) ?
2428 wxEVENT_TYPE_RIGHT_DCLICK
: wxEVENT_TYPE_RIGHT_DOWN
);
2430 event
.m_x
= x
; event
.m_y
= y
;
2431 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2432 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2433 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2434 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2435 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2436 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2437 event
.m_eventObject
= this;
2439 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_RIGHT_DCLICK
;
2440 // if (m_doubleClickAllowed)
2441 GetEventHandler()->OldOnMouseEvent(event
);
2444 void wxWindow::MSWOnMouseMove(const int x
, const int y
, const WXUINT flags
)
2446 // 'normal' move event...
2447 // Set cursor, but only if we're not in 'busy' mode
2449 // Trouble with this is that it sets the cursor for controls too :-(
2450 if (m_windowCursor
.Ok() && !wxIsBusy())
2451 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2453 if (!m_mouseInWindow
)
2455 // Generate an ENTER event
2456 m_mouseInWindow
= TRUE
;
2457 MSWOnMouseEnter(x
, y
, flags
);
2460 wxMouseEvent
event(wxEVENT_TYPE_MOTION
);
2462 event
.m_x
= x
; event
.m_y
= y
;
2463 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2464 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2465 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2466 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2467 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2468 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2469 event
.m_eventObject
= this;
2471 // Window gets a click down message followed by a mouse move
2472 // message even if position isn't changed! We want to discard
2473 // the trailing move event if x and y are the same.
2474 if ((m_lastEvent
== wxEVENT_TYPE_RIGHT_DOWN
|| m_lastEvent
== wxEVENT_TYPE_LEFT_DOWN
||
2475 m_lastEvent
== wxEVENT_TYPE_MIDDLE_DOWN
) &&
2476 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2478 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2479 m_lastEvent
= wxEVENT_TYPE_MOTION
;
2483 m_lastEvent
= wxEVENT_TYPE_MOTION
;
2484 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2485 GetEventHandler()->OldOnMouseEvent(event
);
2488 void wxWindow::MSWOnMouseEnter(const int x
, const int y
, const WXUINT flags
)
2490 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2492 event
.m_x
= x
; event
.m_y
= y
;
2493 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2494 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2495 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2496 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2497 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2498 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2499 event
.m_eventObject
= this;
2501 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2502 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2503 GetEventHandler()->OldOnMouseEvent(event
);
2506 void wxWindow::MSWOnMouseLeave(const int x
, const int y
, const WXUINT flags
)
2508 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2510 event
.m_x
= x
; event
.m_y
= y
;
2511 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2512 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2513 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2514 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2515 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2516 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2517 event
.m_eventObject
= this;
2519 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2520 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2521 GetEventHandler()->OldOnMouseEvent(event
);
2524 void wxWindow::MSWOnChar(const WXWORD wParam
, const WXLPARAM lParam
, const bool isASCII
)
2527 bool tempControlDown
= FALSE
;
2530 // If 1 -> 26, translate to CTRL plus a letter.
2532 if ((id
> 0) && (id
< 27))
2553 tempControlDown
= TRUE
;
2560 if ((id
= wxCharCodeMSWToWX(wParam
)) == 0)
2565 wxKeyEvent
event(wxEVT_CHAR
);
2566 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2567 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2568 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2569 event
.m_altDown
= TRUE
;
2571 event
.m_eventObject
= this;
2572 event
.m_keyCode
= id
;
2573 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2578 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2582 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2584 #if WXWIN_COMPATIBILITY
2585 GetEventHandler()->OldOnChar(event
);
2587 if (!GetEventHandler()->ProcessEvent(event
))
2593 void wxWindow::MSWOnJoyDown(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2597 if (flags
& JOY_BUTTON1CHG
)
2598 change
= wxJOY_BUTTON1
;
2599 if (flags
& JOY_BUTTON2CHG
)
2600 change
= wxJOY_BUTTON2
;
2601 if (flags
& JOY_BUTTON3CHG
)
2602 change
= wxJOY_BUTTON3
;
2603 if (flags
& JOY_BUTTON4CHG
)
2604 change
= wxJOY_BUTTON4
;
2606 if (flags
& JOY_BUTTON1
)
2607 buttons
|= wxJOY_BUTTON1
;
2608 if (flags
& JOY_BUTTON2
)
2609 buttons
|= wxJOY_BUTTON2
;
2610 if (flags
& JOY_BUTTON3
)
2611 buttons
|= wxJOY_BUTTON3
;
2612 if (flags
& JOY_BUTTON4
)
2613 buttons
|= wxJOY_BUTTON4
;
2615 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2616 event
.SetPosition(wxPoint(x
, y
));
2617 event
.SetEventObject(this);
2619 GetEventHandler()->ProcessEvent(event
);
2622 void wxWindow::MSWOnJoyUp(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2626 if (flags
& JOY_BUTTON1CHG
)
2627 change
= wxJOY_BUTTON1
;
2628 if (flags
& JOY_BUTTON2CHG
)
2629 change
= wxJOY_BUTTON2
;
2630 if (flags
& JOY_BUTTON3CHG
)
2631 change
= wxJOY_BUTTON3
;
2632 if (flags
& JOY_BUTTON4CHG
)
2633 change
= wxJOY_BUTTON4
;
2635 if (flags
& JOY_BUTTON1
)
2636 buttons
|= wxJOY_BUTTON1
;
2637 if (flags
& JOY_BUTTON2
)
2638 buttons
|= wxJOY_BUTTON2
;
2639 if (flags
& JOY_BUTTON3
)
2640 buttons
|= wxJOY_BUTTON3
;
2641 if (flags
& JOY_BUTTON4
)
2642 buttons
|= wxJOY_BUTTON4
;
2644 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2645 event
.SetPosition(wxPoint(x
, y
));
2646 event
.SetEventObject(this);
2648 GetEventHandler()->ProcessEvent(event
);
2651 void wxWindow::MSWOnJoyMove(const int joystick
, const int x
, const int y
, const WXUINT flags
)
2654 if (flags
& JOY_BUTTON1
)
2655 buttons
|= wxJOY_BUTTON1
;
2656 if (flags
& JOY_BUTTON2
)
2657 buttons
|= wxJOY_BUTTON2
;
2658 if (flags
& JOY_BUTTON3
)
2659 buttons
|= wxJOY_BUTTON3
;
2660 if (flags
& JOY_BUTTON4
)
2661 buttons
|= wxJOY_BUTTON4
;
2663 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2664 event
.SetPosition(wxPoint(x
, y
));
2665 event
.SetEventObject(this);
2667 GetEventHandler()->ProcessEvent(event
);
2670 void wxWindow::MSWOnJoyZMove(const int joystick
, const int z
, const WXUINT flags
)
2673 if (flags
& JOY_BUTTON1
)
2674 buttons
|= wxJOY_BUTTON1
;
2675 if (flags
& JOY_BUTTON2
)
2676 buttons
|= wxJOY_BUTTON2
;
2677 if (flags
& JOY_BUTTON3
)
2678 buttons
|= wxJOY_BUTTON3
;
2679 if (flags
& JOY_BUTTON4
)
2680 buttons
|= wxJOY_BUTTON4
;
2682 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2683 event
.SetZPosition(z
);
2684 event
.SetEventObject(this);
2686 GetEventHandler()->ProcessEvent(event
);
2689 void wxWindow::MSWOnVScroll(const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2693 wxWindow
*child
= wxFindWinFromHandle(control
);
2695 child
->MSWOnVScroll(wParam
, pos
, control
);
2699 wxScrollEvent event
;
2700 event
.SetPosition(pos
);
2701 event
.SetOrientation(wxVERTICAL
);
2702 event
.m_eventObject
= this;
2707 event
.m_eventType
= wxEVENT_TYPE_SCROLL_TOP
;
2711 event
.m_eventType
= wxEVENT_TYPE_SCROLL_BOTTOM
;
2715 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEUP
;
2719 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEDOWN
;
2723 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEUP
;
2727 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEDOWN
;
2731 case SB_THUMBPOSITION
:
2732 event
.m_eventType
= wxEVENT_TYPE_SCROLL_THUMBTRACK
;
2740 if (!GetEventHandler()->ProcessEvent(event
))
2741 #if WXWIN_COMPATIBILITY
2742 GetEventHandler()->OldOnScroll(event
);
2748 void wxWindow::MSWOnHScroll( const WXWORD wParam
, const WXWORD pos
, const WXHWND control
)
2752 wxWindow
*child
= wxFindWinFromHandle(control
);
2754 child
->MSWOnHScroll(wParam
, pos
, control
);
2758 wxScrollEvent event
;
2759 event
.SetPosition(pos
);
2760 event
.SetOrientation(wxHORIZONTAL
);
2761 event
.m_eventObject
= this;
2766 event
.m_eventType
= wxEVENT_TYPE_SCROLL_TOP
;
2770 event
.m_eventType
= wxEVENT_TYPE_SCROLL_BOTTOM
;
2774 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEUP
;
2778 event
.m_eventType
= wxEVENT_TYPE_SCROLL_LINEDOWN
;
2782 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEUP
;
2786 event
.m_eventType
= wxEVENT_TYPE_SCROLL_PAGEDOWN
;
2790 case SB_THUMBPOSITION
:
2791 event
.m_eventType
= wxEVENT_TYPE_SCROLL_THUMBTRACK
;
2798 if (!GetEventHandler()->ProcessEvent(event
))
2799 #if WXWIN_COMPATIBILITY
2800 GetEventHandler()->OldOnScroll(event
);
2806 void wxWindow::MSWOnShow(bool show
, int status
)
2808 wxShowEvent
event(GetId(), show
);
2809 event
.m_eventObject
= this;
2810 GetEventHandler()->ProcessEvent(event
);
2813 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2815 wxInitDialogEvent
event(GetId());
2816 event
.m_eventObject
= this;
2817 GetEventHandler()->ProcessEvent(event
);
2821 void wxWindow::InitDialog(void)
2823 wxInitDialogEvent
event(GetId());
2824 event
.SetEventObject( this );
2825 GetEventHandler()->ProcessEvent(event
);
2828 // Default init dialog behaviour is to transfer data to window
2829 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2831 TransferDataToWindow();
2834 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2837 HDC dc
= ::GetDC((HWND
) wnd
);
2843 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2845 // the_font->UseResource();
2846 // the_font->RealizeResource();
2847 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2848 was
= SelectObject(dc
,fnt
) ;
2850 GetTextMetrics(dc
, &tm
);
2851 if (the_font
&& fnt
&& was
)
2854 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2856 SelectObject(dc
,was
) ;
2858 ReleaseDC((HWND
)wnd
, dc
);
2859 *x
= tm
.tmAveCharWidth
;
2860 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2863 // the_font->ReleaseResource();
2866 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2867 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2868 int wxCharCodeMSWToWX(int keySym
)
2873 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2874 case VK_BACK
: id
= WXK_BACK
; break;
2875 case VK_TAB
: id
= WXK_TAB
; break;
2876 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2877 case VK_RETURN
: id
= WXK_RETURN
; break;
2878 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2879 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2880 case VK_MENU
: id
= WXK_MENU
; break;
2881 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2882 case VK_SPACE
: id
= WXK_SPACE
; break;
2883 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2884 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2885 case VK_NEXT
: id
= WXK_NEXT
; break;
2886 case VK_END
: id
= WXK_END
; break;
2887 case VK_HOME
: id
= WXK_HOME
; break;
2888 case VK_LEFT
: id
= WXK_LEFT
; break;
2889 case VK_UP
: id
= WXK_UP
; break;
2890 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2891 case VK_DOWN
: id
= WXK_DOWN
; break;
2892 case VK_SELECT
: id
= WXK_SELECT
; break;
2893 case VK_PRINT
: id
= WXK_PRINT
; break;
2894 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2895 case VK_INSERT
: id
= WXK_INSERT
; break;
2896 case VK_DELETE
: id
= WXK_DELETE
; break;
2897 case VK_HELP
: id
= WXK_HELP
; break;
2898 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2899 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2900 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2901 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2902 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2903 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2904 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2905 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2906 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2907 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2908 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2909 case VK_ADD
: id
= WXK_ADD
; break;
2910 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2911 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2912 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2913 case VK_F1
: id
= WXK_F1
; break;
2914 case VK_F2
: id
= WXK_F2
; break;
2915 case VK_F3
: id
= WXK_F3
; break;
2916 case VK_F4
: id
= WXK_F4
; break;
2917 case VK_F5
: id
= WXK_F5
; break;
2918 case VK_F6
: id
= WXK_F6
; break;
2919 case VK_F7
: id
= WXK_F7
; break;
2920 case VK_F8
: id
= WXK_F8
; break;
2921 case VK_F9
: id
= WXK_F9
; break;
2922 case VK_F10
: id
= WXK_F10
; break;
2923 case VK_F11
: id
= WXK_F11
; break;
2924 case VK_F12
: id
= WXK_F12
; break;
2925 case VK_F13
: id
= WXK_F13
; break;
2926 case VK_F14
: id
= WXK_F14
; break;
2927 case VK_F15
: id
= WXK_F15
; break;
2928 case VK_F16
: id
= WXK_F16
; break;
2929 case VK_F17
: id
= WXK_F17
; break;
2930 case VK_F18
: id
= WXK_F18
; break;
2931 case VK_F19
: id
= WXK_F19
; break;
2932 case VK_F20
: id
= WXK_F20
; break;
2933 case VK_F21
: id
= WXK_F21
; break;
2934 case VK_F22
: id
= WXK_F22
; break;
2935 case VK_F23
: id
= WXK_F23
; break;
2936 case VK_F24
: id
= WXK_F24
; break;
2937 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2938 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2947 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2953 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2954 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2955 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2956 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2957 case WXK_MENU
: keySym
= VK_MENU
; break;
2958 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2959 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2960 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2961 case WXK_END
: keySym
= VK_END
; break;
2962 case WXK_HOME
: keySym
= VK_HOME
; break;
2963 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2964 case WXK_UP
: keySym
= VK_UP
; break;
2965 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2966 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2967 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2968 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2969 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2970 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2971 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2972 case WXK_HELP
: keySym
= VK_HELP
; break;
2973 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2974 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2975 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2976 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2977 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2978 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2979 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2980 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2981 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2982 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2983 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2984 case WXK_ADD
: keySym
= VK_ADD
; break;
2985 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2986 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2987 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2988 case WXK_F1
: keySym
= VK_F1
; break;
2989 case WXK_F2
: keySym
= VK_F2
; break;
2990 case WXK_F3
: keySym
= VK_F3
; break;
2991 case WXK_F4
: keySym
= VK_F4
; break;
2992 case WXK_F5
: keySym
= VK_F5
; break;
2993 case WXK_F6
: keySym
= VK_F6
; break;
2994 case WXK_F7
: keySym
= VK_F7
; break;
2995 case WXK_F8
: keySym
= VK_F8
; break;
2996 case WXK_F9
: keySym
= VK_F9
; break;
2997 case WXK_F10
: keySym
= VK_F10
; break;
2998 case WXK_F11
: keySym
= VK_F11
; break;
2999 case WXK_F12
: keySym
= VK_F12
; break;
3000 case WXK_F13
: keySym
= VK_F13
; break;
3001 case WXK_F14
: keySym
= VK_F14
; break;
3002 case WXK_F15
: keySym
= VK_F15
; break;
3003 case WXK_F16
: keySym
= VK_F16
; break;
3004 case WXK_F17
: keySym
= VK_F17
; break;
3005 case WXK_F18
: keySym
= VK_F18
; break;
3006 case WXK_F19
: keySym
= VK_F19
; break;
3007 case WXK_F20
: keySym
= VK_F20
; break;
3008 case WXK_F21
: keySym
= VK_F21
; break;
3009 case WXK_F22
: keySym
= VK_F22
; break;
3010 case WXK_F23
: keySym
= VK_F23
; break;
3011 case WXK_F24
: keySym
= VK_F24
; break;
3012 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
3013 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
3024 // Caret manipulation
3025 void wxWindow::CreateCaret(const int w
, const int h
)
3029 m_caretEnabled
= TRUE
;
3032 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
3037 void wxWindow::ShowCaret(const bool show
)
3042 ::ShowCaret((HWND
) GetHWND());
3044 ::HideCaret((HWND
) GetHWND());
3045 m_caretShown
= show
;
3049 void wxWindow::DestroyCaret(void)
3051 m_caretEnabled
= FALSE
;
3054 void wxWindow::SetCaretPos(const int x
, const int y
)
3056 ::SetCaretPos(x
, y
);
3059 void wxWindow::GetCaretPos(int *x
, int *y
) const
3062 ::GetCaretPos(&point
);
3068 * Update iterator. Use from within OnPaint.
3071 static RECT gs_UpdateRect
;
3073 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
3075 current
= 0; //start somewhere...
3076 #if defined(__WIN32__) && !defined(__win32s__)
3077 rlist
= NULL
; //make sure I don't free randomly
3078 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
3081 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
3082 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
3083 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
3084 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
3089 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
3090 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
3091 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
3092 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
3094 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
3098 wxUpdateIterator::~wxUpdateIterator(void)
3102 if (rlist
) delete (RGNDATA
*) rlist
;
3107 wxUpdateIterator::operator int (void)
3109 if (current
< rects
)
3119 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
3125 void wxUpdateIterator::GetRect(wxRect
*rect
)
3127 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
3128 rect
->x
= mswRect
->left
;
3129 rect
->y
= mswRect
->top
;
3130 rect
->width
= mswRect
->right
- mswRect
->left
;
3131 rect
->height
= mswRect
->bottom
- mswRect
->top
;
3134 int wxUpdateIterator::GetX()
3136 return ((RECT
*)rp
)[current
].left
;
3139 int wxUpdateIterator::GetY()
3141 return ((RECT
*)rp
)[current
].top
;
3144 int wxUpdateIterator::GetW()
3146 return ((RECT
*)rp
)[current
].right
-GetX();
3149 int wxUpdateIterator::GetH()
3151 return ((RECT
*)rp
)[current
].bottom
-GetY();
3154 wxWindow
*wxGetActiveWindow(void)
3156 HWND hWnd
= GetActiveWindow();
3159 return wxFindWinFromHandle((WXHWND
) hWnd
);
3164 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3165 // in active frames and dialogs, regardless of where the focus is.
3166 static HHOOK wxTheKeyboardHook
= 0;
3167 static FARPROC wxTheKeyboardHookProc
= 0;
3168 int APIENTRY _EXPORT
3169 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
3171 void wxSetKeyboardHook(bool doIt
)
3175 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
3176 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
3178 GetCurrentThreadId());
3179 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3186 UnhookWindowsHookEx(wxTheKeyboardHook
);
3187 FreeProcInstance(wxTheKeyboardHookProc
);
3191 int APIENTRY _EXPORT
3192 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
3194 DWORD hiWord
= HIWORD(lParam
);
3195 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3198 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3200 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3201 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3202 event
.m_altDown
= TRUE
;
3204 event
.m_eventObject
= NULL
;
3205 event
.m_keyCode
= id
;
3206 /* begin Albert's fix for control and shift key 26.5 */
3207 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3208 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3209 /* end Albert's fix for control and shift key 26.5 */
3210 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3212 #if WXWIN_COMPATIBILITY
3213 if ( wxTheApp
&& wxTheApp
->OldOnCharHook(event
) )
3216 wxWindow
*win
= wxGetActiveWindow();
3219 if (win
->GetEventHandler()->ProcessEvent(event
))
3224 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3229 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3232 void wxWindow::SetSizeHints(const int minW
, const int minH
, const int maxW
, const int maxH
, const int WXUNUSED(incW
), const int WXUNUSED(incH
))
3240 void wxWindow::Centre(const int direction
)
3242 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3244 wxWindow
*father
= (wxWindow
*)GetParent();
3248 father
->GetClientSize(&panel_width
, &panel_height
);
3249 GetSize(&width
, &height
);
3250 GetPosition(&x
, &y
);
3255 if (direction
& wxHORIZONTAL
)
3256 new_x
= (int)((panel_width
- width
)/2);
3258 if (direction
& wxVERTICAL
)
3259 new_y
= (int)((panel_height
- height
)/2);
3261 SetSize(new_x
, new_y
, -1, -1);
3266 void wxWindow::OnPaint(void)
3268 PaintSelectionHandles();
3272 void wxWindow::WarpPointer (const int x_pos
, const int y_pos
)
3274 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3275 // pixel coordinates, relatives to the canvas -- So, we first need to
3276 // substract origin of the window, then convert to screen position
3278 int x
= x_pos
; int y
= y_pos
;
3279 /* Leave this to the app to decide (and/or wxScrolledWindow)
3280 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3281 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3284 GetWindowRect ((HWND
) GetHWND(), &rect
);
3289 SetCursorPos (x
, y
);
3292 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3295 // Do we have a SetUserScale in wxWindow too, so we can
3296 // get mouse events scaled?
3300 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3301 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3306 bool wxWindow::MSWOnEraseBkgnd (const WXHDC pDC
)
3314 wxEraseEvent
event(m_windowId
, &dc
);
3315 event
.m_eventObject
= this;
3316 if (!GetEventHandler()->ProcessEvent(event
))
3319 dc
.SelectOldObjects(pDC
);
3325 dc
.SelectOldObjects(pDC
);
3328 dc
.SetHDC((WXHDC
) NULL
);
3332 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3335 ::GetClientRect((HWND
) GetHWND(), &rect
);
3337 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3338 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3340 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3341 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3342 ::DeleteObject(hBrush
);
3343 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3345 // Less efficient version (and doesn't account for scrolling)
3347 GetClientSize(& w, & h);
3348 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3349 event.GetDC()->SetBrush(brush);
3350 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3352 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3356 #if WXWIN_COMPATIBILITY
3357 void wxWindow::SetScrollRange(const int orient
, const int range
, const bool refresh
)
3359 #if defined(__WIN95__)
3363 // Try to adjust the range to cope with page size > 1
3364 // - a Windows API quirk
3365 int pageSize
= GetScrollPage(orient
);
3366 if ( pageSize
> 1 && range
> 0)
3368 range1
+= (pageSize
- 1);
3374 if (orient
== wxHORIZONTAL
) {
3380 info
.cbSize
= sizeof(SCROLLINFO
);
3381 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3385 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3387 HWND hWnd
= (HWND
) GetHWND();
3389 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3392 if (orient
== wxHORIZONTAL
)
3397 HWND hWnd
= (HWND
) GetHWND();
3399 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3403 void wxWindow::SetScrollPage(const int orient
, const int page
, const bool refresh
)
3405 #if defined(__WIN95__)
3409 if (orient
== wxHORIZONTAL
) {
3411 m_xThumbSize
= page
;
3414 m_yThumbSize
= page
;
3417 info
.cbSize
= sizeof(SCROLLINFO
);
3420 info
.fMask
= SIF_PAGE
;
3422 HWND hWnd
= (HWND
) GetHWND();
3424 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3426 if (orient
== wxHORIZONTAL
)
3427 m_xThumbSize
= page
;
3429 m_yThumbSize
= page
;
3433 int wxWindow::OldGetScrollRange(const int orient
) const
3436 if (orient
== wxHORIZONTAL
)
3441 #if __WATCOMC__ && defined(__WINDOWS_386__)
3442 short minPos
, maxPos
;
3446 HWND hWnd
= (HWND
) GetHWND();
3449 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3450 #if defined(__WIN95__)
3451 // Try to adjust the range to cope with page size > 1
3452 // - a Windows API quirk
3453 int pageSize
= GetScrollPage(orient
);
3456 maxPos
-= (pageSize
- 1);
3465 int wxWindow::GetScrollPage(const int orient
) const
3467 if (orient
== wxHORIZONTAL
)
3468 return m_xThumbSize
;
3470 return m_yThumbSize
;
3474 int wxWindow::GetScrollPos(const int orient
) const
3477 if (orient
== wxHORIZONTAL
)
3481 HWND hWnd
= (HWND
) GetHWND();
3484 return ::GetScrollPos(hWnd
, wOrient
);
3490 // This now returns the whole range, not just the number
3491 // of positions that we can scroll.
3492 int wxWindow::GetScrollRange(const int orient
) const
3495 if (orient
== wxHORIZONTAL
)
3500 #if __WATCOMC__ && defined(__WINDOWS_386__)
3501 short minPos
, maxPos
;
3505 HWND hWnd
= (HWND
) GetHWND();
3508 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3509 #if defined(__WIN95__)
3510 // Try to adjust the range to cope with page size > 1
3511 // - a Windows API quirk
3512 int pageSize
= GetScrollPage(orient
);
3515 maxPos
-= (pageSize
- 1);
3517 // October 10th: new range concept.
3527 int wxWindow::GetScrollThumb(const int orient
) const
3529 if (orient
== wxHORIZONTAL
)
3530 return m_xThumbSize
;
3532 return m_yThumbSize
;
3535 void wxWindow::SetScrollPos(const int orient
, const int pos
, const bool refresh
)
3537 #if defined(__WIN95__)
3541 if (orient
== wxHORIZONTAL
) {
3547 info
.cbSize
= sizeof(SCROLLINFO
);
3551 info
.fMask
= SIF_POS
;
3553 HWND hWnd
= (HWND
) GetHWND();
3555 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3558 if (orient
== wxHORIZONTAL
)
3563 HWND hWnd
= (HWND
) GetHWND();
3565 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3569 // New function that will replace some of the above.
3570 void wxWindow::SetScrollbar(const int orient
, const int pos
, const int thumbVisible
,
3571 const int range
, const bool refresh
)
3574 SetScrollPage(orient, thumbVisible, FALSE);
3576 int oldRange = range - thumbVisible ;
3577 SetScrollRange(orient, oldRange, FALSE);
3579 SetScrollPos(orient, pos, refresh);
3581 #if defined(__WIN95__)
3582 int oldRange
= range
- thumbVisible
;
3584 int range1
= oldRange
;
3586 // Try to adjust the range to cope with page size > 1
3587 // - a Windows API quirk
3588 int pageSize
= thumbVisible
;
3589 if ( pageSize
> 1 && range
> 0)
3591 range1
+= (pageSize
- 1);
3597 if (orient
== wxHORIZONTAL
) {
3603 info
.cbSize
= sizeof(SCROLLINFO
);
3604 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3608 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3610 HWND hWnd
= (HWND
) GetHWND();
3612 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3615 if (orient
== wxHORIZONTAL
)
3620 HWND hWnd
= (HWND
) GetHWND();
3623 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3624 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3627 if (orient
== wxHORIZONTAL
) {
3628 m_xThumbSize
= thumbVisible
;
3630 m_yThumbSize
= thumbVisible
;
3634 void wxWindow::ScrollWindow(const int dx
, const int dy
, const wxRectangle
*rect
)
3639 rect2
.left
= rect
->x
;
3640 rect2
.top
= rect
->y
;
3641 rect2
.right
= rect
->x
+ rect
->width
;
3642 rect2
.bottom
= rect
->y
+ rect
->height
;
3646 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3648 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3651 void wxWindow::OnSize(wxSizeEvent
& event
)
3655 if (GetAutoLayout())
3661 void wxWindow::CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const
3667 void wxWindow::CalcUnscrolledPosition(const int x, const int y, float *xx, float *yy) const
3674 void wxWindow::SetFont(const wxFont
& font
)
3676 // Decrement the usage count of the old label font
3677 // (we may be able to free it up)
3678 // if (GetFont()->Ok())
3679 // GetFont()->ReleaseResource();
3681 m_windowFont
= font
;
3683 if (!m_windowFont
.Ok())
3686 // m_windowFont.UseResource();
3688 HWND hWnd
= (HWND
) GetHWND();
3691 // m_windowFont.RealizeResource();
3693 if (m_windowFont
.GetResourceHandle())
3694 SendMessage(hWnd
, WM_SETFONT
,
3695 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3699 void wxWindow::SubclassWin(WXHWND hWnd
)
3701 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3703 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3704 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3707 void wxWindow::UnsubclassWin(void)
3709 wxRemoveHandleAssociation(this);
3711 // Restore old Window proc
3712 if ((HWND
) GetHWND())
3714 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3715 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3717 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3723 // Make a Windows extended style from the given wxWindows window style
3724 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3726 WXDWORD exStyle
= 0;
3727 if ( style
& wxTRANSPARENT_WINDOW
)
3728 exStyle
|= WS_EX_TRANSPARENT
;
3730 if ( !eliminateBorders
)
3732 if ( style
& wxSUNKEN_BORDER
)
3733 exStyle
|= WS_EX_CLIENTEDGE
;
3734 if ( style
& wxDOUBLE_BORDER
)
3735 exStyle
|= WS_EX_DLGMODALFRAME
;
3736 #if defined(__WIN95__)
3737 if ( style
& wxRAISED_BORDER
)
3738 exStyle
|= WS_EX_WINDOWEDGE
;
3739 if ( style
& wxSTATIC_BORDER
)
3740 exStyle
|= WS_EX_STATICEDGE
;
3746 // Determines whether native 3D effects or CTL3D should be used,
3747 // applying a default border style if required, and returning an extended
3748 // style to pass to CreateWindowEx.
3749 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3751 // If matches certain criteria, then assume no 3D effects
3752 // unless specifically requested (dealt with in MakeExtendedStyle)
3753 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3756 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3759 // Determine whether we should be using 3D effects or not.
3760 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3762 // 1) App can specify global 3D effects
3763 *want3D
= wxTheApp
->GetAuto3D();
3765 // 2) If the parent is being drawn with user colours, or simple border specified,
3766 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3767 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3770 // 3) Control can override this global setting by defining
3771 // a border style, e.g. wxSUNKEN_BORDER
3772 if (m_windowStyle
& wxSUNKEN_BORDER
)
3775 // 4) If it's a special border, CTL3D can't cope so we want a native border
3776 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3777 (m_windowStyle
& wxSTATIC_BORDER
) )
3780 nativeBorder
= TRUE
;
3783 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3784 // effects from extended style
3787 nativeBorder
= FALSE
;
3790 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3792 // If we want 3D, but haven't specified a border here,
3793 // apply the default border style specified.
3794 // TODO what about non-Win95 WIN32? Does it have borders?
3795 #if defined(__WIN95__) && !CTL3D
3796 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3797 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3798 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3804 #if WXWIN_COMPATIBILITY
3805 void wxWindow::OldOnPaint(void)
3807 wxPaintEvent
event(m_windowId
);
3808 event
.m_eventObject
= this;
3809 if (!GetEventHandler()->ProcessEvent(event
))
3813 void wxWindow::OldOnSize(int w
, int h
)
3815 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
3816 event
.m_eventObject
= this;
3817 if (!GetEventHandler()->ProcessEvent(event
))
3821 void wxWindow::OldOnMouseEvent(wxMouseEvent
& event
)
3823 if (!GetEventHandler()->ProcessEvent(event
))
3827 void wxWindow::OldOnChar(wxKeyEvent
& event
)
3829 if (!GetEventHandler()->ProcessEvent(event
))
3833 void wxWindow::OldOnSetFocus(void)
3835 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3836 event
.m_eventObject
= this;
3837 if (!GetEventHandler()->ProcessEvent(event
))
3841 void wxWindow::OldOnKillFocus(void)
3843 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3844 event
.m_eventObject
= this;
3845 if (!GetEventHandler()->ProcessEvent(event
))
3850 void wxWindow::OnChar(wxKeyEvent
& event
)
3853 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3858 if ( !event
.ControlDown() )
3859 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3862 void wxWindow::OnPaint(wxPaintEvent
& event
)
3867 bool wxWindow::IsEnabled(void) const
3869 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3872 // Dialog support: override these and call
3873 // base class members to add functionality
3874 // that can't be done using validators.
3875 // NOTE: these functions assume that controls
3876 // are direct children of this window, not grandchildren
3877 // or other levels of descendant.
3879 // Transfer values to controls. If returns FALSE,
3880 // it's an application error (pops up a dialog)
3881 bool wxWindow::TransferDataToWindow(void)
3883 wxNode
*node
= GetChildren()->First();
3886 wxWindow
*child
= (wxWindow
*)node
->Data();
3887 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3888 !child
->GetValidator()->TransferToWindow() )
3890 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3894 node
= node
->Next();
3899 // Transfer values from controls. If returns FALSE,
3900 // validation failed: don't quit
3901 bool wxWindow::TransferDataFromWindow(void)
3903 wxNode
*node
= GetChildren()->First();
3906 wxWindow
*child
= (wxWindow
*)node
->Data();
3907 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3912 node
= node
->Next();
3917 bool wxWindow::Validate(void)
3919 wxNode
*node
= GetChildren()->First();
3922 wxWindow
*child
= (wxWindow
*)node
->Data();
3923 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3928 node
= node
->Next();
3933 // Get the window with the focus
3934 wxWindow
*wxWindow::FindFocus(void)
3936 HWND hWnd
= ::GetFocus();
3939 return wxFindWinFromHandle((WXHWND
) hWnd
);
3944 void wxWindow::AddChild(wxWindow
*child
)
3946 GetChildren()->Append(child
);
3947 child
->m_windowParent
= this;
3950 void wxWindow::RemoveChild(wxWindow
*child
)
3953 GetChildren()->DeleteObject(child
);
3954 child
->m_windowParent
= NULL
;
3957 void wxWindow::DestroyChildren(void)
3959 if (GetChildren()) {
3961 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3963 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3965 if ( GetChildren()->Member(child
) )
3972 void wxWindow::MakeModal(const bool modal
)
3974 // Disable all other windows
3975 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3977 wxNode
*node
= wxTopLevelWindows
.First();
3980 wxWindow
*win
= (wxWindow
*)node
->Data();
3982 win
->Enable(!modal
);
3984 node
= node
->Next();
3989 // If nothing defined for this, try the parent.
3990 // E.g. we may be a button loaded from a resource, with no callback function
3992 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3994 if (GetEventHandler()->ProcessEvent(event
) )
3997 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
4000 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
4004 UnsetConstraints(m_constraints
);
4005 delete m_constraints
;
4010 // Make sure other windows know they're part of a 'meaningful relationship'
4011 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
4012 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4013 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
4014 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4015 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
4016 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4017 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
4018 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4019 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
4020 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4021 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
4022 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4023 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
4024 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4025 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
4026 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
4030 // This removes any dangling pointers to this window
4031 // in other windows' constraintsInvolvedIn lists.
4032 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
4036 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
4037 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4038 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
4039 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4040 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
4041 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4042 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
4043 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4044 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
4045 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4046 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
4047 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4048 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
4049 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4050 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
4051 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
4055 // Back-pointer to other windows we're involved with, so if we delete
4056 // this window, we must delete any constraints we're involved with.
4057 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
4059 if (!m_constraintsInvolvedIn
)
4060 m_constraintsInvolvedIn
= new wxList
;
4061 if (!m_constraintsInvolvedIn
->Member(otherWin
))
4062 m_constraintsInvolvedIn
->Append(otherWin
);
4065 // REMOVE back-pointer to other windows we're involved with.
4066 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
4068 if (m_constraintsInvolvedIn
)
4069 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
4072 // Reset any constraints that mention this window
4073 void wxWindow::DeleteRelatedConstraints(void)
4075 if (m_constraintsInvolvedIn
)
4077 wxNode
*node
= m_constraintsInvolvedIn
->First();
4080 wxWindow
*win
= (wxWindow
*)node
->Data();
4081 wxNode
*next
= node
->Next();
4082 wxLayoutConstraints
*constr
= win
->GetConstraints();
4084 // Reset any constraints involving this window
4087 constr
->left
.ResetIfWin((wxWindow
*)this);
4088 constr
->top
.ResetIfWin((wxWindow
*)this);
4089 constr
->right
.ResetIfWin((wxWindow
*)this);
4090 constr
->bottom
.ResetIfWin((wxWindow
*)this);
4091 constr
->width
.ResetIfWin((wxWindow
*)this);
4092 constr
->height
.ResetIfWin((wxWindow
*)this);
4093 constr
->centreX
.ResetIfWin((wxWindow
*)this);
4094 constr
->centreY
.ResetIfWin((wxWindow
*)this);
4099 delete m_constraintsInvolvedIn
;
4100 m_constraintsInvolvedIn
= NULL
;
4104 void wxWindow::SetSizer(wxSizer
*sizer
)
4106 m_windowSizer
= sizer
;
4108 sizer
->SetSizerParent((wxWindow
*)this);
4115 bool wxWindow::Layout(void)
4117 if (GetConstraints())
4120 GetClientSize(&w
, &h
);
4121 GetConstraints()->width
.SetValue(w
);
4122 GetConstraints()->height
.SetValue(h
);
4125 // If top level (one sizer), evaluate the sizer's constraints.
4129 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
4130 GetSizer()->LayoutPhase1(&noChanges
);
4131 GetSizer()->LayoutPhase2(&noChanges
);
4132 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
4137 // Otherwise, evaluate child constraints
4138 ResetConstraints(); // Mark all constraints as unevaluated
4139 DoPhase(1); // Just one phase need if no sizers involved
4141 SetConstraintSizes(); // Recursively set the real window sizes
4147 // Do a phase of evaluating constraints:
4148 // the default behaviour. wxSizers may do a similar
4149 // thing, but also impose their own 'constraints'
4150 // and order the evaluation differently.
4151 bool wxWindow::LayoutPhase1(int *noChanges
)
4153 wxLayoutConstraints
*constr
= GetConstraints();
4156 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
4162 bool wxWindow::LayoutPhase2(int *noChanges
)
4172 // Do a phase of evaluating child constraints
4173 bool wxWindow::DoPhase(const int phase
)
4175 int noIterations
= 0;
4176 int maxIterations
= 500;
4180 while ((noChanges
> 0) && (noIterations
< maxIterations
))
4184 wxNode
*node
= GetChildren()->First();
4187 wxWindow
*child
= (wxWindow
*)node
->Data();
4188 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
4190 wxLayoutConstraints
*constr
= child
->GetConstraints();
4193 if (succeeded
.Member(child
))
4198 int tempNoChanges
= 0;
4199 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
4200 noChanges
+= tempNoChanges
;
4203 succeeded
.Append(child
);
4208 node
= node
->Next();
4215 void wxWindow::ResetConstraints(void)
4217 wxLayoutConstraints
*constr
= GetConstraints();
4220 constr
->left
.SetDone(FALSE
);
4221 constr
->top
.SetDone(FALSE
);
4222 constr
->right
.SetDone(FALSE
);
4223 constr
->bottom
.SetDone(FALSE
);
4224 constr
->width
.SetDone(FALSE
);
4225 constr
->height
.SetDone(FALSE
);
4226 constr
->centreX
.SetDone(FALSE
);
4227 constr
->centreY
.SetDone(FALSE
);
4229 wxNode
*node
= GetChildren()->First();
4232 wxWindow
*win
= (wxWindow
*)node
->Data();
4233 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4234 win
->ResetConstraints();
4235 node
= node
->Next();
4239 // Need to distinguish between setting the 'fake' size for
4240 // windows and sizers, and setting the real values.
4241 void wxWindow::SetConstraintSizes(const bool recurse
)
4243 wxLayoutConstraints
*constr
= GetConstraints();
4244 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4245 constr
->width
.GetDone() && constr
->height
.GetDone())
4247 int x
= constr
->left
.GetValue();
4248 int y
= constr
->top
.GetValue();
4249 int w
= constr
->width
.GetValue();
4250 int h
= constr
->height
.GetValue();
4252 // If we don't want to resize this window, just move it...
4253 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4254 (constr
->height
.GetRelationship() != wxAsIs
))
4256 // Calls Layout() recursively. AAAGH. How can we stop that.
4257 // Simply take Layout() out of non-top level OnSizes.
4258 SizerSetSize(x
, y
, w
, h
);
4267 char *windowClass
= this->GetClassInfo()->GetClassName();
4270 if (GetName() == "")
4271 winName
= "unnamed";
4273 winName
= GetName();
4274 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4275 if (!constr
->left
.GetDone())
4276 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4277 if (!constr
->right
.GetDone())
4278 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4279 if (!constr
->width
.GetDone())
4280 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4281 if (!constr
->height
.GetDone())
4282 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4283 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4288 wxNode
*node
= GetChildren()->First();
4291 wxWindow
*win
= (wxWindow
*)node
->Data();
4292 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4293 win
->SetConstraintSizes();
4294 node
= node
->Next();
4299 // This assumes that all sizers are 'on' the same
4300 // window, i.e. the parent of this window.
4301 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4303 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4304 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4308 m_sizerParent
->GetPosition(&xp
, &yp
);
4309 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4314 void wxWindow::SizerSetSize(const int x
, const int y
, const int w
, const int h
)
4318 TransformSizerToActual(&xx
, &yy
);
4319 SetSize(xx
, yy
, w
, h
);
4322 void wxWindow::SizerMove(const int x
, const int y
)
4326 TransformSizerToActual(&xx
, &yy
);
4330 // Only set the size/position of the constraint (if any)
4331 void wxWindow::SetSizeConstraint(const int x
, const int y
, const int w
, const int h
)
4333 wxLayoutConstraints
*constr
= GetConstraints();
4338 constr
->left
.SetValue(x
);
4339 constr
->left
.SetDone(TRUE
);
4343 constr
->top
.SetValue(y
);
4344 constr
->top
.SetDone(TRUE
);
4348 constr
->width
.SetValue(w
);
4349 constr
->width
.SetDone(TRUE
);
4353 constr
->height
.SetValue(h
);
4354 constr
->height
.SetDone(TRUE
);
4359 void wxWindow::MoveConstraint(const int x
, const int y
)
4361 wxLayoutConstraints
*constr
= GetConstraints();
4366 constr
->left
.SetValue(x
);
4367 constr
->left
.SetDone(TRUE
);
4371 constr
->top
.SetValue(y
);
4372 constr
->top
.SetDone(TRUE
);
4377 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4379 wxLayoutConstraints
*constr
= GetConstraints();
4382 *w
= constr
->width
.GetValue();
4383 *h
= constr
->height
.GetValue();
4389 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4391 wxLayoutConstraints
*constr
= GetConstraints();
4394 *w
= constr
->width
.GetValue();
4395 *h
= constr
->height
.GetValue();
4398 GetClientSize(w
, h
);
4401 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4403 wxLayoutConstraints
*constr
= GetConstraints();
4406 *x
= constr
->left
.GetValue();
4407 *y
= constr
->top
.GetValue();
4413 bool wxWindow::Close(const bool force
)
4415 // Let's generalise it to work the same for any window.
4417 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4424 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4425 event
.SetEventObject(this);
4426 event
.SetForce(force
);
4428 return GetEventHandler()->ProcessEvent(event
);
4431 if ( !force && event.GetVeto() )
4436 if (!wxPendingDelete.Member(this))
4437 wxPendingDelete.Append(this);
4443 wxObject
* wxWindow::GetChild(const int number
) const
4445 // Return a pointer to the Nth object in the Panel
4448 wxNode
*node
= GetChildren()->First();
4451 node
= node
->Next() ;
4454 wxObject
*obj
= (wxObject
*)node
->Data();
4461 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4463 if (initiatingItem
->IsKindOf(CLASSINFO(wxListBox
)) && initiatingItem
->GetCallback())
4465 wxListBox
*lbox
= (wxListBox
*)initiatingItem
;
4466 wxCommandEvent
event(wxEVENT_TYPE_LISTBOX_DCLICK_COMMAND
);
4467 event
.m_commandInt
= -1;
4468 if ((lbox
->GetWindowStyleFlag() & wxLB_MULTIPLE
) == 0)
4470 event
.m_commandString
= copystring(lbox
->GetStringSelection());
4471 event
.m_commandInt
= lbox
->GetSelection();
4472 event
.m_clientData
= lbox
->wxListBox::GetClientData(event
.m_commandInt
);
4474 event
.m_eventObject
= lbox
;
4476 lbox
->ProcessCommand(event
);
4478 if (event
.m_commandString
)
4479 delete[] event
.m_commandString
;
4483 wxButton
*but
= GetDefaultItem();
4486 wxCommandEvent
event(wxEVENT_TYPE_BUTTON_COMMAND
);
4487 but
->Command(event
);
4491 void wxWindow::Clear(void)
4493 wxClientDC
dc(this);
4494 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4495 dc
.SetBackground(brush
);
4499 // Fits the panel around the items
4500 void wxWindow::Fit(void)
4504 wxNode
*node
= GetChildren()->First();
4507 wxWindow
*win
= (wxWindow
*)node
->Data();
4509 win
->GetPosition(&wx
, &wy
);
4510 win
->GetSize(&ww
, &wh
);
4511 if ( wx
+ ww
> maxX
)
4513 if ( wy
+ wh
> maxY
)
4516 node
= node
->Next();
4518 SetClientSize(maxX
+ 5, maxY
+ 5);
4521 void wxWindow::SetValidator(const wxValidator
& validator
)
4523 if ( m_windowValidator
)
4524 delete m_windowValidator
;
4525 m_windowValidator
= validator
.Clone();
4527 if ( m_windowValidator
)
4528 m_windowValidator
->SetWindow(this) ;
4531 // Find a window by id or name
4532 wxWindow
*wxWindow::FindWindow(const long id
)
4537 wxNode
*node
= GetChildren()->First();
4540 wxWindow
*child
= (wxWindow
*)node
->Data();
4541 wxWindow
*found
= child
->FindWindow(id
);
4544 node
= node
->Next();
4549 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4551 if ( GetName() == name
)
4554 wxNode
*node
= GetChildren()->First();
4557 wxWindow
*child
= (wxWindow
*)node
->Data();
4558 wxWindow
*found
= child
->FindWindow(name
);
4561 node
= node
->Next();
4567 // Default input behaviour for a scrolling canvas should be to scroll
4568 // according to the cursor keys pressed
4569 void wxWindow::OnChar(wxKeyEvent& event)
4581 GetScrollUnitsPerPage(&x_page, &y_page);
4583 GetVirtualSize(&v_width,&v_height);
4585 ViewStart(&start_x, &start_y);
4588 y_pages = (int)(v_height/vert_units) - y_page;
4596 switch (event.keyCode)
4603 if (start_y - y_page > 0)
4604 Scroll(start_x, start_y - y_page);
4614 if ((y_page > 0) && (start_y <= y_pages-y-1))
4616 if (y_pages + y < start_y + y_page)
4617 Scroll(start_x, y_pages + y);
4619 Scroll(start_x, start_y + y_page);
4626 if ((y_page > 0) && (start_y >= 1))
4627 Scroll(start_x, start_y - 1);
4633 if ((y_page > 0) && (start_y <= y_pages-y-1))
4636 Scroll(start_x, start_y + 1);
4642 if ((x_page > 0) && (start_x >= 1))
4643 Scroll(start_x - 1, start_y);
4649 Scroll(start_x + 1, start_y);
4660 Scroll(start_x, y_pages+y);
4668 // Setup background and foreground colours correctly
4669 void wxWindow::SetupColours(void)
4672 SetBackgroundColour(GetParent()->GetBackgroundColour());
4675 // Do Update UI processing for child controls
4677 // TODO: should this be implemented for the child window rather
4678 // than the parent? Then you can override it e.g. for wxCheckBox
4679 // to do the Right Thing rather than having to assume a fixed number
4680 // of control classes.
4682 void wxWindow::UpdateWindowUI(void)
4684 wxWindowID id
= GetId();
4687 wxUpdateUIEvent
event(id
);
4688 event
.m_eventObject
= this;
4690 if (this->GetEventHandler()->ProcessEvent(event
))
4692 if (event
.GetSetEnabled())
4693 this->Enable(event
.GetEnabled());
4695 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4696 ((wxControl
*)this)->SetLabel(event
.GetText());
4698 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4700 if (event
.GetSetChecked())
4701 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4703 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4705 if (event
.GetSetChecked())
4706 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4713 void wxWindow::OnIdle(wxIdleEvent
& event
)
4715 // Check if we need to send a LEAVE event
4716 if (m_mouseInWindow
)
4719 ::GetCursorPos(&pt
);
4720 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4722 // Generate a LEAVE event
4723 m_mouseInWindow
= FALSE
;
4724 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4731 // Raise the window to the top of the Z order
4732 void wxWindow::Raise(void)
4734 ::BringWindowToTop((HWND
) GetHWND());
4737 // Lower the window to the bottom of the Z order
4738 void wxWindow::Lower(void)
4740 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);