]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treelist.cpp
Applied colspan corrections, #15274 and #15275 (dghart)
[wxWidgets.git] / src / generic / treelist.cpp
index 6063ccf0a6f9c8ebe0da6ea8000b5c871642482d..56b820780f039aa6132e9ee80091f39621f9ea42 100644 (file)
@@ -3,7 +3,7 @@
 // Purpose:     Generic wxTreeListCtrl implementation.
 // Author:      Vadim Zeitlin
 // Created:     2011-08-19
-// RCS-ID:      $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $
+// RCS-ID:      $Id$
 // Copyright:   (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
@@ -549,23 +549,17 @@ public:
     }
 
     // Event handlers toggling the items checkbox if it was clicked.
-    virtual bool Activate(const wxRect& WXUNUSED(cell),
-                          wxDataViewModel* model,
-                          const wxDataViewItem& item,
-                          unsigned int WXUNUSED(col))
-    {
-        static_cast<wxTreeListModel*>(model)->ToggleItem(item);
-        return true;
-    }
-
-    virtual bool LeftClick(const wxPoint& pos,
-                           const wxRect& WXUNUSED(cell),
-                           wxDataViewModel* model,
-                           const wxDataViewItem& item,
-                           unsigned int WXUNUSED(col))
+    virtual bool ActivateCell(const wxRect& WXUNUSED(cell),
+                              wxDataViewModel *model,
+                              const wxDataViewItem & item,
+                              unsigned int WXUNUSED(col),
+                              const wxMouseEvent *mouseEvent)
     {
-        if ( !wxRect(GetCheckSize()).Contains(pos) )
-            return false;
+        if ( mouseEvent )
+        {
+            if ( !wxRect(GetCheckSize()).Contains(mouseEvent->GetPosition()) )
+                return false;
+        }
 
         static_cast<wxTreeListModel*>(model)->ToggleItem(item);
         return true;
@@ -671,16 +665,20 @@ wxTreeListModel::InsertItem(Node* parent,
     wxScopedPtr<Node>
         newItem(new Node(parent, text, imageClosed, imageOpened, data));
 
+    // FIXME-VC6: This compiler refuses to compare "Node* previous" with
+    //            wxTLI_XXX without some help.
+    const wxTreeListItem previousItem(previous);
+
     // If we have no children at all, then inserting as last child is the same
     // as inserting as the first one so check for it here too.
-    if ( previous == wxTLI_FIRST ||
-            (previous == wxTLI_LAST && !parent->GetChild()) )
+    if ( previousItem == wxTLI_FIRST ||
+            (previousItem == wxTLI_LAST && !parent->GetChild()) )
     {
         parent->InsertChild(newItem.get());
     }
     else // Not the first item, find the previous one.
     {
-        if ( previous == wxTLI_LAST )
+        if ( previousItem == wxTLI_LAST )
         {
             previous = parent->GetChild();
 
@@ -760,7 +758,12 @@ const wxString& wxTreeListModel::GetItemText(Node* item, unsigned col) const
     // empty string we can return reference to.
     wxCHECK_MSG( item, m_root->m_text, "Invalid item" );
 
-    return col == 0 ? item->m_text : item->GetColumnText(col);
+    // Notice that asking for the text of a column of an item that doesn't have
+    // any column texts is not an error so we simply return an empty string in
+    // this case.
+    return col == 0 ? item->m_text
+                    : item->HasColumnsTexts() ? item->GetColumnText(col)
+                                              : m_root->m_text;
 }
 
 void wxTreeListModel::SetItemText(Node* item, unsigned col, const wxString& text)
@@ -1026,10 +1029,14 @@ bool wxTreeListCtrl::Create(wxWindow* parent,
     }
 
     m_view = new wxDataViewCtrl;
+    long styleDataView = HasFlag(wxTL_MULTIPLE) ? wxDV_MULTIPLE
+                                                : wxDV_SINGLE;
+    if ( HasFlag(wxTL_NO_HEADER) )
+        styleDataView |= wxDV_NO_HEADER;
+
     if ( !m_view->Create(this, wxID_ANY,
                          wxPoint(0, 0), GetClientSize(),
-                         HasFlag(wxTL_MULTIPLE) ? wxDV_MULTIPLE
-                                                : wxDV_SINGLE) )
+                         styleDataView) )
     {
         delete m_view;
         m_view = NULL;
@@ -1148,7 +1155,7 @@ void wxTreeListCtrl::SetColumnWidth(unsigned col, int width)
     wxDataViewColumn* const column = m_view->GetColumn(col);
     wxCHECK_RET( column, "No such column?" );
 
-    return column->SetWidth(width);
+    column->SetWidth(width);
 }
 
 int wxTreeListCtrl::GetColumnWidth(unsigned col) const
@@ -1558,7 +1565,7 @@ void wxTreeListCtrl::SendColumnEvent(wxEventType evt, wxDataViewEvent& eventDV)
 void
 wxTreeListCtrl::OnItemToggled(wxTreeListItem item, wxCheckBoxState stateOld)
 {
-    wxTreeListEvent event(wxEVT_COMMAND_TREELIST_ITEM_CHECKED, this, item);
+    wxTreeListEvent event(wxEVT_TREELIST_ITEM_CHECKED, this, item);
     event.SetOldCheckedState(stateOld);
 
     ProcessWindowEvent(event);
@@ -1566,32 +1573,32 @@ wxTreeListCtrl::OnItemToggled(wxTreeListItem item, wxCheckBoxState stateOld)
 
 void wxTreeListCtrl::OnSelectionChanged(wxDataViewEvent& event)
 {
-    SendItemEvent(wxEVT_COMMAND_TREELIST_SELECTION_CHANGED, event);
+    SendItemEvent(wxEVT_TREELIST_SELECTION_CHANGED, event);
 }
 
 void wxTreeListCtrl::OnItemExpanding(wxDataViewEvent& event)
 {
-    SendItemEvent(wxEVT_COMMAND_TREELIST_ITEM_EXPANDING, event);
+    SendItemEvent(wxEVT_TREELIST_ITEM_EXPANDING, event);
 }
 
 void wxTreeListCtrl::OnItemExpanded(wxDataViewEvent& event)
 {
-    SendItemEvent(wxEVT_COMMAND_TREELIST_ITEM_EXPANDED, event);
+    SendItemEvent(wxEVT_TREELIST_ITEM_EXPANDED, event);
 }
 
 void wxTreeListCtrl::OnItemActivated(wxDataViewEvent& event)
 {
-    SendItemEvent(wxEVT_COMMAND_TREELIST_ITEM_ACTIVATED, event);
+    SendItemEvent(wxEVT_TREELIST_ITEM_ACTIVATED, event);
 }
 
 void wxTreeListCtrl::OnItemContextMenu(wxDataViewEvent& event)
 {
-    SendItemEvent(wxEVT_COMMAND_TREELIST_ITEM_CONTEXT_MENU, event);
+    SendItemEvent(wxEVT_TREELIST_ITEM_CONTEXT_MENU, event);
 }
 
 void wxTreeListCtrl::OnColumnSorted(wxDataViewEvent& event)
 {
-    SendColumnEvent(wxEVT_COMMAND_TREELIST_COLUMN_SORTED, event);
+    SendColumnEvent(wxEVT_TREELIST_COLUMN_SORTED, event);
 }
 
 // ----------------------------------------------------------------------------
@@ -1656,10 +1663,10 @@ wxWindow* wxTreeListCtrl::GetView() const
 // wxTreeListEvent implementation
 // ============================================================================
 
-wxIMPLEMENT_ABSTRACT_CLASS(wxTreeListEvent, wxNotifyEvent)
+wxIMPLEMENT_DYNAMIC_CLASS(wxTreeListEvent, wxNotifyEvent)
 
 #define wxDEFINE_TREELIST_EVENT(name) \
-    wxDEFINE_EVENT(wxEVT_COMMAND_TREELIST_##name, wxTreeListEvent)
+    wxDEFINE_EVENT(wxEVT_TREELIST_##name, wxTreeListEvent)
 
 wxDEFINE_TREELIST_EVENT(SELECTION_CHANGED);
 wxDEFINE_TREELIST_EVENT(ITEM_EXPANDING);