1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/dcclient.h"
32 #include "wx/layout.h"
33 #include "wx/dialog.h"
34 #include "wx/listbox.h"
35 #include "wx/button.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
41 #include "wx/ownerdrw.h"
45 #include "wx/msw/ole/droptgt.h"
48 #include "wx/menuitem.h"
50 #include "wx/msw/private.h"
64 #include <wx/msw/gnuwin32/extra.h>
84 static const char *GetMessageName(int message
);
87 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
89 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 extern wxList wxPendingDelete
;
92 void wxRemoveHandleAssociation(wxWindow
*win
);
93 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
94 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
99 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
100 EVT_CHAR(wxWindow::OnChar
)
101 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
102 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
104 EVT_IDLE(wxWindow::OnIdle
)
109 // Find an item given the MS Windows id
110 wxWindow
*wxWindow::FindItem(int id
) const
114 wxNode
*current
= GetChildren()->First();
117 wxWindow
*childWin
= (wxWindow
*)current
->Data();
119 wxWindow
*wnd
= childWin
->FindItem(id
) ;
123 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
125 wxControl
*item
= (wxControl
*)childWin
;
126 if (item
->m_windowId
== id
)
130 // In case it's a 'virtual' control (e.g. radiobox)
131 if (item
->GetSubcontrols().Member((wxObject
*)id
))
135 current
= current
->Next();
140 // Find an item given the MS Windows handle
141 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
145 wxNode
*current
= GetChildren()->First();
148 wxObject
*obj
= (wxObject
*)current
->Data() ;
149 // Do a recursive search.
150 wxWindow
*parent
= (wxWindow
*)obj
;
151 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
155 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
157 wxWindow
*item
= (wxWindow
*)current
->Data();
158 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
162 if ( item
->ContainsHWND(hWnd
) )
166 current
= current
->Next();
171 // Default command handler
172 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
177 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
182 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
186 WXHWND
wxWindow::GetHWND(void) const
188 return (WXHWND
) m_hWnd
;
191 void wxWindow::SetHWND(WXHWND hWnd
)
197 wxWindow::wxWindow(void)
203 m_windowParent
= NULL
;
204 m_windowEventHandler
= this;
206 m_windowCursor
= *wxSTANDARD_CURSOR
;
207 m_children
= new wxList
;
208 m_doubleClickAllowed
= 0 ;
209 m_winCaptured
= FALSE
;
210 m_constraints
= NULL
;
211 m_constraintsInvolvedIn
= NULL
;
212 m_windowSizer
= NULL
;
213 m_sizerParent
= NULL
;
214 m_autoLayout
= FALSE
;
215 m_windowValidator
= NULL
;
220 m_caretWidth
= 0; m_caretHeight
= 0;
221 m_caretEnabled
= FALSE
;
222 m_caretShown
= FALSE
;
230 m_isBeingDeleted
= FALSE
;
237 m_defaultItem
= NULL
;
239 wxSystemSettings settings
;
241 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
242 m_foregroundColour
= *wxBLACK
;
243 m_defaultForegroundColour
= *wxBLACK
;
244 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
247 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
248 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
255 m_acceleratorTable
= 0;
260 m_backgroundTransparent
= FALSE
;
262 m_lastXPos
= (float)-1.0;
263 m_lastYPos
= (float)-1.0;
267 #if USE_DRAG_AND_DROP
268 m_pDropTarget
= NULL
;
273 wxWindow::~wxWindow(void)
275 m_isBeingDeleted
= TRUE
;
277 // JACS - if behaviour is odd, restore this
278 // to the start of ~wxWindow. Vadim has changed
279 // it to nearer the end. Unsure of side-effects
280 // e.g. when deleting associated global data.
281 // Restore old Window proc, if required
284 // Have to delete constraints/sizer FIRST otherwise
285 // sizers may try to look at deleted windows as they
286 // delete themselves.
288 DeleteRelatedConstraints();
291 // This removes any dangling pointers to this window
292 // in other windows' constraintsInvolvedIn lists.
293 UnsetConstraints(m_constraints
);
294 delete m_constraints
;
295 m_constraints
= NULL
;
299 delete m_windowSizer
;
300 m_windowSizer
= NULL
;
302 // If this is a child of a sizer, remove self from parent
304 m_sizerParent
->RemoveChild((wxWindow
*)this);
308 MSWDetachWindowMenu();
310 // TODO for backward compatibility
315 HWND hWnd
= (HWND
) GetHWND();
316 HDC dc
= ::GetDC(hWnd
);
317 m_windowDC
->SelectOldObjects (dc
);
324 m_windowParent
->RemoveChild(this);
329 ::DestroyWindow((HWND
)m_hWnd
);
331 wxRemoveHandleAssociation(this);
336 GlobalFree((HGLOBAL
) m_globalHandle
);
344 // Just in case the window has been Closed, but
345 // we're then deleting immediately: don't leave
346 // dangling pointers.
347 wxPendingDelete
.DeleteObject(this);
349 // Just in case we've loaded a top-level window via
350 // wxWindow::LoadNativeDialog but we weren't a dialog
352 wxTopLevelWindows
.DeleteObject(this);
354 // if (GetFont() && GetFont()->Ok())
355 // GetFont()->ReleaseResource();
357 if ( m_windowValidator
)
358 delete m_windowValidator
;
360 // Restore old Window proc, if required
361 // and remove hWnd <-> wxWindow association
365 // Destroy the window (delayed, if a managed window)
366 bool wxWindow::Destroy(void)
372 extern char wxCanvasClassName
[];
375 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
379 const wxString
& name
)
382 m_isBeingDeleted
= FALSE
;
386 m_windowParent
= NULL
;
387 m_windowEventHandler
= this;
388 // m_windowFont = NULL;
389 // We don't wish internal (potentially transient) fonts to be found
391 // wxTheFontList->RemoveFont(& m_windowFont);
393 m_windowCursor
= *wxSTANDARD_CURSOR
;
394 m_doubleClickAllowed
= 0 ;
395 m_winCaptured
= FALSE
;
396 m_constraints
= NULL
;
397 m_constraintsInvolvedIn
= NULL
;
398 m_windowSizer
= NULL
;
399 m_sizerParent
= NULL
;
400 m_autoLayout
= FALSE
;
401 m_windowValidator
= NULL
;
402 #if USE_DRAG_AND_DROP
403 m_pDropTarget
= NULL
;
409 m_caretWidth
= 0; m_caretHeight
= 0;
410 m_caretEnabled
= FALSE
;
411 m_caretShown
= FALSE
;
424 m_defaultItem
= NULL
;
425 m_windowParent
= NULL
;
426 // m_windowDC = NULL;
427 m_mouseInWindow
= FALSE
;
431 if (parent
) parent
->AddChild(this);
437 m_acceleratorTable
= 0;
442 m_backgroundTransparent
= FALSE
;
444 m_lastXPos
= (float)-1.0;
445 m_lastYPos
= (float)-1.0;
452 m_windowId
= (int)NewControlId();
461 wxSystemSettings settings
;
463 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
464 m_foregroundColour
= *wxBLACK
;
465 m_defaultForegroundColour
= *wxBLACK
;
466 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
468 m_defaultBackgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
469 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
472 m_windowStyle
= style
;
475 if (style
& wxBORDER
)
476 msflags
|= WS_BORDER
;
477 if (style
& wxTHICK_FRAME
)
478 msflags
|= WS_THICKFRAME
;
480 msflags
|= WS_CHILD
| WS_VISIBLE
;
481 if (style
& wxCLIP_CHILDREN
)
482 msflags
|= WS_CLIPCHILDREN
;
485 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
487 // Even with extended styles, need to combine with WS_BORDER
488 // for them to look right.
489 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
490 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
491 msflags
|= WS_BORDER
;
493 m_mouseInWindow
= FALSE
;
496 m_windowId
= (int)NewControlId();
500 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
506 void wxWindow::SetFocus(void)
508 HWND hWnd
= (HWND
) GetHWND();
513 void wxWindow::Enable(bool enable
)
515 m_winEnabled
= enable
;
516 HWND hWnd
= (HWND
) GetHWND();
518 ::EnableWindow(hWnd
, (BOOL
)enable
);
521 void wxWindow::CaptureMouse(void)
523 HWND hWnd
= (HWND
) GetHWND();
524 if (hWnd
&& !m_winCaptured
)
527 m_winCaptured
= TRUE
;
531 void wxWindow::ReleaseMouse(void)
536 m_winCaptured
= FALSE
;
540 // Push/pop event handler (i.e. allow a chain of event handlers
542 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
544 handler
->SetNextHandler(GetEventHandler());
545 SetEventHandler(handler
);
548 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
550 if ( GetEventHandler() )
552 wxEvtHandler
*handlerA
= GetEventHandler();
553 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
554 handlerA
->SetNextHandler(NULL
);
555 SetEventHandler(handlerB
);
568 #if USE_DRAG_AND_DROP
570 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
572 if ( m_pDropTarget
!= 0 ) {
573 m_pDropTarget
->Revoke(m_hWnd
);
574 delete m_pDropTarget
;
577 m_pDropTarget
= pDropTarget
;
578 if ( m_pDropTarget
!= 0 )
579 m_pDropTarget
->Register(m_hWnd
);
584 //old style file-manager drag&drop support
585 // I think we should retain the old-style
586 // DragAcceptFiles in parallel with SetDropTarget.
588 void wxWindow::DragAcceptFiles(bool accept
)
590 HWND hWnd
= (HWND
) GetHWND();
592 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
596 void wxWindow::GetSize(int *x
, int *y
) const
598 HWND hWnd
= (HWND
) GetHWND();
600 GetWindowRect(hWnd
, &rect
);
601 *x
= rect
.right
- rect
.left
;
602 *y
= rect
.bottom
- rect
.top
;
605 void wxWindow::GetPosition(int *x
, int *y
) const
607 HWND hWnd
= (HWND
) GetHWND();
610 hParentWnd
= (HWND
) GetParent()->GetHWND();
613 GetWindowRect(hWnd
, &rect
);
615 // Since we now have the absolute screen coords,
616 // if there's a parent we must subtract its top left corner
622 ::ScreenToClient(hParentWnd
, &point
);
628 void wxWindow::ScreenToClient(int *x
, int *y
) const
630 HWND hWnd
= (HWND
) GetHWND();
634 ::ScreenToClient(hWnd
, &pt
);
640 void wxWindow::ClientToScreen(int *x
, int *y
) const
642 HWND hWnd
= (HWND
) GetHWND();
646 ::ClientToScreen(hWnd
, &pt
);
652 void wxWindow::SetCursor(const wxCursor
& cursor
)
654 m_windowCursor
= cursor
;
655 if (m_windowCursor
.Ok())
657 HWND hWnd
= (HWND
) GetHWND();
659 // Change the cursor NOW if we're within the correct window
661 ::GetCursorPos(&point
);
664 ::GetWindowRect(hWnd
, &rect
);
666 if (::PtInRect(&rect
, point
) && !wxIsBusy())
667 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
670 // This will cause big reentrancy problems if wxFlushEvents is implemented.
672 // return old_cursor;
676 // Get size *available for subwindows* i.e. excluding menu bar etc.
677 // For XView, this is the same as GetSize
678 void wxWindow::GetClientSize(int *x
, int *y
) const
680 HWND hWnd
= (HWND
) GetHWND();
682 GetClientRect(hWnd
, &rect
);
687 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
689 int currentX
, currentY
;
690 GetPosition(¤tX
, ¤tY
);
691 int actualWidth
= width
;
692 int actualHeight
= height
;
695 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
697 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
700 int currentW
,currentH
;
701 GetSize(¤tW
, ¤tH
);
703 actualWidth
= currentW
;
705 actualHeight
= currentH
;
707 HWND hWnd
= (HWND
) GetHWND();
709 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
712 void wxWindow::SetClientSize(int width
, int height
)
714 wxWindow
*parent
= GetParent();
715 HWND hWnd
= (HWND
) GetHWND();
716 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
719 GetClientRect(hWnd
, &rect
);
722 GetWindowRect(hWnd
, &rect2
);
724 // Find the difference between the entire window (title bar and all)
725 // and the client area; add this to the new client size to move the
727 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
728 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
730 // If there's a parent, must subtract the parent's top left corner
731 // since MoveWindow moves relative to the parent
734 point
.x
= rect2
.left
;
738 ::ScreenToClient(hParentWnd
, &point
);
741 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
743 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
744 event
.SetEventObject(this);
745 GetEventHandler()->ProcessEvent(event
);
748 bool wxWindow::Show(bool show
)
750 HWND hWnd
= (HWND
) GetHWND();
756 ShowWindow(hWnd
, (BOOL
)cshow
);
759 BringWindowToTop(hWnd
);
760 // Next line causes a crash on NT, apparently.
761 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
766 bool wxWindow::IsShown(void) const
768 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
771 int wxWindow::GetCharHeight(void) const
773 TEXTMETRIC lpTextMetric
;
774 HWND hWnd
= (HWND
) GetHWND();
775 HDC dc
= ::GetDC(hWnd
);
777 GetTextMetrics(dc
, &lpTextMetric
);
778 ::ReleaseDC(hWnd
, dc
);
780 return lpTextMetric
.tmHeight
;
783 int wxWindow::GetCharWidth(void) const
785 TEXTMETRIC lpTextMetric
;
786 HWND hWnd
= (HWND
) GetHWND();
787 HDC dc
= ::GetDC(hWnd
);
789 GetTextMetrics(dc
, &lpTextMetric
);
790 ::ReleaseDC(hWnd
, dc
);
792 return lpTextMetric
.tmAveCharWidth
;
795 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
796 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
798 wxFont
*fontToUse
= (wxFont
*)theFont
;
800 fontToUse
= (wxFont
*) & m_windowFont
;
802 HWND hWnd
= (HWND
) GetHWND();
803 HDC dc
= ::GetDC(hWnd
);
807 if (fontToUse
&& fontToUse
->Ok())
809 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
810 was
= (HFONT
) SelectObject(dc
,fnt
) ;
815 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
816 GetTextMetrics(dc
, &tm
);
818 if (fontToUse
&& fnt
&& was
)
819 SelectObject(dc
,was
) ;
825 if (descent
) *descent
= tm
.tmDescent
;
826 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
829 // fontToUse->ReleaseResource();
832 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
834 HWND hWnd
= (HWND
) GetHWND();
840 mswRect
.left
= rect
->x
;
841 mswRect
.top
= rect
->y
;
842 mswRect
.right
= rect
->x
+ rect
->width
;
843 mswRect
.bottom
= rect
->y
+ rect
->height
;
845 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
848 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
852 // Hook for new window just as it's being created,
853 // when the window isn't yet associated with the handle
854 wxWindow
*wxWndHook
= NULL
;
857 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
859 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
861 if (!wnd
&& wxWndHook
)
863 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
866 wnd
->m_hWnd
= (WXHWND
) hWnd
;
869 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
871 // Stop right here if we don't have a valid handle
872 // in our wxWnd object.
873 if (wnd
&& !wnd
->m_hWnd
) {
874 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
875 wnd
->m_hWnd
= (WXHWND
) hWnd
;
876 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
882 wnd
->m_lastMsg
= message
;
883 wnd
->m_lastWParam
= wParam
;
884 wnd
->m_lastLParam
= lParam
;
887 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
889 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
892 // Should probably have a test for 'genuine' NT
893 #if defined(__WIN32__)
894 #define DIMENSION_TYPE short
896 #define DIMENSION_TYPE int
899 // Main Windows 3 window proc
900 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
903 wxLogTrace(wxTraceMessages
, "Processing %s", GetMessageName(message
));
906 HWND hWnd
= (HWND
)m_hWnd
;
913 WORD state
= LOWORD(wParam
);
914 WORD minimized
= HIWORD(wParam
);
915 HWND hwnd
= (HWND
)lParam
;
917 WORD state
= (WORD
)wParam
;
918 WORD minimized
= LOWORD(lParam
);
919 HWND hwnd
= (HWND
)HIWORD(lParam
);
921 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
927 HWND hwnd
= (HWND
)wParam
;
928 // return OnSetFocus(hwnd);
930 if (MSWOnSetFocus((WXHWND
) hwnd
))
932 else return MSWDefWindowProc(message
, wParam
, lParam
);
937 HWND hwnd
= (HWND
)lParam
;
938 // return OnKillFocus(hwnd);
939 if (MSWOnKillFocus((WXHWND
) hwnd
))
942 return MSWDefWindowProc(message
, wParam
, lParam
);
947 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
953 MSWOnShow((wParam
!= 0), (int) lParam
);
960 else return MSWDefWindowProc(message
, wParam
, lParam
);
963 case WM_QUERYDRAGICON
:
966 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
968 else return MSWDefWindowProc(message
, wParam
, lParam
);
974 int width
= LOWORD(lParam
);
975 int height
= HIWORD(lParam
);
976 MSWOnSize(width
, height
, wParam
);
980 case WM_WINDOWPOSCHANGING
:
982 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
983 MSWOnWindowPosChanging((void *)pos
);
989 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
990 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
991 MSWOnRButtonDown(x
, y
, wParam
);
996 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
997 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
998 MSWOnRButtonUp(x
, y
, wParam
);
1001 case WM_RBUTTONDBLCLK
:
1003 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1004 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1005 MSWOnRButtonDClick(x
, y
, wParam
);
1008 case WM_MBUTTONDOWN
:
1010 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1011 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1012 MSWOnMButtonDown(x
, y
, wParam
);
1017 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1018 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1019 MSWOnMButtonUp(x
, y
, wParam
);
1022 case WM_MBUTTONDBLCLK
:
1024 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1025 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1026 MSWOnMButtonDClick(x
, y
, wParam
);
1029 case WM_LBUTTONDOWN
:
1031 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1032 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1033 MSWOnLButtonDown(x
, y
, wParam
);
1038 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1039 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1040 MSWOnLButtonUp(x
, y
, wParam
);
1043 case WM_LBUTTONDBLCLK
:
1045 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1046 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1047 MSWOnLButtonDClick(x
, y
, wParam
);
1052 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1053 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1054 MSWOnMouseMove(x
, y
, wParam
);
1057 case MM_JOY1BUTTONDOWN
:
1059 int x
= LOWORD(lParam
);
1060 int y
= HIWORD(lParam
);
1061 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1064 case MM_JOY2BUTTONDOWN
:
1066 int x
= LOWORD(lParam
);
1067 int y
= HIWORD(lParam
);
1068 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1071 case MM_JOY1BUTTONUP
:
1073 int x
= LOWORD(lParam
);
1074 int y
= HIWORD(lParam
);
1075 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1078 case MM_JOY2BUTTONUP
:
1080 int x
= LOWORD(lParam
);
1081 int y
= HIWORD(lParam
);
1082 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1087 int x
= LOWORD(lParam
);
1088 int y
= HIWORD(lParam
);
1089 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1094 int x
= LOWORD(lParam
);
1095 int y
= HIWORD(lParam
);
1096 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1101 int z
= LOWORD(lParam
);
1102 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1107 int z
= LOWORD(lParam
);
1108 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1115 else return MSWDefWindowProc(message
, wParam
, lParam
);
1120 return MSWOnSysCommand(wParam
, lParam
);
1126 WORD id
= LOWORD(wParam
);
1127 HWND hwnd
= (HWND
)lParam
;
1128 WORD cmd
= HIWORD(wParam
);
1130 WORD id
= (WORD
)wParam
;
1131 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1132 WORD cmd
= HIWORD(lParam
);
1134 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1135 return MSWDefWindowProc(message
, wParam
, lParam
);
1138 #if defined(__WIN95__)
1141 if (!MSWOnNotify(wParam
, lParam
))
1142 return MSWDefWindowProc(message
, wParam
, lParam
);
1149 WORD flags
= HIWORD(wParam
);
1150 HMENU sysmenu
= (HMENU
)lParam
;
1152 WORD flags
= LOWORD(lParam
);
1153 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1155 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1158 case WM_INITMENUPOPUP
:
1160 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1165 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1168 case WM_MEASUREITEM
:
1170 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1175 // we consider these message "not interesting"
1176 if ( wParam
== VK_SHIFT
|| wParam
== VK_CONTROL
)
1179 // Avoid duplicate messages to OnChar
1180 if ( (wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) &&
1181 (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) &&
1182 (wParam
!= VK_TAB
) )
1184 MSWOnChar((WORD
)wParam
, lParam
);
1185 if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1188 else if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1189 MSWOnChar((WORD
)wParam
, lParam
);
1197 case WM_CHAR
: // Always an ASCII character
1199 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1206 WORD code
= LOWORD(wParam
);
1207 WORD pos
= HIWORD(wParam
);
1208 HWND control
= (HWND
)lParam
;
1210 WORD code
= (WORD
)wParam
;
1211 WORD pos
= LOWORD(lParam
);
1212 HWND control
= (HWND
)HIWORD(lParam
);
1214 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1220 WORD code
= LOWORD(wParam
);
1221 WORD pos
= HIWORD(wParam
);
1222 HWND control
= (HWND
)lParam
;
1224 WORD code
= (WORD
)wParam
;
1225 WORD pos
= LOWORD(lParam
);
1226 HWND control
= (HWND
)HIWORD(lParam
);
1228 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1232 case WM_CTLCOLORBTN
:
1234 int nCtlColor
= CTLCOLOR_BTN
;
1235 HWND control
= (HWND
)lParam
;
1236 HDC pDC
= (HDC
)wParam
;
1237 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1238 message
, wParam
, lParam
);
1241 case WM_CTLCOLORDLG
:
1243 int nCtlColor
= CTLCOLOR_DLG
;
1244 HWND control
= (HWND
)lParam
;
1245 HDC pDC
= (HDC
)wParam
;
1246 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1247 message
, wParam
, lParam
);\
1250 case WM_CTLCOLORLISTBOX
:
1252 int nCtlColor
= CTLCOLOR_LISTBOX
;
1253 HWND control
= (HWND
)lParam
;
1254 HDC pDC
= (HDC
)wParam
;
1255 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1256 message
, wParam
, lParam
);
1259 case WM_CTLCOLORMSGBOX
:
1261 int nCtlColor
= CTLCOLOR_MSGBOX
;
1262 HWND control
= (HWND
)lParam
;
1263 HDC pDC
= (HDC
)wParam
;
1264 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1265 message
, wParam
, lParam
);
1268 case WM_CTLCOLORSCROLLBAR
:
1270 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1271 HWND control
= (HWND
)lParam
;
1272 HDC pDC
= (HDC
)wParam
;
1273 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1274 message
, wParam
, lParam
);
1277 case WM_CTLCOLORSTATIC
:
1279 int nCtlColor
= CTLCOLOR_STATIC
;
1280 HWND control
= (HWND
)lParam
;
1281 HDC pDC
= (HDC
)wParam
;
1282 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1283 message
, wParam
, lParam
);
1286 case WM_CTLCOLOREDIT
:
1288 int nCtlColor
= CTLCOLOR_EDIT
;
1289 HWND control
= (HWND
)lParam
;
1290 HDC pDC
= (HDC
)wParam
;
1291 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1292 message
, wParam
, lParam
);
1298 HWND control
= (HWND
)LOWORD(lParam
);
1299 int nCtlColor
= (int)HIWORD(lParam
);
1300 HDC pDC
= (HDC
)wParam
;
1301 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1302 message
, wParam
, lParam
);
1306 case WM_SYSCOLORCHANGE
:
1308 // Return value of 0 means, we processed it.
1309 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1312 return MSWDefWindowProc(message
, wParam
, lParam
);
1317 // Prevents flicker when dragging
1318 if (IsIconic(hWnd
)) return 1;
1322 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1323 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1327 case WM_MDIACTIVATE
:
1330 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1331 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1332 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1333 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1335 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1336 (HWND
)HIWORD(lParam
));
1341 MSWOnDropFiles(wParam
);
1346 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1349 case WM_QUERYENDSESSION
:
1351 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1352 return MSWOnClose();
1364 case WM_GETMINMAXINFO
:
1366 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1367 if (m_minSizeX
!= -1)
1368 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1369 if (m_minSizeY
!= -1)
1370 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1371 if (m_maxSizeX
!= -1)
1372 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1373 if (m_maxSizeY
!= -1)
1374 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1375 return MSWDefWindowProc(message
, wParam
, lParam
);
1380 return MSWGetDlgCode();
1386 __ddeUnblock(hWnd, wParam);
1390 case ASYNC_SELECT_MESSAGE:
1391 return ddeWindowProc(hWnd,message,wParam,lParam);
1396 return MSWDefWindowProc(message
, wParam
, lParam
);
1398 return 0; // Success: we processed this command.
1401 // Dialog window proc
1402 LONG APIENTRY _EXPORT
1403 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1408 wxList
*wxWinHandleList
= NULL
;
1409 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1411 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1414 return (wxWindow
*)node
->Data();
1417 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1419 // adding NULL hWnd is (first) surely a result of an error and
1420 // (secondly) breaks menu command processing
1421 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1423 if ( !wxWinHandleList
->Find((long)hWnd
) )
1424 wxWinHandleList
->Append((long)hWnd
, win
);
1427 void wxRemoveHandleAssociation(wxWindow
*win
)
1429 wxWinHandleList
->DeleteObject(win
);
1432 // Default destroyer - override if you destroy it in some other way
1433 // (e.g. with MDI child windows)
1434 void wxWindow::MSWDestroyWindow(void)
1439 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1441 MSWDetachWindowMenu();
1442 // SetWindowLong(handle, 0, (long)0);
1443 HWND oldHandle
= handle
;
1446 ::DestroyWindow(oldHandle
);
1448 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1449 // or when Windows HWND is deleted if MDI parent or
1454 ::DestroyMenu(m_hMenu);
1461 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1462 int x
, int y
, int width
, int height
,
1463 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1465 bool is_dialog
= (dialog_template
!= NULL
);
1466 int x1
= CW_USEDEFAULT
;
1468 int width1
= CW_USEDEFAULT
;
1471 // Find parent's size, if it exists, to set up a possible default
1472 // panel size the size of the parent window
1476 // Was GetWindowRect: JACS 5/5/95
1477 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1479 width1
= parent_rect
.right
- parent_rect
.left
;
1480 height1
= parent_rect
.bottom
- parent_rect
.top
;
1485 if (width
> -1) width1
= width
;
1486 if (height
> -1) height1
= height
;
1488 HWND hParent
= NULL
;
1490 hParent
= (HWND
) parent
->GetHWND();
1496 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1497 // other compilers???
1498 // VZ: it's always needed for Win16 and never for Win32
1500 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1501 (DLGPROC
)wxDlgProc
);
1503 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1505 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1510 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1511 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1512 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1517 if (style
& WS_CHILD
)
1522 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1527 // hParent, NULL, wxGetInstance(),
1528 hParent
, (HMENU
)controlId
, wxGetInstance(),
1534 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1537 "Fatal wxWindows Error");
1541 wxWinHandleList
->Append((long)m_hWnd
, this);
1544 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1548 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1552 bool wxWindow::MSWOnClose(void)
1555 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1560 bool wxWindow::MSWOnDestroy(void)
1563 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1565 // delete our drop target if we've got one
1566 #if USE_DRAG_AND_DROP
1567 if ( m_pDropTarget
!= NULL
) {
1568 m_pDropTarget
->Revoke(m_hWnd
);
1570 delete m_pDropTarget
;
1571 m_pDropTarget
= NULL
;
1578 // Deal with child commands from buttons etc.
1580 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1582 #if defined(__WIN95__)
1583 // Find a child window to send the notification to, e.g. a toolbar.
1584 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1585 // handle of the toolbar; it's probably the handle of the tooltip
1586 // window (anyway, it's parent is also the toolbar's parent).
1587 // So, since we don't know which hWnd or wxWindow originated the
1588 // WM_NOTIFY, we'll need to go through all the children of this window
1589 // trying out MSWNotify.
1590 // This won't work now, though, because any number of controls
1591 // could respond to the same generic messages :-(
1593 /* This doesn't work for toolbars, but try for other controls first.
1595 NMHDR
*hdr
= (NMHDR
*)lParam
;
1596 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1597 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1600 return win
->MSWNotify(wParam
, lParam
);
1603 // Rely on MSWNotify to check whether the message
1604 // belongs to the window or not
1605 wxNode
*node
= GetChildren()->First();
1608 wxWindow
*child
= (wxWindow
*)node
->Data();
1609 if ( child
->MSWNotify(wParam
, lParam
) )
1611 node
= node
->Next();
1621 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1624 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1628 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1632 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1635 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1638 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1640 event
.SetEventObject(this);
1641 GetEventHandler()->ProcessEvent(event
);
1645 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1648 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1651 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1653 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1655 ::ShowCaret((HWND
) GetHWND());
1658 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1659 event
.SetEventObject(this);
1660 if (!GetEventHandler()->ProcessEvent(event
))
1665 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1668 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1676 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1677 event
.SetEventObject(this);
1678 if (!GetEventHandler()->ProcessEvent(event
))
1683 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1686 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1689 HDROP hFilesInfo
= (HDROP
) wParam
;
1691 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1693 // Get the total number of files dropped
1694 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1699 wxString
*files
= new wxString
[gwFilesDropped
];
1701 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1703 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1704 files
[wIndex
] = wxBuffer
;
1706 DragFinish (hFilesInfo
);
1708 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1709 event
.m_eventObject
= this;
1710 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1712 if (!GetEventHandler()->ProcessEvent(event
))
1718 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1721 if ( id
== 0 ) { // is it a menu item?
1722 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1723 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1724 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1726 // prepare to call OnDrawItem()
1728 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1729 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1730 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1731 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1732 return pMenuItem
->OnDrawItem(
1734 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1735 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1738 #endif // owner-drawn menus
1740 wxWindow
*item
= FindItem(id
);
1741 #if USE_DYNAMIC_CLASSES
1742 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1744 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1751 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1754 if ( id
== 0 ) { // is it a menu item?
1755 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1756 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1757 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1759 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1760 &pMeasureStruct
->itemHeight
);
1762 #endif // owner-drawn menus
1764 wxWindow
*item
= FindItem(id
);
1765 #if USE_DYNAMIC_CLASSES
1766 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1768 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1775 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1776 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1779 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1781 if (nCtlColor
== CTLCOLOR_DLG
)
1783 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1786 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1788 WXHBRUSH hBrush
= 0;
1791 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1793 // I think that even for dialogs, we may need to call DefWindowProc (?)
1794 // Or maybe just rely on the usual default behaviour.
1796 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1801 // Define for each class of dialog and control
1802 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1803 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1805 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1808 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1810 wxSysColourChangedEvent event
;
1811 event
.m_eventObject
= this;
1813 // Check if app handles this.
1814 if (GetEventHandler()->ProcessEvent(event
))
1817 // We didn't process it
1821 // Responds to colour changes: passes event on to children.
1822 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1824 wxNode
*node
= GetChildren()->First();
1827 // Only propagate to non-top-level windows
1828 wxWindow
*win
= (wxWindow
*)node
->Data();
1829 if ( win
->GetParent() )
1831 wxSysColourChangedEvent event2
;
1832 event
.m_eventObject
= win
;
1833 win
->GetEventHandler()->ProcessEvent(event2
);
1836 node
= node
->Next();
1840 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1843 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1845 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1848 long wxWindow::Default()
1850 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1855 wxLogTrace(wxTraceMessages
, "Forwarding %s to DefWindowProc.",
1856 GetMessageName(m_lastMsg
));
1859 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1862 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1864 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) ) {
1865 // intercept dialog navigation keys
1866 MSG
*msg
= (MSG
*)pMsg
;
1867 bool bProcess
= TRUE
;
1868 if ( msg
->message
!= WM_KEYDOWN
)
1871 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1874 bool bCtrlDown
= (::GetKeyState(VK_CONTROL
) & 0x100) != 0;
1876 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1877 // (except for Ctrl-Tab combination which is always processed)
1879 if ( bProcess
&& !bCtrlDown
) {
1880 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1885 switch ( msg
->wParam
) {
1887 if ( lDlgCode
& DLGC_WANTTAB
)
1890 bForward
= !(::GetKeyState(VK_SHIFT
) & 0x100);
1895 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1903 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1915 wxNavigationKeyEvent event
;
1916 event
.SetDirection(bForward
);
1917 event
.SetWindowChange(bCtrlDown
);
1918 event
.SetEventObject(this);
1920 if ( GetEventHandler()->ProcessEvent(event
) )
1924 return ::IsDialogMessage((HWND
)GetHWND(), msg
) != 0;
1930 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
1933 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1938 void wxWindow::MSWDetachWindowMenu(void)
1942 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1944 for (i
= 0; i
< N
; i
++)
1947 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1948 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1950 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
1957 bool wxWindow::MSWOnPaint(void)
1959 wxPaintEvent
event(m_windowId
);
1960 event
.SetEventObject(this);
1961 if (!GetEventHandler()->ProcessEvent(event
))
1966 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
1972 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
1979 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
1980 event
.SetEventObject(this);
1981 if (!GetEventHandler()->ProcessEvent(event
))
1987 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
1992 // Deal with child commands from buttons etc.
1993 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
1996 wxDebugMsg("wxWindow::MSWOnCommand\n");
1998 if (wxCurrentPopupMenu
)
2000 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2001 wxCurrentPopupMenu
= NULL
;
2002 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2007 sprintf(buf
, "Looking for item %d...\n", id
);
2011 wxWindow
*item
= FindItem(id
);
2014 bool value
= item
->MSWCommand(cmd
, id
);
2017 wxDebugMsg("MSWCommand succeeded\n");
2019 wxDebugMsg("MSWCommand failed\n");
2026 wxDebugMsg("Could not find item!\n");
2028 wxDebugMsg("Item ids for this panel:\n");
2030 wxNode
*current
= GetChildren()->First();
2033 wxObject
*obj
= (wxObject
*)current
->Data() ;
2034 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2036 wxControl
*item
= (wxControl
*)current
->Data();
2037 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2040 current
= current
->Next();
2048 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2054 wxMaximizeEvent
event(m_windowId
);
2055 event
.SetEventObject(this);
2056 if (!GetEventHandler()->ProcessEvent(event
))
2064 wxIconizeEvent
event(m_windowId
);
2065 event
.SetEventObject(this);
2066 if (!GetEventHandler()->ProcessEvent(event
))
2078 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2080 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2082 event
.m_x
= x
; event
.m_y
= y
;
2083 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2084 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2085 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2086 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2087 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2088 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2089 event
.m_eventObject
= this;
2091 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2093 if (!GetEventHandler()->ProcessEvent(event
))
2097 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2099 wxMouseEvent
event(wxEVT_LEFT_UP
);
2101 event
.m_x
= x
; event
.m_y
= y
;
2102 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2103 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2104 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2105 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2106 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2107 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2108 event
.m_eventObject
= this;
2110 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2112 if (!GetEventHandler()->ProcessEvent(event
))
2116 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2118 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2120 event
.m_x
= x
; event
.m_y
= y
;
2121 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2122 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2123 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2124 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2125 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2126 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2127 event
.m_eventObject
= this;
2129 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2131 if (!GetEventHandler()->ProcessEvent(event
))
2135 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2137 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2139 event
.m_x
= x
; event
.m_y
= y
;
2140 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2141 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2142 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2143 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2144 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2145 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2146 event
.m_eventObject
= this;
2148 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2150 if (!GetEventHandler()->ProcessEvent(event
))
2154 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2156 //wxDebugMsg("MButtonUp\n") ;
2157 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2159 event
.m_x
= x
; event
.m_y
= y
;
2160 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2161 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2162 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2163 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2164 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2165 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2166 event
.m_eventObject
= this;
2168 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2170 if (!GetEventHandler()->ProcessEvent(event
))
2174 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2176 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2178 event
.m_x
= x
; event
.m_y
= y
;
2179 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2180 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2181 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2182 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2183 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2184 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2185 event
.m_eventObject
= this;
2187 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2189 if (!GetEventHandler()->ProcessEvent(event
))
2193 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2195 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2197 event
.m_x
= x
; event
.m_y
= y
;
2198 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2199 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2200 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2201 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2202 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2203 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2204 event
.m_eventObject
= this;
2206 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2208 if (!GetEventHandler()->ProcessEvent(event
))
2212 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2214 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2216 event
.m_x
= x
; event
.m_y
= y
;
2217 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2218 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2219 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2220 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2221 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2222 event
.m_eventObject
= this;
2223 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2225 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2227 if (!GetEventHandler()->ProcessEvent(event
))
2231 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2233 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2235 event
.m_x
= x
; event
.m_y
= y
;
2236 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2237 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2238 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2239 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2240 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2241 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2242 event
.m_eventObject
= this;
2244 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2246 if (!GetEventHandler()->ProcessEvent(event
))
2250 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2252 // 'normal' move event...
2253 // Set cursor, but only if we're not in 'busy' mode
2255 // Trouble with this is that it sets the cursor for controls too :-(
2256 if (m_windowCursor
.Ok() && !wxIsBusy())
2257 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2259 if (!m_mouseInWindow
)
2261 // Generate an ENTER event
2262 m_mouseInWindow
= TRUE
;
2263 MSWOnMouseEnter(x
, y
, flags
);
2266 wxMouseEvent
event(wxEVT_MOTION
);
2268 event
.m_x
= x
; event
.m_y
= y
;
2269 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2270 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2271 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2272 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2273 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2274 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2275 event
.m_eventObject
= this;
2277 // Window gets a click down message followed by a mouse move
2278 // message even if position isn't changed! We want to discard
2279 // the trailing move event if x and y are the same.
2280 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2281 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2282 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2284 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2285 m_lastEvent
= wxEVT_MOTION
;
2289 m_lastEvent
= wxEVT_MOTION
;
2290 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2292 if (!GetEventHandler()->ProcessEvent(event
))
2296 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2298 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2300 event
.m_x
= x
; event
.m_y
= y
;
2301 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2302 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2303 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2304 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2305 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2306 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2307 event
.m_eventObject
= this;
2309 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2310 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2311 // No message - ensure we don't try to call the default behaviour accidentally.
2313 GetEventHandler()->ProcessEvent(event
);
2316 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2318 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2320 event
.m_x
= x
; event
.m_y
= y
;
2321 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2322 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2323 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2324 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2325 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2326 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2327 event
.m_eventObject
= this;
2329 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2330 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2331 // No message - ensure we don't try to call the default behaviour accidentally.
2333 GetEventHandler()->ProcessEvent(event
);
2336 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2339 bool tempControlDown
= FALSE
;
2342 // If 1 -> 26, translate to CTRL plus a letter.
2344 if ((id
> 0) && (id
< 27))
2365 tempControlDown
= TRUE
;
2371 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2372 // it's ASCII and will be processed here only when called from
2373 // WM_CHAR (i.e. when isASCII = TRUE)
2379 wxKeyEvent
event(wxEVT_CHAR
);
2380 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2381 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2382 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2383 event
.m_altDown
= TRUE
;
2385 event
.m_eventObject
= this;
2386 event
.m_keyCode
= id
;
2387 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2392 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2396 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2398 if (!GetEventHandler()->ProcessEvent(event
))
2403 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2407 if (flags
& JOY_BUTTON1CHG
)
2408 change
= wxJOY_BUTTON1
;
2409 if (flags
& JOY_BUTTON2CHG
)
2410 change
= wxJOY_BUTTON2
;
2411 if (flags
& JOY_BUTTON3CHG
)
2412 change
= wxJOY_BUTTON3
;
2413 if (flags
& JOY_BUTTON4CHG
)
2414 change
= wxJOY_BUTTON4
;
2416 if (flags
& JOY_BUTTON1
)
2417 buttons
|= wxJOY_BUTTON1
;
2418 if (flags
& JOY_BUTTON2
)
2419 buttons
|= wxJOY_BUTTON2
;
2420 if (flags
& JOY_BUTTON3
)
2421 buttons
|= wxJOY_BUTTON3
;
2422 if (flags
& JOY_BUTTON4
)
2423 buttons
|= wxJOY_BUTTON4
;
2425 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2426 event
.SetPosition(wxPoint(x
, y
));
2427 event
.SetEventObject(this);
2429 GetEventHandler()->ProcessEvent(event
);
2432 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2436 if (flags
& JOY_BUTTON1CHG
)
2437 change
= wxJOY_BUTTON1
;
2438 if (flags
& JOY_BUTTON2CHG
)
2439 change
= wxJOY_BUTTON2
;
2440 if (flags
& JOY_BUTTON3CHG
)
2441 change
= wxJOY_BUTTON3
;
2442 if (flags
& JOY_BUTTON4CHG
)
2443 change
= wxJOY_BUTTON4
;
2445 if (flags
& JOY_BUTTON1
)
2446 buttons
|= wxJOY_BUTTON1
;
2447 if (flags
& JOY_BUTTON2
)
2448 buttons
|= wxJOY_BUTTON2
;
2449 if (flags
& JOY_BUTTON3
)
2450 buttons
|= wxJOY_BUTTON3
;
2451 if (flags
& JOY_BUTTON4
)
2452 buttons
|= wxJOY_BUTTON4
;
2454 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2455 event
.SetPosition(wxPoint(x
, y
));
2456 event
.SetEventObject(this);
2458 GetEventHandler()->ProcessEvent(event
);
2461 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2464 if (flags
& JOY_BUTTON1
)
2465 buttons
|= wxJOY_BUTTON1
;
2466 if (flags
& JOY_BUTTON2
)
2467 buttons
|= wxJOY_BUTTON2
;
2468 if (flags
& JOY_BUTTON3
)
2469 buttons
|= wxJOY_BUTTON3
;
2470 if (flags
& JOY_BUTTON4
)
2471 buttons
|= wxJOY_BUTTON4
;
2473 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2474 event
.SetPosition(wxPoint(x
, y
));
2475 event
.SetEventObject(this);
2477 GetEventHandler()->ProcessEvent(event
);
2480 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2483 if (flags
& JOY_BUTTON1
)
2484 buttons
|= wxJOY_BUTTON1
;
2485 if (flags
& JOY_BUTTON2
)
2486 buttons
|= wxJOY_BUTTON2
;
2487 if (flags
& JOY_BUTTON3
)
2488 buttons
|= wxJOY_BUTTON3
;
2489 if (flags
& JOY_BUTTON4
)
2490 buttons
|= wxJOY_BUTTON4
;
2492 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2493 event
.SetZPosition(z
);
2494 event
.SetEventObject(this);
2496 GetEventHandler()->ProcessEvent(event
);
2499 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2503 wxWindow
*child
= wxFindWinFromHandle(control
);
2505 child
->MSWOnVScroll(wParam
, pos
, control
);
2509 wxScrollEvent event
;
2510 event
.SetPosition(pos
);
2511 event
.SetOrientation(wxVERTICAL
);
2512 event
.m_eventObject
= this;
2517 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2521 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2525 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2529 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2533 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2537 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2541 case SB_THUMBPOSITION
:
2542 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2550 if (!GetEventHandler()->ProcessEvent(event
))
2554 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2558 wxWindow
*child
= wxFindWinFromHandle(control
);
2560 child
->MSWOnHScroll(wParam
, pos
, control
);
2564 wxScrollEvent event
;
2565 event
.SetPosition(pos
);
2566 event
.SetOrientation(wxHORIZONTAL
);
2567 event
.m_eventObject
= this;
2572 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2576 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2580 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2584 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2588 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2592 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2596 case SB_THUMBPOSITION
:
2597 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2604 if (!GetEventHandler()->ProcessEvent(event
))
2608 void wxWindow::MSWOnShow(bool show
, int status
)
2610 wxShowEvent
event(GetId(), show
);
2611 event
.m_eventObject
= this;
2612 GetEventHandler()->ProcessEvent(event
);
2615 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2617 wxInitDialogEvent
event(GetId());
2618 event
.m_eventObject
= this;
2619 GetEventHandler()->ProcessEvent(event
);
2623 void wxWindow::InitDialog(void)
2625 wxInitDialogEvent
event(GetId());
2626 event
.SetEventObject( this );
2627 GetEventHandler()->ProcessEvent(event
);
2630 // Default init dialog behaviour is to transfer data to window
2631 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2633 TransferDataToWindow();
2636 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2639 HDC dc
= ::GetDC((HWND
) wnd
);
2645 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2647 // the_font->UseResource();
2648 // the_font->RealizeResource();
2649 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2650 was
= (HFONT
) SelectObject(dc
,fnt
) ;
2652 GetTextMetrics(dc
, &tm
);
2653 if (the_font
&& fnt
&& was
)
2656 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2658 SelectObject(dc
,was
) ;
2660 ReleaseDC((HWND
)wnd
, dc
);
2661 *x
= tm
.tmAveCharWidth
;
2662 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2665 // the_font->ReleaseResource();
2668 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2669 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2670 int wxCharCodeMSWToWX(int keySym
)
2675 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2676 case VK_BACK
: id
= WXK_BACK
; break;
2677 case VK_TAB
: id
= WXK_TAB
; break;
2678 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2679 case VK_RETURN
: id
= WXK_RETURN
; break;
2680 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2681 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2682 case VK_MENU
: id
= WXK_MENU
; break;
2683 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2684 case VK_SPACE
: id
= WXK_SPACE
; break;
2685 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2686 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2687 case VK_NEXT
: id
= WXK_NEXT
; break;
2688 case VK_END
: id
= WXK_END
; break;
2689 case VK_HOME
: id
= WXK_HOME
; break;
2690 case VK_LEFT
: id
= WXK_LEFT
; break;
2691 case VK_UP
: id
= WXK_UP
; break;
2692 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2693 case VK_DOWN
: id
= WXK_DOWN
; break;
2694 case VK_SELECT
: id
= WXK_SELECT
; break;
2695 case VK_PRINT
: id
= WXK_PRINT
; break;
2696 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2697 case VK_INSERT
: id
= WXK_INSERT
; break;
2698 case VK_DELETE
: id
= WXK_DELETE
; break;
2699 case VK_HELP
: id
= WXK_HELP
; break;
2700 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2701 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2702 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2703 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2704 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2705 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2706 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2707 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2708 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2709 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2710 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2711 case VK_ADD
: id
= WXK_ADD
; break;
2712 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2713 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2714 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2715 case VK_F1
: id
= WXK_F1
; break;
2716 case VK_F2
: id
= WXK_F2
; break;
2717 case VK_F3
: id
= WXK_F3
; break;
2718 case VK_F4
: id
= WXK_F4
; break;
2719 case VK_F5
: id
= WXK_F5
; break;
2720 case VK_F6
: id
= WXK_F6
; break;
2721 case VK_F7
: id
= WXK_F7
; break;
2722 case VK_F8
: id
= WXK_F8
; break;
2723 case VK_F9
: id
= WXK_F9
; break;
2724 case VK_F10
: id
= WXK_F10
; break;
2725 case VK_F11
: id
= WXK_F11
; break;
2726 case VK_F12
: id
= WXK_F12
; break;
2727 case VK_F13
: id
= WXK_F13
; break;
2728 case VK_F14
: id
= WXK_F14
; break;
2729 case VK_F15
: id
= WXK_F15
; break;
2730 case VK_F16
: id
= WXK_F16
; break;
2731 case VK_F17
: id
= WXK_F17
; break;
2732 case VK_F18
: id
= WXK_F18
; break;
2733 case VK_F19
: id
= WXK_F19
; break;
2734 case VK_F20
: id
= WXK_F20
; break;
2735 case VK_F21
: id
= WXK_F21
; break;
2736 case VK_F22
: id
= WXK_F22
; break;
2737 case VK_F23
: id
= WXK_F23
; break;
2738 case VK_F24
: id
= WXK_F24
; break;
2739 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2740 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2749 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2755 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2756 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2757 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2758 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2759 case WXK_MENU
: keySym
= VK_MENU
; break;
2760 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2761 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2762 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2763 case WXK_END
: keySym
= VK_END
; break;
2764 case WXK_HOME
: keySym
= VK_HOME
; break;
2765 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2766 case WXK_UP
: keySym
= VK_UP
; break;
2767 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2768 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2769 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2770 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2771 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2772 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2773 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2774 case WXK_HELP
: keySym
= VK_HELP
; break;
2775 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2776 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2777 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2778 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2779 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2780 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2781 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2782 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2783 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2784 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2785 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2786 case WXK_ADD
: keySym
= VK_ADD
; break;
2787 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2788 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2789 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2790 case WXK_F1
: keySym
= VK_F1
; break;
2791 case WXK_F2
: keySym
= VK_F2
; break;
2792 case WXK_F3
: keySym
= VK_F3
; break;
2793 case WXK_F4
: keySym
= VK_F4
; break;
2794 case WXK_F5
: keySym
= VK_F5
; break;
2795 case WXK_F6
: keySym
= VK_F6
; break;
2796 case WXK_F7
: keySym
= VK_F7
; break;
2797 case WXK_F8
: keySym
= VK_F8
; break;
2798 case WXK_F9
: keySym
= VK_F9
; break;
2799 case WXK_F10
: keySym
= VK_F10
; break;
2800 case WXK_F11
: keySym
= VK_F11
; break;
2801 case WXK_F12
: keySym
= VK_F12
; break;
2802 case WXK_F13
: keySym
= VK_F13
; break;
2803 case WXK_F14
: keySym
= VK_F14
; break;
2804 case WXK_F15
: keySym
= VK_F15
; break;
2805 case WXK_F16
: keySym
= VK_F16
; break;
2806 case WXK_F17
: keySym
= VK_F17
; break;
2807 case WXK_F18
: keySym
= VK_F18
; break;
2808 case WXK_F19
: keySym
= VK_F19
; break;
2809 case WXK_F20
: keySym
= VK_F20
; break;
2810 case WXK_F21
: keySym
= VK_F21
; break;
2811 case WXK_F22
: keySym
= VK_F22
; break;
2812 case WXK_F23
: keySym
= VK_F23
; break;
2813 case WXK_F24
: keySym
= VK_F24
; break;
2814 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2815 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2826 // Caret manipulation
2827 void wxWindow::CreateCaret(int w
, int h
)
2831 m_caretEnabled
= TRUE
;
2834 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2839 void wxWindow::ShowCaret(bool show
)
2844 ::ShowCaret((HWND
) GetHWND());
2846 ::HideCaret((HWND
) GetHWND());
2847 m_caretShown
= show
;
2851 void wxWindow::DestroyCaret(void)
2853 m_caretEnabled
= FALSE
;
2856 void wxWindow::SetCaretPos(int x
, int y
)
2858 ::SetCaretPos(x
, y
);
2861 void wxWindow::GetCaretPos(int *x
, int *y
) const
2864 ::GetCaretPos(&point
);
2870 * Update iterator. Use from within OnPaint.
2873 static RECT gs_UpdateRect
;
2875 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2877 current
= 0; //start somewhere...
2878 #if defined(__WIN32__) && !defined(__win32s__)
2879 rlist
= NULL
; //make sure I don't free randomly
2880 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2883 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2884 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2885 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2886 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2891 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2892 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2893 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2894 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2896 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
2900 wxUpdateIterator::~wxUpdateIterator(void)
2904 if (rlist
) delete (RGNDATA
*) rlist
;
2909 wxUpdateIterator::operator int (void)
2911 if (current
< rects
)
2921 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
2927 void wxUpdateIterator::GetRect(wxRect
*rect
)
2929 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
2930 rect
->x
= mswRect
->left
;
2931 rect
->y
= mswRect
->top
;
2932 rect
->width
= mswRect
->right
- mswRect
->left
;
2933 rect
->height
= mswRect
->bottom
- mswRect
->top
;
2936 int wxUpdateIterator::GetX()
2938 return ((RECT
*)rp
)[current
].left
;
2941 int wxUpdateIterator::GetY()
2943 return ((RECT
*)rp
)[current
].top
;
2946 int wxUpdateIterator::GetW()
2948 return ((RECT
*)rp
)[current
].right
-GetX();
2951 int wxUpdateIterator::GetH()
2953 return ((RECT
*)rp
)[current
].bottom
-GetY();
2956 wxWindow
*wxGetActiveWindow(void)
2958 HWND hWnd
= GetActiveWindow();
2961 return wxFindWinFromHandle((WXHWND
) hWnd
);
2966 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2967 // in active frames and dialogs, regardless of where the focus is.
2968 static HHOOK wxTheKeyboardHook
= 0;
2969 static FARPROC wxTheKeyboardHookProc
= 0;
2970 int APIENTRY _EXPORT
2971 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
2973 void wxSetKeyboardHook(bool doIt
)
2977 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
2978 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
2980 GetCurrentThreadId());
2981 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2988 UnhookWindowsHookEx(wxTheKeyboardHook
);
2989 FreeProcInstance(wxTheKeyboardHookProc
);
2993 int APIENTRY _EXPORT
2994 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
2996 DWORD hiWord
= HIWORD(lParam
);
2997 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3000 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3002 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3003 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3004 event
.m_altDown
= TRUE
;
3006 event
.m_eventObject
= NULL
;
3007 event
.m_keyCode
= id
;
3008 /* begin Albert's fix for control and shift key 26.5 */
3009 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3010 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3011 /* end Albert's fix for control and shift key 26.5 */
3012 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3014 wxWindow
*win
= wxGetActiveWindow();
3017 if (win
->GetEventHandler()->ProcessEvent(event
))
3022 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3027 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3030 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3038 void wxWindow::Centre(int direction
)
3040 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3042 wxWindow
*father
= (wxWindow
*)GetParent();
3046 father
->GetClientSize(&panel_width
, &panel_height
);
3047 GetSize(&width
, &height
);
3048 GetPosition(&x
, &y
);
3053 if (direction
& wxHORIZONTAL
)
3054 new_x
= (int)((panel_width
- width
)/2);
3056 if (direction
& wxVERTICAL
)
3057 new_y
= (int)((panel_height
- height
)/2);
3059 SetSize(new_x
, new_y
, -1, -1);
3064 void wxWindow::OnPaint(void)
3066 PaintSelectionHandles();
3070 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3072 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3073 // pixel coordinates, relatives to the canvas -- So, we first need to
3074 // substract origin of the window, then convert to screen position
3076 int x
= x_pos
; int y
= y_pos
;
3077 /* Leave this to the app to decide (and/or wxScrolledWindow)
3078 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3079 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3082 GetWindowRect ((HWND
) GetHWND(), &rect
);
3087 SetCursorPos (x
, y
);
3090 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3093 // Do we have a SetUserScale in wxWindow too, so we can
3094 // get mouse events scaled?
3098 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3099 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3104 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3112 wxEraseEvent
event(m_windowId
, &dc
);
3113 event
.m_eventObject
= this;
3114 if (!GetEventHandler()->ProcessEvent(event
))
3117 dc
.SelectOldObjects(pDC
);
3123 dc
.SelectOldObjects(pDC
);
3126 dc
.SetHDC((WXHDC
) NULL
);
3130 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3133 ::GetClientRect((HWND
) GetHWND(), &rect
);
3135 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3136 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3138 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3139 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3140 ::DeleteObject(hBrush
);
3141 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3143 // Less efficient version (and doesn't account for scrolling)
3145 GetClientSize(& w, & h);
3146 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3147 event.GetDC()->SetBrush(brush);
3148 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3150 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3154 #if WXWIN_COMPATIBILITY
3155 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3157 #if defined(__WIN95__)
3161 // Try to adjust the range to cope with page size > 1
3162 // - a Windows API quirk
3163 int pageSize
= GetScrollPage(orient
);
3164 if ( pageSize
> 1 && range
> 0)
3166 range1
+= (pageSize
- 1);
3172 if (orient
== wxHORIZONTAL
) {
3178 info
.cbSize
= sizeof(SCROLLINFO
);
3179 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3183 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3185 HWND hWnd
= (HWND
) GetHWND();
3187 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3190 if (orient
== wxHORIZONTAL
)
3195 HWND hWnd
= (HWND
) GetHWND();
3197 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3201 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3203 #if defined(__WIN95__)
3207 if (orient
== wxHORIZONTAL
) {
3209 m_xThumbSize
= page
;
3212 m_yThumbSize
= page
;
3215 info
.cbSize
= sizeof(SCROLLINFO
);
3218 info
.fMask
= SIF_PAGE
;
3220 HWND hWnd
= (HWND
) GetHWND();
3222 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3224 if (orient
== wxHORIZONTAL
)
3225 m_xThumbSize
= page
;
3227 m_yThumbSize
= page
;
3231 int wxWindow::OldGetScrollRange(int orient
) const
3234 if (orient
== wxHORIZONTAL
)
3239 #if __WATCOMC__ && defined(__WINDOWS_386__)
3240 short minPos
, maxPos
;
3244 HWND hWnd
= (HWND
) GetHWND();
3247 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3248 #if defined(__WIN95__)
3249 // Try to adjust the range to cope with page size > 1
3250 // - a Windows API quirk
3251 int pageSize
= GetScrollPage(orient
);
3254 maxPos
-= (pageSize
- 1);
3263 int wxWindow::GetScrollPage(int orient
) const
3265 if (orient
== wxHORIZONTAL
)
3266 return m_xThumbSize
;
3268 return m_yThumbSize
;
3272 int wxWindow::GetScrollPos(int orient
) const
3275 if (orient
== wxHORIZONTAL
)
3279 HWND hWnd
= (HWND
) GetHWND();
3282 return ::GetScrollPos(hWnd
, wOrient
);
3288 // This now returns the whole range, not just the number
3289 // of positions that we can scroll.
3290 int wxWindow::GetScrollRange(int orient
) const
3293 if (orient
== wxHORIZONTAL
)
3298 #if __WATCOMC__ && defined(__WINDOWS_386__)
3299 short minPos
, maxPos
;
3303 HWND hWnd
= (HWND
) GetHWND();
3306 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3307 #if defined(__WIN95__)
3308 // Try to adjust the range to cope with page size > 1
3309 // - a Windows API quirk
3310 int pageSize
= GetScrollPage(orient
);
3313 maxPos
-= (pageSize
- 1);
3315 // October 10th: new range concept.
3325 int wxWindow::GetScrollThumb(int orient
) const
3327 if (orient
== wxHORIZONTAL
)
3328 return m_xThumbSize
;
3330 return m_yThumbSize
;
3333 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3335 #if defined(__WIN95__)
3339 if (orient
== wxHORIZONTAL
) {
3345 info
.cbSize
= sizeof(SCROLLINFO
);
3349 info
.fMask
= SIF_POS
;
3351 HWND hWnd
= (HWND
) GetHWND();
3353 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3356 if (orient
== wxHORIZONTAL
)
3361 HWND hWnd
= (HWND
) GetHWND();
3363 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3367 // New function that will replace some of the above.
3368 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3369 int range
, bool refresh
)
3372 SetScrollPage(orient, thumbVisible, FALSE);
3374 int oldRange = range - thumbVisible ;
3375 SetScrollRange(orient, oldRange, FALSE);
3377 SetScrollPos(orient, pos, refresh);
3379 #if defined(__WIN95__)
3380 int oldRange
= range
- thumbVisible
;
3382 int range1
= oldRange
;
3384 // Try to adjust the range to cope with page size > 1
3385 // - a Windows API quirk
3386 int pageSize
= thumbVisible
;
3387 if ( pageSize
> 1 && range
> 0)
3389 range1
+= (pageSize
- 1);
3395 if (orient
== wxHORIZONTAL
) {
3401 info
.cbSize
= sizeof(SCROLLINFO
);
3402 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3406 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3408 HWND hWnd
= (HWND
) GetHWND();
3410 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3413 if (orient
== wxHORIZONTAL
)
3418 HWND hWnd
= (HWND
) GetHWND();
3421 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3422 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3425 if (orient
== wxHORIZONTAL
) {
3426 m_xThumbSize
= thumbVisible
;
3428 m_yThumbSize
= thumbVisible
;
3432 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3437 rect2
.left
= rect
->x
;
3438 rect2
.top
= rect
->y
;
3439 rect2
.right
= rect
->x
+ rect
->width
;
3440 rect2
.bottom
= rect
->y
+ rect
->height
;
3444 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3446 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3450 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3456 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3463 void wxWindow::SetFont(const wxFont
& font
)
3465 // Decrement the usage count of the old label font
3466 // (we may be able to free it up)
3467 // if (GetFont()->Ok())
3468 // GetFont()->ReleaseResource();
3470 m_windowFont
= font
;
3472 if (!m_windowFont
.Ok())
3475 // m_windowFont.UseResource();
3477 HWND hWnd
= (HWND
) GetHWND();
3480 // m_windowFont.RealizeResource();
3482 if (m_windowFont
.GetResourceHandle())
3483 SendMessage(hWnd
, WM_SETFONT
,
3484 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3488 void wxWindow::SubclassWin(WXHWND hWnd
)
3490 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3492 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3493 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3496 void wxWindow::UnsubclassWin(void)
3498 wxRemoveHandleAssociation(this);
3500 // Restore old Window proc
3501 if ((HWND
) GetHWND())
3503 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3504 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3506 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3512 // Make a Windows extended style from the given wxWindows window style
3513 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3515 WXDWORD exStyle
= 0;
3516 if ( style
& wxTRANSPARENT_WINDOW
)
3517 exStyle
|= WS_EX_TRANSPARENT
;
3519 if ( !eliminateBorders
)
3521 if ( style
& wxSUNKEN_BORDER
)
3522 exStyle
|= WS_EX_CLIENTEDGE
;
3523 if ( style
& wxDOUBLE_BORDER
)
3524 exStyle
|= WS_EX_DLGMODALFRAME
;
3525 #if defined(__WIN95__)
3526 if ( style
& wxRAISED_BORDER
)
3527 exStyle
|= WS_EX_WINDOWEDGE
;
3528 if ( style
& wxSTATIC_BORDER
)
3529 exStyle
|= WS_EX_STATICEDGE
;
3535 // Determines whether native 3D effects or CTL3D should be used,
3536 // applying a default border style if required, and returning an extended
3537 // style to pass to CreateWindowEx.
3538 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3540 // If matches certain criteria, then assume no 3D effects
3541 // unless specifically requested (dealt with in MakeExtendedStyle)
3542 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3545 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3548 // Determine whether we should be using 3D effects or not.
3549 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3551 // 1) App can specify global 3D effects
3552 *want3D
= wxTheApp
->GetAuto3D();
3554 // 2) If the parent is being drawn with user colours, or simple border specified,
3555 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3556 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3559 // 3) Control can override this global setting by defining
3560 // a border style, e.g. wxSUNKEN_BORDER
3561 if (m_windowStyle
& wxSUNKEN_BORDER
)
3564 // 4) If it's a special border, CTL3D can't cope so we want a native border
3565 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3566 (m_windowStyle
& wxSTATIC_BORDER
) )
3569 nativeBorder
= TRUE
;
3572 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3573 // effects from extended style
3576 nativeBorder
= FALSE
;
3579 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3581 // If we want 3D, but haven't specified a border here,
3582 // apply the default border style specified.
3583 // TODO what about non-Win95 WIN32? Does it have borders?
3584 #if defined(__WIN95__) && !CTL3D
3585 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3586 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3587 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3593 void wxWindow::OnChar(wxKeyEvent
& event
)
3595 if ( event
.KeyCode() == WXK_TAB
) {
3596 // propagate the TABs to the parent - it's up to it to decide what
3598 if ( GetParent() ) {
3599 if ( GetParent()->ProcessEvent(event
) )
3605 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3610 if ( !event
.ControlDown() )
3611 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3614 void wxWindow::OnPaint(wxPaintEvent
& event
)
3619 bool wxWindow::IsEnabled(void) const
3621 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3624 // Dialog support: override these and call
3625 // base class members to add functionality
3626 // that can't be done using validators.
3627 // NOTE: these functions assume that controls
3628 // are direct children of this window, not grandchildren
3629 // or other levels of descendant.
3631 // Transfer values to controls. If returns FALSE,
3632 // it's an application error (pops up a dialog)
3633 bool wxWindow::TransferDataToWindow(void)
3635 wxNode
*node
= GetChildren()->First();
3638 wxWindow
*child
= (wxWindow
*)node
->Data();
3639 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3640 !child
->GetValidator()->TransferToWindow() )
3642 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3646 node
= node
->Next();
3651 // Transfer values from controls. If returns FALSE,
3652 // validation failed: don't quit
3653 bool wxWindow::TransferDataFromWindow(void)
3655 wxNode
*node
= GetChildren()->First();
3658 wxWindow
*child
= (wxWindow
*)node
->Data();
3659 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3664 node
= node
->Next();
3669 bool wxWindow::Validate(void)
3671 wxNode
*node
= GetChildren()->First();
3674 wxWindow
*child
= (wxWindow
*)node
->Data();
3675 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3680 node
= node
->Next();
3685 // Get the window with the focus
3686 wxWindow
*wxWindow::FindFocus(void)
3688 HWND hWnd
= ::GetFocus();
3691 return wxFindWinFromHandle((WXHWND
) hWnd
);
3696 void wxWindow::AddChild(wxWindow
*child
)
3698 GetChildren()->Append(child
);
3699 child
->m_windowParent
= this;
3702 void wxWindow::RemoveChild(wxWindow
*child
)
3705 GetChildren()->DeleteObject(child
);
3706 child
->m_windowParent
= NULL
;
3709 void wxWindow::DestroyChildren(void)
3711 if (GetChildren()) {
3713 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3715 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3717 if ( GetChildren()->Member(child
) )
3724 void wxWindow::MakeModal(bool modal
)
3726 // Disable all other windows
3727 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3729 wxNode
*node
= wxTopLevelWindows
.First();
3732 wxWindow
*win
= (wxWindow
*)node
->Data();
3734 win
->Enable(!modal
);
3736 node
= node
->Next();
3741 // If nothing defined for this, try the parent.
3742 // E.g. we may be a button loaded from a resource, with no callback function
3744 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3746 if (GetEventHandler()->ProcessEvent(event
) )
3749 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3752 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3756 UnsetConstraints(m_constraints
);
3757 delete m_constraints
;
3762 // Make sure other windows know they're part of a 'meaningful relationship'
3763 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3764 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3765 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3766 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3767 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3768 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3769 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3770 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3771 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3772 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3773 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3774 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3775 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3776 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3777 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3778 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3782 // This removes any dangling pointers to this window
3783 // in other windows' constraintsInvolvedIn lists.
3784 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3788 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3789 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3790 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3791 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3792 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3793 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3794 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3795 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3796 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3797 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3798 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3799 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3800 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3801 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3802 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3803 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3807 // Back-pointer to other windows we're involved with, so if we delete
3808 // this window, we must delete any constraints we're involved with.
3809 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3811 if (!m_constraintsInvolvedIn
)
3812 m_constraintsInvolvedIn
= new wxList
;
3813 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3814 m_constraintsInvolvedIn
->Append(otherWin
);
3817 // REMOVE back-pointer to other windows we're involved with.
3818 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3820 if (m_constraintsInvolvedIn
)
3821 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3824 // Reset any constraints that mention this window
3825 void wxWindow::DeleteRelatedConstraints(void)
3827 if (m_constraintsInvolvedIn
)
3829 wxNode
*node
= m_constraintsInvolvedIn
->First();
3832 wxWindow
*win
= (wxWindow
*)node
->Data();
3833 wxNode
*next
= node
->Next();
3834 wxLayoutConstraints
*constr
= win
->GetConstraints();
3836 // Reset any constraints involving this window
3839 constr
->left
.ResetIfWin((wxWindow
*)this);
3840 constr
->top
.ResetIfWin((wxWindow
*)this);
3841 constr
->right
.ResetIfWin((wxWindow
*)this);
3842 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3843 constr
->width
.ResetIfWin((wxWindow
*)this);
3844 constr
->height
.ResetIfWin((wxWindow
*)this);
3845 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3846 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3851 delete m_constraintsInvolvedIn
;
3852 m_constraintsInvolvedIn
= NULL
;
3856 void wxWindow::SetSizer(wxSizer
*sizer
)
3858 m_windowSizer
= sizer
;
3860 sizer
->SetSizerParent((wxWindow
*)this);
3867 bool wxWindow::Layout(void)
3869 if (GetConstraints())
3872 GetClientSize(&w
, &h
);
3873 GetConstraints()->width
.SetValue(w
);
3874 GetConstraints()->height
.SetValue(h
);
3877 // If top level (one sizer), evaluate the sizer's constraints.
3881 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3882 GetSizer()->LayoutPhase1(&noChanges
);
3883 GetSizer()->LayoutPhase2(&noChanges
);
3884 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3889 // Otherwise, evaluate child constraints
3890 ResetConstraints(); // Mark all constraints as unevaluated
3891 DoPhase(1); // Just one phase need if no sizers involved
3893 SetConstraintSizes(); // Recursively set the real window sizes
3899 // Do a phase of evaluating constraints:
3900 // the default behaviour. wxSizers may do a similar
3901 // thing, but also impose their own 'constraints'
3902 // and order the evaluation differently.
3903 bool wxWindow::LayoutPhase1(int *noChanges
)
3905 wxLayoutConstraints
*constr
= GetConstraints();
3908 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3914 bool wxWindow::LayoutPhase2(int *noChanges
)
3924 // Do a phase of evaluating child constraints
3925 bool wxWindow::DoPhase(int phase
)
3927 int noIterations
= 0;
3928 int maxIterations
= 500;
3932 while ((noChanges
> 0) && (noIterations
< maxIterations
))
3936 wxNode
*node
= GetChildren()->First();
3939 wxWindow
*child
= (wxWindow
*)node
->Data();
3940 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
3942 wxLayoutConstraints
*constr
= child
->GetConstraints();
3945 if (succeeded
.Member(child
))
3950 int tempNoChanges
= 0;
3951 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
3952 noChanges
+= tempNoChanges
;
3955 succeeded
.Append(child
);
3960 node
= node
->Next();
3967 void wxWindow::ResetConstraints(void)
3969 wxLayoutConstraints
*constr
= GetConstraints();
3972 constr
->left
.SetDone(FALSE
);
3973 constr
->top
.SetDone(FALSE
);
3974 constr
->right
.SetDone(FALSE
);
3975 constr
->bottom
.SetDone(FALSE
);
3976 constr
->width
.SetDone(FALSE
);
3977 constr
->height
.SetDone(FALSE
);
3978 constr
->centreX
.SetDone(FALSE
);
3979 constr
->centreY
.SetDone(FALSE
);
3981 wxNode
*node
= GetChildren()->First();
3984 wxWindow
*win
= (wxWindow
*)node
->Data();
3985 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
3986 win
->ResetConstraints();
3987 node
= node
->Next();
3991 // Need to distinguish between setting the 'fake' size for
3992 // windows and sizers, and setting the real values.
3993 void wxWindow::SetConstraintSizes(bool recurse
)
3995 wxLayoutConstraints
*constr
= GetConstraints();
3996 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
3997 constr
->width
.GetDone() && constr
->height
.GetDone())
3999 int x
= constr
->left
.GetValue();
4000 int y
= constr
->top
.GetValue();
4001 int w
= constr
->width
.GetValue();
4002 int h
= constr
->height
.GetValue();
4004 // If we don't want to resize this window, just move it...
4005 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4006 (constr
->height
.GetRelationship() != wxAsIs
))
4008 // Calls Layout() recursively. AAAGH. How can we stop that.
4009 // Simply take Layout() out of non-top level OnSizes.
4010 SizerSetSize(x
, y
, w
, h
);
4019 char *windowClass
= this->GetClassInfo()->GetClassName();
4022 if (GetName() == "")
4023 winName
= "unnamed";
4025 winName
= GetName();
4026 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4027 if (!constr
->left
.GetDone())
4028 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4029 if (!constr
->right
.GetDone())
4030 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4031 if (!constr
->width
.GetDone())
4032 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4033 if (!constr
->height
.GetDone())
4034 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4035 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4040 wxNode
*node
= GetChildren()->First();
4043 wxWindow
*win
= (wxWindow
*)node
->Data();
4044 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4045 win
->SetConstraintSizes();
4046 node
= node
->Next();
4051 // This assumes that all sizers are 'on' the same
4052 // window, i.e. the parent of this window.
4053 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4055 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4056 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4060 m_sizerParent
->GetPosition(&xp
, &yp
);
4061 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4066 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4070 TransformSizerToActual(&xx
, &yy
);
4071 SetSize(xx
, yy
, w
, h
);
4074 void wxWindow::SizerMove(int x
, int y
)
4078 TransformSizerToActual(&xx
, &yy
);
4082 // Only set the size/position of the constraint (if any)
4083 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4085 wxLayoutConstraints
*constr
= GetConstraints();
4090 constr
->left
.SetValue(x
);
4091 constr
->left
.SetDone(TRUE
);
4095 constr
->top
.SetValue(y
);
4096 constr
->top
.SetDone(TRUE
);
4100 constr
->width
.SetValue(w
);
4101 constr
->width
.SetDone(TRUE
);
4105 constr
->height
.SetValue(h
);
4106 constr
->height
.SetDone(TRUE
);
4111 void wxWindow::MoveConstraint(int x
, int y
)
4113 wxLayoutConstraints
*constr
= GetConstraints();
4118 constr
->left
.SetValue(x
);
4119 constr
->left
.SetDone(TRUE
);
4123 constr
->top
.SetValue(y
);
4124 constr
->top
.SetDone(TRUE
);
4129 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4131 wxLayoutConstraints
*constr
= GetConstraints();
4134 *w
= constr
->width
.GetValue();
4135 *h
= constr
->height
.GetValue();
4141 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4143 wxLayoutConstraints
*constr
= GetConstraints();
4146 *w
= constr
->width
.GetValue();
4147 *h
= constr
->height
.GetValue();
4150 GetClientSize(w
, h
);
4153 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4155 wxLayoutConstraints
*constr
= GetConstraints();
4158 *x
= constr
->left
.GetValue();
4159 *y
= constr
->top
.GetValue();
4165 bool wxWindow::Close(bool force
)
4167 // Let's generalise it to work the same for any window.
4169 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4176 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4177 event
.SetEventObject(this);
4178 event
.SetForce(force
);
4180 return GetEventHandler()->ProcessEvent(event
);
4183 if ( !force && event.GetVeto() )
4188 if (!wxPendingDelete.Member(this))
4189 wxPendingDelete.Append(this);
4195 wxObject
* wxWindow::GetChild(int number
) const
4197 // Return a pointer to the Nth object in the Panel
4200 wxNode
*node
= GetChildren()->First();
4203 node
= node
->Next() ;
4206 wxObject
*obj
= (wxObject
*)node
->Data();
4213 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4215 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4216 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4219 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4221 wxListBox *lbox = (wxListBox *)initiatingItem;
4222 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4223 event.m_commandInt = -1;
4224 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4226 event.m_commandString = copystring(lbox->GetStringSelection());
4227 event.m_commandInt = lbox->GetSelection();
4228 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4230 event.m_eventObject = lbox;
4232 lbox->ProcessCommand(event);
4234 if (event.m_commandString)
4235 delete[] event.m_commandString;
4239 wxButton *but = GetDefaultItem();
4242 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4243 event.SetEventObject(but);
4244 but->Command(event);
4249 void wxWindow::Clear(void)
4251 wxClientDC
dc(this);
4252 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4253 dc
.SetBackground(brush
);
4257 // Fits the panel around the items
4258 void wxWindow::Fit(void)
4262 wxNode
*node
= GetChildren()->First();
4265 wxWindow
*win
= (wxWindow
*)node
->Data();
4267 win
->GetPosition(&wx
, &wy
);
4268 win
->GetSize(&ww
, &wh
);
4269 if ( wx
+ ww
> maxX
)
4271 if ( wy
+ wh
> maxY
)
4274 node
= node
->Next();
4276 SetClientSize(maxX
+ 5, maxY
+ 5);
4279 void wxWindow::SetValidator(const wxValidator
& validator
)
4281 if ( m_windowValidator
)
4282 delete m_windowValidator
;
4283 m_windowValidator
= validator
.Clone();
4285 if ( m_windowValidator
)
4286 m_windowValidator
->SetWindow(this) ;
4289 // Find a window by id or name
4290 wxWindow
*wxWindow::FindWindow(long id
)
4295 wxNode
*node
= GetChildren()->First();
4298 wxWindow
*child
= (wxWindow
*)node
->Data();
4299 wxWindow
*found
= child
->FindWindow(id
);
4302 node
= node
->Next();
4307 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4309 if ( GetName() == name
)
4312 wxNode
*node
= GetChildren()->First();
4315 wxWindow
*child
= (wxWindow
*)node
->Data();
4316 wxWindow
*found
= child
->FindWindow(name
);
4319 node
= node
->Next();
4325 // Default input behaviour for a scrolling canvas should be to scroll
4326 // according to the cursor keys pressed
4327 void wxWindow::OnChar(wxKeyEvent& event)
4339 GetScrollUnitsPerPage(&x_page, &y_page);
4341 GetVirtualSize(&v_width,&v_height);
4343 ViewStart(&start_x, &start_y);
4346 y_pages = (int)(v_height/vert_units) - y_page;
4354 switch (event.keyCode)
4361 if (start_y - y_page > 0)
4362 Scroll(start_x, start_y - y_page);
4372 if ((y_page > 0) && (start_y <= y_pages-y-1))
4374 if (y_pages + y < start_y + y_page)
4375 Scroll(start_x, y_pages + y);
4377 Scroll(start_x, start_y + y_page);
4384 if ((y_page > 0) && (start_y >= 1))
4385 Scroll(start_x, start_y - 1);
4391 if ((y_page > 0) && (start_y <= y_pages-y-1))
4394 Scroll(start_x, start_y + 1);
4400 if ((x_page > 0) && (start_x >= 1))
4401 Scroll(start_x - 1, start_y);
4407 Scroll(start_x + 1, start_y);
4418 Scroll(start_x, y_pages+y);
4426 // Setup background and foreground colours correctly
4427 void wxWindow::SetupColours(void)
4430 SetBackgroundColour(GetParent()->GetBackgroundColour());
4433 // Do Update UI processing for child controls
4435 // TODO: should this be implemented for the child window rather
4436 // than the parent? Then you can override it e.g. for wxCheckBox
4437 // to do the Right Thing rather than having to assume a fixed number
4438 // of control classes.
4440 void wxWindow::UpdateWindowUI(void)
4442 wxWindowID id
= GetId();
4445 wxUpdateUIEvent
event(id
);
4446 event
.m_eventObject
= this;
4448 if (this->GetEventHandler()->ProcessEvent(event
))
4450 if (event
.GetSetEnabled())
4451 this->Enable(event
.GetEnabled());
4453 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4454 ((wxControl
*)this)->SetLabel(event
.GetText());
4456 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4458 if (event
.GetSetChecked())
4459 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4461 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4463 if (event
.GetSetChecked())
4464 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4471 void wxWindow::OnIdle(wxIdleEvent
& event
)
4473 // Check if we need to send a LEAVE event
4474 if (m_mouseInWindow
)
4477 ::GetCursorPos(&pt
);
4478 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4480 // Generate a LEAVE event
4481 m_mouseInWindow
= FALSE
;
4482 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4488 // Raise the window to the top of the Z order
4489 void wxWindow::Raise(void)
4491 ::BringWindowToTop((HWND
) GetHWND());
4494 // Lower the window to the bottom of the Z order
4495 void wxWindow::Lower(void)
4497 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
4500 long wxWindow::MSWGetDlgCode()
4502 // default: just forward to def window proc (the msg has no parameters)
4503 return MSWDefWindowProc(WM_GETDLGCODE
, 0, 0);
4506 bool wxWindow::AcceptsFocus() const
4508 return IsShown() && IsEnabled();
4512 static const char *GetMessageName(int message
)
4514 switch ( message
) {
4515 case 0x0000: return "WM_NULL";
4516 case 0x0001: return "WM_CREATE";
4517 case 0x0002: return "WM_DESTROY";
4518 case 0x0003: return "WM_MOVE";
4519 case 0x0005: return "WM_SIZE";
4520 case 0x0006: return "WM_ACTIVATE";
4521 case 0x0007: return "WM_SETFOCUS";
4522 case 0x0008: return "WM_KILLFOCUS";
4523 case 0x000A: return "WM_ENABLE";
4524 case 0x000B: return "WM_SETREDRAW";
4525 case 0x000C: return "WM_SETTEXT";
4526 case 0x000D: return "WM_GETTEXT";
4527 case 0x000E: return "WM_GETTEXTLENGTH";
4528 case 0x000F: return "WM_PAINT";
4529 case 0x0010: return "WM_CLOSE";
4530 case 0x0011: return "WM_QUERYENDSESSION";
4531 case 0x0012: return "WM_QUIT";
4532 case 0x0013: return "WM_QUERYOPEN";
4533 case 0x0014: return "WM_ERASEBKGND";
4534 case 0x0015: return "WM_SYSCOLORCHANGE";
4535 case 0x0016: return "WM_ENDSESSION";
4536 case 0x0017: return "WM_SYSTEMERROR";
4537 case 0x0018: return "WM_SHOWWINDOW";
4538 case 0x0019: return "WM_CTLCOLOR";
4539 case 0x001A: return "WM_WININICHANGE";
4540 case 0x001B: return "WM_DEVMODECHANGE";
4541 case 0x001C: return "WM_ACTIVATEAPP";
4542 case 0x001D: return "WM_FONTCHANGE";
4543 case 0x001E: return "WM_TIMECHANGE";
4544 case 0x001F: return "WM_CANCELMODE";
4545 case 0x0020: return "WM_SETCURSOR";
4546 case 0x0021: return "WM_MOUSEACTIVATE";
4547 case 0x0022: return "WM_CHILDACTIVATE";
4548 case 0x0023: return "WM_QUEUESYNC";
4549 case 0x0024: return "WM_GETMINMAXINFO";
4550 case 0x0026: return "WM_PAINTICON";
4551 case 0x0027: return "WM_ICONERASEBKGND";
4552 case 0x0028: return "WM_NEXTDLGCTL";
4553 case 0x002A: return "WM_SPOOLERSTATUS";
4554 case 0x002B: return "WM_DRAWITEM";
4555 case 0x002C: return "WM_MEASUREITEM";
4556 case 0x002D: return "WM_DELETEITEM";
4557 case 0x002E: return "WM_VKEYTOITEM";
4558 case 0x002F: return "WM_CHARTOITEM";
4559 case 0x0030: return "WM_SETFONT";
4560 case 0x0031: return "WM_GETFONT";
4561 case 0x0037: return "WM_QUERYDRAGICON";
4562 case 0x0039: return "WM_COMPAREITEM";
4563 case 0x0041: return "WM_COMPACTING";
4564 case 0x0044: return "WM_COMMNOTIFY";
4565 case 0x0046: return "WM_WINDOWPOSCHANGING";
4566 case 0x0047: return "WM_WINDOWPOSCHANGED";
4567 case 0x0048: return "WM_POWER";
4568 case 0x0081: return "WM_NCCREATE";
4569 case 0x0082: return "WM_NCDESTROY";
4570 case 0x0083: return "WM_NCCALCSIZE";
4571 case 0x0084: return "WM_NCHITTEST";
4572 case 0x0085: return "WM_NCPAINT";
4573 case 0x0086: return "WM_NCACTIVATE";
4574 case 0x0087: return "WM_GETDLGCODE";
4575 case 0x00A0: return "WM_NCMOUSEMOVE";
4576 case 0x00A1: return "WM_NCLBUTTONDOWN";
4577 case 0x00A2: return "WM_NCLBUTTONUP";
4578 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4579 case 0x00A4: return "WM_NCRBUTTONDOWN";
4580 case 0x00A5: return "WM_NCRBUTTONUP";
4581 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4582 case 0x00A7: return "WM_NCMBUTTONDOWN";
4583 case 0x00A8: return "WM_NCMBUTTONUP";
4584 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4585 case 0x0100: return "WM_KEYDOWN";
4586 case 0x0101: return "WM_KEYUP";
4587 case 0x0102: return "WM_CHAR";
4588 case 0x0103: return "WM_DEADCHAR";
4589 case 0x0104: return "WM_SYSKEYDOWN";
4590 case 0x0105: return "WM_SYSKEYUP";
4591 case 0x0106: return "WM_SYSCHAR";
4592 case 0x0107: return "WM_SYSDEADCHAR";
4593 case 0x0108: return "WM_KEYLAST";
4594 case 0x0110: return "WM_INITDIALOG";
4595 case 0x0111: return "WM_COMMAND";
4596 case 0x0112: return "WM_SYSCOMMAND";
4597 case 0x0113: return "WM_TIMER";
4598 case 0x0114: return "WM_HSCROLL";
4599 case 0x0115: return "WM_VSCROLL";
4600 case 0x0116: return "WM_INITMENU";
4601 case 0x0117: return "WM_INITMENUPOPUP";
4602 case 0x011F: return "WM_MENUSELECT";
4603 case 0x0120: return "WM_MENUCHAR";
4604 case 0x0121: return "WM_ENTERIDLE";
4605 case 0x0200: return "WM_MOUSEMOVE";
4606 case 0x0201: return "WM_LBUTTONDOWN";
4607 case 0x0202: return "WM_LBUTTONUP";
4608 case 0x0203: return "WM_LBUTTONDBLCLK";
4609 case 0x0204: return "WM_RBUTTONDOWN";
4610 case 0x0205: return "WM_RBUTTONUP";
4611 case 0x0206: return "WM_RBUTTONDBLCLK";
4612 case 0x0207: return "WM_MBUTTONDOWN";
4613 case 0x0208: return "WM_MBUTTONUP";
4614 case 0x0209: return "WM_MBUTTONDBLCLK";
4615 case 0x0210: return "WM_PARENTNOTIFY";
4616 case 0x0220: return "WM_MDICREATE";
4617 case 0x0221: return "WM_MDIDESTROY";
4618 case 0x0222: return "WM_MDIACTIVATE";
4619 case 0x0223: return "WM_MDIRESTORE";
4620 case 0x0224: return "WM_MDINEXT";
4621 case 0x0225: return "WM_MDIMAXIMIZE";
4622 case 0x0226: return "WM_MDITILE";
4623 case 0x0227: return "WM_MDICASCADE";
4624 case 0x0228: return "WM_MDIICONARRANGE";
4625 case 0x0229: return "WM_MDIGETACTIVE";
4626 case 0x0230: return "WM_MDISETMENU";
4627 case 0x0233: return "WM_DROPFILES";
4628 case 0x0300: return "WM_CUT";
4629 case 0x0301: return "WM_COPY";
4630 case 0x0302: return "WM_PASTE";
4631 case 0x0303: return "WM_CLEAR";
4632 case 0x0304: return "WM_UNDO";
4633 case 0x0305: return "WM_RENDERFORMAT";
4634 case 0x0306: return "WM_RENDERALLFORMATS";
4635 case 0x0307: return "WM_DESTROYCLIPBOARD";
4636 case 0x0308: return "WM_DRAWCLIPBOARD";
4637 case 0x0309: return "WM_PAINTCLIPBOARD";
4638 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4639 case 0x030B: return "WM_SIZECLIPBOARD";
4640 case 0x030C: return "WM_ASKCBFORMATNAME";
4641 case 0x030D: return "WM_CHANGECBCHAIN";
4642 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4643 case 0x030F: return "WM_QUERYNEWPALETTE";
4644 case 0x0310: return "WM_PALETTEISCHANGING";
4645 case 0x0311: return "WM_PALETTECHANGED";
4647 static char s_szBuf
[128];
4648 sprintf(s_szBuf
, "<unknown message = %d>", message
);