2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* TreeView control containing Windows shell folders.
|
|
|
|
*
|
|
|
|
* Originally based on MFCENUM from "Programming the Windows 95 User
|
|
|
|
* interface". Enhanced by Selom Ofori as "ShellTree" class. Modified
|
|
|
|
* extensively.
|
|
|
|
*/
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 15:32:55 -08:00
|
|
|
#ifndef UTIL_SHELLTREE_H
|
|
|
|
#define UTIL_SHELLTREE_H
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ShellTree class.
|
|
|
|
*/
|
|
|
|
class ShellTree : public CTreeCtrl {
|
|
|
|
public:
|
2014-11-03 16:26:53 -08:00
|
|
|
//enum FindAttribs {type_drive, type_folder};
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-03 16:26:53 -08:00
|
|
|
ShellTree(void) {
|
|
|
|
fFolderPathValid = false;
|
|
|
|
}
|
|
|
|
virtual ~ShellTree(void) {
|
|
|
|
Detach(); // we don't own the window handle
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-25 14:34:14 -08:00
|
|
|
/*
|
|
|
|
* Replace a CTreeCtrl in a dialog box with us. All of the styles are
|
|
|
|
* copied from the original dialog window.
|
|
|
|
*
|
|
|
|
* Returns TRUE on success, FALSE on failure.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL ReplaceDlgCtrl(CDialog* pDialog, int treeID);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Populate the tree, starting from "nFolder".
|
|
|
|
*
|
|
|
|
* Returns TRUE on success, FALSE on failure.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL PopulateTree(int nFolder = CSIDL_DESKTOP);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open up and select My Computer.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void ExpandMyComputer(void);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new folder to the tree at the currently-selected node. This may
|
|
|
|
* not actually add a folder if the new folder is at a point in the tree
|
|
|
|
* below where we have already expanded.
|
|
|
|
*
|
|
|
|
* Returns TRUE on success, or FALSE on failure.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL AddFolderAtSelection(const CString& name);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
2014-11-03 16:26:53 -08:00
|
|
|
void GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets a handle to the system image list (by just grabbing whatever is
|
|
|
|
* in place for C:\) and makes it available to the tree control.
|
|
|
|
*
|
|
|
|
* The image list should NOT be deleted.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void EnableImages();
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves the path of the currently selected string.
|
|
|
|
* Pass a CString object that will hold the folder path.
|
|
|
|
* If the path is not in the filesystem(eg MyComputer)
|
|
|
|
* or none is selected it returns false.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL GetSelectedFolderPath(CString &szFolderPath);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves the pointer to the ISHELLFOLDER interface
|
|
|
|
* of the tree node passed as the parameter.
|
|
|
|
*/
|
|
|
|
LPSHELLFOLDER GetParentShellFolder(HTREEITEM folderNode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves the Pointer to an ITEMIDLIST structure that
|
|
|
|
* identifies the subfolder relative to its parent folder.
|
|
|
|
* see GetParentShellFolder();
|
|
|
|
*/
|
|
|
|
LPITEMIDLIST GetRelativeIDLIST(HTREEITEM folderNode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves the Pointer to an ITEMIDLIST
|
|
|
|
* structure that identifies the subfolder relative to the
|
|
|
|
* desktop. This is a fully qualified Item Identifier
|
|
|
|
*/
|
|
|
|
LPITEMIDLIST GetFullyQualifiedID(HTREEITEM folderNode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tunnel into the tree, finding the node that corresponds to the
|
|
|
|
* requested pathname.
|
|
|
|
*
|
|
|
|
* Sets "resultMsg" to a non-empty string on error.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void TunnelTree(CString path, CString* pResultStr);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-03 16:26:53 -08:00
|
|
|
// Get the most-recently-set folder path. This will be updated on
|
|
|
|
// every TVN_SELCHANGED, so add an ON_NOTIFY handler to the parent.
|
|
|
|
BOOL GetFolderPath(CString* pStr) {
|
|
|
|
*pStr = fFolderPath;
|
|
|
|
return fFolderPathValid;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
protected:
|
2014-11-25 14:34:14 -08:00
|
|
|
/*
|
|
|
|
* Respond to TVN_ITEMEXPANDING message.
|
|
|
|
*
|
|
|
|
* If the subtree hasn't been expanded yet, dig in.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle TVN_DELETEITEM notification by cleaning up our stuff.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Respond to TVN_SELCHANGED notification.
|
|
|
|
*/
|
|
|
|
BOOL OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This does the bulk of the work when the selection changes.
|
|
|
|
*
|
|
|
|
* The filesystem path (if any) to the object is placed in "szFolderPath".
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult,
|
|
|
|
CString& szFolderPath);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-25 14:34:14 -08:00
|
|
|
/*
|
|
|
|
* Fills a branch of the TreeView control. Given the shell folder (both as
|
|
|
|
* a shell folder and the fully-qualified item ID list to it) and the parent
|
|
|
|
* item in the tree (TVI_ROOT to start off), add all the kids to the tree.
|
|
|
|
*
|
|
|
|
* Does not try to add the current entry, as a result of which we don't
|
|
|
|
* have a root "Desktop" node that everything is a child of. This is okay.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void FillTreeView(LPSHELLFOLDER lpsf,LPITEMIDLIST lpifq, HTREEITEM hParent);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a node to the tree.
|
|
|
|
*
|
|
|
|
* Returns TRUE on success, FALSE on failure.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
BOOL AddNode(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, LPITEMIDLIST lpifq,
|
|
|
|
unsigned long ulAttrs, HTREEITEM hParent, HTREEITEM* phPrev);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort function callback for TreeView SortChildrenCB.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
static int CALLBACK TreeViewCompareProc(LPARAM, LPARAM, LPARAM);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the TreeView normal and selected icons for the specified entry.
|
|
|
|
*
|
|
|
|
* "lpifq" is the fully-qualified PIDL, LPTV_ITEM is an item in the tree.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the tree entry that corresponds to "My Computer".
|
|
|
|
*
|
|
|
|
* Returns a handle to the tree item, or NULL if My Computer wasn't found
|
|
|
|
* or didn't have any children.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
HTREEITEM FindMyComputer(void);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a pointer to the My Computer node in the tree, find the node
|
|
|
|
* corresponding to the requested drive (which should be of the form
|
|
|
|
* "C:").
|
|
|
|
*
|
|
|
|
* Returns a pointer to the drive's node on success, or NULL on failure.
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
HTREEITEM FindDrive(HTREEITEM myComputer, const CString& drive);
|
2014-11-25 14:34:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a path, search a subtree following the components.
|
|
|
|
*
|
|
|
|
* Pass in the tree's root (it's children will be searched for a
|
|
|
|
* match with the first path component) and the path to look for
|
|
|
|
* (which must start and end with '\\').
|
|
|
|
*/
|
2014-11-03 16:26:53 -08:00
|
|
|
HTREEITEM SearchTree(HTREEITEM treeNode, const CString& path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tree view element. Each one holds a pointer to the ShellFolder
|
|
|
|
* object, a pointer to the ItemIDList for the item within the folder,
|
|
|
|
* and a pointer to the fully-qualified ItemIDList for the item.
|
|
|
|
*/
|
|
|
|
typedef struct TVItemData {
|
|
|
|
LPSHELLFOLDER lpsfParent;
|
|
|
|
LPITEMIDLIST lpi;
|
|
|
|
LPITEMIDLIST lpifq;
|
|
|
|
//bool alphaSort;
|
|
|
|
} TVItemData;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-03 16:26:53 -08:00
|
|
|
CString fFolderPath;
|
|
|
|
BOOL fFolderPathValid;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-03 16:26:53 -08:00
|
|
|
DECLARE_MESSAGE_MAP()
|
2007-03-27 17:47:10 +00:00
|
|
|
};
|
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 15:32:55 -08:00
|
|
|
#endif /*UTIL_SHELLTREE_H*/
|