SPColorManager.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. #include "stdafx.h"
  2. #include <math.h>
  3. #include "SPColorManager.h"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. //===========================================================================
  10. // CSPPaintManagerColorGradient class
  11. //===========================================================================
  12. void CSPPaintManagerColorGradient::SetStandardValue( COLORREF _clrLight , COLORREF _clrDark )
  13. {
  14. clrLight.SetStandardValue( _clrLight );
  15. clrDark.SetStandardValue( _clrDark );
  16. }
  17. void CSPPaintManagerColorGradient::SetStandardValue( const COLORREF & clr )
  18. {
  19. SetStandardValue( clr,clr );
  20. }
  21. void CSPPaintManagerColorGradient::SetCustomValue( COLORREF _clrLight , COLORREF _clrDark )
  22. {
  23. clrLight.SetCustomValue( _clrLight );
  24. clrDark.SetCustomValue( _clrDark );
  25. }
  26. //===========================================================================
  27. // CSPColorManager class
  28. //===========================================================================
  29. #pragma warning( disable : 4244 )
  30. #define clrToolBar GetColor(XPCOLOR_TOOLBAR_FACE)
  31. #define clrWindow GetColor(COLOR_WINDOW)
  32. #define clrHighlight GetColor(COLOR_HIGHLIGHT)
  33. #define pow2(x) pow(x, 2)
  34. #define NORMVALUE(a, b) a = (a < 0) ? 0 : (a > b) ? b : a
  35. //#define UNIQUEVALUE _T("7GWBBA98PRVEBP49JESYMATY1EMQU")
  36. CSPColorManager::CSPColorManager()
  37. {
  38. m_bDisableLunaColors = FALSE;
  39. m_bInit = FALSE;
  40. m_systemTheme = SPSystemThemeAuto;
  41. m_pfnGetSysColor = 0;
  42. for ( int i = 0; i <= XPCOLOR_LAST; i++ )
  43. {
  44. m_arrCustomColor[i] = ( COLORREF ) - 1;
  45. }
  46. RefreshColors();
  47. }
  48. CSPColorManager& AFX_CDECL CSPColorManager::Instance()
  49. {
  50. static CSPColorManager instance;
  51. return instance;
  52. }
  53. float CSPColorManager::ColorWidth( int nLength , int nWidth )
  54. {
  55. if ( nLength > 220 )
  56. {
  57. nLength = 220;
  58. }
  59. return ( 2.0 - ( float ) nLength / 220 ) * nWidth;
  60. }
  61. float CSPColorManager::ColorDelta( COLORREF clrA , COLORREF clrB )
  62. {
  63. return pow2( GetRDelta( clrA ) - GetRDelta( clrB ) ) + pow2( GetGDelta( clrA ) - GetGDelta( clrB ) ) + pow2( GetBDelta( clrA ) - GetBDelta( clrB ) );
  64. }
  65. float CSPColorManager::Length( COLORREF clrA , COLORREF clrB )
  66. {
  67. return sqrt( ColorDelta( clrA,clrB ) );
  68. }
  69. BOOL CSPColorManager::LongColor( COLORREF clrMain , COLORREF clrSub , BOOL bCalcLength , float fDistance )
  70. {
  71. if ( bCalcLength )
  72. {
  73. fDistance = ColorWidth( Length( clrMain,0 ),fDistance );
  74. }
  75. return pow2( fDistance ) < ColorDelta( clrMain,clrSub );
  76. }
  77. COLORREF CSPColorManager::MixColor( COLORREF clrMain , COLORREF clrSub , float fDistance )
  78. {
  79. float fMainLength = Length( clrMain,0 );
  80. float fGate = ColorWidth( fMainLength,fDistance );
  81. BOOL bReverse = TRUE;
  82. if ( Length( clrSub,0 ) > fMainLength )
  83. {
  84. if ( fMainLength > 442 - fGate )
  85. {
  86. bReverse = FALSE;
  87. }
  88. }
  89. else
  90. {
  91. if ( fMainLength > fGate )
  92. {
  93. bReverse = FALSE;
  94. }
  95. }
  96. float fSubRed = GetRDelta( clrSub );
  97. float fSubGreen = GetGDelta( clrSub );
  98. float fSubBlue = GetBDelta( clrSub );
  99. float fMainRed = GetRDelta( clrMain );
  100. float fMainGreen = GetGDelta( clrMain );
  101. float fMainBlue = GetBDelta( clrMain );
  102. if ( bReverse )
  103. {
  104. fSubRed = 195.0 - fSubRed;
  105. fSubGreen = 390.0 - fSubGreen;
  106. fSubBlue = 65.0 - fSubBlue;
  107. fMainRed = 195.0 - fMainRed;
  108. fMainGreen = 390.0 - fMainGreen;
  109. fMainBlue = 65.0 - fMainBlue;
  110. }
  111. float A = __max( 0.001,sqrt( pow2( fSubRed ) + pow2( fSubGreen ) + pow2( fSubBlue ) ) );
  112. float B = fMainRed * fSubRed + fMainGreen * fSubGreen + fMainBlue * fSubBlue;
  113. float X = B / pow2( A );
  114. float fR = X * fSubRed - fMainRed;
  115. float fG = X * fSubGreen - fMainGreen;
  116. float fB = X * fSubBlue - fMainBlue;
  117. float Y = sqrt( pow2( fGate ) - ( pow2( fR ) + pow2( fG ) + pow2( fB ) ) );
  118. float Z = ( B / A - Y );
  119. fR = Z * fSubRed / A;
  120. fG = Z * fSubGreen / A;
  121. fB = Z * fSubBlue / A;
  122. if ( bReverse )
  123. {
  124. fR = 195.0 - fR;
  125. fG = 390.0 - fG;
  126. fB = 65.0 - fB;
  127. }
  128. NORMVALUE( fR,195.0 );
  129. NORMVALUE( fG,390.0 );
  130. NORMVALUE( fB,65.0 );
  131. int nR = .5 + fR * ( 255.0 / 195.0 );
  132. int nG = .5 + fG * ( 255.0 / 390.0 );
  133. int nB = .5 + fB * ( 255.0 / 65.0 );
  134. return RGB( NORMVALUE( nR,255 ),NORMVALUE( nG,255 ),NORMVALUE( nB,255 ) );
  135. }
  136. COLORREF CSPColorManager::AdjustColor( COLORREF clrMain , COLORREF clrSub , float fDistance )
  137. {
  138. float Z = sqrt( pow2( GetRDelta( clrMain ) - GetRDelta( clrSub ) ) + pow2( GetGDelta( clrMain ) - GetGDelta( clrSub ) ) + pow2( GetBDelta( clrMain ) - GetBDelta( clrSub ) ) );
  139. float Q = ( Z - ColorWidth( Length( 0,clrMain ),fDistance ) ) / Z;
  140. float fR = Q * ( GetRDelta( clrMain ) - GetRDelta( clrSub ) ) + GetRDelta( clrSub );
  141. float fG = Q * ( GetGDelta( clrMain ) - GetGDelta( clrSub ) ) + GetGDelta( clrSub );
  142. float fB = Q * ( GetBDelta( clrMain ) - GetBDelta( clrSub ) ) + GetBDelta( clrSub );
  143. NORMVALUE( fR,195.0 );
  144. NORMVALUE( fG,390.0 );
  145. NORMVALUE( fB,65.0 );
  146. int nR = .5 + fR * ( 255.0 / 195.0 );
  147. int nG = .5 + fG * ( 255.0 / 390.0 );
  148. int nB = .5 + fB * ( 255.0 / 65.0 );
  149. return RGB( NORMVALUE( nR,255 ),NORMVALUE( nG,255 ),NORMVALUE( nB,255 ) );
  150. }
  151. COLORREF CSPColorManager::LightColor( COLORREF clrLight , COLORREF clrDark , int nDelta )
  152. {
  153. int nParam = ( nDelta < 100 ? 100 : 1000 );
  154. int nR = ( GetRValue( clrDark ) * ( nParam - nDelta ) + nParam / 2 + GetRValue( clrLight ) * nDelta ) / nParam;
  155. int nG = ( GetGValue( clrDark ) * ( nParam - nDelta ) + nParam / 2 + GetGValue( clrLight ) * nDelta ) / nParam;
  156. int nB = ( GetBValue( clrDark ) * ( nParam - nDelta ) + nParam / 2 + GetBValue( clrLight ) * nDelta ) / nParam;
  157. return RGB( nR,nG,nB );
  158. }
  159. COLORREF CSPColorManager::GetColor( int nIndex )
  160. {
  161. if ( nIndex > XPCOLOR_LAST )
  162. {
  163. return nIndex;
  164. }
  165. return m_arrCustomColor[nIndex] == ( COLORREF ) - 1 ? m_arrStandardColor[nIndex] : m_arrCustomColor[nIndex];
  166. }
  167. void CSPColorManager::RefreshSysColors()
  168. {
  169. m_arrStandardColor[0] = 0;
  170. for ( int i = 1; i < 28; i++ )
  171. {
  172. m_arrStandardColor[i] = ( m_pfnGetSysColor != 0 ? ( *m_pfnGetSysColor ) ( i ) : GetSysColor( i ) );
  173. }
  174. }
  175. void CSPColorManager::SetGetSysColorPtr( PFNGETSYSCOLOR pfnGetSysColor )
  176. {
  177. m_pfnGetSysColor = pfnGetSysColor;
  178. RefreshColors();
  179. }
  180. void CSPColorManager::RefreshXPColors()
  181. {
  182. COLORREF clr3DFace = GetColor( COLOR_3DFACE );
  183. COLORREF clr3DShadow = GetColor( COLOR_3DSHADOW );
  184. m_arrStandardColor[XPCOLOR_TOOLBAR_FACE] = clr3DFace;
  185. m_arrStandardColor[XPCOLOR_HIGHLIGHT] = GetColor( COLOR_WINDOW );
  186. m_arrStandardColor[XPCOLOR_HIGHLIGHT_PUSHED] = GetColor( COLOR_HIGHLIGHT );
  187. m_arrStandardColor[XPCOLOR_MENUBAR_FACE] = GetColor( COLOR_WINDOW );
  188. m_arrStandardColor[XPCOLOR_GRAYTEXT] = GetColor( COLOR_GRAYTEXT );
  189. m_arrStandardColor[XPCOLOR_TOOLBAR_GRIPPER] = clr3DShadow;
  190. m_arrStandardColor[XPCOLOR_SEPARATOR] = clr3DShadow;
  191. m_arrStandardColor[XPCOLOR_MENUBAR_BORDER] = clr3DShadow;
  192. m_arrStandardColor[XPCOLOR_DISABLED] = clr3DShadow;
  193. m_arrStandardColor[XPCOLOR_HIGHLIGHT_CHECKED] = GetColor( COLOR_WINDOW );
  194. m_arrStandardColor[XPCOLOR_HIGHLIGHT_BORDER] = GetColor( COLOR_HIGHLIGHT );
  195. m_arrStandardColor[XPCOLOR_HIGHLIGHT_CHECKED_BORDER] = GetColor( COLOR_HIGHLIGHT );
  196. m_arrStandardColor[XPCOLOR_MENUBAR_TEXT] = GetColor( COLOR_WINDOWTEXT );
  197. m_arrStandardColor[XPCOLOR_HIGHLIGHT_TEXT] = GetColor( COLOR_MENUTEXT );
  198. m_arrStandardColor[XPCOLOR_TOOLBAR_TEXT] = GetColor( COLOR_BTNTEXT );
  199. m_arrStandardColor[XPCOLOR_PUSHED_TEXT] = GetColor( COLOR_HIGHLIGHTTEXT );
  200. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_BACK] = clr3DFace;
  201. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_TEXT] = GetColor( COLOR_BTNTEXT );
  202. m_arrStandardColor[XPCOLOR_MENUBAR_EXPANDED] = clr3DShadow;
  203. m_arrStandardColor[XPCOLOR_HIGHLIGHT_PUSHED_BORDER] = GetColor( COLOR_HIGHLIGHT );
  204. m_arrStandardColor[XPCOLOR_ICONSHADDOW] = clr3DShadow;
  205. m_arrStandardColor[XPCOLOR_3DFACE] = clr3DFace;
  206. m_arrStandardColor[XPCOLOR_3DSHADOW] = clr3DShadow;
  207. m_arrStandardColor[XPCOLOR_EDITCTRLBORDER] = clr3DFace;
  208. m_arrStandardColor[XPCOLOR_FRAME] = clr3DShadow;
  209. m_arrStandardColor[XPCOLOR_SPLITTER_FACE] = clr3DFace;
  210. m_arrStandardColor[XPCOLOR_LABEL] = clr3DFace;
  211. m_arrStandardColor[XPCOLOR_STATICFRAME] = clr3DShadow;
  212. }
  213. void CSPColorManager::RefreshGradientColors()
  214. {
  215. SPCurrentSystemTheme systemTheme = GetCurrentSystemTheme();
  216. grcCaption.SetStandardValue( GetColor( COLOR_3DSHADOW ),GetColor( COLOR_3DSHADOW ) );
  217. grcDockBar.SetStandardValue( GetColor( COLOR_3DFACE ),LightColor( GetColor( COLOR_3DFACE ),GetColor( COLOR_WINDOW ),0xcd ) );
  218. grcShortcutBarGripper.SetStandardValue( GetColor( COLOR_3DFACE ),GetColor( COLOR_3DSHADOW ) );
  219. grcToolBar.SetStandardValue( LightColor( GetColor( COLOR_3DFACE ),GetColor( COLOR_WINDOW ),0xcd ),GetColor( COLOR_3DFACE ) );
  220. if ( !m_bDisableLunaColors )
  221. {
  222. switch ( systemTheme )
  223. {
  224. case SPSystemThemeBlue:
  225. {
  226. m_arrStandardColor[XPCOLOR_FRAME] = RGB( 0,45,150 );
  227. grcCaption.SetStandardValue( RGB( 89,135,214 ),RGB( 0,45,150 ) );
  228. grcDockBar.SetStandardValue( RGB( 158,190,245 ),RGB( 196,218,250 ) );
  229. grcShortcutBarGripper.SetStandardValue( RGB( 89,135,214 ),RGB( 0,45,150 ) );
  230. grcToolBar.SetStandardValue( RGB( 221,236,254 ),RGB( 129,169,226 ) );
  231. }
  232. break;
  233. case SPSystemThemeOlive:
  234. {
  235. m_arrStandardColor[XPCOLOR_FRAME] = RGB( 96,128,88 );;
  236. grcCaption.SetStandardValue( RGB( 175,192,130 ),RGB( 99,122,68 ) );
  237. grcDockBar.SetStandardValue( RGB( 217,217,167 ),RGB( 242,241,228 ) );
  238. grcShortcutBarGripper.SetStandardValue( RGB( 120,142,111 ),RGB( 73,91,67 ) );
  239. grcToolBar.SetStandardValue( RGB( 244,247,222 ),RGB( 183,198,145 ) );
  240. }
  241. break;
  242. case SPSystemThemeSilver:
  243. {
  244. m_arrStandardColor[XPCOLOR_FRAME] = RGB( 124,124,148 );
  245. grcCaption.SetStandardValue( RGB( 168,167,191 ),RGB( 112,111,145 ) );
  246. grcDockBar.SetStandardValue( RGB( 215,215,229 ),RGB( 243,243,247 ) );
  247. grcShortcutBarGripper.SetStandardValue( RGB( 168,167,191 ),RGB( 119,118,151 ) );
  248. grcToolBar.SetStandardValue( RGB( 243,244,250 ),RGB( 153,151,181 ) );
  249. }
  250. break;
  251. }
  252. }
  253. }
  254. void CSPColorManager::RefreshColors( BOOL bInit )
  255. {
  256. if ( bInit && m_bInit )
  257. {
  258. return;
  259. }
  260. m_bInit = TRUE;
  261. struct MUTECOLOR
  262. {
  263. int nIndex;
  264. int clrMain;
  265. int clrSub;
  266. int nDistance;
  267. } ;
  268. BOOL bSimpleColors = FALSE;
  269. CDC * pDC = CWnd::GetDesktopWindow()->GetDC();
  270. if ( pDC )
  271. {
  272. int nColors = pDC->GetDeviceCaps( BITSPIXEL );
  273. CWnd::GetDesktopWindow()->ReleaseDC( pDC );
  274. bSimpleColors = ( nColors > 0 && nColors <= 8 );
  275. }
  276. RefreshSysColors();
  277. RefreshXPColors();
  278. if ( bSimpleColors )
  279. {
  280. RefreshGradientColors();
  281. return;
  282. }
  283. const MUTECOLOR IndexTable[] ={{ XPCOLOR_TOOLBAR_FACE, COLOR_WINDOW, COLOR_3DFACE, 165 }, { XPCOLOR_HIGHLIGHT, COLOR_HIGHLIGHT, COLOR_WINDOW, 0x1E }, { XPCOLOR_HIGHLIGHT_PUSHED, COLOR_HIGHLIGHT, COLOR_WINDOW, 0x32 }, { XPCOLOR_MENUBAR_FACE, COLOR_3DFACE, COLOR_WINDOW, 0x8f }, { XPCOLOR_GRAYTEXT, COLOR_GRAYTEXT, COLOR_WINDOW, 0x46 }, { XPCOLOR_TOOLBAR_GRIPPER, COLOR_3DSHADOW, COLOR_WINDOW, 0x4b }, { XPCOLOR_SEPARATOR, COLOR_3DSHADOW, COLOR_WINDOW, 0x46 }, { XPCOLOR_MENUBAR_BORDER, XPCOLOR_TOOLBAR_TEXT, COLOR_BTNSHADOW, 0x14 }, { XPCOLOR_DISABLED, COLOR_3DSHADOW, COLOR_WINDOW, 0x5A }, { XPCOLOR_MENUBAR_EXPANDED, COLOR_3DFACE, COLOR_3DSHADOW, 90 }};
  284. int i;
  285. for ( i = 0; i < sizeof( IndexTable ) / sizeof( IndexTable[0] ); i++ )
  286. {
  287. m_arrStandardColor[IndexTable[i].nIndex] = LightColor( GetColor( IndexTable[i].clrMain ),GetColor( IndexTable[i].clrSub ),IndexTable[i].nDistance );
  288. }
  289. const MUTECOLOR LongTable[] ={{ XPCOLOR_HIGHLIGHT, XPCOLOR_TOOLBAR_FACE, XPCOLOR_HIGHLIGHT, 50 }, { XPCOLOR_HIGHLIGHT_BORDER, XPCOLOR_TOOLBAR_FACE, COLOR_HIGHLIGHT, 100 }, { XPCOLOR_HIGHLIGHT_PUSHED, XPCOLOR_TOOLBAR_FACE, XPCOLOR_HIGHLIGHT_PUSHED, 30 }, { XPCOLOR_GRAYTEXT, XPCOLOR_MENUBAR_FACE, XPCOLOR_GRAYTEXT, 80 }, { XPCOLOR_HIGHLIGHT_CHECKED_BORDER, XPCOLOR_HIGHLIGHT_PUSHED, XPCOLOR_HIGHLIGHT_CHECKED_BORDER, 100 }, { XPCOLOR_TOOLBAR_GRIPPER, XPCOLOR_TOOLBAR_FACE, XPCOLOR_TOOLBAR_GRIPPER, 85 }, { XPCOLOR_SEPARATOR, XPCOLOR_TOOLBAR_FACE, XPCOLOR_SEPARATOR, 50 }, { XPCOLOR_MENUBAR_BORDER, XPCOLOR_PUSHED_TEXT, XPCOLOR_MENUBAR_BORDER, 100 }, { XPCOLOR_DISABLED, XPCOLOR_TOOLBAR_FACE, XPCOLOR_DISABLED, 80 }, { XPCOLOR_MENUBAR_TEXT, XPCOLOR_MENUBAR_FACE, XPCOLOR_MENUBAR_TEXT, 180 }, { XPCOLOR_HIGHLIGHT_TEXT, XPCOLOR_HIGHLIGHT, XPCOLOR_HIGHLIGHT_TEXT, 180 }, { XPCOLOR_TOOLBAR_TEXT, XPCOLOR_TOOLBAR_FACE, XPCOLOR_TOOLBAR_TEXT, 180 }, { XPCOLOR_PUSHED_TEXT, XPCOLOR_HIGHLIGHT_PUSHED, XPCOLOR_PUSHED_TEXT, 180 }};
  290. if ( LongColor( GetColor( COLOR_3DFACE ),GetColor( XPCOLOR_TOOLBAR_FACE ),1,35 ) )
  291. {
  292. m_arrStandardColor[XPCOLOR_TOOLBAR_FACE] = AdjustColor( GetColor( COLOR_3DFACE ),GetColor( XPCOLOR_TOOLBAR_FACE ),35 );
  293. }
  294. for ( i = 0; i < sizeof( LongTable ) / sizeof( LongTable[0] ); i++ )
  295. {
  296. if ( !LongColor( GetColor( LongTable[i].clrMain ),GetColor( LongTable[i].clrSub ),1,LongTable[i].nDistance ) )
  297. {
  298. m_arrStandardColor[LongTable[i].nIndex] = MixColor( GetColor( LongTable[i].clrMain ),GetColor( LongTable[i].clrSub ),LongTable[i].nDistance );
  299. }
  300. }
  301. if ( LongColor( GetColor( XPCOLOR_MENUBAR_FACE ),GetColor( XPCOLOR_GRAYTEXT ),1,145 ) )
  302. {
  303. m_arrStandardColor[XPCOLOR_GRAYTEXT] = AdjustColor( GetColor( XPCOLOR_MENUBAR_FACE ),GetColor( XPCOLOR_GRAYTEXT ),145 );
  304. }
  305. m_arrStandardColor[XPCOLOR_HIGHLIGHT_CHECKED] = RGB( GetRValue( clrWindow ) * 40 / 100 + GetRValue( clrHighlight ) * 10 / 100 + GetRValue( clrToolBar ) * 50 / 100,GetGValue( clrWindow ) * 40 / 100 + GetGValue( clrHighlight ) * 10 / 100 + GetGValue( clrToolBar ) * 50 / 100,GetBValue( clrWindow ) * 40 / 100 + GetBValue( clrHighlight ) * 10 / 100 + GetBValue( clrToolBar ) * 50 / 100 );
  306. COLORREF clrBtn = GetColor( COLOR_3DFACE );
  307. int r = GetRValue( clrBtn), g = GetGValue( clrBtn ), b = GetBValue( clrBtn );
  308. int nMax = __max( __max( r,g ),b );
  309. if ( nMax == 0 )
  310. {
  311. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_BACK] = RGB( 35,35,35 );
  312. }
  313. else
  314. {
  315. int nDelta = __min( 35,255 - nMax ) + nMax;
  316. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_BACK] = RGB( r * nDelta / nMax,g * nDelta / nMax,b * nDelta / nMax );
  317. }
  318. COLORREF clrShadow = GetColor( COLOR_3DSHADOW );
  319. r = GetRValue( clrShadow ), g = GetGValue( clrShadow ), b = GetBValue( clrShadow );
  320. nMax = __max( __max( r,g ),b );
  321. if ( clrBtn == 0 )
  322. {
  323. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_TEXT] = RGB( 0x7f,0x7f,0x7f );
  324. }
  325. else if ( nMax == 0 )
  326. {
  327. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_TEXT] = RGB( 0,0,0 );
  328. }
  329. else
  330. {
  331. int nDelta = __max( 0,nMax - 43 );
  332. m_arrStandardColor[XPCOLOR_TAB_INACTIVE_TEXT] = RGB( r * nDelta / nMax,g * nDelta / nMax,b * nDelta / nMax );
  333. }
  334. COLORREF clrBackground = m_arrStandardColor[XPCOLOR_HIGHLIGHT];
  335. m_arrStandardColor[XPCOLOR_ICONSHADDOW] = RGB( GetRValue( clrBackground ) * .75,GetGValue( clrBackground ) * .75,GetBValue( clrBackground ) * .75 );
  336. m_arrStandardColor[COLOR_3DLIGHT] = RGB( min( GetRValue( clrBtn ) + 15,255 ),min( GetGValue( clrBtn ) + 15,255 ),min( GetBValue( clrBtn ) + 15,255 ) );
  337. m_arrStandardColor[XPCOLOR_EDITCTRLBORDER] = GetColor( XPCOLOR_TOOLBAR_FACE );
  338. RefreshGradientColors();
  339. //CSPWinThemeWrapper wrpTreeView;
  340. //wrpTreeView.OpenTheme( 0,L"TREEVIEW" );
  341. //if ( wrpTreeView.IsAppThemed() )
  342. //{
  343. // wrpTreeView.GetThemeColor(0, 0, TMT_BORDERCOLOR, &m_arrStandardColor[XPCOLOR_STATICFRAME]);
  344. //}
  345. }
  346. void CSPColorManager::SetColors( int cElements , CONST INT * lpaElements , CONST COLORREF * lpaRgbValues )
  347. {
  348. for ( int i = 0; i < cElements; i++ )
  349. {
  350. m_arrCustomColor[lpaElements[i]] = lpaRgbValues[i];
  351. }
  352. }
  353. void CSPColorManager::SetColor( int nIndex , COLORREF clrValue )
  354. {
  355. m_arrCustomColor[nIndex] = clrValue;
  356. }
  357. double CSPColorManager::GetRDelta( COLORREF clr )
  358. {
  359. return GetRValue( clr ) * ( 195.0 / 255.0 );
  360. }
  361. double CSPColorManager::GetGDelta( COLORREF clr )
  362. {
  363. return GetGValue( clr ) * ( 390.0 / 255.0 );
  364. }
  365. double CSPColorManager::GetBDelta( COLORREF clr )
  366. {
  367. return GetBValue( clr ) * ( 65.0 / 255.0 );
  368. }
  369. void CSPColorManager::DisableLunaColors( BOOL bDisable )
  370. {
  371. m_bDisableLunaColors = bDisable;
  372. }
  373. BOOL CSPColorManager::IsLunaColorsDisabled()
  374. {
  375. return m_bDisableLunaColors;
  376. }
  377. void CSPColorManager::SetLunaTheme( SPCurrentSystemTheme systemTheme )
  378. {
  379. m_systemTheme = systemTheme;
  380. }
  381. SPCurrentSystemTheme CSPColorManager::GetWinThemeWrapperTheme()
  382. {
  383. WCHAR pszThemeFileName[MAX_PATH];
  384. WCHAR pszColorBuff[MAX_PATH];
  385. // get the name of the current theme in use.
  386. // if ( CSPWinThemeWrapper().GetCurrentThemeName( pszThemeFileName,MAX_PATH,pszColorBuff,MAX_PATH,NULL,0 ) != S_OK )
  387. // {
  388. // return SPSystemThemeUnknown;
  389. // }
  390. // search for "luna.msstyles" string in theme name.
  391. if ( wcsstr( _wcslwr( pszThemeFileName ),L"luna.msstyles" ) )
  392. {
  393. if ( wcscmp( _wcslwr( pszColorBuff ),L"normalcolor" ) == 0 )
  394. return SPSystemThemeBlue;
  395. if ( wcscmp( _wcslwr( pszColorBuff ),L"homestead" ) == 0 )
  396. return SPSystemThemeOlive;
  397. if ( wcscmp( _wcslwr( pszColorBuff ),L"metallic" ) == 0 )
  398. return SPSystemThemeSilver;
  399. }
  400. return SPSystemThemeUnknown;
  401. }
  402. SPCurrentSystemTheme CSPColorManager::GetCurrentSystemTheme()
  403. {
  404. if ( m_systemTheme != SPSystemThemeAuto && m_systemTheme != SPSystemThemeDefault )
  405. {
  406. return m_systemTheme;
  407. }
  408. return GetWinThemeWrapperTheme();
  409. }