/** * @file XTPShellListBase.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPSHELLLISTBASE_H__) # define __XTPSHELLLISTBASE_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPDirWatcher; /** * @brief * CXTPShellListBase is a multiple inheritance class derived from CXTPListView * and CXTPShellPidl. It is used to create a CXTPShellListBase class object. */ class _XTP_EXT_CLASS CXTPShellListBase : public CXTPListBase , public CXTPShellPidl { public: /** * @brief * Constructs a CXTPShellListBase object. */ CXTPShellListBase(); /** * @brief * Destroys a CXTPShellListBase object, handles cleanup and deallocation. */ virtual ~CXTPShellListBase(); public: /** * @brief * Call this member function to enable/disable the display of the * shell context menu on the right click of the item. * @param bEnable TRUE to enable the display of the shell context menu. */ virtual void EnableContextMenu(BOOL bEnable); /** * @brief * Call this member function to determine the type of items included in the * shell enumeration. The default is SHCONTF_FOLDERS | SHCONTF_NONFOLDERS. * @param uFlags Determines the type of items included in an enumeration and can * be one or more of the flags listed in the Remarks section. * @details * Styles to be added or removed can be combined by using the bitwise * OR (|) operator. It can be one or more of the following:
* SHCONTF_FOLDERS: Include items that are folders in * the enumeration. * SHCONTF_NONFOLDERS: Include items that are not folders * in the enumeration. * SHCONTF_INCLUDEHIDDEN: Include hidden items in the * enumeration. * SHCONTF_INIT_ON_FIRST_NEXT: IShellFolder::EnumObjects can return * without validating the enumeration * object. Validation can be postponed * until the first call to IEnumIDList::Next. * This flag is intended to be used when * a user interface may be displayed prior * to the first IEnumIDList::Next call. * For a user interface to be presented, * 'hwndOwner' must be set to a valid * window handle. * SHCONTF_NETPRINTERSRCH: The caller is looking for * printer objects. */ virtual void SetEnumFlags(UINT uFlags); /** * @brief * This member function associates the system image list with the list * control. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL InitSystemImageLists(); /** * @brief * This member function populates the list view control. * @param lptvid Pointer to TreeView item data. * @param lpsf Pointer to the parent shell folder. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL PopulateListView(XTP_TVITEMDATA* lptvid, LPSHELLFOLDER lpsf); /** * @brief * This member function returns the index of the list view item that * was double clicked on. * @return * The index of the item that was double clicked, * or -1 if the item was not found. */ virtual int GetDoubleClickedItem(); /** * @brief * This member function displays the system pop-up menu for the selected * item or folder. * @param pos Position to show. */ virtual void ShowShellContextMenu(CPoint pos); /** * @brief * This member function executes the item clicked on * in the list control via the Shell. * @param iItem Index of the list view item clicked on. * @return * true if successful, otherwise false. */ virtual bool ShellOpenItem(int iItem); /** * @brief * This member function executes the item clicked on * in the list control via the Shell. * @param lplvid Pointer to the list view item data. * @return * true if successful, otherwise false. */ virtual bool ShellOpenItem(XTP_LVITEMDATA* lplvid); /** * @brief * This member function retrieves the path for the specified list view * item. * @param iItem Index of the list view item to get the path of. * @param strItemPath Reference to a CString object that receives the path string. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL GetItemPath(int iItem, CString& strItemPath); /** * @brief * This member function creates default columns for the list view. */ virtual void BuildDefaultColumns(); /** * @brief * Override this member function in your derived class to perform custom * sort routines. * @param nCol Passed in from the control. The index of the column clicked. * @param bAscending Passed in from the control. true if the sort order should be ascending. * @return * true if successful, otherwise false. */ virtual bool SortList(int nCol, bool bAscending); /** * @brief * Used by the shell list control to handle a drag drop event. * @param pNMListView Pointer to a NM_LISTVIEW structure. */ virtual void OnDragDrop(NM_LISTVIEW* pNMListView); /** * @brief * Called by the shell list control to insert commas into the specified * numeric value. The result is then returned in the szBufferOut item. An * example of this would be to format a file size 1,024 KB. * @param value [in] Numeric value to insert commas. * @param szBuffer [out] String buffer to receive the formatted string. * @param nSize [in] Size of the string specified by szBuffer. * @return * A string representing a comma separated numeric value. */ virtual TCHAR* InsertCommas(LONGLONG value, TCHAR* szBuffer, UINT nSize); /** * @brief * Call this member function to define a file filter for the files * displayed. Only the files specified by pFilters will be displayed * in the shell list. File extensions are separated by a semi-colon. * Call SetIncludeExtensions(NULL); to restore normal file display. * @param lpszFilters NULL-terminated string representing files to be displayed * in the shell list control. * Example: *
* SetIncludeExtensions(_T("*.wav;*.mp3;*.aif;*.wmv"));
*
*/
virtual void SetIncludeExtensions(LPCTSTR lpszFilters = NULL);
/**
* @brief
* Call this member function to refresh the values for the shell
* settings and compressed colors that are used by the list control.
* @return
* TRUE if shell compressed color display is enabled, otherwise FALSE.
*/
BOOL RefreshRowColors();
/**
* @brief
* Call this member function to enable explorer style for the list.
*/
void SetExplorerStyle();
protected:
/**
* @brief
* This member function is called by the CXTPShellListBase class to
* perform initialization when the window is created or sub-classed.
* @return
* TRUE if the window was successfully initialized, otherwise FALSE.
*/
virtual bool Init();
/**
* @brief
* This member function adds items to the list view.
* @param lptvid Pointer to tree view item data.
* @param lpsf Pointer to the parent shell folder.
* @return
* TRUE if successful, otherwise FALSE.
*/
virtual BOOL InitListViewItems(XTP_TVITEMDATA* lptvid, LPSHELLFOLDER lpsf);
/**
* @brief
* This member function gets the index for the normal and selected
* icons of the current item.
* @param lpifq Fully qualified item ID list for the current item.
* @param lptvitem Pointer to the tree view item that is about to be added to the tree.
*/
virtual void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem);
/**
* @brief
* This member function sets the shell attribute flags for the specified
* list item.
* @param iItem Index of the item to set the attributes for.
* @param dwAttributes Flags retrieved from SHELLFOLDER::GetAttributesOf.
*/
virtual void SetAttributes(int iItem, DWORD dwAttributes);
/**
* @brief
* This member function determines if an item is filtered. You can
* override it in your class.
* @param lpszItemName Friendly name for the folder or file.
* @param ulItemAttrs Attributes of the item.
* @return
* TRUE if the item is filtered, otherwise FALSE.
*/
virtual BOOL IsItemFiltered(LPCTSTR lpszItemName, ULONG ulItemAttrs);
protected:
/** @cond */
//{{AFX_VIRTUAL(CXTPShellListBase)
virtual void UpdateList(int nMessage, XTP_TVITEMDATA* pItemData);
//}}AFX_VIRTUAL
//{{AFX_MSG(CXTPShellListBase)
afx_msg void OnDeleteListItem(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
/** @endcond */
private:
static void InitLocaleFormats();
protected:
int m_nNameColumnWidth; /**< Size in pixels for the name column width. */
UINT m_uFlags; /**< Flags indicating which items to include in the enumeration. */
BOOL m_bContextMenu; /**< TRUE to display the shell context menu on right item click. */
LPITEMIDLIST m_pidlINet; /**< Pointer to the CSIDL_INTERNET folder location. */
CString m_csIncludeEXT; /**< Comma delimited string of extensions to include in file display. */
CXTPDirWatcher* m_pDirThread; /**< Thread used to monitor directory activity. */
CXTPShellSettings m_shSettings; /**< Contains SHELLFLAGSTATE info. */
LPSHELLFOLDER m_lpsfFolder; /**< Represents the parent IShellFolder interface. */
private:
static CString m_strDateFormat;
static CString m_strTimeFormat;
};
//////////////////////////////////////////////////////////////////////
/** @cond */
AFX_INLINE void CXTPShellListBase::SetEnumFlags(UINT uFlags)
{
m_uFlags = uFlags;
}
AFX_INLINE void CXTPShellListBase::EnableContextMenu(BOOL bEnable)
{
m_bContextMenu = bEnable;
}
AFX_INLINE void CXTPShellListBase::SetIncludeExtensions(LPCTSTR lpszFilters)
{
m_csIncludeEXT = lpszFilters;
}
/** @endcond */
/** @cond */
# define DECLARE_SHELLLIST_BASE(ClassName, List, Base) \
DECLARE_LIST_BASE(Base##List, List, Base) \
class _XTP_EXT_CLASS ClassName : public Base##List \
{ \
protected: \
void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) \
{ \
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; \
OnDragDrop(pNMListView); \
*pResult = 0; \
} \
void OnDeleteListItem(NMHDR* pNMHDR, LRESULT* pResult) \
{ \
Base::OnDeleteListItem(pNMHDR, pResult); \
} \
void OnContextMenu(CWnd* pWnd, CPoint pos) \
{ \
if (m_bContextMenu) \
ShowShellContextMenu(pos); \
else \
List::OnContextMenu(pWnd, pos); \
} \
};
# define ON_SHELLLIST_REFLECT \
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk) \
ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag) \
ON_NOTIFY_REFLECT(LVN_BEGINRDRAG, OnBeginDrag) \
ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnDeleteListItem) \
ON_WM_CONTEXTMENU() \
ON_LISTCTRL_REFLECT
/** @endcond */
# include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h"
/** @cond */
#endif // __XTPSHELLLISTBASE_H__
/** @endcond */