From 9fa99f045e39341d64b4ecffbaab6385d9982cee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 8 Oct 2012 12:09:13 +0000 Subject: [PATCH] Improve wxAuiNotebook appearance when using some GTK themes. 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 | 24 ++++++++++++++++++ include/wx/aui/tabartgtk.h | 2 ++ src/aui/auibook.cpp | 17 +++++++++---- src/aui/dockart.cpp | 21 +++++++++++++--- src/aui/tabart.cpp | 50 ++++++++++++++++++++++++++++++++++++++ src/aui/tabartgtk.cpp | 23 ++++++++++++++++++ 6 files changed, 128 insertions(+), 9 deletions(-) diff --git a/include/wx/aui/tabart.h b/include/wx/aui/tabart.h index 329d6bbb26..12621771a6 100644 --- a/include/wx/aui/tabart.h +++ b/include/wx/aui/tabart.h @@ -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, diff --git a/include/wx/aui/tabartgtk.h b/include/wx/aui/tabartgtk.h index 25f1447d91..b094082d81 100644 --- a/include/wx/aui/tabartgtk.h +++ b/include/wx/aui/tabartgtk.h @@ -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); diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index 4a2596f52b..402724309b 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -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){} diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index c25509122c..8187939b02 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -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); + } } } } diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 068070dff2..62c6c5f9dd 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -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, diff --git a/src/aui/tabartgtk.cpp b/src/aui/tabartgtk.cpp index 5c2bfb417f..28bfaa6aaf 100644 --- a/src/aui/tabartgtk.cpp +++ b/src/aui/tabartgtk.cpp @@ -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("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, -- 2.45.2