wxAuiNotebook set border around notebook page only Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
thile
Knows some wx things
Knows some wx things
Posts: 26
Joined: Sat Oct 25, 2008 3:46 pm

wxAuiNotebook set border around notebook page only

Post by thile »

I’m experimenting with the wxAuiNotebook control. I switched to have better control over the background and tab colour.


First problem, the notebook kept having a border around itself even though the style wxBorder_None was used.

Help was found here:
http://forums.wxwidgets.org/viewtopic.p ... ook+border


The border I see is not from wxAuiNotebook itself but from wxAuiDefaultDockArt::DrawBorder

I Implemented new DockArt class and overruled DrawBorder.
This removed the border around the control and i was happy for a day or two.

I now want to optimize and improve this. Firstly I want a border around the notebook page, not around the notebook tabs.

The default implementation of wxAuiDefaultDockArt::DrawBorder draw border around the full wxAuiNotebook control.

Code: Select all

void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow *WXUNUSED(window), const wxRect& _rect, wxAuiPaneInfo& pane)
{
// The rect covers the full notebook.
// I want to draw lines around the left/right/bottom side of the notebook page.
// I if had access to the tab height I could calculate the positions.

// This is default where border is drawn around the notebook
   dc.SetPen(m_border_pen);
    dc.SetBrush(*wxTRANSPARENT_BRUSH);

    wxRect rect = _rect;
    int i, border_width = GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);

    if (pane.IsToolbar())
    {
        for (i = 0; i < border_width; ++i)
        {
            dc.SetPen(*wxWHITE_PEN);
            dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
            dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height);
            dc.SetPen(m_border_pen);
            dc.DrawLine(rect.x, rect.y+rect.height-1,
                        rect.x+rect.width, rect.y+rect.height-1);
            dc.DrawLine(rect.x+rect.width-1, rect.y,
                        rect.x+rect.width-1, rect.y+rect.height);
            rect.Deflate(1);
        }
    }
    else
    {
        for (i = 0; i < border_width; ++i)
        {
            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
            rect.Deflate(1);
        }
    }
}
Attachments
propertypanel_solid_border1.png
propertypanel_solid_border1.png (12.99 KiB) Viewed 4445 times
Allonii
Experienced Solver
Experienced Solver
Posts: 83
Joined: Wed Jun 24, 2009 1:28 pm

Post by Allonii »

The easiest way to do this is to derive from wxAuiNotebook and in the constructor set,

Code: Select all

//m_mgr is a protected wxAuiManager managed by wxAuiNotebook 
m_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE,0);
And then just use default borders around your controls in the tabs.


Another option is to remove all borders and do the drawing yourself. Derive a class from wxAuiTabArt and set the class by calling wxAuiNotebook::SetArtProvider. You can customize the tabs a lot and if you don't want to implement everything from scratch just derive from wxAuiDefaultTabArt and override the desired functions.

To learn how wxauixxx works start by looking at the wxaui sample and then the source code for the wxauixxx classes.
Thanks

Allonii
thile
Knows some wx things
Knows some wx things
Posts: 26
Joined: Sat Oct 25, 2008 3:46 pm

Post by thile »

I’m pretty happy with the results I have got now.

To remove the border I did as suggested and doing all the drawing myself.

1. Created new class derived from wxAuiNotebook
2. New derived class from wxAuiDefaultTabArt
3. New derived class from wxAuiDefaultDockArt
User avatar
silver.moon
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Feb 20, 2015 6:13 am

Re:

Post by silver.moon »

Allonii wrote:The easiest way to do this is to derive from wxAuiNotebook and in the constructor set,

Code: Select all

//m_mgr is a protected wxAuiManager managed by wxAuiNotebook 
m_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE,0);
This does not totally remove the border, it reduces it to width 1px.
Post Reply