SkinPropertyPageThemes.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:10k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // SkinPropertyPageThemes.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "SkinPropertyPageThemes.h"
  6. #include "SkinPropertySheet.h"
  7. #include "MainFrm.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSkinPropertyPageThemes property page
  14. CSkinPropertyPageThemes::CSkinPropertyPageThemes() : CPropertyPage(CSkinPropertyPageThemes::IDD)
  15. {
  16. //{{AFX_DATA_INIT(CSkinPropertyPageThemes)
  17. m_nSchema = 3;
  18. m_nLocalSkins = 0;
  19. m_bApplyMetrics = TRUE;
  20. m_bApplyColors = TRUE;
  21. m_bApplyFrame = TRUE;
  22. m_nTheme = xtpThemeNativeWinXP;
  23. //}}AFX_DATA_INIT
  24. }
  25. CSkinPropertyPageThemes::~CSkinPropertyPageThemes()
  26. {
  27. }
  28. void CSkinPropertyPageThemes::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CPropertyPage::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CSkinPropertyPageThemes)
  32. DDX_Control(pDX, IDC_LIST_THEMES, m_lboxSkins);
  33. DDX_Control(pDX, IDC_COMBO_FONTS, m_cmbFonts);
  34. DDX_Control(pDX, IDC_COMBO_COLORS, m_cmbColors);
  35. DDX_Radio(pDX, IDC_RADIO_OFFICE2000, m_nTheme);
  36. DDX_Radio(pDX, IDC_RADIO_OFFICE2007, m_nSchema);
  37. DDX_Radio(pDX, IDC_RADIO_SKINPATH, m_nLocalSkins);
  38. DDX_Check(pDX, IDC_CHECK_APPLYMETRICS, m_bApplyMetrics);
  39. DDX_Check(pDX, IDC_CHECK_APPLYFRAME, m_bApplyFrame);
  40. DDX_Check(pDX, IDC_CHECK_APPLYCOLORS, m_bApplyColors);
  41. //}}AFX_DATA_MAP
  42. }
  43. IMPLEMENT_DYNCREATE(CSkinPropertyPageThemes, CPropertyPage)
  44. BEGIN_MESSAGE_MAP(CSkinPropertyPageThemes, CPropertyPage)
  45. //{{AFX_MSG_MAP(CSkinPropertyPageThemes)
  46. ON_BN_CLICKED(IDC_RADIO_OFFICE2007, OnRadioSchema)
  47. ON_BN_CLICKED(IDC_RADIO_LUNA, OnRadioSchema)
  48. ON_BN_CLICKED(IDC_RADIO_ROYALE, OnRadioSchema)
  49. ON_BN_CLICKED(IDC_RADIO_VISTA, OnRadioSchema)
  50. ON_BN_CLICKED(IDC_RADIO_DEFAULT, OnRadioSchema)
  51. ON_BN_CLICKED(IDC_RADIO_SKINPATH, ReloadThemes)
  52. ON_LBN_SELCHANGE(IDC_LIST_THEMES, OnSelChangeListThemes)
  53. ON_CBN_SELCHANGE(IDC_COMBO_COLORS, OnSelChangeComboColors)
  54. ON_CBN_SELCHANGE(IDC_COMBO_FONTS, OnSelChangeComboFonts)
  55. ON_WM_DESTROY()
  56. ON_BN_CLICKED(IDC_CHECK_APPLYMETRICS, OnCheckApplyMetrics)
  57. ON_BN_CLICKED(IDC_CHECK_APPLYFRAME, OnCheckApplyFrame)
  58. ON_BN_CLICKED(IDC_CHECK_APPLYCOLORS, OnCheckApplyColors)
  59. ON_BN_CLICKED(IDC_RADIO_SKINPATH2, ReloadThemes)
  60. ON_BN_CLICKED(IDC_RADIO_OFFICE2000, OnThemeChanged)
  61. ON_BN_CLICKED(IDC_RADIO_OFFICE2003, OnThemeChanged)
  62. ON_BN_CLICKED(IDC_RADIO_OFFICEXP, OnThemeChanged)
  63. ON_BN_CLICKED(IDC_RADIO_WINTHEME, OnThemeChanged)
  64. ON_BN_CLICKED(IDC_RADIO_OFFICE2003_BLUE, OnThemeChangedLuna)
  65. ON_BN_CLICKED(IDC_RADIO_OFFICE2003_OLIVE, OnThemeChangedLuna)
  66. ON_BN_CLICKED(IDC_RADIO_OFFICE2003_METALLIC, OnThemeChangedLuna)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. void CSkinPropertyPageThemes::OnRadioSchema() 
  70. {
  71. UpdateData();
  72. ((CMainFrame*)AfxGetMainWnd())->OnShemaChanged(m_nSchema);
  73. }
  74. void CSkinPropertyPageThemes::EnumerateThemeColors(CXTPSkinManagerResourceFile* pFile, LPCTSTR lpszResourcePath, LPCTSTR lpszThemeName) 
  75. {
  76. THEME* pTheme= new THEME;
  77. pTheme->strResourcePath = lpszResourcePath;
  78. CString str;
  79. CString strIniFile;
  80. CString csColorSchemes;
  81. CString csSizes;
  82. while(pFile->ReadString(str))
  83. {
  84. str.TrimLeft();
  85. if (str.IsEmpty())
  86. continue;
  87. if (str[1] == _T(';'))
  88. continue;
  89. if (str.Left(5).CompareNoCase(_T("[file")) == 0)
  90. {
  91. strIniFile = str.Mid(6, str.GetLength() - 7) + _T(".ini");
  92. csColorSchemes.Empty();
  93. csSizes.Empty();
  94. }
  95. else if (str[1] == _T('['))
  96. {
  97. strIniFile.Empty();
  98. csColorSchemes.Empty();
  99. csSizes.Empty();
  100. }
  101. else if (!strIniFile.IsEmpty())
  102. {
  103. int nPos = str.Find(_T('='));
  104. if (nPos > 0 && str.Left(12).CompareNoCase(_T("ColorSchemes")) == 0)
  105. {
  106. csColorSchemes = str.Mid(nPos + 1);
  107. csColorSchemes.TrimLeft();
  108. }
  109. if (nPos > 0 && str.Left(5).CompareNoCase(_T("Sizes")) == 0)
  110. {
  111. csSizes = str.Mid(nPos + 1);
  112. csSizes.TrimLeft();
  113. }
  114. if (!csSizes.IsEmpty() && !csColorSchemes.IsEmpty())
  115. {
  116. THEMEINFO* pThemeInfo = new THEMEINFO();
  117. pThemeInfo->csIniFileName = strIniFile;
  118. pThemeInfo->csColorSchemes = csColorSchemes;
  119. pThemeInfo->csSizes = csSizes;
  120. pThemeInfo->pTheme = pTheme;
  121. pTheme->m_arrThemes.Add(pThemeInfo);
  122. strIniFile.Empty();
  123. }
  124. }
  125. }
  126. if (pTheme->m_arrThemes.GetSize() == 0)
  127. {
  128. delete pTheme;
  129. return;
  130. }
  131. int nIndex = m_lboxSkins.AddString(lpszThemeName);
  132. m_lboxSkins.SetItemDataPtr(nIndex, pTheme);
  133. }
  134. void CSkinPropertyPageThemes::EnumerateThemes(CString strResourcePath) 
  135. {
  136. CXTPSkinManagerResourceFile f;
  137. if (!f.Open(strResourcePath, _T("Themes.ini")))
  138. return;
  139. TCHAR szSkinName[256];
  140. if (::LoadString(f.GetModuleHandle(), 5000, szSkinName, 256))
  141. {
  142. EnumerateThemeColors(&f, strResourcePath, szSkinName);
  143. return;
  144. }
  145. }
  146. void CSkinPropertyPageThemes::FindThemes(CString strPath, BOOL bRecurse)
  147. {
  148. CFileFind f;
  149. BOOL bNext = f.FindFile(strPath + _T("*.*"));
  150. while(bNext)
  151. {
  152. bNext = f.FindNextFile();
  153. if (f.IsDots())
  154. continue;
  155. if (f.IsDirectory())
  156. {
  157. if (bRecurse)
  158. {
  159. FindThemes(f.GetFilePath() + "\", TRUE);
  160. }
  161. }
  162. else 
  163. {
  164. CString strExtension = f.GetFileName().Right(9);
  165. if ((strExtension.CompareNoCase(_T(".msstyles")) == 0) || (strExtension.CompareNoCase(_T(".cjstyles")) == 0))
  166. {
  167. EnumerateThemes(f.GetFilePath());
  168. }
  169. }
  170. }
  171. m_lboxSkins.SetCurSel(-1);
  172. }
  173. BOOL CSkinPropertyPageThemes::OnInitDialog() 
  174. {
  175. CPropertyPage::OnInitDialog();
  176. ReloadThemes();
  177. return TRUE;  // return TRUE unless you set the focus to a control
  178.               // EXCEPTION: OCX Property Pages should return FALSE
  179. }
  180. void CSkinPropertyPageThemes::ReleaseThemes()
  181. {
  182. for (int i = 0; i < m_lboxSkins.GetCount(); i++)
  183. {
  184. THEME* pTheme = (THEME*)m_lboxSkins.GetItemDataPtr(i);
  185. for (int j = 0; j < pTheme->m_arrThemes.GetSize(); j++)
  186. {
  187. delete pTheme->m_arrThemes[j];
  188. }
  189. delete pTheme;
  190. }
  191. m_lboxSkins.ResetContent();
  192. m_cmbFonts.ResetContent();
  193. m_cmbColors.ResetContent();
  194. }
  195. void CSkinPropertyPageThemes::ReloadThemes()
  196. {
  197. UpdateData();
  198. ReleaseThemes();
  199. if (m_nLocalSkins == 0)
  200. {
  201. CString csStylesPath = CMainFrame::GetStylesPath();
  202. FindThemes(csStylesPath, FALSE);
  203. }
  204. else
  205. {
  206. CString csStylesPath;
  207. GetWindowsDirectory(csStylesPath.GetBuffer(MAX_PATH), MAX_PATH);
  208. csStylesPath.ReleaseBuffer();
  209. FindThemes(csStylesPath + _T("\Resources\Themes\"), TRUE);
  210. }
  211. }
  212. void CSkinPropertyPageThemes::OnSelChangeListThemes() 
  213. {
  214. m_cmbColors.ResetContent();
  215. m_cmbFonts.ResetContent();
  216. int nCurSel = m_lboxSkins.GetCurSel();
  217. if (nCurSel == LB_ERR)
  218. return;
  219. THEME* pTheme = (THEME*)m_lboxSkins.GetItemDataPtr(nCurSel);
  220. for (int i = 0; i < pTheme->m_arrThemes.GetSize(); i++)
  221. {
  222. THEMEINFO* pThemeInfo = pTheme->m_arrThemes[i];
  223. if (m_cmbColors.FindStringExact(-1, pThemeInfo->csColorSchemes) == LB_ERR)
  224. {
  225. int nIndex = m_cmbColors.AddString(pThemeInfo->csColorSchemes);
  226. m_cmbColors.SetItemDataPtr(nIndex, pThemeInfo);
  227. }
  228. if (m_cmbFonts.FindStringExact(-1, pThemeInfo->csSizes) == LB_ERR)
  229. {
  230. int nIndex = m_cmbFonts.AddString(pThemeInfo->csSizes);
  231. m_cmbFonts.SetItemDataPtr(nIndex, pThemeInfo);
  232. }
  233. }
  234. m_cmbColors.SetCurSel(0);
  235. m_cmbFonts.SetCurSel(0);
  236. OnSelChangeComboColors();
  237. }
  238. void CSkinPropertyPageThemes::SetTheme(int nColor, int nFont)
  239. {
  240. UpdateData();
  241. if (nColor == LB_ERR)
  242. return;
  243. THEMEINFO* pThemeInfo = (THEMEINFO*)m_cmbColors.GetItemDataPtr(nColor);
  244. CString csColorSchemes = pThemeInfo->csColorSchemes;
  245. CString csSizes;
  246. if (nFont != LB_ERR && m_bApplyMetrics)
  247. {
  248. THEMEINFO* pThemeInfo = (THEMEINFO*)m_cmbFonts.GetItemDataPtr(nFont);
  249. csSizes = pThemeInfo->csSizes;
  250. }
  251. THEME* pTheme = pThemeInfo->pTheme;
  252. for (int i = 0; i < pTheme->m_arrThemes.GetSize(); i++)
  253. {
  254. THEMEINFO* pThemeInfo = pTheme->m_arrThemes[i];
  255. if (pThemeInfo->csColorSchemes == csColorSchemes && 
  256. (csSizes.IsEmpty() || pThemeInfo->csSizes == csSizes))
  257. {
  258. XTPSkinManager()->LoadSkin(pTheme->strResourcePath, pThemeInfo->csIniFileName);
  259. break;
  260. }
  261. }
  262. CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
  263. pWnd->OnSkinChanged();
  264. pWnd->RedrawFrame(this);
  265. }
  266. void CSkinPropertyPageThemes::OnSelChangeComboColors() 
  267. {
  268. SetTheme(m_cmbColors.GetCurSel(), m_cmbFonts.GetCurSel());
  269. }
  270. void CSkinPropertyPageThemes::OnSelChangeComboFonts() 
  271. {
  272. SetTheme(m_cmbColors.GetCurSel(), m_cmbFonts.GetCurSel());
  273. }
  274. void CSkinPropertyPageThemes::OnDestroy() 
  275. {
  276. ReleaseThemes();
  277. CPropertyPage::OnDestroy();
  278. }
  279. void CSkinPropertyPageThemes::OnCheckApplyMetrics() 
  280. {
  281. UpdateData();
  282. DWORD dwApplyOptions = XTPSkinManager()->GetApplyOptions();
  283. if (m_bApplyMetrics)
  284. XTPSkinManager()->SetApplyOptions(dwApplyOptions | xtpSkinApplyMetrics);
  285. else
  286. XTPSkinManager()->SetApplyOptions(dwApplyOptions & ~xtpSkinApplyMetrics);
  287. m_cmbFonts.EnableWindow(m_bApplyMetrics);
  288. }
  289. void CSkinPropertyPageThemes::OnCheckApplyFrame() 
  290. {
  291. UpdateData();
  292. DWORD dwApplyOptions = XTPSkinManager()->GetApplyOptions();
  293. if (m_bApplyFrame)
  294. XTPSkinManager()->SetApplyOptions(dwApplyOptions | xtpSkinApplyFrame);
  295. else
  296. XTPSkinManager()->SetApplyOptions(dwApplyOptions & ~xtpSkinApplyFrame);
  297. }
  298. void CSkinPropertyPageThemes::OnCheckApplyColors() 
  299. {
  300. UpdateData();
  301. DWORD dwApplyOptions = XTPSkinManager()->GetApplyOptions();
  302. if (m_bApplyColors)
  303. XTPSkinManager()->SetApplyOptions(dwApplyOptions | xtpSkinApplyColors);
  304. else
  305. XTPSkinManager()->SetApplyOptions(dwApplyOptions & ~xtpSkinApplyColors);
  306. }
  307. void CSkinPropertyPageThemes::OnThemeChanged() 
  308. {
  309. XTPColorManager()->SetLunaTheme(xtpSystemThemeAuto);
  310. UpdateData();
  311. CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
  312. pWnd->SetTheme(m_nTheme);
  313. }
  314. void CSkinPropertyPageThemes::OnThemeChangedLuna() 
  315. {
  316. UpdateData();
  317. XTPColorManager()->SetLunaTheme(XTPCurrentSystemTheme(xtpSystemThemeBlue + m_nTheme - 4));
  318. CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
  319. pWnd->SetTheme(xtpThemeOffice2003);
  320. }