new wxWindow::FindWindowByXXX() methods replacing the old global functions

(patches 560214, 559916, 559811, ...)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15664 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2002-05-25 14:24:43 +00:00
parent 3317223b08
commit 146ba0feac
6 changed files with 197 additions and 108 deletions

View File

@ -2160,6 +2160,9 @@ Find a menu item identifier associated with the given frame's menu bar.
\func{wxWindow *}{wxFindWindowByLabel}{\param{const wxString\& }{label}, \param{wxWindow *}{parent=NULL}}
{\bf NB:} This function is obsolete, please use
\helpref{wxWindow::FindWindowByLabel}{wxwindowfindwindowbylabel} instead.
Find a window by its label. Depending on the type of window, the label may be a window title
or panel item label. If {\it parent} is NULL, the search will start from all top-level
frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy.
@ -2173,6 +2176,9 @@ The search is recursive in both cases.
\func{wxWindow *}{wxFindWindowByName}{\param{const wxString\& }{name}, \param{wxWindow *}{parent=NULL}}
{\bf NB:} This function is obsolete, please use
\helpref{wxWindow::FindWindowByName}{wxwindowfindwindowbyname} instead.
Find a window by its name (as given in a window constructor or {\bf Create} function call).
If {\it parent} is NULL, the search will start from all top-level
frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy.

View File

@ -469,6 +469,49 @@ implements the following methods:\par
\end{twocollist}}
}
\membersection{wxWindow::FindWindowById}\label{wxwindowfindwindow}
\func{wxWindow*}{FindWindowById}{\param{long}{ id}}
Find the first window with the given {\it id}.
If {\it parent} is NULL, the search will start from all top-level
frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy.
The search is recursive in both cases.
\wxheading{See also}
\helpref{FindWindowById}{wxwindowfindwindowbyid}
\membersection{wxWindow::FindWindowByName}\label{wxwindowfindwindowbyname}
\func{wxWindow*}{FindWindowByName}{\param{long}{ id}}
Find a window by its name (as given in a window constructor or {\bf Create} function call).
If {\it parent} is NULL, the search will start from all top-level
frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy.
The search is recursive in both cases.
If no window with such name is found,
\helpref{FindWindowByLabel}{wxwindowfindwindowbylabel} is called.
\wxheading{See also}
\helpref{FindWindowById}{wxwindowfindwindowbyid}
\membersection{wxWindow::FindWindowByLabel}\label{wxwindowfindwindowbylabel}
\func{wxWindow*}{FindWindowByLabel}{\param{long}{ id}}
Find a window by its label. Depending on the type of window, the label may be a window title
or panel item label. If {\it parent} is NULL, the search will start from all top-level
frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy.
The search is recursive in both cases.
\wxheading{See also}
\helpref{FindWindowById}{wxwindowfindwindowbyid}
\membersection{wxWindow::Fit}\label{wxwindowfit}
\func{virtual void}{Fit}{\void}

View File

@ -332,14 +332,6 @@ WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
// Window search
// ----------------------------------------------------------------------------
// Find the window/widget with the given title or label.
// Pass a parent to begin the search from, or NULL to look through
// all windows.
WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
// Find window by name, and if that fails, by label.
WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
// Returns menu item id or -1 if none.
WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
@ -348,6 +340,18 @@ WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, con
WXDLLEXPORT wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
WXDLLEXPORT wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
// NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
//
// Find the window/widget with the given title or label.
// Pass a parent to begin the search from, or NULL to look through
// all windows.
WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
// NB: this function is obsolete, use wxWindow::FindWindowByName() instead
//
// Find window by name, and if that fails, by label.
WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
// ----------------------------------------------------------------------------
// Message/event queue helpers
// ----------------------------------------------------------------------------

View File

@ -423,14 +423,24 @@ public:
// was changed, FALSE otherwise (error or newParent == oldParent)
virtual bool Reparent( wxWindowBase *newParent );
// implementation mostly
virtual void AddChild( wxWindowBase *child );
virtual void RemoveChild( wxWindowBase *child );
// looking for windows
// -------------------
// find window among the descendants of this one either by id or by
// name (return NULL if not found)
wxWindow *FindWindow( long id );
wxWindow *FindWindow( const wxString& name );
// implementation mostly
virtual void AddChild( wxWindowBase *child );
virtual void RemoveChild( wxWindowBase *child );
// Find a window among any window (all return NULL if not found)
static wxWindow *FindWindowById( long id, const wxWindow *parent = NULL );
static wxWindow *FindWindowByName( const wxString& name,
const wxWindow *parent = NULL );
static wxWindow *FindWindowByLabel( const wxString& label,
const wxWindow *parent = NULL );
// event handler stuff
// -------------------

View File

