]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dirctrlg.cpp
avoid populating the array with NULL controls during creation (SetWindowVariant calli...
[wxWidgets.git] / src / generic / dirctrlg.cpp
index 9bb119ebea1bc63dca59e602ed82108c275f8be8..24073aeeae029bf82f549dffe37c14fea09d3d76 100644 (file)
@@ -29,7 +29,6 @@
     #include "wx/icon.h"
     #include "wx/settings.h"
     #include "wx/msgdlg.h"
-    #include "wx/cmndata.h"
     #include "wx/choice.h"
     #include "wx/textctrl.h"
     #include "wx/layout.h"
@@ -437,64 +436,6 @@ bool wxDirItemData::HasFiles(const wxString& WXUNUSED(spec)) const
 // wxGenericDirCtrl
 //-----------------------------------------------------------------------------
 
-
-#if wxUSE_EXTENDED_RTTI
-WX_DEFINE_FLAGS( wxGenericDirCtrlStyle )
-
-wxBEGIN_FLAGS( wxGenericDirCtrlStyle )
-    // new style border flags, we put them first to
-    // use them for streaming out
-    wxFLAGS_MEMBER(wxBORDER_SIMPLE)
-    wxFLAGS_MEMBER(wxBORDER_SUNKEN)
-    wxFLAGS_MEMBER(wxBORDER_DOUBLE)
-    wxFLAGS_MEMBER(wxBORDER_RAISED)
-    wxFLAGS_MEMBER(wxBORDER_STATIC)
-    wxFLAGS_MEMBER(wxBORDER_NONE)
-
-    // old style border flags
-    wxFLAGS_MEMBER(wxSIMPLE_BORDER)
-    wxFLAGS_MEMBER(wxSUNKEN_BORDER)
-    wxFLAGS_MEMBER(wxDOUBLE_BORDER)
-    wxFLAGS_MEMBER(wxRAISED_BORDER)
-    wxFLAGS_MEMBER(wxSTATIC_BORDER)
-    wxFLAGS_MEMBER(wxBORDER)
-
-    // standard window styles
-    wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
-    wxFLAGS_MEMBER(wxCLIP_CHILDREN)
-    wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
-    wxFLAGS_MEMBER(wxWANTS_CHARS)
-    wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
-    wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
-    wxFLAGS_MEMBER(wxVSCROLL)
-    wxFLAGS_MEMBER(wxHSCROLL)
-
-    wxFLAGS_MEMBER(wxDIRCTRL_DIR_ONLY)
-    wxFLAGS_MEMBER(wxDIRCTRL_3D_INTERNAL)
-    wxFLAGS_MEMBER(wxDIRCTRL_SELECT_FIRST)
-    wxFLAGS_MEMBER(wxDIRCTRL_MULTIPLE)
-
-wxEND_FLAGS( wxGenericDirCtrlStyle )
-
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxGenericDirCtrl, wxControl,"wx/dirctrl.h")
-
-wxBEGIN_PROPERTIES_TABLE(wxGenericDirCtrl)
-    wxHIDE_PROPERTY( Children )
-    wxPROPERTY( DefaultPath , wxString , SetDefaultPath , GetDefaultPath  , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
-    wxPROPERTY( Filter , wxString , SetFilter , GetFilter  , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
-    wxPROPERTY( DefaultFilter , int , SetFilterIndex, GetFilterIndex, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
-    wxPROPERTY_FLAGS( WindowStyle, wxGenericDirCtrlStyle, long, SetWindowStyleFlag, GetWindowStyleFlag, EMPTY_MACROVALUE , 0, wxT("Helpstring"), wxT("group") )
-wxEND_PROPERTIES_TABLE()
-
-wxBEGIN_HANDLERS_TABLE(wxGenericDirCtrl)
-wxEND_HANDLERS_TABLE()
-
-wxCONSTRUCTOR_8( wxGenericDirCtrl , wxWindow* , Parent , wxWindowID , Id , wxString , DefaultPath ,
-                 wxPoint , Position , wxSize , Size , long , WindowStyle , wxString , Filter , int , DefaultFilter )
-#else
-IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl, wxControl)
-#endif
-
 BEGIN_EVENT_TABLE(wxGenericDirCtrl, wxControl)
   EVT_TREE_ITEM_EXPANDING     (wxID_TREECTRL, wxGenericDirCtrl::OnExpandItem)
   EVT_TREE_ITEM_COLLAPSED     (wxID_TREECTRL, wxGenericDirCtrl::OnCollapseItem)
@@ -761,14 +702,9 @@ void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event)
     //     ctor when wxTR_HIDE_ROOT was specified
 
     if (!m_rootId.IsOk())
-
         m_rootId = m_treeCtrl->GetRootItem();
 
     ExpandDir(parentId);
-    if ( m_treeCtrl->GetChildrenCount(parentId, false) == 0 )
-    {
-        m_treeCtrl->SetItemHasChildren(parentId, false);
-    }
 }
 
 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent &event )
@@ -785,22 +721,15 @@ void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId)
         return;
 
     data->m_isExpanded = false;
-    wxTreeItemIdValue cookie;
-    /* Workaround because DeleteChildren has disapeared (why?) and
-     * CollapseAndReset doesn't work as advertised (deletes parent too) */
-    child = m_treeCtrl->GetFirstChild(parentId, cookie);
-    while (child.IsOk())
-    {
-        m_treeCtrl->Delete(child);
-        /* Not GetNextChild below, because the cookie mechanism can't
-         * handle disappearing children! */
-        child = m_treeCtrl->GetFirstChild(parentId, cookie);
-    }
+
+    m_treeCtrl->Freeze();
     if (parentId != m_treeCtrl->GetRootItem())
