1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/dcclient.h"
32 #include "wx/layout.h"
33 #include "wx/dialog.h"
34 #include "wx/listbox.h"
35 #include "wx/button.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
41 #include "wx/ownerdrw.h"
45 #include "wx/msw/ole/droptgt.h"
48 #include "wx/menuitem.h"
50 #include "wx/msw/private.h"
64 #include <wx/msw/gnuwin32/extra.h>
84 const char *wxGetMessageName(int message
);
87 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
89 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 extern wxList wxPendingDelete
;
92 void wxRemoveHandleAssociation(wxWindow
*win
);
93 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
94 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
99 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
100 EVT_CHAR(wxWindow::OnChar
)
101 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
102 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
104 EVT_IDLE(wxWindow::OnIdle
)
109 // Find an item given the MS Windows id
110 wxWindow
*wxWindow::FindItem(int id
) const
114 wxNode
*current
= GetChildren()->First();
117 wxWindow
*childWin
= (wxWindow
*)current
->Data();
119 wxWindow
*wnd
= childWin
->FindItem(id
) ;
123 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
125 wxControl
*item
= (wxControl
*)childWin
;
126 if (item
->m_windowId
== id
)
130 // In case it's a 'virtual' control (e.g. radiobox)
131 if (item
->GetSubcontrols().Member((wxObject
*)id
))
135 current
= current
->Next();
140 // Find an item given the MS Windows handle
141 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
145 wxNode
*current
= GetChildren()->First();
148 wxObject
*obj
= (wxObject
*)current
->Data() ;
149 // Do a recursive search.
150 wxWindow
*parent
= (wxWindow
*)obj
;
151 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
155 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
157 wxWindow
*item
= (wxWindow
*)current
->Data();
158 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
162 if ( item
->ContainsHWND(hWnd
) )
166 current
= current
->Next();
171 // Default command handler
172 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
177 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
182 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
186 WXHWND
wxWindow::GetHWND(void) const
188 return (WXHWND
) m_hWnd
;
191 void wxWindow::SetHWND(WXHWND hWnd
)
197 wxWindow::wxWindow(void)
203 m_windowParent
= NULL
;
204 m_windowEventHandler
= this;
206 m_windowCursor
= *wxSTANDARD_CURSOR
;
207 m_children
= new wxList
;
208 m_doubleClickAllowed
= 0 ;
209 m_winCaptured
= FALSE
;
210 m_constraints
= NULL
;
211 m_constraintsInvolvedIn
= NULL
;
212 m_windowSizer
= NULL
;
213 m_sizerParent
= NULL
;
214 m_autoLayout
= FALSE
;
215 m_windowValidator
= NULL
;
220 m_caretWidth
= 0; m_caretHeight
= 0;
221 m_caretEnabled
= FALSE
;
222 m_caretShown
= FALSE
;
230 m_isBeingDeleted
= FALSE
;
237 m_defaultItem
= NULL
;
239 wxSystemSettings settings
;
241 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
242 m_foregroundColour
= *wxBLACK
;
243 m_defaultForegroundColour
= *wxBLACK
;
244 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
247 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
248 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
255 // m_acceleratorTable = 0;
260 m_backgroundTransparent
= FALSE
;
262 m_lastXPos
= (float)-1.0;
263 m_lastYPos
= (float)-1.0;
267 #if USE_DRAG_AND_DROP
268 m_pDropTarget
= NULL
;
273 wxWindow::~wxWindow(void)
275 m_isBeingDeleted
= TRUE
;
277 // JACS - if behaviour is odd, restore this
278 // to the start of ~wxWindow. Vadim has changed
279 // it to nearer the end. Unsure of side-effects
280 // e.g. when deleting associated global data.
281 // Restore old Window proc, if required
284 // Have to delete constraints/sizer FIRST otherwise
285 // sizers may try to look at deleted windows as they
286 // delete themselves.
288 DeleteRelatedConstraints();
291 // This removes any dangling pointers to this window
292 // in other windows' constraintsInvolvedIn lists.
293 UnsetConstraints(m_constraints
);
294 delete m_constraints
;
295 m_constraints
= NULL
;
299 delete m_windowSizer
;
300 m_windowSizer
= NULL
;
302 // If this is a child of a sizer, remove self from parent
304 m_sizerParent
->RemoveChild((wxWindow
*)this);
308 MSWDetachWindowMenu();
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
);
625 // We may be faking the client origin.
626 // So a window that's really at (0, 30) may appear
627 // (to wxWin apps) to be at (0, 0).
630 wxPoint
pt(GetParent()->GetClientAreaOrigin());
638 void wxWindow::ScreenToClient(int *x
, int *y
) const
640 HWND hWnd
= (HWND
) GetHWND();
644 ::ScreenToClient(hWnd
, &pt
);
647 // We may be faking the client origin.
648 // So a window that's really at (0, 30) may appear
649 // (to wxWin apps) to be at (0, 0).
652 wxPoint pt1(GetParent()->GetClientAreaOrigin());
662 void wxWindow::ClientToScreen(int *x
, int *y
) const
664 HWND hWnd
= (HWND
) GetHWND();
670 // We may be faking the client origin.
671 // So a window that's really at (0, 30) may appear
672 // (to wxWin apps) to be at (0, 0).
675 wxPoint pt1(GetParent()->GetClientAreaOrigin());
681 ::ClientToScreen(hWnd
, &pt
);
687 void wxWindow::SetCursor(const wxCursor
& cursor
)
689 m_windowCursor
= cursor
;
690 if (m_windowCursor
.Ok())
692 HWND hWnd
= (HWND
) GetHWND();
694 // Change the cursor NOW if we're within the correct window
696 ::GetCursorPos(&point
);
699 ::GetWindowRect(hWnd
, &rect
);
701 if (::PtInRect(&rect
, point
) && !wxIsBusy())
702 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
705 // This will cause big reentrancy problems if wxFlushEvents is implemented.
707 // return old_cursor;
711 // Get size *available for subwindows* i.e. excluding menu bar etc.
712 void wxWindow::GetClientSize(int *x
, int *y
) const
714 HWND hWnd
= (HWND
) GetHWND();
716 GetClientRect(hWnd
, &rect
);
721 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
723 int currentX
, currentY
;
724 GetPosition(¤tX
, ¤tY
);
725 int actualWidth
= width
;
726 int actualHeight
= height
;
729 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
731 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
734 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
736 int currentW
,currentH
;
737 GetSize(¤tW
, ¤tH
);
739 actualWidth
= currentW
;
741 actualHeight
= currentH
;
743 HWND hWnd
= (HWND
) GetHWND();
745 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
748 void wxWindow::SetClientSize(int width
, int height
)
750 wxWindow
*parent
= GetParent();
751 HWND hWnd
= (HWND
) GetHWND();
752 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
755 GetClientRect(hWnd
, &rect
);
758 GetWindowRect(hWnd
, &rect2
);
760 // Find the difference between the entire window (title bar and all)
761 // and the client area; add this to the new client size to move the
763 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
764 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
766 // If there's a parent, must subtract the parent's top left corner
767 // since MoveWindow moves relative to the parent
770 point
.x
= rect2
.left
;
774 ::ScreenToClient(hParentWnd
, &point
);
777 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
779 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
780 event
.SetEventObject(this);
781 GetEventHandler()->ProcessEvent(event
);
784 // For implementation purposes - sometimes decorations make the client area
786 wxPoint
wxWindow::GetClientAreaOrigin() const
788 return wxPoint(0, 0);
791 // Makes an adjustment to the window position (for example, a frame that has
792 // a toolbar that it manages itself).
793 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
795 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
797 wxPoint
pt(GetParent()->GetClientAreaOrigin());
798 x
+= pt
.x
; y
+= pt
.y
;
802 bool wxWindow::Show(bool show
)
804 HWND hWnd
= (HWND
) GetHWND();
810 ShowWindow(hWnd
, (BOOL
)cshow
);
813 BringWindowToTop(hWnd
);
814 // Next line causes a crash on NT, apparently.
815 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
820 bool wxWindow::IsShown(void) const
822 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
825 int wxWindow::GetCharHeight(void) const
827 TEXTMETRIC lpTextMetric
;
828 HWND hWnd
= (HWND
) GetHWND();
829 HDC dc
= ::GetDC(hWnd
);
831 GetTextMetrics(dc
, &lpTextMetric
);
832 ::ReleaseDC(hWnd
, dc
);
834 return lpTextMetric
.tmHeight
;
837 int wxWindow::GetCharWidth(void) const
839 TEXTMETRIC lpTextMetric
;
840 HWND hWnd
= (HWND
) GetHWND();
841 HDC dc
= ::GetDC(hWnd
);
843 GetTextMetrics(dc
, &lpTextMetric
);
844 ::ReleaseDC(hWnd
, dc
);
846 return lpTextMetric
.tmAveCharWidth
;
849 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
850 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
852 wxFont
*fontToUse
= (wxFont
*)theFont
;
854 fontToUse
= (wxFont
*) & m_windowFont
;
856 HWND hWnd
= (HWND
) GetHWND();
857 HDC dc
= ::GetDC(hWnd
);
861 if (fontToUse
&& fontToUse
->Ok())
863 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
864 was
= (HFONT
) SelectObject(dc
,fnt
) ;
869 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
870 GetTextMetrics(dc
, &tm
);
872 if (fontToUse
&& fnt
&& was
)
873 SelectObject(dc
,was
) ;
879 if (descent
) *descent
= tm
.tmDescent
;
880 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
883 // fontToUse->ReleaseResource();
886 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
888 HWND hWnd
= (HWND
) GetHWND();
894 mswRect
.left
= rect
->x
;
895 mswRect
.top
= rect
->y
;
896 mswRect
.right
= rect
->x
+ rect
->width
;
897 mswRect
.bottom
= rect
->y
+ rect
->height
;
899 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
902 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
906 // Hook for new window just as it's being created,
907 // when the window isn't yet associated with the handle
908 wxWindow
*wxWndHook
= NULL
;
911 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
913 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
915 if (!wnd
&& wxWndHook
)
917 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
920 wnd
->m_hWnd
= (WXHWND
) hWnd
;
923 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
925 // Stop right here if we don't have a valid handle
926 // in our wxWnd object.
927 if (wnd
&& !wnd
->m_hWnd
) {
928 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
929 wnd
->m_hWnd
= (WXHWND
) hWnd
;
930 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
936 wnd
->m_lastMsg
= message
;
937 wnd
->m_lastWParam
= wParam
;
938 wnd
->m_lastLParam
= lParam
;
941 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
943 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
946 // Should probably have a test for 'genuine' NT
947 #if defined(__WIN32__)
948 #define DIMENSION_TYPE short
950 #define DIMENSION_TYPE int
953 // Main Windows 3 window proc
954 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
957 wxLogTrace(wxTraceMessages
, "Processing %s", wxGetMessageName(message
));
960 HWND hWnd
= (HWND
)m_hWnd
;
967 WORD state
= LOWORD(wParam
);
968 WORD minimized
= HIWORD(wParam
);
969 HWND hwnd
= (HWND
)lParam
;
971 WORD state
= (WORD
)wParam
;
972 WORD minimized
= LOWORD(lParam
);
973 HWND hwnd
= (HWND
)HIWORD(lParam
);
975 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
981 HWND hwnd
= (HWND
)wParam
;
982 // return OnSetFocus(hwnd);
984 if (MSWOnSetFocus((WXHWND
) hwnd
))
986 else return MSWDefWindowProc(message
, wParam
, lParam
);
991 HWND hwnd
= (HWND
)lParam
;
992 // return OnKillFocus(hwnd);
993 if (MSWOnKillFocus((WXHWND
) hwnd
))
996 return MSWDefWindowProc(message
, wParam
, lParam
);
1001 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
1007 MSWOnShow((wParam
!= 0), (int) lParam
);
1014 else return MSWDefWindowProc(message
, wParam
, lParam
);
1017 case WM_QUERYDRAGICON
:
1020 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1022 else return MSWDefWindowProc(message
, wParam
, lParam
);
1028 int width
= LOWORD(lParam
);
1029 int height
= HIWORD(lParam
);
1030 MSWOnSize(width
, height
, wParam
);
1034 case WM_WINDOWPOSCHANGING
:
1036 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1037 MSWOnWindowPosChanging((void *)pos
);
1041 case WM_RBUTTONDOWN
:
1043 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1044 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1045 MSWOnRButtonDown(x
, y
, wParam
);
1050 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1051 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1052 MSWOnRButtonUp(x
, y
, wParam
);
1055 case WM_RBUTTONDBLCLK
:
1057 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1058 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1059 MSWOnRButtonDClick(x
, y
, wParam
);
1062 case WM_MBUTTONDOWN
:
1064 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1065 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1066 MSWOnMButtonDown(x
, y
, wParam
);
1071 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1072 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1073 MSWOnMButtonUp(x
, y
, wParam
);
1076 case WM_MBUTTONDBLCLK
:
1078 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1079 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1080 MSWOnMButtonDClick(x
, y
, wParam
);
1083 case WM_LBUTTONDOWN
:
1085 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1086 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1087 MSWOnLButtonDown(x
, y
, wParam
);
1092 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1093 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1094 MSWOnLButtonUp(x
, y
, wParam
);
1097 case WM_LBUTTONDBLCLK
:
1099 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1100 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1101 MSWOnLButtonDClick(x
, y
, wParam
);
1106 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1107 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1108 MSWOnMouseMove(x
, y
, wParam
);
1111 case MM_JOY1BUTTONDOWN
:
1113 int x
= LOWORD(lParam
);
1114 int y
= HIWORD(lParam
);
1115 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1118 case MM_JOY2BUTTONDOWN
:
1120 int x
= LOWORD(lParam
);
1121 int y
= HIWORD(lParam
);
1122 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1125 case MM_JOY1BUTTONUP
:
1127 int x
= LOWORD(lParam
);
1128 int y
= HIWORD(lParam
);
1129 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1132 case MM_JOY2BUTTONUP
:
1134 int x
= LOWORD(lParam
);
1135 int y
= HIWORD(lParam
);
1136 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1141 int x
= LOWORD(lParam
);
1142 int y
= HIWORD(lParam
);
1143 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1148 int x
= LOWORD(lParam
);
1149 int y
= HIWORD(lParam
);
1150 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1155 int z
= LOWORD(lParam
);
1156 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1161 int z
= LOWORD(lParam
);
1162 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1169 else return MSWDefWindowProc(message
, wParam
, lParam
);
1174 return MSWOnSysCommand(wParam
, lParam
);
1180 WORD id
= LOWORD(wParam
);
1181 HWND hwnd
= (HWND
)lParam
;
1182 WORD cmd
= HIWORD(wParam
);
1184 WORD id
= (WORD
)wParam
;
1185 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1186 WORD cmd
= HIWORD(lParam
);
1188 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1189 return MSWDefWindowProc(message
, wParam
, lParam
);
1192 #if defined(__WIN95__)
1195 if (!MSWOnNotify(wParam
, lParam
))
1196 return MSWDefWindowProc(message
, wParam
, lParam
);
1203 WORD flags
= HIWORD(wParam
);
1204 HMENU sysmenu
= (HMENU
)lParam
;
1206 WORD flags
= LOWORD(lParam
);
1207 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1209 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1212 case WM_INITMENUPOPUP
:
1214 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1219 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1222 case WM_MEASUREITEM
:
1224 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1229 // we consider these message "not interesting"
1230 if ( wParam
== VK_SHIFT
|| wParam
== VK_CONTROL
)
1233 // Avoid duplicate messages to OnChar
1234 if ( (wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) &&
1235 (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) &&
1236 (wParam
!= VK_TAB
) )
1238 MSWOnChar((WORD
)wParam
, lParam
);
1239 if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1242 else if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1243 MSWOnChar((WORD
)wParam
, lParam
);
1251 case WM_CHAR
: // Always an ASCII character
1253 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1260 WORD code
= LOWORD(wParam
);
1261 WORD pos
= HIWORD(wParam
);
1262 HWND control
= (HWND
)lParam
;
1264 WORD code
= (WORD
)wParam
;
1265 WORD pos
= LOWORD(lParam
);
1266 HWND control
= (HWND
)HIWORD(lParam
);
1268 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1274 WORD code
= LOWORD(wParam
);
1275 WORD pos
= HIWORD(wParam
);
1276 HWND control
= (HWND
)lParam
;
1278 WORD code
= (WORD
)wParam
;
1279 WORD pos
= LOWORD(lParam
);
1280 HWND control
= (HWND
)HIWORD(lParam
);
1282 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1286 case WM_CTLCOLORBTN
:
1288 int nCtlColor
= CTLCOLOR_BTN
;
1289 HWND control
= (HWND
)lParam
;
1290 HDC pDC
= (HDC
)wParam
;
1291 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1292 message
, wParam
, lParam
);
1295 case WM_CTLCOLORDLG
:
1297 int nCtlColor
= CTLCOLOR_DLG
;
1298 HWND control
= (HWND
)lParam
;
1299 HDC pDC
= (HDC
)wParam
;
1300 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1301 message
, wParam
, lParam
);\
1304 case WM_CTLCOLORLISTBOX
:
1306 int nCtlColor
= CTLCOLOR_LISTBOX
;
1307 HWND control
= (HWND
)lParam
;
1308 HDC pDC
= (HDC
)wParam
;
1309 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1310 message
, wParam
, lParam
);
1313 case WM_CTLCOLORMSGBOX
:
1315 int nCtlColor
= CTLCOLOR_MSGBOX
;
1316 HWND control
= (HWND
)lParam
;
1317 HDC pDC
= (HDC
)wParam
;
1318 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1319 message
, wParam
, lParam
);
1322 case WM_CTLCOLORSCROLLBAR
:
1324 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1325 HWND control
= (HWND
)lParam
;
1326 HDC pDC
= (HDC
)wParam
;
1327 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1328 message
, wParam
, lParam
);
1331 case WM_CTLCOLORSTATIC
:
1333 int nCtlColor
= CTLCOLOR_STATIC
;
1334 HWND control
= (HWND
)lParam
;
1335 HDC pDC
= (HDC
)wParam
;
1336 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1337 message
, wParam
, lParam
);
1340 case WM_CTLCOLOREDIT
:
1342 int nCtlColor
= CTLCOLOR_EDIT
;
1343 HWND control
= (HWND
)lParam
;
1344 HDC pDC
= (HDC
)wParam
;
1345 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1346 message
, wParam
, lParam
);
1352 HWND control
= (HWND
)LOWORD(lParam
);
1353 int nCtlColor
= (int)HIWORD(lParam
);
1354 HDC pDC
= (HDC
)wParam
;
1355 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1356 message
, wParam
, lParam
);
1360 case WM_SYSCOLORCHANGE
:
1362 // Return value of 0 means, we processed it.
1363 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1366 return MSWDefWindowProc(message
, wParam
, lParam
);
1369 case WM_PALETTECHANGED
:
1371 return MSWOnPaletteChanged((WXHWND
) (HWND
) wParam
);
1374 case WM_QUERYNEWPALETTE
:
1376 return MSWOnQueryNewPalette();
1381 // Prevents flicker when dragging
1382 if (IsIconic(hWnd
)) return 1;
1386 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1387 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1391 case WM_MDIACTIVATE
:
1394 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1395 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1396 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1397 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1399 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1400 (HWND
)HIWORD(lParam
));
1405 MSWOnDropFiles(wParam
);
1410 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1413 case WM_QUERYENDSESSION
:
1415 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1416 return MSWOnClose();
1428 case WM_GETMINMAXINFO
:
1430 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1431 if (m_minSizeX
!= -1)
1432 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1433 if (m_minSizeY
!= -1)
1434 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1435 if (m_maxSizeX
!= -1)
1436 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1437 if (m_maxSizeY
!= -1)
1438 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1439 return MSWDefWindowProc(message
, wParam
, lParam
);
1444 return MSWGetDlgCode();
1450 __ddeUnblock(hWnd, wParam);
1454 case ASYNC_SELECT_MESSAGE:
1455 return ddeWindowProc(hWnd,message,wParam,lParam);
1460 return MSWDefWindowProc(message
, wParam
, lParam
);
1462 return 0; // Success: we processed this command.
1465 // Dialog window proc
1466 LONG APIENTRY _EXPORT
1467 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1472 wxList
*wxWinHandleList
= NULL
;
1473 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1475 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1478 return (wxWindow
*)node
->Data();
1481 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1483 // adding NULL hWnd is (first) surely a result of an error and
1484 // (secondly) breaks menu command processing
1485 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1487 if ( !wxWinHandleList
->Find((long)hWnd
) )
1488 wxWinHandleList
->Append((long)hWnd
, win
);
1491 void wxRemoveHandleAssociation(wxWindow
*win
)
1493 wxWinHandleList
->DeleteObject(win
);
1496 // Default destroyer - override if you destroy it in some other way
1497 // (e.g. with MDI child windows)
1498 void wxWindow::MSWDestroyWindow(void)
1503 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1505 MSWDetachWindowMenu();
1506 // SetWindowLong(handle, 0, (long)0);
1507 HWND oldHandle
= handle
;
1510 ::DestroyWindow(oldHandle
);
1512 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1513 // or when Windows HWND is deleted if MDI parent or
1518 ::DestroyMenu(m_hMenu);
1525 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1526 int x
, int y
, int width
, int height
,
1527 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1529 bool is_dialog
= (dialog_template
!= NULL
);
1530 int x1
= CW_USEDEFAULT
;
1532 int width1
= CW_USEDEFAULT
;
1535 // Find parent's size, if it exists, to set up a possible default
1536 // panel size the size of the parent window
1540 // Was GetWindowRect: JACS 5/5/95
1541 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1543 width1
= parent_rect
.right
- parent_rect
.left
;
1544 height1
= parent_rect
.bottom
- parent_rect
.top
;
1549 if (width
> -1) width1
= width
;
1550 if (height
> -1) height1
= height
;
1552 HWND hParent
= NULL
;
1554 hParent
= (HWND
) parent
->GetHWND();
1560 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1561 // other compilers???
1562 // VZ: it's always needed for Win16 and never for Win32
1564 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1565 (DLGPROC
)wxDlgProc
);
1567 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1569 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1574 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1575 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1576 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1581 if (style
& WS_CHILD
)
1586 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1591 // hParent, NULL, wxGetInstance(),
1592 hParent
, (HMENU
)controlId
, wxGetInstance(),
1598 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1601 "Fatal wxWindows Error");
1605 wxWinHandleList
->Append((long)m_hWnd
, this);
1608 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1612 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1616 bool wxWindow::MSWOnClose(void)
1619 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1624 bool wxWindow::MSWOnDestroy(void)
1627 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1629 // delete our drop target if we've got one
1630 #if USE_DRAG_AND_DROP
1631 if ( m_pDropTarget
!= NULL
) {
1632 m_pDropTarget
->Revoke(m_hWnd
);
1634 delete m_pDropTarget
;
1635 m_pDropTarget
= NULL
;
1642 // Deal with child commands from buttons etc.
1644 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1646 #if defined(__WIN95__)
1647 // Find a child window to send the notification to, e.g. a toolbar.
1648 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1649 // handle of the toolbar; it's probably the handle of the tooltip
1650 // window (anyway, it's parent is also the toolbar's parent).
1651 // So, since we don't know which hWnd or wxWindow originated the
1652 // WM_NOTIFY, we'll need to go through all the children of this window
1653 // trying out MSWNotify.
1654 // This won't work now, though, because any number of controls
1655 // could respond to the same generic messages :-(
1657 /* This doesn't work for toolbars, but try for other controls first.
1659 NMHDR
*hdr
= (NMHDR
*)lParam
;
1660 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1661 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1664 return win
->MSWNotify(wParam
, lParam
);
1667 // Rely on MSWNotify to check whether the message
1668 // belongs to the window or not
1669 wxNode
*node
= GetChildren()->First();
1672 wxWindow
*child
= (wxWindow
*)node
->Data();
1673 if ( child
->MSWNotify(wParam
, lParam
) )
1675 node
= node
->Next();
1685 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1688 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1692 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1696 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1699 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1702 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1704 event
.SetEventObject(this);
1705 GetEventHandler()->ProcessEvent(event
);
1709 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1712 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1715 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1717 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1719 ::ShowCaret((HWND
) GetHWND());
1722 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1723 event
.SetEventObject(this);
1724 if (!GetEventHandler()->ProcessEvent(event
))
1729 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1732 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1740 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1741 event
.SetEventObject(this);
1742 if (!GetEventHandler()->ProcessEvent(event
))
1747 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1750 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1753 HDROP hFilesInfo
= (HDROP
) wParam
;
1755 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1757 // Get the total number of files dropped
1758 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1763 wxString
*files
= new wxString
[gwFilesDropped
];
1765 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1767 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1768 files
[wIndex
] = wxBuffer
;
1770 DragFinish (hFilesInfo
);
1772 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1773 event
.m_eventObject
= this;
1774 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1776 if (!GetEventHandler()->ProcessEvent(event
))
1782 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1785 if ( id
== 0 ) { // is it a menu item?
1786 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1787 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1788 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1790 // prepare to call OnDrawItem()
1792 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1793 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1794 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1795 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1796 return pMenuItem
->OnDrawItem(
1798 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1799 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1802 #endif // owner-drawn menus
1804 wxWindow
*item
= FindItem(id
);
1805 #if USE_DYNAMIC_CLASSES
1806 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1808 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1815 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1818 if ( id
== 0 ) { // is it a menu item?
1819 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1820 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1821 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1823 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1824 &pMeasureStruct
->itemHeight
);
1826 #endif // owner-drawn menus
1828 wxWindow
*item
= FindItem(id
);
1829 #if USE_DYNAMIC_CLASSES
1830 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1832 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1839 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1840 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1843 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1845 if (nCtlColor
== CTLCOLOR_DLG
)
1847 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1850 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1852 WXHBRUSH hBrush
= 0;
1855 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1857 // I think that even for dialogs, we may need to call DefWindowProc (?)
1858 // Or maybe just rely on the usual default behaviour.
1860 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1865 // Define for each class of dialog and control
1866 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1867 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1869 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1872 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1874 wxSysColourChangedEvent event
;
1875 event
.SetEventObject(this);
1877 // Check if app handles this.
1878 if (GetEventHandler()->ProcessEvent(event
))
1881 // We didn't process it
1885 long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange
)
1887 wxPaletteChangedEvent
event(GetId());
1888 event
.SetEventObject(this);
1889 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
1890 GetEventHandler()->ProcessEvent(event
);
1894 long wxWindow::MSWOnQueryNewPalette()
1896 wxQueryNewPaletteEvent
event(GetId());
1897 event
.SetEventObject(this);
1898 if (!GetEventHandler()->ProcessEvent(event
) || !event
.GetPaletteRealized())
1900 return (long) FALSE
;
1906 // Responds to colour changes: passes event on to children.
1907 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1909 wxNode
*node
= GetChildren()->First();
1912 // Only propagate to non-top-level windows
1913 wxWindow
*win
= (wxWindow
*)node
->Data();
1914 if ( win
->GetParent() )
1916 wxSysColourChangedEvent event2
;
1917 event
.m_eventObject
= win
;
1918 win
->GetEventHandler()->ProcessEvent(event2
);
1921 node
= node
->Next();
1925 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1928 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1930 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1933 long wxWindow::Default()
1935 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1940 wxLogTrace(wxTraceMessages
, "Forwarding %s to DefWindowProc.",
1941 wxGetMessageName(m_lastMsg
));
1944 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1947 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1949 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) ) {
1950 // intercept dialog navigation keys
1951 MSG
*msg
= (MSG
*)pMsg
;
1952 bool bProcess
= TRUE
;
1953 if ( msg
->message
!= WM_KEYDOWN
)
1956 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1959 bool bCtrlDown
= (::GetKeyState(VK_CONTROL
) & 0x100) != 0;
1961 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1962 // (except for Ctrl-Tab combination which is always processed)
1964 if ( bProcess
&& !bCtrlDown
) {
1965 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1970 switch ( msg
->wParam
) {
1972 if ( lDlgCode
& DLGC_WANTTAB
)
1975 bForward
= !(::GetKeyState(VK_SHIFT
) & 0x100);
1980 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1988 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
2000 wxNavigationKeyEvent event
;
2001 event
.SetDirection(bForward
);
2002 event
.SetWindowChange(bCtrlDown
);
2003 event
.SetEventObject(this);
2005 if ( GetEventHandler()->ProcessEvent(event
) )
2009 return ::IsDialogMessage((HWND
)GetHWND(), msg
) != 0;
2015 bool wxWindow::MSWTranslateMessage(WXMSG
* WXUNUSED(pMsg
))
2020 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
2023 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
2028 void wxWindow::MSWDetachWindowMenu(void)
2032 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
2034 for (i
= 0; i
< N
; i
++)
2037 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
2038 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
2040 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
2047 bool wxWindow::MSWOnPaint(void)
2050 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2051 ::GetUpdateRgn((HWND
) GetHWND(), hRegion
, FALSE
);
2053 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
2056 ::GetUpdateRect((HWND
) GetHWND(), & updateRect
, FALSE
);
2058 m_updateRegion
= wxRegion(updateRect
.left
, updateRect
.top
,
2059 updateRect
.right
- updateRect
.left
, updateRect
.bottom
- updateRect
.top
);
2062 wxPaintEvent
event(m_windowId
);
2063 event
.SetEventObject(this);
2064 if (!GetEventHandler()->ProcessEvent(event
))
2069 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
2075 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2082 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2083 event
.SetEventObject(this);
2084 if (!GetEventHandler()->ProcessEvent(event
))
2090 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2095 // Deal with child commands from buttons etc.
2096 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
2099 wxDebugMsg("wxWindow::MSWOnCommand\n");
2101 if (wxCurrentPopupMenu
)
2103 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2104 wxCurrentPopupMenu
= NULL
;
2105 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2110 sprintf(buf
, "Looking for item %d...\n", id
);
2114 wxWindow
*item
= FindItem(id
);
2117 bool value
= item
->MSWCommand(cmd
, id
);
2120 wxDebugMsg("MSWCommand succeeded\n");
2122 wxDebugMsg("MSWCommand failed\n");
2129 wxDebugMsg("Could not find item!\n");
2131 wxDebugMsg("Item ids for this panel:\n");
2133 wxNode
*current
= GetChildren()->First();
2136 wxObject
*obj
= (wxObject
*)current
->Data() ;
2137 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2139 wxControl
*item
= (wxControl
*)current
->Data();
2140 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2143 current
= current
->Next();
2151 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2157 wxMaximizeEvent
event(m_windowId
);
2158 event
.SetEventObject(this);
2159 if (!GetEventHandler()->ProcessEvent(event
))
2167 wxIconizeEvent
event(m_windowId
);
2168 event
.SetEventObject(this);
2169 if (!GetEventHandler()->ProcessEvent(event
))
2181 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2183 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2185 event
.m_x
= x
; event
.m_y
= y
;
2186 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2187 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2188 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2189 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2190 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2191 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2192 event
.m_eventObject
= this;
2194 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2196 if (!GetEventHandler()->ProcessEvent(event
))
2200 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2202 wxMouseEvent
event(wxEVT_LEFT_UP
);
2204 event
.m_x
= x
; event
.m_y
= y
;
2205 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2206 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2207 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2208 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2209 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2210 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2211 event
.m_eventObject
= this;
2213 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2215 if (!GetEventHandler()->ProcessEvent(event
))
2219 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2221 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2223 event
.m_x
= x
; event
.m_y
= y
;
2224 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2225 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2226 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2227 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2228 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2229 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2230 event
.m_eventObject
= this;
2232 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2234 if (!GetEventHandler()->ProcessEvent(event
))
2238 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2240 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2242 event
.m_x
= x
; event
.m_y
= y
;
2243 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2244 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2245 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2246 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2247 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2248 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2249 event
.m_eventObject
= this;
2251 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2253 if (!GetEventHandler()->ProcessEvent(event
))
2257 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2259 //wxDebugMsg("MButtonUp\n") ;
2260 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2262 event
.m_x
= x
; event
.m_y
= y
;
2263 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2264 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2265 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2266 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2267 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2268 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2269 event
.m_eventObject
= this;
2271 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2273 if (!GetEventHandler()->ProcessEvent(event
))
2277 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2279 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2281 event
.m_x
= x
; event
.m_y
= y
;
2282 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2283 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2284 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2285 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2286 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2287 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2288 event
.m_eventObject
= this;
2290 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2292 if (!GetEventHandler()->ProcessEvent(event
))
2296 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2298 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
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_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2311 if (!GetEventHandler()->ProcessEvent(event
))
2315 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2317 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2319 event
.m_x
= x
; event
.m_y
= y
;
2320 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2321 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2322 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2323 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2324 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2325 event
.m_eventObject
= this;
2326 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2328 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2330 if (!GetEventHandler()->ProcessEvent(event
))
2334 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2336 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2338 event
.m_x
= x
; event
.m_y
= y
;
2339 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2340 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2341 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2342 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2343 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2344 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2345 event
.m_eventObject
= this;
2347 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2349 if (!GetEventHandler()->ProcessEvent(event
))
2353 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2355 // 'normal' move event...
2356 // Set cursor, but only if we're not in 'busy' mode
2358 // Trouble with this is that it sets the cursor for controls too :-(
2359 if (m_windowCursor
.Ok() && !wxIsBusy())
2360 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2362 if (!m_mouseInWindow
)
2364 // Generate an ENTER event
2365 m_mouseInWindow
= TRUE
;
2366 MSWOnMouseEnter(x
, y
, flags
);
2369 wxMouseEvent
event(wxEVT_MOTION
);
2371 event
.m_x
= x
; event
.m_y
= y
;
2372 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2373 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2374 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2375 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2376 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2377 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2378 event
.m_eventObject
= this;
2380 // Window gets a click down message followed by a mouse move
2381 // message even if position isn't changed! We want to discard
2382 // the trailing move event if x and y are the same.
2383 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2384 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2385 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2387 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2388 m_lastEvent
= wxEVT_MOTION
;
2392 m_lastEvent
= wxEVT_MOTION
;
2393 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2395 if (!GetEventHandler()->ProcessEvent(event
))
2399 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2401 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2403 event
.m_x
= x
; event
.m_y
= y
;
2404 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2405 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2406 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2407 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2408 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2409 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2410 event
.m_eventObject
= this;
2412 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2413 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2414 // No message - ensure we don't try to call the default behaviour accidentally.
2416 GetEventHandler()->ProcessEvent(event
);
2419 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2421 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2423 event
.m_x
= x
; event
.m_y
= y
;
2424 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2425 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2426 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2427 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2428 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2429 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2430 event
.m_eventObject
= this;
2432 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2433 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2434 // No message - ensure we don't try to call the default behaviour accidentally.
2436 GetEventHandler()->ProcessEvent(event
);
2439 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2442 bool tempControlDown
= FALSE
;
2445 // If 1 -> 26, translate to CTRL plus a letter.
2447 if ((id
> 0) && (id
< 27))
2468 tempControlDown
= TRUE
;
2474 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2475 // it's ASCII and will be processed here only when called from
2476 // WM_CHAR (i.e. when isASCII = TRUE)
2482 wxKeyEvent
event(wxEVT_CHAR
);
2483 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2484 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2485 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2486 event
.m_altDown
= TRUE
;
2488 event
.m_eventObject
= this;
2489 event
.m_keyCode
= id
;
2490 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2495 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2499 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2501 if (!GetEventHandler()->ProcessEvent(event
))
2506 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2510 if (flags
& JOY_BUTTON1CHG
)
2511 change
= wxJOY_BUTTON1
;
2512 if (flags
& JOY_BUTTON2CHG
)
2513 change
= wxJOY_BUTTON2
;
2514 if (flags
& JOY_BUTTON3CHG
)
2515 change
= wxJOY_BUTTON3
;
2516 if (flags
& JOY_BUTTON4CHG
)
2517 change
= wxJOY_BUTTON4
;
2519 if (flags
& JOY_BUTTON1
)
2520 buttons
|= wxJOY_BUTTON1
;
2521 if (flags
& JOY_BUTTON2
)
2522 buttons
|= wxJOY_BUTTON2
;
2523 if (flags
& JOY_BUTTON3
)
2524 buttons
|= wxJOY_BUTTON3
;
2525 if (flags
& JOY_BUTTON4
)
2526 buttons
|= wxJOY_BUTTON4
;
2528 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2529 event
.SetPosition(wxPoint(x
, y
));
2530 event
.SetEventObject(this);
2532 GetEventHandler()->ProcessEvent(event
);
2535 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2539 if (flags
& JOY_BUTTON1CHG
)
2540 change
= wxJOY_BUTTON1
;
2541 if (flags
& JOY_BUTTON2CHG
)
2542 change
= wxJOY_BUTTON2
;
2543 if (flags
& JOY_BUTTON3CHG
)
2544 change
= wxJOY_BUTTON3
;
2545 if (flags
& JOY_BUTTON4CHG
)
2546 change
= wxJOY_BUTTON4
;
2548 if (flags
& JOY_BUTTON1
)
2549 buttons
|= wxJOY_BUTTON1
;
2550 if (flags
& JOY_BUTTON2
)
2551 buttons
|= wxJOY_BUTTON2
;
2552 if (flags
& JOY_BUTTON3
)
2553 buttons
|= wxJOY_BUTTON3
;
2554 if (flags
& JOY_BUTTON4
)
2555 buttons
|= wxJOY_BUTTON4
;
2557 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2558 event
.SetPosition(wxPoint(x
, y
));
2559 event
.SetEventObject(this);
2561 GetEventHandler()->ProcessEvent(event
);
2564 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2567 if (flags
& JOY_BUTTON1
)
2568 buttons
|= wxJOY_BUTTON1
;
2569 if (flags
& JOY_BUTTON2
)
2570 buttons
|= wxJOY_BUTTON2
;
2571 if (flags
& JOY_BUTTON3
)
2572 buttons
|= wxJOY_BUTTON3
;
2573 if (flags
& JOY_BUTTON4
)
2574 buttons
|= wxJOY_BUTTON4
;
2576 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2577 event
.SetPosition(wxPoint(x
, y
));
2578 event
.SetEventObject(this);
2580 GetEventHandler()->ProcessEvent(event
);
2583 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2586 if (flags
& JOY_BUTTON1
)
2587 buttons
|= wxJOY_BUTTON1
;
2588 if (flags
& JOY_BUTTON2
)
2589 buttons
|= wxJOY_BUTTON2
;
2590 if (flags
& JOY_BUTTON3
)
2591 buttons
|= wxJOY_BUTTON3
;
2592 if (flags
& JOY_BUTTON4
)
2593 buttons
|= wxJOY_BUTTON4
;
2595 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2596 event
.SetZPosition(z
);
2597 event
.SetEventObject(this);
2599 GetEventHandler()->ProcessEvent(event
);
2602 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2606 wxWindow
*child
= wxFindWinFromHandle(control
);
2608 child
->MSWOnVScroll(wParam
, pos
, control
);
2612 wxScrollEvent event
;
2613 event
.SetPosition(pos
);
2614 event
.SetOrientation(wxVERTICAL
);
2615 event
.m_eventObject
= this;
2620 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2624 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2628 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2632 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2636 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2640 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2644 case SB_THUMBPOSITION
:
2645 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2653 if (!GetEventHandler()->ProcessEvent(event
))
2657 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2661 wxWindow
*child
= wxFindWinFromHandle(control
);
2663 child
->MSWOnHScroll(wParam
, pos
, control
);
2667 wxScrollEvent event
;
2668 event
.SetPosition(pos
);
2669 event
.SetOrientation(wxHORIZONTAL
);
2670 event
.m_eventObject
= this;
2675 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2679 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2683 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2687 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2691 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2695 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2699 case SB_THUMBPOSITION
:
2700 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2707 if (!GetEventHandler()->ProcessEvent(event
))
2711 void wxWindow::MSWOnShow(bool show
, int status
)
2713 wxShowEvent
event(GetId(), show
);
2714 event
.m_eventObject
= this;
2715 GetEventHandler()->ProcessEvent(event
);
2718 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2720 wxInitDialogEvent
event(GetId());
2721 event
.m_eventObject
= this;
2722 GetEventHandler()->ProcessEvent(event
);
2726 void wxWindow::InitDialog(void)
2728 wxInitDialogEvent
event(GetId());
2729 event
.SetEventObject( this );
2730 GetEventHandler()->ProcessEvent(event
);
2733 // Default init dialog behaviour is to transfer data to window
2734 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2736 TransferDataToWindow();
2739 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2742 HDC dc
= ::GetDC((HWND
) wnd
);
2748 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2750 // the_font->UseResource();
2751 // the_font->RealizeResource();
2752 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2753 was
= (HFONT
) SelectObject(dc
,fnt
) ;
2755 GetTextMetrics(dc
, &tm
);
2756 if (the_font
&& fnt
&& was
)
2759 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2761 SelectObject(dc
,was
) ;
2763 ReleaseDC((HWND
)wnd
, dc
);
2764 *x
= tm
.tmAveCharWidth
;
2765 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2768 // the_font->ReleaseResource();
2771 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2772 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2773 int wxCharCodeMSWToWX(int keySym
)
2778 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2779 case VK_BACK
: id
= WXK_BACK
; break;
2780 case VK_TAB
: id
= WXK_TAB
; break;
2781 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2782 case VK_RETURN
: id
= WXK_RETURN
; break;
2783 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2784 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2785 case VK_MENU
: id
= WXK_MENU
; break;
2786 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2787 case VK_SPACE
: id
= WXK_SPACE
; break;
2788 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2789 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2790 case VK_NEXT
: id
= WXK_NEXT
; break;
2791 case VK_END
: id
= WXK_END
; break;
2792 case VK_HOME
: id
= WXK_HOME
; break;
2793 case VK_LEFT
: id
= WXK_LEFT
; break;
2794 case VK_UP
: id
= WXK_UP
; break;
2795 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2796 case VK_DOWN
: id
= WXK_DOWN
; break;
2797 case VK_SELECT
: id
= WXK_SELECT
; break;
2798 case VK_PRINT
: id
= WXK_PRINT
; break;
2799 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2800 case VK_INSERT
: id
= WXK_INSERT
; break;
2801 case VK_DELETE
: id
= WXK_DELETE
; break;
2802 case VK_HELP
: id
= WXK_HELP
; break;
2803 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2804 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2805 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2806 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2807 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2808 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2809 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2810 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2811 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2812 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2813 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2814 case VK_ADD
: id
= WXK_ADD
; break;
2815 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2816 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2817 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2818 case VK_F1
: id
= WXK_F1
; break;
2819 case VK_F2
: id
= WXK_F2
; break;
2820 case VK_F3
: id
= WXK_F3
; break;
2821 case VK_F4
: id
= WXK_F4
; break;
2822 case VK_F5
: id
= WXK_F5
; break;
2823 case VK_F6
: id
= WXK_F6
; break;
2824 case VK_F7
: id
= WXK_F7
; break;
2825 case VK_F8
: id
= WXK_F8
; break;
2826 case VK_F9
: id
= WXK_F9
; break;
2827 case VK_F10
: id
= WXK_F10
; break;
2828 case VK_F11
: id
= WXK_F11
; break;
2829 case VK_F12
: id
= WXK_F12
; break;
2830 case VK_F13
: id
= WXK_F13
; break;
2831 case VK_F14
: id
= WXK_F14
; break;
2832 case VK_F15
: id
= WXK_F15
; break;
2833 case VK_F16
: id
= WXK_F16
; break;
2834 case VK_F17
: id
= WXK_F17
; break;
2835 case VK_F18
: id
= WXK_F18
; break;
2836 case VK_F19
: id
= WXK_F19
; break;
2837 case VK_F20
: id
= WXK_F20
; break;
2838 case VK_F21
: id
= WXK_F21
; break;
2839 case VK_F22
: id
= WXK_F22
; break;
2840 case VK_F23
: id
= WXK_F23
; break;
2841 case VK_F24
: id
= WXK_F24
; break;
2842 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2843 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2852 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2858 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2859 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2860 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2861 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2862 case WXK_MENU
: keySym
= VK_MENU
; break;
2863 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2864 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2865 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2866 case WXK_END
: keySym
= VK_END
; break;
2867 case WXK_HOME
: keySym
= VK_HOME
; break;
2868 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2869 case WXK_UP
: keySym
= VK_UP
; break;
2870 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2871 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2872 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2873 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2874 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2875 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2876 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2877 case WXK_HELP
: keySym
= VK_HELP
; break;
2878 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2879 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2880 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2881 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2882 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2883 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2884 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2885 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2886 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2887 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2888 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2889 case WXK_ADD
: keySym
= VK_ADD
; break;
2890 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2891 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2892 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2893 case WXK_F1
: keySym
= VK_F1
; break;
2894 case WXK_F2
: keySym
= VK_F2
; break;
2895 case WXK_F3
: keySym
= VK_F3
; break;
2896 case WXK_F4
: keySym
= VK_F4
; break;
2897 case WXK_F5
: keySym
= VK_F5
; break;
2898 case WXK_F6
: keySym
= VK_F6
; break;
2899 case WXK_F7
: keySym
= VK_F7
; break;
2900 case WXK_F8
: keySym
= VK_F8
; break;
2901 case WXK_F9
: keySym
= VK_F9
; break;
2902 case WXK_F10
: keySym
= VK_F10
; break;
2903 case WXK_F11
: keySym
= VK_F11
; break;
2904 case WXK_F12
: keySym
= VK_F12
; break;
2905 case WXK_F13
: keySym
= VK_F13
; break;
2906 case WXK_F14
: keySym
= VK_F14
; break;
2907 case WXK_F15
: keySym
= VK_F15
; break;
2908 case WXK_F16
: keySym
= VK_F16
; break;
2909 case WXK_F17
: keySym
= VK_F17
; break;
2910 case WXK_F18
: keySym
= VK_F18
; break;
2911 case WXK_F19
: keySym
= VK_F19
; break;
2912 case WXK_F20
: keySym
= VK_F20
; break;
2913 case WXK_F21
: keySym
= VK_F21
; break;
2914 case WXK_F22
: keySym
= VK_F22
; break;
2915 case WXK_F23
: keySym
= VK_F23
; break;
2916 case WXK_F24
: keySym
= VK_F24
; break;
2917 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2918 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2929 // Caret manipulation
2930 void wxWindow::CreateCaret(int w
, int h
)
2934 m_caretEnabled
= TRUE
;
2937 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2942 void wxWindow::ShowCaret(bool show
)
2947 ::ShowCaret((HWND
) GetHWND());
2949 ::HideCaret((HWND
) GetHWND());
2950 m_caretShown
= show
;
2954 void wxWindow::DestroyCaret(void)
2956 m_caretEnabled
= FALSE
;
2959 void wxWindow::SetCaretPos(int x
, int y
)
2961 ::SetCaretPos(x
, y
);
2964 void wxWindow::GetCaretPos(int *x
, int *y
) const
2967 ::GetCaretPos(&point
);
2972 // OBSOLETE: use GetUpdateRegion instead.
2976 * Update iterator. Use from within OnPaint.
2979 static RECT gs_UpdateRect
;
2981 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2983 current
= 0; //start somewhere...
2984 #if defined(__WIN32__) && !defined(__win32s__)
2985 rlist
= NULL
; //make sure I don't free randomly
2986 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2989 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2990 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2991 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2992 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2997 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2998 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2999 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
3000 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
3002 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
3006 wxUpdateIterator::~wxUpdateIterator(void)
3010 if (rlist
) delete (RGNDATA
*) rlist
;
3015 wxUpdateIterator::operator int (void)
3017 if (current
< rects
)
3027 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
3033 void wxUpdateIterator::GetRect(wxRect
*rect
)
3035 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
3036 rect
->x
= mswRect
->left
;
3037 rect
->y
= mswRect
->top
;
3038 rect
->width
= mswRect
->right
- mswRect
->left
;
3039 rect
->height
= mswRect
->bottom
- mswRect
->top
;
3042 int wxUpdateIterator::GetX()
3044 return ((RECT
*)rp
)[current
].left
;
3047 int wxUpdateIterator::GetY()
3049 return ((RECT
*)rp
)[current
].top
;
3052 int wxUpdateIterator::GetW()
3054 return ((RECT
*)rp
)[current
].right
-GetX();
3057 int wxUpdateIterator::GetH()
3059 return ((RECT
*)rp
)[current
].bottom
-GetY();
3063 wxWindow
*wxGetActiveWindow(void)
3065 HWND hWnd
= GetActiveWindow();
3068 return wxFindWinFromHandle((WXHWND
) hWnd
);
3073 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3074 // in active frames and dialogs, regardless of where the focus is.
3075 static HHOOK wxTheKeyboardHook
= 0;
3076 static FARPROC wxTheKeyboardHookProc
= 0;
3077 int APIENTRY _EXPORT
3078 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
3080 void wxSetKeyboardHook(bool doIt
)
3084 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
3085 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
3087 GetCurrentThreadId());
3088 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3095 UnhookWindowsHookEx(wxTheKeyboardHook
);
3096 FreeProcInstance(wxTheKeyboardHookProc
);
3100 int APIENTRY _EXPORT
3101 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
3103 DWORD hiWord
= HIWORD(lParam
);
3104 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3107 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3109 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3110 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3111 event
.m_altDown
= TRUE
;
3113 event
.m_eventObject
= NULL
;
3114 event
.m_keyCode
= id
;
3115 /* begin Albert's fix for control and shift key 26.5 */
3116 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3117 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3118 /* end Albert's fix for control and shift key 26.5 */
3119 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3121 wxWindow
*win
= wxGetActiveWindow();
3124 if (win
->GetEventHandler()->ProcessEvent(event
))
3129 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3134 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3137 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3145 void wxWindow::Centre(int direction
)
3147 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3149 wxWindow
*father
= (wxWindow
*)GetParent();
3153 father
->GetClientSize(&panel_width
, &panel_height
);
3154 GetSize(&width
, &height
);
3155 GetPosition(&x
, &y
);
3160 if (direction
& wxHORIZONTAL
)
3161 new_x
= (int)((panel_width
- width
)/2);
3163 if (direction
& wxVERTICAL
)
3164 new_y
= (int)((panel_height
- height
)/2);
3166 SetSize(new_x
, new_y
, -1, -1);
3171 void wxWindow::OnPaint(void)
3173 PaintSelectionHandles();
3177 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3179 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3180 // pixel coordinates, relatives to the canvas -- So, we first need to
3181 // substract origin of the window, then convert to screen position
3183 int x
= x_pos
; int y
= y_pos
;
3184 /* Leave this to the app to decide (and/or wxScrolledWindow)
3185 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3186 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3189 GetWindowRect ((HWND
) GetHWND(), &rect
);
3194 SetCursorPos (x
, y
);
3197 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3200 // Do we have a SetUserScale in wxWindow too, so we can
3201 // get mouse events scaled?
3205 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3206 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3211 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3219 wxEraseEvent
event(m_windowId
, &dc
);
3220 event
.m_eventObject
= this;
3221 if (!GetEventHandler()->ProcessEvent(event
))
3224 dc
.SelectOldObjects(pDC
);
3230 dc
.SelectOldObjects(pDC
);
3233 dc
.SetHDC((WXHDC
) NULL
);
3237 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3240 ::GetClientRect((HWND
) GetHWND(), &rect
);
3242 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3243 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3245 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3246 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3247 ::DeleteObject(hBrush
);
3248 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3250 // Less efficient version (and doesn't account for scrolling)
3252 GetClientSize(& w, & h);
3253 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3254 event.GetDC()->SetBrush(brush);
3255 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3257 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3261 #if WXWIN_COMPATIBILITY
3262 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3264 #if defined(__WIN95__)
3268 // Try to adjust the range to cope with page size > 1
3269 // - a Windows API quirk
3270 int pageSize
= GetScrollPage(orient
);
3271 if ( pageSize
> 1 && range
> 0)
3273 range1
+= (pageSize
- 1);
3279 if (orient
== wxHORIZONTAL
) {
3285 info
.cbSize
= sizeof(SCROLLINFO
);
3286 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3290 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3292 HWND hWnd
= (HWND
) GetHWND();
3294 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3297 if (orient
== wxHORIZONTAL
)
3302 HWND hWnd
= (HWND
) GetHWND();
3304 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3308 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3310 #if defined(__WIN95__)
3314 if (orient
== wxHORIZONTAL
) {
3316 m_xThumbSize
= page
;
3319 m_yThumbSize
= page
;
3322 info
.cbSize
= sizeof(SCROLLINFO
);
3325 info
.fMask
= SIF_PAGE
;
3327 HWND hWnd
= (HWND
) GetHWND();
3329 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3331 if (orient
== wxHORIZONTAL
)
3332 m_xThumbSize
= page
;
3334 m_yThumbSize
= page
;
3338 int wxWindow::OldGetScrollRange(int orient
) const
3341 if (orient
== wxHORIZONTAL
)
3346 #if __WATCOMC__ && defined(__WINDOWS_386__)
3347 short minPos
, maxPos
;
3351 HWND hWnd
= (HWND
) GetHWND();
3354 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3355 #if defined(__WIN95__)
3356 // Try to adjust the range to cope with page size > 1
3357 // - a Windows API quirk
3358 int pageSize
= GetScrollPage(orient
);
3361 maxPos
-= (pageSize
- 1);
3370 int wxWindow::GetScrollPage(int orient
) const
3372 if (orient
== wxHORIZONTAL
)
3373 return m_xThumbSize
;
3375 return m_yThumbSize
;
3379 int wxWindow::GetScrollPos(int orient
) const
3382 if (orient
== wxHORIZONTAL
)
3386 HWND hWnd
= (HWND
) GetHWND();
3389 return ::GetScrollPos(hWnd
, wOrient
);
3395 // This now returns the whole range, not just the number
3396 // of positions that we can scroll.
3397 int wxWindow::GetScrollRange(int orient
) const
3400 if (orient
== wxHORIZONTAL
)
3405 #if __WATCOMC__ && defined(__WINDOWS_386__)
3406 short minPos
, maxPos
;
3410 HWND hWnd
= (HWND
) GetHWND();
3413 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3414 #if defined(__WIN95__)
3415 // Try to adjust the range to cope with page size > 1
3416 // - a Windows API quirk
3417 int pageSize
= GetScrollPage(orient
);
3420 maxPos
-= (pageSize
- 1);
3422 // October 10th: new range concept.
3432 int wxWindow::GetScrollThumb(int orient
) const
3434 if (orient
== wxHORIZONTAL
)
3435 return m_xThumbSize
;
3437 return m_yThumbSize
;
3440 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3442 #if defined(__WIN95__)
3446 if (orient
== wxHORIZONTAL
) {
3452 info
.cbSize
= sizeof(SCROLLINFO
);
3456 info
.fMask
= SIF_POS
;
3458 HWND hWnd
= (HWND
) GetHWND();
3460 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3463 if (orient
== wxHORIZONTAL
)
3468 HWND hWnd
= (HWND
) GetHWND();
3470 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3474 // New function that will replace some of the above.
3475 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3476 int range
, bool refresh
)
3479 SetScrollPage(orient, thumbVisible, FALSE);
3481 int oldRange = range - thumbVisible ;
3482 SetScrollRange(orient, oldRange, FALSE);
3484 SetScrollPos(orient, pos, refresh);
3486 #if defined(__WIN95__)
3487 int oldRange
= range
- thumbVisible
;
3489 int range1
= oldRange
;
3491 // Try to adjust the range to cope with page size > 1
3492 // - a Windows API quirk
3493 int pageSize
= thumbVisible
;
3494 if ( pageSize
> 1 && range
> 0)
3496 range1
+= (pageSize
- 1);
3502 if (orient
== wxHORIZONTAL
) {
3508 info
.cbSize
= sizeof(SCROLLINFO
);
3509 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3513 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3515 HWND hWnd
= (HWND
) GetHWND();
3517 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3520 if (orient
== wxHORIZONTAL
)
3525 HWND hWnd
= (HWND
) GetHWND();
3528 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3529 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3532 if (orient
== wxHORIZONTAL
) {
3533 m_xThumbSize
= thumbVisible
;
3535 m_yThumbSize
= thumbVisible
;
3539 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3544 rect2
.left
= rect
->x
;
3545 rect2
.top
= rect
->y
;
3546 rect2
.right
= rect
->x
+ rect
->width
;
3547 rect2
.bottom
= rect
->y
+ rect
->height
;
3551 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3553 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3557 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3563 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3570 void wxWindow::SetFont(const wxFont
& font
)
3572 // Decrement the usage count of the old label font
3573 // (we may be able to free it up)
3574 // if (GetFont()->Ok())
3575 // GetFont()->ReleaseResource();
3577 m_windowFont
= font
;
3579 if (!m_windowFont
.Ok())
3582 // m_windowFont.UseResource();
3584 HWND hWnd
= (HWND
) GetHWND();
3587 // m_windowFont.RealizeResource();
3589 if (m_windowFont
.GetResourceHandle())
3590 SendMessage(hWnd
, WM_SETFONT
,
3591 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3595 void wxWindow::SubclassWin(WXHWND hWnd
)
3597 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3599 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3600 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3603 void wxWindow::UnsubclassWin(void)
3605 wxRemoveHandleAssociation(this);
3607 // Restore old Window proc
3608 if ((HWND
) GetHWND())
3610 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3611 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3613 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3619 // Make a Windows extended style from the given wxWindows window style
3620 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3622 WXDWORD exStyle
= 0;
3623 if ( style
& wxTRANSPARENT_WINDOW
)
3624 exStyle
|= WS_EX_TRANSPARENT
;
3626 if ( !eliminateBorders
)
3628 if ( style
& wxSUNKEN_BORDER
)
3629 exStyle
|= WS_EX_CLIENTEDGE
;
3630 if ( style
& wxDOUBLE_BORDER
)
3631 exStyle
|= WS_EX_DLGMODALFRAME
;
3632 #if defined(__WIN95__)
3633 if ( style
& wxRAISED_BORDER
)
3634 exStyle
|= WS_EX_WINDOWEDGE
;
3635 if ( style
& wxSTATIC_BORDER
)
3636 exStyle
|= WS_EX_STATICEDGE
;
3642 // Determines whether native 3D effects or CTL3D should be used,
3643 // applying a default border style if required, and returning an extended
3644 // style to pass to CreateWindowEx.
3645 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3647 // If matches certain criteria, then assume no 3D effects
3648 // unless specifically requested (dealt with in MakeExtendedStyle)
3649 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3652 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3655 // Determine whether we should be using 3D effects or not.
3656 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3658 // 1) App can specify global 3D effects
3659 *want3D
= wxTheApp
->GetAuto3D();
3661 // 2) If the parent is being drawn with user colours, or simple border specified,
3662 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3663 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3666 // 3) Control can override this global setting by defining
3667 // a border style, e.g. wxSUNKEN_BORDER
3668 if (m_windowStyle
& wxSUNKEN_BORDER
)
3671 // 4) If it's a special border, CTL3D can't cope so we want a native border
3672 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3673 (m_windowStyle
& wxSTATIC_BORDER
) )
3676 nativeBorder
= TRUE
;
3679 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3680 // effects from extended style
3683 nativeBorder
= FALSE
;
3686 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3688 // If we want 3D, but haven't specified a border here,
3689 // apply the default border style specified.
3690 // TODO what about non-Win95 WIN32? Does it have borders?
3691 #if defined(__WIN95__) && !CTL3D
3692 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3693 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3694 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3700 void wxWindow::OnChar(wxKeyEvent
& event
)
3702 if ( event
.KeyCode() == WXK_TAB
) {
3703 // propagate the TABs to the parent - it's up to it to decide what
3705 if ( GetParent() ) {
3706 if ( GetParent()->ProcessEvent(event
) )
3712 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3717 if ( !event
.ControlDown() )
3718 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3721 void wxWindow::OnPaint(wxPaintEvent
& event
)
3726 bool wxWindow::IsEnabled(void) const
3728 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3731 // Dialog support: override these and call
3732 // base class members to add functionality
3733 // that can't be done using validators.
3734 // NOTE: these functions assume that controls
3735 // are direct children of this window, not grandchildren
3736 // or other levels of descendant.
3738 // Transfer values to controls. If returns FALSE,
3739 // it's an application error (pops up a dialog)
3740 bool wxWindow::TransferDataToWindow(void)
3742 wxNode
*node
= GetChildren()->First();
3745 wxWindow
*child
= (wxWindow
*)node
->Data();
3746 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3747 !child
->GetValidator()->TransferToWindow() )
3749 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3753 node
= node
->Next();
3758 // Transfer values from controls. If returns FALSE,
3759 // validation failed: don't quit
3760 bool wxWindow::TransferDataFromWindow(void)
3762 wxNode
*node
= GetChildren()->First();
3765 wxWindow
*child
= (wxWindow
*)node
->Data();
3766 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3771 node
= node
->Next();
3776 bool wxWindow::Validate(void)
3778 wxNode
*node
= GetChildren()->First();
3781 wxWindow
*child
= (wxWindow
*)node
->Data();
3782 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3787 node
= node
->Next();
3792 // Get the window with the focus
3793 wxWindow
*wxWindow::FindFocus(void)
3795 HWND hWnd
= ::GetFocus();
3798 return wxFindWinFromHandle((WXHWND
) hWnd
);
3803 void wxWindow::AddChild(wxWindow
*child
)
3805 GetChildren()->Append(child
);
3806 child
->m_windowParent
= this;
3809 void wxWindow::RemoveChild(wxWindow
*child
)
3812 GetChildren()->DeleteObject(child
);
3813 child
->m_windowParent
= NULL
;
3816 void wxWindow::DestroyChildren(void)
3818 if (GetChildren()) {
3820 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3822 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3824 if ( GetChildren()->Member(child
) )
3831 void wxWindow::MakeModal(bool modal
)
3833 // Disable all other windows
3834 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3836 wxNode
*node
= wxTopLevelWindows
.First();
3839 wxWindow
*win
= (wxWindow
*)node
->Data();
3841 win
->Enable(!modal
);
3843 node
= node
->Next();
3848 // If nothing defined for this, try the parent.
3849 // E.g. we may be a button loaded from a resource, with no callback function
3851 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3853 if (GetEventHandler()->ProcessEvent(event
) )
3856 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3859 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3863 UnsetConstraints(m_constraints
);
3864 delete m_constraints
;
3869 // Make sure other windows know they're part of a 'meaningful relationship'
3870 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3871 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3872 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3873 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3874 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3875 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3876 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3877 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3878 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3879 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3880 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3881 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3882 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3883 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3884 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3885 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3889 // This removes any dangling pointers to this window
3890 // in other windows' constraintsInvolvedIn lists.
3891 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3895 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3896 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3897 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3898 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3899 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3900 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3901 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3902 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3903 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3904 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3905 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3906 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3907 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3908 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3909 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3910 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3914 // Back-pointer to other windows we're involved with, so if we delete
3915 // this window, we must delete any constraints we're involved with.
3916 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3918 if (!m_constraintsInvolvedIn
)
3919 m_constraintsInvolvedIn
= new wxList
;
3920 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3921 m_constraintsInvolvedIn
->Append(otherWin
);
3924 // REMOVE back-pointer to other windows we're involved with.
3925 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3927 if (m_constraintsInvolvedIn
)
3928 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3931 // Reset any constraints that mention this window
3932 void wxWindow::DeleteRelatedConstraints(void)
3934 if (m_constraintsInvolvedIn
)
3936 wxNode
*node
= m_constraintsInvolvedIn
->First();
3939 wxWindow
*win
= (wxWindow
*)node
->Data();
3940 wxNode
*next
= node
->Next();
3941 wxLayoutConstraints
*constr
= win
->GetConstraints();
3943 // Reset any constraints involving this window
3946 constr
->left
.ResetIfWin((wxWindow
*)this);
3947 constr
->top
.ResetIfWin((wxWindow
*)this);
3948 constr
->right
.ResetIfWin((wxWindow
*)this);
3949 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3950 constr
->width
.ResetIfWin((wxWindow
*)this);
3951 constr
->height
.ResetIfWin((wxWindow
*)this);
3952 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3953 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3958 delete m_constraintsInvolvedIn
;
3959 m_constraintsInvolvedIn
= NULL
;
3963 void wxWindow::SetSizer(wxSizer
*sizer
)
3965 m_windowSizer
= sizer
;
3967 sizer
->SetSizerParent((wxWindow
*)this);
3974 bool wxWindow::Layout(void)
3976 if (GetConstraints())
3979 GetClientSize(&w
, &h
);
3980 GetConstraints()->width
.SetValue(w
);
3981 GetConstraints()->height
.SetValue(h
);
3984 // If top level (one sizer), evaluate the sizer's constraints.
3988 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3989 GetSizer()->LayoutPhase1(&noChanges
);
3990 GetSizer()->LayoutPhase2(&noChanges
);
3991 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3996 // Otherwise, evaluate child constraints
3997 ResetConstraints(); // Mark all constraints as unevaluated
3998 DoPhase(1); // Just one phase need if no sizers involved
4000 SetConstraintSizes(); // Recursively set the real window sizes
4006 // Do a phase of evaluating constraints:
4007 // the default behaviour. wxSizers may do a similar
4008 // thing, but also impose their own 'constraints'
4009 // and order the evaluation differently.
4010 bool wxWindow::LayoutPhase1(int *noChanges
)
4012 wxLayoutConstraints
*constr
= GetConstraints();
4015 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
4021 bool wxWindow::LayoutPhase2(int *noChanges
)
4031 // Do a phase of evaluating child constraints
4032 bool wxWindow::DoPhase(int phase
)
4034 int noIterations
= 0;
4035 int maxIterations
= 500;
4039 while ((noChanges
> 0) && (noIterations
< maxIterations
))
4043 wxNode
*node
= GetChildren()->First();
4046 wxWindow
*child
= (wxWindow
*)node
->Data();
4047 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
4049 wxLayoutConstraints
*constr
= child
->GetConstraints();
4052 if (succeeded
.Member(child
))
4057 int tempNoChanges
= 0;
4058 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
4059 noChanges
+= tempNoChanges
;
4062 succeeded
.Append(child
);
4067 node
= node
->Next();
4074 void wxWindow::ResetConstraints(void)
4076 wxLayoutConstraints
*constr
= GetConstraints();
4079 constr
->left
.SetDone(FALSE
);
4080 constr
->top
.SetDone(FALSE
);
4081 constr
->right
.SetDone(FALSE
);
4082 constr
->bottom
.SetDone(FALSE
);
4083 constr
->width
.SetDone(FALSE
);
4084 constr
->height
.SetDone(FALSE
);
4085 constr
->centreX
.SetDone(FALSE
);
4086 constr
->centreY
.SetDone(FALSE
);
4088 wxNode
*node
= GetChildren()->First();
4091 wxWindow
*win
= (wxWindow
*)node
->Data();
4092 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4093 win
->ResetConstraints();
4094 node
= node
->Next();
4098 // Need to distinguish between setting the 'fake' size for
4099 // windows and sizers, and setting the real values.
4100 void wxWindow::SetConstraintSizes(bool recurse
)
4102 wxLayoutConstraints
*constr
= GetConstraints();
4103 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4104 constr
->width
.GetDone() && constr
->height
.GetDone())
4106 int x
= constr
->left
.GetValue();
4107 int y
= constr
->top
.GetValue();
4108 int w
= constr
->width
.GetValue();
4109 int h
= constr
->height
.GetValue();
4111 // If we don't want to resize this window, just move it...
4112 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4113 (constr
->height
.GetRelationship() != wxAsIs
))
4115 // Calls Layout() recursively. AAAGH. How can we stop that.
4116 // Simply take Layout() out of non-top level OnSizes.
4117 SizerSetSize(x
, y
, w
, h
);
4126 char *windowClass
= this->GetClassInfo()->GetClassName();
4129 if (GetName() == "")
4130 winName
= "unnamed";
4132 winName
= GetName();
4133 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4134 if (!constr
->left
.GetDone())
4135 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4136 if (!constr
->right
.GetDone())
4137 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4138 if (!constr
->width
.GetDone())
4139 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4140 if (!constr
->height
.GetDone())
4141 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4142 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4147 wxNode
*node
= GetChildren()->First();
4150 wxWindow
*win
= (wxWindow
*)node
->Data();
4151 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4152 win
->SetConstraintSizes();
4153 node
= node
->Next();
4158 // This assumes that all sizers are 'on' the same
4159 // window, i.e. the parent of this window.
4160 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4162 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4163 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4167 m_sizerParent
->GetPosition(&xp
, &yp
);
4168 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4173 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4177 TransformSizerToActual(&xx
, &yy
);
4178 SetSize(xx
, yy
, w
, h
);
4181 void wxWindow::SizerMove(int x
, int y
)
4185 TransformSizerToActual(&xx
, &yy
);
4189 // Only set the size/position of the constraint (if any)
4190 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4192 wxLayoutConstraints
*constr
= GetConstraints();
4197 constr
->left
.SetValue(x
);
4198 constr
->left
.SetDone(TRUE
);
4202 constr
->top
.SetValue(y
);
4203 constr
->top
.SetDone(TRUE
);
4207 constr
->width
.SetValue(w
);
4208 constr
->width
.SetDone(TRUE
);
4212 constr
->height
.SetValue(h
);
4213 constr
->height
.SetDone(TRUE
);
4218 void wxWindow::MoveConstraint(int x
, int y
)
4220 wxLayoutConstraints
*constr
= GetConstraints();
4225 constr
->left
.SetValue(x
);
4226 constr
->left
.SetDone(TRUE
);
4230 constr
->top
.SetValue(y
);
4231 constr
->top
.SetDone(TRUE
);
4236 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4238 wxLayoutConstraints
*constr
= GetConstraints();
4241 *w
= constr
->width
.GetValue();
4242 *h
= constr
->height
.GetValue();
4248 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4250 wxLayoutConstraints
*constr
= GetConstraints();
4253 *w
= constr
->width
.GetValue();
4254 *h
= constr
->height
.GetValue();
4257 GetClientSize(w
, h
);
4260 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4262 wxLayoutConstraints
*constr
= GetConstraints();
4265 *x
= constr
->left
.GetValue();
4266 *y
= constr
->top
.GetValue();
4272 bool wxWindow::Close(bool force
)
4274 // Let's generalise it to work the same for any window.
4276 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4283 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4284 event
.SetEventObject(this);
4285 event
.SetForce(force
);
4287 return GetEventHandler()->ProcessEvent(event
);
4290 if ( !force && event.GetVeto() )
4295 if (!wxPendingDelete.Member(this))
4296 wxPendingDelete.Append(this);
4302 wxObject
* wxWindow::GetChild(int number
) const
4304 // Return a pointer to the Nth object in the Panel
4307 wxNode
*node
= GetChildren()->First();
4310 node
= node
->Next() ;
4313 wxObject
*obj
= (wxObject
*)node
->Data();
4320 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4322 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4323 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4326 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4328 wxListBox *lbox = (wxListBox *)initiatingItem;
4329 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4330 event.m_commandInt = -1;
4331 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4333 event.m_commandString = copystring(lbox->GetStringSelection());
4334 event.m_commandInt = lbox->GetSelection();
4335 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4337 event.m_eventObject = lbox;
4339 lbox->ProcessCommand(event);
4341 if (event.m_commandString)
4342 delete[] event.m_commandString;
4346 wxButton *but = GetDefaultItem();
4349 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4350 event.SetEventObject(but);
4351 but->Command(event);
4356 void wxWindow::Clear(void)
4358 wxClientDC
dc(this);
4359 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4360 dc
.SetBackground(brush
);
4364 // Fits the panel around the items
4365 void wxWindow::Fit(void)
4369 wxNode
*node
= GetChildren()->First();
4372 wxWindow
*win
= (wxWindow
*)node
->Data();
4374 win
->GetPosition(&wx
, &wy
);
4375 win
->GetSize(&ww
, &wh
);
4376 if ( wx
+ ww
> maxX
)
4378 if ( wy
+ wh
> maxY
)
4381 node
= node
->Next();
4383 SetClientSize(maxX
+ 5, maxY
+ 5);
4386 void wxWindow::SetValidator(const wxValidator
& validator
)
4388 if ( m_windowValidator
)
4389 delete m_windowValidator
;
4390 m_windowValidator
= validator
.Clone();
4392 if ( m_windowValidator
)
4393 m_windowValidator
->SetWindow(this) ;
4396 // Find a window by id or name
4397 wxWindow
*wxWindow::FindWindow(long id
)
4402 wxNode
*node
= GetChildren()->First();
4405 wxWindow
*child
= (wxWindow
*)node
->Data();
4406 wxWindow
*found
= child
->FindWindow(id
);
4409 node
= node
->Next();
4414 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4416 if ( GetName() == name
)
4419 wxNode
*node
= GetChildren()->First();
4422 wxWindow
*child
= (wxWindow
*)node
->Data();
4423 wxWindow
*found
= child
->FindWindow(name
);
4426 node
= node
->Next();
4432 // Default input behaviour for a scrolling canvas should be to scroll
4433 // according to the cursor keys pressed
4434 void wxWindow::OnChar(wxKeyEvent& event)
4446 GetScrollUnitsPerPage(&x_page, &y_page);
4448 GetVirtualSize(&v_width,&v_height);
4450 ViewStart(&start_x, &start_y);
4453 y_pages = (int)(v_height/vert_units) - y_page;
4461 switch (event.keyCode)
4468 if (start_y - y_page > 0)
4469 Scroll(start_x, start_y - y_page);
4479 if ((y_page > 0) && (start_y <= y_pages-y-1))
4481 if (y_pages + y < start_y + y_page)
4482 Scroll(start_x, y_pages + y);
4484 Scroll(start_x, start_y + y_page);
4491 if ((y_page > 0) && (start_y >= 1))
4492 Scroll(start_x, start_y - 1);
4498 if ((y_page > 0) && (start_y <= y_pages-y-1))
4501 Scroll(start_x, start_y + 1);
4507 if ((x_page > 0) && (start_x >= 1))
4508 Scroll(start_x - 1, start_y);
4514 Scroll(start_x + 1, start_y);
4525 Scroll(start_x, y_pages+y);
4533 // Setup background and foreground colours correctly
4534 void wxWindow::SetupColours(void)
4537 SetBackgroundColour(GetParent()->GetBackgroundColour());
4540 void wxWindow::OnIdle(wxIdleEvent
& event
)
4542 // Check if we need to send a LEAVE event
4543 if (m_mouseInWindow
)
4546 ::GetCursorPos(&pt
);
4547 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4549 // Generate a LEAVE event
4550 m_mouseInWindow
= FALSE
;
4551 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4557 // Raise the window to the top of the Z order
4558 void wxWindow::Raise(void)
4560 ::BringWindowToTop((HWND
) GetHWND());
4563 // Lower the window to the bottom of the Z order
4564 void wxWindow::Lower(void)
4566 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
4569 long wxWindow::MSWGetDlgCode()
4571 // default: just forward to def window proc (the msg has no parameters)
4572 return MSWDefWindowProc(WM_GETDLGCODE
, 0, 0);
4575 bool wxWindow::AcceptsFocus() const
4577 return IsShown() && IsEnabled();
4580 // Update region access
4581 wxRegion
wxWindow::GetUpdateRegion() const
4583 return m_updateRegion
;
4586 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
4588 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
4591 bool wxWindow::IsExposed(const wxPoint
& pt
) const
4593 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
4596 bool wxWindow::IsExposed(const wxRect
& rect
) const
4598 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
4602 const char *wxGetMessageName(int message
)
4604 switch ( message
) {
4605 case 0x0000: return "WM_NULL";
4606 case 0x0001: return "WM_CREATE";
4607 case 0x0002: return "WM_DESTROY";
4608 case 0x0003: return "WM_MOVE";
4609 case 0x0005: return "WM_SIZE";
4610 case 0x0006: return "WM_ACTIVATE";
4611 case 0x0007: return "WM_SETFOCUS";
4612 case 0x0008: return "WM_KILLFOCUS";
4613 case 0x000A: return "WM_ENABLE";
4614 case 0x000B: return "WM_SETREDRAW";
4615 case 0x000C: return "WM_SETTEXT";
4616 case 0x000D: return "WM_GETTEXT";
4617 case 0x000E: return "WM_GETTEXTLENGTH";
4618 case 0x000F: return "WM_PAINT";
4619 case 0x0010: return "WM_CLOSE";
4620 case 0x0011: return "WM_QUERYENDSESSION";
4621 case 0x0012: return "WM_QUIT";
4622 case 0x0013: return "WM_QUERYOPEN";
4623 case 0x0014: return "WM_ERASEBKGND";
4624 case 0x0015: return "WM_SYSCOLORCHANGE";
4625 case 0x0016: return "WM_ENDSESSION";
4626 case 0x0017: return "WM_SYSTEMERROR";
4627 case 0x0018: return "WM_SHOWWINDOW";
4628 case 0x0019: return "WM_CTLCOLOR";
4629 case 0x001A: return "WM_WININICHANGE";
4630 case 0x001B: return "WM_DEVMODECHANGE";
4631 case 0x001C: return "WM_ACTIVATEAPP";
4632 case 0x001D: return "WM_FONTCHANGE";
4633 case 0x001E: return "WM_TIMECHANGE";
4634 case 0x001F: return "WM_CANCELMODE";
4635 case 0x0020: return "WM_SETCURSOR";
4636 case 0x0021: return "WM_MOUSEACTIVATE";
4637 case 0x0022: return "WM_CHILDACTIVATE";
4638 case 0x0023: return "WM_QUEUESYNC";
4639 case 0x0024: return "WM_GETMINMAXINFO";
4640 case 0x0026: return "WM_PAINTICON";
4641 case 0x0027: return "WM_ICONERASEBKGND";
4642 case 0x0028: return "WM_NEXTDLGCTL";
4643 case 0x002A: return "WM_SPOOLERSTATUS";
4644 case 0x002B: return "WM_DRAWITEM";
4645 case 0x002C: return "WM_MEASUREITEM";
4646 case 0x002D: return "WM_DELETEITEM";
4647 case 0x002E: return "WM_VKEYTOITEM";
4648 case 0x002F: return "WM_CHARTOITEM";
4649 case 0x0030: return "WM_SETFONT";
4650 case 0x0031: return "WM_GETFONT";
4651 case 0x0037: return "WM_QUERYDRAGICON";
4652 case 0x0039: return "WM_COMPAREITEM";
4653 case 0x0041: return "WM_COMPACTING";
4654 case 0x0044: return "WM_COMMNOTIFY";
4655 case 0x0046: return "WM_WINDOWPOSCHANGING";
4656 case 0x0047: return "WM_WINDOWPOSCHANGED";
4657 case 0x0048: return "WM_POWER";
4658 case 0x0081: return "WM_NCCREATE";
4659 case 0x0082: return "WM_NCDESTROY";
4660 case 0x0083: return "WM_NCCALCSIZE";
4661 case 0x0084: return "WM_NCHITTEST";
4662 case 0x0085: return "WM_NCPAINT";
4663 case 0x0086: return "WM_NCACTIVATE";
4664 case 0x0087: return "WM_GETDLGCODE";
4665 case 0x00A0: return "WM_NCMOUSEMOVE";
4666 case 0x00A1: return "WM_NCLBUTTONDOWN";
4667 case 0x00A2: return "WM_NCLBUTTONUP";
4668 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4669 case 0x00A4: return "WM_NCRBUTTONDOWN";
4670 case 0x00A5: return "WM_NCRBUTTONUP";
4671 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4672 case 0x00A7: return "WM_NCMBUTTONDOWN";
4673 case 0x00A8: return "WM_NCMBUTTONUP";
4674 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4675 case 0x0100: return "WM_KEYDOWN";
4676 case 0x0101: return "WM_KEYUP";
4677 case 0x0102: return "WM_CHAR";
4678 case 0x0103: return "WM_DEADCHAR";
4679 case 0x0104: return "WM_SYSKEYDOWN";
4680 case 0x0105: return "WM_SYSKEYUP";
4681 case 0x0106: return "WM_SYSCHAR";
4682 case 0x0107: return "WM_SYSDEADCHAR";
4683 case 0x0108: return "WM_KEYLAST";
4684 case 0x0110: return "WM_INITDIALOG";
4685 case 0x0111: return "WM_COMMAND";
4686 case 0x0112: return "WM_SYSCOMMAND";
4687 case 0x0113: return "WM_TIMER";
4688 case 0x0114: return "WM_HSCROLL";
4689 case 0x0115: return "WM_VSCROLL";
4690 case 0x0116: return "WM_INITMENU";
4691 case 0x0117: return "WM_INITMENUPOPUP";
4692 case 0x011F: return "WM_MENUSELECT";
4693 case 0x0120: return "WM_MENUCHAR";
4694 case 0x0121: return "WM_ENTERIDLE";
4695 case 0x0200: return "WM_MOUSEMOVE";
4696 case 0x0201: return "WM_LBUTTONDOWN";
4697 case 0x0202: return "WM_LBUTTONUP";
4698 case 0x0203: return "WM_LBUTTONDBLCLK";
4699 case 0x0204: return "WM_RBUTTONDOWN";
4700 case 0x0205: return "WM_RBUTTONUP";
4701 case 0x0206: return "WM_RBUTTONDBLCLK";
4702 case 0x0207: return "WM_MBUTTONDOWN";
4703 case 0x0208: return "WM_MBUTTONUP";
4704 case 0x0209: return "WM_MBUTTONDBLCLK";
4705 case 0x0210: return "WM_PARENTNOTIFY";
4706 case 0x0220: return "WM_MDICREATE";
4707 case 0x0221: return "WM_MDIDESTROY";
4708 case 0x0222: return "WM_MDIACTIVATE";
4709 case 0x0223: return "WM_MDIRESTORE";
4710 case 0x0224: return "WM_MDINEXT";
4711 case 0x0225: return "WM_MDIMAXIMIZE";
4712 case 0x0226: return "WM_MDITILE";
4713 case 0x0227: return "WM_MDICASCADE";
4714 case 0x0228: return "WM_MDIICONARRANGE";
4715 case 0x0229: return "WM_MDIGETACTIVE";
4716 case 0x0230: return "WM_MDISETMENU";
4717 case 0x0233: return "WM_DROPFILES";
4718 case 0x0300: return "WM_CUT";
4719 case 0x0301: return "WM_COPY";
4720 case 0x0302: return "WM_PASTE";
4721 case 0x0303: return "WM_CLEAR";
4722 case 0x0304: return "WM_UNDO";
4723 case 0x0305: return "WM_RENDERFORMAT";
4724 case 0x0306: return "WM_RENDERALLFORMATS";
4725 case 0x0307: return "WM_DESTROYCLIPBOARD";
4726 case 0x0308: return "WM_DRAWCLIPBOARD";
4727 case 0x0309: return "WM_PAINTCLIPBOARD";
4728 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4729 case 0x030B: return "WM_SIZECLIPBOARD";
4730 case 0x030C: return "WM_ASKCBFORMATNAME";
4731 case 0x030D: return "WM_CHANGECBCHAIN";
4732 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4733 case 0x030F: return "WM_QUERYNEWPALETTE";
4734 case 0x0310: return "WM_PALETTEISCHANGING";
4735 case 0x0311: return "WM_PALETTECHANGED";
4737 static char s_szBuf
[128];
4738 sprintf(s_szBuf
, "<unknown message = %d>", message
);