Page 1 of 1

[SOLVED] Custom widget constructor not being invoked

Posted: Wed May 23, 2007 17:37
by daves
I just tried to set a break point in my custom widget constructor. I'm using the code that levia posted here:

http://www.cegui.org.uk/wiki/index.php/ ... istboxItem

so my constructor looks like this:

Code: Select all

   CEGUI_DEFINE_WINDOW_FACTORY(CheckListboxItem)
   const String CheckListboxItem::WidgetTypeName("CEGUI/CheckListboxItem");
   CheckListboxItem::CheckListboxItem(const String &type, const String &name) :
            ItemEntry(type, name)
   {
      int i = 0;
   }


For some reason I see the ItemEntry constructor being invoked but not that of my custom widget.

at the application level I register the custom factory as follows:

Code: Select all

   CEGUI::WindowFactoryManager& wfMgr = CEGUI::WindowFactoryManager::getSingleton();
    wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(CheckListboxItem));
    wfMgr.addFalagardWindowMapping("WindowsLook/CheckListboxItem", "CEGUI/ItemEntry", "WindowsLook/CheckListboxItem", "Falagard/ItemEntry");


and then instantiate the widget as follows:

Code: Select all

CEGUI::CheckListboxItem * check = (CEGUI::CheckListboxItem*)wmgr.createWindow("WindowsLook/CheckListboxItem", "ckb");


I assumed that the constructor was being invoked because when I run my app I see a box containing a text item with a checkbox to the left of it. I assumed that because I saw the checkbox that the constructor must be called. But I'm thinking now that I see the checkbox next to the list item because of the looknfeel specification of the custom widget.

Why is my constructor not being called in direct response to the "createWindow"?

Edited with the following finding:



Hmm its the following call:

Code: Select all

wfMgr.addFalagardWindowMapping("WindowsLook/CheckListboxItem", "CEGUI/ItemEntry", "WindowsLook/CheckListboxItem", "Falagard/ItemEntry");


If I change it to this

Code: Select all

wfMgr.addFalagardWindowMapping("WindowsLook/CheckListboxItem", "CEGUI/CheckListboxItem", "WindowsLook/CheckListboxItem", "Falagard/ItemEntry");


then my constructor is called. Is one of these two methods wrong, or are they both reasonable depending on the nature of the custom widget?

Posted: Wed May 23, 2007 17:57
by Ludi
There's a small mistake in the article.

Have a look at this thread, nearly at the end: http://www.cegui.org.uk/phpBB2/viewtopic.php?t=2571

Posted: Wed May 23, 2007 19:15
by daves
Thanks for the pointer. Did you ever work through the other issues that you highlighted within that thread?

Posted: Wed May 23, 2007 20:17
by Ludi
What other issue do you mean?