@ -102,11 +102,6 @@
// function protoypes
// ----------------------------------------------------------------------------
#if wxUSE_GUI
static wxWindow *wxFindWindowByLabel1(const wxString& title, wxWindow *parent);
static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow *parent);
#endif // wxUSE_GUI
// ============================================================================
// implementation
// ============================================================================
@ -491,52 +486,9 @@ wxString wxStripMenuCodes(const wxString& in)
wxWindow *
wxFindWindowByLabel (const wxString& title, wxWindow * parent)
{
if (parent)
{
return wxFindWindowByLabel1(title, parent);
}
else
{
for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
wxWindow *retwin = wxFindWindowByLabel1 (title, win);
if (retwin)
return retwin;
} // for()
}
return (wxWindow *) NULL;
return wxWindow::FindWindowByLabel( title, parent );
}
// Recursive
static wxWindow *
wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
{
if (parent)
{
if (parent->GetLabel() == title)
return parent;
}
if (parent)
{
for ( wxWindowList::Node * node = parent->GetChildren().GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = (wxWindow *)node->GetData();
wxWindow *retwin = wxFindWindowByLabel1 (title, win);
if (retwin)
return retwin;
}
}
return (wxWindow *) NULL; // Not found
}
/*
* If parent is non-NULL, look through children for a name
@ -545,54 +497,9 @@ wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
*/
wxWindow *
wxFindWindowByName (const wxString& title, wxWindow * parent)
wxFindWindowByName (const wxString& name, wxWindow * parent)
{
if (parent)
{
return wxFindWindowByName1 (title, parent);
}
else
{
for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
wxWindow *retwin = wxFindWindowByName1 (title, win);
if (retwin)
return retwin;
}
}
// Failed? Try by label instead.
return wxFindWindowByLabel(title, parent);
}
// Recursive
static wxWindow *
wxFindWindowByName1 (const wxString& title, wxWindow * parent)
{
if (parent)
{
if ( parent->GetName() == title )
return parent;
}
if (parent)
{
for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
{
wxWindow *win = (wxWindow *) node->Data ();
wxWindow *retwin = wxFindWindowByName1 (title, win);
if (retwin)
return retwin;
} // for()
}
return (wxWindow *) NULL; // Not found
return wxWindow::FindWindowByName( name, parent );
}
// Returns menu item id or -1 if none.

View File

@ -870,7 +870,7 @@ bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
}
// ----------------------------------------------------------------------------
// find window by id or name
// find child window by id or name
// ----------------------------------------------------------------------------
wxWindow *wxWindowBase::FindWindow( long id )
@ -905,6 +905,125 @@ wxWindow *wxWindowBase::FindWindow( const wxString& name )
return (wxWindow *)res;
}
// find any window by id or name or label: If parent is non-NULL, look through
// children for a label or title matching the specified string. If NULL, look
// through all top-level windows.
//
// to avoid duplicating code we reuse the same helper function but with
// different comparators
typedef bool (*wxFindWindowCmp)(const wxWindow *win,
const wxString& label, long id);
static
bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
long WXUNUSED(id))
{
return win->GetLabel() == label;
}
static
bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
long WXUNUSED(id))
{
return win->GetName() == label;
}
static
bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
long id)
{
return win->GetId() == id;
}
// recursive helper for the FindWindowByXXX() functions
static
wxWindow *wxFindWindowRecursively(const wxWindow *parent,
const wxString& label,
long id,
wxFindWindowCmp cmp)
{
if ( parent )
{
// see if this is the one we're looking for
if ( (*cmp)(parent, label, id) )
return (wxWindow *)parent;
// It wasn't, so check all its children
for ( wxWindowList::Node * node = parent->GetChildren().GetFirst();
node;
node = node->GetNext() )
{
// recursively check each child
wxWindow *win = (wxWindow *)node->GetData();
wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
if (retwin)
return retwin;
}
}
// Not found
return NULL;
}
// helper for FindWindowByXXX()
static
wxWindow *wxFindWindowHelper(const wxWindow *parent,
const wxString& label,
long id,
wxFindWindowCmp cmp)
{
if ( parent )
{
// just check parent and all its children
return wxFindWindowRecursively(parent, label, id, cmp);
}
// start at very top of wx's windows
for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
node;
node = node->GetNext() )
{
// recursively check each window & its children
wxWindow *win = node->GetData();
wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
if (retwin)
return retwin;
}
return NULL;
}
/* static */
wxWindow *
wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
{
return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
}
/* static */
wxWindow *
wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
{
wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
if ( !win )
{
// fall back to the label
win = FindWindowByLabel(title, parent);
}
return win;
}
/* static */
wxWindow *
wxWindowBase::FindWindowById( long id, const wxWindow* parent )
{
return wxFindWindowHelper(parent, _T(""), id, wxFindWindowCmpIds);
}
// ----------------------------------------------------------------------------
// dialog oriented functions
// ----------------------------------------------------------------------------