preferencesuitasklistcolorspage.cpp

来自「管理项目进度工具的原代码」· C++ 代码 · 共 767 行 · 第 1/2 页

CPP
767
字号
	GetDlgItem(IDC_TREEFONTLIST)->EnableWindow(m_bSpecifyTreeFont);
	GetDlgItem(IDC_TREEFONTSIZE)->EnableWindow(m_bSpecifyTreeFont);
	GetDlgItem(IDC_TREEFONTSIZELABEL)->EnableWindow(m_bSpecifyTreeFont);
	GetDlgItem(IDC_COMMENTSUSETREEFONT)->EnableWindow(m_bSpecifyTreeFont);

	GetDlgItem(IDC_SPECIFYCOMMENTSFONT)->EnableWindow(!m_bCommentsUseTreeFont || !m_bSpecifyTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZE)->EnableWindow(m_bSpecifyCommentsFont && !m_bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZELABEL)->EnableWindow(m_bSpecifyCommentsFont && !m_bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTLIST)->EnableWindow(m_bSpecifyCommentsFont && !m_bCommentsUseTreeFont);

	if (m_bSpecifyTreeFont)
		m_cbTreeFonts.SetSelectedFont(m_sTreeFont);
}

BOOL CPreferencesUITasklistColorsPage::GetTreeFont(CString& sFaceName, int& nPointSize) const
{
	if (m_bSpecifyTreeFont)
	{
		sFaceName = m_sTreeFont;
		nPointSize = m_nTreeFontSize;
	}

	return m_bSpecifyTreeFont;
}

BOOL CPreferencesUITasklistColorsPage::GetCommentsFont(CString& sFaceName, int& nPointSize) const
{
	if ((m_bSpecifyTreeFont && m_bCommentsUseTreeFont) || !m_bSpecifyCommentsFont)
		return FALSE;

	sFaceName = m_sCommentsFont;
	nPointSize = m_nCommentsFontSize;

	return m_bSpecifyCommentsFont;
}

void CPreferencesUITasklistColorsPage::OnSetgridlinecolor() 
{
	m_crGridlines = m_btGridlineColor.GetColor();
}

void CPreferencesUITasklistColorsPage::OnSpecifygridlinecolor() 
{
	UpdateData();	

	m_btGridlineColor.EnableWindow(m_bSpecifyGridColor);
}

void CPreferencesUITasklistColorsPage::OnSetdonecolor() 
{
	m_crDone = m_btDoneColor.GetColor();
}

void CPreferencesUITasklistColorsPage::OnSpecifydonecolor() 
{
	UpdateData();	

	m_btDoneColor.EnableWindow(m_bSpecifyDoneColor);
}

void CPreferencesUITasklistColorsPage::OnAltlinecolor() 
{
	m_crAltLine = m_btAltLineColor.GetColor();
}

void CPreferencesUITasklistColorsPage::OnSpecifyAlternatelinecolor() 
{
	UpdateData();	
	
	m_btAltLineColor.EnableWindow(m_bAlternateLineColor);
}

void CPreferencesUITasklistColorsPage::OnChangeTextColorOption() 
{
	UpdateData();

	// if the text color option is COLOROPT_PRIORITY and 
	// the user has got priority coloring turned off then switch it on
	if (!m_bColorPriority && m_nTextColorOption == COLOROPT_PRIORITY)
	{
		m_bColorPriority = TRUE;
		UpdateData(FALSE);

		OnColorPriority();
	}

	GetDlgItem(IDC_CATEGORYCOLORS)->EnableWindow(m_nTextColorOption == COLOROPT_CATEGORY);
	m_btCatColor.EnableWindow(m_nTextColorOption == COLOROPT_CATEGORY && 
								!m_sSelCategory.IsEmpty());
}

void CPreferencesUITasklistColorsPage::OnSetcategorycolor() 
{
	UpdateData();

	int nColor = FindCategoryColor(m_sSelCategory);

	if (nColor >= 0)
		m_aCategoryColors[nColor].color = m_btCatColor.GetColor();
	else
	{
		CATCOLOR cc;
		cc.sCategory = m_sSelCategory;
		cc.color = m_btCatColor.GetColor();

		m_aCategoryColors.Add(cc);
	}
}

