View previous topic :: View next topic |
Author |
Message |
mwarning
Joined: 01 Apr 2007 Posts: 56
|
Posted: Sat Mar 08, 2008 10:20 am Post subject: get instance back from gtk.Notebook |
|
|
I use a gtk.Notebook and .appendPage to add some class instance (MyClass : HBox { /**/})
to be displayed.
When I use "uint i = nb.getCurrentPage(); auto mybox = nb.getNthPage(i);" I can't cast it back to MyClass.
In the implementation I see that instead of the MyClass pointer, the .getWidgetStruct
is called and stored instead in the background. And this is what is returned by .getNthPage (wrapped in a Widget instance).
So I guess it's not possible to get the original instance back.
Do I have to maintain my own storage for MyClass instances?
Or is there another way to do it? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Mar 09, 2008 10:10 am Post subject: |
|
|
You can store a pointer to your class using GObject.setData.
Code: | class MyBox : HBox
{
this(int i)
{
....
setData("MyBox", cast(void*)this);
}
} |
and
Code: | MyBox mybox = cast(MyBox)nb.getNthPage(i).getData("MyBox"); |
this worked in the small test i did. |
|
Back to top |
|
|
mwarning
Joined: 01 Apr 2007 Posts: 56
|
Posted: Sun Mar 09, 2008 6:37 pm Post subject: |
|
|
Thanks, nice idea |
|
Back to top |
|
|
|