wxAuiDefaultTabArt customization

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
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

wxAuiDefaultTabArt customization

Post by papillon68 »

I'm trying to customize a wxAuiNotebook but it seems no changes are successful.
I've derived a new class for the wxAuiDefaultTabArt:

Code: Select all

class MyAuiTabArt : public wxAuiDefaultTabArt
{
public:
	MyAuiTabArt() {}
	virtual ~MyAuiTabArt() {}
	wxAuiDefaultTabArt *Clone() {
		return new MyAuiTabArt();
	}
	void DrawButton(wxDC &dc, wxWindow *wnd, const wxRect &inRect, int bitmapId, int buttonState, int orientation, wxRect *outRect);
};
and using this code to draw a customized tab:

Code: Select all

 void MyAuiTabArt::DrawButton(wxDC &dc, wxWindow *wnd, const wxRect &inRect, int bitmapId, int buttonState, int orientation, wxRect *outRect)
 {
	 dc.SetPen(wxPen(wxColor(255, 0, 0), 0));
	 dc.DrawRectangle(wxPoint(0, 0), wxSize(400, 100));
	 dc.SetBackground(wxColor(255, 0, 0));
	 dc.SetTextForeground( wxColour(255, 240, 233));
 }

Code: Select all

	myTabArt = new MyAuiTabArt();
	myAuiNotebook->SetArtProvider(myTabArt);
I couldn't find any specific information around or in the documentation, so I'm wondering if any of you guys were able to do it. Thanks.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxAuiDefaultTabArt customization

Post by doublemax »

Does the DrawButton get called?

If yes, try using the "wxRect &inRect" for drawing, don't draw at (0,0). E.g. dc.DrawRectangle( inRect );
Use the source, Luke!
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: wxAuiDefaultTabArt customization

Post by papillon68 »

Thanks for the reply, doublemax.
No the function wasn't called and so I ended up subclassing DrawTab like this:

Code: Select all

 void MyAuiTabArt::DrawTab(wxDC &dc, wxWindow *wnd, const wxAuiNotebookPage &pane, const wxRect &inRect, int closeButtonState, wxRect *outTabRect, wxRect *outButtonRect, int *xExtent)
 {
	wxSize tabSize(200, 40);
	outTabRect->SetSize(tabSize);
	dc.SetBrush(panelBackgroundColor);
	dc.DrawRectangle(inRect);
	dc.SetBrush(dockBackgroundColor);
	dc.DrawRectangle(pane.rect);
	wxFont captionFont;
	captionFont.SetPointSize(11);
	dc.SetFont(captionFont);
	dc.SetTextForeground(dockTitleColor);
	dc.DrawText(pane.caption, 0, 0);	 
 }
I use dc.DrawRectangle(inRect) to color the whole tab row, and later dc.DrawRectangle(pane.rect) to color the tab background. And the dc.DrawText for the tab caption.
I hope this can be useful for other folks.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Post Reply