findtaskdlg.cpp
来自「管理项目进度工具的原代码」· C++ 代码 · 共 1,310 行 · 第 1/3 页
CPP
1,310 行
SaveSettings();
CDialog::OnDestroy();
}
void CFindTaskDlg::SaveSettings()
{
UpdateData();
AfxGetApp()->WriteProfileInt("FindTasks", "SearchAllTaskLists", m_bAllTasklists);
AfxGetApp()->WriteProfileInt("FindTasks", "IncludeDoneTasks", m_bIncludeDone);
AfxGetApp()->WriteProfileInt("FindTasks", "LastFindOption", m_nFindOption);
AfxGetApp()->WriteProfileInt("FindTasks", "AutoSelectSingles", m_bAutoSelectSingles);
// save column widths
AfxGetApp()->WriteProfileInt("FindTasks", "PathColWidth", m_lcResults.GetColumnWidth(COL_PATH));
AfxGetApp()->WriteProfileInt("FindTasks", "MatchColWidth", m_lcResults.GetColumnWidth(COL_MATCH));
// pos
CRect rDialog = m_dockMgr.GetUnDockedRect();
AfxGetApp()->WriteProfileInt("FindTasks", "TopLeft", MAKELPARAM(rDialog.left, rDialog.top));
AfxGetApp()->WriteProfileInt("FindTasks", "BottomRight", MAKELPARAM(rDialog.right, rDialog.bottom));
AfxGetApp()->WriteProfileInt("FindTasks", "DockPos", m_dockMgr.GetDockPos());
AfxGetApp()->WriteProfileInt("FindTasks", "LastDockPos", m_dockMgr.GetLastDockPos());
AfxGetApp()->WriteProfileInt("FindTasks", "DockedWidth", m_dockMgr.GetDockedWidth(FALSE));
AfxGetApp()->WriteProfileInt("FindTasks", "DockedWidthMax", m_dockMgr.GetDockedWidth(TRUE));
AfxGetApp()->WriteProfileInt("FindTasks", "DockedHeight", m_dockMgr.GetDockedHeight(FALSE));
AfxGetApp()->WriteProfileInt("FindTasks", "DockedHeightMax", m_dockMgr.GetDockedHeight(TRUE));
}
void CFindTaskDlg::OnSelchangeFindoption()
{
UpdateData();
m_nFindOption = (FIND_WHAT)m_host.GetPageItemData(m_nSelFindIndex);
CPropertyPage* pPage = (CPropertyPage*)m_cbFindOptions.GetItemDataPtr(m_nSelFindIndex);
ASSERT (pPage);
m_host.SetActivePage(pPage, FALSE);
// set focus back to combo to allow user to continue navigating
m_cbFindOptions.SetFocus();
}
void CFindTaskDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
if (m_dockMgr.Initialized())
{
if (!m_dockMgr.IsDocked())
{
CDlgUnits dlu(this);
lpMMI->ptMinTrackSize.x = dlu.ToPixelsX(290);
lpMMI->ptMinTrackSize.y = dlu.ToPixelsY(230);
}
else
{
CSize rDef = GetMinDockedSize(m_dockMgr.GetDockPos());
lpMMI->ptMinTrackSize.y = rDef.cy;
lpMMI->ptMinTrackSize.x = rDef.cx;
}
}
}
BOOL CFindTaskDlg::PreTranslateMessage(MSG* pMsg)
{
// handle enter key if results list has the focus
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN && pMsg->hwnd == m_lcResults)
{
int nSel = m_lcResults.GetNextItem(-1, LVIS_FOCUSED | LVIS_SELECTED);
if (nSel != -1)
{
FTDRESULT res;
DWORD dwKey = m_lcResults.GetItemData(nSel);
if (m_mapResults.Lookup(dwKey, res))
GetParent()->SendMessage(WM_FTD_SELECTRESULT, dwKey, (LPARAM)&res);
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CFindTaskDlg::OnSelectall()
{
int nRes = GetResultCount();
// if there is only one result then act as if the user
// clicked on it directly
if (nRes == 1)
{
FTDRESULT res;
DWORD dwKey = m_lcResults.GetItemData(0);
if (dwKey == HEADERROW && m_lcResults.GetItemCount() == 2)
{
DWORD dwKey = m_lcResults.GetItemData(1);
VERIFY (m_mapResults.Lookup(dwKey, res));
GetParent()->SendMessage(WM_FTD_SELECTRESULT, dwKey, (LPARAM)&res);
}
}
else if (nRes) // > 1
GetParent()->SendMessage(WM_FTD_SELECTALL);
}
void CFindTaskDlg::OnDockright()
{
// toggle docked state
if (m_dockMgr.GetDockPos() == DMP_RIGHT)
m_dockMgr.UnDock();
else
m_dockMgr.Dock(DMP_RIGHT);
ResizeDlg();
m_toolbar.RefreshButtonStates();
}
void CFindTaskDlg::OnUpdateDockright(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_dockMgr.GetDockPos() == DMP_RIGHT);
}
void CFindTaskDlg::OnDockleft()
{
// toggle docked state
if (m_dockMgr.GetDockPos() == DMP_LEFT)
m_dockMgr.UnDock();
else
m_dockMgr.Dock(DMP_LEFT);
ResizeDlg();
m_toolbar.RefreshButtonStates();
}
void CFindTaskDlg::OnUpdateDockleft(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_dockMgr.GetDockPos() == DMP_LEFT);
}
void CFindTaskDlg::OnUndock()
{
m_dockMgr.Dock(DMP_UNDOCKED);
ResizeDlg();
m_toolbar.RefreshButtonStates();
}
void CFindTaskDlg::OnUpdateUndock(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_dockMgr.GetDockPos() == DMP_UNDOCKED);
}
void CFindTaskDlg::InitFieldColumn()
{
const SEARCHFIELD* pField = GetSearchField(m_nFindOption);
static int nPrevFieldWidth = MATCH_COLWIDTH;
int nColWidth = m_lcResults.GetColumnWidth(COL_MATCH);
if (!(pField && pField->nIDColumn))
{
// hide the column
LVCOLUMN lvc = { LVCF_WIDTH, 0, 0 };
m_lcResults.SetColumn(COL_MATCH, &lvc);
// and prevent resizing
m_hdrResults.LockColumn(COL_MATCH);
}
else
{
// prepare the column
CEnString sColumn(pField->nIDColumn);
LVCOLUMN lvc = { LVCF_TEXT | LVCF_FMT, pField->nAlign, 0, (LPTSTR)(LPCTSTR)sColumn };
if (!nColWidth && nPrevFieldWidth)
{
lvc.mask |= LVCF_WIDTH;
lvc.cx = nPrevFieldWidth;
}
m_lcResults.SetColumn(COL_MATCH, &lvc);
// and allow resizing
m_hdrResults.LockColumn(COL_MATCH, FALSE);
}
if (nColWidth)
nPrevFieldWidth = nColWidth;
}
void CFindTaskDlg::OnDockbelow()
{
// toggle docked state
if (m_dockMgr.GetDockPos() == DMP_BELOW)
m_dockMgr.UnDock();
else
m_dockMgr.Dock(DMP_BELOW);
ResizeDlg();
m_toolbar.RefreshButtonStates();
}
void CFindTaskDlg::OnUpdateDockbelow(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_dockMgr.GetDockPos() == DMP_BELOW);
}
void CFindTaskDlg::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMCUSTOMDRAW* pNMCD = (NMCUSTOMDRAW*)pNMHDR;
NMLVCUSTOMDRAW* pLVCD = (NMLVCUSTOMDRAW*)pNMCD;
if (pNMCD->dwDrawStage == CDDS_PREPAINT)
*pResult = CDRF_NOTIFYITEMDRAW; // ask for item notifications.
else if (pNMCD->dwDrawStage == CDDS_ITEMPREPAINT)
{
DWORD dwKey = m_lcResults.GetItemData((int)pNMCD->dwItemSpec);
if (dwKey == HEADERROW) // header line
{
CString sText = m_lcResults.GetItemText((int)pNMCD->dwItemSpec, 0);
if (!sText.IsEmpty())
{
CDC* pDC = CDC::FromHandle(pNMCD->hdc);
CRect rItem;
m_lcResults.GetItemRect((int)pNMCD->dwItemSpec, rItem, LVIR_LABEL);
rItem.left -= 2;
int nSave = pDC->SaveDC();
pDC->SelectObject(&m_fontBold);
pDC->SetTextColor(0);
pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
pDC->SetBkMode(OPAQUE);
pDC->DrawText(sText, rItem, DT_TOP | DT_LEFT | DT_END_ELLIPSIS | DT_NOPREFIX);
// draw a horizontal dividing line
pDC->DrawText(sText, rItem, DT_TOP | DT_LEFT | DT_END_ELLIPSIS | DT_NOPREFIX | DT_CALCRECT);
pDC->FillSolidRect(rItem.right + 6, rItem.top + rItem.Height() / 2, 600 - rItem.right, 1, GetSysColor(COLOR_3DSHADOW));
pDC->RestoreDC(nSave);
}
*pResult |= CDRF_SKIPDEFAULT; // always
}
else // result
{
FTDRESULT res;
if (m_mapResults.Lookup(dwKey, res) && res.bDone)
{
// get the users 'done' colour
if (AfxGetApp()->GetProfileInt("Preferences", "SpecifyDoneColor", FALSE))
{
COLORREF crText = (COLORREF)AfxGetApp()->GetProfileInt("Preferences\\Colors", "TaskDone", -1);
if (crText != (COLORREF)-1)
{
pLVCD->clrText = crText;
*pResult |= CDRF_NEWFONT;
}
}
}
}
}
}
void CFindTaskDlg::DeleteResults(int nTaskList)
{
// work backwards from the last list res
int nItem = m_lcResults.GetItemCount();
while (nItem--)
{
FTDRESULT res;
DWORD dwKey = m_lcResults.GetItemData(nItem);
VERIFY (m_mapResults.Lookup(dwKey, res));
if (res.nTaskList == nTaskList)
{
m_lcResults.DeleteItem(nItem);
m_mapResults.RemoveKey(dwKey);
}
}
// update 'found' count
m_sResultsLabel.Format(IDS_FTD_SOMERESULTS, m_lcResults.GetItemCount());
UpdateData(FALSE);
}
void CFindTaskDlg::OnSearchresults()
{
UpdateData();
}
BOOL CFindTaskDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// if the cursor is over a non-header row then show the 'hand' pointer
// can't use LVS_EX_ONECLICKACTIVATE for this because this *cannot* be
// overridden for header items
if (pWnd == &m_lcResults && nHitTest == HTCLIENT)
{
CPoint ptCursor(::GetMessagePos());
pWnd->ScreenToClient(&ptCursor);
int nItem = m_lcResults.HitTest(ptCursor);
if (nItem != -1 && m_lcResults.GetItemData(nItem) != HEADERROW) // normal result
{
SetCursor(Misc::HandCursor());
return TRUE;
}
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CFindTaskDlg::OnItemchangingResults(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// we're interested in keyboard selection state changes only
if (pNMListView->uChanged & LVIF_STATE)
{
BOOL bWasSel = (pNMListView->uOldState & LVIS_SELECTED);
BOOL bIsSel = (pNMListView->uNewState & LVIS_SELECTED);
// has a header row just become selected?
if (bIsSel && !bWasSel && pNMListView->lParam == HEADERROW)
{
if (Misc::KeyIsPressed(VK_LBUTTON))
{
// restore previous selection
SelectItem(m_nCurSel);
}
else // keyboard
{
// we need to get the next valid item in the direction
// the user is moving
BOOL bDown = (GetSelectedItem() < pNMListView->iItem);
int nNextItem = GetNextResult(pNMListView->iItem, bDown);
if (nNextItem != -1)
SelectItem(nNextItem);
else
{
SelectItem(m_nCurSel);
// make sure the non-selectable item is visible
m_lcResults.EnsureVisible(pNMListView->iItem, FALSE);
}
}
*pResult = TRUE;
return;
}
}
m_nCurSel = pNMListView->iItem;
*pResult = 0;
}
int CFindTaskDlg::GetNextResult(int nItem, BOOL bDown)
{
int nNext = nItem + (bDown ? 1 : -1); // next item
while (nNext >= 0 && nNext < m_lcResults.GetItemCount())
{
if (m_lcResults.GetItemData(nNext) != HEADERROW)
return nNext;
nNext += bDown ? 1 : -1; // next item
}
// no next item
return -1;
}
void CFindTaskDlg::SelectItem(int nItem)
{
m_lcResults.SetItemState(nItem, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_nCurSel = nItem;
}
int CFindTaskDlg::GetSelectedItem()
{
return m_nCurSel;
}
/*
void CFindTaskDlg::InvalidateVisibleHeaderRows()
{
CRect rClient;
m_lcResults.GetClientRect(rClient);
int nItem = m_lcResults.GetItemCount();
while (nItem--)
{
if (m_lcResults.GetItemData(nItem) == HEADERROW)
{
CRect rItem;
if (m_lcResults.GetItemRect(nItem, rItem, LVIR_BOUNDS))
{
if (CRect().IntersectRect(rClient, rItem))
m_lcResults.InvalidateRect(rItem);
else if (rItem.top > rClient.bottom)
break; // passed the bottom of the visible list
}
}
}
}
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?