int CPreferencesUITasklistColorsPage::FindCategoryColor(LPCTSTR szCategory)
{
	int nColor = m_aCategoryColors.GetSize();

	while (nColor--)
	{
		CATCOLOR& cc = m_aCategoryColors[nColor];

		if (cc.sCategory.CompareNoCase(szCategory) == 0)
			return nColor;
	}

	return -1;
}

void CPreferencesUITasklistColorsPage::OnEditCategorycolors() 
{
	UpdateData();

	m_btCatColor.EnableWindow(m_nTextColorOption == COLOROPT_CATEGORY && 
								!m_sSelCategory.IsEmpty());
}

void CPreferencesUITasklistColorsPage::OnSelchangeCategorycolors() 
{
	UpdateData();

	int nSel = m_cbCategories.GetCurSel();
	m_cbCategories.GetLBText(nSel, m_sSelCategory);
	
	int nColor = FindCategoryColor(m_sSelCategory);

	if (nColor >= 0)
		m_btCatColor.SetColor(m_aCategoryColors[nColor].color);

	m_btCatColor.EnableWindow(m_nTextColorOption == COLOROPT_CATEGORY && 
								!m_sSelCategory.IsEmpty());
}

LRESULT CPreferencesUITasklistColorsPage::OnCategoryAdded(WPARAM /*wParam*/, LPARAM lParam)
{
   CString sCategory((LPCTSTR)lParam);

   if (!sCategory.IsEmpty() && FindCategoryColor(sCategory) != -1)
   {
		CATCOLOR cc;
		cc.sCategory = sCategory;
		cc.color = 0;

		m_aCategoryColors.Add(cc);
   }
  
   return 0L;
}

LRESULT CPreferencesUITasklistColorsPage::OnCategoryDeleted(WPARAM /*wParam*/, LPARAM lParam)
{
   CString sCategory((LPCTSTR)lParam);

   if (!sCategory.IsEmpty())
   {
      int nDel = FindCategoryColor(sCategory);

      if (nDel != -1)
         m_aCategoryColors.RemoveAt(nDel);
   }
  
   return 0L;
}

void CPreferencesUITasklistColorsPage::OnCommentsusetreefont() 
{
	UpdateData();

	BOOL bCommentsUseTreeFont = (m_bCommentsUseTreeFont && m_bSpecifyTreeFont);
	GetDlgItem(IDC_SPECIFYCOMMENTSFONT)->EnableWindow(!bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZE)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZELABEL)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTLIST)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);
}

void CPreferencesUITasklistColorsPage::OnSpecifycommentsfont() 
{
	UpdateData();
	
	BOOL bCommentsUseTreeFont = (m_bCommentsUseTreeFont && m_bSpecifyTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZE)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTSIZELABEL)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);
	GetDlgItem(IDC_COMMENTSFONTLIST)->EnableWindow(m_bSpecifyCommentsFont && !bCommentsUseTreeFont);

	if (m_bSpecifyCommentsFont && !bCommentsUseTreeFont)
		m_cbCommentsFonts.SetSelectedFont(m_sCommentsFont);
}

void CPreferencesUITasklistColorsPage::OnDuetaskcolor() 
{
	UpdateData();	
	
	m_btDueColor.EnableWindow(m_bSpecifyDueColor);
}

void CPreferencesUITasklistColorsPage::OnDuetodaytaskcolor() 
{
	UpdateData();	
	
	m_btDueTodayColor.EnableWindow(m_bSpecifyDueTodayColor);
}

void CPreferencesUITasklistColorsPage::OnSetduetaskcolor() 
{
	m_crDue = m_btDueColor.GetColor();
}

void CPreferencesUITasklistColorsPage::OnSetduetodaytaskcolor() 
{
	m_crDueToday = m_btDueTodayColor.GetColor();
}

void CPreferencesUITasklistColorsPage::LoadPreferences(const CPreferencesStorage& prefs)
{
	m_crLow = prefs.GetProfileInt("Preferences\\Colors", "Low", PRIORITYLOWCOLOR);
	m_crHigh = prefs.GetProfileInt("Preferences\\Colors", "High", PRIORITYHIGHCOLOR);

	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P0", RGB(30, 225, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P1", RGB(30, 225, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P2", RGB(30, 225, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P3", RGB(30, 225, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P4", RGB(0, 0, 255)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P5", RGB(0, 0, 255)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P6", RGB(0, 0, 255)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P7", RGB(0, 0, 255)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P8", RGB(255, 0, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P9", RGB(255, 0, 0)));
	m_aPriorityColors.Add(prefs.GetProfileInt("Preferences\\Colors", "P10", RGB(255, 0, 0)));

	// category colors
	int nColor = prefs.GetProfileInt("Preferences\\CatColors", "Count", 0);

	while (nColor--)
	{
		CString sKey;
		sKey.Format("Preferences\\CatColors\\P%d", nColor);

		CATCOLOR cc;
		cc.color = prefs.GetProfileInt(sKey, "Color", 0);
		cc.sCategory = prefs.GetProfileString(sKey, "Category");

		if (!cc.sCategory.IsEmpty())
		{
			m_sSelCategory = cc.sCategory;
			m_aCategoryColors.Add(cc);
		}
	}

	// add in the users default categories
	CStringArray aDefCats;
	prefs.GetArrayItems("Preferences\\CategoryList", aDefCats);

	int nDefColor = aDefCats.GetSize();

	while (nDefColor--)
	{
		const CString& sDefCat = aDefCats[nDefColor];

		if (sDefCat.IsEmpty())
			continue;

		// make sure this category is not already specified
		nColor = m_aCategoryColors.GetSize();

		while (nColor--)
		{
			if (m_aCategoryColors[nColor].sCategory.CompareNoCase(sDefCat) == 0) // match
				break;
		}

		if (nColor >= 0) // match
			continue; // skip

		CATCOLOR cc;
		cc.color = 0;
		cc.sCategory = sDefCat;

		m_sSelCategory = sDefCat;
		m_aCategoryColors.Add(cc);
	}
	
	// prefs
	m_bColorPriority = prefs.GetProfileInt("Preferences", "ColorPriority", TRUE);
	m_bGradientPriorityColors = !prefs.GetProfileInt("Preferences", "IndividualPriorityColors", FALSE);
	m_sTreeFont = prefs.GetProfileString("Preferences", "TreeFont", "Arial");
	m_nTreeFontSize = prefs.GetProfileInt("Preferences", "FontSize", 8);
	m_bSpecifyTreeFont = prefs.GetProfileInt("Preferences", "SpecifyTreeFont", FALSE);
	m_sCommentsFont = prefs.GetProfileString("Preferences", "CommentsFont", "Arial");
	m_nCommentsFontSize = prefs.GetProfileInt("Preferences", "CommentsFontSize", 8);
	m_bSpecifyCommentsFont = prefs.GetProfileInt("Preferences", "SpecifyCommentsFont", FALSE);
	m_bSpecifyGridColor = prefs.GetProfileInt("Preferences", "SpecifyGridColor", TRUE);
	m_crGridlines = prefs.GetProfileInt("Preferences\\Colors", "Gridlines", GRIDLINECOLOR);
	m_bSpecifyDoneColor = prefs.GetProfileInt("Preferences", "SpecifyDoneColor", TRUE);
	m_bSpecifyDueColor = prefs.GetProfileInt("Preferences", "SpecifyDueColor", FALSE);
	m_bSpecifyDueTodayColor = prefs.GetProfileInt("Preferences", "SpecifyDueTodayColor", FALSE);
	m_crDone = prefs.GetProfileInt("Preferences\\Colors", "TaskDone", TASKDONECOLOR);
	m_crDue = prefs.GetProfileInt("Preferences\\Colors", "TaskDue", TASKDUECOLOR);
	m_crDueToday = prefs.GetProfileInt("Preferences\\Colors", "TaskDueToday", TASKDUECOLOR);
	m_bColorTaskBackground = prefs.GetProfileInt("Preferences", "ColorTaskBackground", FALSE);
	m_bCommentsUseTreeFont = prefs.GetProfileInt("Preferences", "CommentsUseTreeFont", FALSE);
	m_bHLSColorGradient = prefs.GetProfileInt("Preferences", "HLSColorGradient", TRUE);
	m_bHidePriorityNumber = prefs.GetProfileInt("Preferences", "HidePriorityNumber", FALSE);
	m_bAlternateLineColor = prefs.GetProfileInt("Preferences", "AlternateLineColor", TRUE);
	m_crAltLine = prefs.GetProfileInt("Preferences\\Colors", "AlternateLines", ALTERNATELINECOLOR);

	// bkwds compatibility
	if (prefs.GetProfileInt("Preferences", "ColorByPriority", FALSE))
		m_nTextColorOption = COLOROPT_PRIORITY;

	m_nTextColorOption = prefs.GetProfileInt("Preferences", "TextColorOption", m_nTextColorOption);
}

