FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

get instance back from gtk.Notebook

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Sat Mar 08, 2008 10:20 am    Post subject: get instance back from gtk.Notebook Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Mar 09, 2008 10:10 am    Post subject: Reply with quote

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
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Sun Mar 09, 2008 6:37 pm    Post subject: Reply with quote

Thanks, nice idea
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group