manager.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: manager.h
  3. // Purpose: interface of wxPropertyGridManager
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxPropertyGridPage
  9. Holder of property grid page information. You can subclass this and
  10. give instance in wxPropertyGridManager::AddPage. It inherits from
  11. wxEvtHandler and can be used to process events specific to this
  12. page (id of events will still be same as manager's). If you don't
  13. want to use it to process all events of the page, you need to
  14. return @false in the derived wxPropertyGridPage::IsHandlingAllEvents.
  15. Please note that wxPropertyGridPage lacks many non-const property
  16. manipulation functions found in wxPropertyGridManager.
  17. Please use parent manager (m_manager member variable) when needed.
  18. Please note that most member functions are inherited and as such not
  19. documented on this page. This means you will probably also want to read
  20. wxPropertyGridInterface class reference.
  21. @section propgridpage_event_handling Event Handling
  22. wxPropertyGridPage receives events emitted by its wxPropertyGridManager, but
  23. only those events that are specific to that page. If wxPropertyGridPage::
  24. IsHandlingAllEvents returns false, then unhandled events are sent to the
  25. manager's parent, as usual.
  26. See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
  27. for more information.
  28. @library{wxpropgrid}
  29. @category{propgrid}
  30. */
  31. class WXDLLIMPEXP_PROPGRID wxPropertyGridPage : public wxEvtHandler,
  32. public wxPropertyGridInterface
  33. {
  34. friend class wxPropertyGridManager;
  35. public:
  36. wxPropertyGridPage();
  37. virtual ~wxPropertyGridPage();
  38. /**
  39. Deletes all properties on page.
  40. */
  41. virtual void Clear();
  42. /**
  43. Reduces column sizes to minimum possible that contents are still visibly
  44. (naturally some margin space will be applied as well).
  45. @return Returns minimum size for the page to still display everything.
  46. @remarks This function only works properly if size of containing grid was
  47. already fairly large.
  48. Note that you can also get calculated column widths by calling
  49. GetColumnWidth() immediately after this function returns.
  50. */
  51. wxSize FitColumns();
  52. /**
  53. Returns page index in manager;
  54. */
  55. inline int GetIndex() const;
  56. /**
  57. Returns "root property". It does not have name, etc. and it is not
  58. visible. It is only useful for accessing its children.
  59. */
  60. wxPGProperty* GetRoot() const;
  61. /**
  62. Returns x-coordinate position of splitter on a page.
  63. */
  64. int GetSplitterPosition( int col = 0 ) const;
  65. /**
  66. Returns id of the tool bar item that represents this page on
  67. wxPropertyGridManager's wxToolBar.
  68. */
  69. int GetToolId() const;
  70. /**
  71. Do any member initialization in this method.
  72. @remarks - Called every time the page is added into a manager.
  73. - You can add properties to the page here.
  74. */
  75. virtual void Init();
  76. /**
  77. Return false here to indicate unhandled events should be
  78. propagated to manager's parent, as normal.
  79. */
  80. virtual bool IsHandlingAllEvents() const;
  81. /**
  82. Called every time page is about to be shown.
  83. Useful, for instance, creating properties just-in-time.
  84. */
  85. virtual void OnShow();
  86. /**
  87. Refreshes given property on page.
  88. */
  89. virtual void RefreshProperty( wxPGProperty* p );
  90. /**
  91. Sets splitter position on page.
  92. @remarks
  93. Splitter position cannot exceed grid size, and therefore setting it
  94. during form creation may fail as initial grid size is often smaller than
  95. desired splitter position, especially when sizers are being used.
  96. */
  97. void SetSplitterPosition( int splitterPos, int col = 0 );
  98. };
  99. /**
  100. @class wxPropertyGridManager
  101. wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
  102. which can optionally have toolbar for mode and page selection, a help text
  103. box, and a header.
  104. wxPropertyGridManager inherits from wxPropertyGridInterface, and as such
  105. it has most property manipulation functions. However, only some of them affect
  106. properties on all pages (eg. GetPropertyByName() and ExpandAll()), while some
  107. (eg. Append()) only apply to the currently selected page.
  108. To operate explicitly on properties on specific page, use
  109. wxPropertyGridManager::GetPage() to obtain pointer to page's
  110. wxPropertyGridPage object.
  111. Visual methods, such as SetCellBackgroundColour() are only available in
  112. wxPropertyGrid. Use wxPropertyGridManager::GetGrid() to obtain pointer to it.
  113. Non-virtual iterators will not work in wxPropertyGridManager. Instead, you must
  114. acquire the internal grid (GetGrid()) or wxPropertyGridPage object (GetPage()).
  115. wxPropertyGridManager constructor has exact same format as wxPropertyGrid
  116. constructor, and basically accepts same extra window style flags (albeit also
  117. has some extra ones).
  118. Here's some example code for creating and populating a wxPropertyGridManager:
  119. @code
  120. wxPropertyGridManager* pgMan = new wxPropertyGridManager(this, PGID,
  121. wxDefaultPosition, wxDefaultSize,
  122. // These and other similar styles are automatically
  123. // passed to the embedded wxPropertyGrid.
  124. wxPG_BOLD_MODIFIED|wxPG_SPLITTER_AUTO_CENTER|
  125. // Include toolbar.
  126. wxPG_TOOLBAR |
  127. // Include description box.
  128. wxPG_DESCRIPTION |
  129. // Include compactor.
  130. wxPG_COMPACTOR |
  131. // Plus defaults.
  132. wxPGMAN_DEFAULT_STYLE
  133. );
  134. wxPropertyGridPage* page;
  135. page = pgMan->AddPage("First Page");
  136. page->Append( new wxPropertyCategory("Category A1") );
  137. page->Append( new wxIntProperty("Number",wxPG_LABEL,1) );
  138. page->Append( new wxColourProperty("Colour",wxPG_LABEL,*wxWHITE) );
  139. page = pgMan->AddPage("Second Page");
  140. page->Append( "Text",wxPG_LABEL,"(no text)" );
  141. page->Append( new wxFontProperty("Font",wxPG_LABEL) );
  142. // Display a header above the grid
  143. pgMan->ShowHeader();
  144. @endcode
  145. @section propgridmanager_window_styles_ Window Styles
  146. See @ref propgrid_window_styles.
  147. @section propgridmanager_event_handling Event Handling
  148. See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
  149. for more information.
  150. @library{wxpropgrid}
  151. @category{propgrid}
  152. */
  153. class wxPropertyGridManager : public wxPanel, public wxPropertyGridInterface
  154. {
  155. public:
  156. /**
  157. Creates new property page. Note that the first page is not created
  158. automatically.
  159. @param label
  160. A label for the page. This may be shown as a toolbar tooltip etc.
  161. @param bmp
  162. Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
  163. default image is used.
  164. @param pageObj
  165. wxPropertyGridPage instance. Manager will take ownership of this
  166. object. NULL indicates that a default page instance should be created.
  167. @return Returns pointer to created property grid page.
  168. @remarks If toolbar is used, it is highly recommended that the pages are
  169. added when the toolbar is not turned off using window style flag
  170. switching. Otherwise toolbar buttons might not be added properly.
  171. */
  172. wxPropertyGridPage* AddPage( const wxString& label = wxEmptyString,
  173. const wxBitmap& bmp = wxPG_NULL_BITMAP,
  174. wxPropertyGridPage* pageObj = NULL );
  175. /**
  176. Deletes all properties and all pages.
  177. */
  178. virtual void Clear();
  179. /**
  180. Deletes all properties on given page.
  181. */
  182. void ClearPage( int page );
  183. /**
  184. Forces updating the value of property from the editor control.
  185. @return Returns @true if value was actually updated.
  186. */
  187. bool CommitChangesFromEditor( wxUint32 flags = 0 );
  188. /**
  189. Two step creation. Whenever the control is created without any parameters,
  190. use Create to actually create it. Don't access the control's public methods
  191. before this is called.
  192. @see @ref propgrid_window_styles
  193. */
  194. bool Create( wxWindow *parent, wxWindowID id = wxID_ANY,
  195. const wxPoint& pos = wxDefaultPosition,
  196. const wxSize& size = wxDefaultSize,
  197. long style = wxPGMAN_DEFAULT_STYLE,
  198. const wxString& name = wxPropertyGridManagerNameStr );
  199. /**
  200. Enables or disables (shows/hides) categories according to parameter enable.
  201. @remarks
  202. Calling his may not properly update toolbar buttons.
  203. */
  204. bool EnableCategories( bool enable );
  205. /**
  206. Selects page, scrolls and/or expands items to ensure that the
  207. given item is visible.
  208. @return Returns @true if something was actually done.
  209. */
  210. bool EnsureVisible( wxPGPropArg id );
  211. /**
  212. Returns number of columns on given page. By the default,
  213. returns number of columns on current page.
  214. */
  215. int GetColumnCount( int page = -1 ) const;
  216. /**
  217. Returns height of the description text box.
  218. */
  219. int GetDescBoxHeight() const;
  220. /**
  221. Returns pointer to the contained wxPropertyGrid. This does not change
  222. after wxPropertyGridManager has been created, so you can safely obtain
  223. pointer once and use it for the entire lifetime of the manager
  224. instance.
  225. */
  226. wxPropertyGrid* GetGrid();
  227. /**
  228. Similar to GetIterator, but instead returns wxPGVIterator instance,
  229. which can be useful for forward-iterating through arbitrary property
  230. containers.
  231. */
  232. virtual wxPGVIterator GetVIterator( int flags ) const;
  233. /**
  234. Returns currently selected page.
  235. */
  236. wxPropertyGridPage* GetCurrentPage() const;
  237. /**
  238. Returns page object for given page index.
  239. */
  240. wxPropertyGridPage* GetPage( unsigned int ind ) const;
  241. /**
  242. Returns page object for given page name.
  243. */
  244. wxPropertyGridPage* GetPage( const wxString& name ) const;
  245. /**
  246. Returns index for a page name. If no match is found, wxNOT_FOUND is
  247. returned.
  248. */
  249. int GetPageByName( const wxString& name ) const;
  250. /**
  251. Returns number of managed pages.
  252. */
  253. size_t GetPageCount() const;
  254. /**
  255. Returns name of given page.
  256. */
  257. const wxString& GetPageName( int index ) const;
  258. /**
  259. Returns "root property" of the given page. It does not have name, etc.
  260. and it is not visible. It is only useful for accessing its children.
  261. */
  262. wxPGProperty* GetPageRoot( int index ) const;
  263. /** Returns index to currently selected page. */
  264. int GetSelectedPage() const;
  265. /** Alias for GetSelection(). */
  266. wxPGProperty* GetSelectedProperty() const;
  267. /** Shortcut for GetGrid()->GetSelection(). */
  268. wxPGProperty* GetSelection() const;
  269. /**
  270. Returns a pointer to the toolbar currently associated with the
  271. wxPropertyGridManager (if any).
  272. */
  273. wxToolBar* GetToolBar() const;
  274. /**
  275. Creates new property page. Note that the first page is not created
  276. automatically.
  277. @param index
  278. Add to this position. -1 will add as the last item.
  279. @param label
  280. A label for the page. This may be shown as a toolbar tooltip etc.
  281. @param bmp
  282. Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
  283. default image is used.
  284. @param pageObj
  285. wxPropertyGridPage instance. Manager will take ownership of this
  286. object. If NULL, default page object is constructed.
  287. @return Returns pointer to created page.
  288. */
  289. virtual wxPropertyGridPage* InsertPage( int index, const wxString& label,
  290. const wxBitmap& bmp = wxNullBitmap,
  291. wxPropertyGridPage* pageObj = NULL );
  292. /**
  293. Returns @true if any property on any page has been modified by the user.
  294. */
  295. bool IsAnyModified() const;
  296. /**
  297. Returns @true if updating is frozen (ie. Freeze() called but not yet Thaw() ).
  298. */
  299. bool IsFrozen() const;
  300. /**
  301. Returns @true if any property on given page has been modified by the user.
  302. */
  303. bool IsPageModified( size_t index ) const;
  304. /**
  305. Returns true if property is selected. Since selection is page
  306. based, this function checks every page in the manager.
  307. */
  308. virtual bool IsPropertySelected( wxPGPropArg id ) const;
  309. /**
  310. Removes a page.
  311. @return Returns @false if it was not possible to remove page in question.
  312. */
  313. virtual bool RemovePage( int page );
  314. /**
  315. Select and displays a given page.
  316. @param index
  317. Index of page being seleced. Can be -1 to select nothing.
  318. */
  319. void SelectPage( int index );
  320. /**
  321. Select and displays a given page (by label).
  322. */
  323. void SelectPage( const wxString& label );
  324. /** Select and displays a given page. */
  325. void SelectPage( wxPropertyGridPage* page );
  326. /**
  327. Select a property.
  328. @see wxPropertyGrid::SelectProperty(),
  329. wxPropertyGridInterface::ClearSelection()
  330. */
  331. bool SelectProperty( wxPGPropArg id, bool focus = false );
  332. /**
  333. Sets number of columns on given page (default is current page).
  334. @remarks If you use header, then you should always use this
  335. member function to set the column count, instead of
  336. ones present in wxPropertyGrid or wxPropertyGridPage.
  337. */
  338. void SetColumnCount( int colCount, int page = -1 );
  339. /**
  340. Sets a column title. Default title for column 0 is "Property",
  341. and "Value" for column 1.
  342. @remarks If header is not shown yet, then calling this
  343. member function will make it visible.
  344. */
  345. void SetColumnTitle( int idx, const wxString& title );
  346. /**
  347. Sets label and text in description box.
  348. */
  349. void SetDescription( const wxString& label, const wxString& content );
  350. /** Sets y coordinate of the description box splitter. */
  351. void SetDescBoxHeight( int ht, bool refresh = true );
  352. /**
  353. Moves splitter as left as possible, while still allowing all
  354. labels to be shown in full.
  355. @param subProps
  356. If @false, will still allow sub-properties (ie. properties which
  357. parent is not root or category) to be cropped.
  358. @param allPages
  359. If @true, takes labels on all pages into account.
  360. */
  361. void SetSplitterLeft( bool subProps = false, bool allPages = true );
  362. /** Moves splitter as left as possible on an individual page, while still allowing all
  363. labels to be shown in full.
  364. */
  365. void SetPageSplitterLeft(int page, bool subProps = false);
  366. /**
  367. Sets splitter position on individual page.
  368. @remarks If you use header, then you should always use this
  369. member function to set the splitter position, instead of
  370. ones present in wxPropertyGrid or wxPropertyGridPage.
  371. */
  372. void SetPageSplitterPosition( int page, int pos, int column = 0 );
  373. /**
  374. Sets splitter position for all pages.
  375. @remarks Splitter position cannot exceed grid size, and therefore
  376. setting it during form creation may fail as initial grid
  377. size is often smaller than desired splitter position,
  378. especially when sizers are being used.
  379. If you use header, then you should always use this
  380. member function to set the splitter position, instead of
  381. ones present in wxPropertyGrid or wxPropertyGridPage.
  382. */
  383. void SetSplitterPosition( int pos, int column = 0 );
  384. /**
  385. Show or hide the property grid header control. It is hidden
  386. by the default.
  387. @remarks Grid may look better if you use wxPG_NO_INTERNAL_BORDER
  388. window style when showing a header.
  389. */
  390. void ShowHeader(bool show = true);
  391. protected:
  392. //
  393. // Subclassing helpers
  394. //
  395. /**
  396. Creates property grid for the manager. Reimplement in derived class to
  397. use subclassed wxPropertyGrid. However, if you do this then you
  398. must also use the two-step construction (ie. default constructor and
  399. Create() instead of constructor with arguments) when creating the
  400. manager.
  401. */
  402. virtual wxPropertyGrid* CreatePropertyGrid() const;
  403. };