]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Added RTTI macros to wxSplashScreen.
[wxWidgets.git] / src / generic / treectlg.cpp
index a4db0ea4fa1f2034f73c1ec6bef17722e8859a15..3176b1eb9280dd407f86ef7e2933c929381d3e47 100644 (file)
@@ -360,21 +360,6 @@ void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
         m_owner->OnRenameAccept();
 }
 
-#if 0
-// -----------------------------------------------------------------------------
-// wxTreeEvent
-// -----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxNotifyEvent)
-
-wxTreeEvent::wxTreeEvent( wxEventType commandType, int id )
-           : wxNotifyEvent( commandType, id )
-{
-    m_code = 0;
-    m_itemOld = (wxGenericTreeItem *)NULL;
-}
-#endif
-
 // -----------------------------------------------------------------------------
 // wxGenericTreeItem
 // -----------------------------------------------------------------------------
@@ -614,9 +599,23 @@ void wxGenericTreeCtrl::Init()
     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;
@@ -665,14 +664,15 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
     SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
 
 //  m_dottedPen = wxPen( "grey", 0, wxDOT );  too slow under XFree86
-    m_dottedPen = wxPen( "grey", 0, 0 );
+    m_dottedPen = wxPen( wxT("grey"), 0, 0 );
 
     return TRUE;
 }
 
 wxGenericTreeCtrl::~wxGenericTreeCtrl()
 {
-    wxDELETE( m_hilightBrush );
+    delete m_hilightBrush;
+    delete m_hilightUnfocusedBrush;
 
     DeleteAllItems();
 
@@ -1017,15 +1017,6 @@ wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const
     }
 }
 
-wxTreeItemId wxGenericTreeCtrl::GetPrev(const wxTreeItemId& item) const
-{
-    wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
-
-    wxFAIL_MSG(wxT("not implemented"));
-
-    return wxTreeItemId();
-}
-
 wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
 {
     wxTreeItemId id = GetRootItem();
@@ -1838,10 +1829,9 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 
     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
     {
@@ -1855,7 +1845,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 
     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
@@ -1999,12 +1989,12 @@ 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
-            (item->IsSelected()) ? wxBLACK_PEN :
+            (item->IsSelected() && m_hasFocus) ? wxBLACK_PEN :
 #endif // !__WXMAC__
             wxTRANSPARENT_PEN;
 
         wxColour colText;
-        if (item->IsSelected() && m_hasFocus)
+        if ( item->IsSelected() )
         {
             colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
         }
@@ -2146,28 +2136,34 @@ void wxGenericTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
     PaintLevel( m_anchor, dc, 0, y );
 }
 
-void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
+void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent &event )
 {
     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;
 
-    if (m_current)
-        RefreshLine( m_current );
+    RefreshSelected();
+
+    event.Skip();
 }
 
 void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
 {
     wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
-    te.m_code = (int)event.KeyCode();
+    te.m_evtKey = event;
     te.SetEventObject( this );
-    GetEventHandler()->ProcessEvent( te );
+    if ( GetEventHandler()->ProcessEvent( te ) )
+    {
+        // intercepted by the user code
+        return;
+    }
 
     if ( (m_current == 0) || (m_key_current == 0) )
     {
@@ -2225,7 +2221,6 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
             {
                 wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
                 event.m_item = (long) m_current;
-                event.m_code = 0;
                 event.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( event );
             }
@@ -2650,7 +2645,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         {
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
             nevent.m_item = (long) item;
-            nevent.m_code = 0;
             CalcScrolledPosition(x, y,
                                  &nevent.m_pointDrag.x,
                                  &nevent.m_pointDrag.y);
@@ -2711,23 +2705,22 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                 m_renameTimer->Stop();
                 m_lastOnSame = FALSE;
 
-                if (item->HasPlus())
+                // send activate event first
+                wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
+                nevent.m_item = (long) item;
+                CalcScrolledPosition(x, y,
+                                     &nevent.m_pointDrag.x,
+                                     &nevent.m_pointDrag.y);
+                nevent.SetEventObject( this );
+                if ( !GetEventHandler()->ProcessEvent( nevent ) )
                 {
-                    // for a "directory" node, toggle expansion
-                    Toggle(item);
-                }
-                else
-                {
-                    // for a "file" node, activate it
-                    wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
-                                        GetId() );
-                    nevent.m_item = (long) item;
-                    nevent.m_code = 0;
-                    CalcScrolledPosition(x, y,
-                                         &nevent.m_pointDrag.x,
-                                         &nevent.m_pointDrag.y);
-                    nevent.SetEventObject( this );
-                    GetEventHandler()->ProcessEvent( nevent );
+                    // if the user code didn't process the activate event,
+                    // handle it ourselves by toggling the item when it is
+                    // double clicked
+                    if ( item->HasPlus() )
+                    {
+                        Toggle(item);
+                    }
                 }
             }
         }
@@ -2885,4 +2878,49 @@ void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item )
     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]);
+    }
+}
+
+// ----------------------------------------------------------------------------
+// changing colours: we need to refresh the tree control
+// ----------------------------------------------------------------------------
+
+bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour& colour)
+{
+    if ( !wxWindow::SetBackgroundColour(colour) )
+        return FALSE;
+
+    Refresh();
+
+    return TRUE;
+}
+
+bool wxGenericTreeCtrl::SetForegroundColour(const wxColour& colour)
+{
+    if ( !wxWindow::SetForegroundColour(colour) )
+        return FALSE;
+
+    Refresh();
+
+    return TRUE;
+}
+
 #endif // wxUSE_TREECTRL