📄 bcgptaskspane.cpp
字号:
break;
case 32:
nFlags |= ILC_COLOR32;
break;
}
icons.Create (cx, bmpObj.bmHeight, nFlags, 0, 0);
icons.Add (&bmp, clrTransparent);
SetIconsList (icons);
return TRUE;
}
//******************************************************************************************
int CBCGPTasksPane::AddPage (LPCTSTR lpszPageLabel)
{
ASSERT(lpszPageLabel != NULL);
CBCGPTasksPanePage* pPage = new CBCGPTasksPanePage(lpszPageLabel, this);
ASSERT_VALID (pPage);
m_lstTasksPanes.AddTail (pPage);
RebuildMenu ();
return m_lstTasksPanes.GetCount()-1;
}
//******************************************************************************************
void CBCGPTasksPane::RemovePage (int nPageIdx)
{
ASSERT(nPageIdx > 0);
ASSERT(nPageIdx <= m_lstTasksPanes.GetCount ()-1);
POSITION posPage = m_lstTasksPanes.FindIndex (nPageIdx);
ASSERT(posPage != NULL);
CBCGPTasksPanePage* pPage = (CBCGPTasksPanePage*) m_lstTasksPanes.GetAt (posPage);
ASSERT_VALID(pPage);
//----------------------
// Reset an active page:
//----------------------
ASSERT(m_iActivePage >= 0);
ASSERT(m_iActivePage <= m_arrHistoryStack.GetUpperBound ());
int nOldActivePageIdx = m_arrHistoryStack[m_iActivePage];
if (m_lstTasksPanes.GetCount () == 1)
{
int nOldActivePage = m_iActivePage;
m_iActivePage = 0;
ChangeActivePage (0, nOldActivePage); // Default page
}
else if (nOldActivePageIdx >= nPageIdx)
{
int nOldActivePage = m_iActivePage;
m_iActivePage--;
ChangeActivePage (m_iActivePage, nOldActivePage);
}
else if (GetSafeHwnd () != NULL)
{
RebuildMenu ();
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
//-----------------------------------------------
// First, remove all tasks groups from this page:
//-----------------------------------------------
for (POSITION pos = m_lstTaskGroups.GetHeadPosition (); pos != NULL;)
{
POSITION posSave = pos;
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID(pGroup);
if (pGroup->m_pPage == pPage)
{
m_lstTaskGroups.RemoveAt (posSave);
delete pGroup;
}
}
//-------------
// Remove page:
//-------------
pos = m_lstTasksPanes.FindIndex (nPageIdx);
ASSERT(pos != NULL);
m_lstTasksPanes.RemoveAt (pos);
delete pPage;
// ----------------
// Refresh history:
// ----------------
CArray <int, int> arrCopy;
arrCopy.Copy (m_arrHistoryStack);
m_arrHistoryStack.RemoveAll ();
for (int i=0; i < arrCopy.GetSize (); i++)
{
if (arrCopy[i] < nPageIdx)
{
m_arrHistoryStack.Add (arrCopy[i]);
}
else if (arrCopy[i] > nPageIdx)
{
m_arrHistoryStack.Add (arrCopy[i]-1);
}
}
RebuildMenu ();
}
//******************************************************************************************
void CBCGPTasksPane::RemoveAllPages ()
{
//----------------------
// Reset an active page:
//----------------------
m_iActivePage = 0;
ChangeActivePage (0, m_iActivePage); // Default page
m_arrHistoryStack.RemoveAll ();
m_arrHistoryStack.Add (0);
//--------------------------------------------------------
// First, remove all tasks group except from default page:
//--------------------------------------------------------
for (POSITION pos = m_lstTaskGroups.FindIndex (1); pos != NULL;)
{
POSITION posSave = pos;
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID(pGroup);
if (pGroup->m_pPage != NULL) // except default page
{
m_lstTaskGroups.RemoveAt (posSave);
delete pGroup;
}
}
//----------------------------------
// Remove pages except default page:
//----------------------------------
while (m_lstTasksPanes.GetCount () > 1)
{
delete m_lstTasksPanes.RemoveTail ();
}
}
//******************************************************************************************
int CBCGPTasksPane::AddGroup (int nPageIdx, LPCTSTR lpszGroupName, BOOL bBottomLocation/* = FALSE*/,
BOOL bSpecial/* = FALSE*/, HICON hIcon/* = NULL*/)
{
ASSERT (nPageIdx >= 0);
ASSERT (nPageIdx <= m_lstTasksPanes.GetCount ()-1);
// ---------------
// Get active page
// ---------------
CBCGPTasksPanePage* pActivePage = NULL;
POSITION posPage = m_lstTasksPanes.FindIndex (nPageIdx);
ASSERT(posPage != NULL);
pActivePage = (CBCGPTasksPanePage*) m_lstTasksPanes.GetAt (posPage);
ASSERT_VALID(pActivePage);
// -------------
// Add new group
// -------------
for (POSITION pos = m_lstTaskGroups.GetHeadPosition (); pos != NULL;)
{
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID (pGroup);
if (pGroup->m_pPage == pActivePage)
{
if (pGroup->m_bIsBottom)
{
pGroup->m_bIsBottom = FALSE;
}
}
}
m_lstTaskGroups.AddTail (new CBCGPTasksGroup (lpszGroupName, bBottomLocation,
bSpecial, FALSE, pActivePage, hIcon));
AdjustScroll ();
ReposTasks ();
return m_lstTaskGroups.GetCount () - 1;
}
//******************************************************************************************
void CBCGPTasksPane::RemoveGroup (int nGroup)
{
ASSERT (nGroup >= 0);
ASSERT (nGroup < m_lstTaskGroups.GetCount ());
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
m_lstTaskGroups.RemoveAt (pos);
delete pGroup;
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
//******************************************************************************************
void CBCGPTasksPane::RemoveAllGroups (int nPageIdx/* = 0*/)
{
ASSERT (nPageIdx >= 0);
ASSERT (nPageIdx < m_lstTasksPanes.GetCount ());
POSITION posPage = m_lstTasksPanes.FindIndex (nPageIdx);
if (posPage == NULL)
{
ASSERT (FALSE);
return;
}
CBCGPTasksPanePage* pPage = (CBCGPTasksPanePage*) m_lstTasksPanes.GetAt (posPage);
ASSERT_VALID (pPage);
//----------------------------------------
// Remove all tasks groups from this page:
//----------------------------------------
for (POSITION pos = m_lstTaskGroups.GetHeadPosition (); pos != NULL;)
{
POSITION posSave = pos;
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID(pGroup);
if (pGroup->m_pPage == pPage)
{
m_lstTaskGroups.RemoveAt (posSave);
delete pGroup;
}
}
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
//******************************************************************************************
BOOL CBCGPTasksPane::SetGroupName (int nGroup, LPCTSTR lpszGroupName)
{
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
BOOL bCaptionWasEmpty = pGroup->m_strName.IsEmpty();
pGroup->m_strName = lpszGroupName;
if ((!bCaptionWasEmpty && pGroup->m_strName.IsEmpty()) ||
(bCaptionWasEmpty && !pGroup->m_strName.IsEmpty()))
{
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
else
{
InvalidateRect (&pGroup->m_rect);
}
return TRUE;
}
//******************************************************************************************
BOOL CBCGPTasksPane::CollapseGroup (CBCGPTasksGroup* pGroup, BOOL bCollapse)
{
ASSERT_VALID (pGroup);
if ((!bCollapse && pGroup->m_bIsCollapsed) ||
(bCollapse && !pGroup->m_bIsCollapsed))
{
pGroup->m_bIsCollapsed = bCollapse;
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
return TRUE;
}
//******************************************************************************************
CBCGPTasksGroup* CBCGPTasksPane::GetTaskGroup (int nGroup) const
{
ASSERT(nGroup >= 0);
ASSERT(nGroup < m_lstTaskGroups.GetCount ());
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
return NULL;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
return pGroup;
}
//******************************************************************************************
BOOL CBCGPTasksPane::GetGroupLocation (CBCGPTasksGroup* pGroup, int &nGroup) const
{
ASSERT_VALID (pGroup);
int nGroupCount = 0;
for (POSITION pos = m_lstTaskGroups.GetHeadPosition (); pos != NULL; nGroupCount++)
{
CBCGPTasksGroup* pTaskGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID (pTaskGroup);
if (pTaskGroup == pGroup)
{
nGroup = nGroupCount;
return TRUE;
}
}
return FALSE; // not found
}
//******************************************************************************************
int CBCGPTasksPane::AddTask (int nGroup, LPCTSTR lpszTaskName, int nTaskIcon/* = -1*/,
UINT uiCommandID/* = 0*/, DWORD dwUserData/* = 0*/)
{
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return -1;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
pGroup->m_lstTasks.AddTail (new CBCGPTask (
pGroup, lpszTaskName, nTaskIcon, uiCommandID, dwUserData));
AdjustScroll ();
ReposTasks ();
return pGroup->m_lstTasks.GetCount () - 1;
}
//*********************************************************************************
BOOL CBCGPTasksPane::SetTaskName (int nGroup, int nTask, LPCTSTR lpszTaskName)
{
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
pos = pGroup->m_lstTasks.FindIndex (nTask);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTask* pTask = (CBCGPTask*) pGroup->m_lstTasks.GetAt (pos);
pTask->m_strName = lpszTaskName;
if (pTask->m_bVisible)
InvalidateRect (pTask->m_rect);
return TRUE;
}
//******************************************************************************************
BOOL CBCGPTasksPane::ShowTask (int nGroup, int nTask, BOOL bShow)
{
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
pos = pGroup->m_lstTasks.FindIndex (nTask);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTask* pTask = (CBCGPTask*) pGroup->m_lstTasks.GetAt (pos);
if ((!bShow && pTask->m_bVisible) ||
(bShow && !pTask->m_bVisible))
{
pTask->m_bVisible = bShow;
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
return TRUE;
}
//******************************************************************************************
BOOL CBCGPTasksPane::ShowTaskByCmdId (UINT uiCommandID, BOOL bShow)
{
int nGroup, nTask;
if (!GetTaskLocation (uiCommandID, nGroup, nTask))
return FALSE;
return ShowTask (nGroup, nTask, bShow);
}
//******************************************************************************************
BOOL CBCGPTasksPane::RemoveTask (int nGroup, int nTask)
{
ASSERT(nGroup >= 0);
ASSERT(nGroup < m_lstTaskGroups.GetCount ());
POSITION pos = m_lstTaskGroups.FindIndex (nGroup);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetAt (pos);
ASSERT_VALID (pGroup);
pos = pGroup->m_lstTasks.FindIndex (nTask);
if (pos == NULL)
{
ASSERT (FALSE);
return FALSE;
}
delete pGroup->m_lstTasks.GetAt (pos);
pGroup->m_lstTasks.RemoveAt (pos);
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
return TRUE;
}
//******************************************************************************************
void CBCGPTasksPane::RemoveAllTasks (int nGroup)
{
ASSERT(nGroup >= 0);
ASSERT(nGroup < m_lstTaskGroups.GetCount ());
CBCGPTasksGroup* pGroup = GetTaskGroup (nGroup);
ASSERT_VALID (pGroup);
while (!pGroup->m_lstTasks.IsEmpty ())
{
delete pGroup->m_lstTasks.RemoveHead ();
}
AdjustScroll ();
ReposTasks ();
RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
//******************************************************************************************
BOOL CBCGPTasksPane::GetTaskLocation (UINT uiCommandID, int& nGroup, int& nTask) const
{
nGroup = 0;
for (POSITION pos = m_lstTaskGroups.GetHeadPosition (); pos != NULL; ++nGroup)
{
CBCGPTasksGroup* pGroup = (CBCGPTasksGroup*) m_lstTaskGroups.GetNext (pos);
ASSERT_VALID (pGroup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -