elipsis for oversized pane captions
authorBenjamin Williams <bwilliams@kirix.com>
Tue, 7 Nov 2006 15:40:23 +0000 (15:40 +0000)
committerBenjamin Williams <bwilliams@kirix.com>
Tue, 7 Nov 2006 15:40:23 +0000 (15:40 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43164 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/aui/auidemo.cpp
src/aui/dockart.cpp
src/aui/framemanager.cpp

index 5f4f7c3ca0dddc658864ed7204e31c0bffbe0a35..c9036eea9dc9c6edb3755f60f026408f2c7e677b 100644 (file)
@@ -815,12 +815,12 @@ MyFrame::MyFrame(wxWindow* parent,
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("test2")).Caption(wxT("Client Size Reporter")).
                   Bottom().Position(1).
-                  PinButton(true).CloseButton(true).MaximizeButton(true));
+                  CloseButton(true).MaximizeButton(true));
 
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("test3")).Caption(wxT("Client Size Reporter")).
                   Bottom().
-                  PinButton(true).CloseButton(true).MaximizeButton(true));
+                  CloseButton(true).MaximizeButton(true));
 
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("test4")).Caption(wxT("Pane Caption")).
@@ -833,12 +833,12 @@ MyFrame::MyFrame(wxWindow* parent,
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("test6")).Caption(wxT("Client Size Reporter")).
                   Right().Row(1).
-                  PinButton(true).CloseButton(true).MaximizeButton(true));
+                  CloseButton(true).MaximizeButton(true));
 
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("test7")).Caption(wxT("Client Size Reporter")).
                   Left().Layer(1).
-                  PinButton(true).CloseButton(true).MaximizeButton(true));
+                  CloseButton(true).MaximizeButton(true));
 
     m_mgr.AddPane(CreateTreeCtrl(), wxAuiPaneInfo().
                   Name(wxT("test8")).Caption(wxT("Tree Pane")).
@@ -1328,7 +1328,7 @@ void MyFrame::OnCreateSizeReport(wxCommandEvent& WXUNUSED(event))
     m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
                   Name(wxT("Test")).Caption(wxT("Client Size Reporter")).
                   Float().FloatingPosition(GetStartPosition()).
-                  PinButton(true).CloseButton(true).MaximizeButton(true));
+                  CloseButton(true).MaximizeButton(true));
     m_mgr.Update();
 }
 
index b1e4603b915c8cc528c4006064fe0f7e0d86481a..248f63b8a5a8c96e0c5446c1025d136c326626fe 100644 (file)
@@ -129,6 +129,34 @@ static void DrawGradientRectangle(wxDC& dc,
 
 }
 
+static wxString ChopText(wxDC& dc, const wxString& text, int max_size)
+{
+    wxCoord x,y;
+    
+    // first check if the text fits with no problems
+    dc.GetTextExtent(text, &x, &y);
+    if (x <= max_size)
+        return text;
+        
+    size_t i, len = text.Length();
+    size_t last_good_length = 0;
+    for (i = 0; i < len; ++i)
+    {
+        wxString s = text.Left(i);
+        s += wxT("...");
+        
+        dc.GetTextExtent(s, &x, &y);
+        if (x > max_size)
+            break;
+        
+        last_good_length = i;
+    }
+
+    wxString ret = text.Left(last_good_length);
+    ret += wxT("...");
+    return ret;
+}
+
 wxAuiDefaultDockArt::wxAuiDefaultDockArt()
 {
 #ifdef __WXMAC__
@@ -522,8 +550,20 @@ void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window),
     wxCoord w,h;
     dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);
 
-    dc.SetClippingRegion(rect);
-    dc.DrawText(text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
+    wxRect clip_rect = rect;
+    clip_rect.width -= 3; // text offset
+    clip_rect.width -= 2; // button padding
+    if (pane.HasCloseButton())
+        clip_rect.width -= m_button_size;
+    if (pane.HasPinButton())
+        clip_rect.width -= m_button_size;    
+    if (pane.HasMaximizeButton())
+        clip_rect.width -= m_button_size;    
+
+    wxString draw_text = ChopText(dc, text, clip_rect.width);
+
+    dc.SetClippingRegion(clip_rect);
+    dc.DrawText(draw_text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
     dc.DestroyClippingRegion();
 }
 
index 53345802dc604f3982d6262eb8d66c36ec409a07..bf0138345d6dfadae89dac5c57bc4cb6bef746e6 100644 (file)
@@ -834,7 +834,14 @@ bool wxAuiManager::AddPane(wxWindow* window, const wxAuiPaneInfo& pane_info)
         button.button_id = wxAUI_BUTTON_MAXIMIZE_RESTORE;
         pinfo.buttons.Add(button);
     }
-
+    
+    if (pinfo.HasPinButton())
+    {
+        wxAuiPaneButton button;
+        button.button_id = wxAUI_BUTTON_PIN;
+        pinfo.buttons.Add(button);
+    }
+    
     if (pinfo.HasCloseButton())
     {
         wxAuiPaneButton button;