Page 1 of 1

[SOLVED] H: Can not getUserData() from the current Tab.

Posted: Mon Mar 02, 2009 00:39
by Van
CEGUI: 0.6.2

How does one get their user data and ID from a tab they created?

This does NOT work:

Code: Select all


...

   mLastTabNumber++;
   mNewTabItem->TabNumber = mLastTabNumber;

...

   // Create the new TAB
   mNewTabItem->TabWindow = ( CEGUI::DefaultWindow *) CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow", mTemp );
   mTabControl->addTab( mNewTabItem->TabWindow );
   mNewTabItem->TabWindow->setFont( mNewTabItem->Font );
   mNewTabItem->TabWindow->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.0f, 0.0f ), CEGUI::UDim( 0.0f, 0.0f ) ) );
   mNewTabItem->TabWindow->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0.0f ), CEGUI::UDim( 1.0f, 0.0f ) ) );
   mNewTabItem->TabWindow->setText( mTabName );
   mNewTabItem->TabWindow->setUserData( mNewTabItem );
   mNewTabItem->TabWindow->setID( mNewTabItem->TabNumber );

...



and then when the CEGUI::TabControl fires off the EventSelectionChanged event...

Code: Select all


bool clsGUIChat::event_TabControl_TabChange(const CEGUI::EventArgs& e)
{
   // Get the current tab from the tab control.
   CEGUI::Window *mTabWindow = mTabControl->getActiveChild();
   if ( !mTabWindow || mTabWindow->getID() < 1 ) return true;

   // Can this tab be deleted?
   if ( mTabWindow->getID() == 1 )
      mPopupMenu[ PUM_MAIN ]->getChild( "Chat/PopupMenu/Tab/Delete" )->setEnabled( false );
   else
      mPopupMenu[ PUM_MAIN ]->getChild( "Chat/PopupMenu/Tab/Delete" )->setEnabled( true );   // Default

   // Update current Tab Item and Fonts.
   mCurrentTabItem = (tTabItem *) mTabWindow->getUserData();
   if ( mCurrentTabItem )
   {
      setTabFont( mCurrentTabItem, mCurrentTabItem->Font );
      refreshTabFonts();
   } // mCurrentTabItem?
   return true;
} // event_TabControl_TabChange



mTabWindow->getID() < 1 fails. Refer to this line when the tab is created: mNewTabItem->TabWindow->setID( mNewTabItem->TabNumber );

So, how can I do a getUserData() so I can get my data that I assigned way back up in mNewTabItem->TabWindow->setUserData( mNewTabItem );

It appears that the window being returned to me as the current tab is not really the window I created.

Posted: Mon Mar 02, 2009 09:17
by scriptkid
Hi,

i have no compiled code at hands, but some questions/suggestions. Can you verify that the ActiveChild is equal to the window inside the event:

Code: Select all

Window* eventWindow = static_cast<const WindowEventArgs&>(e).window;

if (eventWindow->GetName() == mTabControl->getActiveChild()->GetName()
{
  // Equal ...
}


Also, but this might be a dull question. Did you initialize your mLastTabNumber item correctly? Maybe it has a bogus (negative) value?

HTH.

Posted: Mon Mar 02, 2009 10:29
by Van
Yes, mLastTabNumber is fine. When I step through the code the numbers are valid (we started with 1 - zero is invalid) .

I added the WindowEventArgs that you suggested and eventWindow does NOT equal getActiveChild.

As I stepped through the code I drilled down into the mTabControl and I did see my windows attached to the first child of mTabControl however, none of the children of mTabControl represent the window I created. So, CEGUI is definitely creating some auto windows.

Posted: Mon Mar 02, 2009 10:47
by Van
OK, Solved it..

The proper way to get the active (or any) tab window from a tab control:

Code: Select all


   // Get the current tab from the tab control.
   CEGUI::Window *mTabWindow = mTabControl->getTabContentsAtIndex( mTabControl->getSelectedTabIndex() );



use CEGUI::TabControl::getTabContentsAtIndex()