Page 1 of 1
How to force wxToolbar background color under OS X ?
Posted: Mon Mar 03, 2014 11:11 am
by eranon
Hello,
I have several wxToolbar for which I would like to force the background color. It works under Windows using SetBackgroundColour(), but this way seems to have no effect under OS X (tested under OS X 10.8 and wxWidgets 3.0.0).
Also, knowing my toolbars are with a 16x16 px buttons (and not positionned at standard locations), I indicated to not use the native control (using call below during app-init). However, with or without this, SetBackgroundColour is ignored (see EDIT1) :
Code: Select all
wxSystemOptions::SetOption("mac.toolbar.no-native", 1);
So, does OS X is a specific case (what a surprise - huuuu) ? There's not any warning in the SetBackgroundColour()'s documentation. Is there a special trick to know... Should I derive wxToolbar and override a specific virtual method or just handle the EVT_ERASE_BACKGROUND through Bind() or Connect() ?
What's the right way to follow for Mac, please ?
--
EDIT1 : Well, certainly that without "mac.toolbar.no-native" I'm with non-native toolbar too (implicitely), because the toolbar is not directly a frame's child. So, the question remains : how to force background color of a non-native wxToolbar under OSX.
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Mar 03, 2014 1:07 pm
by eranon
Tried handling EVT_ERASE_BACKGROUND like this and still no background color change
Code: Select all
/* use of connect rather than bind is done willingly here ;) */
bar1->Connect(wxID_ANY, wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(MyFrame::OnToolbarEraseBackground), NULL, this);
void MyFrame::OnToolbarEraseBackground(wxEraseEvent &event)
{
// Force background color of the given toolbar
wxDC* pdc = event.GetDC();
wxBrush brush(wxColour(255,0,0)); // red during test only :)
pdc->SetBackground(brush);
pdc->Clear();
/* no skip event to prevent default system behavior */
}
The event handler is well fired and event.GetId() well return the right ID (so, no mistake about concerned toolbar), but the background color doesn't change (still the OSX's dark-grey)
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Mar 03, 2014 4:59 pm
by eranon
Succeeded providing a wxEVT_PAINT handler rather than a EVT_ERASE_BACKGROUND one.
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Aug 11, 2014 7:40 pm
by alan93
and yet wxEVT_PAINT event has no GetDC().
Can I ask how you worked that out? I think I could use that.
Re: How to force wxToolbar background color under OS X ?
Posted: Tue Aug 19, 2014 5:48 am
by eranif
You just need to construct a wxPaintDC On the stack and use that
Re: How to force wxToolbar background color under OS X ?
Posted: Tue Aug 19, 2014 8:12 pm
by alan93
Great thanks, I'll try that.
Re: How to force wxToolbar background color under OS X ?
Posted: Tue Aug 26, 2014 12:30 pm
by alan93
This didn't work for me
Code: Select all
bar1->Connect(wxID_ANY, wxEVT_PAINT, wxPaintEventHandler( MyFrame::OnToolbarEraseBackground), NULL, this->GetEventHandler() );
void MyFrame::OnToolbarEraseBackground(wxPaintEvent &event) // doesn't execute
{
// Force background color of the given toolbar
wxPaintDC dc(this) ;
wxBrush brush(wxColour(255,0,0)); // red during test only :)
dc.SetBackground(brush);
dc.Clear();
/* no skip event to prevent default system behavior */
}
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Sep 15, 2014 12:12 pm
by eranon
Hello,
I just see your MP on 12 Aug 2014 now (oops). Not came here since a long time. Well, I take a look at my code... wait a "minute"...
OK, here is the way I gone :
Code: Select all
#ifdef __WXOSX__
void DedeeFrame::OnToolbarPaint(wxPaintEvent &event)
{
// Forces color of the given toolbar
// REF : inspired by <wxWidgets-3.0.0>/src/osx/cocoa/toolbar.mm:OnPaint()
// NB : here, the wxTB_LEFT/RIGHT/BOTTOM/TOP are ignored (if needed ***LATER, see in original REF source)
wxWindow* pWnd = (wxWindow*) event.GetEventObject();
wxPaintDC dc(pWnd);
wxBrush brush(pWnd->GetParent()->GetBackgroundColour());
dc.SetBackground(brush);
dc.Clear();
/* no event skip to prevent default system color */
}
#endif // __WXOSX__
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Apr 27, 2020 2:43 am
by cutecode
hello, eranon
I put your code in my wxAuiToolBar. The toolbar indeed pained with frame colour, but no buttons are displaied.
Could you, pleese, help me how to show the buttons, too?
Re: How to force wxToolbar background color under OS X ?
Posted: Mon Apr 27, 2020 3:55 am
by cutecode
got it, I should overwite wxAuiToolBarArt
thx