-        m_treeCtrl->Collapse(parentId);
+        m_treeCtrl->CollapseAndReset(parentId);
+    m_treeCtrl->DeleteChildren(parentId);
+    m_treeCtrl->Thaw();
 }
 
-void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
+void wxGenericDirCtrl::PopulateNode(wxTreeItemId parentId)
 {
     wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(parentId);
 
@@ -899,6 +828,10 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
         filenames.Sort(wxDirCtrlStringCompareFunction);
     }
 
+    // Now we really know whether we have any children so tell the tree control
+    // about it.
+    m_treeCtrl->SetItemHasChildren(parentId, !dirs.empty() || !filenames.empty());
+
     // Add the sorted dirs
     size_t i;
     for (i = 0; i < dirs.GetCount(); i++)
@@ -918,7 +851,7 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
         // assume that it does have children by default as it can take a long
         // time to really check for this (think remote drives...)
         //
-        // and if we're wrong, we'll correct it later in OnExpandItem() if
+        // and if we're wrong, we'll correct the icon later if
         // the user really tries to open this item
         m_treeCtrl->SetItemHasChildren(id);
     }
@@ -943,6 +876,12 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
     }
 }
 
+void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
+{
+    // ExpandDir() will not actually expand the tree node, just populate it
+    PopulateNode(parentId);
+}
+
 void wxGenericDirCtrl::ReCreateTree()
 {
     CollapseDir(m_treeCtrl->GetRootItem());
@@ -1102,6 +1041,22 @@ bool wxGenericDirCtrl::CollapsePath(const wxString& path)
 
 wxString wxGenericDirCtrl::GetPath() const
 {
+    // Allow calling GetPath() in multiple selection from OnSelFilter
+    if (m_treeCtrl->HasFlag(wxTR_MULTIPLE))
+    {
+        wxArrayTreeItemIds items;
+        m_treeCtrl->GetSelections(items);
+        if (items.size() > 0)
+        {
+            // return first string only
+            wxTreeItemId id = items[0];
+            wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(id);
+            return data->m_path;
+        }
+
+        return wxEmptyString;
+    }
+
     wxTreeItemId id = m_treeCtrl->GetSelection();
     if (id)
     {
@@ -1179,12 +1134,7 @@ void wxGenericDirCtrl::SelectPath(const wxString& path, bool select)
 
     if ( done )
     {
-        if(select && m_treeCtrl->IsSelected(id))
-            return;
-        else
-        {
-            m_treeCtrl->SelectItem(id, select);
-        }
+        m_treeCtrl->SelectItem(id, select);
     }
 }
 
@@ -1391,16 +1341,33 @@ void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent& WXUNUSED(event))
 {
     int sel = GetSelection();
 
-    wxString currentPath = m_dirCtrl->GetPath();
+    if (m_dirCtrl->HasFlag(wxDIRCTRL_MULTIPLE))
+    {
+        wxArrayString paths;
+        m_dirCtrl->GetPaths(paths);
+
+        m_dirCtrl->SetFilterIndex(sel);
+
+        // If the filter has changed, the view is out of date, so
+        // collapse the tree.
+        m_dirCtrl->ReCreateTree();
 
-    m_dirCtrl->SetFilterIndex(sel);
+        // Expand and select the previously selected paths
+        for (unsigned int i = 0; i < paths.GetCount(); i++)
+        {
+            m_dirCtrl->ExpandPath(paths.Item(i));
+        }
+    }
+    else
+    {
+        wxString currentPath = m_dirCtrl->GetPath();
 
-    // If the filter has changed, the view is out of date, so
-    // collapse the tree.
-    m_dirCtrl->ReCreateTree();
+        m_dirCtrl->SetFilterIndex(sel);
+        m_dirCtrl->ReCreateTree();
 
-    // Try to restore the selection, or at least the directory
-    m_dirCtrl->ExpandPath(currentPath);
+        // Try to restore the selection, or at least the directory
+        m_dirCtrl->ExpandPath(currentPath);
+    }
 }
 
 void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilter)
@@ -1426,7 +1393,7 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt
 
 #ifndef __WXGTK20__
 /* Computer (c) Julian Smart */
-static const char * file_icons_tbl_computer_xpm[] = {
+static const char* const file_icons_tbl_computer_xpm[] = {
 /* columns rows colors chars-per-pixel */
 "16 16 42 1",
 "r c #4E7FD0",
@@ -1508,11 +1475,7 @@ public:
     bool OnInit() { wxTheFileIconsTable = new wxFileIconsTable; return true; }
     void OnExit()
     {
-        if (wxTheFileIconsTable)
-        {
-            delete wxTheFileIconsTable;
-            wxTheFileIconsTable = NULL;
-        }
+        wxDELETE(wxTheFileIconsTable);
     }
 };
 
@@ -1587,14 +1550,14 @@ void wxFileIconsTable::Create()
                                                    wxART_CMN_DIALOG,
                                                    wxSize(16, 16)));
     // executable
-    if (GetIconID(wxEmptyString, _T("application/x-executable")) == file)
+    if (GetIconID(wxEmptyString, wxT("application/x-executable")) == file)
     {
         m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE,
                                                        wxART_CMN_DIALOG,
                                                        wxSize(16, 16)));
-        delete m_HashTable->Get(_T("exe"));
-        m_HashTable->Delete(_T("exe"));
-        m_HashTable->Put(_T("exe"), new wxFileIconEntry(executable));
+        delete m_HashTable->Get(wxT("exe"));
+        m_HashTable->Delete(wxT("exe"));
+        m_HashTable->Put(wxT("exe"), new wxFileIconEntry(executable));
     }
     /* else put into list by GetIconID
        (KDE defines application/x-executable for *.exe and has nice icon)