]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dirctrlg.cpp
wxVariant is in wxBase so should be forward declared using WXDLLIMPEXP_BASE and not...
[wxWidgets.git] / src / generic / dirctrlg.cpp
index 9b12eb10d139d1c11420c6df7c6d668628f2253b..7c88c16a7cd5fb2bd94154788ef714a3f3379095 100644 (file)
@@ -57,6 +57,7 @@
 
 #ifdef __WXMSW__
 #include <windows.h>
+#include "wx/msw/winundef.h"
 
 // FIXME - Mingw32 1.0 has both _getdrive() and _chdrive(). For now, let's assume
 //         older releases don't, but it should be verified and the checks modified
@@ -166,9 +167,19 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
                 path.Printf(wxT("%c:\\"), 'A' + i);
                 name.Printf(wxT("%c:"), 'A' + i);
 
+                // Note: If _filesys is unsupported by some compilers,
+                //       we can always replace it by DosQueryFSAttach
+                char filesysname[20];
+                _filesys(name.fn_str(), filesysname, sizeof(filesysname));
+                /* FAT, LAN, HPFS, CDFS, NFS */
                 int imageId;
                 if (path == wxT("A:\\") || path == wxT("B:\\"))
                     imageId = wxFileIconsTable::floppy;
+                else if (!strcmp(filesysname, "CDFS"))
+                    imageId = wxFileIconsTable::cdrom;
+                else if (!strcmp(filesysname, "LAN") ||
+                         !strcmp(filesysname, "NFS"))
+                    imageId = wxFileIconsTable::drive;
                 else
                     imageId = wxFileIconsTable::drive;
                 paths.Add(path);
@@ -258,7 +269,7 @@ bool wxIsDriveAvailable(const wxString& dirName)
         //     like it when MS-DOS app accesses empty floppy drive
         return (dirNameLower[0u] == wxT('a') ||
                 dirNameLower[0u] == wxT('b') ||
-                wxPathExists(dirNameLower));
+                wxDirExists(dirNameLower));
     }
     else
 #endif
@@ -267,10 +278,9 @@ bool wxIsDriveAvailable(const wxString& dirName)
 
 #elif defined(__WINDOWS__) || defined(__OS2__)
 
-int setdrive(int drive)
+int setdrive(int WXUNUSED_IN_WINCE(drive))
 {
 #ifdef __WXWINCE__
-    wxUnusedVar(drive);
     return 0;
 #elif defined(__GNUWIN32__) && \
     (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
@@ -300,10 +310,9 @@ int setdrive(int drive)
 #endif // !GNUWIN32
 }
 
-bool wxIsDriveAvailable(const wxString& dirName)
+bool wxIsDriveAvailable(const wxString& WXUNUSED_IN_WINCE(dirName))
 {
 #ifdef __WXWINCE__
-    wxUnusedVar(dirName);
     return false;
 #else
 #ifdef __WIN32__
@@ -317,7 +326,7 @@ bool wxIsDriveAvailable(const wxString& dirName)
     {
         wxString dirNameLower(dirName.Lower());
 #if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
-        success = wxPathExists(dirNameLower);
+        success = wxDirExists(dirNameLower);
 #else
         #if defined(__OS2__)
         // Avoid changing to drive since no media may be inserted.
@@ -486,6 +495,26 @@ wxGenericDirCtrl::wxGenericDirCtrl(void)
     Init();
 }
 
+void wxGenericDirCtrl::ExpandRoot()
+{
+    ExpandDir(m_rootId); // automatically expand first level
+
+    // Expand and select the default path
+    if (!m_defaultPath.empty())
+    {
+        ExpandPath(m_defaultPath);
+    }
+#ifdef __UNIX__
+    else
+    {
+        // On Unix, there's only one node under the (hidden) root node. It
+        // represents the / path, so the user would always have to expand it;
+        // let's do it ourselves
+        ExpandPath( wxT("/") );
+    }
+#endif
+}
+
 bool wxGenericDirCtrl::Create(wxWindow *parent,
                               const wxWindowID id,
                               const wxString& dir,
@@ -503,8 +532,14 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
 
     Init();
 
-    long treeStyle = wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT;
-    
+    long treeStyle = wxTR_HAS_BUTTONS;
+
+    // On Windows CE, if you hide the root, you get a crash when
+    // attempting to access data for children of the root item.
+#ifndef __WXWINCE__
+    treeStyle |= wxTR_HIDE_ROOT;
+#endif
+
 #ifdef __WXGTK20__
     treeStyle |= wxTR_NO_LINES;
 #endif
@@ -532,6 +567,13 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
     m_defaultPath = dir;
     m_filter = filter;
 
+    if (m_filter.empty())
+#ifdef __UNIX__
+        m_filter = wxT("*");
+#else
+        m_filter = wxT("*.*");
+#endif
+
     SetFilterIndex(defaultFilter);
 
     if (m_filterListCtrl)
@@ -552,22 +594,8 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
 
     m_rootId = m_treeCtrl->AddRoot( rootName, 3, -1, rootData);
     m_treeCtrl->SetItemHasChildren(m_rootId);
-    ExpandDir(m_rootId); // automatically expand first level
-    
-    // Expand and select the default path
-    if (!m_defaultPath.empty())
-    {
-        ExpandPath(m_defaultPath);
-    }
-#ifdef __UNIX__
-    else
-    {
-        // On Unix, there's only one node under the (hidden) root node. It
-        // represents the / path, so the user would always have to expand it;
-        // let's do it ourselves
-        ExpandPath( wxT("/") );
-    }
-#endif
+
+    ExpandRoot();
 
     SetBestSize(size);
     DoResize();
@@ -732,6 +760,8 @@ void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId)
          * handle disappearing children! */
         child = m_treeCtrl->GetFirstChild(parentId, cookie);
     }
+    if (parentId != m_treeCtrl->GetRootItem())
+        m_treeCtrl->Collapse(parentId);
 }
 
 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
