Theme.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "stdafx.h"
  2. #include ".\theme.h"
  3. #include "shared/TextConvert.h"
  4. #include "Misc.h"
  5. #include "Options.h"
  6. #include "shared/Tokenizer.h"
  7. CTheme::CTheme(void)
  8. {
  9. m_lFileVersion = 0;
  10. m_LastWriteTime = 0;
  11. m_lastTheme = _T("");
  12. m_CaptionLeft = RGB(0, 84, 195);
  13. m_CaptionRight = RGB(61, 149, 255);
  14. m_CaptionLeftTopMost = RGB(122, 150, 223);
  15. m_CaptionRightTopMost = RGB(157, 185, 235);
  16. m_CaptionLeftNotConnected = RGB(255, 0, 0);
  17. m_CaptionRightNotConnected = RGB(255, 0, 0);
  18. m_CaptionTextColor = RGB(255, 255, 255);
  19. m_ListBoxOddRowsBG = RGB(255, 255, 255);
  20. m_ListBoxEvenRowsBG = RGB(240, 240, 240);
  21. m_ListBoxOddRowsText = RGB(0, 0, 0);
  22. m_ListBoxEvenRowsText = RGB(0, 0, 0);
  23. m_ListBoxSelectedBG = RGB(30, 116, 211);
  24. m_ListBoxSelectedNoFocusBG = RGB(236, 233, 216);
  25. m_ListBoxSelectedText = RGB(255, 255, 255);
  26. m_ListBoxSelectedNoFocusText = RGB(0, 0, 0);
  27. }
  28. CTheme::~CTheme(void)
  29. {
  30. }
  31. bool CTheme::Load(CString csTheme, bool bHeaderOnly, bool bCheckLastWriteTime)
  32. {
  33. if(csTheme.IsEmpty())
  34. return false;
  35. CString csPath = CGetSetOptions::GetPath(PATH_THEMES);
  36. csPath += csTheme;
  37. csPath += ".xml";
  38. __int64 LastWrite = GetLastWriteTime(csPath);
  39. if(bCheckLastWriteTime)
  40. {
  41. if(m_lastTheme == csTheme &&
  42. LastWrite == m_LastWriteTime)
  43. {
  44. return true;
  45. }
  46. }
  47. m_LastWriteTime = LastWrite;
  48. m_lastTheme = csTheme;
  49. Log(StrF(_T("Loading Theme %s"), csPath));
  50. CStringA csPathA = CTextConvert::ConvertToChar(csPath);
  51. TiXmlDocument doc(csPathA);
  52. if(!doc.LoadFile())
  53. {
  54. m_csLastError.Format(_T("Error loading Theme %s - reason = %s"), csPath, doc.ErrorDesc());
  55. ASSERT(!m_csLastError);
  56. Log(m_csLastError);
  57. return false;
  58. }
  59. TiXmlElement *ItemHeader = doc.FirstChildElement("Ditto_Theme_File");
  60. if(!ItemHeader)
  61. {
  62. m_csLastError.Format(_T("Error finding the section Ditto_Theme_File"));
  63. ASSERT(!m_csLastError);
  64. Log(m_csLastError);
  65. return false;
  66. }
  67. CString csVersion = ItemHeader->Attribute("Version");
  68. m_lFileVersion = ATOI(csVersion);
  69. m_csAuthor = ItemHeader->Attribute("Author");
  70. m_csNotes = ItemHeader->Attribute("Notes");
  71. if(bHeaderOnly)
  72. return true;
  73. LoadElement(ItemHeader, "CaptionLeft", m_CaptionLeft);
  74. LoadElement(ItemHeader, "CaptionRight", m_CaptionRight);
  75. LoadElement(ItemHeader, "CaptionLeftTopMost", m_CaptionLeftTopMost);
  76. LoadElement(ItemHeader, "CaptionRightTopMost", m_CaptionRightTopMost);
  77. LoadElement(ItemHeader, "CaptionLeftNotConnected", m_CaptionLeftNotConnected);
  78. LoadElement(ItemHeader, "CaptionRightNotConnected", m_CaptionRightNotConnected);
  79. LoadElement(ItemHeader, "CaptionTextColor", m_CaptionTextColor);
  80. LoadElement(ItemHeader, "ListBoxOddRowsBG", m_ListBoxOddRowsBG);
  81. LoadElement(ItemHeader, "ListBoxEvenRowsBG", m_ListBoxEvenRowsBG);
  82. LoadElement(ItemHeader, "ListBoxOddRowsText", m_ListBoxOddRowsText);
  83. LoadElement(ItemHeader, "ListBoxEvenRowsText", m_ListBoxEvenRowsText);
  84. LoadElement(ItemHeader, "ListBoxSelectedBG", m_ListBoxSelectedBG);
  85. LoadElement(ItemHeader, "ListBoxSelectedNoFocusBG", m_ListBoxSelectedNoFocusBG);
  86. LoadElement(ItemHeader, "ListBoxSelectedText", m_ListBoxSelectedText);
  87. LoadElement(ItemHeader, "ListBoxSelectedNoFocusText", m_ListBoxSelectedNoFocusText);
  88. return true;
  89. }
  90. bool CTheme::LoadElement(TiXmlElement *pParent, CStringA csNode, COLORREF &Color)
  91. {
  92. TiXmlElement *pColorNode = pParent->FirstChildElement(csNode);
  93. if(pColorNode == NULL)
  94. {
  95. m_csLastError.Format(_T("Theme Load, error loading Node = %s"), csNode);
  96. Log(m_csLastError);
  97. return false;
  98. }
  99. TiXmlNode *pColor = pColorNode->FirstChild();
  100. if(pColor == NULL)
  101. {
  102. m_csLastError.Format(_T("Theme Load, error getting node text for = %s"), csNode);
  103. Log(m_csLastError);
  104. return false;
  105. }
  106. CString csColor = pColor->Value();
  107. csColor = csColor.Trim();
  108. csColor.Replace(_T("RGB("), _T(""));
  109. csColor.Replace(_T(")"), _T(""));
  110. CTokenizer token(csColor, _T(","));
  111. CString csR;
  112. CString csG;
  113. CString csB;
  114. token.Next(csR);
  115. token.Next(csG);
  116. token.Next(csB);
  117. csR = csR.Trim();
  118. csG = csG.Trim();
  119. csB = csB.Trim();
  120. //Only the first is valid they entered the RGB value as a single number
  121. if(csR != "" && csG == "" && csB == "")
  122. {
  123. Color = ATOI(csR);
  124. }
  125. else
  126. {
  127. Color = RGB(ATOI(csR), ATOI(csG), ATOI(csB));
  128. }
  129. return true;
  130. }