X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/028003016290b62becb31873c38a202d6e61eec4..105e45b9d02d7e9ed10923957ae1ce60c037273d:/src/generic/tabg.cpp diff --git a/src/generic/tabg.cpp b/src/generic/tabg.cpp index fe7590fd50..297d93d55e 100644 --- a/src/generic/tabg.cpp +++ b/src/generic/tabg.cpp @@ -207,7 +207,12 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) dc.GetTextExtent(GetLabel(), &textWidth, &textHeight); int textX = (int)(tabX + (GetWidth() - textWidth)/2.0); + if (textX < (tabX + 2)) + textX = (tabX + 2); + + dc.SetClippingRegion(tabX, tabY, GetWidth(), GetHeight()); dc.DrawText(GetLabel(), textX, textY); + dc.DestroyClippingRegion(); if (m_isSelected) { @@ -597,6 +602,54 @@ wxTabControl *wxTabView::AddTab(int id, const wxString& label, wxTabControl *exi return tabControl; } + +// Remove the tab without deleting the window +bool wxTabView::RemoveTab(int id) +{ + wxNode *layerNode = m_layers.First(); + while (layerNode) + { + wxTabLayer *layer = (wxTabLayer *)layerNode->Data(); + wxNode *tabNode = layer->First(); + while (tabNode) + { + wxTabControl *tab = (wxTabControl *)tabNode->Data(); + if (tab->GetId() == id) + { + if (id == m_tabSelection) + m_tabSelection = -1; + delete tab; + delete tabNode; + m_noTabs --; + + // The layout has changed + Layout(); + return TRUE; + } + tabNode = tabNode->Next(); + } + layerNode = layerNode->Next(); + } + return FALSE; +} + +bool wxTabView::SetTabText(int id, const wxString& label) +{ + wxTabControl* control = FindTabControlForId(id); + if (!control) + return FALSE; + control->SetLabel(label); + return TRUE; +} + +wxString wxTabView::GetTabText(int id) const +{ + wxTabControl* control = FindTabControlForId(id); + if (!control) + return wxEmptyString; + else + return control->GetLabel(); +} // Returns the total height of the tabs component -- this may be several // times the height of a tab, if there are several tab layers (rows). @@ -645,6 +698,7 @@ void wxTabView::ClearTabs(bool deleteTabs) delete layerNode; layerNode = nextLayerNode; } + m_noTabs = 0; } @@ -732,6 +786,10 @@ void wxTabView::Layout(void) // Draw all tabs void wxTabView::Draw(wxDC& dc) { + // Don't draw anything if there are no tabs. + if (GetNumberOfTabs() == 0) + return; + // Draw top margin area (beneath tabs and above view area) if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { @@ -767,7 +825,7 @@ void wxTabView::Draw(wxDC& dc) #ifndef wxUSE_NEW_METHOD if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX) { - dc.SetPen(GetShadowPen()); + dc.SetPen(* GetShadowPen()); // Draw bottom line dc.DrawLine( @@ -785,7 +843,7 @@ void wxTabView::Draw(wxDC& dc) (GetViewRect().y + GetViewRect().height) ); - dc.SetPen(wxBLACK_PEN); + dc.SetPen(* wxBLACK_PEN); // Draw bottom line dc.DrawLine( @@ -968,20 +1026,26 @@ void wxTabView::SetTabSelection(int sel, bool activateTool) { int oldSel = m_tabSelection; wxTabControl *control = FindTabControlForId(sel); + wxTabControl *oldControl = FindTabControlForId(m_tabSelection); if (!OnTabPreActivate(sel, oldSel)) return; if (control) - control->SetSelected((sel != 0)); // TODO ?? - else + control->SetSelected((sel != -1)); // TODO ?? + else if (sel != -1) { - wxMessageBox(_("Could not find tab for id"), _("Error"), wxOK); + wxFAIL_MSG(_("Could not find tab for id")); return; } + + if (oldControl) + oldControl->SetSelected(FALSE); m_tabSelection = sel; - MoveSelectionTab(control); + + if (control) + MoveSelectionTab(control); if (activateTool) OnTabActivate(sel, oldSel);