PropDlg.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:8k
- #if !defined(AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_)
- #define AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_
- #pragma once
- #include "Folder.h"
- // The "Properties" dialog for folders and files.
- //
- // It is *not* a COM PropertySheet Shell extension
- // but a normal dialog that fakes a Property Sheet by placing
- // a TabView control around all child controls.
- class CPropertiesDlg :
- public CDialogImpl<CPropertiesDlg>
- {
- public:
- enum {IDD = IDD_PROP_FILE};
- BEGIN_MSG_MAP(CPropertiesDlg)
- MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
- COMMAND_ID_HANDLER(IDOK, OnOk)
- COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
- COMMAND_ID_HANDLER(IDC_APPLY, OnApply)
- COMMAND_ID_HANDLER(IDC_READONLY, OnChange)
- COMMAND_ID_HANDLER(IDC_HIDDEN, OnChange)
- COMMAND_ID_HANDLER(IDC_ARCHIVE, OnChange)
- COMMAND_HANDLER(IDC_FILENAME, EN_CHANGE, OnChange)
- COMMAND_HANDLER(IDC_COMMENT, EN_CHANGE, OnChange)
- END_MSG_MAP()
- CFolder *m_pFolder;
- CPidl m_pidlFolder;
- CPidl m_pidlItem;
- //
- WORD m_retcode;
- CPropertiesDlg()
- {
- m_pFolder = NULL;
- m_retcode = IDCANCEL; // default return-code is "no changes"
- }
- HRESULT _Init(CFolder *pFolder, LPCITEMIDLIST pidlItem)
- {
- ATLASSERT(pFolder);
- m_pFolder = pFolder;
- m_pidlItem.Copy(pidlItem);
- m_pidlFolder.Copy(m_pFolder->m_pidlPath);
- if( m_pidlItem.IsEmpty() ) {
- // If we're looking at the folder itself, go one back and get path right
- m_pidlItem.Copy( m_pidlFolder.GetLastItem() );
- m_pidlFolder.RemoveLast();
- }
- if( m_pidlItem.IsEmpty() ) return E_INVALIDARG;
- return S_OK;
- }
- LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
- {
- ATLASSERT(m_pFolder);
- ATLASSERT(m_pidlItem);
- USES_CONVERSION;
- // Open the volume so we can read attributes.
- // We open with read/write access so we can determine if the
- // volume is read-only!
- HRESULT hr;
- CAdfDevice dev;
- CAdfVolume vol;
- hr = m_pFolder->_OpenAmigaDevice(m_pFolder->m_pidl, FALSE, m_pidlFolder, dev, vol);
- if( FAILED(hr) ) return 1;
- LPCPIDLDATA pData = pidl_cast((LPITEMIDLIST)m_pidlItem);
- // Setup the TabView control.
- // Need to create a default page and put the Tab in the background.
- CResString<64> sTabName(IDS_GENERAL);
- HWND hwnd = ::GetDlgItem(m_hWnd, IDC_TAB);
- TCITEM itm = { 0 };
- itm.mask = TCIF_TEXT;
- itm.pszText = (LPTSTR)sTabName;
- itm.cchTextMax = _tcslen(sTabName);
- TabCtrl_InsertItem(hwnd, 0, &itm);
- ::SetWindowPos(hwnd, HWND_BOTTOM, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
- // Set the icon
- UINT iIconIndex = pData->type==PT_FILE ? ICON_INDEX_FILE : ICON_INDEX_FOLDER;
- HICON hIcon = ImageList_GetIcon(_Module.m_ImageLists.m_hImageListLarge, iIconIndex, ILD_TRANSPARENT);
- SendDlgItemMessage(IDC_APPICON, STM_SETICON, (WPARAM)hIcon, 0); // BUG: We leak HICON
- TCHAR szTemp[MAX_PATH];
-
- SetDlgItemText(IDC_FILENAME, pData->szName);
- SendDlgItemMessage(IDC_FILENAME, EM_LIMITTEXT, MAXNAMELEN-1, 0);
- SetDlgItemText(IDC_COMMENT, pData->szComment);
- SendDlgItemMessage(IDC_COMMENT, EM_LIMITTEXT, MAXCMMTLEN-1, 0);
- PidlGetFullPath(szTemp, m_pidlFolder);
- SetDlgItemText(IDC_LOCATION, szTemp);
- TCHAR szDate[32];
- TCHAR szTime[32];
- ::GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE, &pData->ftTime, NULL, szDate, lengthof(szDate) );
- ::GetTimeFormat( LOCALE_USER_DEFAULT, 0, &pData->ftTime, NULL, szTime, lengthof(szTime) );
- ::wsprintf(szTemp, _T("%s %s"), szDate, szTime);
- SetDlgItemText(IDC_CREATED, szTemp);
- WCHAR szwTemp[256];
- LONGLONG longlong = 0;
- longlong = pData->dwSize;
- ::StrFormatByteSizeW(longlong, szwTemp, lengthof(szwTemp));
- SetDlgItemText(IDC_FILESIZE, W2CT(szwTemp));
- // BUG: Hardcoded block-size
- const int blocksize = LOGICAL_BLOCK_SIZE;
- ULONG dwSize = CAdfFile::_CalcBlocksNeeded(pData->dwSize, blocksize) * blocksize;
- longlong = dwSize;
- ::StrFormatByteSizeW(longlong, szwTemp, lengthof(szwTemp));
- SetDlgItemText(IDC_FILESIZEONDISK, W2CT(szwTemp));
- CheckDlgButton(IDC_READONLY, hasW(pData->dwAccess) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(IDC_HIDDEN, hasH(pData->dwAccess) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(IDC_ARCHIVE, hasA(pData->dwAccess) ? BST_CHECKED : BST_UNCHECKED);
- // In case of a read-only volume, disable some controls
- if( vol.IsReadOnly() ) {
- SendDlgItemMessage(IDC_FILENAME, EM_SETREADONLY, TRUE, 0);
- SendDlgItemMessage(IDC_COMMENT, EM_SETREADONLY, TRUE, 0);
- ::EnableWindow(GetDlgItem(IDC_READONLY), FALSE);
- ::EnableWindow(GetDlgItem(IDC_HIDDEN), FALSE);
- ::EnableWindow(GetDlgItem(IDC_ARCHIVE), FALSE);
- }
- ::EnableWindow(GetDlgItem(IDC_APPLY), FALSE);
- return 0;
- }
- LRESULT OnOk(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
- {
- if( ::IsWindowEnabled(GetDlgItem(IDC_APPLY)) ) OnApply(0,0,0,bHandled);
- EndDialog(m_retcode);
- return 0;
- }
- LRESULT OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- EndDialog(m_retcode);
- return 0;
- }
- LRESULT OnApply(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- USES_CONVERSION;
- HRESULT hr;
- // Save changes...
- LPCPIDLDATA pData = pidl_cast((LPITEMIDLIST)m_pidlItem);
- // Rename object if nessecary
- TCHAR szNewName[MAXNAMELEN+1];
- GetDlgItemText(IDC_FILENAME, szNewName, MAXNAMELEN);
- if( _tcscmp(pData->szName, szNewName)!=0 ) {
- // BUG: Won't this fail if we rename twice? Need to store 'pidlNew' argument?
- hr = m_pFolder->SetNameOf(m_hWnd, m_pidlItem, T2OLE(szNewName), 0, NULL);
- if( FAILED(hr) ) {
- SetDlgItemText(IDC_FILENAME, pData->szName);
- ::MessageBeep(MB_ICONEXCLAMATION);
- return 0;
- }
- }
- // Open the volume so we can change attributes
- CAdfDevice dev;
- CAdfVolume vol;
- hr = m_pFolder->_OpenAmigaDevice(m_pFolder->m_pidl, FALSE, m_pidlFolder, dev, vol);
- if( FAILED(hr) ) return 0;
- // Check for change in comment
- TCHAR szNewComment[MAXCMMTLEN+1];
- GetDlgItemText(IDC_COMMENT, szNewComment, MAXCMMTLEN);
- if( _tcscmp(pData->szComment, szNewComment)!=0 ) {
- vol.SetFileComment(szNewName, vol.GetDirectoryPtr(), szNewComment);
- }
- // Get the status of the file attributes
- bool bReadOnly = IsDlgButtonChecked(IDC_READONLY)==BST_CHECKED;
- bool bHidden = IsDlgButtonChecked(IDC_HIDDEN)==BST_CHECKED;
- bool bArchived = IsDlgButtonChecked(IDC_ARCHIVE)==BST_CHECKED;
- // Calculate new access rights for file
- DWORD dwAccess = pData->dwAccess;
- if( bReadOnly ) dwAccess |= ACCMASK_W; else dwAccess &= ~ACCMASK_W;
- if( bHidden ) dwAccess |= ACCMASK_H; else dwAccess &= ~ACCMASK_H;
- if( bArchived ) dwAccess |= ACCMASK_A; else dwAccess &= ~ACCMASK_A;
- // Set the access rights for the file if changed
- if( pData->dwAccess != dwAccess ) {
- vol.SetFileAccess(szNewName, vol.GetDirectoryPtr(), dwAccess);
- };
- // Ask Shell to refresh parent directory and the item itself
- CPidl pidl;
- pidl.Copy(m_pFolder->m_pidl);
- pidl.Concatenate(m_pidlFolder);
- ::SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST | SHCNF_FLUSH, pidl, NULL);
- pidl.Concatenate(m_pidlItem);
- ::SHChangeNotify(SHCNE_ATTRIBUTES, SHCNF_IDLIST | SHCNF_FLUSH, pidl, NULL);
- // Back to unmodified state...
- ::EnableWindow(GetDlgItem(IDC_APPLY), FALSE);
- m_retcode = IDOK;
- return 0;
- }
- LRESULT OnChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- ::EnableWindow(GetDlgItem(IDC_APPLY), TRUE);
- return 0;
- }
- };
- #endif // !defined(AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_)