]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/tabg.cpp
postscript Blit()
[wxWidgets.git] / src / generic / tabg.cpp
index 5adc584c4c8ba48386dcf83d19bc405d82636138..297d93d55e382a38195213ecb9dba2a90f79a742 100644 (file)
@@ -43,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;
@@ -86,7 +85,11 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
     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
@@ -152,6 +155,10 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
       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
@@ -170,6 +177,10 @@ 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));
@@ -185,9 +196,9 @@ 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);
@@ -196,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)
   {
@@ -510,13 +526,14 @@ 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
@@ -578,13 +595,61 @@ 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).
@@ -633,6 +698,7 @@ void wxTabView::ClearTabs(bool deleteTabs)
     delete layerNode;
     layerNode = nextLayerNode;
   }
+  m_noTabs = 0;
 }
 
 
@@ -720,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)
        {
@@ -755,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(
@@ -773,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),
+#if defined(__WXMOTIF__)
+                               (GetViewRect().x + GetViewRect().width + 1),
+#else
                                (GetViewRect().x + GetViewRect().width + 2),
+#endif
+
                                (GetViewRect().y + GetViewRect().height + 1)
                                );
 
@@ -951,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);