X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c67daf87774c71ae9f73af9969008af220e52a11..2a29700ecf3d6862db16c5f5c9086a698a7ff247:/src/generic/tabg.cpp diff --git a/src/generic/tabg.cpp b/src/generic/tabg.cpp index 433d3c1801..297d93d55e 100644 --- a/src/generic/tabg.cpp +++ b/src/generic/tabg.cpp @@ -31,6 +31,10 @@ #include "wx/tab.h" +// not defined: use old, square tab implementation (fills in tabs) +// defined: use new, rounded tab implementation (doesn't colour in tabs) +// #define wxUSE_NEW_METHOD + IMPLEMENT_DYNAMIC_CLASS(wxTabControl, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxTabLayer, wxList) @@ -39,7 +43,6 @@ wxTabControl::wxTabControl(wxTabView *v) { m_view = v; m_isSelected = FALSE; - m_labelFont = (wxFont *) NULL; m_offsetX = 0; m_offsetY = 0; m_width = 0; @@ -56,7 +59,7 @@ wxTabControl::~wxTabControl(void) void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) { // Old, but in some ways better (drawing opaque tabs) -#if 0 +#ifndef wxUSE_NEW_METHOD if (!m_view) return; @@ -70,23 +73,27 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) int tabHeightInc = 0; if (m_isSelected) { - tabHeightInc = (view->GetTabSelectionHeight() - view->GetTabHeight()); + tabHeightInc = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); tabY -= tabHeightInc; } - dc.SetPen(wxTRANSPARENT_PEN); + dc.SetPen(*wxTRANSPARENT_PEN); // Draw grey background - if (view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) + if (m_view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { - dc.SetBrush(m_view->GetBackgroundBrush()); + dc.SetBrush(*m_view->GetBackgroundBrush()); // Add 1 because the pen is transparent. Under Motif, may be different. +#ifdef __WXMOTIF__ + dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + tabHeightInc)); +#else dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc)); +#endif } // Draw highlight and shadow - dc.SetPen(m_view->GetHighlightPen()); + dc.SetPen(*m_view->GetHighlightPen()); // Calculate the top of the tab beneath. It's the height of the tab, MINUS // a bit if the tab below happens to be selected. Check. @@ -107,7 +114,7 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) dc.DrawLine(tabX, tabY, tabX, (tabY + GetHeight() + tabHeightInc - subtractThis)); dc.DrawLine(tabX, tabY, (tabX + GetWidth()), tabY); - dc.SetPen(m_view->GetShadowPen()); + dc.SetPen(*m_view->GetShadowPen()); // Test if we're outside the right-hand edge of the view area if (((tabX + GetWidth()) >= m_view->GetViewRect().x + m_view->GetViewRect().width) && (m_view->GetTabStyle() & wxTAB_STYLE_DRAW_BOX)) @@ -126,7 +133,7 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) (tabX + GetWidth()), (bottomY-1)); // Draw black line to emphasize shadow - dc.SetPen(wxBLACK_PEN); + dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), bottomY); @@ -145,13 +152,17 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) int maxPositions = ((wxTabLayer *)m_view->GetLayers().Nth(0)->Data())->Number(); // Only down to the bottom of the tab, not to the top of the view - if ( GetColPosition() < maxPositions ) + if ( GetRowPosition() < (maxPositions - 1) ) topY = tabY + GetHeight() + tabHeightInc; +#ifdef __WXMOTIF__ + topY -= 1; +#endif + // Shadow dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), topY); // Draw black line to emphasize shadow - dc.SetPen(wxBLACK_PEN); + dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), topY); } @@ -166,12 +177,16 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) if (tabBeneath && tabBeneath->IsSelected()) subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); +#ifdef __WXMOTIF__ + subtractThis += 1; +#endif + // Draw only to next tab down. dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc - subtractThis)); // Draw black line to emphasize shadow - dc.SetPen(wxBLACK_PEN); + dc.SetPen(*wxBLACK_PEN); dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), (tabY + GetHeight() + tabHeightInc - subtractThis)); } @@ -181,23 +196,27 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) int textY = tabY + m_view->GetVerticalTabTextSpacing() + tabHeightInc; if (m_isSelected) - dc.SetFont(m_view->GetSelectedTabFont()); + dc.SetFont(* m_view->GetSelectedTabFont()); else - dc.SetFont(GetFont()); + dc.SetFont(* GetFont()); wxColour col(m_view->GetTextColour()); - dc.SetTextForeground(&col); -// dc.SetTextForeground(&(m_view->GetTextColour())); + dc.SetTextForeground(col); dc.SetBackgroundMode(wxTRANSPARENT); - float textWidth, textHeight; + long textWidth, textHeight; 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) { - dc.SetPen(m_view->GetHighlightPen()); + dc.SetPen(*m_view->GetHighlightPen()); // Draw white highlight from the tab's left side to the left hand edge of the view dc.DrawLine(m_view->GetViewRect().x, (tabY + GetHeight() + tabHeightInc), @@ -207,10 +226,9 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) dc.DrawLine((tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc), m_view->GetViewRect().x + m_view->GetViewRect().width, (tabY + GetHeight() + tabHeightInc)); } -#endif +#else + // New HEL version with rounder tabs -// New HEL version with rounder tabs -#if 1 if (!m_view) return; int tabInc = 0; @@ -508,16 +526,20 @@ wxTabView::wxTabView(long style) m_shadowPen = wxGREY_PEN; m_backgroundPen = wxLIGHT_GREY_PEN; m_backgroundBrush = wxLIGHT_GREY_BRUSH; - m_tabFont = wxTheFontList->FindOrCreateFont(9, wxSWISS, wxNORMAL, wxNORMAL); - m_tabSelectedFont = wxTheFontList->FindOrCreateFont(9, wxSWISS, wxNORMAL, wxBOLD); + m_tabFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); + m_tabSelectedFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); m_window = (wxWindow *) NULL; } wxTabView::~wxTabView() { + ClearTabs(TRUE); } // Automatically positions tabs +// TODO: this should just add the tab to a list, and then +// a layout function (e.g. Realize) should be called when all tabs have been added. +// The view rect could easily change as the view window is resized. wxTabControl *wxTabView::AddTab(int id, const wxString& label, wxTabControl *existingTab) { // First, find which layer we should be adding to. @@ -573,14 +595,88 @@ wxTabControl *wxTabView::AddTab(int id, const wxString& label, wxTabControl *exi tabControl->SetSize(GetTabWidth(), GetTabHeight()); tabControl->SetId(id); tabControl->SetLabel(label); - tabControl->SetFont(GetTabFont()); + tabControl->SetFont(* GetTabFont()); tabLayer->Append(tabControl); m_noTabs ++; 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). +int wxTabView::GetTotalTabHeight() +{ + int minY = 0; + + 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->GetY() < minY) + minY = tab->GetY(); + + tabNode = tabNode->Next(); + } + layerNode = layerNode->Next(); + } + + return - minY; +} + void wxTabView::ClearTabs(bool deleteTabs) { wxNode *layerNode = m_layers.First(); @@ -602,8 +698,10 @@ void wxTabView::ClearTabs(bool deleteTabs) delete layerNode; layerNode = nextLayerNode; } + m_noTabs = 0; } - + + // Layout tabs (optional, e.g. if resizing window) void wxTabView::Layout(void) { @@ -688,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) { @@ -720,16 +822,16 @@ void wxTabView::Draw(wxDC& dc) } -#if 0 +#ifndef wxUSE_NEW_METHOD if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX) { - dc.SetPen(GetShadowPen()); + dc.SetPen(* GetShadowPen()); // Draw bottom line dc.DrawLine( (GetViewRect().x + 1), (GetViewRect().y + GetViewRect().height), - (GetViewRect().x + GetViewRect().width), + (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y + GetViewRect().height) ); @@ -741,13 +843,18 @@ void wxTabView::Draw(wxDC& dc) (GetViewRect().y + GetViewRect().height) ); - dc.SetPen(wxBLACK_PEN); + dc.SetPen(* wxBLACK_PEN); // Draw bottom line dc.DrawLine( (GetViewRect().x), (GetViewRect().y + GetViewRect().height + 1), - (GetViewRect().x + GetViewRect().width), +#if defined(__WXMOTIF__) + (GetViewRect().x + GetViewRect().width + 1), +#else + (GetViewRect().x + GetViewRect().width + 2), +#endif + (GetViewRect().y + GetViewRect().height + 1) ); @@ -919,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); @@ -1088,7 +1201,7 @@ void wxTabbedPanel::OnPaint(wxPaintEvent& WXUNUSED(event) ) } /* - * wxDialogTabView + * wxPanelTabView */ IMPLEMENT_CLASS(wxPanelTabView, wxTabView)