]> git.saurik.com Git - wxWidgets.git/commitdiff
Improve wxAuiNotebook appearance when using some GTK themes.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 8 Oct 2012 12:09:13 +0000 (12:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 8 Oct 2012 12:09:13 +0000 (12:09 +0000)
Let wxAuiNotebook render the border itself, instead of doing it in dock art
class. This allows the notebook to do it correctly for the current theme.

Closes #14710.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72641 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/aui/tabart.h
include/wx/aui/tabartgtk.h
src/aui/auibook.cpp
src/aui/dockart.cpp
src/aui/tabart.cpp
src/aui/tabartgtk.cpp

index 329d6bbb26d32b8c1a94f8a442d7359f0c70325b..12621771a62e45a7d77c88c782026dcb872e1cf6 100644 (file)
@@ -56,6 +56,11 @@ public:
     virtual void SetColour(const wxColour& colour) = 0;
     virtual void SetActiveColour(const wxColour& colour) = 0;
 
+    virtual void DrawBorder(
+                 wxDC& dc,
+                 wxWindow* wnd,
+                 const wxRect& rect) = 0;
+
     virtual void DrawBackground(
                          wxDC& dc,
                          wxWindow* wnd,
@@ -95,6 +100,9 @@ public:
 
     virtual int GetIndentSize() = 0;
 
+    virtual int GetBorderWidth(
+                         wxWindow* wnd) = 0;
+
     virtual int GetBestTabCtrlSize(
                          wxWindow* wnd,
                          const wxAuiNotebookPageArray& pages,
@@ -121,6 +129,11 @@ public:
     void SetColour(const wxColour& colour);
     void SetActiveColour(const wxColour& colour);
 
+    void DrawBorder(
+                 wxDC& dc,
+                 wxWindow* wnd,
+                 const wxRect& rect);
+
     void DrawBackground(
                  wxDC& dc,
                  wxWindow* wnd,
@@ -146,6 +159,9 @@ public:
 
     int GetIndentSize();
 
+    int GetBorderWidth(
+                 wxWindow* wnd);
+
     wxSize GetTabSize(
                  wxDC& dc,
                  wxWindow* wnd,
@@ -209,6 +225,11 @@ public:
     void SetColour(const wxColour& colour);
     void SetActiveColour(const wxColour& colour);
 
+    void DrawBorder(
+                 wxDC& dc,
+                 wxWindow* wnd,
+                 const wxRect& rect);
+
     void DrawBackground(
                  wxDC& dc,
                  wxWindow* wnd,
@@ -234,6 +255,9 @@ public:
 
     int GetIndentSize();
 
+    int GetBorderWidth(
+                 wxWindow* wnd);
+
     wxSize GetTabSize(
                  wxDC& dc,
                  wxWindow* wnd,
index 25f1447d910f359539467f4250d1db8957b7662a..b094082d81ea3ce41bdcdc74ef3a1d57adc7192b 100644 (file)
@@ -33,6 +33,7 @@ public:
     wxAuiGtkTabArt();
 
     virtual wxAuiTabArt* Clone();
+    virtual void DrawBorder(wxDC& dc, wxWindow* wnd, const wxRect& rect);
     virtual void DrawBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect);
     virtual void DrawTab(wxDC& dc,
                          wxWindow* wnd,
@@ -46,6 +47,7 @@ public:
                     int button_state, int orientation, wxRect* out_rect);
     int GetBestTabCtrlSize(wxWindow* wnd, const wxAuiNotebookPageArray& pages,
                             const wxSize& required_bmp_size);
+    int GetBorderWidth(wxWindow* wnd);
     virtual wxSize GetTabSize(wxDC& dc, wxWindow* wnd, const wxString& caption,
                               const wxBitmap& bitmap, bool active,
                               int close_button_state, int* x_extent);
index 4a2596f52bcc915576b137cb6b2ec4fbb58fd050..402724309bbfe8867754ed216531fae171e09992 100644 (file)
@@ -1543,7 +1543,10 @@ public:
 
         for (i = 0; i < page_count; ++i)
         {
-            int height = m_rect.height - m_tabCtrlHeight;
+            wxAuiNotebookPage& page = pages.Item(i);
+            int border_width = m_tabs->GetArtProvider()->GetBorderWidth(page.window);
+
+            int height = m_rect.height - m_tabCtrlHeight - border_width;
             if ( height < 0 )
             {
                 // avoid passing negative height to wxWindow::SetSize(), this
@@ -1551,15 +1554,19 @@ public:
                 height = 0;
             }
 
-            wxAuiNotebookPage& page = pages.Item(i);
             if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM)
             {
-                page.window->SetSize(m_rect.x, m_rect.y, m_rect.width, height);
+                page.window->SetSize(m_rect.x + 2 * border_width,
+                                     m_rect.y + 2 *  border_width,
+                                     m_rect.width - 4 * border_width,
+                                     height);
             }
             else //TODO: if (GetFlags() & wxAUI_NB_TOP)
             {
-                page.window->SetSize(m_rect.x, m_rect.y + m_tabCtrlHeight,
-                                     m_rect.width, height);
+                page.window->SetSize(m_rect.x + 2 * border_width,
+                                     m_rect.y + m_tabCtrlHeight,
+                                     m_rect.width - 4 * border_width,
+                                     height);
             }
             // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
             // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
index c25509122c1ceaa9f9f98e8dd1e4cfdcfa74e699..8187939b028984f9039636d238bc6c56955c00cc 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "wx/aui/framemanager.h"
 #include "wx/aui/dockart.h"
+#include "wx/aui/auibook.h"
+#include "wx/aui/tabart.h"
 
 #ifndef WX_PRECOMP
     #include "wx/settings.h"
@@ -466,7 +468,7 @@ void wxAuiDefaultDockArt::DrawBackground(wxDC& dc, wxWindow *WXUNUSED(window), i
     dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
 }
 
-void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow *WXUNUSED(window), const wxRect& _rect,
+void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow* window, const wxRect& _rect,
                                   wxAuiPaneInfo& pane)
 {
     dc.SetPen(m_borderPen);
@@ -492,10 +494,21 @@ void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow *WXUNUSED(window), const
     }
     else
     {
-        for (i = 0; i < border_width; ++i)
+        // notebooks draw the border themselves, so they can use native rendering (e.g. tabartgtk)
+        wxAuiTabArt* art = 0;
+        wxAuiNotebook* nb = wxDynamicCast(window, wxAuiNotebook);
+        if (nb)
+            art = nb->GetArtProvider();
+
+        if (art)
+            art->DrawBorder(dc, window, rect);
+        else
         {
-            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
-            rect.Deflate(1);
+            for (i = 0; i < border_width; ++i)
+            {
+                dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
+                rect.Deflate(1);
+            }
         }
     }
 }
index 068070dff29d90e7169df63546755490f51b2d67..62c6c5f9ddfa46ccb9678d64e94872dcf66ab7b5 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "wx/renderer.h"
 #include "wx/aui/auibook.h"
+#include "wx/aui/framemanager.h"
+#include "wx/aui/dockart.h"
 
 #ifdef __WXMAC__
 #include "wx/osx/private.h"
@@ -244,6 +246,18 @@ void wxAuiGenericTabArt::SetSizingInfo(const wxSize& tab_ctrl_size,
 }
 
 
+void wxAuiGenericTabArt::DrawBorder(wxDC& dc, wxWindow* wnd, const wxRect& rect)
+{
+    int i, border_width = GetBorderWidth(wnd);
+
+    wxRect theRect(rect);
+    for (i = 0; i < border_width; ++i)
+    {
+        dc.DrawRectangle(theRect.x, theRect.y, theRect.width, theRect.height);
+        theRect.Deflate(1);
+    }
+}
+
 void wxAuiGenericTabArt::DrawBackground(wxDC& dc,
                                         wxWindow* WXUNUSED(wnd),
                                         const wxRect& rect)
@@ -584,6 +598,18 @@ int wxAuiGenericTabArt::GetIndentSize()
     return 5;
 }
 
+int wxAuiGenericTabArt::GetBorderWidth(wxWindow* wnd)
+{
+    wxAuiManager* mgr = wxAuiManager::GetManager(wnd);
+    if (mgr)
+    {
+       wxAuiDockArt*  art = mgr->GetArtProvider();
+        if (art)
+            return art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
+    }
+    return 1;
+}
+
 wxSize wxAuiGenericTabArt::GetTabSize(wxDC& dc,
                                       wxWindow* WXUNUSED(wnd),
                                       const wxString& caption,
@@ -908,6 +934,18 @@ void wxAuiSimpleTabArt::SetActiveColour(const wxColour& colour)
     m_selectedBkPen = wxPen(colour);
 }
 
+void wxAuiSimpleTabArt::DrawBorder(wxDC& dc, wxWindow* wnd, const wxRect& rect)
+{
+    int i, border_width = GetBorderWidth(wnd);
+
+    wxRect theRect(rect);
+    for (i = 0; i < border_width; ++i)
+    {
+        dc.DrawRectangle(theRect.x, theRect.y, theRect.width, theRect.height);
+        theRect.Deflate(1);
+    }
+}
+
 void wxAuiSimpleTabArt::DrawBackground(wxDC& dc,
                                        wxWindow* WXUNUSED(wnd),
                                        const wxRect& rect)
@@ -1087,6 +1125,18 @@ int wxAuiSimpleTabArt::GetIndentSize()
     return 0;
 }
 
+int wxAuiSimpleTabArt::GetBorderWidth(wxWindow* wnd)
+{
+    wxAuiManager* mgr = wxAuiManager::GetManager(wnd);
+    if (mgr)
+    {
+       wxAuiDockArt*  art = mgr->GetArtProvider();
+        if (art)
+            return art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
+    }
+    return 1;
+}
+
 wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc,
                                      wxWindow* WXUNUSED(wnd),
                                      const wxString& caption,
index 5c2bfb417f5e6b2c9299b1a41563a502c08153b2..28bfaa6aafbf6851f8235ad82826c61a3f38fee3 100644 (file)
@@ -79,6 +79,23 @@ void wxAuiGtkTabArt::DrawBackground(wxDC& dc, wxWindow* WXUNUSED(wnd), const wxR
                                        rect.x, rect.y, rect.width, rect.height);
 }
 
+void wxAuiGtkTabArt::DrawBorder(wxDC& WXUNUSED(dc), wxWindow* wnd, const wxRect& rect)
+{
+    int generic_border_width = wxAuiGenericTabArt::GetBorderWidth(wnd);
+
+    if (!wnd) return;
+    if (!wnd->m_wxwindow) return;
+    if (!gtk_widget_is_drawable(wnd->m_wxwindow)) return;
+
+    GtkStyle *style_notebook = gtk_widget_get_style(wxGTKPrivate::GetNotebookWidget());
+
+    gtk_paint_box(style_notebook, wnd->GTKGetDrawingWindow(), GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+                  NULL, wnd->m_wxwindow,
+                  const_cast<char*>("notebook"),
+                  rect.x + generic_border_width + 1, rect.y + generic_border_width + 1,
+                  rect.width - (generic_border_width + 1), rect.height - (generic_border_width + 1));
+}
+
 void ButtonStateAndShadow(int button_state, GtkStateType &state, GtkShadowType &shadow)
 {
 
@@ -464,6 +481,12 @@ int wxAuiGtkTabArt::GetBestTabCtrlSize(wxWindow* wnd,
     return tab_height;
 }
 
+int wxAuiGtkTabArt::GetBorderWidth(wxWindow* wnd)
+{
+    return wxAuiGenericTabArt::GetBorderWidth(wnd) + wxMax(GTK_NOTEBOOK (wxGTKPrivate::GetNotebookWidget())->tab_hborder,
+                                                           GTK_NOTEBOOK (wxGTKPrivate::GetNotebookWidget())->tab_vborder);
+}
+
 wxSize wxAuiGtkTabArt::GetTabSize(wxDC& dc,
                               wxWindow* wnd,
                               const wxString& caption,