SPPropertyGrid.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRID_H__)
  7. #define __SPPROPERTYGRID_H__
  8. //}}AFX_CODEJOCK_PRIVATE
  9. #if _MSC_VER > 1000
  10. #pragma once
  11. #endif // _MSC_VER > 1000
  12. #include "SPPropertyGridPaintManager.h"
  13. #include "SPDrawHelpers.h"
  14. //-----------------------------------------------------------------------
  15. // Summary:
  16. // SPPropertyGridSortOrder is an enumeration used by CSPPropertyGrid to
  17. // determine the grouping style. This will specify how the items
  18. // in the grid are displayed, I.e. Alphabetical, not sort, and
  19. // grouped by category.
  20. // See Also: CSPPropertyGrid::SetPropertySort, CSPPropertyGrid::GetPropertySort
  21. // Example:
  22. // <code>SPPropertyGridSortOrder sort = m_wndPropertyGrid.GetPropertySort();</code>
  23. //
  24. // <KEYWORDS SPGridSortCategorized, SPGridSortAlphabetical, SPGridSortNoSort>
  25. //-----------------------------------------------------------------------
  26. enum SPPropertyGridSortOrder
  27. {
  28. SPGridSortCategorized , // Group items by category.
  29. SPGridSortAlphabetical , // Sort items alphabetically.
  30. SPGridSortNoSort // Disable sorting and grouping, all items are displayed in
  31. // the order that they are added to the grid.
  32. };
  33. #include "SPPropertyGridView.h"
  34. class CSPPropertyGridView;
  35. class CSPPropertyGridPaintManager;
  36. class CSPPropertyGrid;
  37. //===========================================================================
  38. // Summary:
  39. // CSPPropertyGridUpdateContext is a CCmdTarget derived class used
  40. // to save the state of the property grid such as the currently
  41. // selected item, SPPropertyGridSortOrder preference, and the expanding state
  42. // of each item in the grid. The property grid state information is
  43. // stored in the CSPPropertyGridUpdateContext object when
  44. // CSPPropertyGrid::BeginUpdate is called and after CSPPropertyGrid::EndUpdate
  45. // the expanding state of each item, selected item, and sort preference
  46. // will be restored.
  47. // Remarks:
  48. // Each time you add a new item or category to the grid, The state
  49. // of the grid is updated the grid is redrawn.
  50. //
  51. // If you want to delete all items in the grid and then add allot of
  52. // new items it will be quite slow. To do this, you would call
  53. // BeginUpdate, then delete all the items. The property grid will be
  54. // locked until you call EndUpdate.
  55. //
  56. // It might be useful to call BeginWaitCursor to indicate that the
  57. // grid is "busy" updating.
  58. // See Also: CSPPropertyGrid::BeginUpdate, CSPPropertyGrid::EndUpdate
  59. //===========================================================================
  60. class CSPPropertyGridUpdateContext : public CCmdTarget
  61. {
  62. public:
  63. //-----------------------------------------------------------------------
  64. // Summary:
  65. // Constructs a CSPPropertyGridUpdateContext object.
  66. //-----------------------------------------------------------------------
  67. CSPPropertyGridUpdateContext();
  68. public:
  69. //-----------------------------------------------------------------------
  70. // Summary:
  71. // Call this member to determine if any items in the grid were
  72. // expanded before CSPPropertyGrid::BeginUpdate was called.
  73. // Only items with children can be expanded.
  74. // Returns:
  75. // TRUE if no items were expanded before BeginUpdate, FALSE if
  76. // at least one item was expanded.
  77. //-----------------------------------------------------------------------
  78. BOOL IsEmpty();
  79. protected:
  80. CMap< UINT, UINT, BOOL, BOOL& >m_mapState; // Stores the expanded state of each item in the grid before CSPPropertyGrid::BeginUpdate.
  81. UINT m_nSelected; // Stores the Id of the currently selected item before CSPPropertyGrid::BeginUpdate.
  82. SPPropertyGridSortOrder m_propertySort; // Stores the currently used sort method of the grid before CSPPropertyGrid::BeginUpdate.
  83. friend class CSPPropertyGrid;
  84. };
  85. //===========================================================================
  86. // Summary:
  87. // CSPPropertyGridToolBar is a CToolBar derived class.
  88. // It is an internal class used by Property Grid control
  89. //===========================================================================
  90. class CSPPropertyGridToolBar : public CToolBar
  91. {
  92. public:
  93. //-----------------------------------------------------------------------
  94. // Summary:
  95. // Constructs a CSPPropertyGridToolBar object
  96. //-----------------------------------------------------------------------
  97. CSPPropertyGridToolBar();
  98. protected:
  99. //{{AFX_CODEJOCK_PRIVATE
  100. //{{AFX_VIRTUAL(CSPPropertyGridToolBar)
  101. virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  102. //}}AFX_VIRTUAL
  103. //{{AFX_MSG(CSPPropertyGridToolBar)
  104. afx_msg BOOL OnEraseBkgnd(CDC*);
  105. afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
  106. afx_msg void OnPaint();
  107. //}}AFX_MSG
  108. DECLARE_MESSAGE_MAP()
  109. //}}AFX_CODEJOCK_PRIVATE
  110. };
  111. class CSPPropertyGridVerbs;
  112. //===========================================================================
  113. // Summary:
  114. // CSPPropertyGridVerb is used to create a verb link similar to what is seen
  115. // in Visual Studio .NET. For example, when the DataGrid control is selected at
  116. // design time in VS .NET, an AutoFormat link button appears in the Properties window
  117. // just below the property grid and above the help panel.
  118. // Verbs will be displayed in a separate panel just below the property grid. Verbs
  119. // are links that can be used to perform actions in your application. When a verb is
  120. // clicked, CSPPropertyGrid::OnVerbClick is called by the framework.
  121. // If both the verb panel and help panel are visible at the same time, the verb panel
  122. // is displayed above the help panel.
  123. // See Also: CSPPropertyGrid::GetVerbs, CSPPropertyGridVerbs
  124. //===========================================================================
  125. class CSPPropertyGridVerb : public CCmdTarget
  126. {
  127. public:
  128. //-----------------------------------------------------------------------
  129. // Summary:
  130. // Constructs a CSPPropertyGridVerb object.
  131. //-----------------------------------------------------------------------
  132. CSPPropertyGridVerb();
  133. public:
  134. //-----------------------------------------------------------------------
  135. // Summary:
  136. // Call this member to retrieve the text caption of this verb link.
  137. // Returns:
  138. // Text caption of this verb link.
  139. //-----------------------------------------------------------------------
  140. CString GetCaption();
  141. //-----------------------------------------------------------------------
  142. // Summary:
  143. // Call this member to retrieve the Id assigned to this verb link.
  144. // Returns:
  145. // The Id of this verb link.
  146. //-----------------------------------------------------------------------
  147. int GetID();
  148. //-----------------------------------------------------------------------
  149. // Summary:
  150. // Call this member to retrieve the Index of this verb link within the
  151. // collection of verbs.
  152. // Returns:
  153. // Index of this verb within the collection of verb links.
  154. //-----------------------------------------------------------------------
  155. int GetIndex();
  156. //-----------------------------------------------------------------------
  157. // Summary:
  158. // Call this member to determine if this verb link is currently focused.
  159. // If focused, a focus rectangle is placed around the text caption of the verb.
  160. // Returns:
  161. // TRUE if this verb is currently focused, FALSE if this verb is not focused.
  162. //-----------------------------------------------------------------------
  163. BOOL IsFocused();
  164. //-----------------------------------------------------------------------
  165. // Summary:
  166. // Used internally by PaintManager and PropertyGrid to set the
  167. // bounding rectangle for verbs. You do not need to call
  168. // this member.
  169. // Parameters:
  170. // rc - Bounding rectangle containing the verb text.
  171. //-----------------------------------------------------------------------
  172. void SetPart( CRect rc );
  173. //-----------------------------------------------------------------------
  174. // Summary:
  175. // Used internally by PaintManager and PropertyGrid to get the
  176. // bounding rectangle for verbs. You do not need to call
  177. // this member.
  178. // Returns:
  179. // Bounding rectangle of verb.
  180. //-----------------------------------------------------------------------
  181. CRect GetPart();
  182. //-----------------------------------------------------------------------
  183. // Summary:
  184. // Call this member to retrieve the last position that the user
  185. // clicked.
  186. // Returns:
  187. // Retrieves the last position the user clicked. If it was "clicked"
  188. // by pressing the Enter key while a verb has focus, then the
  189. // BottomLeft position of the "clicked" Verb is returned.
  190. //-----------------------------------------------------------------------
  191. CPoint GetClickPoint();
  192. protected:
  193. CString m_strCaption; // Text caption of this verb link.
  194. int m_nID; // Id assigned this verb link.
  195. int m_nIndex; // Index of this verb link in the collection of verbs.
  196. CRect m_rcPart; // Bounding rectangle of verb.
  197. CPoint m_ptClick; // The last position the user clicked.
  198. CSPPropertyGridVerbs * m_pVerbs; // Collection of verb links.
  199. friend class CSPPropertyGridVerbs;
  200. friend class CSPPropertyGrid;
  201. };
  202. //===========================================================================
  203. // Summary:
  204. // A collection of CSPPropertyGridVerb objects that are displayed in the
  205. // verb panel. See CSPPropertyGridVerb for a description of verbs.
  206. // See Also: CSPPropertyGridVerb
  207. //===========================================================================
  208. class CSPPropertyGridVerbs : public CCmdTarget
  209. {
  210. public:
  211. //-------------------------------------------------------------------------
  212. // Summary:
  213. // Constructs a CSPPropertyGridVerbs object.
  214. //-------------------------------------------------------------------------
  215. CSPPropertyGridVerbs();
  216. //-------------------------------------------------------------------------
  217. // Summary:
  218. // Destroys a CSPPropertyGridVerbs object, handles cleanup and deallocation.
  219. //-------------------------------------------------------------------------
  220. ~CSPPropertyGridVerbs();
  221. public:
  222. //-----------------------------------------------------------------------
  223. // Summary:
  224. // Call this member to determine if any verbs have been added to the
  225. // collection of verbs.
  226. // Returns:
  227. // TRUE if there are no verbs in the collection, FALSE if there is at
  228. // least one verb in the collection.
  229. //-----------------------------------------------------------------------
  230. BOOL IsEmpty();
  231. //-----------------------------------------------------------------------
  232. // Summary:
  233. // Call this member to remove all verbs from the collection of verbs.
  234. //-----------------------------------------------------------------------
  235. void RemoveAll();
  236. //-----------------------------------------------------------------------
  237. // Summary:
  238. // Call this member to get a pointer to a specific verb in the collection
  239. // of verbs.
  240. // Parameters:
  241. // nIndex - Index of the verb withing the collection of verbs.
  242. // Returns:
  243. // Verb at the specified location in the collection of verbs.
  244. //-----------------------------------------------------------------------
  245. CSPPropertyGridVerb * GetAt( int nIndex );
  246. //-----------------------------------------------------------------------
  247. // Summary:
  248. // Call this member to retrieve the total number of verb links in the
  249. // collection of verbs.
  250. // Returns:
  251. // Total number of verbs in the collection of verbs.
  252. //-----------------------------------------------------------------------
  253. int GetCount();
  254. //-----------------------------------------------------------------------
  255. // Summary:
  256. // Call this member to add a verb link to the verb panel.
  257. // Parameters:
  258. // strCaption - Text caption of the verb link.
  259. // nID - Id to assign to the new verb link.
  260. // Remarks:
  261. // This will add a CSPPropertyGridVerb object to the collection of
  262. // verbs. Verbs are displayed in the verb panel that is located just
  263. // below the property grid and above the help panel.
  264. //-----------------------------------------------------------------------
  265. void Add( LPCTSTR strCaption , UINT nID );
  266. protected:
  267. CArray< CSPPropertyGridVerb*, CSPPropertyGridVerb * > m_arrVerbs; // Collection of verb links.
  268. CSPPropertyGrid * m_pGrid; // Pointer to the property grid that the verbs are drawn on.
  269. friend class CSPPropertyGrid;
  270. friend class CSPPropertyGridVerb;
  271. };
  272. //-----------------------------------------------------------------------
  273. // Summary:
  274. // SPPropertyGridUI is an enumeration used by CSPPropertyGrid
  275. // during navigation of the Property Grid, items, and verbs
  276. // that specifies which object should receive focus.
  277. // Remarks:
  278. // After the Tab key or Shift+Tab key combinations are pressed,
  279. // focus will be given to the object specified in the SPPropertyGridUI
  280. // enumeration. I.e. If SPGridUIViewNext is passed into
  281. // OnNaviagte when an item in the grid has focus, then the next
  282. // item will receive focus.
  283. // See Also: CSPPropertyGrid::OnNavigate, CSPPropertyGrid::NavigateItems
  284. //
  285. // <KEYWORDS SPGridUIParentPrev, SPGridUIViewPrev, SPGridUIView, SPGridUIInplaceEdit, SPGridUIInplaceButton, SPGridUIViewNext, SPGridUIVerb, SPGridUIParentNext>
  286. //-----------------------------------------------------------------------
  287. enum SPPropertyGridUI
  288. {
  289. SPGridUIParentPrev = -2 , // Used to indicate that focus should be given to the previous object in the tab order.
  290. SPGridUIViewPrev = -1 , // If m_bTabItems is TRUE, Used to indicate that focus should be given to the previous item in the grid.
  291. // This occurs when an item has focus and Shift+Tab is pressed.
  292. SPGridUIView = 0 , // Used to indicate that focus should be given to the Property Grid.
  293. SPGridUIInplaceEdit = 1 , // Used to indicate that the Tab key is pressed while in an in-place edit box has focus.
  294. SPGridUIInplaceButton = 2 , // Used to indicate that the Tab key is pressed while an in-place button has focus.
  295. SPGridUIViewNext = 3 , // If m_bTabItems is TRUE, Used to indicate that focus should be given to the next item in the grid.
  296. // This occurs when an item has focus and the Tab key is pressed.
  297. SPGridUIVerb = 4 , // Used to indicate that the Tab key is pressed while in Verb has focus.
  298. SPGridUIParentNext = 5 , // Used to indicate that focus should be given to the next object in the tab order.
  299. };
  300. //-----------------------------------------------------------------------
  301. // Summary:
  302. // SPPropertyGridHitCode is an enumeration used by CSPPropertyGrid
  303. // to determine which part of the property grid is located at a
  304. // specific point. CSPPropertyGrid::HitTest is used to test
  305. // a point when the user clicks on the property grid.
  306. // See Also:
  307. // CSPPropertyGrid::HitTest
  308. // Example:
  309. // See CSPPropertyGrid::HitTest.
  310. //
  311. // <KEYWORDS SPGridHitError, SPGridHitHelpSplitter, SPGridHitVerbsSplitter, SPGridHitFirstVerb>
  312. //-----------------------------------------------------------------------
  313. enum SPPropertyGridHitCode
  314. {
  315. SPGridHitError = -1 , // Indicates that the help splitter, verb splitter
  316. // and verbs were not clicked.
  317. SPGridHitHelpSplitter = 1 , // Indicates that the help splitter was clicked.
  318. SPGridHitVerbsSplitter = 2 , // Indicates that the Verb splitter was clicked.
  319. SPGridHitFirstVerb = 3 , // Determines if the item clicked upon is a verb.
  320. };
  321. //===========================================================================
  322. // Summary:
  323. // CSPPropertyGrid is a CWnd derived class. It is used to create a property grid
  324. // control similar to the property window in VS.NET.
  325. // See the "PropertyGrid" demo for an example of its usage.
  326. //===========================================================================
  327. class CSPPropertyGrid : public CWnd
  328. {
  329. DECLARE_DYNAMIC( CSPPropertyGrid )
  330. public:
  331. //-----------------------------------------------------------------------
  332. // Summary:
  333. // Constructs a CSPPropertyGrid object
  334. //-----------------------------------------------------------------------
  335. CSPPropertyGrid();
  336. //-----------------------------------------------------------------------
  337. // Summary:
  338. // Destroys a CSPPropertyGrid object, handles cleanup and deallocation
  339. //-----------------------------------------------------------------------
  340. virtual ~CSPPropertyGrid();
  341. //-----------------------------------------------------------------------
  342. // Summary:
  343. // Call this member function to create the Property Grid control.
  344. // Parameters:
  345. // rect - Size of the control.
  346. // pParentWnd - Parent of the control.
  347. // nID - Identifier of the Property Grid control.
  348. // dwListStyle - List style of the items in the Property Grid.
  349. // Remarks:
  350. // Available styles are listed below:
  351. //
  352. // <p><b>LBS_OWNERDRAWFIXED</b> - The owner of the grid is
  353. // responsible for drawing its contents; the items in the
  354. // list box are the same height, should be used with
  355. // LBS_NOINTEGRALHEIGHT.
  356. // <p><b>LBS_OWNERDRAWVARIABLE</b> - The owner of the grid is
  357. // responsible for drawing its contents; the items
  358. // in the grid are variable in height, should be used with
  359. // LBS_NOINTEGRALHEIGHT
  360. // <p><b>SP_PGS_OWNERDRAW</b> - Apply this style to the property
  361. // grid to use the owner draw feature. Catch SP_PGN_DRAWITEM
  362. // to draw item. Recommended to use custom Paint Manager
  363. // instead. (SetCustomTheme)
  364. // Returns:
  365. // TRUE if successful, otherwise returns FALSE.
  366. // See Also: SetCustomTheme, SetTheme
  367. //-----------------------------------------------------------------------
  368. virtual BOOL Create( const RECT & rect , CWnd * pParentWnd , UINT nID , DWORD dwListStyle = LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT );
  369. public:
  370. //-----------------------------------------------------------------------
  371. // Summary:
  372. // Call this member function to add a new category to the Property Grid control.
  373. // Parameters:
  374. // strCaption - Name of the category to add.
  375. // Parameters:
  376. // nID - Identifier of new category.
  377. // Returns:
  378. // The pointer to the item object of the newly inserted category.
  379. //-----------------------------------------------------------------------
  380. CSPPropertyGridItem * AddCategory( CString strCaption );
  381. CSPPropertyGridItem * AddCategory( int nID );//<COMBINE CSPPropertyGrid::AddCategory@CString>
  382. //-----------------------------------------------------------------------
  383. // Summary:
  384. // Call this member function to insert a new category to the Property Grid control.
  385. // Parameters:
  386. // strCaption - Name of the category to add.
  387. // Parameters:
  388. // nID - Identifier of new category.
  389. // nIndex - Index of category to be inserted
  390. // Returns:
  391. // The pointer to the item object of the newly inserted category.
  392. //-----------------------------------------------------------------------
  393. CSPPropertyGridItem * InsertCategory( int nIndex , CString strCaption );
  394. CSPPropertyGridItem * InsertCategory( int nIndex , int nID );//<COMBINE CSPPropertyGrid::InsertCategory@int@CString>
  395. //-----------------------------------------------------------------------
  396. // Summary:
  397. // Call this member function to modify the way items are grouped.
  398. // Parameters:
  399. // sort - style of grouping. Can be any of the values listed in the Remarks section.
  400. // Remarks:
  401. // sort parameter can be one of the following:
  402. // * <b>SPGridSortCategorized</b> Group items by category.
  403. // * <b>SPGridSortAlphabetical</b> Sort items alphabetically.
  404. // * <b>SPGridSortNoSort</b> Disable sorting.
  405. // See Also: GetPropertySort
  406. //-----------------------------------------------------------------------
  407. void SetPropertySort( SPPropertyGridSortOrder sort );
  408. //-----------------------------------------------------------------------
  409. // Summary:
  410. // Call this member function to get the current grouping style for
  411. // the Property Grid control.
  412. // Returns:
  413. // An SPPropertyGridSortOrder value representing the current grouping style.
  414. // See Also: SetPropertySort
  415. //-----------------------------------------------------------------------
  416. SPPropertyGridSortOrder GetPropertySort();
  417. //-----------------------------------------------------------------------
  418. // Summary:
  419. // Call this member function to show or hide the toolbar control
  420. // in the Property Grid window.
  421. // Parameters:
  422. // bShow - TRUE to show the toolbar control, or FALSE to hide it.
  423. //-----------------------------------------------------------------------
  424. void ShowToolBar( BOOL bShow = TRUE );
  425. //-----------------------------------------------------------------------
  426. // Summary:
  427. // Call this member function to show or hide the description pane
  428. // in the Property Grid window.
  429. // Parameters:
  430. // bShow - TRUE to show the description pane, or FALSE to hide it.
  431. //-----------------------------------------------------------------------
  432. void ShowHelp( BOOL bShow = TRUE );
  433. //-----------------------------------------------------------------------
  434. // Summary:
  435. // Call this member function to set the custom colors of the Property
  436. // Grid control.
  437. // Parameters:
  438. // clrHelpBack - An RGB value that represents the background color
  439. // the of description pane.
  440. // clrHelpFore - An RGB value that represents the text color of
  441. // the description pane.
  442. // clrViewLine - An RGB value that represents the color of separating
  443. // lines in control.
  444. // clrViewBack - An RGB value that represents the background color
  445. // of the Property Grid control.
  446. // clrViewFore - An RGB value that represents the text color of
  447. // the Property Grid control.
  448. // clrCategoryFore - An RGB value that represents the text color of
  449. // the Category item text.
  450. //-----------------------------------------------------------------------
  451. void SetCustomColors( COLORREF clrHelpBack , COLORREF clrHelpFore , COLORREF clrViewLine , COLORREF clrViewBack , COLORREF clrViewFore , COLORREF clrCategoryFore = ::GetSysColor( COLOR_GRAYTEXT ) );
  452. //-----------------------------------------------------------------------
  453. // Summary:
  454. // Call this member function to set the default colors of the Property
  455. // Grid control.
  456. //-----------------------------------------------------------------------
  457. void SetStandardColors();
  458. //-----------------------------------------------------------------------
  459. // Summary:
  460. // Call this member function to find an item.
  461. // Parameters:
  462. // strCaption - Caption for the item to find.
  463. // nID - Identifier for the item to find.
  464. // Returns:
  465. // The pointer to the CSPPropertyGridItem object.
  466. //-----------------------------------------------------------------------
  467. CSPPropertyGridItem * FindItem( CString strCaption );
  468. CSPPropertyGridItem * FindItem( UINT nID ); // <COMBINE CSPPropertyGrid::FindItem@CString>
  469. //-----------------------------------------------------------------------
  470. // Summary:
  471. // Removes all items from the list box of a property grid control.
  472. //-----------------------------------------------------------------------
  473. void ResetContent();
  474. //-----------------------------------------------------------------------
  475. // Summary:
  476. // Call this member function to determine if the help pane is visible.
  477. // Returns:
  478. // TRUE if the help pane is visible, otherwise returns FALSE.
  479. //-----------------------------------------------------------------------
  480. BOOL IsHelpVisible() const;
  481. //-----------------------------------------------------------------------
  482. // Summary:
  483. // Call this member function to determine if the toolbar is visible.
  484. // Returns:
  485. // TRUE if the toolbar is visible, otherwise returns FALSE.
  486. //-----------------------------------------------------------------------
  487. BOOL IsBarVisible() const;
  488. //-----------------------------------------------------------------------
  489. // Summary:
  490. // Call this member function to return the height of the help pane
  491. // when it is visible.
  492. // Returns:
  493. // An integer value that represents the height in pixels.
  494. //-----------------------------------------------------------------------
  495. int GetHelpHeight() const;
  496. //-----------------------------------------------------------------------
  497. // Summary:
  498. // Call this member function to return the background color for
  499. // the property grid.
  500. // Returns:
  501. // An RGB value.
  502. //-----------------------------------------------------------------------
  503. COLORREF GetHelpBackColor();
  504. //-----------------------------------------------------------------------
  505. // Summary:
  506. // Call this member function to return the foreground color for
  507. // the property grid.
  508. // Returns:
  509. // An RGB value.
  510. //-----------------------------------------------------------------------
  511. COLORREF GetHelpForeColor();
  512. //-----------------------------------------------------------------------
  513. // Summary:
  514. // Call this member function to return the categories of the property
  515. // grid.
  516. // Returns:
  517. // The pointer to the CSPPropertyGridItems object that represents
  518. // collection of the categories.
  519. //-----------------------------------------------------------------------
  520. CSPPropertyGridItems * GetCategories();
  521. //-----------------------------------------------------------------------
  522. // Summary:
  523. // Call this member to return a pointer to the collection of verbs that
  524. // are displayed in the verb panel.
  525. // Returns:
  526. // The pointer to the CSPPropertyGridVerbs object that represents
  527. // the collection of verbs.
  528. //-----------------------------------------------------------------------
  529. CSPPropertyGridVerbs * GetVerbs();
  530. //-----------------------------------------------------------------------
  531. // Summary:
  532. // Call this method to retrieve reference to the view object.
  533. // Returns:
  534. // A CSPPropertyGridView object
  535. //-----------------------------------------------------------------------
  536. CSPPropertyGridView &GetGridView();
  537. //-----------------------------------------------------------------------
  538. // Summary:
  539. // Call this method to retrieve reference to the toolbar for the
  540. // property grid.
  541. // Returns:
  542. // A reference to a CToolBar object
  543. //-----------------------------------------------------------------------
  544. CToolBar &GetToolBar();
  545. //-----------------------------------------------------------------------
  546. // Summary:
  547. // Call this member function to get selected item.
  548. // Returns:
  549. // The pointer to the CSPPropertyGridItems object currently selected.
  550. //-----------------------------------------------------------------------
  551. CSPPropertyGridItem * GetSelectedItem();
  552. //-----------------------------------------------------------------------
  553. // Summary:
  554. // Call this member function to set the height of the help pane
  555. // when visible.
  556. // Parameters:
  557. // nHeight - The integer value represents the height in pixels.
  558. //-----------------------------------------------------------------------
  559. void SetHelpHeight( int nHeight );
  560. //-----------------------------------------------------------------------
  561. // Summary:
  562. // Call this member function to set the divider position of the grid view.
  563. // Parameters:
  564. // dDivider - A value between 0 and 1 that represents the location of the divider as
  565. // a percentage from the left side of the view. For example, if you wanted
  566. // the divider to divide at 25% you would pass in .25.
  567. //-----------------------------------------------------------------------
  568. void SetViewDivider( double dDivider );
  569. //-----------------------------------------------------------------------
  570. // Summary:
  571. // This method sets the grid抯 current font to the specified font.
  572. // Parameters:
  573. // pFont - Pointer to a CFont object.
  574. //-----------------------------------------------------------------------
  575. void SetFont( CFont * pFont );
  576. //-----------------------------------------------------------------------
  577. // Summary:
  578. // Call this member to set the grid theme.
  579. // Parameters:
  580. // paintTheme - theme of property grid. Can be one of the values
  581. // listed in the Remarks section.
  582. // Remarks:
  583. // paintTheme can be one of the following values:
  584. // * <b>SPGridThemeDefault</b> Enables default theme.
  585. // * <b>SPGridThemeNativeWinXP</b> Enables WinXP style theme.
  586. // * <b>SPGridThemeOffice2003</b> Enables Office 2003 style theme.
  587. // * <b>SPGridThemeCool</b> Enables Cool theme.
  588. // * <b>SPGridThemeSimple</b> Enables Visual Basic style theme.
  589. // * <b>SPGridThemeDelphi</b> Enables Delphi style theme.
  590. // * <b>SPGridThemeWhidbey</b> Enables Visual Studio 2005 "Whidbey" style theme.
  591. //-----------------------------------------------------------------------
  592. void SetTheme( SPPropertyGridPaintTheme paintTheme );
  593. //-----------------------------------------------------------------------
  594. // Summary:
  595. // Call this method to set custom theme of the grid.
  596. // Parameters:
  597. // pPaintManager - Points to a CSPPropertyGridPaintManager object
  598. //-----------------------------------------------------------------------
  599. void SetCustomTheme( CSPPropertyGridPaintManager * pPaintManager );
  600. //-----------------------------------------------------------------------
  601. // Summary:
  602. // Retrieves current theme of the grid.
  603. //-----------------------------------------------------------------------
  604. SPPropertyGridPaintTheme GetCurrentTheme();
  605. //-----------------------------------------------------------------------
  606. // Summary:
  607. // Call this method to refresh items in the list.
  608. //-----------------------------------------------------------------------
  609. void Refresh();
  610. //-----------------------------------------------------------------------
  611. // Summary:
  612. // Call this member function to "lock" the property grid. This
  613. // should be called when adding or deleting a large number of item.
  614. // Parameters:
  615. // context - Pointer to a CSPPropertyGridUpdateContext object.
  616. // Remarks:
  617. // Each time you add a new item or category to the grid, The state
  618. // of the grid is updated the grid is redrawn.
  619. //
  620. // If you want to delete all items in the grid and then add allot of
  621. // new items it will be quite slow. To do this, you would call
  622. // BeginUpdate, then delete all the items. The property grid will be
  623. // locked until you call EndUpdate.
  624. //
  625. // It might be useful to call BeginWaitCursor to indicate that the
  626. // grid is "busy" updating.
  627. // See Also: EndUpdate, CSPPropertyGridUpdateContext
  628. //-----------------------------------------------------------------------
  629. void BeginUpdate( CSPPropertyGridUpdateContext & context );
  630. //-----------------------------------------------------------------------
  631. // Summary:
  632. // This member should be called after BeginUpdate. You need to call
  633. // EndUpdate to "unlock" the grid after you have finished adding
  634. // and deleting a large amount of items.
  635. // Parameters:
  636. // context - Pointer to a CSPPropertyGridUpdateContext object.
  637. // See Also: BeginUpdate, CSPPropertyGridUpdateContext
  638. //-----------------------------------------------------------------------
  639. void EndUpdate( CSPPropertyGridUpdateContext & context );
  640. //-----------------------------------------------------------------------
  641. // Summary:
  642. // Call this member to determine if the verb panel is currently visible.
  643. // Returns:
  644. // TRUE if the verb panel is visible, FALSE otherwise.
  645. // See Also: CSPPropertyGridVerb, CSPPropertyGridVerbs
  646. //-----------------------------------------------------------------------
  647. BOOL IsVerbsVisible();
  648. //-----------------------------------------------------------------------
  649. // Summary:
  650. // Returns the currently used control's Paint Manager.
  651. // Remarks:
  652. // Call this member function to get the paint manager object used
  653. // for drawing a property grid control window.
  654. // Returns:
  655. // Pointer to the paint manager object.
  656. //-----------------------------------------------------------------------
  657. CSPPropertyGridPaintManager * GetPaintManager();
  658. //-----------------------------------------------------------------------
  659. // Summary:
  660. // Creates View of Property grid. Override this member to use custom view.
  661. //-----------------------------------------------------------------------
  662. virtual CSPPropertyGridView * CreateView();
  663. //-----------------------------------------------------------------------
  664. // Summary:
  665. // This member is called when a user clicks on a verb or when a
  666. // verb has focus and the enter key is pressed. Override this
  667. // member to perform custom actions such as displaying a dialog.
  668. // Parameters:
  669. // nIndex - Index of the verb within the collection of verbs.
  670. // pt - Point on the screen that the user clicked. This
  671. // will the position of the mouse cursor over a verb. This
  672. // point is stored in the CSPPropertyGridVerb::m_ptClick
  673. // member which is a CPoint object. Coordinates will be
  674. // relative to the screen and not the client.
  675. //-----------------------------------------------------------------------
  676. virtual void OnVerbClick( int nIndex , CPoint pt );
  677. //-----------------------------------------------------------------------
  678. // Summary:
  679. // This member is called when items in the property grid are navigated
  680. // using key on the keyboard. This includes navigating the built in
  681. // toolbar, verbs, and items in the property grid.
  682. // Parameters:
  683. // nUIElement - Indicates which object should receive focus.
  684. // Members of SPPropertyGridUI are used to indicate
  685. // which object receives focus.
  686. // bForward - TRUE if the Tab key is pressed and items are being
  687. // navigated in the forward direction, FALSE if Shift+Tab
  688. // is pressed and items are navigated backwards.
  689. // TRUE if the Right or Down arrow is used to navigate the items.
  690. // FALSE if the Up or Left arrow is used to navigate the items.
  691. // pItem - Pointer to the currently selected item.
  692. // See Also: SPPropertyGridUI
  693. //-----------------------------------------------------------------------
  694. virtual void OnNavigate( SPPropertyGridUI nUIElement , BOOL bForward , CSPPropertyGridItem * pItem );
  695. //-----------------------------------------------------------------------
  696. // Summary:
  697. // Call this method to enable navigate items using Tab key.
  698. // Parameters:
  699. // bTabItems - TRUE to navigate items in the grid using the tab key.
  700. // When TRUE, focus will move in this order:
  701. // Caption, Item Value, Item InPlaceButton (if used), Next item Caption
  702. // FALSE not to navigate the items in the grid with the tab key.
  703. //-----------------------------------------------------------------------
  704. void NavigateItems( BOOL bTabItems );
  705. //-----------------------------------------------------------------------
  706. // Summary:
  707. // Call this member to specify the height of the verb box when visible.
  708. // Parameters:
  709. // nHeight - Height of the verb box.
  710. // See Also: CSPPropertyGridVerb, CSPPropertyGridVerbs, IsVerbsVisible
  711. //-----------------------------------------------------------------------
  712. void SetVerbsHeight( int nHeight );
  713. protected:
  714. //-----------------------------------------------------------------------
  715. // Summary:
  716. // This method is called by the framework during resizing of splitters.
  717. // Parameters:
  718. // rc - Specifies the reference to a CRect object specifying
  719. // the tracking rectangle.
  720. //-----------------------------------------------------------------------
  721. void OnInvertTracker( CRect rc );
  722. //-----------------------------------------------------------------------
  723. // Summary:
  724. // This member is called to determine if the help splitter,
  725. // verb splitter, or a verb was clicked upon.
  726. // Parameters:
  727. // pt - A point to test.
  728. // Returns:
  729. // The HitTest method returns the following values which specify which
  730. // part of the property grid located under the coordinates specified
  731. // by <i>pt</i>.
  732. //
  733. // * <b>SPGridHitError</b> Indicates something else was clicked.
  734. // * <b>SPGridHitHelpSplitter</b> Indicates the help splitter was clicked.
  735. // * <b>SPGridHitVerbsSplitter</b> Indicates the verb splitter was clicked.
  736. // * <b>SPGridHitFirstVerb</b> If the return value is greater than or
  737. // equal to SPGridHitFirstVerb then the item clicked upon is
  738. // a verb. You can retrieve the verb index by subtracting
  739. // SPGridHitFirstVerb from the return value, for example:
  740. // <code>
  741. // int iHit = m_wndPropertyGrid.HitTest(pt);
  742. // if (iHit >= SPGridHitFirstVerb)
  743. // {
  744. // // Get the index of the verb.
  745. // m_iVerbIndex = (iHit-SPGridHitFirstVerb);
  746. // }
  747. // </code>
  748. // See Also:
  749. // SPPropertyGridHitCode
  750. //-----------------------------------------------------------------------
  751. virtual int HitTest( CPoint pt );
  752. //-----------------------------------------------------------------------
  753. // Summary:
  754. // This member is called when a new item is selected in the
  755. // grid. Or focus switched from one item to a different item.
  756. // Parameters:
  757. // pItem - Item that the selection has changed too. This is the
  758. // item that just received focus.
  759. // See Also: GetSelectedItem
  760. //-----------------------------------------------------------------------
  761. virtual void OnSelectionChanged( CSPPropertyGridItem * pItem );
  762. //-------------------------------------------------------------------------
  763. // Summary:
  764. // This member is called when the sort order has changed.
  765. // See Also: SetPropertySort
  766. //-------------------------------------------------------------------------
  767. virtual void OnSortChanged();
  768. //-----------------------------------------------------------------------
  769. // Summary:
  770. // This member is called to recalculate the position and size of the
  771. // property grid, then it resizes the grid to the specified size.
  772. // New size is 0,0,cx,cy.
  773. // This is the area that hold the toolbar and grid, this does not
  774. // include the area for the verb and help panel.
  775. // Parameters:
  776. // cx - New bottom-right x coordinate of the grid's bounding rectangle.
  777. // cy - New bottom-right y coordinate of the grid's bounding rectangle.
  778. //-----------------------------------------------------------------------
  779. virtual void Reposition( int cx , int cy );
  780. //-------------------------------------------------------------------------
  781. // Summary:
  782. // This member is called when the "built-in" toolbar is created.
  783. //-------------------------------------------------------------------------
  784. void CreateToolbar();
  785. //-------------------------------------------------------------------------
  786. // Summary:
  787. // This member is called when the toolbar buttons need to be redrawn.
  788. // Remarks:
  789. // This occurs when the sort order has changed, and when the toolbar
  790. // is shown. Sort order can be changed by code or by clicking on
  791. // a button in the toolbar.
  792. //-------------------------------------------------------------------------
  793. void RefreshToolBarButtons();
  794. //-------------------------------------------------------------------------
  795. // Summary:
  796. // This member is called when a Verb receives focus, and when focus
  797. // switches from one verb to a different verb.
  798. //-------------------------------------------------------------------------
  799. void OnVerbsChanged();
  800. private:
  801. CWnd * GetNextGridTabItem( BOOL bForward );
  802. void RestoreExpandingState( CSPPropertyGridItems * pItems , CMap< UINT, UINT, BOOL, BOOL& > * pState );
  803. void SaveExpandingState( CSPPropertyGridItems * pItems , CMap< UINT, UINT, BOOL, BOOL& > * pState , UINT & nSelected );
  804. public:
  805. int m_nHelpHeight; // Height of the description area (help panel).
  806. int m_nVerbsHeight; // Height of the verbs panel.
  807. CSPPaintManagerColor m_clrHelpBack; // Color of the description background.
  808. CSPPaintManagerColor m_clrHelpFore; // Color of the description text.
  809. protected:
  810. BOOL m_bHelpVisible; // TRUE if the help panel is visible.
  811. BOOL m_bToolBarVisible; // TRUE if the built in toolbar is visible.
  812. CSPPropertyGridToolBar m_wndToolbar; // Pointer to the "built-in" PropertyGrid toolbar.
  813. HCURSOR m_hCursorSplit; // Handle to the cursor when positioned over a splitter.
  814. HCURSOR m_hCursorHand; // Handle of the cursor.
  815. BOOL m_bTabItems; // TRUE to navigate items with the tab key.
  816. CSPPropertyGridVerbs * m_pVerbs; // Collection of verbs (links) displayed in the verb panel when the panel is visible.
  817. BOOL m_bVerbsVisible; // TRUE if the verb panel is visible.
  818. SPPropertyGridPaintTheme m_themeCurrent; // Currently set theme.
  819. CSPPropertyGridPaintManager * m_pPaintManager; // Current paint manager.
  820. int m_nFocusedVerb; // Index of the currently focused verb within the collection of verbs.
  821. private:
  822. CRect m_rectTracker;
  823. CSPPropertyGridView * m_pView;
  824. BOOL m_bVerbActivate;
  825. protected:
  826. //{{AFX_CODEJOCK_PRIVATE
  827. //{{AFX_MSG(CSPPropertyGrid)
  828. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  829. afx_msg void OnPaint();
  830. afx_msg void OnSetFocus(CWnd* pOldWnd);
  831. afx_msg void OnKillFocus(CWnd* pNewWnd);
  832. afx_msg void OnSize(UINT nType, int cx, int cy);
  833. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  834. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  835. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  836. afx_msg void OnSortAlphabetic();
  837. afx_msg void OnSortCategorized();
  838. afx_msg void OnSysColorChange();
  839. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  840. afx_msg UINT OnGetDlgCode();
  841. //}}AFX_MSG
  842. private:
  843. BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
  844. DECLARE_MESSAGE_MAP()
  845. friend class CSPPropertyGridView;
  846. friend class CPropertyGridCtrl;
  847. friend class CSPPropertyGridVerb;
  848. friend class CSPPropertyGridVerbs;
  849. //}}AFX_CODEJOCK_PRIVATE
  850. };
  851. //////////////////////////////////////////////////////////////////////
  852. AFX_INLINE BOOL CSPPropertyGridUpdateContext::IsEmpty()
  853. {
  854. return m_mapState.IsEmpty();
  855. }
  856. AFX_INLINE CString CSPPropertyGridVerb::GetCaption()
  857. {
  858. return m_strCaption;
  859. }
  860. AFX_INLINE int CSPPropertyGridVerb::GetID()
  861. {
  862. return m_nID;
  863. }
  864. AFX_INLINE int CSPPropertyGridVerb::GetIndex()
  865. {
  866. return m_nIndex;
  867. }
  868. AFX_INLINE void CSPPropertyGridVerb::SetPart( CRect rc )
  869. {
  870. m_rcPart = rc;
  871. }
  872. AFX_INLINE CRect CSPPropertyGridVerb::GetPart()
  873. {
  874. return m_rcPart;
  875. }
  876. AFX_INLINE CPoint CSPPropertyGridVerb::GetClickPoint()
  877. {
  878. return m_ptClick;
  879. }
  880. AFX_INLINE BOOL CSPPropertyGridVerb::IsFocused()
  881. {
  882. return ( m_nIndex == m_pVerbs->m_pGrid->m_nFocusedVerb ) && ( ::GetFocus() == m_pVerbs->m_pGrid->GetSafeHwnd() );
  883. }
  884. AFX_INLINE CSPPropertyGridVerb * CSPPropertyGridVerbs::GetAt( int nIndex )
  885. {
  886. return m_arrVerbs.GetAt( nIndex );
  887. }
  888. AFX_INLINE BOOL CSPPropertyGridVerbs::IsEmpty()
  889. {
  890. return m_arrVerbs.GetSize() == 0;
  891. }
  892. AFX_INLINE CSPPropertyGridItem * CSPPropertyGrid::FindItem( CString strCaption )
  893. {
  894. return GetGridView().m_pCategories->FindItem( strCaption );
  895. }
  896. AFX_INLINE CSPPropertyGridItem * CSPPropertyGrid::FindItem( UINT nID )
  897. {
  898. return GetGridView().m_pCategories->FindItem( nID );
  899. }
  900. AFX_INLINE CSPPropertyGridItem * CSPPropertyGrid::AddCategory( CString strCaption )
  901. {
  902. return GetGridView().AddCategory( strCaption );
  903. }
  904. AFX_INLINE CSPPropertyGridItem * CSPPropertyGrid::InsertCategory( int nIndex , CString strCaption )
  905. {
  906. return GetGridView().InsertCategory( nIndex,strCaption );
  907. }
  908. AFX_INLINE void CSPPropertyGrid::SetPropertySort( SPPropertyGridSortOrder sort )
  909. {
  910. GetGridView().SetPropertySort( sort );
  911. }
  912. AFX_INLINE SPPropertyGridSortOrder CSPPropertyGrid::GetPropertySort()
  913. {
  914. return GetGridView().m_properetySort;
  915. }
  916. AFX_INLINE BOOL CSPPropertyGrid::IsHelpVisible() const
  917. {
  918. return m_bHelpVisible;
  919. }
  920. AFX_INLINE BOOL CSPPropertyGrid::IsBarVisible() const
  921. {
  922. return m_bToolBarVisible;
  923. }
  924. AFX_INLINE int CSPPropertyGrid::GetHelpHeight() const
  925. {
  926. return m_nHelpHeight;
  927. }
  928. AFX_INLINE COLORREF CSPPropertyGrid::GetHelpBackColor()
  929. {
  930. return m_clrHelpBack;
  931. }
  932. AFX_INLINE COLORREF CSPPropertyGrid::GetHelpForeColor()
  933. {
  934. return m_clrHelpFore;
  935. }
  936. AFX_INLINE CToolBar & CSPPropertyGrid::GetToolBar()
  937. {
  938. return m_wndToolbar;
  939. }
  940. AFX_INLINE SPPropertyGridPaintTheme CSPPropertyGrid::GetCurrentTheme()
  941. {
  942. return m_themeCurrent;
  943. }
  944. AFX_INLINE CSPPropertyGridVerbs * CSPPropertyGrid::GetVerbs()
  945. {
  946. return m_pVerbs;
  947. }
  948. AFX_INLINE BOOL CSPPropertyGrid::IsVerbsVisible()
  949. {
  950. return !m_pVerbs->IsEmpty();
  951. }
  952. AFX_INLINE CSPPropertyGridPaintManager * CSPPropertyGrid::GetPaintManager()
  953. {
  954. return m_pPaintManager;
  955. }
  956. AFX_INLINE BOOL CSPPropertyGrid::Create( LPCTSTR lpszClassName , LPCTSTR lpszWindowName , DWORD dwStyle , const RECT & rect , CWnd * pParentWnd , UINT nID , CCreateContext * pContext )
  957. {
  958. return CWnd::Create( lpszClassName,lpszWindowName,dwStyle,rect,pParentWnd,nID,pContext );
  959. }
  960. AFX_INLINE void CSPPropertyGrid::NavigateItems( BOOL bTabItems )
  961. {
  962. m_bTabItems = bTabItems;
  963. }
  964. #endif // #if !defined(__SPPROPERTYGRID_H__)