]> git.saurik.com Git - wxWidgets.git/commitdiff
draw the selected items in another colour when the control doesn't have focus, a...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 20 Aug 2001 14:13:34 +0000 (14:13 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 20 Aug 2001 14:13:34 +0000 (14:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11421 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/treectlg.h
src/generic/treectlg.cpp

index a330263f1db71a23fba7a8660b46590abc349230..545ecd90fd5e114d5bb7a8e60825412b64783193 100644 (file)
@@ -81,10 +81,10 @@ public:
     void SetSpacing(unsigned int spacing);
 
         // image list: these functions allow to associate an image list with
     void SetSpacing(unsigned int spacing);
 
         // image list: these functions allow to associate an image list with
-        // the control and retrieve it. Note that when assigned with 
+        // the control and retrieve it. Note that when assigned with
         // SetImageList, the control does _not_ delete
         // the associated image list when it's deleted in order to allow image
         // SetImageList, the control does _not_ delete
         // the associated image list when it's deleted in order to allow image
-        // lists to be shared between different controls. If you use 
+        // lists to be shared between different controls. If you use
         // AssignImageList, the control _does_ delete the image list.
         //
         // The normal image list is for the icons which correspond to the
         // AssignImageList, the control _does_ delete the image list.
         //
         // The normal image list is for the icons which correspond to the
@@ -357,10 +357,11 @@ protected:
     unsigned short       m_spacing;
     int                  m_lineHeight;
     wxPen                m_dottedPen;
     unsigned short       m_spacing;
     int                  m_lineHeight;
     wxPen                m_dottedPen;
-    wxBrush             *m_hilightBrush;
+    wxBrush             *m_hilightBrush,
+                        *m_hilightUnfocusedBrush;
     bool                 m_hasFocus;
     bool                 m_dirty;
     bool                 m_hasFocus;
     bool                 m_dirty;
-    bool                 m_ownsImageListNormal, 
+    bool                 m_ownsImageListNormal,
                          m_ownsImageListState,
                          m_ownsImageListButtons;
     bool                 m_isDragging; // true between BEGIN/END drag events
                          m_ownsImageListState,
                          m_ownsImageListButtons;
     bool                 m_isDragging; // true between BEGIN/END drag events
@@ -405,6 +406,12 @@ protected:
     void RefreshSubtree( wxGenericTreeItem *item );
     void RefreshLine( wxGenericTreeItem *item );
 
     void RefreshSubtree( wxGenericTreeItem *item );
     void RefreshLine( wxGenericTreeItem *item );
 
+    // redraw all selected items
+    void RefreshSelected();
+
+    // RefreshSelected() recursive helper
+    void RefreshSelectedUnder(wxGenericTreeItem *item);
+
     void OnRenameTimer();
     void OnRenameAccept();
 
     void OnRenameTimer();
     void OnRenameAccept();
 
index a4db0ea4fa1f2034f73c1ec6bef17722e8859a15..f2b3ca9dde89d3af36e5720f41b46d284d60b949 100644 (file)
@@ -614,9 +614,23 @@ void wxGenericTreeCtrl::Init()
     m_indent = 15;
     m_spacing = 18;
 
     m_indent = 15;
     m_spacing = 18;
 
-    m_hilightBrush = new wxBrush(
-               wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT),
-               wxSOLID);
+    m_hilightBrush = new wxBrush
+                         (
+                            wxSystemSettings::GetSystemColour
+                            (
+                                wxSYS_COLOUR_HIGHLIGHT
+                            ),
+                            wxSOLID
+                         );
+
+    m_hilightUnfocusedBrush = new wxBrush
+                              (
+                                 wxSystemSettings::GetSystemColour
+                                 (
+                                     wxSYS_COLOUR_BTNSHADOW
+                                 ),
+                                 wxSOLID
+                              );
 
     m_imageListNormal = m_imageListButtons =
     m_imageListState = (wxImageList *) NULL;
 
     m_imageListNormal = m_imageListButtons =
     m_imageListState = (wxImageList *) NULL;
@@ -672,7 +686,8 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
 
 wxGenericTreeCtrl::~wxGenericTreeCtrl()
 {
 
 wxGenericTreeCtrl::~wxGenericTreeCtrl()
 {
-    wxDELETE( m_hilightBrush );
+    delete m_hilightBrush;
+    delete m_hilightUnfocusedBrush;
 
     DeleteAllItems();
 
 
     DeleteAllItems();
 
@@ -1838,10 +1853,9 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 
     int total_h = GetLineHeight(item);
 
 
     int total_h = GetLineHeight(item);
 
-    bool paintBg = item->IsSelected() && m_hasFocus;
-    if ( paintBg )
+    if ( item->IsSelected() )
     {
     {
-        dc.SetBrush(*m_hilightBrush);
+        dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush));
     }
     else
     {
     }
     else
     {
@@ -1855,7 +1869,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 
     int offset = HasFlag(wxTR_ROW_LINES) ? 1 : 0;
 
 
     int offset = HasFlag(wxTR_ROW_LINES) ? 1 : 0;
 
-    if ( item->IsSelected() && image != NO_IMAGE)
+    if ( item->IsSelected() && image != NO_IMAGE )
     {
         // If it's selected, and there's an image, then we should
         // take care to leave the area under the image painted in the
     {
         // If it's selected, and there's an image, then we should
         // take care to leave the area under the image painted in the
@@ -1999,7 +2013,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
 #ifndef __WXMAC__
             // don't draw rect outline if we already have the
             // background color under Mac
 #ifndef __WXMAC__
             // don't draw rect outline if we already have the
             // background color under Mac
-            (item->IsSelected()) ? wxBLACK_PEN :
+            (item->IsSelected() && m_hasFocus) ? wxBLACK_PEN :
 #endif // !__WXMAC__
             wxTRANSPARENT_PEN;
 
 #endif // !__WXMAC__
             wxTRANSPARENT_PEN;
 
@@ -2146,20 +2160,22 @@ void wxGenericTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
     PaintLevel( m_anchor, dc, 0, y );
 }
 
     PaintLevel( m_anchor, dc, 0, y );
 }
 
-void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
+void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent &event )
 {
     m_hasFocus = TRUE;
 
 {
     m_hasFocus = TRUE;
 
-    if (m_current)
-        RefreshLine( m_current );
+    RefreshSelected();
+
+    event.Skip();
 }
 
 }
 
-void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
+void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent &event )
 {
     m_hasFocus = FALSE;
 
 {
     m_hasFocus = FALSE;
 
-    if (m_current)
-        RefreshLine( m_current );
+    RefreshSelected();
+
+    event.Skip();
 }
 
 void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
 }
 
 void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
@@ -2885,4 +2901,25 @@ void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item )
     Refresh( TRUE, &rect );
 }
 
     Refresh( TRUE, &rect );
 }
 
+void wxGenericTreeCtrl::RefreshSelected()
+{
+    // TODO: this is awfully inefficient, we should keep the list of all
+    //       selected items internally, should be much faster
+    if ( m_anchor )
+        RefreshSelectedUnder(m_anchor);
+}
+
+void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem *item)
+{
+    if ( item->IsSelected() )
+        RefreshLine(item);
+
+    const wxArrayGenericTreeItems& children = item->GetChildren();
+    size_t count = children.GetCount();
+    for ( size_t n = 0; n < count; n++ )
+    {
+        RefreshSelectedUnder(children[n]);
+    }
+}
+
 #endif // wxUSE_TREECTRL
 #endif // wxUSE_TREECTRL