📄 tabbedmdisave.cpp
字号:
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_ParentList(
ITabbedMDIChildModifiedList** parentList)
{
ATLASSERT(parentList != NULL);
if(parentList == NULL)
{
return E_POINTER;
}
*parentList = m_parentList;
if(m_parentList)
{
m_parentList->AddRef();
}
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::putref_ParentList(
ITabbedMDIChildModifiedList* parentList)
{
if( m_parentList != NULL && parentList != NULL &&
m_parentList != parentList)
{
// Neither the current nor the new parent list is NULL.
// Remove ourselves from the old parent (?)
// (doing so would mess up the current InsertList)
//long index = -1;
//m_parentList->get_Index(this, &index);
//if(index >= 0)
//{
// m_parentList->Remove(index);
//}
}
m_parentList = parentList;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_SubItems(
ITabbedMDIChildModifiedList** subItems)
{
// The first time they ask for the sub items, we'll create it.
HRESULT hr = S_OK;
if(m_subItems == NULL)
{
ATL::CComObject<CTabbedMDIChildModifiedList>* newSubItems = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedList>::CreateInstance(&newSubItems);
if(newSubItems != NULL)
{
newSubItems->AddRef();
newSubItems->putref_ParentItem(this);
m_subItems = newSubItems;
newSubItems->Release();
}
}
return m_subItems.CopyTo(subItems);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::CopyTo(
ITabbedMDIChildModifiedItem* destination)
{
if(destination == NULL)
{
return E_INVALIDARG;
}
destination->put_Window(m_window);
destination->put_Name(m_name);
destination->put_DisplayName(m_displayName);
destination->put_Description(m_description);
destination->put_LastModifiedUTC(m_lastModified);
destination->put_Icon(m_icon);
destination->putref_UserData(m_userData);
// The destination keeps its current parent
//destination->putref_ParentList(m_parentList);
ATL::CComPtr<ITabbedMDIChildModifiedList> subItems;
destination->get_SubItems(&subItems);
if(subItems)
{
subItems->Clear();
if(m_subItems)
{
subItems->InsertList(-1, m_subItems);
}
}
return S_OK;
}
// Methods not exposed over iterface
STDMETHODIMP CTabbedMDIChildModifiedItem::InitNew(HWND window,
const wchar_t* name, const wchar_t* displayName, const wchar_t* description,
DATE lastModified, HICON icon)
{
this->put_Window(window);
this->put_Name(name);
this->put_DisplayName(displayName);
this->put_Description(description);
this->put_LastModifiedUTC(lastModified);
this->put_Icon(icon);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// Global functions
HRESULT CreateTabbedMDIChildModifiedList(ITabbedMDIChildModifiedList** list)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedList>* newItemList = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedList>::CreateInstance(&newItemList);
if(newItemList != NULL)
{
hr = newItemList->QueryInterface(list);
}
return hr;
}
HRESULT CreateTabbedMDIChildModifiedItem(HWND window,
const wchar_t* name, const wchar_t* displayName, const wchar_t* description,
DATE lastModified, HICON icon,
ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedItem>* newItem = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedItem>::CreateInstance(&newItem);
if(newItem != NULL)
{
newItem->AddRef();
hr = newItem->InitNew(window, name, displayName, description, lastModified, icon);
if(SUCCEEDED(hr))
{
hr = newItem->QueryInterface(item);
}
newItem->Release();
}
return hr;
}
HRESULT CreateEmptyTabbedMDIChildModifiedItem(ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedItem>* newItem = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedItem>::CreateInstance(&newItem);
if(newItem != NULL)
{
hr = newItem->QueryInterface(item);
}
return hr;
}
/////////////////////////////////////////////////////////////////////////////
// CSaveModifiedItemsDialog
#include "commctrl.h"
CSaveModifiedItemsDialog::CSaveModifiedItemsDialog(ITabbedMDIChildModifiedList* list, bool canCancel) :
m_modifiedList(list),
m_canCancel(canCancel),
m_haveAtLeastOneModifiedDate(false),
m_list(this, 1),
m_dialogIcon(NULL),
m_imageUnchecked(-1),
m_imageChecked(-1),
m_imageIndeterminate(-1),
m_trackColumnWidth(0),
m_trackColumnIndex(-1),
m_lastVisibleColumn(eColumn_Last)
{
for(int i=0; i<eColumn_Count; ++i)
{
m_showColumn[i] = true;
}
}
CSaveModifiedItemsDialog::~CSaveModifiedItemsDialog()
{
}
bool CSaveModifiedItemsDialog::HideColumn(ColumnIndex column)
{
ATLASSERT(((!m_header.IsWindow()) || (m_header.IsWindow() && m_header.GetItemCount() < 1)) &&
"Please call this before InitializeColumns().");
if(column < 0 || column > eColumn_Last || column == eColumn_Name)
{
ATLASSERT(0 && "Invalid column index");
return false;
}
m_showColumn[column] = false;
if(column == m_lastVisibleColumn)
{
// Find the new last visible column
while((m_lastVisibleColumn > 0) && !m_showColumn[m_lastVisibleColumn])
{
m_lastVisibleColumn = (ColumnIndex)((int)m_lastVisibleColumn-1);
}
}
return true;
}
LRESULT CSaveModifiedItemsDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CenterWindow(GetParent());
this->InitializeControls();
this->InitializeValues();
// NOTE: We need to do this init after InitializeValues, in
// case the default size of any control changes
this->DlgResize_Init(true, true, WS_THICKFRAME | WS_CLIPCHILDREN);
return 1; // Let the dialog manager set initial focus
}
LRESULT CSaveModifiedItemsDialog::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
LONG dwListStyle = m_list.GetWindowLong(GWL_STYLE);
if((dwListStyle & LVS_SHAREIMAGELISTS) == LVS_SHAREIMAGELISTS)
{
// We're responsible for cleaning up the list view's image list
if(!m_images.IsNull())
{
m_images.Destroy();
}
}
if(!m_stateImages.IsNull())
{
m_stateImages.Destroy();
}
if(m_dialogIcon != NULL)
{
::DestroyIcon(m_dialogIcon);
m_dialogIcon = NULL;
}
if(m_list.IsWindow())
{
m_list.UnsubclassWindow();
}
// Be sure others see the message (especially DefWindowProc)
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnYes(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(m_modifiedList)
{
int count = m_list.GetItemCount();
for(int i=0; i<count; ++i)
{
CheckState checkState = this->GetTristateCheckState(i);
if(checkState == eCheckState_Unchecked)
{
ATL::CComQIPtr<ITabbedMDIChildModifiedItem> item(this->GetIUnknownForItem(i));
if(item)
{
ATL::CComPtr<ITabbedMDIChildModifiedList> parentList;
item->get_ParentList(&parentList);
if(parentList)
{
long index = -1;
parentList->get_Index(item, &index);
if(index >= 0)
{
parentList->Remove(index);
}
}
}
}
}
}
this->EndDialog(wID);
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnEndDialog(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
this->EndDialog(wID);
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewInsertItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
bHandled = TRUE;
LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)pnmh;
if(pnmLV != NULL)
{
// It'd be nice if they set the lParam of NMLISTVIEW, but they don't.
// Only iItem is valid
//LPARAM lParam = pnmLV->lParam;
//if(lParam != NULL)
//{
// // Keep an AddRef around for the item, and Release in OnDeleteItem
// ((IUnknown*)lParam)->AddRef();
//}
IUnknown* punk = this->GetIUnknownForItem(pnmLV->iItem);
if(punk)
{
// Keep an AddRef around for the item, and Release in OnDeleteItem
punk->AddRef();
}
}
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewDeleteItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
bHandled = TRUE;
LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)pnmh;
if(pnmLV != NULL)
{
LPARAM lParam = pnmLV->lParam;
if(lParam != NULL)
{
((IUnknown*)lParam)->Release();
pnmLV->lParam = 0;
}
}
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewKeyDownToToggleCheck(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMLVKEYDOWN* keyDown = (NMLVKEYDOWN*)pnmh;
if(keyDown && keyDown->wVKey == VK_SPACE)
{
int item = m_list.GetNextItem(-1, LVNI_FOCUSED);
if(item != -1 && ::GetKeyState(VK_CONTROL) >= 0)
{
this->ToggleCheckState(item);
}
}
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewClickToToggleCheck(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMITEMACTIVATE* itemActivate = (NMITEMACTIVATE*)pnmh;
if(itemActivate)
{
LVHITTESTINFO lvh = { 0 };
lvh.pt = itemActivate->ptAction;
if(m_list.HitTest(&lvh) != -1 && lvh.flags == LVHT_ONITEMSTATEICON && ::GetKeyState(VK_CONTROL) >= 0)
{
this->ToggleCheckState(lvh.iItem);
}
}
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// Erase the background in OnListViewPaint
return 1;
}
LRESULT CSaveModifiedItemsDialog::OnListViewPaint(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if(wParam != NULL)
{
WTL::CMemDC memdc((HDC)wParam, NULL);
//memdc.FillSolidRect(&memdc.m_rc, ::GetSysColor(COLOR_WINDOW));
m_list.DefWindowProc(WM_ERASEBKGND, (WPARAM)memdc.m_hDC, 0);
m_list.DefWindowProc(uMsg, (WPARAM)memdc.m_hDC, 0);
if(m_header.IsWindow())
{
m_header.SendMessage(WM_PAINT, (WPARAM)memdc.m_hDC, 0);
m_header.ValidateRect(&memdc.m_rc);
}
}
else
{
WTL::CPaintDC dc(m_list);
WTL::CMemDC memdc(dc.m_hDC, &dc.m_ps.rcPaint);
//memdc.FillSolidRect(&dc.m_ps.rcPaint, ::GetSysColor(COLOR_WINDOW));
m_list.DefWindowProc(WM_ERASEBKGND, (WPARAM)memdc.m_hDC, 0);
m_list.DefWindowProc(uMsg, (WPARAM)memdc.m_hDC, 0);
if(m_header.IsWindow())
{
m_header.SendMessage(WM_PAINT, (WPARAM)memdc.m_hDC, 0);
m_header.ValidateRect(&dc.m_ps.rcPaint);
}
}
return 0;
}
//LRESULT CSaveModifiedItemsDialog::OnHeaderPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//{
// if( wParam != NULL )
// {
// WTL::CMemDC memdc((HDC)wParam, NULL);
// memdc.FillSolidRect(&memdc.m_rc, ::GetSysColor(COLOR_BTNFACE));
// m_header.DefWindowProc( uMsg, (WPARAM)memdc.m_hDC, 0);
// }
// else
// {
// WTL::CPaintDC dc(m_header);
// WTL::CMemDC memdc(dc.m_hDC, &dc.m_ps.rcPaint);
// memdc.FillSolidRect(&dc.m_ps.rcPaint, ::GetSysColor(COLOR_BTNFACE));
// m_header.DefWindowProc( uMsg, (WPARAM)memdc.m_hDC, 0);
// }
// return 0;
//}
LRESULT CSaveModifiedItemsDialog::OnHeaderBeginTrack(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMHEADER* headerInfo = (NMHEADER*)pnmh;
if(headerInfo)
{
m_trackColumnIndex = headerInfo->iItem;
m_trackColumnWidth = m_list.GetColumnWidth(m_trackColumnIndex);
if( (m_trackColumnIndex < 0) ||
(m_trackColumnIndex >= m_lastVisibleColumn) ||
!m_showColumn[m_trackColumnIndex])
{
// Don't allow resizing on the last column,
// or on a column we are hiding
m_trackColumnIndex = -1;
bHandled = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -