propgrid.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: propgrid.h
  3. // Purpose: interface of wxPropertyGrid
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @section propgrid_window_styles wxPropertyGrid Window Styles
  9. SetWindowStyleFlag method can be used to modify some of these at run-time.
  10. @{
  11. */
  12. enum wxPG_WINDOW_STYLES
  13. {
  14. /**
  15. This will cause Sort() automatically after an item is added.
  16. When inserting a lot of items in this mode, it may make sense to
  17. use Freeze() before operations and Thaw() afterwards to increase
  18. performance.
  19. */
  20. wxPG_AUTO_SORT = 0x00000010,
  21. /**
  22. Categories are not initially shown (even if added).
  23. IMPORTANT NOTE: If you do not plan to use categories, then this
  24. style will waste resources.
  25. This flag can also be changed using wxPropertyGrid::EnableCategories method.
  26. */
  27. wxPG_HIDE_CATEGORIES = 0x00000020,
  28. /**
  29. This style combines non-categoric mode and automatic sorting.
  30. */
  31. wxPG_ALPHABETIC_MODE = (wxPG_HIDE_CATEGORIES|wxPG_AUTO_SORT),
  32. /**
  33. Modified values are shown in bold font. Changing this requires Refresh()
  34. to show changes.
  35. */
  36. wxPG_BOLD_MODIFIED = 0x00000040,
  37. /**
  38. When wxPropertyGrid is resized, splitter moves to the center. This
  39. behaviour stops once the user manually moves the splitter.
  40. */
  41. wxPG_SPLITTER_AUTO_CENTER = 0x00000080,
  42. /**
  43. Display tool tips for cell text that cannot be shown completely. If
  44. wxUSE_TOOLTIPS is 0, then this doesn't have any effect.
  45. */
  46. wxPG_TOOLTIPS = 0x00000100,
  47. /**
  48. Disables margin and hides all expand/collapse buttons that would appear
  49. outside the margin (for sub-properties). Toggling this style automatically
  50. expands all collapsed items.
  51. */
  52. wxPG_HIDE_MARGIN = 0x00000200,
  53. /**
  54. This style prevents user from moving the splitter.
  55. */
  56. wxPG_STATIC_SPLITTER = 0x00000400,
  57. /**
  58. Combination of other styles that make it impossible for user to modify
  59. the layout.
  60. */
  61. wxPG_STATIC_LAYOUT = (wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER),
  62. /**
  63. Disables wxTextCtrl based editors for properties which
  64. can be edited in another way. Equals calling
  65. wxPropertyGrid::LimitPropertyEditing() for all added properties.
  66. */
  67. wxPG_LIMITED_EDITING = 0x00000800,
  68. /**
  69. wxPropertyGridManager only: Show tool bar for mode and page selection.
  70. */
  71. wxPG_TOOLBAR = 0x00001000,
  72. /**
  73. wxPropertyGridManager only: Show adjustable text box showing description
  74. or help text, if available, for currently selected property.
  75. */
  76. wxPG_DESCRIPTION = 0x00002000,
  77. /** wxPropertyGridManager only: don't show an internal border around the
  78. property grid. Recommended if you use a header.
  79. */
  80. wxPG_NO_INTERNAL_BORDER = 0x00004000
  81. };
  82. enum wxPG_EX_WINDOW_STYLES
  83. {
  84. /**
  85. NOTE: wxPG_EX_xxx are extra window styles and must be set using SetExtraStyle()
  86. member function.
  87. Speeds up switching to wxPG_HIDE_CATEGORIES mode. Initially, if
  88. wxPG_HIDE_CATEGORIES is not defined, the non-categorized data storage is not
  89. activated, and switching the mode first time becomes somewhat slower.
  90. wxPG_EX_INIT_NOCAT activates the non-categorized data storage right away.
  91. NOTE: If you do plan not switching to non-categoric mode, or if
  92. you don't plan to use categories at all, then using this style will result
  93. in waste of resources.
  94. */
  95. wxPG_EX_INIT_NOCAT = 0x00001000,
  96. /**
  97. Extended window style that sets wxPropertyGridManager tool bar to not
  98. use flat style.
  99. */
  100. wxPG_EX_NO_FLAT_TOOLBAR = 0x00002000,
  101. /**
  102. Shows alphabetic/categoric mode buttons from tool bar.
  103. */
  104. wxPG_EX_MODE_BUTTONS = 0x00008000,
  105. /**
  106. Show property help strings as tool tips instead as text on the status bar.
  107. You can set the help strings using SetPropertyHelpString member function.
  108. */
  109. wxPG_EX_HELP_AS_TOOLTIPS = 0x00010000,
  110. /**
  111. Allows relying on native double-buffering.
  112. */
  113. wxPG_EX_NATIVE_DOUBLE_BUFFERING = 0x00080000,
  114. /**
  115. Set this style to let user have ability to set values of properties to
  116. unspecified state. Same as setting wxPG_PROP_AUTO_UNSPECIFIED for
  117. all properties.
  118. */
  119. wxPG_EX_AUTO_UNSPECIFIED_VALUES = 0x00200000,
  120. /**
  121. If this style is used, built-in attributes (such as wxPG_FLOAT_PRECISION and
  122. wxPG_STRING_PASSWORD) are not stored into property's attribute storage (thus
  123. they are not readable).
  124. Note that this option is global, and applies to all wxPG property containers.
  125. */
  126. wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES = 0x00400000,
  127. /**
  128. Hides page selection buttons from tool bar.
  129. */
  130. wxPG_EX_HIDE_PAGE_BUTTONS = 0x01000000,
  131. /** Allows multiple properties to be selected by user (by pressing SHIFT
  132. when clicking on a property, or by dragging with left mouse button
  133. down).
  134. You can get array of selected properties with
  135. wxPropertyGridInterface::GetSelectedProperties(). In multiple selection
  136. mode wxPropertyGridInterface::GetSelection() returns
  137. property which has editor active (usually the first one
  138. selected). Other useful member functions are ClearSelection(),
  139. AddToSelection() and RemoveFromSelection().
  140. */
  141. wxPG_EX_MULTIPLE_SELECTION = 0x02000000,
  142. /**
  143. This enables top-level window tracking which allows wxPropertyGrid to
  144. notify the application of last-minute property value changes by user.
  145. This style is not enabled by default because it may cause crashes when
  146. wxPropertyGrid is used in with wxAUI or similar system.
  147. @remarks If you are not in fact using any system that may change
  148. wxPropertyGrid's top-level parent window on its own, then you
  149. are recommended to enable this style.
  150. */
  151. wxPG_EX_ENABLE_TLP_TRACKING = 0x04000000,
  152. /** Don't show divider above toolbar, on Windows.
  153. */
  154. wxPG_EX_NO_TOOLBAR_DIVIDER = 0x04000000,
  155. /** Show a separator below the toolbar.
  156. */
  157. wxPG_EX_TOOLBAR_SEPARATOR = 0x08000000
  158. };
  159. /** Combines various styles.
  160. */
  161. #define wxPG_DEFAULT_STYLE (0)
  162. /** Combines various styles.
  163. */
  164. #define wxPGMAN_DEFAULT_STYLE (0)
  165. /** @}
  166. */
  167. // -----------------------------------------------------------------------
  168. /**
  169. @section propgrid_vfbflags wxPropertyGrid Validation Failure behaviour Flags
  170. @{
  171. */
  172. enum wxPG_VALIDATION_FAILURE_BEHAVIOR_FLAGS
  173. {
  174. /**
  175. Prevents user from leaving property unless value is valid. If this
  176. behaviour flag is not used, then value change is instead cancelled.
  177. */
  178. wxPG_VFB_STAY_IN_PROPERTY = 0x01,
  179. /**
  180. Calls wxBell() on validation failure.
  181. */
  182. wxPG_VFB_BEEP = 0x02,
  183. /**
  184. Cell with invalid value will be marked (with red colour).
  185. */
  186. wxPG_VFB_MARK_CELL = 0x04,
  187. /**
  188. Display a text message explaining the situation.
  189. To customize the way the message is displayed, you need to
  190. reimplement wxPropertyGrid::DoShowPropertyError() in a
  191. derived class. Default behaviour is to display the text on
  192. the top-level frame's status bar, if present, and otherwise
  193. using wxMessageBox.
  194. */
  195. wxPG_VFB_SHOW_MESSAGE = 0x08,
  196. /**
  197. Similar to wxPG_VFB_SHOW_MESSAGE, except always displays the
  198. message using wxMessageBox.
  199. */
  200. wxPG_VFB_SHOW_MESSAGEBOX = 0x10,
  201. /**
  202. Similar to wxPG_VFB_SHOW_MESSAGE, except always displays the
  203. message on the status bar (when present - you can reimplement
  204. wxPropertyGrid::GetStatusBar() in a derived class to specify
  205. this yourself).
  206. */
  207. wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR = 0x20,
  208. /**
  209. Defaults.
  210. */
  211. wxPG_VFB_DEFAULT = wxPG_VFB_MARK_CELL |
  212. wxPG_VFB_SHOW_MESSAGEBOX,
  213. };
  214. /** @}
  215. */
  216. typedef wxByte wxPGVFBFlags;
  217. /**
  218. wxPGValidationInfo
  219. Used to convey validation information to and from functions that
  220. actually perform validation. Mostly used in custom property classes.
  221. */
  222. class wxPGValidationInfo
  223. {
  224. public:
  225. /**
  226. @return Returns failure behaviour which is a combination of
  227. @ref propgrid_vfbflags.
  228. */
  229. wxPGVFBFlags GetFailureBehavior();
  230. /**
  231. Returns current failure message.
  232. */
  233. const wxString& GetFailureMessage() const;
  234. /**
  235. Returns reference to pending value.
  236. */
  237. wxVariant& GetValue();
  238. /** Set validation failure behaviour
  239. @param failureBehavior
  240. Mixture of @ref propgrid_vfbflags.
  241. */
  242. void SetFailureBehavior(wxPGVFBFlags failureBehavior);
  243. /**
  244. Set current failure message.
  245. */
  246. void SetFailureMessage(const wxString& message);
  247. };
  248. // -----------------------------------------------------------------------
  249. /**
  250. @section propgrid_keyboard_actions wxPropertyGrid Action Identifiers
  251. These are used with wxPropertyGrid::AddActionTrigger() and
  252. wxPropertyGrid::ClearActionTriggers().
  253. @{
  254. */
  255. enum wxPG_KEYBOARD_ACTIONS
  256. {
  257. wxPG_ACTION_INVALID = 0,
  258. /** Select the next property. */
  259. wxPG_ACTION_NEXT_PROPERTY,
  260. /** Select the previous property. */
  261. wxPG_ACTION_PREV_PROPERTY,
  262. /** Expand the selected property, if it has child items. */
  263. wxPG_ACTION_EXPAND_PROPERTY,
  264. /** Collapse the selected property, if it has child items. */
  265. wxPG_ACTION_COLLAPSE_PROPERTY,
  266. /** Cancel and undo any editing done in the currently active property
  267. editor.
  268. */
  269. wxPG_ACTION_CANCEL_EDIT,
  270. /** Move focus to the editor control of the currently selected
  271. property.
  272. */
  273. wxPG_ACTION_EDIT,
  274. /** Causes editor's button (if any) to be pressed. */
  275. wxPG_ACTION_PRESS_BUTTON,
  276. wxPG_ACTION_MAX
  277. };
  278. /** @}
  279. */
  280. /** This callback function is used for sorting properties.
  281. Call wxPropertyGrid::SetSortFunction() to set it.
  282. Sort function should return a value greater than 0 if position of p1 is
  283. after p2. So, for instance, when comparing property names, you can use
  284. following implementation:
  285. @code
  286. int MyPropertySortFunction(wxPropertyGrid* propGrid,
  287. wxPGProperty* p1,
  288. wxPGProperty* p2)
  289. {
  290. return p1->GetBaseName().compare( p2->GetBaseName() );
  291. }
  292. @endcode
  293. */
  294. typedef int (*wxPGSortCallback)(wxPropertyGrid* propGrid,
  295. wxPGProperty* p1,
  296. wxPGProperty* p2);
  297. // -----------------------------------------------------------------------
  298. /**
  299. @class wxPropertyGrid
  300. wxPropertyGrid is a specialized grid for editing properties - in other
  301. words name = value pairs. List of ready-to-use property classes include
  302. strings, numbers, flag sets, fonts, colours and many others. It is possible,
  303. for example, to categorize properties, set up a complete tree-hierarchy,
  304. add more than two columns, and set arbitrary per-property attributes.
  305. Please note that most member functions are inherited and as such not
  306. documented on this page. This means you will probably also want to read
  307. wxPropertyGridInterface class reference.
  308. See also @ref overview_propgrid.
  309. @section propgrid_window_styles_ Window Styles
  310. See @ref propgrid_window_styles.
  311. @section propgrid_event_handling Event Handling
  312. To process input from a property grid control, use these event handler macros
  313. to direct input to member functions that take a wxPropertyGridEvent argument.
  314. @beginEventEmissionTable{wxPropertyGridEvent}
  315. @event{EVT_PG_SELECTED (id, func)}
  316. Respond to @c wxEVT_PG_SELECTED event, generated when a property selection
  317. has been changed, either by user action or by indirect program
  318. function. For instance, collapsing a parent property programmatically
  319. causes any selected child property to become unselected, and may
  320. therefore cause this event to be generated.
  321. @event{EVT_PG_CHANGED(id, func)}
  322. Respond to @c wxEVT_PG_CHANGED event, generated when property value
  323. has been changed by the user.
  324. @event{EVT_PG_CHANGING(id, func)}
  325. Respond to @c wxEVT_PG_CHANGING event, generated when property value
  326. is about to be changed by user. Use wxPropertyGridEvent::GetValue()
  327. to take a peek at the pending value, and wxPropertyGridEvent::Veto()
  328. to prevent change from taking place, if necessary.
  329. @event{EVT_PG_HIGHLIGHTED(id, func)}
  330. Respond to @c wxEVT_PG_HIGHLIGHTED event, which occurs when mouse
  331. moves over a property. Event's property is NULL if hovered area does
  332. not belong to any property.
  333. @event{EVT_PG_RIGHT_CLICK(id, func)}
  334. Respond to @c wxEVT_PG_RIGHT_CLICK event, which occurs when property is
  335. clicked on with right mouse button.
  336. @event{EVT_PG_DOUBLE_CLICK(id, func)}
  337. Respond to @c wxEVT_PG_DOUBLE_CLICK event, which occurs when property is
  338. double-clicked on with left mouse button.
  339. @event{EVT_PG_ITEM_COLLAPSED(id, func)}
  340. Respond to @c wxEVT_PG_ITEM_COLLAPSED event, generated when user collapses
  341. a property or category.
  342. @event{EVT_PG_ITEM_EXPANDED(id, func)}
  343. Respond to @c wxEVT_PG_ITEM_EXPANDED event, generated when user expands
  344. a property or category.
  345. @event{EVT_PG_LABEL_EDIT_BEGIN(id, func)}
  346. Respond to @c wxEVT_PG_LABEL_EDIT_BEGIN event, generated when user is
  347. about to begin editing a property label. You can veto this event to
  348. prevent the action.
  349. @event{EVT_PG_LABEL_EDIT_ENDING(id, func)}
  350. Respond to @c wxEVT_PG_LABEL_EDIT_ENDING event, generated when user is
  351. about to end editing of a property label. You can veto this event to
  352. prevent the action.
  353. @event{EVT_PG_COL_BEGIN_DRAG(id, func)}
  354. Respond to @c wxEVT_PG_COL_BEGIN_DRAG event, generated when user
  355. starts resizing a column - can be vetoed.
  356. @event{EVT_PG_COL_DRAGGING,(id, func)}
  357. Respond to @c wxEVT_PG_COL_DRAGGING, event, generated when a
  358. column resize by user is in progress. This event is also generated
  359. when user double-clicks the splitter in order to recenter
  360. it.
  361. @event{EVT_PG_COL_END_DRAG(id, func)}
  362. Respond to @c wxEVT_PG_COL_END_DRAG event, generated after column
  363. resize by user has finished.
  364. @endEventTable
  365. @remarks
  366. Use Freeze() and Thaw() respectively to disable and enable drawing.
  367. This will also delay sorting etc. miscellaneous calculations to the last
  368. possible moment.
  369. @library{wxpropgrid}
  370. @category{propgrid}
  371. @appearance{propertygrid}
  372. */
  373. class wxPropertyGrid : public wxControl,
  374. public wxScrollHelper,
  375. public wxPropertyGridInterface
  376. {
  377. public:
  378. /**
  379. Two step constructor.
  380. Call Create() when this constructor is called to build up the wxPropertyGrid
  381. */
  382. wxPropertyGrid();
  383. /**
  384. Constructor.
  385. The styles to be used are styles valid for the wxWindow.
  386. @see @ref propgrid_window_styles.
  387. */
  388. wxPropertyGrid( wxWindow *parent, wxWindowID id = wxID_ANY,
  389. const wxPoint& pos = wxDefaultPosition,
  390. const wxSize& size = wxDefaultSize,
  391. long style = wxPG_DEFAULT_STYLE,
  392. const wxString& name = wxPropertyGridNameStr );
  393. /** Destructor */
  394. virtual ~wxPropertyGrid();
  395. /**
  396. Adds given key combination to trigger given action.
  397. Here is a sample code to make Enter key press move focus to
  398. the next property.
  399. @code
  400. propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
  401. WXK_RETURN);
  402. propGrid->DedicateKey(WXK_RETURN);
  403. @endcode
  404. @param action
  405. Which action to trigger. See @ref propgrid_keyboard_actions.
  406. @param keycode
  407. Which keycode triggers the action.
  408. @param modifiers
  409. Which key event modifiers, in addition to keycode, are needed to
  410. trigger the action.
  411. */
  412. void AddActionTrigger( int action, int keycode, int modifiers = 0 );
  413. /**
  414. Adds given property into selection. If wxPG_EX_MULTIPLE_SELECTION
  415. extra style is not used, then this has same effect as
  416. calling SelectProperty().
  417. @remarks Multiple selection is not supported for categories. This
  418. means that if you have properties selected, you cannot
  419. add category to selection, and also if you have category
  420. selected, you cannot add other properties to selection.
  421. This member function will fail silently in these cases,
  422. even returning true.
  423. */
  424. bool AddToSelection( wxPGPropArg id );
  425. /**
  426. This static function enables or disables automatic use of
  427. wxGetTranslation() for following strings: wxEnumProperty list labels,
  428. wxFlagsProperty child property labels.
  429. Default is false.
  430. */
  431. static void AutoGetTranslation( bool enable );
  432. /**
  433. Creates label editor wxTextCtrl for given column, for property
  434. that is currently selected. When multiple selection is
  435. enabled, this applies to whatever property GetSelection()
  436. returns.
  437. @param colIndex
  438. Which column's label to edit. Note that you should not
  439. use value 1, which is reserved for property value
  440. column.
  441. @see EndLabelEdit(), MakeColumnEditable()
  442. */
  443. void BeginLabelEdit( unsigned int colIndex = 0 );
  444. /**
  445. Changes value of a property, as if from an editor. Use this instead of
  446. SetPropertyValue() if you need the value to run through validation
  447. process, and also send the property change event.
  448. @return Returns true if value was successfully changed.
  449. */
  450. bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
  451. /**
  452. Centers the splitter.
  453. @param enableAutoResizing
  454. If @true, automatic column resizing is enabled (only applicapple
  455. if window style wxPG_SPLITTER_AUTO_CENTER is used).
  456. */
  457. void CenterSplitter( bool enableAutoResizing = false );
  458. /**
  459. Deletes all properties.
  460. */
  461. virtual void Clear();
  462. /**
  463. Clears action triggers for given action.
  464. @param action
  465. Which action to trigger. @ref propgrid_keyboard_actions.
  466. */
  467. void ClearActionTriggers( int action );
  468. /**
  469. Forces updating the value of property from the editor control.
  470. Note that @c wxEVT_PG_CHANGING and @c wxEVT_PG_CHANGED are dispatched using
  471. ProcessEvent, meaning your event handlers will be called immediately.
  472. @return Returns @true if anything was changed.
  473. */
  474. virtual bool CommitChangesFromEditor( wxUint32 flags = 0 );
  475. /**
  476. Two step creation. Whenever the control is created without any
  477. parameters, use Create to actually create it. Don't access the control's
  478. public methods before this is called
  479. @see @ref propgrid_window_styles.
  480. */
  481. bool Create( wxWindow *parent, wxWindowID id = wxID_ANY,
  482. const wxPoint& pos = wxDefaultPosition,
  483. const wxSize& size = wxDefaultSize,
  484. long style = wxPG_DEFAULT_STYLE,
  485. const wxString& name = wxPropertyGridNameStr );
  486. /**
  487. Dedicates a specific keycode to wxPropertyGrid. This means that such
  488. key presses will not be redirected to editor controls.
  489. Using this function allows, for example, navigation between
  490. properties using arrow keys even when the focus is in the editor
  491. control.
  492. */
  493. void DedicateKey( int keycode );
  494. /**
  495. Enables or disables (shows/hides) categories according to parameter
  496. enable.
  497. @remarks This functions deselects selected property, if any. Validation
  498. failure option wxPG_VFB_STAY_IN_PROPERTY is not respected, ie.
  499. selection is cleared even if editor had invalid value.
  500. */
  501. bool EnableCategories( bool enable );
  502. /**
  503. Destroys label editor wxTextCtrl, if any.
  504. @param commit
  505. Use @true (default) to store edited label text in
  506. property cell data.
  507. @see BeginLabelEdit(), MakeColumnEditable()
  508. */
  509. void EndLabelEdit( bool commit = true );
  510. /**
  511. Scrolls and/or expands items to ensure that the given item is visible.
  512. @return Returns @true if something was actually done.
  513. */
  514. bool EnsureVisible( wxPGPropArg id );
  515. /**
  516. Reduces column sizes to minimum possible, while still retaining
  517. fully visible grid contents (labels, images).
  518. @return Minimum size for the grid to still display everything.
  519. @remarks Does not work well with wxPG_SPLITTER_AUTO_CENTER window style.
  520. This function only works properly if grid size prior to call was
  521. already fairly large.
  522. Note that you can also get calculated column widths by calling
  523. GetState->GetColumnWidth() immediately after this function
  524. returns.
  525. */
  526. wxSize FitColumns();
  527. /**
  528. Returns currently active label editor, NULL if none.
  529. */
  530. wxTextCtrl* GetLabelEditor() const;
  531. /**
  532. Returns wxWindow that the properties are painted on, and which should be
  533. used as the parent for editor controls.
  534. */
  535. wxWindow* GetPanel();
  536. /**
  537. Returns current category caption background colour.
  538. */
  539. wxColour GetCaptionBackgroundColour() const;
  540. /**
  541. Returns current category caption font.
  542. */
  543. wxFont& GetCaptionFont();
  544. /**
  545. Returns current category caption text colour.
  546. */
  547. wxColour GetCaptionForegroundColour() const;
  548. /**
  549. Returns current cell background colour.
  550. */
  551. wxColour GetCellBackgroundColour() const;
  552. /**
  553. Returns current cell text colour when disabled.
  554. */
  555. wxColour GetCellDisabledTextColour() const;
  556. /**
  557. Returns current cell text colour.
  558. */
  559. wxColour GetCellTextColour() const;
  560. /**
  561. Returns number of columns currently on grid.
  562. */
  563. unsigned int GetColumnCount() const;
  564. /**
  565. Returns colour of empty space below properties.
  566. */
  567. wxColour GetEmptySpaceColour() const;
  568. /**
  569. Returns height of highest characters of used font.
  570. */
  571. int GetFontHeight() const;
  572. /**
  573. Returns pointer to itself. Dummy function that enables same kind
  574. of code to use wxPropertyGrid and wxPropertyGridManager.
  575. */
  576. wxPropertyGrid* GetGrid();
  577. /**
  578. Returns rectangle of custom paint image.
  579. @param property
  580. Return image rectangle for this property.
  581. @param item
  582. Which choice of property to use (each choice may have
  583. different image).
  584. */
  585. wxRect GetImageRect( wxPGProperty* property, int item ) const;
  586. /**
  587. Returns size of the custom paint image in front of property.
  588. @param property
  589. Return image rectangle for this property.
  590. If this argument is NULL, then preferred size is returned.
  591. @param item
  592. Which choice of property to use (each choice may have
  593. different image).
  594. */
  595. wxSize GetImageSize( wxPGProperty* property = NULL, int item = -1 ) const;
  596. /**
  597. Returns last item which could be iterated using given flags.
  598. @param flags
  599. See @ref propgrid_iterator_flags.
  600. */
  601. wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT );
  602. /**
  603. Returns colour of lines between cells.
  604. */
  605. wxColour GetLineColour() const;
  606. /**
  607. Returns background colour of margin.
  608. */
  609. wxColour GetMarginColour() const;
  610. /**
  611. Returns "root property". It does not have name, etc. and it is not
  612. visible. It is only useful for accessing its children.
  613. */
  614. wxPGProperty* GetRoot() const;
  615. /**
  616. Returns height of a single grid row (in pixels).
  617. */
  618. int GetRowHeight() const;
  619. /**
  620. Returns currently selected property.
  621. */
  622. wxPGProperty* GetSelectedProperty() const;
  623. /**
  624. Returns currently selected property.
  625. */
  626. wxPGProperty* GetSelection() const;
  627. /**
  628. Returns current selection background colour.
  629. */
  630. wxColour GetSelectionBackgroundColour() const;
  631. /**
  632. Returns current selection text colour.
  633. */
  634. wxColour GetSelectionForegroundColour() const;
  635. /**
  636. Returns the property sort function (default is @NULL).
  637. @see SetSortFunction
  638. */
  639. wxPGSortCallback GetSortFunction() const;
  640. /**
  641. Returns current splitter x position.
  642. */
  643. int GetSplitterPosition( unsigned int splitterIndex = 0 ) const;
  644. /**
  645. Returns wxTextCtrl active in currently selected property, if any. Takes
  646. wxOwnerDrawnComboBox into account.
  647. */
  648. wxTextCtrl* GetEditorTextCtrl() const;
  649. /**
  650. Returns current appearance of unspecified value cells.
  651. @see SetUnspecifiedValueAppearance()
  652. */
  653. const wxPGCell& GetUnspecifiedValueAppearance() const;
  654. /**
  655. Returns (visual) text representation of the unspecified
  656. property value.
  657. @param argFlags For internal use only.
  658. */
  659. wxString GetUnspecifiedValueText( int argFlags = 0 ) const;
  660. /**
  661. Returns current vertical spacing.
  662. */
  663. int GetVerticalSpacing() const;
  664. /**
  665. Returns information about arbitrary position in the grid.
  666. @param pt
  667. Coordinates in the virtual grid space. You may need to use
  668. wxScrolled<T>::CalcScrolledPosition() for translating
  669. wxPropertyGrid client coordinates into something this member
  670. function can use.
  671. */
  672. wxPropertyGridHitTestResult HitTest( const wxPoint& pt ) const;
  673. /**
  674. Returns true if any property has been modified by the user.
  675. */
  676. bool IsAnyModified() const;
  677. /**
  678. Returns @true if a property editor control has focus.
  679. */
  680. bool IsEditorFocused() const;
  681. /**
  682. Returns true if updating is frozen (ie. Freeze() called but not
  683. yet Thaw() ).
  684. */
  685. bool IsFrozen() const;
  686. /**
  687. Makes given column editable by user.
  688. @param column
  689. The index of the column to make editable.
  690. @param editable
  691. Using @false here will disable column from being editable.
  692. @see BeginLabelEdit(), EndLabelEdit()
  693. */
  694. void MakeColumnEditable( unsigned int column, bool editable = true );
  695. /**
  696. It is recommended that you call this function any time your code causes
  697. wxPropertyGrid's top-level parent to change. wxPropertyGrid's OnIdle()
  698. handler should be able to detect most changes, but it is not perfect.
  699. @param newTLP
  700. New top-level parent that is about to be set. Old top-level parent
  701. window should still exist as the current one.
  702. @remarks This function is automatically called from wxPropertyGrid::
  703. Reparent() and wxPropertyGridManager::Reparent(). You only
  704. need to use it if you reparent wxPropertyGrid indirectly.
  705. */
  706. void OnTLPChanging( wxWindow* newTLP );
  707. /**
  708. Refreshes any active editor control.
  709. */
  710. void RefreshEditor();
  711. /**
  712. Redraws given property.
  713. */
  714. virtual void RefreshProperty( wxPGProperty* p );
  715. /** Forwards to DoRegisterEditorClass with empty name. */
  716. static wxPGEditor* RegisterEditorClass( wxPGEditor* editor,
  717. bool noDefCheck = false );
  718. /**
  719. Registers a new editor class.
  720. @return Returns pointer to the editor class instance that should be used.
  721. */
  722. static wxPGEditor* DoRegisterEditorClass( wxPGEditor* editor,
  723. const wxString& name,
  724. bool noDefCheck = false );
  725. /**
  726. Resets all colours to the original system values.
  727. */
  728. void ResetColours();
  729. /**
  730. Resets column sizes and splitter positions, based on proportions.
  731. @param enableAutoResizing
  732. If @true, automatic column resizing is enabled (only applicapple
  733. if window style wxPG_SPLITTER_AUTO_CENTER is used).
  734. @see wxPropertyGridInterface::SetColumnProportion()
  735. */
  736. void ResetColumnSizes( bool enableAutoResizing = false );
  737. /**
  738. Removes given property from selection. If property is not selected,
  739. an assertion failure will occur.
  740. */
  741. bool RemoveFromSelection( wxPGPropArg id );
  742. /**
  743. Selects a property. Editor widget is automatically created, but
  744. not focused unless focus is true.
  745. @param id
  746. Property to select (name or pointer).
  747. @param focus
  748. If @true, move keyboard focus to the created editor right away.
  749. @return returns @true if selection finished successfully. Usually only
  750. fails if current value in editor is not valid.
  751. @remarks In wxPropertyGrid 1.4, this member function used to generate
  752. @c wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
  753. does that.
  754. @remarks This clears any previous selection.
  755. @see wxPropertyGridInterface::ClearSelection()
  756. */
  757. bool SelectProperty( wxPGPropArg id, bool focus = false );
  758. /**
  759. Sets category caption background colour.
  760. */
  761. void SetCaptionBackgroundColour(const wxColour& col);
  762. /**
  763. Sets category caption text colour.
  764. */
  765. void SetCaptionTextColour(const wxColour& col);
  766. /**
  767. Sets default cell background colour - applies to property cells.
  768. Note that appearance of editor widgets may not be affected.
  769. */
  770. void SetCellBackgroundColour(const wxColour& col);
  771. /**
  772. Sets cell text colour for disabled properties.
  773. */
  774. void SetCellDisabledTextColour(const wxColour& col);
  775. /**
  776. Sets default cell text colour - applies to property name and value text.
  777. Note that appearance of editor widgets may not be affected.
  778. */
  779. void SetCellTextColour(const wxColour& col);
  780. /**
  781. Set number of columns (2 or more).
  782. */
  783. void SetColumnCount( int colCount );
  784. /**
  785. Sets the 'current' category - Append will add non-category properties
  786. under it.
  787. */
  788. void SetCurrentCategory( wxPGPropArg id );
  789. /**
  790. Sets colour of empty space below properties.
  791. */
  792. void SetEmptySpaceColour(const wxColour& col);
  793. /**
  794. Sets colour of lines between cells.
  795. */
  796. void SetLineColour(const wxColour& col);
  797. /**
  798. Sets background colour of margin.
  799. */
  800. void SetMarginColour(const wxColour& col);
  801. /**
  802. Set entire new selection from given list of properties.
  803. */
  804. void SetSelection( const wxArrayPGProperty& newSelection );
  805. /**
  806. Sets selection background colour - applies to selected property name
  807. background.
  808. */
  809. void SetSelectionBackgroundColour(const wxColour& col);
  810. /**
  811. Sets selection foreground colour - applies to selected property name text.
  812. */
  813. void SetSelectionTextColour(const wxColour& col);
  814. /**
  815. Sets the property sorting function.
  816. @param sortFunction
  817. The sorting function to be used. It should return a value greater
  818. than 0 if position of p1 is after p2. So, for instance, when
  819. comparing property names, you can use following implementation:
  820. @code
  821. int MyPropertySortFunction(wxPropertyGrid* propGrid,
  822. wxPGProperty* p1,
  823. wxPGProperty* p2)
  824. {
  825. return p1->GetBaseName().compare( p2->GetBaseName() );
  826. }
  827. @endcode
  828. @remarks
  829. Default property sort function sorts properties by their labels
  830. (case-insensitively).
  831. @see GetSortFunction, wxPropertyGridInterface::Sort,
  832. wxPropertyGridInterface::SortChildren
  833. */
  834. void SetSortFunction( wxPGSortCallback sortFunction );
  835. /**
  836. Sets x coordinate of the splitter.
  837. @remarks Splitter position cannot exceed grid size, and therefore setting
  838. it during form creation may fail as initial grid size is often
  839. smaller than desired splitter position, especially when sizers
  840. are being used.
  841. */
  842. void SetSplitterPosition( int newxpos, int col = 0 );
  843. /**
  844. Moves splitter as left as possible, while still allowing all
  845. labels to be shown in full.
  846. @param privateChildrenToo
  847. If @false, will still allow private children to be cropped.
  848. */
  849. void SetSplitterLeft( bool privateChildrenToo = false );
  850. /**
  851. Sets appearance of value cells representing an unspecified property
  852. value. Default appearance is blank.
  853. @remarks If you set the unspecified value to have any
  854. textual representation, then that will override
  855. "InlineHelp" attribute.
  856. @see wxPGProperty::SetValueToUnspecified(),
  857. wxPGProperty::IsValueUnspecified()
  858. */
  859. void SetUnspecifiedValueAppearance( const wxPGCell& cell );
  860. /**
  861. Sets vertical spacing. Can be 1, 2, or 3 - a value relative to font
  862. height. Value of 2 should be default on most platforms.
  863. */
  864. void SetVerticalSpacing( int vspacing );
  865. /**
  866. @name wxPropertyGrid customization
  867. Reimplement these member functions in derived class for better
  868. control over wxPropertyGrid behaviour.
  869. */
  870. //@{
  871. /**
  872. Override in derived class to display error messages in custom manner
  873. (these message usually only result from validation failure).
  874. @remarks If you implement this, then you also need to implement
  875. DoHidePropertyError() - possibly to do nothing, if error
  876. does not need hiding (e.g. it was logged or shown in a
  877. message box).
  878. @see DoHidePropertyError()
  879. */
  880. virtual void DoShowPropertyError( wxPGProperty* property,
  881. const wxString& msg );
  882. /**
  883. Override in derived class to hide an error displayed by
  884. DoShowPropertyError().
  885. @see DoShowPropertyError()
  886. */
  887. virtual void DoHidePropertyError( wxPGProperty* property );
  888. /**
  889. Return wxStatusBar that is used by this wxPropertyGrid. You can
  890. reimplement this member function in derived class to override
  891. the default behaviour of using the top-level wxFrame's status
  892. bar, if any.
  893. */
  894. virtual wxStatusBar* GetStatusBar();
  895. //@}
  896. /**
  897. @name Property development functions
  898. These member functions are usually only called when creating custom
  899. user properties.
  900. */
  901. //@{
  902. /**
  903. Call when editor widget's contents is modified. For example, this is
  904. called when changes text in wxTextCtrl (used in wxStringProperty and
  905. wxIntProperty).
  906. @remarks This function should only be called by custom properties.
  907. @see wxPGProperty::OnEvent()
  908. */
  909. void EditorsValueWasModified();
  910. /**
  911. Reverse of EditorsValueWasModified().
  912. @remarks This function should only be called by custom properties.
  913. */
  914. void EditorsValueWasNotModified();
  915. /**
  916. Returns most up-to-date value of selected property. This will return
  917. value different from GetSelectedProperty()->GetValue() only when text
  918. editor is activate and string edited by user represents valid,
  919. uncommitted property value.
  920. */
  921. wxVariant GetUncommittedPropertyValue();
  922. /**
  923. Returns true if editor's value was marked modified.
  924. */
  925. bool IsEditorsValueModified() const;
  926. /**
  927. Shows an brief error message that is related to a property.
  928. */
  929. void ShowPropertyError( wxPGPropArg id, const wxString& msg );
  930. /**
  931. You can use this member function, for instance, to detect in
  932. wxPGProperty::OnEvent() if wxPGProperty::SetValueInEvent() was
  933. already called in wxPGEditor::OnEvent(). It really only detects
  934. if was value was changed using wxPGProperty::SetValueInEvent(), which
  935. is usually used when a 'picker' dialog is displayed. If value was
  936. written by "normal means" in wxPGProperty::StringToValue() or
  937. IntToValue(), then this function will return false (on the other hand,
  938. wxPGProperty::OnEvent() is not even called in those cases).
  939. */
  940. bool WasValueChangedInEvent() const;
  941. //@}
  942. };
  943. /**
  944. @class wxPropertyGridEvent
  945. A property grid event holds information about events associated with
  946. wxPropertyGrid objects.
  947. @library{wxpropgrid}
  948. @category{propgrid}
  949. */
  950. class wxPropertyGridEvent : public wxCommandEvent
  951. {
  952. public:
  953. /** Constructor. */
  954. wxPropertyGridEvent(wxEventType commandType=0, int id=0);
  955. /** Copy constructor. */
  956. wxPropertyGridEvent(const wxPropertyGridEvent& event);
  957. /** Destructor. */
  958. ~wxPropertyGridEvent();
  959. /**
  960. Returns true if you can veto the action that the event is signaling.
  961. */
  962. bool CanVeto() const;
  963. /**
  964. Returns the column index associated with this event.
  965. For the column dragging events, it is the column to the left
  966. of the splitter being dragged
  967. */
  968. unsigned int GetColumn() const;
  969. /**
  970. Returns highest level non-category, non-root parent of property for
  971. which event occurred. Useful when you have nested properties with
  972. children.
  973. @remarks If immediate parent is root or category, this will return the
  974. property itself.
  975. */
  976. wxPGProperty* GetMainParent() const;
  977. /**
  978. Returns property associated with this event.
  979. @remarks You should assume that this property can always be NULL.
  980. For instance, @c wxEVT_PG_SELECTED is emitted not only when
  981. a new property is selected, but also when selection is
  982. cleared by user activity.
  983. */
  984. wxPGProperty* GetProperty() const;
  985. /**
  986. Returns current validation failure flags.
  987. */
  988. wxPGVFBFlags GetValidationFailureBehavior() const;
  989. /**
  990. Returns name of the associated property.
  991. @remarks Property name is stored in event, so it remains
  992. accessible even after the associated property or
  993. the property grid has been deleted.
  994. */
  995. wxString GetPropertyName() const;
  996. /**
  997. Returns value of the associated property. Works for all event
  998. types, but for @c wxEVT_PG_CHANGING this member function returns
  999. the value that is pending, so you can call Veto() if the
  1000. value is not satisfactory.
  1001. @remarks Property value is stored in event, so it remains
  1002. accessible even after the associated property or
  1003. the property grid has been deleted.
  1004. */
  1005. wxVariant GetPropertyValue() const
  1006. /**
  1007. @see GetPropertyValue()
  1008. */
  1009. wxVariant GetValue() const;
  1010. /**
  1011. Set if event can be vetoed.
  1012. */
  1013. void SetCanVeto( bool canVeto );
  1014. /** Changes the property associated with this event. */
  1015. void SetProperty( wxPGProperty* p );
  1016. /**
  1017. Set override validation failure behaviour. Only effective if Veto() was
  1018. also called, and only allowed if event type is @c wxEVT_PG_CHANGING.
  1019. */
  1020. void SetValidationFailureBehavior( wxPGVFBFlags flags );
  1021. /**
  1022. Sets custom failure message for this time only. Only applies if
  1023. wxPG_VFB_SHOW_MESSAGE is set in validation failure flags.
  1024. */
  1025. void SetValidationFailureMessage( const wxString& message );
  1026. /**
  1027. Call this from your event handler to veto action that the event is
  1028. signaling. You can only veto a shutdown if wxPropertyGridEvent::CanVeto()
  1029. returns true.
  1030. @remarks Currently only @c wxEVT_PG_CHANGING supports vetoing.
  1031. */
  1032. void Veto( bool veto = true );
  1033. /**
  1034. Returns @true if event was vetoed.
  1035. */
  1036. bool WasVetoed() const;
  1037. };