SPPPropertyGrid.cpp 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #include "stdafx.h"
  7. #include "SPVC80Helpers.h"
  8. #include "SPDrawHelpers.h"
  9. #include "resource.h"
  10. #include "SPPropertyGridInplaceEdit.h"
  11. #include "SPPropertyGridInplaceButton.h"
  12. #include "SPPropertyGridInplaceList.h"
  13. #include "SPPropertyGridItem.h"
  14. #include "SPPropertyGrid.h"
  15. #include "SPPropertyGridDefines.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. const int SPLITTER_HEIGHT = 3;
  22. const int TOOLBAR_HEIGHT = 25;
  23. //////////////////////////////////////////////////////////////////////////
  24. // CSPPropertyGridUpdateContext
  25. CSPPropertyGridUpdateContext::CSPPropertyGridUpdateContext()
  26. {
  27. }
  28. //////////////////////////////////////////////////////////////////////////
  29. // CSPPropertyGridVerb
  30. CSPPropertyGridVerb::CSPPropertyGridVerb()
  31. {
  32. }
  33. //////////////////////////////////////////////////////////////////////////
  34. // CSPPropertyGridVerbs
  35. CSPPropertyGridVerbs::CSPPropertyGridVerbs()
  36. {
  37. }
  38. CSPPropertyGridVerbs::~CSPPropertyGridVerbs()
  39. {
  40. for ( int i = 0; i < m_arrVerbs.GetSize(); i++ )
  41. {
  42. m_arrVerbs[i]->InternalRelease();
  43. }
  44. }
  45. void CSPPropertyGridVerbs::RemoveAll()
  46. {
  47. if ( IsEmpty() )
  48. {
  49. return;
  50. }
  51. for ( int i = 0; i < m_arrVerbs.GetSize(); i++ )
  52. {
  53. m_arrVerbs[i]->InternalRelease();
  54. }
  55. m_arrVerbs.RemoveAll();
  56. m_pGrid->OnVerbsChanged();
  57. }
  58. int CSPPropertyGridVerbs::GetCount()
  59. {
  60. return ( int ) m_arrVerbs.GetSize();
  61. }
  62. void CSPPropertyGridVerbs::Add( LPCTSTR strCaption , UINT nID )
  63. {
  64. CSPPropertyGridVerb * pVerb = new CSPPropertyGridVerb();
  65. pVerb->m_nID = nID;
  66. pVerb->m_strCaption = strCaption;
  67. pVerb->m_pVerbs = this;
  68. pVerb->m_rcPart.SetRectEmpty();
  69. pVerb->m_ptClick = CPoint( 0 );
  70. pVerb->m_nIndex = ( UINT ) m_arrVerbs.Add( pVerb );
  71. m_pGrid->OnVerbsChanged();
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CSPPropertyGridToolBar
  75. CSPPropertyGridToolBar::CSPPropertyGridToolBar()
  76. {
  77. m_cxLeftBorder = m_cxRightBorder = m_cyBottomBorder = m_cyTopBorder = 0;
  78. }
  79. BEGIN_MESSAGE_MAP(CSPPropertyGridToolBar, CToolBar)
  80. //{{AFX_MSG_MAP(CToolBar)
  81. ON_WM_PAINT()
  82. ON_WM_ERASEBKGND()
  83. ON_WM_NCCALCSIZE()
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. BOOL CSPPropertyGridToolBar::OnEraseBkgnd( CDC * )
  87. {
  88. return TRUE;
  89. }
  90. void CSPPropertyGridToolBar::OnNcCalcSize( BOOL /*bCalcValidRects*/ , NCCALCSIZE_PARAMS* /*lpncsp*/ )
  91. {
  92. }
  93. void CSPPropertyGridToolBar::OnPaint()
  94. {
  95. CPaintDC dc ( this );
  96. CSPClientRect rc ( this );
  97. CSPBufferDC memDC ( dc,rc );
  98. memDC.FillSolidRect( rc,GetXtremeColor( COLOR_3DFACE ) );
  99. CToolBar::DefWindowProc( WM_PAINT,( WPARAM ) memDC.m_hDC,0 );
  100. }
  101. void CSPPropertyGridToolBar::OnUpdateCmdUI( CFrameWnd* /*pTarget*/ , BOOL /*bDisableIfNoHndler*/ )
  102. {
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CSPPropertyGrid
  106. CSPPropertyGrid::CSPPropertyGrid() : m_bHelpVisible( TRUE ) , m_bToolBarVisible( FALSE ) , m_nHelpHeight( 58 )
  107. {
  108. m_pView = 0;
  109. m_hCursorSplit = AfxGetApp()->LoadCursor( SP_IDC_VSPLITBAR );
  110. m_hCursorHand = ::LoadCursor( 0,MAKEINTRESOURCE( 32649 ) );
  111. if ( m_hCursorHand == 0 )
  112. {
  113. m_hCursorHand = AfxGetApp()->LoadCursor( MAKEINTRESOURCE( SP_IDC_HAND ) );
  114. }
  115. m_pPaintManager = new CSPPropertyGridPaintManager( this );
  116. m_themeCurrent = SPGridThemeDefault;
  117. m_pVerbs = new CSPPropertyGridVerbs;
  118. m_pVerbs->m_pGrid = this;
  119. m_nVerbsHeight = 25;
  120. m_nFocusedVerb = -1;
  121. m_bVerbActivate = FALSE;
  122. m_bVerbsVisible = FALSE;
  123. m_bTabItems = FALSE;
  124. }
  125. CSPPropertyGrid::~CSPPropertyGrid()
  126. {
  127. delete m_pPaintManager;
  128. if ( m_pView )
  129. {
  130. delete m_pView;
  131. }
  132. m_pVerbs->InternalRelease();
  133. }
  134. CSPPropertyGridView * CSPPropertyGrid::CreateView()
  135. {
  136. return new CSPPropertyGridView();
  137. }
  138. CSPPropertyGridView & CSPPropertyGrid::GetGridView()
  139. {
  140. if ( m_pView == 0 )
  141. {
  142. m_pView = CreateView();
  143. m_pView->m_pGrid = this;
  144. }
  145. return *m_pView;
  146. }
  147. IMPLEMENT_DYNAMIC( CSPPropertyGrid , CWnd )
  148. BEGIN_MESSAGE_MAP(CSPPropertyGrid, CWnd)
  149. //{{AFX_MSG_MAP(CSPPropertyGrid)
  150. ON_WM_ERASEBKGND()
  151. ON_WM_PAINT()
  152. ON_WM_SETFOCUS()
  153. ON_WM_KILLFOCUS()
  154. ON_WM_SIZE()
  155. ON_WM_SETCURSOR()
  156. ON_WM_LBUTTONDOWN()
  157. ON_WM_LBUTTONUP()
  158. ON_WM_KEYDOWN()
  159. ON_COMMAND(SP_IDC_SORT_ALPHABETIC, OnSortAlphabetic)
  160. ON_COMMAND(SP_IDC_SORT_CATEGORIZED, OnSortCategorized)
  161. ON_WM_SYSCOLORCHANGE()
  162. ON_WM_GETDLGCODE()
  163. //}}AFX_MSG_MAP
  164. END_MESSAGE_MAP()
  165. UINT CSPPropertyGrid::OnGetDlgCode()
  166. {
  167. return DLGC_WANTALLKEYS;
  168. }
  169. BOOL CSPPropertyGrid::Create( const RECT & rect , CWnd * pParentWnd , UINT nID , DWORD dwListStyle /*= LBS_OWNERDRAWFIXED| LBS_NOINTEGRALHEIGHT*/ )
  170. {
  171. LPCTSTR pszCreateClass = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW,::LoadCursor( NULL,IDC_ARROW ) );
  172. CSPEmptyRect rc;
  173. if ( !CreateEx( 0,pszCreateClass,_T( "" ),WS_TABSTOP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD | WS_GROUP,rc,pParentWnd,nID ) )
  174. {
  175. return FALSE;
  176. }
  177. if ( !GetGridView().CreateEx( WS_EX_STATICEDGE,_T( "LISTBOX" ),NULL,WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD | WS_VISIBLE | LBS_NOTIFY | WS_VSCROLL | WS_TABSTOP | dwListStyle,rc,this,0 ) )
  178. {
  179. return FALSE;
  180. }
  181. GetGridView().ResetContent();
  182. SetWindowPos( 0,rect.left,rect.top,rect.right - rect.left,rect.bottom - rect.top,SWP_SHOWWINDOW | SWP_NOZORDER );
  183. SetStandardColors();
  184. return TRUE;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CSPPropertyGrid message handlers
  188. BOOL CSPPropertyGrid::OnEraseBkgnd( CDC * )
  189. {
  190. return TRUE;
  191. }
  192. void CSPPropertyGrid::OnPaint()
  193. {
  194. CPaintDC dcPaint ( this );
  195. CSPClientRect rc ( this );
  196. CSPBufferDC dc ( dcPaint,rc );
  197. m_pPaintManager->FillPropertyGrid( &dc );
  198. }
  199. CWnd * CSPPropertyGrid::GetNextGridTabItem( BOOL bForward )
  200. {
  201. CWnd * pParent = this;
  202. if ( !pParent || !pParent->GetParent() )
  203. {
  204. ASSERT( FALSE );
  205. return 0 ;
  206. }
  207. CWnd * pNextItem = pParent->GetParent()->GetNextDlgTabItem( pParent,bForward );
  208. if ( pNextItem == pParent )
  209. {
  210. return 0;
  211. }
  212. return pNextItem;
  213. }
  214. void CSPPropertyGrid::OnNavigate( SPPropertyGridUI nUIElement , BOOL bForward , CSPPropertyGridItem * pItem )
  215. {
  216. int nNextElement = bForward ? +1 : -1;
  217. int nUI = nUIElement + nNextElement;
  218. if ( pItem == NULL )
  219. {
  220. pItem = GetGridView().GetSelectedItem();
  221. }
  222. while ( nUI != nUIElement )
  223. {
  224. if ( nUI == SPGridUIViewPrev )
  225. {
  226. nUI += nNextElement;
  227. if ( m_bTabItems )
  228. {
  229. int nIndex = !bForward && pItem ? pItem->m_nIndex - 1 : 0;
  230. if ( nIndex >= 0 )
  231. {
  232. GetGridView().SetFocus();
  233. GetGridView().SetCurSel( nIndex );
  234. GetGridView().OnSelectionChanged();
  235. if ( bForward )
  236. return;
  237. nUI = SPGridUIInplaceButton;
  238. pItem = GetGridView().GetSelectedItem();
  239. }
  240. }
  241. }
  242. if ( nUI == SPGridUIView )
  243. {
  244. GetGridView().SetFocus();
  245. return;
  246. }
  247. if ( nUI == SPGridUIInplaceEdit )
  248. {
  249. if ( pItem && pItem->GetFlags() & SPGridItemHasEdit )
  250. {
  251. pItem->OnSelect();
  252. pItem->GetInplaceEdit().SetFocus();
  253. pItem->GetInplaceEdit().SetSel( 0,-1 );
  254. return;
  255. }
  256. nUI += nNextElement;
  257. }
  258. if ( nUI == SPGridUIInplaceButton )
  259. {
  260. if ( pItem && pItem->GetInplaceButton().GetSafeHwnd() && pItem->GetInplaceButton().IsWindowVisible() && pItem->GetInplaceButton().GetItem() == pItem )
  261. {
  262. pItem->GetInplaceButton().SetFocus();
  263. return;
  264. }
  265. nUI += nNextElement;
  266. }
  267. if ( nUI == SPGridUIViewNext )
  268. {
  269. if ( m_bTabItems )
  270. {
  271. int nIndex = bForward ? ( pItem ? pItem->m_nIndex + 1 : 0 ) : GetGridView().GetCount() - 1;
  272. if ( nIndex < GetGridView().GetCount() )
  273. {
  274. GetGridView().SetFocus();
  275. GetGridView().SetCurSel( nIndex );
  276. GetGridView().OnSelectionChanged();
  277. if ( bForward )
  278. return;
  279. pItem = GetGridView().GetSelectedItem();
  280. }
  281. }
  282. nUI += nNextElement;
  283. }
  284. if ( nUI == SPGridUIVerb )
  285. {
  286. if ( IsVerbsVisible() )
  287. {
  288. m_nFocusedVerb = bForward ? 0 : m_pVerbs->GetCount() - 1;
  289. m_bVerbActivate = TRUE;
  290. SetFocus();
  291. m_bVerbActivate = FALSE;
  292. Invalidate( FALSE );
  293. return;
  294. }
  295. nUI += nNextElement;
  296. }
  297. if ( nUI == SPGridUIParentNext || nUI == SPGridUIParentPrev )
  298. {
  299. CWnd * pWndNext = GetNextGridTabItem( !bForward );
  300. if ( pWndNext != NULL )
  301. {
  302. pWndNext->SetFocus();
  303. return;
  304. }
  305. if ( nUI == SPGridUIParentNext )
  306. nUI = SPGridUIViewPrev;
  307. else
  308. nUI = SPGridUIVerb;
  309. }
  310. if ( nUI < SPGridUIParentPrev || nUI > SPGridUIParentNext )
  311. {
  312. ASSERT( FALSE );
  313. return;
  314. }
  315. }
  316. }
  317. void CSPPropertyGrid::OnKeyDown( UINT nChar , UINT nRepCnt , UINT nFlags )
  318. {
  319. if ( m_nFocusedVerb != -1 && IsVerbsVisible() )
  320. {
  321. if ( m_nFocusedVerb >= m_pVerbs->GetCount() )
  322. m_nFocusedVerb = m_pVerbs->GetCount() - 1;
  323. BOOL bForward = GetKeyState( VK_SHIFT ) >= 0;
  324. if ( ( nChar == VK_TAB ) && bForward && ( m_nFocusedVerb == m_pVerbs->GetCount() - 1 ) )
  325. {
  326. OnNavigate( SPGridUIVerb,TRUE,NULL );
  327. return;
  328. }
  329. else if ( ( nChar == VK_TAB ) && !bForward && ( m_nFocusedVerb == 0 ) )
  330. {
  331. OnNavigate( SPGridUIVerb,FALSE,NULL );
  332. return;
  333. }
  334. else if ( nChar == VK_RIGHT || nChar == VK_DOWN || ( ( nChar == VK_TAB ) && bForward ) )
  335. {
  336. m_nFocusedVerb ++;
  337. if ( m_nFocusedVerb >= m_pVerbs->GetCount() )
  338. m_nFocusedVerb = 0;
  339. Invalidate( FALSE );
  340. }
  341. else if ( nChar == VK_LEFT || nChar == VK_UP || nChar == VK_TAB )
  342. {
  343. m_nFocusedVerb --;
  344. if ( m_nFocusedVerb < 0 )
  345. m_nFocusedVerb = m_pVerbs->GetCount() - 1;
  346. Invalidate( FALSE );
  347. }
  348. else if ( nChar == VK_RETURN )
  349. {
  350. CRect rcPart = m_pVerbs->GetAt( m_nFocusedVerb )->GetPart();
  351. OnVerbClick( m_nFocusedVerb,CPoint( rcPart.left,rcPart.bottom ) );
  352. }
  353. }
  354. CWnd::OnKeyDown( nChar,nRepCnt,nFlags );
  355. }
  356. void CSPPropertyGrid::OnKillFocus( CWnd * pNewWnd )
  357. {
  358. if ( m_nFocusedVerb != -1 )
  359. {
  360. m_nFocusedVerb = -1;
  361. Invalidate( FALSE );
  362. }
  363. CWnd::OnKillFocus( pNewWnd );
  364. }
  365. void CSPPropertyGrid::OnSetFocus( CWnd * pOldWnd )
  366. {
  367. if ( !m_bVerbActivate )
  368. {
  369. if ( pOldWnd && pOldWnd == GetNextGridTabItem( FALSE ) && GetKeyState( VK_SHIFT ) < 0 )
  370. {
  371. OnNavigate( SPGridUIParentNext,FALSE,NULL );
  372. }
  373. else if ( pOldWnd && pOldWnd == GetNextGridTabItem( TRUE ) && GetKeyState( VK_SHIFT ) >= 0 )
  374. {
  375. OnNavigate( SPGridUIParentPrev,TRUE,NULL );
  376. }
  377. else
  378. {
  379. GetGridView().SetFocus();
  380. }
  381. }
  382. else
  383. {
  384. CWnd::OnSetFocus( pOldWnd );
  385. }
  386. }
  387. void CSPPropertyGrid::OnSize( UINT nType , int cx , int cy )
  388. {
  389. CWnd::OnSize( nType,cx,cy );
  390. if ( !GetGridView().GetSafeHwnd() )
  391. {
  392. return;
  393. }
  394. Reposition( cx,cy );
  395. }
  396. int CSPPropertyGrid::HitTest( CPoint pt )
  397. {
  398. CSPClientRect rc ( this );
  399. if ( m_bHelpVisible )
  400. {
  401. CRect rcSplitter ( CPoint( rc.left,rc.bottom - SPLITTER_HEIGHT - m_nHelpHeight ),CSize( rc.Width(),SPLITTER_HEIGHT ) );
  402. if ( rcSplitter.PtInRect( pt ) )
  403. return SPGridHitHelpSplitter;
  404. rc.bottom -= SPLITTER_HEIGHT + m_nHelpHeight;
  405. }
  406. if ( IsVerbsVisible() )
  407. {
  408. CRect rcSplitter ( CPoint( rc.left,rc.bottom - SPLITTER_HEIGHT - m_nVerbsHeight ),CSize( rc.Width(),SPLITTER_HEIGHT ) );
  409. if ( rcSplitter.PtInRect( pt ) )
  410. return SPGridHitVerbsSplitter;
  411. CRect rcVerbs ( rc );
  412. rcVerbs.top = rc.bottom - m_nVerbsHeight;
  413. if ( rcVerbs.PtInRect( pt ) )
  414. {
  415. CWindowDC dc ( this );
  416. int nIndex = m_pPaintManager->HitTestVerbs( &dc,rcVerbs,pt );
  417. if ( nIndex != -1 )
  418. {
  419. return SPGridHitFirstVerb + nIndex;
  420. }
  421. }
  422. }
  423. return SPGridHitError;
  424. }
  425. BOOL CSPPropertyGrid::OnSetCursor( CWnd * pWnd , UINT nHitTest , UINT message )
  426. {
  427. if ( nHitTest == HTCLIENT )
  428. {
  429. CPoint point;
  430. GetCursorPos( &point );
  431. ScreenToClient( &point );
  432. int nHitTest = HitTest( point );
  433. if ( nHitTest == SPGridHitHelpSplitter || nHitTest == SPGridHitVerbsSplitter )
  434. {
  435. SetCursor( m_hCursorSplit );
  436. return TRUE;
  437. }
  438. if ( ( nHitTest != -1 ) && ( nHitTest >= SPGridHitFirstVerb ) )
  439. {
  440. SetCursor( m_hCursorHand );
  441. return TRUE;
  442. }
  443. }
  444. return CWnd::OnSetCursor( pWnd,nHitTest,message );
  445. }
  446. void CSPPropertyGrid::OnInvertTracker( CRect rect )
  447. {
  448. ASSERT_VALID( this );
  449. ASSERT( !rect.IsRectEmpty() );
  450. ASSERT( ( GetStyle() & WS_CLIPCHILDREN ) == 0 );
  451. // pat-blt without clip children on
  452. CDC * pDC = GetDC();
  453. CBrush brush ( GetXtremeColor( COLOR_3DFACE ) );
  454. CBrush *pBrush = ( CBrush * ) pDC->SelectObject( &brush );
  455. pDC->PatBlt( rect.left,rect.top,rect.Width(),rect.Height(),PATINVERT );
  456. pDC->SelectObject( pBrush );
  457. ReleaseDC( pDC );
  458. }
  459. void CSPPropertyGrid::OnSelectionChanged( CSPPropertyGridItem * pItem )
  460. {
  461. CSPClientRect rc ( this );
  462. CRect rcHelp ( rc );
  463. rcHelp.top = rc.bottom - m_nHelpHeight;
  464. if ( pItem )
  465. {
  466. GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_SELECTION_CHANGED,( LPARAM ) pItem );
  467. }
  468. InvalidateRect( rcHelp,FALSE );
  469. }
  470. void CSPPropertyGrid::OnVerbsChanged()
  471. {
  472. if ( m_bVerbsVisible != IsVerbsVisible() && GetGridView().m_nLockUpdate == 0 )
  473. {
  474. CSPClientRect rc ( this );
  475. Reposition( rc.Width(),rc.Height() );
  476. }
  477. else if ( GetSafeHwnd() && GetGridView().m_nLockUpdate == 0 )
  478. {
  479. Invalidate( FALSE );
  480. }
  481. }
  482. void CSPPropertyGrid::OnVerbClick( int nIndex , CPoint pt )
  483. {
  484. ClientToScreen( &pt );
  485. ASSERT( nIndex < m_pVerbs->GetCount() );
  486. CSPPropertyGridVerb * pVerb = m_pVerbs->GetAt( nIndex );
  487. pVerb->m_ptClick = pt;
  488. GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_VERB_CLICK,( LPARAM ) pVerb );
  489. }
  490. void CSPPropertyGrid::OnLButtonUp( UINT nFlags , CPoint point )
  491. {
  492. if ( ( m_nFocusedVerb != -1 ) && ( m_nFocusedVerb == HitTest( point ) - SPGridHitFirstVerb ) )
  493. {
  494. OnVerbClick( m_nFocusedVerb,point );
  495. }
  496. else
  497. {
  498. CWnd::OnLButtonUp( nFlags,point );
  499. }
  500. }
  501. void CSPPropertyGrid::OnLButtonDown( UINT nFlags , CPoint point )
  502. {
  503. int nHitTest = HitTest( point );
  504. if ( ( nHitTest != -1 ) && ( nHitTest >= SPGridHitFirstVerb ) )
  505. {
  506. m_nFocusedVerb = nHitTest - SPGridHitFirstVerb;
  507. m_bVerbActivate = TRUE;
  508. SetFocus();
  509. m_bVerbActivate = FALSE;
  510. Invalidate( FALSE );
  511. return;
  512. }
  513. SetFocus();
  514. if ( ( nHitTest == SPGridHitHelpSplitter ) || ( nHitTest == SPGridHitVerbsSplitter ) )
  515. {
  516. SetCapture();
  517. CSPClientRect rc ( this );
  518. BOOL bHelpHitTest = nHitTest == SPGridHitHelpSplitter;
  519. CRect rcAvail = bHelpHitTest ? CRect( 0,20 + TOOLBAR_HEIGHT,rc.right,rc.bottom ) : CRect( 0,20 + TOOLBAR_HEIGHT,rc.right,rc.bottom - ( IsHelpVisible() ? m_nHelpHeight + SPLITTER_HEIGHT : 0 ) );
  520. ModifyStyle( WS_CLIPCHILDREN | WS_CLIPSIBLINGS,0,FALSE );
  521. m_rectTracker.SetRect( 0,point.y,rc.Width(),point.y + 3 );
  522. OnInvertTracker( m_rectTracker );
  523. BOOL bAccept = FALSE;
  524. while ( GetCapture() == this )
  525. {
  526. MSG msg;
  527. if ( !GetMessage( &msg,NULL,0,0 ) )
  528. break;
  529. if ( msg.message == WM_MOUSEMOVE )
  530. {
  531. point = CPoint( msg.lParam );
  532. point.y = __min( point.y,rcAvail.bottom - 20 );
  533. point.y = __max( ( int ) point.y,int( rcAvail.top ) );
  534. if ( m_rectTracker.top != point.y )
  535. {
  536. OnInvertTracker( m_rectTracker );
  537. m_rectTracker.OffsetRect( 0,point.y - m_rectTracker.top );
  538. OnInvertTracker( m_rectTracker );
  539. }
  540. }
  541. else if ( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE )
  542. break;
  543. else if ( msg.message == WM_LBUTTONUP )
  544. {
  545. bAccept = TRUE;
  546. break;
  547. }
  548. else
  549. ::DispatchMessage( &msg );
  550. }
  551. ReleaseCapture();
  552. if ( bAccept )
  553. {
  554. if ( bHelpHitTest )
  555. m_nHelpHeight = rcAvail.bottom - m_rectTracker.top - 2;
  556. else
  557. m_nVerbsHeight = rcAvail.bottom - m_rectTracker.top - 2;
  558. Reposition( rc.Width(),rc.Height() );
  559. }
  560. Invalidate( FALSE );
  561. ModifyStyle( 0,WS_CLIPCHILDREN | WS_CLIPSIBLINGS,FALSE );
  562. return;
  563. }
  564. CWnd::OnLButtonDown( nFlags,point );
  565. }
  566. void CSPPropertyGrid::Reposition( int cx , int cy )
  567. {
  568. if ( GetGridView().m_nLockUpdate > 0 )
  569. {
  570. return;
  571. }
  572. if ( GetSafeHwnd() == 0 )
  573. {
  574. return;
  575. }
  576. CRect rcView ( 0,0,cx,cy );
  577. if ( m_bHelpVisible )
  578. {
  579. rcView.bottom -= m_nHelpHeight + SPLITTER_HEIGHT;
  580. }
  581. if ( IsVerbsVisible() )
  582. {
  583. rcView.bottom -= m_nVerbsHeight + SPLITTER_HEIGHT;
  584. }
  585. m_bVerbsVisible = IsVerbsVisible();
  586. if ( m_bToolBarVisible )
  587. {
  588. ASSERT( m_wndToolbar.GetSafeHwnd() );
  589. CRect rcToolBar ( 1,1,cx - 1,TOOLBAR_HEIGHT - 1 );
  590. m_wndToolbar.MoveWindow( rcToolBar );
  591. rcView.top += TOOLBAR_HEIGHT;
  592. }
  593. GetGridView().MoveWindow( rcView );
  594. Invalidate( FALSE );
  595. }
  596. void CSPPropertyGrid::CreateToolbar()
  597. {
  598. #if _MSC_VER < 1200
  599. m_wndToolbar.Create( this,TBSTYLE_FLAT | WS_CHILD | WS_VISIBLE | CBRS_TOOLTIPS | WS_BORDER,0 );
  600. #else
  601. m_wndToolbar.CreateEx( this,TBSTYLE_FLAT,WS_BORDER | WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_TOOLTIPS );
  602. #endif
  603. VERIFY( m_wndToolbar.LoadToolBar( SP_IDR_TBAR_PROPGRID ) );
  604. }
  605. void CSPPropertyGrid::ShowToolBar( BOOL bShow )
  606. {
  607. if ( bShow && !m_wndToolbar.GetSafeHwnd() )
  608. {
  609. CreateToolbar();
  610. }
  611. else
  612. {
  613. if ( m_wndToolbar.GetSafeHwnd() )
  614. {
  615. m_wndToolbar.ShowWindow( bShow ? SW_SHOW : SW_HIDE );
  616. }
  617. }
  618. m_bToolBarVisible = bShow;
  619. CSPClientRect rc ( this );
  620. Reposition( rc.Width(),rc.Height() );
  621. RefreshToolBarButtons();
  622. }
  623. void CSPPropertyGrid::RefreshToolBarButtons()
  624. {
  625. if ( m_bToolBarVisible )
  626. {
  627. m_wndToolbar.GetToolBarCtrl().SetState( SP_IDC_SORT_CATEGORIZED,TBSTATE_ENABLED | ( GetGridView().m_properetySort == SPGridSortCategorized ? TBSTATE_CHECKED : 0 ) );
  628. m_wndToolbar.GetToolBarCtrl().SetState( SP_IDC_SORT_ALPHABETIC,TBSTATE_ENABLED | ( GetGridView().m_properetySort == SPGridSortAlphabetical ? TBSTATE_CHECKED : 0 ) );
  629. }
  630. }
  631. void CSPPropertyGrid::ShowHelp( BOOL bShow )
  632. {
  633. m_bHelpVisible = bShow;
  634. CSPClientRect rc ( this );
  635. Reposition( rc.Width(),rc.Height() );
  636. }
  637. void CSPPropertyGrid::OnSortAlphabetic()
  638. {
  639. SetPropertySort( SPGridSortAlphabetical );
  640. }
  641. void CSPPropertyGrid::OnSortCategorized()
  642. {
  643. SetPropertySort( SPGridSortCategorized );
  644. }
  645. void CSPPropertyGrid::OnSortChanged()
  646. {
  647. RefreshToolBarButtons();
  648. OnSelectionChanged( NULL );
  649. GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_SORTORDER_CHANGED,( LPARAM ) GetDlgCtrlID() );
  650. }
  651. void CSPPropertyGrid::SetStandardColors()
  652. {
  653. m_clrHelpBack.SetDefaultValue();
  654. m_clrHelpFore.SetDefaultValue();
  655. GetGridView().m_clrLine.SetDefaultValue();
  656. GetGridView().m_clrBack.SetDefaultValue();
  657. GetGridView().m_clrFore.SetDefaultValue();
  658. GetGridView().m_clrReadOnlyFore.SetDefaultValue();
  659. GetGridView().m_clrCategoryFore.SetDefaultValue();
  660. m_pPaintManager->RefreshMetrics();
  661. RedrawWindow( NULL,NULL,RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE | RDW_ERASE );
  662. }
  663. void CSPPropertyGrid::SetCustomColors( COLORREF clrHelpBack , COLORREF clrHelpFore , COLORREF clrViewLine , COLORREF clrViewBack , COLORREF clrViewFore , COLORREF clrCategoryFore )
  664. {
  665. m_clrHelpBack.SetCustomValue( clrHelpBack );
  666. m_clrHelpFore.SetCustomValue( clrHelpFore );
  667. GetGridView().m_clrLine.SetCustomValue( clrViewLine );
  668. GetGridView().m_clrBack.SetCustomValue( clrViewBack );
  669. GetGridView().m_clrFore.SetCustomValue( clrViewFore );
  670. GetGridView().m_clrCategoryFore.SetCustomValue( clrCategoryFore );
  671. RedrawWindow( NULL,NULL,RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE | RDW_ERASE );
  672. }
  673. void CSPPropertyGrid::ResetContent()
  674. {
  675. m_pVerbs->RemoveAll();
  676. GetGridView().ResetContent();
  677. GetGridView().m_nLockUpdate++;
  678. GetGridView().m_pCategories->Clear();
  679. GetGridView().m_nLockUpdate--;
  680. }
  681. CSPPropertyGridItems * CSPPropertyGrid::GetCategories()
  682. {
  683. return GetGridView().m_pCategories;
  684. }
  685. CSPPropertyGridItem * CSPPropertyGrid::AddCategory( int nID )
  686. {
  687. CString strCaption;
  688. VERIFY( strCaption.LoadString( nID ) );
  689. CSPPropertyGridItem * pItem = GetGridView().AddCategory( strCaption );
  690. pItem->SetID( nID );
  691. return pItem;
  692. }
  693. CSPPropertyGridItem * CSPPropertyGrid::InsertCategory( int nIndex , int nID )
  694. {
  695. CString strCaption;
  696. VERIFY( strCaption.LoadString( nID ) );
  697. CSPPropertyGridItem * pItem = GetGridView().InsertCategory( nIndex,strCaption );
  698. pItem->SetID( nID );
  699. return pItem;
  700. }
  701. void CSPPropertyGrid::SetFont( CFont * pFont )
  702. {
  703. LOGFONT lf;
  704. if ( pFont->GetLogFont( &lf ) )
  705. {
  706. GetGridView().m_fontNormal.DeleteObject();
  707. GetGridView().m_fontBold.DeleteObject();
  708. lf.lfWeight = FW_NORMAL;
  709. VERIFY( GetGridView().m_fontNormal.CreateFontIndirect( &lf ) );
  710. lf.lfWeight = FW_BOLD;
  711. VERIFY( GetGridView().m_fontBold.CreateFontIndirect( &lf ) );
  712. if ( GetGridView().m_wndEdit.GetSafeHwnd() )
  713. {
  714. GetGridView().m_wndEdit.SetFont( &GetGridView().m_fontNormal );
  715. }
  716. Refresh();
  717. }
  718. }
  719. void CSPPropertyGrid::Refresh()
  720. {
  721. GetGridView().SetPropertySort( GetPropertySort(),TRUE );
  722. }
  723. void CSPPropertyGrid::SaveExpandingState( CSPPropertyGridItems * pItems , CMap< UINT, UINT, BOOL, BOOL& > * pState , UINT & nSelected )
  724. {
  725. for ( int nItem = 0; nItem < pItems->GetCount(); nItem++ )
  726. {
  727. CSPPropertyGridItem * pItem = pItems->GetAt( nItem );
  728. if ( pItem->GetID() != 0 )
  729. {
  730. if ( pItem->HasChilds() )
  731. {
  732. BOOL bExpanded = pItem->IsExpanded();
  733. pState->SetAt( pItem->GetID(),bExpanded );
  734. }
  735. if ( pItem->IsSelected() )
  736. nSelected = pItem->GetID();
  737. }
  738. SaveExpandingState( pItem->GetChilds(),pState,nSelected );
  739. }
  740. }
  741. void CSPPropertyGrid::RestoreExpandingState( CSPPropertyGridItems * pItems , CMap< UINT, UINT, BOOL, BOOL& > * pState )
  742. {
  743. for ( int nItem = 0; nItem < pItems->GetCount(); nItem++ )
  744. {
  745. CSPPropertyGridItem * pItem = pItems->GetAt( nItem );
  746. BOOL bExpanded;
  747. if ( pItem->GetID() != 0 && pState->Lookup( pItem->GetID(),bExpanded ) )
  748. {
  749. if ( bExpanded )
  750. pItem->Expand();
  751. else
  752. pItem->Collapse();
  753. }
  754. RestoreExpandingState( pItem->GetChilds(),pState );
  755. }
  756. }
  757. void CSPPropertyGrid::BeginUpdate( CSPPropertyGridUpdateContext & context )
  758. {
  759. GetGridView().m_nLockUpdate = 1;
  760. context.m_nSelected = 0;
  761. SaveExpandingState( GetCategories(),&context.m_mapState,context.m_nSelected );
  762. context.m_propertySort = GetPropertySort();
  763. ResetContent();
  764. }
  765. void CSPPropertyGrid::EndUpdate( CSPPropertyGridUpdateContext & context )
  766. {
  767. RestoreExpandingState( GetCategories(),&context.m_mapState );
  768. GetGridView().m_nLockUpdate = 0;
  769. GetGridView().SetPropertySort( context.m_propertySort,TRUE );
  770. if ( context.m_nSelected > 0 )
  771. {
  772. for ( int i = 0; i < GetGridView().GetCount(); i++ )
  773. {
  774. CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) GetGridView().GetItemDataPtr( i );
  775. if ( pItem && pItem->GetID() == context.m_nSelected )
  776. {
  777. pItem->Select();
  778. break;
  779. }
  780. }
  781. }
  782. CSPClientRect rc ( this );
  783. Reposition( rc.Width(),rc.Height() );
  784. }
  785. void CSPPropertyGrid::SetVerbsHeight( int nHeight )
  786. {
  787. ASSERT( nHeight > 0 );
  788. m_nVerbsHeight = nHeight;
  789. if ( GetSafeHwnd() )
  790. {
  791. CSPClientRect rc ( this );
  792. Reposition( rc.Width(),rc.Height() );
  793. }
  794. }
  795. void CSPPropertyGrid::SetHelpHeight( int nHeight )
  796. {
  797. ASSERT( nHeight > 0 );
  798. m_nHelpHeight = nHeight;
  799. if ( GetSafeHwnd() )
  800. {
  801. CSPClientRect rc ( this );
  802. Reposition( rc.Width(),rc.Height() );
  803. }
  804. }
  805. void CSPPropertyGrid::SetViewDivider( double dDivider )
  806. {
  807. ASSERT( dDivider > 0 && dDivider < 1 );
  808. GetGridView().m_dDivider = dDivider;
  809. if ( GetSafeHwnd() )
  810. {
  811. CSPClientRect rc ( this );
  812. Reposition( rc.Width(),rc.Height() );
  813. }
  814. }
  815. CSPPropertyGridItem * CSPPropertyGrid::GetSelectedItem()
  816. {
  817. return GetGridView().GetSelectedItem();
  818. }
  819. void CSPPropertyGrid::SetTheme( SPPropertyGridPaintTheme paintTheme )
  820. {
  821. ASSERT( m_pPaintManager );
  822. delete m_pPaintManager;
  823. if ( paintTheme == SPGridThemeDefault )
  824. {
  825. m_pPaintManager = new CSPPropertyGridPaintManager( this );
  826. }
  827. else if ( paintTheme == SPGridThemeCool )
  828. {
  829. m_pPaintManager = new CSPPropertyGridCoolTheme( this );
  830. }
  831. else if ( paintTheme == SPGridThemeDelphi )
  832. {
  833. m_pPaintManager = new CSPPropertyGridDelphiTheme( this );
  834. }
  835. else if ( paintTheme == SPGridThemeNativeWinXP )
  836. {
  837. m_pPaintManager = new CSPPropertyGridNativeXPTheme( this );
  838. }
  839. else if ( paintTheme == SPGridThemeOffice2003 )
  840. {
  841. m_pPaintManager = new CSPPropertyGridOffice2003Theme( this );
  842. }
  843. else if ( paintTheme == SPGridThemeSimple )
  844. {
  845. m_pPaintManager = new CSPPropertyGridSimpleTheme( this );
  846. }
  847. else if ( paintTheme == SPGridThemeWhidbey )
  848. {
  849. m_pPaintManager = new CSPPropertyGridWhidbeyTheme( this );
  850. }
  851. else
  852. {
  853. ASSERT( FALSE );
  854. }
  855. m_themeCurrent = paintTheme;
  856. if ( GetSafeHwnd() )
  857. {
  858. RedrawWindow( NULL,NULL,RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE | RDW_ERASE );
  859. }
  860. }
  861. void CSPPropertyGrid::SetCustomTheme( CSPPropertyGridPaintManager * pPaintManager )
  862. {
  863. ASSERT( m_pPaintManager );
  864. delete m_pPaintManager;
  865. m_pPaintManager = pPaintManager;
  866. if ( GetSafeHwnd() )
  867. {
  868. RedrawWindow( NULL,NULL,RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE | RDW_ERASE );
  869. }
  870. }
  871. void CSPPropertyGrid::OnSysColorChange()
  872. {
  873. CWnd::OnSysColorChange();
  874. m_pPaintManager->RefreshMetrics();
  875. }