#include #include extern "C" { #include } TabView::TabView() : View(), m_numberOfTabs(0), m_activeTabIndex(-1), m_selectedTabIndex(-1) { } int TabView::numberOfTabs() const { return m_numberOfTabs; } void TabView::drawRect(KDContext * ctx, KDRect rect) const { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); // Draw a separator with the content ctx->fillRect(KDRect(0, height-k_activeTabHeight, width, k_activeTabHeight), KDColorWhite); } void TabView::addTab(ViewController * controller) { assert(m_numberOfTabs < k_maxNumberOfTabs); uint8_t tabIndex = m_numberOfTabs; m_cells[tabIndex].setNamedController(controller); m_numberOfTabs++; markRectAsDirty(bounds()); } void TabView::setActiveIndex(int index) { assert(index < m_numberOfTabs); if (m_activeTabIndex == index) { return; } if (m_activeTabIndex >= 0) { m_cells[m_activeTabIndex].setActive(false); } m_activeTabIndex = index; m_cells[m_activeTabIndex].setActive(true); } void TabView::setSelectedIndex(int index) { assert(index < m_numberOfTabs); if (m_selectedTabIndex == index) { return; } if (m_selectedTabIndex >= 0) { m_cells[m_selectedTabIndex].setSelected(false); } m_selectedTabIndex = index; if (m_selectedTabIndex >= 0) { m_cells[m_selectedTabIndex].setSelected(true); } } int TabView::numberOfSubviews() const { return m_numberOfTabs; } View * TabView::subviewAtIndex(int index) { assert(index < m_numberOfTabs); return &m_cells[index]; } void TabView::layoutSubviews() { KDCoordinate emptyWidth = bounds().width(); for (int i=0; i