/************************************************************************* Add a new tab *************************************************************************/ void TabControl::addTab(Window* wnd) { // abort attempts to add null window pointers, but log it for tracking. if (!wnd) { Logger::getSingleton().logEvent("Attempt to add null window pointer as " "tab to TabControl '" + getName() + "'. Ignoring!", Informative); return; } // Create a new TabButton addButtonForTabContent(wnd); // Add the window to the content pane getTabPane()->addChildWindow(wnd); // Auto-select? if (getTabCount() == 1) setSelectedTab(wnd->getName()); else // initialise invisible content wnd->setVisible(false); // when adding the 1st page, autosize tab pane height if (d_tabHeight.d_scale == 0 && d_tabHeight.d_offset == -1) d_tabHeight.d_offset = 8 + getFont()->getFontHeight (); // Just request redraw performChildWindowLayout(); invalidate(); // Subscribe to text changed event so that we can resize as needed d_eventConnections[wnd] = wnd->subscribeEvent(Window::EventTextChanged, Event::Subscriber(&TabControl::handleContentWindowTextChanged, this)); }
void TabControl::removeTab_impl(Window* window) { // silently abort if window to be removed is 0. if (!window) return; // delete connection to event we subscribed earlier d_eventConnections.erase(window); // Was this selected? bool reselect = window->isVisible(); // Tab buttons are the 2nd onward children getTabPane()->removeChildWindow(window); // remove button too removeButtonForTabContent(window); if (reselect && (getTabCount() > 0)) // Select another tab setSelectedTab(getTabPane()->getChildAtIdx(0)->getName()); performChildWindowLayout(); invalidate(); }
ChannelTabPane* ChatGuiBox::getOrCreateChannelPane( const ChatConnectionConfig& cfg, bool isSystemIO ) { // check if already have this pane ChannelTabPane* p_pane = getTabPane( cfg ); if ( p_pane ) return p_pane; // create new tab pane p_pane = new ChannelTabPane( _p_tabCtrl, this, isSystemIO ); p_pane->setTitle( cfg._protocol + " " + cfg._channel ); // append the new channel to list _tabpanes.push_back( std::make_pair( cfg, p_pane ) ); // register callback p_pane->setConfiguration( cfg ); cfg._p_protocolHandler->registerProtocolCallback( p_pane, cfg._channel ); // set tab selection to new created or exsiting pane p_pane->setSelection(); return p_pane; }
/************************************************************************* Layout the widgets *************************************************************************/ void TabControl::performChildWindowLayout() { Window* tabButtonPane = getTabButtonPane(); Window* tabContentPane = getTabPane(); // Enable top/bottom edges of the tabPane control, // if supported by looknfeel if (tabContentPane->isPropertyPresent (EnableTop)) tabContentPane->setProperty (EnableTop, (d_tabPanePos == Top) ? n0 : n1); if (tabContentPane->isPropertyPresent (EnableBottom)) tabContentPane->setProperty (EnableBottom, (d_tabPanePos == Top) ? n1 : n0); if (tabButtonPane->isPropertyPresent (EnableTop)) tabButtonPane->setProperty (EnableTop, (d_tabPanePos == Top) ? n0 : n1); if (tabButtonPane->isPropertyPresent (EnableBottom)) tabButtonPane->setProperty (EnableBottom, (d_tabPanePos == Top) ? n1 : n0); Window::performChildWindowLayout(); // Calculate the size & position of the tab scroll buttons Window *scrollLeftBtn = 0, *scrollRightBtn = 0; String name = getName() + ButtonScrollLeftSuffix; if (WindowManager::getSingleton().isWindowPresent (name)) scrollLeftBtn = WindowManager::getSingleton().getWindow (name); name = getName() + ButtonScrollRightSuffix; if (WindowManager::getSingleton().isWindowPresent (name)) scrollRightBtn = WindowManager::getSingleton().getWindow (name); // Calculate the positions and sizes of the tab buttons if (d_firstTabOffset > 0) d_firstTabOffset = 0; for (;;) { size_t i; for (i = 0; i < d_tabButtonVector.size (); ++i) calculateTabButtonSizePosition (i); if (d_tabButtonVector.empty ()) { if (scrollRightBtn) scrollRightBtn->setVisible (false); if (scrollLeftBtn) scrollLeftBtn->setVisible (false); break; } // Now check if tab pane wasn't scrolled too far --i; float xmax = d_tabButtonVector [i]->getXPosition ().d_offset + d_tabButtonVector [i]->getPixelSize ().d_width; float width = tabContentPane->getPixelSize ().d_width; // If right button margin exceeds right window margin, // or leftmost button is at offset 0, finish if ((xmax > (width - 0.5)) || (d_firstTabOffset == 0)) { if (scrollLeftBtn) scrollLeftBtn->setVisible (d_firstTabOffset < 0); if (scrollRightBtn) scrollRightBtn->setVisible (xmax > width); break; } // Scroll the tab pane until the rightmost button // touches the right margin d_firstTabOffset += width - xmax; // If we scrolled it too far, set leftmost button offset to 0 if (d_firstTabOffset > 0) d_firstTabOffset = 0; } }
/************************************************************************* Remove a tab by ID *************************************************************************/ void TabControl::removeTab(uint ID) { // do nothing if given window is not attached as a tab. if (getTabPane()->isChild(ID)) removeTab_impl(getTabPane()->getChild(ID)); }
/************************************************************************* Remove a tab *************************************************************************/ void TabControl::removeTab(const String& name) { // do nothing if given window is not attached as a tab. if (getTabPane()->isChild(name)) removeTab_impl(getTabPane()->getChild(name)); }
/************************************************************************* Make the tab by window name visible *************************************************************************/ void TabControl::makeTabVisible(const String &name) { makeTabVisible_impl(getTabPane()->getChild(name)); }
/************************************************************************* Make the tab by window ID visible *************************************************************************/ void TabControl::makeTabVisible(uint ID) { makeTabVisible_impl(getTabPane()->getChild(ID)); }
/************************************************************************* Set the selected tab by window ID *************************************************************************/ void TabControl::setSelectedTab(uint ID) { selectTab_impl(getTabPane()->getChild(ID)); }
/************************************************************************* Set the selected tab by window name *************************************************************************/ void TabControl::setSelectedTab(const String &name) { selectTab_impl(getTabPane()->getChild(name)); }
/************************************************************************* Get the tab at a given ID *************************************************************************/ Window* TabControl::getTabContents(uint ID) const { return getTabPane()->getChild(ID); }
/************************************************************************* Get the tab with a given name *************************************************************************/ Window* TabControl::getTabContents(const String& name) const { return getTabPane()->getChild(name); }
/************************************************************************* Get the number of tabs *************************************************************************/ size_t TabControl::getTabCount(void) const { return getTabPane()->getChildCount(); }