@@ -755,7 +785,7 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
 
     wxString dirName(data->m_path);
 
-#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
+#if (defined(__WINDOWS__) && !defined(__WXWINCE__)) || defined(__DOS__) || defined(__OS2__)
     // Check if this is a root directory and if so,
     // whether the drive is avaiable.
     if (!wxIsDriveAvailable(dirName))
@@ -819,7 +849,7 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
             while(strTok.HasMoreTokens())
             {
                 curFilter = strTok.GetNextToken();
-                if (d.GetFirst(& eachFilename, m_currentFilterStr, style))
+                if (d.GetFirst(& eachFilename, curFilter, style))
                 {
                     do
                     {
@@ -886,7 +916,18 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
 void wxGenericDirCtrl::ReCreateTree()
 {
     CollapseDir(m_treeCtrl->GetRootItem());
-    ExpandDir(m_treeCtrl->GetRootItem());
+    ExpandRoot();
+}
+
+void wxGenericDirCtrl::CollapseTree()
+{
+    wxTreeItemIdValue cookie;
+    wxTreeItemId child = m_treeCtrl->GetFirstChild(m_rootId, cookie);
+    while (child.IsOk())
+    {
+        CollapseDir(child);
+        child = m_treeCtrl->GetNextChild(m_rootId, cookie);
+    }
 }
 
 // Find the child that matches the first part of 'path'.
@@ -1089,7 +1130,11 @@ void wxGenericDirCtrl::SetFilterIndex(int n)
     if (ExtractWildcard(m_filter, n, f, d))
         m_currentFilterStr = f;
     else
+#ifdef __UNIX__
+        m_currentFilterStr = wxT("*");
+#else
         m_currentFilterStr = wxT("*.*");
+#endif
 }
 
 void wxGenericDirCtrl::SetFilter(const wxString& filter)
@@ -1100,7 +1145,11 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter)
     if (ExtractWildcard(m_filter, m_currentFilter, f, d))
         m_currentFilterStr = f;
     else
+#ifdef __UNIX__
+        m_currentFilterStr = wxT("*");
+#else
         m_currentFilterStr = wxT("*.*");
+#endif
 }
 
 // Extract description and actual filter from overall filter string
@@ -1253,32 +1302,72 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt
 // wxFileIconsTable icons
 // ----------------------------------------------------------------------------
 
-/* Computer */
+#ifndef __WXGTK24__
+/* Computer (c) Julian Smart */
 static const char * file_icons_tbl_computer_xpm[] = {
-"16 16 7 1",
-"     s None    c None",
-".    c #808080",
-"X    c #c0c0c0",
-"o    c Black",
-"O    c Gray100",
-"+    c #008080",
-"@    c Blue",
-"    ........... ",
-"   .XXXXXXXXXX.o",
-"   .OOOOOOOOO..o",
-"   .OoooooooX..o",
-"   .Oo+...@+X..o",
-"   .Oo+XXX.+X..o",
-"   .Oo+....+X..o",
-"   .Oo++++++X..o",
-"   .OXXXXXXXX.oo",
-"   ..........o.o",
-"   ...........Xo",
-"   .XXXXXXXXXX.o",
-"  .o.o.o.o.o...o",
-" .oXoXoXoXoXo.o ",
-".XOXXXXXXXXX.o  ",
-"............o   "};
+/* columns rows colors chars-per-pixel */
+"16 16 42 1",
+"r c #4E7FD0",
+"$ c #7198D9",
+"; c #DCE6F6",
+"q c #FFFFFF",
+"u c #4A7CCE",
+"# c #779DDB",
+"w c #95B2E3",
+"y c #7FA2DD",
+"f c #3263B4",
+"= c #EAF0FA",
+"< c #B1C7EB",
+"% c #6992D7",
+"9 c #D9E4F5",
+"o c #9BB7E5",
+"6 c #F7F9FD",
+", c #BED0EE",
+"3 c #F0F5FC",
+"1 c #A8C0E8",
+"  c None",
+"0 c #FDFEFF",
+"4 c #C4D5F0",
+"@ c #81A4DD",
+"e c #4377CD",
+"- c #E2EAF8",
+"i c #9FB9E5",
+"> c #CCDAF2",
+"+ c #89A9DF",
+"s c #5584D1",
+"t c #5D89D3",
+": c #D2DFF4",
+"5 c #FAFCFE",
+"2 c #F5F8FD",
+"8 c #DFE8F7",
+"& c #5E8AD4",
+"X c #638ED5",
+"a c #CEDCF2",
+"p c #90AFE2",
+"d c #2F5DA9",
+"* c #5282D0",
+"7 c #E5EDF9",
+". c #A2BCE6",
+"O c #8CACE0",
+/* pixels */
+"                ",
+"  .XXXXXXXXXXX  ",
+"  oXO++@#$%&*X  ",
+"  oX=-;:>,<1%X  ",
+"  oX23=-;:4,$X  ",
+"  oX5633789:@X  ",
+"  oX05623=78+X  ",
+"  oXqq05623=OX  ",
+"  oX,,,,,<<<$X  ",
+"  wXXXXXXXXXXe  ",
+"  XrtX%$$y@+O,, ",
+"  uyiiiiiiiii@< ",
+" ouiiiiiiiiiip<a",
+" rustX%$$y@+Ow,,",
+" dfffffffffffffd",
+"                "
+};
+#endif // GTK+ < 2.4
 
 // ----------------------------------------------------------------------------
 // wxFileIconsTable & friends