CeguiDotNet layout loading + event handlers


10-08-2006 22:28:29


I'm having trouble registering event handlers for objects on a layout loaded window

Let's say I created a FrameWindow with an Editbox named 'commandline'
Now I do the following to load the window :
mWindow = WM.LoadWindowLayout("consolewindow.layout");
Editbox commandline = (Editbox) mWindow.getChild("commandline");
commandline.KeyUp += new KeyEventDelegate(commandline_KeyUp);

I get an invalid cast exception on the second line. I understand that SWIG does not retain the hierarchy b/w class Window and Editbox.

My question is : Is there an easy way to get a correctly typed window ?

I guess the solution would be to build the typed window using construtors like Editbox(IntPtr cPtr, bool cMemoryOwn) but I don't know how to do it easily (meaning without meddling with SWIG interface files and rebuilding the wrapper)

Thank in advance
Any help appreciated



11-08-2006 10:31:09

Ok I found a solution. I use the static methods Window.getCPtr() to retrieve the object handle and then artificially create the subclassed object using that handle.
It works OK but it might get hard to debug if the real type of the native object is not the type of the c# object we're creating. A type change in the layout file *will* crash the application if the change is not done in the code.

mWindow = WM.LoadWindowLayout("consolewindow.layout");
commandline = (Editbox)new Editbox(Window.getCPtr(mWindow.getChild("commandline")).Handle, false);
commandline.KeyUp +=new KeyEventDelegate(commandline_KeyUp);
commandline.TextAccepted += new WindowEventDelegate(commandline_TextAccepted);
logbox = (StaticText)new StaticText(Window.getCPtr(mWindow.getChild("logbox")).Handle, false);
logbox.TextChanged +=new WindowEventDelegate(logbox_TextChanged);