]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dirctrlg.cpp
Fixed crash caused by A=B?C:D used for returning wxObject derived type.
[wxWidgets.git] / src / generic / dirctrlg.cpp
index ca26e8cc8045c9018dd073046b0c7412d8d695a8..5e1a3ffbfe78a2978439c61959f935ba7f91d98c 100644 (file)
     #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"
+    #include "wx/sizer.h"
+    #include "wx/textdlg.h"
+    #include "wx/gdicmn.h"
+    #include "wx/image.h"
+    #include "wx/module.h"
 #endif
 
-#include "wx/module.h"
-#include "wx/layout.h"
-#include "wx/textctrl.h"
-#include "wx/textdlg.h"
 #include "wx/filefn.h"
-#include "wx/cmndata.h"
-#include "wx/gdicmn.h"
 #include "wx/imaglist.h"
-#include "wx/sizer.h"
 #include "wx/tokenzr.h"
 #include "wx/dir.h"
 #include "wx/artprov.h"
 #include "wx/mimetype.h"
-#include "wx/image.h"
-#include "wx/choice.h"
 
 #if wxUSE_STATLINE
     #include "wx/statline.h"
 #endif
 
 #if defined(__OS2__) || defined(__DOS__)
-  #ifdef __OS2__
-    #define INCL_BASE
-    #include <os2.h>
-    #ifndef __EMX__
-      #include <direct.h>
+    #ifdef __OS2__
+        #define INCL_BASE
+        #include <os2.h>
+        #ifndef __EMX__
+            #include <direct.h>
+        #endif
+        #include <stdlib.h>
+        #include <ctype.h>
     #endif
-    #include <stdlib.h>
-    #include <ctype.h>
-  #endif
-  extern bool wxIsDriveAvailable(const wxString& dirName);
+    extern bool wxIsDriveAvailable(const wxString& dirName);
 #endif // __OS2__
 
 #if defined(__WXMAC__)
@@ -121,14 +121,8 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
         path.Printf(wxT("%c:\\"), driveBuffer[i]);
         name.Printf(wxT("%c:"), driveBuffer[i]);
 
-#if !defined(__WXWINCE__)
-        wxChar pname[52]; // FIXME: why 52 and not MAX_PATH or whatever?
-        if ( GetVolumeInformation(path, pname, WXSIZEOF(pname),
-                                  NULL, NULL, NULL, NULL, 0) )
-        {
-            name << _T(' ') << pname;
-        }
-#endif // __WXWINCE__
+        // Do not use GetVolumeInformation to further decorate the
+        // name, since it can cause severe delays on network drives.
 
         int imageId;
         int driveType = ::GetDriveType(path);
@@ -283,7 +277,7 @@ bool wxIsDriveAvailable(const wxString& dirName)
 #ifdef __WATCOMC__
     wxUnusedVar(dirName);
 #else
-    if ( dirName.Len() == 3 && dirName[1u] == wxT(':') )
+    if ( dirName.length() == 3 && dirName[1u] == wxT(':') )
     {
         wxString dirNameLower(dirName.Lower());
         // VS: always return true for removable media, since Win95 doesn't
@@ -343,7 +337,7 @@ bool wxIsDriveAvailable(const wxString& WXUNUSED_IN_WINCE(dirName))
 
     // Check if this is a root directory and if so,
     // whether the drive is available.
-    if (dirName.Len() == 3 && dirName[(size_t)1] == wxT(':'))
+    if (dirName.length() == 3 && dirName[(size_t)1] == wxT(':'))
     {
         wxString dirNameLower(dirName.Lower());
 #if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
@@ -550,6 +544,7 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
         return false;
 
     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
+    SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
 
     Init();
 
@@ -704,8 +699,8 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event)
         return;
 
     if ((event.GetLabel().empty()) ||
-        (event.GetLabel() == _(".")) ||
-        (event.GetLabel() == _("..")) ||
+        (event.GetLabel() == wxT(".")) ||
+        (event.GetLabel() == wxT("..")) ||
         (event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) ||
         (event.GetLabel().Find(wxT('\\')) != wxNOT_FOUND) ||
         (event.GetLabel().Find(wxT('|')) != wxNOT_FOUND))
@@ -988,12 +983,12 @@ wxTreeItemId wxGenericDirCtrl::FindChild(wxTreeItemId parentId, const wxString&
             childPath.MakeLower();
 #endif
 
-            if (childPath.Len() <= path2.Len())
+            if (childPath.length() <= path2.length())
             {
-                wxString path3 = path2.Mid(0, childPath.Len());
+                wxString path3 = path2.Mid(0, childPath.length());
                 if (childPath == path3)
                 {
-                    if (path3.Len() == path2.Len())
+                    if (path3.length() == path2.length())
                         done = true;
                     else
                         done = false;
@@ -1065,6 +1060,33 @@ bool wxGenericDirCtrl::ExpandPath(const wxString& path)
     return true;
 }
 
+
+bool wxGenericDirCtrl::CollapsePath(const wxString& path)
+{
+    bool done           = false;
+    wxTreeItemId id     = FindChild(m_rootId, path, done);
+    wxTreeItemId lastId = id; // The last non-zero id
+
+    while ( id.IsOk() && !done )
+    {
+        CollapseDir(id);
+
+        id = FindChild(id, path, done);
+
+        if ( id.IsOk() )
+            lastId = id;
+    }
+
+    if ( !lastId.IsOk() )
+        return false;
+
+    m_treeCtrl->SelectItem(lastId);
+    m_treeCtrl->EnsureVisible(lastId);
+
+    return true;
+}
+
+
 wxString wxGenericDirCtrl::GetPath() const
 {
     wxTreeItemId id = m_treeCtrl->GetSelection();