I have just added code to make docked panes have an icon.
It's quite simple, but is working well.
Here's the code :
In wxPaneInfo I added :
- Code: Select all
wxBitmap icon; // Pane Icon
This member is public as the others (thus it's not clean).
- Code: Select all
void SetIcon(wxImage* image){
if (image!=NULL)
{
icon =wxBitmap(*image);
} else
{
icon =wxBitmap();
}
}
This piece of code enables removing an Icon
I put a few lines here :
- Code: Select all
void wxDefaultDockArt::DrawCaption(wxDC& dc,
const wxString& text,
const wxRect& rect,
wxPaneInfo& pane)
{
// Caption offset : Caption is drawn a few pixels further if the pane icon is not NULL
int caption_offset =0;
if (pane.icon.Ok())
{
caption_offset+= pane.icon.GetWidth()+3;
}
//
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetFont(m_caption_font);
DrawCaptionBackground(dc, rect,
(pane.state & wxPaneInfo::optionActive)?true:false);
DrawIcon(dc, rect, pane);
if (pane.state & wxPaneInfo::optionActive)
dc.SetTextForeground(m_active_caption_text_colour);
else
dc.SetTextForeground(m_inactive_caption_text_colour);
wxCoord w,h;
dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);
dc.SetClippingRegion(rect);
dc.DrawText(text, rect.x+3+caption_offset, rect.y+(rect.height/2)-(h/2)-1);
dc.DestroyClippingRegion();
}
- Code: Select all
void wxDefaultDockArt::DrawIcon(wxDC& dc, const wxRect& rect, wxPaneInfo& pane){
// Draw the icon centered vertically
if (pane.icon.Ok())
{
dc.DrawBitmap(pane.icon, rect.x+2, rect.y+(rect.height-pane.icon.GetHeight())/2, true);
}
}
To change a pane icon, you just have to do :
- Code: Select all
// manager is a wxFrameManager
// img is a wxImage that is valid or NULL
manager.GetPane(pane).SetIcon(&img);
To clear a pane icon, do :
- Code: Select all
// manager is a wxFrameManager
// img is a wxImage that is valid or NULL
manager.GetPane(pane).SetIcon(NULL);
Here it is