SPPPropertyGridPaintManager.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #include "stdafx.h"
  7. //#include "Tmschema.h"
  8. #include "SPVC80Helpers.h"
  9. #include "SPDrawHelpers.h"
  10. #include "SPPropertyGridPaintManager.h"
  11. #include "SPPropertyGridInplaceEdit.h"
  12. #include "SPPropertyGridInplaceButton.h"
  13. #include "SPPropertyGridInplaceList.h"
  14. #include "SPPropertyGridItem.h"
  15. #include "SPPropertyGrid.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21. //////////////////////////////////////////////////////////////////////
  22. // Construction/Destruction
  23. //////////////////////////////////////////////////////////////////////
  24. CSPPropertyGridPaintManager::CSPPropertyGridPaintManager( CSPPropertyGrid * pGrid ) : m_pGrid( pGrid )
  25. {
  26. m_bThemed = FALSE;
  27. LOGFONT lfIcon;
  28. VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT,sizeof( lfIcon ),&lfIcon,0 ) );
  29. lfIcon.lfWeight = FW_NORMAL;
  30. lfIcon.lfItalic = FALSE;
  31. VERIFY( m_fntVerbNormal.CreateFontIndirect( &lfIcon ) );
  32. lfIcon.lfUnderline = TRUE;
  33. VERIFY( m_fntVerbUnderline.CreateFontIndirect( &lfIcon ) );
  34. RefreshMetrics();
  35. }
  36. CSPPropertyGridPaintManager::~CSPPropertyGridPaintManager()
  37. {
  38. }
  39. void CSPPropertyGridPaintManager::RefreshMetrics()
  40. {
  41. SPColorManager()->RefreshColors();
  42. m_clrFace = GetXtremeColor( COLOR_3DFACE );
  43. m_clrShadow = GetXtremeColor( COLOR_3DSHADOW );
  44. m_clrVerbFace = GetXtremeColor( COLOR_ACTIVECAPTION );
  45. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  46. m_pGrid->m_clrHelpBack.SetStandardValue( m_clrFace );
  47. m_pGrid->m_clrHelpFore.SetStandardValue( GetXtremeColor( COLOR_BTNTEXT ) );
  48. pView->m_clrLine.SetStandardValue( GetSysColor( COLOR_SCROLLBAR ) );
  49. pView->m_clrCategoryFore.SetStandardValue( GetXtremeColor( COLOR_GRAYTEXT ) );
  50. pView->m_clrBack.SetStandardValue( GetXtremeColor( COLOR_WINDOW ) );
  51. pView->m_clrFore.SetStandardValue( GetXtremeColor( COLOR_WINDOWTEXT ) );
  52. pView->m_clrReadOnlyFore.SetStandardValue( GetXtremeColor( COLOR_GRAYTEXT ) );
  53. }
  54. void CSPPropertyGridPaintManager::FillPropertyGrid( CDC * pDC )
  55. {
  56. CSPClientRect rc ( m_pGrid );
  57. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  58. pDC->FillSolidRect( rc,m_clrFace );
  59. pDC->SetBkMode( TRANSPARENT );
  60. if ( m_pGrid->IsHelpVisible() )
  61. {
  62. CSPPenDC pen ( *pDC,m_clrShadow );
  63. CSPBrushDC brush ( *pDC,m_pGrid->m_clrHelpBack );
  64. CRect rcHelp ( rc );
  65. rcHelp.top = rc.bottom - m_pGrid->m_nHelpHeight;
  66. pDC->Rectangle( rcHelp );
  67. CSPFontDC font ( pDC,&pView->m_fontBold );
  68. CSPPropertyGridItem * pItem = m_pGrid->GetSelectedItem();
  69. if ( pItem )
  70. {
  71. pDC->SetTextColor( m_pGrid->m_clrHelpFore );
  72. pDC->SetBkColor( m_pGrid->m_clrHelpBack );
  73. CRect rcCaption ( rcHelp );
  74. rcCaption.DeflateRect( 6,3 );
  75. pDC->DrawText( pItem->GetCaption(),rcCaption,DT_SINGLELINE | DT_NOPREFIX );
  76. CString strDesc = pItem->GetDescription();
  77. if ( !strDesc.IsEmpty() )
  78. {
  79. CSPFontDC font ( pDC,&pView->m_fontNormal );
  80. CSPEmptyRect rcCaption;
  81. pDC->DrawText( pItem->GetCaption(),rcCaption,DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT );
  82. CRect rcDesc ( rcHelp );
  83. rcDesc.DeflateRect( 6,3 + rcCaption.Height() + 3,6,3 );
  84. pDC->DrawText( strDesc,rcDesc,DT_WORDBREAK | DT_NOPREFIX );
  85. }
  86. }
  87. rc.bottom -= m_pGrid->m_nHelpHeight + 3;
  88. }
  89. if ( m_pGrid->IsVerbsVisible() )
  90. {
  91. CSPPenDC pen ( *pDC,m_clrShadow );
  92. CSPBrushDC brush ( *pDC,m_pGrid->m_clrHelpBack );
  93. CRect rcVerbs ( rc );
  94. rcVerbs.top = rc.bottom - m_pGrid->m_nVerbsHeight;
  95. HitTestVerbs( pDC,rcVerbs,CPoint( 0 ) );
  96. }
  97. }
  98. int CSPPropertyGridPaintManager::HitTestVerbs( CDC * pDC , CRect rcVerbs , CPoint pt )
  99. {
  100. #define DRAWTESPART(strCaption)\
  101. CRect rcText(CRect(x, y, min(x + nTextWidth, rcVerbs.right), min(y + nTextHeight, rcVerbs.bottom)));\
  102. if (bDraw) {\
  103. pVerb->SetPart(rcText);\
  104. pDC->SetTextColor(m_clrVerbFace);\
  105. pDC->DrawText(strCaption, rcText, DT_SINGLELINE|DT_NOPREFIX); \
  106. if (pVerb->IsFocused()) {\
  107. pDC->SetTextColor(m_pGrid->m_clrHelpBack); pDC->SetBkColor(0); rcText.bottom ++;\
  108. pDC->DrawFocusRect(rcText);\
  109. }\
  110. }\
  111. else if (rcText.PtInRect(pt)) return i;
  112. BOOL bDraw = ( pt == CPoint( 0 ) );
  113. if ( bDraw )
  114. {
  115. pDC->Rectangle( rcVerbs );
  116. }
  117. CSPFontDC font ( pDC,&m_fntVerbUnderline );
  118. rcVerbs.DeflateRect( 6,4 );
  119. int nCount = m_pGrid->GetVerbs()->GetCount();
  120. int x = rcVerbs. left, y = rcVerbs.top, nWidth = rcVerbs.Width();
  121. int nTextHeight = pDC->GetTextExtent( _T( "XXX" ) ).cy;
  122. for ( int i = 0; i < nCount; i++ )
  123. {
  124. CSPPropertyGridVerb * pVerb = m_pGrid->GetVerbs()->GetAt( i );
  125. CString strCaption = pVerb->GetCaption();
  126. while ( TRUE )
  127. {
  128. if ( strCaption.IsEmpty() )
  129. break;
  130. int nTextWidth = pDC->GetTextExtent( strCaption ).cx;
  131. if ( x + nTextWidth < nWidth )
  132. {
  133. DRAWTESPART( strCaption );
  134. x += nTextWidth;
  135. break;
  136. }
  137. else
  138. {
  139. int nStartIndex = ( strCaption.GetLength() - 1 ) * ( nWidth - x ) / nTextWidth;
  140. int nIndex = nStartIndex;
  141. if ( ( nStartIndex < 1 ) && ( x == rcVerbs.left ) )
  142. {
  143. i = nCount - 1;
  144. break;
  145. }
  146. for ( ; nIndex >= 0; nIndex-- )
  147. {
  148. if ( strCaption[nIndex] == _T( ' ' ) || strCaption[nIndex] == _T( ',' ) || strCaption[nIndex] == _T( '-' ) )
  149. break;
  150. }
  151. if ( nIndex > 0 || ( x == rcVerbs.left ) )
  152. {
  153. if ( nIndex <= 0 )
  154. nIndex = nStartIndex;
  155. CString strLeft = strCaption.Left( nIndex + 1 );
  156. CString strRight = strCaption.Mid( nIndex + 1 );
  157. int nTextWidth = pDC->GetTextExtent( strLeft ).cx;
  158. DRAWTESPART( strLeft );
  159. x = rcVerbs.left;
  160. y += nTextHeight;
  161. strCaption = strRight;
  162. }
  163. else
  164. {
  165. y += nTextHeight;
  166. x = rcVerbs.left;
  167. }
  168. }
  169. if ( y >= rcVerbs.bottom )
  170. break;
  171. }
  172. if ( ( y >= rcVerbs.bottom ) || ( i == nCount - 1 ) )
  173. break;
  174. if ( bDraw )
  175. {
  176. font.SetFont( &m_fntVerbNormal );
  177. pDC->SetTextColor( m_pGrid->m_clrHelpFore );
  178. pDC->DrawText( _T( "," ),1,CRect( x,y,x + 8,min( y + nTextHeight,rcVerbs.bottom ) ),DT_SINGLELINE | DT_NOPREFIX );
  179. font.SetFont( &m_fntVerbUnderline );
  180. }
  181. x += 8;
  182. }
  183. return -1;
  184. }
  185. void CSPPropertyGridPaintManager::FillPropertyGridView( CDC * pDC , BOOL bClient )
  186. {
  187. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  188. if ( bClient )
  189. {
  190. CSPClientRect rc ( pView );
  191. pDC->FillSolidRect( rc,pView->m_clrBack );
  192. }
  193. else
  194. {
  195. CSPWindowRect rc ( pView );
  196. rc.OffsetRect( -rc.TopLeft() );
  197. pDC->Draw3dRect( rc,m_clrShadow,m_clrShadow );
  198. }
  199. }
  200. void CSPPropertyGridPaintManager::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
  201. {
  202. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  203. if ( pView->GetStyle() & LBS_OWNERDRAWVARIABLE )
  204. {
  205. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpMeasureItemStruct->itemData;
  206. pItem->MeasureItem( lpMeasureItemStruct );
  207. }
  208. }
  209. void CSPPropertyGridPaintManager::DrawCategoryCaptionBackground( CDC * pDC , CRect rc )
  210. {
  211. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  212. pDC->FillSolidRect( rc,pView->m_clrLine );
  213. }
  214. void CSPPropertyGridPaintManager::DrawItem( PDRAWITEMSTRUCT lpDrawItemStruct )
  215. {
  216. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  217. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpDrawItemStruct->itemData;
  218. CSPWindowRect rcWindow ( pView );
  219. CRect rc = lpDrawItemStruct->rcItem;
  220. CSPBufferDC dc ( lpDrawItemStruct->hDC,rc );
  221. CSPFontDC font ( &dc,&pView->m_fontNormal );
  222. COLORREF clrWindow = pView->m_clrBack;
  223. dc.FillSolidRect( rc,clrWindow );
  224. dc.SetBkMode( TRANSPARENT );
  225. CRect rcCaption ( rc.left,rc.top,rc.left + pView->GetDividerPos(),rc.bottom );
  226. if ( pItem->IsCategory() )
  227. {
  228. DrawCategoryCaptionBackground( &dc,rc );
  229. CSPFontDC font ( &dc,&pView->m_fontBold );
  230. dc.SetTextColor( pView->m_clrCategoryFore );
  231. CSPEmptyRect rcDrawText;
  232. dc.DrawText( pItem->GetCaption(),rcDrawText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_CALCRECT );
  233. CRect rcText ( CPoint( ( ( pItem->GetIndent() + 1 ) * SP_PGI_EXPAND_BORDER ) - 1,rc.top + 1 ),CSize( rcDrawText.Width() + 4,rc.Height() - 3 ) );
  234. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_RIGHT );
  235. if ( ( lpDrawItemStruct->itemAction | ODA_FOCUS ) && ( lpDrawItemStruct->itemState & ODS_FOCUS ) )
  236. {
  237. dc.SetTextColor( 0 );
  238. dc.DrawFocusRect( rcText );
  239. }
  240. }
  241. else
  242. {
  243. dc.SetTextColor( pItem->GetReadOnly() ? pView->m_clrReadOnlyFore : pView->m_clrFore );
  244. CRect rcValue ( rc );
  245. rcValue.left = rcCaption.right + 4;
  246. rcValue.bottom -= 1;
  247. if ( !pItem->OnDrawItemValue( dc,rcValue ) )
  248. {
  249. dc.DrawText( pItem->GetViewValue(),rcValue,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  250. }
  251. BOOL bSelected = ( ( lpDrawItemStruct->itemAction | ODA_SELECT ) && ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
  252. BOOL bFocused = bSelected && CWnd::GetFocus() && ( ( CWnd::GetFocus() == pView ) || ( CWnd::GetFocus()->GetParent() == pView ) || ( CWnd::GetFocus()->GetOwner() == pView ) );
  253. if ( bFocused )
  254. {
  255. dc.SetTextColor( ::GetXtremeColor( COLOR_HIGHLIGHTTEXT ) );
  256. dc.FillSolidRect( rcCaption,::GetXtremeColor( COLOR_HIGHLIGHT ) );
  257. }
  258. else if ( bSelected )
  259. {
  260. dc.FillSolidRect( rcCaption,pView->m_clrLine );
  261. }
  262. CSPPropertyGridItem * pCategory = pItem->GetParentItem();
  263. while ( pCategory != NULL )
  264. {
  265. if ( pCategory->IsCategory() )
  266. dc.FillSolidRect( rc.left + pCategory->GetIndent() * SP_PGI_EXPAND_BORDER,rc.top,SP_PGI_EXPAND_BORDER,rc.Height(),pView->m_clrLine );
  267. pCategory = pCategory->GetParentItem();
  268. }
  269. CSPPenDC pen ( dc,pView->m_clrLine );
  270. dc.MoveTo( 0,rc.bottom - 1 ); dc.LineTo( rc.right,rc.bottom - 1 );
  271. dc.MoveTo( rcCaption.right,rc.top ); dc.LineTo( rcCaption.right,rc.bottom - 1 );
  272. CRect rcText ( rc );
  273. rcText.left = pItem->GetIndent() * SP_PGI_EXPAND_BORDER + 3;
  274. rcText.right = rcCaption.right - 1;
  275. rcText.bottom -= 1;
  276. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  277. }
  278. CSPPropertyGridItem * pNext = pView->GetItem( lpDrawItemStruct->itemID + 1 );
  279. if ( pNext && pNext->IsCategory() && pNext->IsVisible() )
  280. {
  281. dc.FillSolidRect( pNext->GetIndent() * SP_PGI_EXPAND_BORDER,rc.bottom - 1,rc.Width(),1,m_clrFace );
  282. }
  283. if ( pItem->HasChilds() )
  284. {
  285. CRgn rgn;
  286. if ( !pItem->IsCategory() )
  287. {
  288. rgn.CreateRectRgnIndirect( &rcCaption );
  289. dc.SelectClipRgn( &rgn );
  290. }
  291. DrawExpandButton( dc,pItem,rcCaption );
  292. dc.SelectClipRgn( NULL );
  293. }
  294. }
  295. void CSPPropertyGridPaintManager::DrawExpandButton( CDC & dc , CSPPropertyGridItem * pItem , CRect rcCaption )
  296. {
  297. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  298. CRect rcSign ( CPoint( SP_PGI_EXPAND_BORDER / 2 - 5,rcCaption.CenterPoint().y - 4 ),CSize( 9,9 ) );
  299. if ( pItem->GetIndent() > 0 )
  300. {
  301. rcSign.OffsetRect( ( pItem->GetIndent() - ( pItem->IsCategory() ? 0 : 1 ) ) * SP_PGI_EXPAND_BORDER,0 );
  302. }
  303. CPoint pt = rcSign.CenterPoint();
  304. if ( !pItem->IsCategory() )
  305. dc.FillSolidRect( rcSign,pView->m_clrBack );
  306. dc.Draw3dRect( rcSign,pView->m_clrFore,pView->m_clrFore );
  307. CSPPenDC pen ( dc,pView->m_clrFore );
  308. dc.MoveTo( pt.x - 2,pt.y );
  309. dc.LineTo( pt.x + 3,pt.y );
  310. if ( !pItem->IsExpanded() )
  311. {
  312. dc.MoveTo( pt.x,pt.y - 2 );
  313. dc.LineTo( pt.x,pt.y + 3 );
  314. }
  315. }
  316. void CSPPropertyGridPaintManager::FillInplaceButton( CDC * pDC , CSPPropertyGridInplaceButton * pButton )
  317. {
  318. CSPClientRect rect ( pButton );
  319. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  320. CPoint ptDots ( rect.CenterPoint().x,rect.CenterPoint().y + 3 );
  321. pDC->FillSolidRect( rect,GetXtremeColor( COLOR_3DFACE ) );
  322. if ( pButton->m_bPressed && pButton->m_bOver )
  323. pDC->Draw3dRect( rect,GetXtremeColor( COLOR_3DSHADOW ),GetXtremeColor( COLOR_3DSHADOW ) );
  324. else
  325. {
  326. pDC->Draw3dRect( rect,GetXtremeColor( COLOR_3DFACE ),GetXtremeColor( COLOR_3DDKSHADOW ) );
  327. rect.DeflateRect( 1,1 );
  328. pDC->Draw3dRect( rect,GetXtremeColor( COLOR_WINDOW ),GetXtremeColor( COLOR_3DSHADOW ) );
  329. }
  330. if ( pButton->GetItem()->GetFlags() & SPGridItemHasComboButton )
  331. {
  332. CPoint pt = rect.CenterPoint();
  333. CSPDrawHelpers::Triangle( pDC,CPoint( pt.x - 3,pt.y - 1 ),CPoint( pt.x + 3,pt.y - 1 ),CPoint( pt.x,pt.y + 2 ),GetXtremeColor( COLOR_BTNTEXT ) );
  334. }
  335. if ( pButton->GetItem()->GetFlags() & SPGridItemHasExpandButton )
  336. {
  337. pDC->FillSolidRect( ptDots.x - 4,ptDots.y,2,2,GetXtremeColor( COLOR_BTNTEXT ) );
  338. pDC->FillSolidRect( ptDots.x,ptDots.y,2,2,GetXtremeColor( COLOR_BTNTEXT ) );
  339. pDC->FillSolidRect( ptDots.x + 4,ptDots.y,2,2,GetXtremeColor( COLOR_BTNTEXT ) );
  340. }
  341. if ( CWnd::GetFocus() == pButton )
  342. {
  343. pDC->SetTextColor( GetXtremeColor( COLOR_BTNTEXT ) );
  344. pDC->SetBkColor( GetXtremeColor( COLOR_3DFACE ) );
  345. rect.DeflateRect( 2,2 );
  346. pDC->DrawFocusRect( rect );
  347. }
  348. }
  349. CSPPropertyGridNativeXPTheme::CSPPropertyGridNativeXPTheme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  350. {
  351. m_bThemed = TRUE;
  352. RefreshMetrics();
  353. }
  354. void CSPPropertyGridNativeXPTheme::RefreshMetrics()
  355. {
  356. CSPPropertyGridPaintManager::RefreshMetrics();
  357. SPCurrentSystemTheme systemTheme = SPDrawHelpers()->GetCurrentSystemTheme();
  358. switch ( systemTheme )
  359. {
  360. case SPSystemThemeSilver:
  361. case SPSystemThemeBlue:
  362. m_clrShadow = RGB( 127,157,185 ); break;
  363. case SPSystemThemeOlive:
  364. m_clrShadow = RGB( 164,185,127 ); break;
  365. }
  366. }
  367. //////////////////////////////////////////////////////////////////////
  368. //
  369. CSPPropertyGridOffice2003Theme::CSPPropertyGridOffice2003Theme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  370. {
  371. RefreshMetrics();
  372. }
  373. void CSPPropertyGridOffice2003Theme::RefreshMetrics()
  374. {
  375. CSPPropertyGridPaintManager::RefreshMetrics();
  376. m_bThemed = TRUE;
  377. m_bLunaTheme = FALSE;
  378. if ( !SPColorManager()->IsLunaColorsDisabled() )
  379. {
  380. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  381. SPCurrentSystemTheme systemTheme = SPDrawHelpers()->GetCurrentSystemTheme();
  382. switch ( systemTheme )
  383. {
  384. case SPSystemThemeBlue:
  385. m_clrFace = RGB( 221,236,254 );
  386. m_clrShadow = RGB( 123,164,224 );
  387. m_pGrid->m_clrHelpBack.SetStandardValue( m_clrFace );
  388. pView->m_clrLine.SetStandardValue( RGB( 169,199,240 ) );
  389. pView->m_clrCategoryFore.SetStandardValue( 0 );
  390. m_bLunaTheme = TRUE;
  391. break;
  392. case SPSystemThemeOlive:
  393. m_clrFace = RGB( 243,242,231 );
  394. m_clrShadow = RGB( 188,187,177 );
  395. m_pGrid->m_clrHelpBack.SetStandardValue( m_clrFace );
  396. pView->m_clrLine.SetStandardValue( RGB( 197,212,159 ) );
  397. pView->m_clrCategoryFore.SetStandardValue( 0 );
  398. m_bLunaTheme = TRUE;
  399. break;
  400. case SPSystemThemeSilver:
  401. m_clrFace = RGB( 238,238,244 );
  402. m_clrShadow = RGB( 161,160,187 );
  403. m_pGrid->m_clrHelpBack.SetStandardValue( m_clrFace );
  404. pView->m_clrLine.SetStandardValue( RGB( 192,192,211 ) );
  405. pView->m_clrCategoryFore.SetStandardValue( 0 );
  406. m_bLunaTheme = TRUE;
  407. break;
  408. }
  409. }
  410. }
  411. //////////////////////////////////////////////////////////////////////
  412. // CSPPropertyGridCoolTheme
  413. CSPPropertyGridCoolTheme::CSPPropertyGridCoolTheme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  414. {
  415. RefreshMetrics();
  416. }
  417. void CSPPropertyGridCoolTheme::RefreshMetrics()
  418. {
  419. CSPPropertyGridPaintManager::RefreshMetrics();
  420. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  421. pView->m_clrLine.SetStandardValue( GetXtremeColor( COLOR_3DFACE ) );
  422. }
  423. void CSPPropertyGridCoolTheme::DrawItem( PDRAWITEMSTRUCT lpDrawItemStruct )
  424. {
  425. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  426. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpDrawItemStruct->itemData;
  427. COLORREF clrWindow = pView->m_clrBack;
  428. ASSERT( pItem != NULL );
  429. CSPWindowRect rcWindow ( pView );
  430. CRect rc = lpDrawItemStruct->rcItem;
  431. CSPBufferDC dc ( lpDrawItemStruct->hDC,rc );
  432. CSPFontDC font ( &dc,&pView->m_fontNormal );
  433. dc.FillSolidRect( rc,clrWindow );
  434. dc.SetBkMode( TRANSPARENT );
  435. CRect rcCaption ( rc.left,rc.top,rc.left + pView->GetDividerPos(),rc.bottom );
  436. COLORREF clrLine = pView->m_clrLine;
  437. COLORREF clrFore = pView->m_clrFore;
  438. COLORREF clrShadow = GetXtremeColor( COLOR_3DSHADOW );
  439. if ( pItem->IsCategory() )
  440. {
  441. dc.FillSolidRect( rc,clrLine );
  442. CSPFontDC font ( &dc,&pView->m_fontBold );
  443. dc.SetTextColor( pView->m_clrCategoryFore );
  444. int nIndent = SP_PGI_EXPAND_BORDER * ( pItem->GetIndent() + 1 );
  445. if ( ( lpDrawItemStruct->itemAction | ODA_FOCUS ) && ( lpDrawItemStruct->itemState & ODS_FOCUS ) )
  446. {
  447. dc.SetTextColor( ::GetXtremeColor( COLOR_HIGHLIGHTTEXT ) );
  448. dc.FillSolidRect( CRect( nIndent,rc.top,rc.right,rc.bottom ),::GetXtremeColor( COLOR_HIGHLIGHT ) );
  449. }
  450. CRect rcText ( nIndent + 3,rc.top,rc.right,rc.bottom - 1 );
  451. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  452. dc.FillSolidRect( ( pItem->GetIndent() + ( pItem->IsExpanded() ? 1 : 0 ) ) * SP_PGI_EXPAND_BORDER - 1,rc.bottom - 1,rc.Width(),1,clrShadow );
  453. CSPPropertyGridItem * pCategory = pItem->GetParentItem();
  454. while ( pCategory != NULL )
  455. {
  456. if ( pCategory->IsCategory() )
  457. {
  458. dc.FillSolidRect( rc.left + pCategory->GetIndent() * SP_PGI_EXPAND_BORDER,rc.top,SP_PGI_EXPAND_BORDER,rc.Height(),clrLine );
  459. dc.FillSolidRect( rc.left + ( pCategory->GetIndent() + 1 ) * SP_PGI_EXPAND_BORDER - 1,rc.top,1,rc.Height() + 2,clrShadow );
  460. }
  461. pCategory = pCategory->GetParentItem();
  462. }
  463. }
  464. else
  465. {
  466. dc.SetTextColor( pItem->GetReadOnly() ? pView->m_clrReadOnlyFore : clrFore );
  467. CRect rcValue ( rc );
  468. rcValue.left = rcCaption.right + 4;
  469. rcValue.bottom -= 1;
  470. if ( !pItem->OnDrawItemValue( dc,rcValue ) )
  471. {
  472. dc.DrawText( pItem->GetViewValue(),rcValue,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX );
  473. }
  474. BOOL bSelected = ( ( lpDrawItemStruct->itemAction | ODA_SELECT ) && ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
  475. BOOL bFocused = bSelected && CWnd::GetFocus() && ( ( CWnd::GetFocus() == pView ) || ( CWnd::GetFocus()->GetParent() == pView ) || ( CWnd::GetFocus()->GetOwner() == pView ) );
  476. if ( bFocused )
  477. {
  478. dc.SetTextColor( ::GetXtremeColor( COLOR_HIGHLIGHTTEXT ) );
  479. dc.FillSolidRect( rcCaption,::GetXtremeColor( COLOR_HIGHLIGHT ) );
  480. }
  481. else if ( bSelected )
  482. {
  483. dc.FillSolidRect( rcCaption,clrLine );
  484. }
  485. CSPPenDC pen ( dc,clrLine );
  486. dc.MoveTo( 0,rc.bottom - 1 ); dc.LineTo( rc.right,rc.bottom - 1 );
  487. dc.MoveTo( rcCaption.right,rc.top ); dc.LineTo( rcCaption.right,rc.bottom - 1 );
  488. CSPPropertyGridItem * pCategory = pItem->GetParentItem();
  489. while ( pCategory != NULL )
  490. {
  491. if ( pCategory->IsCategory() )
  492. {
  493. dc.FillSolidRect( rc.left + pCategory->GetIndent() * SP_PGI_EXPAND_BORDER,rc.top,SP_PGI_EXPAND_BORDER,rc.Height(),clrLine );
  494. dc.FillSolidRect( rc.left + ( pCategory->GetIndent() + 1 ) * SP_PGI_EXPAND_BORDER - 1,rc.top,1,rc.Height() + 2,clrShadow );
  495. }
  496. pCategory = pCategory->GetParentItem();
  497. }
  498. CRect rcText ( rc );
  499. rcText.left = pItem->GetIndent() * SP_PGI_EXPAND_BORDER + 3;
  500. rcText.right = rcCaption.right - 1;
  501. rcText.bottom -= 1;
  502. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  503. }
  504. CSPPropertyGridItem * pNext = ( CSPPropertyGridItem * ) pView->GetItemDataPtr( lpDrawItemStruct->itemID + 1 );
  505. if ( ( ( ULONG_PTR ) pNext == ( ULONG_PTR ) ( -1 ) ) )
  506. {
  507. dc.FillSolidRect( 0,rc.bottom - 1,rc.Width(),1,clrShadow );
  508. }
  509. else if ( pNext && pNext->IsCategory() && pNext->IsVisible() )
  510. {
  511. dc.FillSolidRect( pNext->GetIndent() * SP_PGI_EXPAND_BORDER,rc.bottom - 1,rc.Width(),1,clrShadow );
  512. }
  513. CSPPropertyGridItem * pPrev = pItem;
  514. CSPPropertyGridItem * pCategory = pPrev->GetParentItem();
  515. while ( pCategory != NULL )
  516. {
  517. if ( pItem->HasChilds() && pItem->IsExpanded() )
  518. break;
  519. if ( pCategory->IsCategory() && pCategory->IsVisible() && pCategory->GetChilds()->GetAt( pCategory->GetChilds()->GetCount() - 1 ) == pPrev )
  520. {
  521. dc.FillSolidRect( pCategory->GetIndent() * SP_PGI_EXPAND_BORDER,rc.bottom - 1,rc.Width(),1,clrShadow );
  522. }
  523. else
  524. break;
  525. pPrev = pCategory;
  526. pCategory = pPrev->GetParentItem();
  527. }
  528. if ( pItem->HasChilds() )
  529. {
  530. CRgn rgn;
  531. if ( !pItem->IsCategory() )
  532. {
  533. rgn.CreateRectRgnIndirect( &rcCaption );
  534. dc.SelectClipRgn( &rgn );
  535. }
  536. DrawExpandButton( dc,pItem,rcCaption );
  537. dc.SelectClipRgn( NULL );
  538. }
  539. }
  540. //////////////////////////////////////////////////////////////////////
  541. // CSPPropertyGridSimpleTheme
  542. CSPPropertyGridSimpleTheme::CSPPropertyGridSimpleTheme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  543. {
  544. RefreshMetrics();
  545. }
  546. void CSPPropertyGridSimpleTheme::RefreshMetrics()
  547. {
  548. CSPPropertyGridPaintManager::RefreshMetrics();
  549. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  550. pView->m_clrLine.SetStandardValue( GetXtremeColor( COLOR_3DFACE ) );
  551. }
  552. void CSPPropertyGridSimpleTheme::DrawItem( PDRAWITEMSTRUCT lpDrawItemStruct )
  553. {
  554. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  555. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpDrawItemStruct->itemData;
  556. COLORREF clrWindow = pView->m_clrBack;
  557. ASSERT( pItem != NULL );
  558. CSPWindowRect rcWindow ( pView );
  559. CRect rc = lpDrawItemStruct->rcItem;
  560. CSPBufferDC dc ( lpDrawItemStruct->hDC,rc );
  561. CSPFontDC font ( &dc,pItem->IsCategory() ? &pView->m_fontBold : &pView->m_fontNormal );
  562. dc.FillSolidRect( rc,clrWindow );
  563. dc.SetBkMode( TRANSPARENT );
  564. CRect rcCaption ( rc.left,rc.top,rc.left + pView->GetDividerPos(),rc.bottom );
  565. COLORREF clrLine = pView->m_clrLine;
  566. COLORREF clrFore = pView->m_clrFore;
  567. {
  568. if ( !pItem->IsCategory() )
  569. {
  570. dc.SetTextColor( pItem->GetReadOnly() ? pView->m_clrReadOnlyFore : clrFore );
  571. CRect rcValue ( rc );
  572. rcValue.left = rcCaption.right + 4;
  573. rcValue.bottom -= 1;
  574. if ( !pItem->OnDrawItemValue( dc,rcValue ) )
  575. {
  576. dc.DrawText( pItem->GetViewValue(),rcValue,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX );
  577. }
  578. }
  579. dc.SetTextColor( clrFore );
  580. BOOL bSelected = ( ( lpDrawItemStruct->itemAction | ODA_SELECT ) && ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
  581. BOOL bFocused = bSelected && CWnd::GetFocus() && ( ( CWnd::GetFocus() == pView ) || ( CWnd::GetFocus()->GetParent() == pView ) || ( CWnd::GetFocus()->GetOwner() == pView ) );
  582. if ( bFocused )
  583. {
  584. dc.SetTextColor( ::GetXtremeColor( COLOR_HIGHLIGHTTEXT ) );
  585. dc.FillSolidRect( CRect( SP_PGI_EXPAND_BORDER,rcCaption.top,rcCaption.right,rcCaption.bottom ),::GetXtremeColor( COLOR_HIGHLIGHT ) );
  586. }
  587. else if ( bSelected )
  588. {
  589. dc.FillSolidRect( CRect( SP_PGI_EXPAND_BORDER,rcCaption.top,rcCaption.right,rcCaption.bottom ),clrLine );
  590. }
  591. dc.FillSolidRect( SP_PGI_EXPAND_BORDER - 1,rc.top,1,rc.Height(),clrLine );
  592. CSPPenDC pen ( dc,clrLine );
  593. dc.MoveTo( SP_PGI_EXPAND_BORDER,rc.bottom - 1 ); dc.LineTo( rc.right,rc.bottom - 1 );
  594. dc.MoveTo( rcCaption.right,rc.top ); dc.LineTo( rcCaption.right,rc.bottom - 1 );
  595. CRect rcText ( rc );
  596. rcText.left = ( pItem->GetIndent() + ( pItem->IsCategory() ? 1 : 0 ) ) * SP_PGI_EXPAND_BORDER + 3;
  597. rcText.right = rcCaption.right - 1;
  598. rcText.bottom -= 1;
  599. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  600. }
  601. if ( pView->GetCount() == ( int ) lpDrawItemStruct->itemID + 1 )
  602. {
  603. dc.FillSolidRect( 0,rc.bottom - 1,rc.Width(),1,clrLine );
  604. }
  605. if ( pItem->HasChilds() )
  606. {
  607. CRgn rgn;
  608. rgn.CreateRectRgnIndirect( &rcCaption );
  609. dc.SelectClipRgn( &rgn );
  610. DrawExpandButton( dc,pItem,rcCaption );
  611. dc.SelectClipRgn( NULL );
  612. }
  613. }
  614. //////////////////////////////////////////////////////////////////////
  615. // CSPPropertyGridDelphiTheme
  616. CSPPropertyGridDelphiTheme::CSPPropertyGridDelphiTheme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  617. {
  618. RefreshMetrics();
  619. }
  620. void CSPPropertyGridDelphiTheme::DrawItem( PDRAWITEMSTRUCT lpDrawItemStruct )
  621. {
  622. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  623. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpDrawItemStruct->itemData;
  624. COLORREF clrWindow = pView->m_clrBack;
  625. ASSERT( pItem != NULL );
  626. CSPWindowRect rcWindow ( pView );
  627. CRect rc = lpDrawItemStruct->rcItem;
  628. CSPBufferDC dc ( lpDrawItemStruct->hDC,rc );
  629. CSPFontDC font ( &dc,pItem->IsCategory() ? &pView->m_fontBold : &pView->m_fontNormal );
  630. dc.FillSolidRect( rc,clrWindow );
  631. dc.SetBkMode( TRANSPARENT );
  632. CRect rcCaption ( rc.left,rc.top,rc.left + pView->GetDividerPos(),rc.bottom );
  633. COLORREF clrFore = pView->m_clrFore;
  634. COLORREF clrShadow = GetXtremeColor( COLOR_3DSHADOW );
  635. COLORREF clrLight = GetXtremeColor( COLOR_BTNHIGHLIGHT );
  636. {
  637. if ( !pItem->IsCategory() )
  638. {
  639. dc.SetTextColor( pItem->GetReadOnly() ? pView->m_clrReadOnlyFore : clrFore );
  640. CRect rcValue ( rc );
  641. rcValue.left = rcCaption.right + 4;
  642. rcValue.bottom -= 1;
  643. if ( !pItem->OnDrawItemValue( dc,rcValue ) )
  644. {
  645. dc.DrawText( pItem->GetViewValue(),rcValue,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX );
  646. }
  647. }
  648. dc.SetTextColor( clrFore );
  649. dc.Draw3dRect( rcCaption.right - 1,rc.top,1,rc.Height(),clrShadow,clrShadow );
  650. dc.Draw3dRect( rcCaption.right,rc.top,1,rc.Height(),clrLight,clrLight );
  651. BOOL bSelected = ( ( lpDrawItemStruct->itemAction | ODA_SELECT ) && ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
  652. BOOL bFocused = bSelected && CWnd::GetFocus() && ( ( CWnd::GetFocus() == pView ) || ( CWnd::GetFocus()->GetParent() == pView ) || ( CWnd::GetFocus()->GetOwner() == pView ) );
  653. if ( bFocused || bSelected )
  654. {
  655. dc.Draw3dRect( rc,clrFore,clrLight );
  656. }
  657. else
  658. {
  659. for ( int i = 0; i < rc.right; i += 2 )
  660. {
  661. dc.SetPixel( i,rc.bottom - 1,clrShadow );
  662. }
  663. }
  664. CRect rcText ( rc );
  665. rcText.left = ( pItem->GetIndent() + ( pItem->IsCategory() ? 1 : 0 ) ) * SP_PGI_EXPAND_BORDER + 3;
  666. rcText.right = rcCaption.right - 1;
  667. rcText.bottom -= 1;
  668. dc.DrawText( pItem->GetCaption(),rcText,DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER );
  669. }
  670. if ( pItem->HasChilds() )
  671. {
  672. CRgn rgn;
  673. rgn.CreateRectRgnIndirect( &rcCaption );
  674. dc.SelectClipRgn( &rgn );
  675. DrawExpandButton( dc,pItem,rcCaption );
  676. dc.SelectClipRgn( NULL );
  677. }
  678. }
  679. void CSPPropertyGridDelphiTheme::RefreshMetrics()
  680. {
  681. CSPPropertyGridPaintManager::RefreshMetrics();
  682. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  683. pView->m_clrBack.SetStandardValue( GetXtremeColor( COLOR_3DFACE ) );
  684. pView->m_clrFore.SetStandardValue( RGB( 0,0,128 ) );
  685. }
  686. //////////////////////////////////////////////////////////////////////////
  687. // CSPPropertyGridWhidbeyTheme
  688. CSPPropertyGridWhidbeyTheme::CSPPropertyGridWhidbeyTheme( CSPPropertyGrid * pGrid ) : CSPPropertyGridPaintManager( pGrid )
  689. {
  690. m_bThemed = TRUE;
  691. RefreshMetrics();
  692. }
  693. void CSPPropertyGridWhidbeyTheme::DrawCategoryCaptionBackground( CDC * pDC , CRect rc )
  694. {
  695. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  696. pDC->FillSolidRect( rc,pView->m_clrLine );
  697. SPDrawHelpers()->GradientFill( pDC,CRect( rc.left,rc.bottom - 2,rc.right,rc.bottom - 1 ),pView->m_clrLine,GetXtremeColor( COLOR_3DHIGHLIGHT ),TRUE );
  698. }
  699. void CSPPropertyGridWhidbeyTheme::RefreshMetrics()
  700. {
  701. CSPPropertyGridPaintManager::RefreshMetrics();
  702. CSPPropertyGridView * pView = &m_pGrid->GetGridView();
  703. pView->m_clrLine.SetStandardValue( GetXtremeColor( COLOR_3DFACE ) );
  704. pView->m_clrCategoryFore.SetStandardValue( GetXtremeColor( COLOR_BTNTEXT ) );
  705. m_clrShadow = GetXtremeColor( XPCOLOR_STATICFRAME );
  706. }
  707. void CSPPropertyGridWhidbeyTheme::DrawExpandButton( CDC & dc , CSPPropertyGridItem * pItem , CRect rcCaption )
  708. {
  709. CRect rcButton ( CPoint( SP_PGI_EXPAND_BORDER / 2 - 5,rcCaption.CenterPoint().y - 4 ),CSize( 9,9 ) );
  710. if ( pItem->GetIndent() > 0 )
  711. {
  712. rcButton.OffsetRect( ( pItem->GetIndent() - ( pItem->IsCategory() ? 0 : 1 ) ) * SP_PGI_EXPAND_BORDER,0 );
  713. }
  714. CDC * pDC = &dc;
  715. COLORREF clrButton = GetXtremeColor( COLOR_3DFACE );
  716. COLORREF clrFrame = GetXtremeColor( COLOR_3DSHADOW );
  717. pDC->FillSolidRect( rcButton.left + 1,rcButton.top + 1,7,7,clrButton );
  718. pDC->FillSolidRect( rcButton.left + 1,rcButton.top,9 - 2,1,clrFrame );
  719. pDC->FillSolidRect( rcButton.left + 1,rcButton.bottom - 1,9 - 2,1,clrFrame );
  720. pDC->FillSolidRect( rcButton.left,rcButton.top + 1,1,9 - 2,clrFrame );
  721. pDC->FillSolidRect( rcButton.right - 1,rcButton.top + 1,1,9 - 2,clrFrame );
  722. pDC->FillSolidRect( rcButton.left + 1,rcButton.top + 1,9 - 2,3,0xFFFFFF );
  723. pDC->FillSolidRect( rcButton.left + 1,rcButton.top + 4,9 - 4,2,0xFFFFFF );
  724. pDC->FillSolidRect( rcButton.left + 2,rcButton.top + 4,9 - 4,1,0 );
  725. if ( !pItem->IsExpanded() )
  726. {
  727. pDC->FillSolidRect( rcButton.left + 4,rcButton.top + 2,1,9 - 4,0 );
  728. }
  729. }