Re: wxAuiNotebook, changing the close button bitmap?
PB <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
*Disclaimer: I know little about wxAUI, just took a look at the sources,
and I am Windows only.*
Replacing close button bitmaps in wxAuiSimpleTabArt is very simple but more
complicated with wxAuiDefaultTabArt. wxAuiDefaultTabArt differs between
platforms
<https://github.com/wxWidgets/wxWidgets/blob/14f6f82e46641ef226b23143c1f44570c769176b/include/wx/aui/tabart.h#L320>,
e.g., it actually is wxAuiMSWTabArt on Windows which uses native theme API
to draw the button.
Anyway, I tried if using a custom art for the tab works, writing a
proof-of-concept code using a help bitmap as the close button (same for
active and disabled), borrowing the draw methods from the generic tab art
when needed, not caring about how it looks:
[image: wx-auintb-art.png]
#include <wx/wx.h>
#include <wx/artprov.h>
#include <wx/aui/auibook.h>
class MyAuiSimpleTabArt : public wxAuiSimpleTabArt
{
public:
MyAuiSimpleTabArt(const wxBitmapBundle& activeCloseBmp, const
wxBitmapBundle& disabledCloseBmp)
{
m_activeCloseBmp = activeCloseBmp;
m_disabledCloseBmp = disabledCloseBmp;
}
wxAuiTabArt* Clone()
{
return new MyAuiSimpleTabArt(*this);
}
};
class MyAuiDefaultTabArt : public wxAuiDefaultTabArt
{
public:
MyAuiDefaultTabArt(const wxBitmapBundle& activeCloseBmp, const
wxBitmapBundle& disabledCloseBmp)
{
m_activeCloseBmp = activeCloseBmp;
m_disabledCloseBmp = disabledCloseBmp;
}
// This draws the "Close active tab" button on the far right
void DrawButton(wxDC& dc, wxWindow* wnd, const wxRect& in_rect, int
bitmap_id, int button_state, int orientation, wxRect* out_rect) override
{
// for testing, use generic version
wxAuiGenericTabArt::DrawButton(dc, wnd, in_rect, bitmap_id,
button_state, orientation, out_rect);
}
void DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page,
const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect,
wxRect* out_button_rect, int* x_extent) override
{
// for testing, use generic version
wxAuiGenericTabArt::DrawTab(dc, wnd, page, in_rect,
close_button_state, out_tab_rect, out_button_rect, x_extent);
}
wxAuiTabArt* Clone()
{
return new MyAuiDefaultTabArt(*this);
}
};
class MyFrame : public wxFrame
{
public:
MyFrame(wxWindow* parent = nullptr) : wxFrame(parent, wxID_ANY, "Test")
{
const wxBitmapBundle activeClose =
wxArtProvider::GetBitmapBundle(wxART_HELP, wxART_OTHER, wxSize(16,16));
const wxBitmapBundle disabledClose = activeClose;
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(AddNotebook(new MyAuiSimpleTabArt(activeClose,
disabledClose)), wxSizerFlags(1).Expand());
mainSizer->Add(AddNotebook(new MyAuiDefaultTabArt(activeClose,
disabledClose)), wxSizerFlags(1).Expand());
SetSizer(mainSizer);
}
private:
wxAuiNotebook* AddNotebook(wxAuiTabArt* tabArt)
{
wxAuiNotebook* notebook = new wxAuiNotebook(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize, wxAUI_NB_CLOSE_BUTTON |
wxAUI_NB_CLOSE_ON_ALL_TABS | wxAUI_NB_DEFAULT_STYLE);
notebook->SetArtProvider(tabArt);
for ( size_t i = 0; i < 10; ++i )
notebook->AddPage(new wxPanel(notebook), wxString::Format("Page
%zu", i), false);
return notebook;
}
};
class MyApp : public wxApp
{
bool OnInit() override
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
To conclude, customizing the tab art seems possible but may require some
effort to look good and work properly on all the platforms.
Regards,
PB
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/83420575-6b17-49ad-9bd7-f0ab92800594n%40googlegroups.com.
wx-auintb-art.png
(image/png, 23.1 KB) - not displayed