+// Is the tab visible?
+bool wxAuiTabContainer::IsTabVisible(int tabPage, int tabOffset, wxDC* dc, wxWindow* wnd)
+{
+ if (!dc || !dc->IsOk())
+ return false;
+
+ size_t i;
+ size_t page_count = m_pages.GetCount();
+ size_t button_count = m_buttons.GetCount();
+
+ // Hasn't been rendered yet; assume it's visible
+ if (m_tab_close_buttons.GetCount() < page_count)
+ return true;
+
+ // First check if both buttons are disabled - if so, there's no need to
+ // check further for visibility.
+ int arrowButtonVisibleCount = 0;
+ for (i = 0; i < button_count; ++i)
+ {
+ wxAuiTabContainerButton& button = m_buttons.Item(i);
+ if (button.id == wxAUI_BUTTON_LEFT ||
+ button.id == wxAUI_BUTTON_RIGHT)
+ {
+ if ((button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) == 0)
+ arrowButtonVisibleCount ++;
+ }
+ }
+
+ // Tab must be visible
+ if (arrowButtonVisibleCount == 0)
+ return true;
+
+ // If tab is less than the given offset, it must be invisible by definition
+ if (tabPage < tabOffset)
+ return false;
+
+ // draw buttons
+ int left_buttons_width = 0;
+ int right_buttons_width = 0;
+
+ int offset = 0;
+
+ // calculate size of the buttons on the right side
+ offset = m_rect.x + m_rect.width;
+ for (i = 0; i < button_count; ++i)
+ {
+ wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1);
+
+ if (button.location != wxRIGHT)
+ continue;
+ if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN)
+ continue;
+
+ offset -= button.rect.GetWidth();
+ right_buttons_width += button.rect.GetWidth();
+ }
+
+ offset = 0;
+
+ // calculate size of the buttons on the left side
+ for (i = 0; i < button_count; ++i)
+ {
+ wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1);
+
+ if (button.location != wxLEFT)
+ continue;
+ if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN)
+ continue;
+
+ offset += button.rect.GetWidth();
+ left_buttons_width += button.rect.GetWidth();
+ }
+
+ offset = left_buttons_width;
+
+ if (offset == 0)
+ offset += m_art->GetIndentSize();
+
+ wxRect active_rect;
+
+ wxRect rect = m_rect;
+ rect.y = 0;
+ rect.height = m_rect.height;
+
+ // See if the given page is visible at the given tab offset (effectively scroll position)
+ for (i = tabOffset; i < page_count; ++i)
+ {
+ wxAuiNotebookPage& page = m_pages.Item(i);
+ wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(i);
+
+ rect.x = offset;
+ rect.width = m_rect.width - right_buttons_width - offset - 2;
+
+ if (rect.width <= 0)
+ return false; // haven't found the tab, and we've run out of space, so return false
+
+ int x_extent = 0;
+ wxSize size = m_art->GetTabSize(*dc,
+ wnd,
+ page.caption,
+ page.bitmap,
+ page.active,
+ tab_button.cur_state,
+ &x_extent);
+
+ offset += x_extent;
+
+ if (i == (size_t) tabPage)
+ {
+ // If not all of the tab is visible, and supposing there's space to display it all,
+ // we could do better so we return false.
+ if (((m_rect.width - right_buttons_width - offset - 2) <= 0) && ((m_rect.width - right_buttons_width - left_buttons_width) > x_extent))
+ return false;
+ else
+ return true;
+ }
+ }
+
+ // Shouldn't really get here, but if it does, assume the tab is visible to prevent
+ // further looping in calling code.
+ return true;
+}
+
+// Make the tab visible if it wasn't already
+void wxAuiTabContainer::MakeTabVisible(int tabPage, wxWindow* win)
+{
+ wxClientDC dc(win);
+ if (!IsTabVisible(tabPage, GetTabOffset(), & dc, win))
+ {
+ int i;
+ for (i = 0; i < (int) m_pages.GetCount(); i++)
+ {
+ if (IsTabVisible(tabPage, i, & dc, win))
+ {
+ SetTabOffset(i);
+ win->Refresh();
+ return;
+ }
+ }
+ }
+}