Page 1 of 1
Enable/disable tabs
Posted: Fri Apr 06, 2007 20:57
by LennyH
The behavior I would most like is to be able to disable and enable tab buttons of a tab control. For instance, there could be cases where you have a tab control with multiple tab pages, but you only want the user to access another tab page with proper requirements met.
There does not appear to be ability to do this?
A 'fake' way of doing it might be adding/removing the tabs as needed. However, after removing/adding the same tab multiple times, it will eventually give an alreadyexists exception.
So, any thoughts?
Posted: Sat Apr 07, 2007 14:12
by Rackle
You could "find" the button widget that is used to switch from one pane to the other and disable it. Going through the addTab() code within src/elements/CeguiTabControl.cpp:makeButtonName() indicates that the name of the button is:
Code: Select all
String buttonName = getTabButtonPane()->getName();
buttonName.append(TabButtonNameSuffix);
size_t pathEndPos = wnd->getName().find_last_of("/");
buttonName.append(wnd->getName().substr(pathEndPos == String::npos ? 0 : pathEndPos + 1));
Or if you know the handle of the tab pane you could use getButtonForTabContents() to retrieve the TabButton directly.
Or you can recursively iterate through the TabControl's children until you find one that contains the TabButtonNameSuffix tag and is of type TabButton.
At work we trap the "a widget is being modified" event and disable every tab except the current one (which contains the widget being modified) and then reactivate the other tabs when the user cancels or saves. One day I'll write a Cegui function that mimics that behavior, something along the lines of:
Code: Select all
void setTabButtons(const CEGUI::TabControl* pTabControl, const CEGUI::String& pTabButtonName, const bool& pEnable)
{
for(iterator = first_tab_button; iterator != last_tab_button; iterator++)
{
if( (*iterator).compare(pTabButtonName) != 0 )
{
windowManager.setWindowEnable( (*iterator), pEnable);
}
}
}
I see that as an extension of what you are seeking.
Posted: Mon Apr 09, 2007 17:00
by LennyH
Using getTabButtonForTabContents is what I was wanting to use before, but it's protected. How would I get the handle to the tab pane? If I had that, I would then be able to get the buttons, and subsequently set the enabled value to true or false?
Posted: Mon Apr 09, 2007 21:26
by Rackle
The name of the tab button is generated from a formula based on the TabControl name. Bypass everything and go that way...or recursively display the name of every child of that TabControl until you find the one that makes sense then use getWindow("name of the tab button")->setEnabled(false).
Maybe I'll have some Cegui time this week and provide the complete answer.
Posted: Tue Apr 10, 2007 17:10
by LennyH
Sorry if it seems like I am looking for a complete answer. It's not that, it's just that this would be a 'nice to have' before the next deadline, but it's not vital either. I don't really have the time to spend going through the code of CEGUI itself. Combined with me being a little flabbergasted that this basic functionality is not already exposed through a function ( but, it's not completely reasonable to expect anybody to foresee the needs of the users, either ) makes me a little ancy.
I do realize I can use get window to get it from the CEGUI system; but as you said, the name is generated, and I don't have the time to go hunting for that...not for this delivery anyway. I'll keep this thread under my hat, and it'll probably be a future enhancement.
Thanks for the help.
Posted: Tue Apr 10, 2007 18:29
by Rackle
Here's the snippet you need to go through the children of the tab control.
Code: Select all
void processChildren(CEGUI::Window* pWindow)
{
for(size_t childIdx = 0;
childIdx < pWindow>getChildCount();
childIdx++)
{
DISPLAY WINDOW NAME OF: pWindow->getChildAtIdx(childIdx)->getName();
processChildren(pWindow->getChildAtIdx(childIdx));
}
}
You'd call it with the pointer to the TabControl window and somehow display the name of each child, or send it to the log file. It should be pretty easy to find the proper window name and derive the button name, which is based on the tab control name, a constant name, and the name of the button (I think).