From 57591e0edb8cbaa2b12e4a0da68fe445fa636747 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 8 Sep 2000 13:52:10 +0000 Subject: [PATCH] Fixed some broken things related to context help, fixed memory leak in wxGenericTreeCtrl (Init should be called before Create, not _in_ Create) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8295 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/treectlg.h | 1 + include/wx/utils.h | 3 +++ src/common/cshelp.cpp | 6 +++--- src/common/utilscmn.cpp | 9 ++++++--- src/generic/treectlg.cpp | 2 -- src/gtk/utilsgtk.cpp | 6 ++++++ src/gtk/window.cpp | 2 ++ src/gtk1/utilsgtk.cpp | 6 ++++++ src/gtk1/window.cpp | 2 ++ src/mac/carbon/utils.cpp | 4 ++++ src/mac/carbon/window.cpp | 5 +++-- src/mac/utils.cpp | 4 ++++ src/mac/window.cpp | 5 +++-- src/motif/utils.cpp | 5 +++++ src/motif/window.cpp | 4 +--- src/msw/window.cpp | 12 +++++++++--- 16 files changed, 58 insertions(+), 18 deletions(-) diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index 650d518bc3..1bc9bd1103 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -57,6 +57,7 @@ public: const wxValidator &validator = wxDefaultValidator, const wxString& name = wxTreeCtrlNameStr) { + Init(); Create(parent, id, pos, size, style, validator, name); } diff --git a/include/wx/utils.h b/include/wx/utils.h index b907015be3..c472247690 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -270,6 +270,9 @@ WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent // Returns menu item id or -1 if none. WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString); +// Find the wxWindow at the given point. wxGenericFindWindowAtPoint +// is always present but may be less reliable than a native version. +WXDLLEXPORT wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt); WXDLLEXPORT wxWindow* wxFindWindowAtPoint(const wxPoint& pt); // ---------------------------------------------------------------------------- diff --git a/src/common/cshelp.cpp b/src/common/cshelp.cpp index fe75524bb8..37a3ade54c 100644 --- a/src/common/cshelp.cpp +++ b/src/common/cshelp.cpp @@ -191,8 +191,8 @@ bool wxContextHelp::DispatchEvent(wxWindow* win, const wxPoint& pt) #if !defined(__WXMSW__) static char * csquery_xpm[] = { "12 11 2 1", -" c None", -". c Black", +" c None", +". c #000000", " ", " .... ", " .. .. ", @@ -228,7 +228,7 @@ wxContextHelpButton::wxContextHelpButton(wxWindow* parent, wxWindowID id, void wxContextHelpButton::OnContextHelp(wxCommandEvent& event) { - wxContextHelp contextHelp; + wxContextHelp contextHelp(GetParent()); } #endif // wxUSE_HELP diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index e35cd29f78..e556674f85 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -694,16 +694,19 @@ wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt) return NULL; } -wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt) { - wxNode* node = wxTopLevelWindows.First(); + // Go backwards through the list since windows + // on top are likely to have been appended most + // recently. + wxNode* node = wxTopLevelWindows.Last(); while (node) { wxWindow* win = (wxWindow*) node->Data(); wxWindow* found = wxFindWindowAtPoint(win, pt); if (found) return found; - node = node->Next(); + node = node->Previous(); } return NULL; } diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index d63cdc8705..7d9ea69e54 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -638,8 +638,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator &validator, const wxString& name ) { - Init(); - wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ); #if wxUSE_VALIDATORS diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 92aac44482..1f985793be 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -111,6 +111,12 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) return wxGTK; } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} + + // ---------------------------------------------------------------------------- // subprocess routines // ---------------------------------------------------------------------------- diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index d56ab1057d..9d8bd481a9 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -3777,6 +3777,8 @@ wxPoint wxGetMousePosition() int x, y; GdkWindow* windowAtPtr = gdk_window_at_pointer(& x, & y); + if (!windowAtPtr) + return wxPoint(-999, -999); Display *display = GDK_WINDOW_XDISPLAY(windowAtPtr); Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 92aac44482..1f985793be 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -111,6 +111,12 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) return wxGTK; } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} + + // ---------------------------------------------------------------------------- // subprocess routines // ---------------------------------------------------------------------------- diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index d56ab1057d..9d8bd481a9 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -3777,6 +3777,8 @@ wxPoint wxGetMousePosition() int x, y; GdkWindow* windowAtPtr = gdk_window_at_pointer(& x, & y); + if (!windowAtPtr) + return wxPoint(-999, -999); Display *display = GDK_WINDOW_XDISPLAY(windowAtPtr); Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 0031f1efad..b312321562 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -329,3 +329,7 @@ void wxDisplaySize(int *width, int *height) #endif } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index fe831d3d08..d2696fe6e0 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -2369,7 +2369,8 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt) // Get the current mouse position. wxPoint wxGetMousePosition() { - wxFAIL_MSG(_("Not implemented")); - return wxPoint; + int x, y; + wxGetMousePosition(& x, & y); + return wxPoint(x, y); } diff --git a/src/mac/utils.cpp b/src/mac/utils.cpp index 0031f1efad..b312321562 100644 --- a/src/mac/utils.cpp +++ b/src/mac/utils.cpp @@ -329,3 +329,7 @@ void wxDisplaySize(int *width, int *height) #endif } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} diff --git a/src/mac/window.cpp b/src/mac/window.cpp index fe831d3d08..d2696fe6e0 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -2369,7 +2369,8 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt) // Get the current mouse position. wxPoint wxGetMousePosition() { - wxFAIL_MSG(_("Not implemented")); - return wxPoint; + int x, y; + wxGetMousePosition(& x, & y); + return wxPoint(x, y); } diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 2194b1d835..0dab1add9b 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -706,6 +706,11 @@ wxString wxGetDisplayName() return gs_displayName; } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} + // ---------------------------------------------------------------------------- // accelerators // ---------------------------------------------------------------------------- diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 5e39ed8eef..80302f08d7 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -2992,9 +2992,7 @@ wxWindow *wxGetActiveWindow() // position. wxWindow* wxFindWindowAtPointer(wxPoint& pt) { - pt = wxGetMousePosition(); - wxWindow* found = wxFindWindowAtPoint(pt); - return found; + return wxFindWindowAtPoint(wxGetMousePosition()); } // Get the current mouse position. diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 6a4d9c2250..c7b28bac0b 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4389,9 +4389,15 @@ static TEXTMETRIC wxGetTextMetrics(const wxWindow *win) // position. wxWindow* wxFindWindowAtPointer(wxPoint& pt) { - // Use current message to find last mouse position - extern MSG s_currentMsg; - HWND hWndHit = ::WindowFromPoint(s_currentMsg.pt); + return wxFindWindowAtPoint(wxGetMousePosition()); +} + +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + POINT pt2; + pt2.x = pt.x; + pt2.y = pt.y; + HWND hWndHit = ::WindowFromPoint(pt2); wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ; HWND hWnd = hWndHit; -- 2.45.2