Theme.cpp 4.3 KB

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