diff options
Diffstat (limited to 'NSCmpts/SourceProp.cpp')
-rw-r--r-- | NSCmpts/SourceProp.cpp | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/NSCmpts/SourceProp.cpp b/NSCmpts/SourceProp.cpp new file mode 100644 index 0000000..40cb0bf --- /dev/null +++ b/NSCmpts/SourceProp.cpp @@ -0,0 +1,306 @@ +// SourceProp.cpp : Implementation of CSourceProp +#include "stdafx.h" +#include "NSCmpts.h" +#include "SourceProp.h" +#include <path.h> + +///////////////////////////////////////////////////////////////////////////// +// CSourceProp + +LRESULT CSourceProp::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Load the System Image list + m_imgList.Load(true); + + // Set the List + m_ctlList = GetDlgItem(IDC_SOURCE_LIST); + m_ctlList.SetImageList(m_imgList, LVSIL_SMALL); + + // We need at least one bogus column since we're using + // report view + LV_COLUMN lvC; // list view column structure + + // Now initialize the columns you will need. + // Initialize the LV_COLUMN structure. + // The mask specifies that the fmt, width, pszText, and subitem members + // of the structure are valid. + lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM; + lvC.fmt = LVCFMT_LEFT; // left-align column + lvC.cx = 200; // width of column in pixels + lvC.iSubItem = 0; + + if(m_ctlList.InsertColumn(0, &lvC) == -1) + return true; + + bHandled = true; + return TRUE; +} + +LRESULT CSourceProp::OnChange(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // Make sure the column is the width of control + RECT rect; + m_ctlList.GetClientRect(&rect); + m_ctlList.SetColumnWidth(0, rect.right); + + return 0; +} + + +LRESULT CSourceProp::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + UpdateData(true); + return 0; +} + +LRESULT CSourceProp::OnShowWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + HWND hwndParent = GetParent(); + + // Sets the DropTarget for the Parent Window and removes + // it when hidden. For some reason if we set it for the + // property page itself it doesn't work. + // + // Since there could be multiple property pages fiddling + // with the parent windows Drag Drop Status, we use a + // window property to keep track of the current owner. + + if(wParam) + { + IDropTarget* pTarget = NULL; + QueryInterface(IID_IDropTarget, (void**)&pTarget); + ASSERT(pTarget); + + // Not mission critical (used only for drag drop) + RevokeDragDrop(hwndParent); + HRESULT hr = RegisterDragDrop(hwndParent, pTarget); + + // Register Drag Drop Addrefs + pTarget->Release(); + + // Set the window property to a pointer to us + if(SUCCEEDED(hr)) + SetProp(hwndParent, _T("DropTarget"), (HANDLE)this); + } + else + { + // If window property is pointer to us then ... + if((CSourceProp*)GetProp(hwndParent, _T("DropTarget")) == this) + { + // Remove Drag Drop + RevokeDragDrop(hwndParent); + RemoveProp(hwndParent, _T("DropTarget")); + } + } + + return 0; +} + +LRESULT CSourceProp::OnEndLabelEdit(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + LVITEM* pItem = &((NMLVDISPINFO*)pnmh)->item; + + // Only Change if there is Text + if(pItem->pszText == NULL) + return 0; + + file_path path(pItem->pszText); + if(path.exists()) + { + pItem->iImage = m_imgList.GetFileIndex(pItem->pszText); + // WINBUG: Windows 95 (original version) doesn't set LVIF_TEXT + // have to set it here. + pItem->mask |= (LVIF_IMAGE | LVIF_TEXT); + + // Set Item text + m_ctlList.SetItem(pItem); + } + else + { + string sTemp; + sTemp.load_string(IDS_BACKUP_VALID_PATH); + + MessageBox(sTemp, _T("Night Security"), MB_OK | MB_ICONWARNING); + } + + return 0; +} + +LRESULT CSourceProp::OnListSetFocus(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // Disclaimer: This is a kludge fix + // SysListView32 wouldn't redraw itself when it had focus + // and app was activated + m_ctlList.Invalidate(); + m_ctlList.RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE); + return 0; +} + +LRESULT CSourceProp::OnKeyDown(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + NMLVKEYDOWN* pLVKeyDow = (NMLVKEYDOWN*)pnmh; + + // if F2 then Edit + if(pLVKeyDow->wVKey == VK_F2) + { + m_ctlList.SetFocus(); // Needs to have the Focus in order to edit + m_ctlList.EditLabel(m_ctlList.GetNextItem(-1, LVNI_ALL | LVNI_FOCUSED)); + } + + // If Delete then call Delete Handler + if(pLVKeyDow->wVKey == VK_DELETE) + { + OnRemove(0, 0, 0, bHandled); + } + + return 0; +} + +LRESULT CSourceProp::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + int iItem = -1; + + // Loop through selected items + while((iItem = m_ctlList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED)) != -1) + // Take it out of List Box + m_ctlList.DeleteItem(iItem); + + return 0; +} + +LRESULT CSourceProp::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + LPMALLOC pMalloc; + if(FAILED(::SHGetMalloc(&pMalloc))) + return 0; + + TCHAR buff[MAX_PATH]; + BROWSEINFO bi; + bi.hwndOwner = m_hWnd; + bi.pidlRoot = NULL; + bi.pszDisplayName = buff; + bi.lpszTitle = _T("Choose a folder to add."); + bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; + bi.lpfn = NULL; + bi.lParam = 0; + + LPITEMIDLIST pidl = SHBrowseForFolder(&bi); + + if(pidl == NULL) + return 0; + + if(::SHGetPathFromIDList(pidl, buff)) + AddFile(buff); + + pMalloc->Free(pidl); + pMalloc->Release(); + + bHandled = true; + return 0; +} + +bool CSourceProp::AddFile(string sFileName) +{ + int nIndex = m_imgList.GetFileIndex(sFileName); + + LVITEM lv; + lv.mask = LVIF_TEXT | LVIF_IMAGE; + lv.iItem = 0; + lv.iSubItem = 0; + lv.pszText = sFileName.get_buffer(sFileName.size() + 1); + lv.iImage = nIndex; + + return ListView_InsertItem(GetDlgItem(IDC_SOURCE_LIST), &lv) >= 0; +} + +STDMETHODIMP CSourceProp::DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) +{ + HRESULT hr = E_FAIL; + FORMATETC fmte = + { + CF_HDROP, // use CF_HDROP format + NULL, // no specific device required + DVASPECT_CONTENT, // embedded object + -1, // must be -1 for DVASPECT_CONTENT + TYMED_HGLOBAL // how to transfer data + }; + STGMEDIUM medium; + + // No data object + if (pDataObject == NULL) + return E_FAIL; + + // Use the given IDataObject to get a list of filenames (CF_HDROP). + hr = pDataObject->GetData(&fmte, &medium); + + if(SUCCEEDED(hr)) + { + ReleaseStgMedium(&medium); + *pdwEffect = DROPEFFECT_LINK; + } + else + *pdwEffect = DROPEFFECT_NONE; + + return hr; +} + +STDMETHODIMP CSourceProp::Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) +{ + HRESULT hr = E_FAIL; + FORMATETC fmte = + { + CF_HDROP, // use CF_HDROP format + NULL, // no specific device required + DVASPECT_CONTENT, // embedded object + -1, // must be -1 for DVASPECT_CONTENT + TYMED_HGLOBAL // how to transfer data + }; + STGMEDIUM medium; + + // No data object + if(!pDataObject) + return hr; + + // Use the given IDataObject to get a list of filenames (CF_HDROP). + hr = pDataObject->GetData(&fmte, &medium); + + if(FAILED(hr)) + return hr; + + // Get Number of Files + int nFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT) -1, NULL, 0); + + string sFile; + int nTotLength = 0; + + // Okay now Circle through and get all the files + for (int nCnt = 0; nCnt < nFiles; nCnt++) + { + if(DragQueryFile((HDROP) medium.hGlobal, nCnt, sFile.get_buffer(MAX_PATH), MAX_PATH)) + AddFile(sFile); + } + + // Release the data. + ReleaseStgMedium(&medium); + + return hr; +} + +void CSourceProp::UpdateData(bool bSave) +{ + if(bSave) + { + m_aPaths.clear(); + TCHAR buff[MAX_PATH]; + int nItem = 0; + while(m_ctlList.GetItemText(nItem++, 0, buff, MAX_PATH)) + m_aPaths.push_back(buff); + } + else + { + string_array::const_iterator iter = m_aPaths.begin(); + for(; iter != m_aPaths.end(); iter++) + AddFile(*iter); + } + +} |