void CPreferencesUITasklistColorsPage::SavePreferences(CPreferencesStorage& prefs)
{
	// save settings
	// priority colors
	prefs.WriteProfileInt("Preferences\\Colors", "Low", m_crLow);
	prefs.WriteProfileInt("Preferences\\Colors", "High", m_crHigh);

	int nColor = 11;

	while (nColor--)
	{
		CString sKey;
		sKey.Format("P%d", nColor);
		prefs.WriteProfileInt("Preferences\\Colors", sKey, m_aPriorityColors[nColor]);
	}

	// category colors
	nColor = m_aCategoryColors.GetSize();
	prefs.WriteProfileInt("Preferences\\CatColors", "Count", nColor);

	while (nColor--)
	{
		CString sKey;
		sKey.Format("Preferences\\CatColors\\P%d", nColor);

		const CATCOLOR& cc = m_aCategoryColors[nColor];
		prefs.WriteProfileInt(sKey, "Color", cc.color);
		prefs.WriteProfileString(sKey, "Category", cc.sCategory);
	}

	// save settings
	prefs.WriteProfileInt("Preferences", "TextColorOption", m_nTextColorOption);
	prefs.WriteProfileInt("Preferences", "ColorPriority", m_bColorPriority);
	prefs.WriteProfileInt("Preferences", "IndividualPriorityColors", !m_bGradientPriorityColors);
	prefs.WriteProfileString("Preferences", "TreeFont", m_sTreeFont);
	prefs.WriteProfileInt("Preferences", "FontSize", m_nTreeFontSize);
	prefs.WriteProfileInt("Preferences", "SpecifyTreeFont", m_bSpecifyTreeFont);
	prefs.WriteProfileString("Preferences", "CommentsFont", m_sCommentsFont);
	prefs.WriteProfileInt("Preferences", "CommentsFontSize", m_nCommentsFontSize);
	prefs.WriteProfileInt("Preferences", "SpecifyCommentsFont", m_bSpecifyCommentsFont);
	prefs.WriteProfileInt("Preferences", "SpecifyGridColor", m_bSpecifyGridColor);
	prefs.WriteProfileInt("Preferences\\Colors", "Gridlines", m_crGridlines);
	prefs.WriteProfileInt("Preferences", "SpecifyDoneColor", m_bSpecifyDoneColor);
	prefs.WriteProfileInt("Preferences\\Colors", "TaskDone", m_crDone);
	prefs.WriteProfileInt("Preferences", "SpecifyDueColor", m_bSpecifyDueColor);
	prefs.WriteProfileInt("Preferences\\Colors", "TaskDue", m_crDue);
	prefs.WriteProfileInt("Preferences", "SpecifyDueTodayColor", m_bSpecifyDueTodayColor);
	prefs.WriteProfileInt("Preferences\\Colors", "TaskDueToday", m_crDueToday);
	prefs.WriteProfileInt("Preferences", "ColorTaskBackground", m_bColorTaskBackground);
	prefs.WriteProfileInt("Preferences", "CommentsUseTreeFont", m_bCommentsUseTreeFont);
	prefs.WriteProfileInt("Preferences", "HLSColorGradient", m_bHLSColorGradient);
	prefs.WriteProfileInt("Preferences", "HidePriorityNumber", m_bHidePriorityNumber);
	prefs.WriteProfileInt("Preferences\\Colors", "AlternateLines", m_crAltLine);
	prefs.WriteProfileInt("Preferences", "AlternateLineColor", m_bAlternateLineColor);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?