Theme.cpp 4.2 KB

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