cwfrompoint.cpp

Go to the documentation of this file.
00001 // $Id: cwfrompoint.cpp 1412 2006-07-05 19:53:47Z alex $
00002 /* @@tag:xara-cn-tp@@ THIRD PARTY COPYRIGHT */
00003 // The following line makes normalize.pl skip type fixing
00004 /* SKIPFIXTYPES: START */
00005 
00006 // This file is derived from CVSHEAD wxWidgets and is thus
00007 // under the wxWidgets / wxWindows license.
00008 
00009 #include "cwfrompoint.h"
00010 
00011 #include <wx/notebook.h>
00012 
00013 // wxChildWindowFromPoint
00014 //
00015 // This is a routine derived from wxFindWindowAtPoint (the unexported variant thereof).
00016 // It finds the child window of a window passed as a parameter, which contains the point
00017 // passed in. It fill find the deepest such child window. If no child window contains the
00018 // point passed in, it will return a pointer to the window itself, unless that also
00019 // does not contain the point in question, in which case it will return NULL.
00020 // The "hidden" flag determines whether or not it should examine windows which are
00021 // hidden (i.e. for which IsShown() is false). The routine can be passed a depth
00022 // to recurse to, negative depth being infinite recursion, zero meaning do not look at
00023 // child windows, and positive meaning a limited depth.
00024 //
00025 // Inputs:
00026 //   wxWindow * win       The window to examine, plus children thereof
00027 //   const wxPoint& pt    The coordinate, in screen coords
00028 //   bool hidden          Flag, true to examine hidden windows as well (defaults to true)
00029 //   int depth            Depth of recursion; zero to not recurse, positive for that number
00030 //                        of levels, negative for infinite recursion (defaults to 1)
00031 // Returns:
00032 //   wxWindow *           Pointer to the deepest window searched containing pt, or NULL
00033 
00034 wxWindow* wxChildWindowFromPoint(wxWindow* win, const wxPoint& pt, bool hidden /* =true */, int depth /* =1 */)
00035 {
00036     bool shown = win->IsShown();
00037 
00038     if (win->IsKindOf(CLASSINFO(wxMDIChildFrame)))
00039     {
00040         wxWindow * pParent=win;
00041         // Look for a wxMDIParentFrame
00042         while ((pParent = /*assignment*/ pParent->GetParent()) && !(pParent->IsKindOf(CLASSINFO(wxMDIParentFrame)))) {}
00043         if (pParent)
00044         {
00045             // If this isn't the active child, then treat it as if it was hidden.
00046             if (((wxMDIParentFrame *)pParent)->GetActiveChild() != win)
00047                 shown=FALSE;
00048         }
00049     }
00050 
00051     if (!(hidden || shown))
00052         return NULL;
00053 
00054     // Hack for wxNotebook case: at least in wxGTK, all pages
00055     // claim to be shown, so we must only deal with the selected one.
00056 #if wxUSE_NOTEBOOK
00057     // If depth is >0, we want to descend as we have more searching to do. If depth
00058     // is negative, that means descend to infinite depth. So don't descend if depth
00059     // is exactly zero
00060     if (depth && (win->IsKindOf(CLASSINFO(wxNotebook))))
00061     {
00062       wxNotebook* nb = (wxNotebook*) win;
00063       int sel = nb->GetSelection();
00064       if (sel >= 0)
00065       {
00066         wxWindow* child = nb->GetPage(sel);
00067         wxWindow* foundWin = wxChildWindowFromPoint(child, pt, hidden, (depth<0)?depth:depth-1);
00068         if (foundWin)
00069            return foundWin;
00070       }
00071     }
00072 #endif
00073 
00074     // If depth is >0, we want to descend as we have more searching to do. If depth
00075     // is negative, that means descend to infinite depth. So don't descend if depth
00076     // is exactly zero
00077     if (depth)
00078     {
00079         wxWindowList::compatibility_iterator node = win->GetChildren().GetLast();
00080         while (node)
00081         {
00082             wxWindow* child = node->GetData();
00083             wxWindow* foundWin = wxChildWindowFromPoint(child, pt, hidden, (depth<0)?depth:depth-1);
00084             if (foundWin)
00085               return foundWin;
00086             node = node->GetPrevious();
00087         }
00088     }
00089 
00090     wxPoint pos = win->GetPosition();
00091     wxSize sz = win->GetSize();
00092     if (win->GetParent() && !win->IsTopLevel()) // Do not translate coords in TLWs as they are already screen coords
00093     {
00094         pos = win->GetParent()->ClientToScreen(pos);
00095     }
00096 
00097     wxRect rect(pos, sz);
00098     if (rect.Inside(pt))
00099         return win;
00100     else
00101         return NULL;
00102 }
00103 
00104 // The same routine again but without the window hint
00105 
00106 wxWindow* wxChildWindowFromPoint(const wxPoint& pt, bool hidden /* =true */, int depth /* =1 */)
00107 {
00108     // Go backwards through the list since windows
00109     // on top are likely to have been appended most
00110     // recently.
00111     wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetLast();
00112     while (node)
00113     {
00114         wxWindow* win = node->GetData();
00115         wxWindow* found = wxChildWindowFromPoint(win, pt, hidden, depth);
00116         if (found)
00117             return found;
00118         node = node->GetPrevious();
00119     }
00120     return NULL;
00121 }
00122 
00123 

Generated on Sat Nov 10 03:49:00 2007 for Camelot by  doxygen 1.4.4