]> git.saurik.com Git - wxWidgets.git/blobdiff - src/aui/auibook.cpp
compilation fix after operator==() removal
[wxWidgets.git] / src / aui / auibook.cpp
index e831f89b34f22807fb541a2ae3dcb05b41c4d4e2..d8e98c979a8db753cdf6aa01549004e0362349cf 100644 (file)
@@ -198,33 +198,27 @@ void wxDefaultTabArt::DrawTab(wxDC* dc,
 {
     wxCoord normal_textx, normal_texty;
     wxCoord selected_textx, selected_texty;
-    wxCoord measured_textx, measured_texty;
     wxCoord textx, texty;
-
-
+    
     // if the caption is empty, measure some temporary text
     wxString caption = caption_text;
     if (caption_text.empty())
         caption = wxT("Xj");
-        
-    // measure text
-    dc->SetFont(m_measuring_font);
-    dc->GetTextExtent(caption, &measured_textx, &measured_texty);
-
+            
     dc->SetFont(m_selected_font);
     dc->GetTextExtent(caption, &selected_textx, &selected_texty);
-
+    
     dc->SetFont(m_normal_font);
     dc->GetTextExtent(caption, &normal_textx, &normal_texty);
+        
+    // figure out the size of the tab
+    wxSize tab_size = GetTabSize(dc, caption, active, x_extent);
 
-    caption = caption_text;
-
-    wxCoord tab_height = measured_texty + 4;
-    wxCoord tab_width = measured_textx + tab_height + 5;
+    wxCoord tab_height = tab_size.y;
+    wxCoord tab_width = tab_size.x;
     wxCoord tab_x = in_rect.x;
     wxCoord tab_y = in_rect.y + in_rect.height - tab_height;
 
-
     // select pen, brush and font for the tab to be drawn
 
     if (active)
@@ -274,10 +268,9 @@ void wxDefaultTabArt::DrawTab(wxDC* dc,
 
     dc->DrawText(caption,
                  tab_x + (tab_height/3) + (tab_width/2) - (textx/2),
-                 tab_y + tab_height - texty - 2);
+                 (tab_y + tab_height)/2 - (texty/2) + 1);
 
     *out_rect = wxRect(tab_x, tab_y, tab_width, tab_height);
-    *x_extent = tab_width - (tab_height/2) - 1;
 }
 
 
@@ -348,12 +341,15 @@ void wxDefaultTabArt::DrawButton(
     
     if (orientation == wxLEFT)
     {
+        rect.SetX(in_rect.x);
+        rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2));
         rect.SetWidth(bmp.GetWidth());
         rect.SetHeight(bmp.GetHeight());
     }
      else
     {
-        rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), in_rect.y,
+        rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(),
+                      ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2),
                       bmp.GetWidth(), bmp.GetHeight());
     }
     
@@ -365,7 +361,14 @@ void wxDefaultTabArt::DrawButton(
 
 
 
-
+int wxDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd)
+{
+    wxClientDC dc(wnd);
+    dc.SetFont(m_measuring_font);
+    int x_ext = 0;
+    wxSize s = GetTabSize(&dc, wxT("ABCDEFGHIj"), true, &x_ext);
+    return s.y+3;
+}
 
 void wxDefaultTabArt::SetNormalFont(const wxFont& font)
 {
@@ -624,16 +627,25 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
     // find out if size of tabs is larger than can be
     // afforded on screen
     int total_width = 0;
-    
+    int visible_width = 0;
     for (i = 0; i < page_count; ++i)
     {
         wxAuiNotebookPage& page = m_pages.Item(i);
         int x_extent = 0;
         wxSize size = m_art->GetTabSize(&dc, page.caption, page.active, &x_extent);
+        
         if (i+1 < page_count)
             total_width += x_extent;
              else
             total_width += size.x;
+            
+        if (i >= m_tab_offset)
+        {
+            if (i+1 < page_count)
+                visible_width += x_extent;
+                 else
+                visible_width += size.x;
+        }
     }
     
     if (total_width > m_rect.GetWidth() - 20 || m_tab_offset != 0)
@@ -663,6 +675,26 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
         }
     }
 
+    // determine whether left button should be enabled
+    for (i = 0; i < button_count; ++i)
+    {
+        wxAuiTabContainerButton& button = m_buttons.Item(i);
+        if (button.id == wxAUI_BUTTON_LEFT)
+        {
+            if (m_tab_offset == 0)
+                button.cur_state |= wxAUI_BUTTON_STATE_DISABLED;
+                 else
+                button.cur_state &= ~wxAUI_BUTTON_STATE_DISABLED;
+        }
+        if (button.id == wxAUI_BUTTON_RIGHT)
+        {
+            if (visible_width < m_rect.GetWidth() - ((int)button_count*16))
+                button.cur_state |= wxAUI_BUTTON_STATE_DISABLED;
+                 else
+                button.cur_state &= ~wxAUI_BUTTON_STATE_DISABLED;
+        }
+    }
+
 
 
     // draw background
@@ -992,10 +1024,13 @@ void wxAuiTabCtrl::OnLeftUp(wxMouseEvent&)
         Refresh();
         Update();
 
-        wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, m_windowId);
-        evt.SetInt(m_hover_button->id);
-        evt.SetEventObject(this);
-        GetEventHandler()->ProcessEvent(evt);
+        if (!(m_hover_button->cur_state & wxAUI_BUTTON_STATE_DISABLED))
+        {
+            wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, m_windowId);
+            evt.SetInt(m_hover_button->id);
+            evt.SetEventObject(this);
+            GetEventHandler()->ProcessEvent(evt);
+        }
     }
 
     m_click_pt = wxDefaultPosition;
@@ -1271,11 +1306,7 @@ void wxAuiMultiNotebook::InitNotebook()
     m_selected_font.SetWeight(wxBOLD);
 
     // choose a default for the tab height
-    wxClientDC dc(this);
-    int tx, ty;
-    dc.SetFont(m_selected_font);
-    dc.GetTextExtent(wxT("ABCDEFGHhijklm"), &tx, &ty);
-    m_tab_ctrl_height = (ty*150)/100;
+    m_tab_ctrl_height = m_tabs.GetArtProvider()->GetBestTabCtrlSize(this);
 
     m_dummy_wnd = new wxWindow(this, wxID_ANY, wxPoint(0,0), wxSize(0,0));
     m_dummy_wnd->SetSize(200, 200);