Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

wxAUI

<< < (6/7) > >>

Pecan:
you might also consider the following code. wxWindow::RemoveEventHandler()
depends on a valid window pointer. My experience says that stowed window
pointers become invalid quickly as CB opens/closes/destorys/deletes frames,
panels, list/tree ctrls etc...

I had to use if (winExists(p)) before calling p->RemoveEventHandler(thisorthat)
because "*p" may have disappeared along with its EventHanders.
If so, just do the delete thisorthat.

thanks
pecan


--- Code: ---// ----------------------------------------------------------------------------
wxWindow* wxKeyBinder::FindWindowRecursively(const wxWindow* parent, const wxWindow* handle)
// ----------------------------------------------------------------------------
{//+v0.4.4
    if ( parent )
    {
        // see if this is the one we're looking for
        if ( parent == handle )
            return (wxWindow *)parent;

        // It wasn't, so check all its children
        for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
              node;
              node = node->GetNext() )
        {
            // recursively check each child
            wxWindow *win = (wxWindow *)node->GetData();
            wxWindow *retwin = FindWindowRecursively(win, handle);
            if (retwin)
                return retwin;
        }
    }

    // Not found
    return NULL;
}
// ----------------------------------------------------------------------------
wxWindow* wxKeyBinder::winExists(wxWindow *parent)
// ----------------------------------------------------------------------------
{ //+v0.4.4

    if ( !parent )
    {
        return NULL;
    }

    // start at very top of wx's windows
    for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
          node;
          node = node->GetNext() )
    {
        // recursively check each window & its children
        wxWindow* win = node->GetData();
        wxWindow* retwin = FindWindowRecursively(win, parent);
        if (retwin)
            return retwin;
    }

    return NULL;
}
// ----------------------------------------------------------------------------


--- End code ---

280Z28:
There are several sections of wxAUI where recursive searching for windows might be good, but I haven't thought through them enough to be sure of myself in saying so. If you can say for sure that the parent window's ID is unique, then you could store the frame's ID and call the following in UnInit():


--- Code: ---//static wxWindow* FindWindowById(long id, wxWindow* parent = NULL)

wxWindow window = wxWindow::FindWindowById(m_frameid);
if ( window )
    window->RemoveEventHandler(this);

--- End code ---

And your findWindowRecursively function might look like this. It would work right for:

1) Any window with a unique ID.
2) Any child window with a unique ID up to parent's scope.

This is the key. If you can scope your calls or (if it's one of the main frames of the app) know that it's unique, this is good.


--- Code: ---wxWindow* FindWindowRecursively(wxWindow* parent, wxWindow* child)
{
    if ( !parent || !child )
        return NULL;
    return wxWindow::FindWindowById(child->GetId(), parent);
}

wxWindow* wxKeyBinder::winExists(wxWindow *parent)
{
    if ( !parent )
        return NULL;
    return wxWindow::FindWindowById(parent->GetId());
}

--- End code ---

Pecan:
When your *pointerToWindow has disappeared, you
cannot use it to do FindWindowById or any any FindXXX
calls to the wxWindow code. It'll get a segfault.

If you have stowd locally the address of the windows/frames
etc, my experience says it is unique. Its like a MSwnd handle.

The window id is unique also, according to the docs, but to
use it requires a valid wxWindow ptr, which, in many CB
situations is not the case. Especially for plugins that have
stowed windowPtrs in a local array.
I have had SO MANY stale window ptrs.

In order to Remove the EvtHandler and delete the instance,
ya gotta do it by wxWindow ptr. If the window is gone,
ya better find out before hand (before using the ptr.)
and just do the delete.

thanks
pecan



280Z28:

--- Quote from: Pecan on January 12, 2006, 07:28:49 pm ---When your *pointerToWindow has disappeared, you
cannot use it to do FindWindowById or any any FindXXX
calls to the wxWindow code. It'll get a segfault.

If you have stowd locally the address of the windows/frames
etc, my experience says it is unique. Its like a MSwnd handle.

The window id is unique also, according to the docs, but to
use it requires a valid wxWindow ptr, which, in many CB
situations is not the case. Especially for plugins that have
stowed windowPtrs in a local array.
I have had SO MANY stale window ptrs.

In order to Remove the EvtHandler and delete the instance,
ya gotta do it by wxWindow ptr. If the window is gone,
ya better find out before hand (before using the ptr.)
and just do the delete.

thanks
pecan

--- End quote ---

Why don't you just store an array of their IDs, and maybe the ID of a parent? So you can find the parent by ID, and then find children by ID. If you have the ID, it won't crash.

Michael:
Hello,

Just for info. It seems that soon wxAUI version 0.9.2 will be available :). From bwilliams:


--- Quote ---Next week I plan to put in a solid week and hopefully get 0.9.2 out by the end of next week. That is an optimistic estimate, because there are a few new features I'd like to code. Normally we prefer to do monthly, but I was distracted by another pressing need.

--- End quote ---

Best wishes,
Michael

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version