Theme.cpp 4.4 KB

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