From: Vadim Zeitlin Date: Wed, 12 Jan 2011 13:39:36 +0000 (+0000) Subject: Add support for icons in wxAUI panes title bars. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4254f672164bdc7e171c33a5663facbe6afa0833 Add support for icons in wxAUI panes title bars. Add wxAuiPaneInfo::Icon() method and shows its use in the sample. Closes #12856. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66670 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index bfb6390632..3f35549ed6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -433,6 +433,7 @@ All (GUI): - Added wxCommandLinkButton (Rickard Westerlund, GSoC 2010 project). - Added wxUIActionSimulator (Steven Lamerton, GSoC 2010 project). - wxAUI: support auto-orientable toolbars (wsu). +- wxAUI: add support for icons in pane title bars (triton). - Added wxDataViewCtrl::Set/GetCurrentItem(). - Added possibility to disable individual wxDataViewCtrl items (Neno Ganchev). - wxHTML: render in RTL order inside RTL window (Richard Bullington-McGuire). diff --git a/include/wx/aui/dockart.h b/include/wx/aui/dockart.h index 444308bdc9..027f399644 100644 --- a/include/wx/aui/dockart.h +++ b/include/wx/aui/dockart.h @@ -130,6 +130,10 @@ public: const wxRect& rect, wxAuiPaneInfo& pane); + void DrawIcon(wxDC& dc, + const wxRect& rect, + wxAuiPaneInfo& pane); + protected: void DrawCaptionBackground(wxDC& dc, const wxRect& rect, bool active); diff --git a/include/wx/aui/framemanager.h b/include/wx/aui/framemanager.h index ef5be06f56..73a452efac 100644 --- a/include/wx/aui/framemanager.h +++ b/include/wx/aui/framemanager.h @@ -173,6 +173,7 @@ public: { name = c.name; caption = c.caption; + icon = c.icon; window = c.window; frame = c.frame; state = c.state; @@ -271,6 +272,7 @@ public: } wxAuiPaneInfo& Name(const wxString& n) { name = n; return *this; } wxAuiPaneInfo& Caption(const wxString& c) { caption = c; return *this; } + wxAuiPaneInfo& Icon(const wxBitmap& b) { icon = b; return *this; } wxAuiPaneInfo& Left() { dock_direction = wxAUI_DOCK_LEFT; return *this; } wxAuiPaneInfo& Right() { dock_direction = wxAUI_DOCK_RIGHT; return *this; } wxAuiPaneInfo& Top() { dock_direction = wxAUI_DOCK_TOP; return *this; } @@ -418,6 +420,7 @@ public: public: wxString name; // name of the pane wxString caption; // caption displayed on the window + wxBitmap icon; // icon of the pane, may be invalid wxWindow* window; // window that is in this pane wxFrame* frame; // floating frame window that holds the pane @@ -438,6 +441,7 @@ public: wxAuiPaneButtonArray buttons; // buttons on the pane + wxRect rect; // current rectangle (populated by wxAUI) bool IsValid() const; diff --git a/interface/wx/aui/framemanager.h b/interface/wx/aui/framemanager.h index 36855b16a1..ba58430ce5 100644 --- a/interface/wx/aui/framemanager.h +++ b/interface/wx/aui/framemanager.h @@ -570,6 +570,17 @@ public: */ wxAuiPaneInfo& Hide(); + /** + Icon() sets the icon of the pane. + + Notice that the height of the icon should be smaller than the value + returned by wxAuiDockArt::GetMetric(wxAUI_DOCKART_CAPTION_SIZE) to + ensure that it appears correctly. + + @since 2.9.2 + */ + wxAuiPaneInfo& Icon(const wxBitmap& b); + /** IsBottomDockable() returns @true if the pane can be docked at the bottom of the managed frame. diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index 33dbaac0ca..570138976d 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -916,9 +916,19 @@ MyFrame::MyFrame(wxWindow* parent, CloseButton(true).MaximizeButton(true)); wxWindow* wnd10 = CreateTextCtrl(wxT("This pane will prompt the user before hiding.")); + + // Give this pane an icon, too, just for testing. + int iconSize = m_mgr.GetArtProvider()->GetMetric(wxAUI_DOCKART_CAPTION_SIZE); + + // Make it even to use 16 pixel icons with default 17 caption height. + iconSize &= ~1; + m_mgr.AddPane(wnd10, wxAuiPaneInfo(). Name(wxT("test10")).Caption(wxT("Text Pane with Hide Prompt")). - Bottom().Layer(1).Position(1)); + Bottom().Layer(1).Position(1). + Icon(wxArtProvider::GetBitmap(wxART_WARNING, + wxART_OTHER, + wxSize(iconSize, iconSize)))); m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo(). Name(wxT("test11")).Caption(wxT("Fixed Pane")). diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 3d9675b2ba..003b47aa3f 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -547,6 +547,14 @@ void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window), DrawCaptionBackground(dc, rect, (pane.state & wxAuiPaneInfo::optionActive)?true:false); + int caption_offset = 0; + if ( pane.icon.IsOk() ) + { + DrawIcon(dc, rect, pane); + + caption_offset += pane.icon.GetWidth() + 3; + } + if (pane.state & wxAuiPaneInfo::optionActive) dc.SetTextForeground(m_active_caption_text_colour); else @@ -569,10 +577,19 @@ void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window), wxString draw_text = wxAuiChopText(dc, text, clip_rect.width); dc.SetClippingRegion(clip_rect); - dc.DrawText(draw_text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1); + dc.DrawText(draw_text, rect.x+3 + caption_offset, rect.y+(rect.height/2)-(h/2)-1); dc.DestroyClippingRegion(); } +void +wxAuiDefaultDockArt::DrawIcon(wxDC& dc, const wxRect& rect, wxAuiPaneInfo& pane) +{ + // Draw the icon centered vertically + dc.DrawBitmap(pane.icon, + rect.x+2, rect.y+(rect.height-pane.icon.GetHeight())/2, + true); +} + void wxAuiDefaultDockArt::DrawGripper(wxDC& dc, wxWindow *WXUNUSED(window), const wxRect& rect, wxAuiPaneInfo& pane)