Files
envi-code/SourceCode/Code2026/tg_shs/shs_kerncmd/XMLTreeFileDlgHelper.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

146 lines
3.3 KiB
C++

#include "stdafx.h"
#include "XMLTreeFileDlgHelper.h"
#include <sys/stat.h>
/////////////////
// test whether pathname is directory
//
#ifdef _UNICODE
#define MYstat _wstat
#else
#define MYstat _stat
#endif
#ifdef _UNICODE
#define XTREELPCTSTR LPCWSTR
#else
#define XTREELPCTSTR LPCSTR
#endif
static BOOL IsFolder(LPCTSTR strPathName)
{
char *szPath = NULL;
#ifdef _UNICODE
// Zyu modify on 100722,支持64位
//int iLen = 2*wcslen(strPathName);//CString,TCHAR汉字算一个字符,因此不用普通计算长度
INT_PTR iLen = 2*wcslen(strPathName);//CString,TCHAR汉字算一个字符,因此不用普通计算长度
szPath = new char[iLen+1];
wcstombs(szPath,strPathName,iLen+1);//转换成功返回为非负值
#else
szPath = "";
#endif
struct _stat st;
BOOL bIs = _stat(szPath, &st)==0 && (st.st_mode & _S_IFDIR);
#ifdef _UNICODE
delete szPath;
szPath = NULL;
#endif
return bIs;
}
CXMLTreeFileDlgHelper::CXMLTreeFileDlgHelper()
{
}
CXMLTreeFileDlgHelper::~CXMLTreeFileDlgHelper()
{
}
//////////////////
// Initialize: subclass appropriate windows
//
void CXMLTreeFileDlgHelper::Init(CFileDialog* pDlg)
{
// cubclass dialog
ASSERT(pDlg);
m_pDlg = pDlg;
m_dlghook.HookWindow(pDlg);
// subclass dialog's owner/parent
CWnd* pWnd = pDlg->GetParent();
ASSERT(pWnd);
pWnd = pWnd->GetParent();
ASSERT(pWnd);
m_ownerhook.Init(pWnd, pDlg);
// hook up
m_dlghook.m_pHelper = this;
m_ownerhook.m_pHelper = this;
}
//////////////////
// Get name of item -- what you see in the list control
//
CString CXMLTreeFileDlgHelper::GetItemName(int i)
{
return GetListCtrl()->GetItemText(i,0);
}
//////////////////
// Find out if item is a folder.
//
BOOL CXMLTreeFileDlgHelper::IsItemFolder(int i)
{
// Concatenate current folder name with item name to get full path name.
// This won't work in general--the item could be a link or shell
// object--but then IsFolder returns FALSE anyway, correctly.
//
CString path = m_pDlg->GetFolderPath();
int len = path.GetLength();
if (len==0 || path[len-1] != '\\')
path += '\\';
path += GetItemName(i);
return IsFolder(path);
}
//////////////////
// Get underlying list control
//
CListCtrl* CXMLTreeFileDlgHelper::GetListCtrl()
{
ASSERT(m_pDlg);
CWnd* pWnd = m_pDlg->GetParent()->GetDlgItem(lst2);
ASSERT(pWnd);
CListCtrl* plc = (CListCtrl*)pWnd->GetDlgItem(1);
ASSERT(plc);
#ifdef DEBUG
char classname[32];
::GetClassName(plc->m_hWnd, classname, sizeof(classname));
ASSERT(strcmp(classname,"SysListView32")==0);
#endif
return plc;
}
//////////////////
// virtual window proc to trap dialog messages
//
LRESULT CFileDialogHook::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
if (msg==WM_COMMAND || msg==WM_NOTIFY) {
m_pHelper->m_bUpdateUI = TRUE;
}
return CXMLTreeSubclassWnd::WindowProc(msg, wp, lp);
}
void CFileDialogOwnerHook::Init(CWnd* pOwner, CFileDialog* pDlg)
{
HookWindow(pOwner);
m_pDlg = pDlg;
m_hwndParent = pDlg->GetParent()->m_hWnd;
ASSERT(m_hwndParent);
}
//////////////////
// virtual window proc to trap dialog parent messages
//
LRESULT CFileDialogOwnerHook::WindowProc(UINT msg,
WPARAM wp, LPARAM lp)
{
if (msg==WM_ENTERIDLE && (HWND)lp==m_hwndParent) {
if (m_pHelper->m_bUpdateUI) {
m_pDlg->UpdateDialogControls(m_pDlg, FALSE);
m_pHelper->m_bUpdateUI=FALSE;
}
}
return CXMLTreeSubclassWnd::WindowProc(msg, wp, lp);
}