merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / subsys / system / explorer / shell / entries.cpp
index 38adda1..ab75f9d 100644 (file)
@@ -18,7 +18,7 @@
 
 
  //
 
 
  //
- // Explorer clone, lean version
+ // Explorer clone
  //
  // entries.cpp
  //
  //
  // entries.cpp
  //
@@ -28,6 +28,8 @@
 
 #include "precomp.h"
 
 
 #include "precomp.h"
 
+//#include "entries.h"
+
 
  // allocate and initialise a directory entry
 Entry::Entry(ENTRY_TYPE etype)
 
  // allocate and initialise a directory entry
 Entry::Entry(ENTRY_TYPE etype)
@@ -108,35 +110,33 @@ Entry::~Entry()
 
 
  // read directory tree and expand to the given location
 
 
  // read directory tree and expand to the given location
-Entry* Entry::read_tree(const void* path, SORT_ORDER sortOrder)
+Entry* Entry::read_tree(const void* path, SORT_ORDER sortOrder, int scan_flags)
 {
        CONTEXT("Entry::read_tree()");
 
 {
        CONTEXT("Entry::read_tree()");
 
-       HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
+       WaitCursor wait;
 
        Entry* entry = this;
 
        for(const void*p=path; p && entry; ) {
 
        Entry* entry = this;
 
        for(const void*p=path; p && entry; ) {
-               entry->read_directory(sortOrder);
+               entry->smart_scan(sortOrder, scan_flags);
 
                if (entry->_down)
                        entry->_expanded = true;
 
 
                if (entry->_down)
                        entry->_expanded = true;
 
-               Entry* next_entry = entry->find_entry(p);
+               Entry* found = entry->find_entry(p);
                p = entry->get_next_path_component(p);
 
                p = entry->get_next_path_component(p);
 
-               entry = next_entry;
+               entry = found;
        }
 
        }
 
-       SetCursor(old_cursor);
-
        return entry;
 }
 
 
        return entry;
 }
 
 
-void Entry::read_directory(SORT_ORDER sortOrder, int scan_flags)
+void Entry::read_directory_base(SORT_ORDER sortOrder, int scan_flags)
 {
 {
-       CONTEXT("Entry::read_directory(SORT_ORDER)");
+       CONTEXT("Entry::read_directory_base()");
 
         // call into subclass
        read_directory(scan_flags);
 
         // call into subclass
        read_directory(scan_flags);
@@ -308,13 +308,13 @@ void Entry::sort_directory(SORT_ORDER sortOrder)
 }
 
 
 }
 
 
-void Entry::smart_scan(int scan_flags)
+void Entry::smart_scan(SORT_ORDER sortOrder, int scan_flags)
 {
        CONTEXT("Entry::smart_scan()");
 
        if (!_scanned) {
                free_subentries();
 {
        CONTEXT("Entry::smart_scan()");
 
        if (!_scanned) {
                free_subentries();
-               read_directory(SORT_NAME, scan_flags);  // we could use IShellFolder2::GetDefaultColumn to determine sort order
+               read_directory_base(sortOrder, scan_flags);     ///@todo We could use IShellFolder2::GetDefaultColumn to determine sort order.
        }
 }
 
        }
 }
 
@@ -325,7 +325,7 @@ void Entry::extract_icon()
 
        ICON_ID icon_id = ICID_NONE;
 
 
        ICON_ID icon_id = ICID_NONE;
 
-       if (get_path(path))
+       if (get_path(path) && _tcsncmp(path,TEXT("::{"),3))
                icon_id = g_Globals._icon_cache.extract(path);
 
        if (icon_id == ICID_NONE) {
                icon_id = g_Globals._icon_cache.extract(path);
 
        if (icon_id == ICID_NONE) {
@@ -398,11 +398,57 @@ BOOL Entry::launch_entry(HWND hwnd, UINT nCmdShow)
         // add path to the recent file list
        SHAddToRecentDocs(SHARD_PATH, cmd);
 
         // add path to the recent file list
        SHAddToRecentDocs(SHARD_PATH, cmd);
 
-        // start program, open document...
+         // start program, open document...
        return launch_file(hwnd, cmd, nCmdShow);
 }
 
 
        return launch_file(hwnd, cmd, nCmdShow);
 }
 
 
+HRESULT Entry::do_context_menu(HWND hwnd, const POINT& pos, CtxMenuInterfaces& cm_ifs)
+{
+       ShellPath shell_path = create_absolute_pidl();
+       LPCITEMIDLIST pidl_abs = shell_path;
+
+       if (!pidl_abs)
+               return S_FALSE; // no action for registry entries, etc.
+
+       static DynamicFct<HRESULT(WINAPI*)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*)> SHBindToParent(TEXT("SHELL32"), "SHBindToParent");
+
+       if (SHBindToParent) {
+               IShellFolder* parentFolder;
+               LPCITEMIDLIST pidlLast;
+
+                // get and use the parent folder to display correct context menu in all cases -> correct "Properties" dialog for directories, ...
+               HRESULT hr = (*SHBindToParent)(pidl_abs, IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast);
+
+               if (SUCCEEDED(hr)) {
+                       hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pos.x, pos.y, cm_ifs);
+
+                       parentFolder->Release();
+               }
+
+               return hr;
+       } else {
+               /**@todo use parent folder instead of desktop folder
+               Entry* dir = _up;
+
+               ShellPath parent_path;
+
+               if (dir)
+                       parent_path = dir->create_absolute_pidl();
+               else
+                       parent_path = DesktopFolderPath();
+
+               ShellPath shell_path = create_relative_pidl(parent_path);
+               LPCITEMIDLIST pidl = shell_path;
+
+               ShellFolder parent_folder = parent_path;
+               return ShellFolderContextMenu(parent_folder, hwnd, 1, &pidl, pos.x, pos.y);
+               */
+               return ShellFolderContextMenu(GetDesktopFolder(), hwnd, 1, &pidl_abs, pos.x, pos.y, cm_ifs);
+       }
+}
+
+
 HRESULT Entry::GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut)
 {
        TCHAR path[MAX_PATH];
 HRESULT Entry::GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut)
 {
        TCHAR path[MAX_PATH];
@@ -477,3 +523,28 @@ void Entry::free_subentries()
                } while(next);
        }
 }
                } while(next);
        }
 }
+
+
+Entry* Root::read_tree(LPCTSTR path, int scan_flags)
+{
+       Entry* entry;
+
+       if (path && *path)
+               entry = _entry->read_tree(path, _sort_order);
+       else {
+               entry = _entry->read_tree(NULL, _sort_order);
+
+               _entry->smart_scan();
+
+               if (_entry->_down)
+                       _entry->_expanded = true;
+       }
+
+       return entry;
+}
+
+
+Entry* Root::read_tree(LPCITEMIDLIST pidl, int scan_flags)
+{
+       return _entry->read_tree(pidl, _sort_order);
+}