property.h 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: property.h
  3. // Purpose: interface of wxPGProperty
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxNullProperty ((wxPGProperty*)NULL)
  8. /**
  9. @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
  10. wxPGProperty::SetAttribute() and wxPropertyGridInterface::SetPropertyAttribute()
  11. accept one of these as attribute name argument.
  12. You can use strings instead of constants.
  13. However, some of these constants are redefined to use cached strings which
  14. may reduce your binary size by some amount.
  15. @{
  16. */
  17. /** Set default value for property.
  18. */
  19. #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
  20. /** Universal, int or double. Minimum value for numeric properties.
  21. */
  22. #define wxPG_ATTR_MIN wxS("Min")
  23. /** Universal, int or double. Maximum value for numeric properties.
  24. */
  25. #define wxPG_ATTR_MAX wxS("Max")
  26. /** Universal, string. When set, will be shown as text after the displayed
  27. text value. Alternatively, if third column is enabled, text will be shown
  28. there (for any type of property).
  29. */
  30. #define wxPG_ATTR_UNITS wxS("Units")
  31. /** When set, will be shown as 'greyed' text in property's value cell when
  32. the actual displayed value is blank.
  33. */
  34. #define wxPG_ATTR_HINT wxS("Hint")
  35. /**
  36. @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
  37. */
  38. #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
  39. /** Universal, wxArrayString. Set to enable auto-completion in any
  40. wxTextCtrl-based property editor.
  41. */
  42. #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
  43. /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
  44. Default value is False.
  45. When set to True, bool property will use check box instead of a
  46. combo box as its editor control. If you set this attribute
  47. for a wxFlagsProperty, it is automatically applied to child
  48. bool properties.
  49. */
  50. #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
  51. /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
  52. Default value is False.
  53. Set to True for the bool property to cycle value on double click
  54. (instead of showing the popup listbox). If you set this attribute
  55. for a wxFlagsProperty, it is automatically applied to child
  56. bool properties.
  57. */
  58. #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
  59. /** wxFloatProperty (and similar) specific, int, default -1. Sets the (max) precision
  60. used when floating point value is rendered as text. The default -1 means infinite
  61. precision.
  62. */
  63. #define wxPG_FLOAT_PRECISION wxS("Precision")
  64. /** The text will be echoed as asterisks (wxTE_PASSWORD will be passed to textctrl etc).
  65. */
  66. #define wxPG_STRING_PASSWORD wxS("Password")
  67. /** Define base used by a wxUIntProperty. Valid constants are
  68. wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
  69. (lowercase characters).
  70. */
  71. #define wxPG_UINT_BASE wxS("Base")
  72. /** Define prefix rendered to wxUIntProperty. Accepted constants
  73. wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
  74. <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
  75. numbers.
  76. */
  77. #define wxPG_UINT_PREFIX wxS("Prefix")
  78. /** wxFileProperty/wxImageFileProperty specific, wxChar*, default is detected/varies.
  79. Sets the wildcard used in the triggered wxFileDialog. Format is the
  80. same.
  81. */
  82. #define wxPG_FILE_WILDCARD wxS("Wildcard")
  83. /** wxFileProperty/wxImageFileProperty specific, int, default 1.
  84. When 0, only the file name is shown (i.e. drive and directory are hidden).
  85. */
  86. #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
  87. /** Specific to wxFileProperty and derived properties, wxString, default empty.
  88. If set, then the filename is shown relative to the given path string.
  89. */
  90. #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
  91. /** Specific to wxFileProperty and derived properties, wxString, default is empty.
  92. Sets the initial path of where to look for files.
  93. */
  94. #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
  95. /** Specific to wxFileProperty and derivatives, wxString, default is empty.
  96. Sets a specific title for the dir dialog.
  97. */
  98. #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
  99. /** Specific to wxFileProperty and derivatives, long, default is 0.
  100. Sets a specific wxFileDialog style for the file dialog, e.g. ::wxFD_SAVE.
  101. @since 2.9.4
  102. */
  103. #define wxPG_FILE_DIALOG_STYLE wxS("DialogStyle")
  104. /** Specific to wxDirProperty, wxString, default is empty.
  105. Sets a specific message for the dir dialog.
  106. */
  107. #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
  108. /**
  109. wxArrayStringProperty's string delimiter character. If this is a quotation
  110. mark or hyphen, then strings will be quoted instead (with given
  111. character).
  112. Default delimiter is quotation mark.
  113. */
  114. #define wxPG_ARRAY_DELIMITER wxS("Delimiter")
  115. /** Sets displayed date format for wxDateProperty.
  116. */
  117. #define wxPG_DATE_FORMAT wxS("DateFormat")
  118. /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
  119. is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE will enable
  120. better unspecified value support in the editor.
  121. */
  122. #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
  123. /** SpinCtrl editor, int or double. How much number changes when button is
  124. pressed (or up/down on keyboard).
  125. */
  126. #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
  127. /** SpinCtrl editor, bool. If @true, value wraps at Min/Max.
  128. */
  129. #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
  130. /** SpinCtrl editor, bool. If @true, value can also by changed by moving
  131. mouse when left mouse button is being pressed.
  132. */
  133. #define wxPG_ATTR_SPINCTRL_MOTIONSPIN wxS("MotionSpin")
  134. /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
  135. appear before list strings. If 2, user strings appear after list string.
  136. */
  137. #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
  138. /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
  139. colour from property's list of choices.
  140. */
  141. #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
  142. /**
  143. wxColourProperty and its kind: Set to True in order to support editing
  144. alpha colour component.
  145. */
  146. #define wxPG_COLOUR_HAS_ALPHA wxS("HasAlpha")
  147. /** @}
  148. */
  149. /** @section propgrid_propflags wxPGProperty Flags
  150. @{
  151. */
  152. enum wxPGPropertyFlags
  153. {
  154. /** Indicates bold font.
  155. */
  156. wxPG_PROP_MODIFIED = 0x0001,
  157. /** Disables ('greyed' text and editor does not activate) property.
  158. */
  159. wxPG_PROP_DISABLED = 0x0002,
  160. /** Hider button will hide this property.
  161. */
  162. wxPG_PROP_HIDDEN = 0x0004,
  163. /** This property has custom paint image just in front of its value.
  164. If property only draws custom images into a popup list, then this
  165. flag should not be set.
  166. */
  167. wxPG_PROP_CUSTOMIMAGE = 0x0008,
  168. /** Do not create text based editor for this property (but button-triggered
  169. dialog and choice are ok).
  170. */
  171. wxPG_PROP_NOEDITOR = 0x0010,
  172. /** Property is collapsed, ie. it's children are hidden.
  173. */
  174. wxPG_PROP_COLLAPSED = 0x0020,
  175. /**
  176. If property is selected, then indicates that validation failed for pending
  177. value.
  178. If property is not selected, then indicates that the actual property
  179. value has failed validation (NB: this behaviour is not currently supported,
  180. but may be used in the future).
  181. */
  182. wxPG_PROP_INVALID_VALUE = 0x0040,
  183. // 0x0080,
  184. /** Switched via SetWasModified(). Temporary flag - only used when
  185. setting/changing property value.
  186. */
  187. wxPG_PROP_WAS_MODIFIED = 0x0200,
  188. /**
  189. If set, then child properties (if any) are private, and should be
  190. "invisible" to the application.
  191. */
  192. wxPG_PROP_AGGREGATE = 0x0400,
  193. /** If set, then child properties (if any) are copies and should not
  194. be deleted in dtor.
  195. */
  196. wxPG_PROP_CHILDREN_ARE_COPIES = 0x0800,
  197. /**
  198. Classifies this item as a non-category.
  199. Used for faster item type identification.
  200. */
  201. wxPG_PROP_PROPERTY = 0x1000,
  202. /**
  203. Classifies this item as a category.
  204. Used for faster item type identification.
  205. */
  206. wxPG_PROP_CATEGORY = 0x2000,
  207. /** Classifies this item as a property that has children, but is not aggregate
  208. (ie children are not private).
  209. */
  210. wxPG_PROP_MISC_PARENT = 0x4000,
  211. /** Property is read-only. Editor is still created for wxTextCtrl-based
  212. property editors. For others, editor is not usually created because
  213. they do implement wxTE_READONLY style or equivalent.
  214. */
  215. wxPG_PROP_READONLY = 0x8000,
  216. //
  217. // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
  218. //
  219. /** Property's value is composed from values of child properties.
  220. @remarks
  221. This flag cannot be used with property iterators.
  222. */
  223. wxPG_PROP_COMPOSED_VALUE = 0x00010000,
  224. /** Common value of property is selectable in editor.
  225. @remarks
  226. This flag cannot be used with property iterators.
  227. */
  228. wxPG_PROP_USES_COMMON_VALUE = 0x00020000,
  229. /** Property can be set to unspecified value via editor.
  230. Currently, this applies to following properties:
  231. - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
  232. Clear the text field
  233. @remarks
  234. This flag cannot be used with property iterators.
  235. @see wxPGProperty::SetAutoUnspecified()
  236. */
  237. wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000,
  238. /** Indicates the bit useable by derived properties.
  239. */
  240. wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000,
  241. /** Indicates the bit useable by derived properties.
  242. */
  243. wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000,
  244. /** Indicates that the property is being deleted and should be ignored.
  245. */
  246. wxPG_PROP_BEING_DELETED = 0x00200000
  247. };
  248. /** Topmost flag.
  249. */
  250. #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
  251. /** Property with children must have one of these set, otherwise iterators
  252. will not work correctly.
  253. Code should automatically take care of this, however.
  254. */
  255. #define wxPG_PROP_PARENTAL_FLAGS \
  256. ((wxPGPropertyFlags)(wxPG_PROP_AGGREGATE | \
  257. wxPG_PROP_CATEGORY | \
  258. wxPG_PROP_MISC_PARENT))
  259. /** @}
  260. */
  261. /**
  262. @class wxPGProperty
  263. wxPGProperty is base class for all wxPropertyGrid properties. In
  264. sections below we cover few related topics.
  265. @li @ref pgproperty_properties
  266. @li @ref pgproperty_creating
  267. @section pgproperty_properties Supplied Ready-to-use Property Classes
  268. Here is a list and short description of supplied fully-functional
  269. property classes. They are located in either props.h or advprops.h.
  270. @li @ref wxArrayStringProperty
  271. @li @ref wxBoolProperty
  272. @li @ref wxColourProperty
  273. @li @ref wxCursorProperty
  274. @li @ref wxDateProperty
  275. @li @ref wxDirProperty
  276. @li @ref wxEditEnumProperty
  277. @li @ref wxEnumProperty
  278. @li @ref wxFileProperty
  279. @li @ref wxFlagsProperty
  280. @li @ref wxFloatProperty
  281. @li @ref wxFontProperty
  282. @li @ref wxImageFileProperty
  283. @li @ref wxIntProperty
  284. @li @ref wxLongStringProperty
  285. @li @ref wxMultiChoiceProperty
  286. @li @ref wxPropertyCategory
  287. @li @ref wxStringProperty
  288. @li @ref wxSystemColourProperty
  289. @li @ref wxUIntProperty
  290. @subsection wxPropertyCategory
  291. Not an actual property per se, but a header for a group of properties.
  292. Regardless inherits from wxPGProperty, and supports displaying 'labels'
  293. for columns other than the first one. Easiest way to set category's
  294. label for second column is to call wxPGProperty::SetValue() with string
  295. argument.
  296. @subsection wxStringProperty
  297. Simple string property. wxPG_STRING_PASSWORD attribute may be used
  298. to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
  299. wxPG_ATTR_AUTOCOMPLETE attribute may be used to enable auto-completion
  300. (use a wxArrayString value), and is also supported by any property that
  301. happens to use a wxTextCtrl-based editor.
  302. @remarks wxStringProperty has a special trait: if it has value of
  303. "<composed>", and also has child properties, then its displayed
  304. value becomes composition of child property values, similar as
  305. with wxFontProperty, for instance.
  306. @subsection wxIntProperty
  307. Like wxStringProperty, but converts text to a signed long integer.
  308. wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
  309. To safely convert variant to integer, use code like this:
  310. @code
  311. wxLongLong ll;
  312. ll << property->GetValue();
  313. // or
  314. wxLongLong ll = propertyGrid->GetPropertyValueAsLong(property);
  315. @endcode
  316. @subsection wxUIntProperty
  317. Like wxIntProperty, but displays value as unsigned int. To set
  318. the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
  319. To set the globally used base, manipulate wxPG_UINT_BASE int
  320. attribute. Regardless of current prefix, understands (hex) values starting
  321. with both "0x" and "$".
  322. Like wxIntProperty, wxUIntProperty seamlessly supports 64-bit unsigned
  323. integers (ie. wxULongLong). Same wxVariant safety rules apply.
  324. @subsection wxFloatProperty
  325. Like wxStringProperty, but converts text to a double-precision floating point.
  326. Default float-to-text precision is 6 decimals, but this can be changed
  327. by modifying wxPG_FLOAT_PRECISION attribute.
  328. Note that when displaying the value, sign is omitted if the resulting
  329. textual representation is effectively zero (for example, -0.0001 with
  330. precision of 3 will become 0.0 instead of -0.0). This behaviour is unlike
  331. what C standard library does, but should result in better end-user
  332. experience in almost all cases.
  333. @subsection wxBoolProperty
  334. Represents a boolean value. wxChoice is used as editor control, by the
  335. default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true in order to
  336. use check box instead.
  337. @subsection wxLongStringProperty
  338. Like wxStringProperty, but has a button that triggers a small text editor
  339. dialog. Note that in long string values, tabs are represented by "\t" and
  340. line break by "\n".
  341. To display custom dialog on button press, you can subclass
  342. wxLongStringProperty and implement OnButtonClick, like this:
  343. @code
  344. virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
  345. {
  346. wxSize dialogSize(...size of your dialog...);
  347. wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
  348. dialogSize)
  349. // Create dialog dlg at dlgPos. Use value as initial string
  350. // value.
  351. ...
  352. if ( dlg.ShowModal() == wxID_OK )
  353. {
  354. value = dlg.GetStringValue);
  355. return true;
  356. }
  357. return false;
  358. }
  359. @endcode
  360. Also, if you wish not to have line breaks and tabs translated to
  361. escape sequences, then do following in constructor of your subclass:
  362. @code
  363. m_flags |= wxPG_PROP_NO_ESCAPE;
  364. @endcode
  365. @subsection wxDirProperty
  366. Like wxLongStringProperty, but the button triggers dir selector instead.
  367. Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
  368. @subsection wxFileProperty
  369. Like wxLongStringProperty, but the button triggers file selector instead.
  370. Default wildcard is "All files..." but this can be changed by setting
  371. wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
  372. Attribute wxPG_FILE_SHOW_FULL_PATH can be set to @false in order to show
  373. only the filename, not the entire path.
  374. @subsection wxEnumProperty
  375. Represents a single selection from a list of choices -
  376. wxOwnerDrawnComboBox is used to edit the value.
  377. @subsection wxFlagsProperty
  378. Represents a bit set that fits in a long integer. wxBoolProperty sub-
  379. properties are created for editing individual bits. Textctrl is created to
  380. manually edit the flags as a text; a continuous sequence of spaces, commas
  381. and semicolons are considered as a flag id separator.
  382. <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
  383. you will need to use wxPGProperty::SetChoices() - otherwise they will not
  384. get updated properly.
  385. wxFlagsProperty supports the same attributes as wxBoolProperty.
  386. @subsection wxArrayStringProperty
  387. Allows editing of a list of strings in wxTextCtrl and in a separate
  388. dialog. Supports "Delimiter" attribute, which defaults to comma (',').
  389. @subsection wxDateProperty
  390. wxDateTime property. Default editor is DatePickerCtrl, although TextCtrl
  391. should work as well. wxPG_DATE_FORMAT attribute can be used to change
  392. string wxDateTime::Format uses (although default is recommended as it is
  393. locale-dependent), and wxPG_DATE_PICKER_STYLE allows changing window
  394. style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
  395. Using wxDP_ALLOWNONE will enable better unspecified value support.
  396. @subsection wxEditEnumProperty
  397. Represents a string that can be freely edited or selected from list of choices -
  398. custom combobox control is used to edit the value.
  399. @subsection wxMultiChoiceProperty
  400. Allows editing a multiple selection from a list of strings. This is
  401. property is pretty much built around concept of wxMultiChoiceDialog.
  402. It uses wxArrayString value.
  403. @subsection wxImageFileProperty
  404. Like wxFileProperty, but has thumbnail of the image in front of
  405. the filename and autogenerates wildcard from available image handlers.
  406. @subsection wxColourProperty
  407. <b>Useful alternate editor:</b> Choice.
  408. Represents wxColour. wxButton is used to trigger a colour picker dialog.
  409. There are various sub-classing opportunities with this class. See
  410. below in wxSystemColourProperty section for details.
  411. Setting "HasAlpha" attribute to @true for this property allows user to
  412. edit the alpha colour component.
  413. @subsection wxFontProperty
  414. Represents wxFont. Various sub-properties are used to edit individual
  415. subvalues.
  416. @subsection wxSystemColourProperty
  417. Represents wxColour and a system colour index. wxChoice is used to edit
  418. the value. Drop-down list has color images. Note that value type
  419. is wxColourPropertyValue instead of wxColour (which wxColourProperty
  420. uses).
  421. @code
  422. class wxColourPropertyValue : public wxObject
  423. {
  424. public:
  425. // An integer value relating to the colour, and which exact
  426. // meaning depends on the property with which it is used.
  427. //
  428. // For wxSystemColourProperty:
  429. // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
  430. // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
  431. wxUint32 m_type;
  432. // Resulting colour. Should be correct regardless of type.
  433. wxColour m_colour;
  434. };
  435. @endcode
  436. in wxSystemColourProperty, and its derived class wxColourProperty, there
  437. are various sub-classing features. To set a basic list of colour
  438. names, call wxPGProperty::SetChoices().
  439. @code
  440. // Override in derived class to customize how colours are translated
  441. // to strings.
  442. virtual wxString ColourToString( const wxColour& col, int index ) const;
  443. // Returns index of entry that triggers colour picker dialog
  444. // (default is last).
  445. virtual int GetCustomColourIndex() const;
  446. // Helper function to show the colour dialog
  447. bool QueryColourFromUser( wxVariant& variant ) const;
  448. // Returns colour for given choice.
  449. // Default function returns wxSystemSettings::GetColour(index).
  450. virtual wxColour GetColour( int index ) const;
  451. @endcode
  452. @subsection wxCursorProperty
  453. Represents a wxCursor. wxChoice is used to edit the value.
  454. Drop-down list has cursor images under some (wxMSW) platforms.
  455. @section pgproperty_creating Creating Custom Properties
  456. New properties can be created by subclassing wxPGProperty or one
  457. of the provided property classes, and (re)implementing necessary
  458. member functions. Below, each virtual member function has ample
  459. documentation about its purpose and any odd details which to keep
  460. in mind.
  461. Here is a very simple 'template' code:
  462. @code
  463. class MyProperty : public wxPGProperty
  464. {
  465. public:
  466. // Default constructor
  467. MyProperty() { }
  468. // All arguments of this ctor must have a default value -
  469. // use wxPG_LABEL for label and name
  470. MyProperty( const wxString& label = wxPG_LABEL,
  471. const wxString& name = wxPG_LABEL,
  472. const wxString& value = wxEmptyString )
  473. : wxPGProperty(label, name)
  474. {
  475. // m_value is wxVariant
  476. m_value = value;
  477. }
  478. virtual ~MyProperty() { }
  479. const wxPGEditor* DoGetEditorClass() const
  480. {
  481. // Determines editor used by property.
  482. // You can replace 'TextCtrl' below with any of these
  483. // builtin-in property editor identifiers: Choice, ComboBox,
  484. // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
  485. // DatePickerCtrl.
  486. return wxPGEditor_TextCtrl;
  487. }
  488. virtual wxString ValueToString( wxVariant& value,
  489. int argFlags ) const
  490. {
  491. // TODO: Convert given property value to a string
  492. }
  493. virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
  494. {
  495. // TODO: Adapt string to property value.
  496. }
  497. protected:
  498. };
  499. @endcode
  500. Since wxPGProperty derives from wxObject, you can use standard
  501. wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS macros. From the
  502. above example they were omitted for sake of simplicity, and besides,
  503. they are only really needed if you need to use wxRTTI with your
  504. property class.
  505. You can change the 'value type' of a property by simply assigning different
  506. type of variant with SetValue. <b>It is mandatory to implement
  507. wxVariantData class for all data types used as property values.</b>
  508. You can use macros declared in wxPropertyGrid headers. For instance:
  509. @code
  510. // In header file:
  511. // (If you need to have export declaration, use version of macros
  512. // with _EXPORTED postfix)
  513. WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
  514. // In sources file:
  515. WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
  516. // Or, if you don't have valid == operator:
  517. WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
  518. @endcode
  519. @library{wxpropgrid}
  520. @category{propgrid}
  521. */
  522. class wxPGProperty : public wxObject
  523. {
  524. public:
  525. typedef wxUint32 FlagType;
  526. /**
  527. Default constructor.
  528. */
  529. wxPGProperty();
  530. /**
  531. Constructor.
  532. Non-abstract property classes should have constructor of this style:
  533. @code
  534. MyProperty( const wxString& label, const wxString& name, const T& value )
  535. : wxPGProperty(label, name)
  536. {
  537. // Generally recommended way to set the initial value
  538. // (as it should work in pretty much 100% of cases).
  539. wxVariant variant;
  540. variant << value;
  541. SetValue(variant);
  542. // If has private child properties then create them here.
  543. // For example:
  544. // AddPrivateChild( new wxStringProperty("Subprop 1",
  545. // wxPG_LABEL,
  546. // value.GetSubProp1()));
  547. }
  548. @endcode
  549. */
  550. wxPGProperty( const wxString& label, const wxString& name );
  551. /**
  552. Virtual destructor. It is customary for derived properties to implement this.
  553. */
  554. virtual ~wxPGProperty();
  555. /**
  556. This virtual function is called after m_value has been set.
  557. @remarks
  558. - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
  559. will not be called.
  560. - m_value may be of any variant type. Typically properties internally support only
  561. one variant type, and as such OnSetValue() provides a good opportunity to convert
  562. supported values into internal type.
  563. - Default implementation does nothing.
  564. */
  565. virtual void OnSetValue();
  566. /**
  567. Override this to return something else than m_value as the value.
  568. */
  569. virtual wxVariant DoGetValue() const;
  570. /**
  571. Implement this function in derived class to check the value.
  572. Return @true if it is ok. Returning @false prevents property change events
  573. from occurring.
  574. @remarks
  575. - Default implementation always returns @true.
  576. */
  577. virtual bool ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const;
  578. /**
  579. Converts text into wxVariant value appropriate for this property.
  580. @param variant
  581. On function entry this is the old value (should not be wxNullVariant
  582. in normal cases). Translated value must be assigned back to it.
  583. @param text
  584. Text to be translated into variant.
  585. @param argFlags
  586. If wxPG_FULL_VALUE is set, returns complete, storable value instead
  587. of displayable one (they may be different).
  588. If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
  589. composite property string value (as generated by ValueToString()
  590. called with this same flag).
  591. @return Returns @true if resulting wxVariant value was different.
  592. @remarks Default implementation converts semicolon delimited tokens into
  593. child values. Only works for properties with children.
  594. You might want to take into account that m_value is Null variant
  595. if property value is unspecified (which is usually only case if
  596. you explicitly enabled that sort behaviour).
  597. */
  598. virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const;
  599. /**
  600. Converts integer (possibly a choice selection) into wxVariant value
  601. appropriate for this property.
  602. @param variant
  603. On function entry this is the old value (should not be wxNullVariant
  604. in normal cases). Translated value must be assigned back to it.
  605. @param number
  606. Integer to be translated into variant.
  607. @param argFlags
  608. If wxPG_FULL_VALUE is set, returns complete, storable value instead
  609. of displayable one.
  610. @return Returns @true if resulting wxVariant value was different.
  611. @remarks
  612. - If property is not supposed to use choice or spinctrl or other editor
  613. with int-based value, it is not necessary to implement this method.
  614. - Default implementation simply assign given int to m_value.
  615. - If property uses choice control, and displays a dialog on some choice
  616. items, then it is preferred to display that dialog in IntToValue
  617. instead of OnEvent.
  618. - You might want to take into account that m_value is Mull variant if
  619. property value is unspecified (which is usually only case if you
  620. explicitly enabled that sort behaviour).
  621. */
  622. virtual bool IntToValue( wxVariant& variant, int number, int argFlags = 0 ) const;
  623. /**
  624. Converts property value into a text representation.
  625. @param value
  626. Value to be converted.
  627. @param argFlags
  628. If 0 (default value), then displayed string is returned.
  629. If wxPG_FULL_VALUE is set, returns complete, storable string value
  630. instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
  631. string value that must be editable in textctrl.
  632. If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
  633. display as a part of string property's composite text representation.
  634. @remarks Default implementation calls GenerateComposedValue().
  635. */
  636. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  637. /**
  638. Converts string to a value, and if successful, calls SetValue() on it.
  639. Default behaviour is to do nothing.
  640. @param text
  641. String to get the value from.
  642. @param flags
  643. @todo docme
  644. @return @true if value was changed.
  645. */
  646. bool SetValueFromString( const wxString& text, int flags = 0 );
  647. /**
  648. Converts integer to a value, and if successful, calls SetValue() on it.
  649. Default behaviour is to do nothing.
  650. @param value
  651. Int to get the value from.
  652. @param flags
  653. If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
  654. @return @true if value was changed.
  655. */
  656. bool SetValueFromInt( long value, int flags = 0 );
  657. /**
  658. Returns size of the custom painted image in front of property. This method
  659. must be overridden to return non-default value if OnCustomPaint is to be
  660. called.
  661. @param item
  662. Normally -1, but can be an index to the property's list of items.
  663. @remarks
  664. - Default behaviour is to return wxSize(0,0), which means no image.
  665. - Default image width or height is indicated with dimension -1.
  666. - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
  667. */
  668. virtual wxSize OnMeasureImage( int item = -1 ) const;
  669. /**
  670. Events received by editor widgets are processed here. Note that editor class
  671. usually processes most events. Some, such as button press events of
  672. TextCtrlAndButton class, can be handled here. Also, if custom handling
  673. for regular events is desired, then that can also be done (for example,
  674. wxSystemColourProperty custom handles @c wxEVT_CHOICE
  675. to display colour picker dialog when 'custom' selection is made).
  676. If the event causes value to be changed, SetValueInEvent() should be called
  677. to set the new value.
  678. The parameter @a event is the associated wxEvent.
  679. @retval
  680. Should return @true if any changes in value should be reported.
  681. @remarks
  682. - If property uses choice control, and displays a dialog on some choice items,
  683. then it is preferred to display that dialog in IntToValue instead of OnEvent.
  684. */
  685. virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_primary, wxEvent& event );
  686. /**
  687. Called after value of a child property has been altered. Must return
  688. new value of the whole property (after any alterations warranted by
  689. child's new value).
  690. Note that this function is usually called at the time that value of
  691. this property, or given child property, is still pending for change,
  692. and as such, result of GetValue() or m_value should not be relied
  693. on.
  694. Sample pseudo-code implementation:
  695. @code
  696. wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
  697. int childIndex,
  698. wxVariant& childValue ) const
  699. {
  700. // Acquire reference to actual type of data stored in variant
  701. // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
  702. // were used to create the variant class).
  703. T& data = TFromVariant(thisValue);
  704. // Copy childValue into data.
  705. switch ( childIndex )
  706. {
  707. case 0:
  708. data.SetSubProp1( childvalue.GetLong() );
  709. break;
  710. case 1:
  711. data.SetSubProp2( childvalue.GetString() );
  712. break;
  713. ...
  714. }
  715. // Return altered data
  716. return data;
  717. }
  718. @endcode
  719. @param thisValue
  720. Value of this property. Changed value should be returned (in
  721. previous versions of wxPropertyGrid it was only necessary to
  722. write value back to this argument).
  723. @param childIndex
  724. Index of child changed (you can use Item(childIndex) to get
  725. child property).
  726. @param childValue
  727. (Pending) value of the child property.
  728. @return
  729. Modified value of the whole property.
  730. */
  731. virtual wxVariant ChildChanged( wxVariant& thisValue,
  732. int childIndex,
  733. wxVariant& childValue ) const;
  734. /**
  735. Returns pointer to an instance of used editor.
  736. */
  737. virtual const wxPGEditor* DoGetEditorClass() const;
  738. /**
  739. Returns pointer to the wxValidator that should be used
  740. with the editor of this property (@NULL for no validator).
  741. Setting validator explicitly via SetPropertyValidator
  742. will override this.
  743. In most situations, code like this should work well
  744. (macros are used to maintain one actual validator instance,
  745. so on the second call the function exits within the first
  746. macro):
  747. @code
  748. wxValidator* wxMyPropertyClass::DoGetValidator () const
  749. {
  750. WX_PG_DOGETVALIDATOR_ENTRY()
  751. wxMyValidator* validator = new wxMyValidator(...);
  752. ... prepare validator...
  753. WX_PG_DOGETVALIDATOR_EXIT(validator)
  754. }
  755. @endcode
  756. @remarks
  757. You can get common filename validator by returning
  758. wxFileProperty::GetClassValidator(). wxDirProperty,
  759. for example, uses it.
  760. */
  761. virtual wxValidator* DoGetValidator () const;
  762. /**
  763. Override to paint an image in front of the property value text or drop-down
  764. list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
  765. If property's OnMeasureImage() returns size that has height != 0 but less than
  766. row height ( < 0 has special meanings), wxPropertyGrid calls this method to
  767. draw a custom image in a limited area in front of the editor control or
  768. value text/graphics, and if control has drop-down list, then the image is
  769. drawn there as well (even in the case OnMeasureImage() returned higher height
  770. than row height).
  771. NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
  772. using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
  773. If rect.x is < 0, then this is a measure item call, which means that
  774. dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
  775. to the height of the image of item at index paintdata.m_choiceItem. This call
  776. may be done even as often as once every drop-down popup show.
  777. @param dc
  778. wxDC to paint on.
  779. @param rect
  780. Box reserved for custom graphics. Includes surrounding rectangle, if any.
  781. If x is < 0, then this is a measure item call (see above).
  782. @param paintdata
  783. wxPGPaintData structure with much useful data about painted item.
  784. @code
  785. struct wxPGPaintData
  786. {
  787. // wxPropertyGrid.
  788. const wxPropertyGrid* m_parent;
  789. // Normally -1, otherwise index to drop-down list item that has to be drawn.
  790. int m_choiceItem;
  791. // Set to drawn width in OnCustomPaint (optional).
  792. int m_drawnWidth;
  793. // In a measure item call, set this to the height of item at m_choiceItem index
  794. int m_drawnHeight;
  795. };
  796. @endcode
  797. @remarks
  798. - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
  799. must be set to the full width drawn in pixels.
  800. - Due to technical reasons, rect's height will be default even if custom height
  801. was reported during measure call.
  802. - Brush is guaranteed to be default background colour. It has been already used to
  803. clear the background of area being painted. It can be modified.
  804. - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
  805. drawing framing rectangle. It can be changed as well.
  806. @see ValueToString()
  807. */
  808. virtual void OnCustomPaint( wxDC& dc, const wxRect& rect, wxPGPaintData& paintdata );
  809. /**
  810. Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
  811. Default implementation returns editor's renderer for all columns.
  812. */
  813. virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
  814. /**
  815. Returns which choice is currently selected. Only applies to properties
  816. which have choices.
  817. Needs to reimplemented in derived class if property value does not
  818. map directly to a choice. Integer as index, bool, and string usually do.
  819. */
  820. virtual int GetChoiceSelection() const;
  821. /**
  822. Refresh values of child properties. Automatically called after value is set.
  823. */
  824. virtual void RefreshChildren();
  825. /**
  826. Reimplement this member function to add special handling for
  827. attributes of this property.
  828. @return Return @false to have the attribute automatically stored in
  829. m_attributes. Default implementation simply does that and
  830. nothing else.
  831. @remarks To actually set property attribute values from the
  832. application, use wxPGProperty::SetAttribute() instead.
  833. */
  834. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  835. /**
  836. Returns value of an attribute.
  837. Override if custom handling of attributes is needed.
  838. Default implementation simply return @NULL variant.
  839. */
  840. virtual wxVariant DoGetAttribute( const wxString& name ) const;
  841. /**
  842. Returns instance of a new wxPGEditorDialogAdapter instance, which is
  843. used when user presses the (optional) button next to the editor control;
  844. Default implementation returns @NULL (ie. no action is generated when
  845. button is pressed).
  846. */
  847. virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
  848. /**
  849. Called whenever validation has failed with given pending value.
  850. @remarks If you implement this in your custom property class, please
  851. remember to call the baser implementation as well, since they
  852. may use it to revert property into pre-change state.
  853. */
  854. virtual void OnValidationFailure( wxVariant& pendingValue );
  855. /**
  856. Append a new choice to property's list of choices.
  857. @param label
  858. Label for added choice.
  859. @param value
  860. Value for new choice. Do not specify if you wish this
  861. to equal choice index.
  862. @return
  863. Index to added choice.
  864. */
  865. int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE );
  866. /**
  867. Adds a private child property.
  868. @deprecated Use AddPrivateChild() instead.
  869. @see AddPrivateChild()
  870. */
  871. wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
  872. /**
  873. Adds a private child property. If you use this instead of
  874. wxPropertyGridInterface::Insert() or
  875. wxPropertyGridInterface::AppendIn(), then property's parental
  876. type will automatically be set up to wxPG_PROP_AGGREGATE. In other
  877. words, all properties of this property will become private.
  878. */
  879. void AddPrivateChild( wxPGProperty* prop );
  880. /**
  881. Adapts list variant into proper value using consecutive
  882. ChildChanged() calls.
  883. */
  884. void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
  885. /**
  886. Use this member function to add independent (ie. regular) children to
  887. a property.
  888. @return Appended childProperty.
  889. @remarks wxPropertyGrid is not automatically refreshed by this
  890. function.
  891. @see InsertChild(), AddPrivateChild()
  892. */
  893. wxPGProperty* AppendChild( wxPGProperty* childProperty );
  894. /**
  895. Determines, recursively, if all children are not unspecified.
  896. @param pendingList
  897. Assumes members in this wxVariant list as pending
  898. replacement values.
  899. */
  900. bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
  901. /**
  902. Returns @true if children of this property are component values (for instance,
  903. points size, face name, and is_underlined are component values of a font).
  904. */
  905. bool AreChildrenComponents() const;
  906. /**
  907. Sets or clears given property flag. Mainly for internal use.
  908. @remarks Setting a property flag never has any side-effect, and is
  909. intended almost exclusively for internal use. So, for
  910. example, if you want to disable a property, call
  911. Enable(false) instead of setting wxPG_PROP_DISABLED flag.
  912. @see HasFlag(), GetFlags()
  913. */
  914. void ChangeFlag( wxPGPropertyFlags flag, bool set );
  915. /**
  916. Deletes children of the property.
  917. */
  918. void DeleteChildren();
  919. /**
  920. Removes entry from property's wxPGChoices and editor control (if it is active).
  921. If selected item is deleted, then the value is set to unspecified.
  922. */
  923. void DeleteChoice( int index );
  924. /**
  925. Enables or disables the property. Disabled property usually appears
  926. as having grey text.
  927. @param enable
  928. If @false, property is disabled instead.
  929. @see wxPropertyGridInterface::EnableProperty()
  930. */
  931. void Enable( bool enable = true );
  932. /**
  933. Composes text from values of child properties.
  934. */
  935. wxString GenerateComposedValue() const;
  936. /**
  937. Returns property attribute value, null variant if not found.
  938. */
  939. wxVariant GetAttribute( const wxString& name ) const;
  940. /** Returns named attribute, as string, if found. Otherwise defVal is returned.
  941. */
  942. wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
  943. /** Returns named attribute, as long, if found. Otherwise defVal is returned.
  944. */
  945. long GetAttributeAsLong( const wxString& name, long defVal ) const;
  946. /** Returns named attribute, as double, if found. Otherwise defVal is returned.
  947. */
  948. double GetAttributeAsDouble( const wxString& name, double defVal ) const;
  949. /**
  950. Returns attributes as list wxVariant.
  951. */
  952. wxVariant GetAttributesAsList() const;
  953. /**
  954. Returns editor used for given column. @NULL for no editor.
  955. */
  956. const wxPGEditor* GetColumnEditor( int column ) const;
  957. /** Returns property's base name (ie. parent's name is not added in any case) */
  958. const wxString& GetBaseName() const;
  959. /**
  960. Returns wxPGCell of given column.
  961. @remarks const version of this member function returns 'default'
  962. wxPGCell object if the property itself didn't hold
  963. cell data.
  964. */
  965. const wxPGCell& GetCell( unsigned int column ) const;
  966. /**
  967. Returns wxPGCell of given column, creating one if necessary.
  968. */
  969. wxPGCell& GetCell( unsigned int column );
  970. /**
  971. Returns wxPGCell of given column, creating one if necessary.
  972. */
  973. wxPGCell& GetOrCreateCell( unsigned int column );
  974. /**
  975. Returns number of child properties.
  976. */
  977. unsigned int GetChildCount() const;
  978. /**
  979. Returns height of children, recursively, and
  980. by taking expanded/collapsed status into account.
  981. @param lh
  982. Line height. Pass result of GetGrid()->GetRowHeight() here.
  983. @param iMax
  984. Only used (internally) when finding property y-positions.
  985. */
  986. int GetChildrenHeight( int lh, int iMax = -1 ) const;
  987. /**
  988. Returns read-only reference to property's list of choices.
  989. */
  990. const wxPGChoices& GetChoices() const;
  991. /**
  992. Returns client data (void*) of a property.
  993. */
  994. void* GetClientData() const;
  995. /** Sets managed client object of a property.
  996. */
  997. wxClientData *GetClientObject() const;
  998. /**
  999. Returns property's default value. If property's value type is not
  1000. a built-in one, and "DefaultValue" attribute is not defined, then
  1001. this function usually returns Null variant.
  1002. */
  1003. wxVariant GetDefaultValue() const;
  1004. /** Returns property's displayed text.
  1005. */
  1006. wxString GetDisplayedString() const;
  1007. /**
  1008. Returns wxPGEditor that will be used and created when
  1009. property becomes selected. Returns more accurate value
  1010. than DoGetEditorClass().
  1011. */
  1012. const wxPGEditor* GetEditorClass() const;
  1013. /**
  1014. Returns property flags.
  1015. */
  1016. FlagType GetFlags() const;
  1017. /** Returns property grid where property lies. */
  1018. wxPropertyGrid* GetGrid() const;
  1019. /**
  1020. Returns owner wxPropertyGrid, but only if one is currently on a page
  1021. displaying this property.
  1022. */
  1023. wxPropertyGrid* GetGridIfDisplayed() const;
  1024. /**
  1025. Returns property's help or description text.
  1026. @see SetHelpString()
  1027. */
  1028. const wxString& GetHelpString() const;
  1029. /**
  1030. Returns position in parent's array.
  1031. */
  1032. unsigned int GetIndexInParent() const;
  1033. /** Returns property's label. */
  1034. const wxString& GetLabel() const;
  1035. /**
  1036. Returns last visible child property, recursively.
  1037. */
  1038. const wxPGProperty* GetLastVisibleSubItem() const;
  1039. /**
  1040. Returns highest level non-category, non-root parent. Useful when you
  1041. have nested properties with children.
  1042. @remarks If immediate parent is root or category, this will return the
  1043. property itself.
  1044. */
  1045. wxPGProperty* GetMainParent() const;
  1046. /** Returns maximum allowed length of property's text value.
  1047. */
  1048. int GetMaxLength() const;
  1049. /** Returns property's name with all (non-category, non-root) parents. */
  1050. wxString GetName() const;
  1051. /** Return parent of property */
  1052. wxPGProperty* GetParent() const;
  1053. /**
  1054. Returns (direct) child property with given name (or @NULL if not found).
  1055. */
  1056. wxPGProperty* GetPropertyByName( const wxString& name ) const;
  1057. /** Gets assignable version of property's validator. */
  1058. wxValidator* GetValidator() const;
  1059. /**
  1060. Returns property's value.
  1061. */
  1062. wxVariant GetValue() const;
  1063. /**
  1064. Returns bitmap that appears next to value text. Only returns non-@NULL
  1065. bitmap if one was set with SetValueImage().
  1066. */
  1067. wxBitmap* GetValueImage() const;
  1068. /** Returns text representation of property's value.
  1069. @param argFlags
  1070. If 0 (default value), then displayed string is returned.
  1071. If wxPG_FULL_VALUE is set, returns complete, storable string value
  1072. instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
  1073. string value that must be editable in textctrl. If
  1074. wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
  1075. display as a part of string property's composite text
  1076. representation.
  1077. @remarks In older versions, this function used to be overridden to convert
  1078. property's value into a string representation. This function is
  1079. now handled by ValueToString(), and overriding this function now
  1080. will result in run-time assertion failure.
  1081. */
  1082. virtual wxString GetValueAsString( int argFlags = 0 ) const;
  1083. /** Synonymous to GetValueAsString().
  1084. @deprecated Use GetValueAsString() instead.
  1085. @see GetValueAsString()
  1086. */
  1087. wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
  1088. /**
  1089. Returns value type used by this property.
  1090. */
  1091. wxString GetValueType() const;
  1092. /**
  1093. Returns coordinate to the top y of the property. Note that the
  1094. position of scrollbars is not taken into account.
  1095. */
  1096. int GetY() const;
  1097. /**
  1098. Returns non-zero if property has given flag set.
  1099. @see propgrid_propflags
  1100. */
  1101. FlagType HasFlag( wxPGPropertyFlags flag ) const;
  1102. /**
  1103. Returns @true if property has even one visible child.
  1104. */
  1105. bool HasVisibleChildren() const;
  1106. /**
  1107. Hides or reveals the property.
  1108. @param hide
  1109. @true for hide, @false for reveal.
  1110. @param flags
  1111. By default changes are applied recursively. Set this parameter wxPG_DONT_RECURSE to prevent this.
  1112. */
  1113. bool Hide( bool hide, int flags = wxPG_RECURSE );
  1114. /**
  1115. Returns index of given child property. wxNOT_FOUND if
  1116. given property is not child of this.
  1117. */
  1118. int Index( const wxPGProperty* p ) const;
  1119. /**
  1120. Use this member function to add independent (ie. regular) children to
  1121. a property.
  1122. @return Inserted childProperty.
  1123. @remarks wxPropertyGrid is not automatically refreshed by this
  1124. function.
  1125. @see AppendChild(), AddPrivateChild()
  1126. */
  1127. wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
  1128. /**
  1129. Inserts a new choice to property's list of choices.
  1130. @param label
  1131. Text for new choice
  1132. @param index
  1133. Insertion position. Use wxNOT_FOUND to append.
  1134. @param value
  1135. Value for new choice. Do not specify if you wish this
  1136. to equal choice index.
  1137. */
  1138. int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
  1139. /**
  1140. Returns @true if this property is actually a wxPropertyCategory.
  1141. */
  1142. bool IsCategory() const;
  1143. /**
  1144. Returns @true if property is enabled.
  1145. */
  1146. bool IsEnabled() const;
  1147. /**
  1148. Returns @true if property has visible children.
  1149. */
  1150. bool IsExpanded() const;
  1151. /**
  1152. Returns @true if this property is actually a wxRootProperty.
  1153. */
  1154. bool IsRoot() const;
  1155. /**
  1156. Returns @true if candidateParent is some parent of this property.
  1157. */
  1158. bool IsSomeParent( wxPGProperty* candidateParent ) const;
  1159. /**
  1160. Returns true if property has editable wxTextCtrl when selected.
  1161. @remarks Although disabled properties do not displayed editor, they still
  1162. return @true here as being disabled is considered a temporary
  1163. condition (unlike being read-only or having limited editing enabled).
  1164. */
  1165. bool IsTextEditable() const;
  1166. /**
  1167. Returns @true if property's value is considered unspecified. This
  1168. usually means that value is Null variant.
  1169. */
  1170. bool IsValueUnspecified() const;
  1171. /**
  1172. Returns true if all parents expanded.
  1173. */
  1174. bool IsVisible() const;
  1175. /**
  1176. Returns child property at index i.
  1177. */
  1178. wxPGProperty* Item( unsigned int i ) const;
  1179. /**
  1180. If property's editor is active, then update it's value.
  1181. */
  1182. void RefreshEditor();
  1183. /**
  1184. Sets an attribute for this property.
  1185. @param name
  1186. Text identifier of attribute. See @ref propgrid_property_attributes.
  1187. @param value
  1188. Value of attribute.
  1189. @remarks Setting attribute's value to Null variant will simply remove it
  1190. from property's set of attributes.
  1191. */
  1192. void SetAttribute( const wxString& name, wxVariant value );
  1193. /**
  1194. Set if user can change the property's value to unspecified by
  1195. modifying the value of the editor control (usually by clearing
  1196. it). Currently, this can work with following properties:
  1197. wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty.
  1198. @param enable
  1199. Whether to enable or disable this behaviour (it is disabled by
  1200. default).
  1201. */
  1202. void SetAutoUnspecified( bool enable = true );
  1203. /**
  1204. Sets property's background colour.
  1205. @param colour
  1206. Background colour to use.
  1207. @param flags
  1208. Default is wxPG_RECURSE which causes colour to be set recursively.
  1209. Omit this flag to only set colour for the property in question
  1210. and not any of its children.
  1211. */
  1212. void SetBackgroundColour( const wxColour& colour,
  1213. int flags = wxPG_RECURSE );
  1214. /**
  1215. Sets editor for a property.
  1216. @param editor
  1217. For builtin editors, use wxPGEditor_X, where X is builtin editor's
  1218. name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
  1219. For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
  1220. */
  1221. void SetEditor( const wxPGEditor* editor );
  1222. /**
  1223. Sets editor for a property, by editor name.
  1224. */
  1225. void SetEditor( const wxString& editorName );
  1226. /**
  1227. Sets cell information for given column.
  1228. */
  1229. void SetCell( int column, const wxPGCell& cell );
  1230. /**
  1231. Sets new set of choices for the property.
  1232. @remarks This operation deselects the property and clears its
  1233. value.
  1234. */
  1235. bool SetChoices( wxPGChoices& choices );
  1236. /**
  1237. Sets client data (void*) of a property.
  1238. @remarks This untyped client data has to be deleted manually.
  1239. */
  1240. void SetClientData( void* clientData );
  1241. /** Returns client object of a property.
  1242. */
  1243. void SetClientObject(wxClientData* clientObject);
  1244. /**
  1245. Sets selected choice and changes property value.
  1246. Tries to retain value type, although currently if it is not string,
  1247. then it is forced to integer.
  1248. */
  1249. void SetChoiceSelection( int newValue );
  1250. /** Set default value of a property. Synonymous to
  1251. @code
  1252. SetAttribute("DefaultValue", value);
  1253. @endcode
  1254. */
  1255. void SetDefaultValue( wxVariant& value );
  1256. /**
  1257. Sets or clears given property flag, recursively. This function is
  1258. primarily intended for internal use.
  1259. @see ChangeFlag()
  1260. */
  1261. void SetFlagRecursively( wxPGPropertyFlags flag, bool set );
  1262. /**
  1263. Sets property's help string, which is shown, for example, in
  1264. wxPropertyGridManager's description text box.
  1265. */
  1266. void SetHelpString( const wxString& helpString );
  1267. /**
  1268. Sets property's label.
  1269. @remarks Properties under same parent may have same labels. However,
  1270. property names must still remain unique.
  1271. */
  1272. void SetLabel( const wxString& label );
  1273. /**
  1274. Set max length of text in text editor.
  1275. */
  1276. bool SetMaxLength( int maxLen );
  1277. /**
  1278. Sets property's "is it modified?" flag. Affects children recursively.
  1279. */
  1280. void SetModifiedStatus( bool modified );
  1281. /**
  1282. Sets new (base) name for property.
  1283. */
  1284. void SetName( const wxString& newName );
  1285. /**
  1286. Changes what sort of parent this property is for its children.
  1287. @param flag
  1288. Use one of the following values: wxPG_PROP_MISC_PARENT (for generic
  1289. parents), wxPG_PROP_CATEGORY (for categories), or
  1290. wxPG_PROP_AGGREGATE (for derived property classes with private
  1291. children).
  1292. @remarks You generally do not need to call this function.
  1293. */
  1294. void SetParentalType( int flag );
  1295. /**
  1296. Sets property's text colour.
  1297. @param colour
  1298. Text colour to use.
  1299. @param flags
  1300. Default is wxPG_RECURSE which causes colour to be set recursively.
  1301. Omit this flag to only set colour for the property in question
  1302. and not any of its children.
  1303. */
  1304. void SetTextColour( const wxColour& colour,
  1305. int flags = wxPG_RECURSE );
  1306. /** Sets wxValidator for a property */
  1307. void SetValidator( const wxValidator& validator );
  1308. /**
  1309. Call this to set value of the property. Unlike methods in wxPropertyGrid,
  1310. this does not automatically update the display.
  1311. @remarks
  1312. Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
  1313. validation process and send property change event.
  1314. If you need to change property value in event, based on user input, use
  1315. SetValueInEvent() instead.
  1316. @param value
  1317. The value to set.
  1318. @param pList
  1319. Pointer to list variant that contains child values. Used to indicate
  1320. which children should be marked as modified. Usually you just use @NULL.
  1321. @param flags
  1322. wxPG_SETVAL_REFRESH_EDITOR is set by default, to refresh editor
  1323. and redraw properties.
  1324. */
  1325. void SetValue( wxVariant value, wxVariant* pList = NULL,
  1326. int flags = wxPG_SETVAL_REFRESH_EDITOR );
  1327. /**
  1328. Set wxBitmap in front of the value. This bitmap may be ignored
  1329. by custom cell renderers.
  1330. */
  1331. void SetValueImage( wxBitmap& bmp );
  1332. /**
  1333. Call this function in OnEvent(), OnButtonClick() etc. to change the
  1334. property value based on user input.
  1335. @remarks This method is const since it doesn't actually modify value, but posts
  1336. given variant as pending value, stored in wxPropertyGrid.
  1337. */
  1338. void SetValueInEvent( wxVariant value ) const;
  1339. /**
  1340. Sets property's value to unspecified (ie. Null variant).
  1341. */
  1342. void SetValueToUnspecified();
  1343. /**
  1344. Call with @false in OnSetValue() to cancel value changes after all
  1345. (ie. cancel @true returned by StringToValue() or IntToValue()).
  1346. */
  1347. void SetWasModified( bool set = true );
  1348. /**
  1349. Updates composed values of parent non-category properties, recursively.
  1350. Returns topmost property updated.
  1351. */
  1352. wxPGProperty* UpdateParentValues();
  1353. /**
  1354. Returns @true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
  1355. */
  1356. bool UsesAutoUnspecified() const;
  1357. protected:
  1358. /** Deletes all child properties. */
  1359. void Empty();
  1360. };
  1361. /**
  1362. @class wxPGCell
  1363. Base class for wxPropertyGrid cell information.
  1364. @library{wxpropgrid}
  1365. @category{propgrid}
  1366. */
  1367. class wxPGCell : public wxObject
  1368. {
  1369. public:
  1370. wxPGCell();
  1371. wxPGCell(const wxPGCell& other);
  1372. wxPGCell( const wxString& text,
  1373. const wxBitmap& bitmap = wxNullBitmap,
  1374. const wxColour& fgCol = wxNullColour,
  1375. const wxColour& bgCol = wxNullColour );
  1376. virtual ~wxPGCell();
  1377. const wxPGCellData* GetData() const;
  1378. /**
  1379. Returns @true if this cell has custom text stored within.
  1380. */
  1381. bool HasText() const;
  1382. /**
  1383. Merges valid data from srcCell into this.
  1384. */
  1385. void MergeFrom( const wxPGCell& srcCell );
  1386. void SetText( const wxString& text );
  1387. void SetBitmap( const wxBitmap& bitmap );
  1388. void SetFgCol( const wxColour& col );
  1389. /**
  1390. Sets font of the cell.
  1391. @remarks Because wxPropertyGrid does not support rows of
  1392. different height, it makes little sense to change
  1393. size of the font. Therefore it is recommended
  1394. to use return value of wxPropertyGrid::GetFont()
  1395. or wxPropertyGrid::GetCaptionFont() as a basis
  1396. for the font that, after modifications, is passed
  1397. to this member function.
  1398. */
  1399. void SetFont( const wxFont& font );
  1400. void SetBgCol( const wxColour& col );
  1401. const wxString& GetText() const;
  1402. const wxBitmap& GetBitmap() const;
  1403. const wxColour& GetFgCol() const;
  1404. /**
  1405. Returns font of the cell. If no specific font is set for this
  1406. cell, then the font will be invalid.
  1407. */
  1408. const wxFont& GetFont() const;
  1409. const wxColour& GetBgCol() const;
  1410. wxPGCell& operator=( const wxPGCell& other );
  1411. };
  1412. /**
  1413. @class wxPGChoices
  1414. Helper class for managing choices of wxPropertyGrid properties.
  1415. Each entry can have label, value, bitmap, text colour, and background
  1416. colour.
  1417. wxPGChoices uses reference counting, similar to other wxWidgets classes.
  1418. This means that assignment operator and copy constructor only copy the
  1419. reference and not the actual data. Use Copy() member function to create a
  1420. real copy.
  1421. @remarks If you do not specify value for entry, index is used.
  1422. @library{wxpropgrid}
  1423. @category{propgrid}
  1424. */
  1425. class wxPGChoices
  1426. {
  1427. public:
  1428. typedef long ValArrItem;
  1429. /**
  1430. Default constructor.
  1431. */
  1432. wxPGChoices();
  1433. /**
  1434. Copy constructor, uses reference counting. To create a real copy,
  1435. use Copy() member function instead.
  1436. */
  1437. wxPGChoices( const wxPGChoices& a );
  1438. /** Constructor. */
  1439. wxPGChoices( const wxChar** labels, const long* values = NULL );
  1440. /** Constructor. */
  1441. wxPGChoices( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() );
  1442. /** Constructor. */
  1443. wxPGChoices( wxPGChoicesData* data );
  1444. /** Destructor. */
  1445. ~wxPGChoices();
  1446. /**
  1447. Adds to current. If did not have own copies, creates them now. If was empty,
  1448. identical to set except that creates copies.
  1449. */
  1450. void Add( const wxChar** labels, const ValArrItem* values = NULL );
  1451. /** Version that works with wxArrayString and wxArrayInt. */
  1452. void Add( const wxArrayString& arr, const wxArrayInt& arrint );
  1453. /** Adds single item. */
  1454. wxPGChoiceEntry& Add( const wxString& label, int value = wxPG_INVALID_VALUE );
  1455. /** Adds a single item, with bitmap. */
  1456. wxPGChoiceEntry& Add( const wxString& label, const wxBitmap& bitmap,
  1457. int value = wxPG_INVALID_VALUE );
  1458. /** Adds a single item with full entry information. */
  1459. wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry );
  1460. /** Adds single item, sorted. */
  1461. wxPGChoiceEntry& AddAsSorted( const wxString& label, int value = wxPG_INVALID_VALUE );
  1462. /**
  1463. Assigns choices data, using reference counting. To create a real copy,
  1464. use Copy() member function instead.
  1465. */
  1466. void Assign( const wxPGChoices& a );
  1467. /**
  1468. Assigns data from another set of choices.
  1469. */
  1470. void AssignData( wxPGChoicesData* data );
  1471. /**
  1472. Deletes all items.
  1473. */
  1474. void Clear();
  1475. /**
  1476. Returns a real copy of the choices.
  1477. */
  1478. wxPGChoices Copy() const;
  1479. /**
  1480. Returns label of item.
  1481. */
  1482. const wxString& GetLabel( unsigned int ind ) const;
  1483. /**
  1484. Returns number of items.
  1485. */
  1486. unsigned int GetCount() const;
  1487. /**
  1488. Returns value of item;
  1489. */
  1490. int GetValue( unsigned int ind ) const;
  1491. /**
  1492. Returns array of values matching the given strings. Unmatching strings
  1493. result in wxPG_INVALID_VALUE entry in array.
  1494. */
  1495. wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
  1496. /**
  1497. Returns array of indices matching given strings. Unmatching strings
  1498. are added to 'unmatched', if not @NULL.
  1499. */
  1500. wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
  1501. wxArrayString* unmatched = NULL ) const;
  1502. /**
  1503. Returns index of item with given label.
  1504. */
  1505. int Index( const wxString& label ) const;
  1506. /**
  1507. Returns index of item with given value.
  1508. */
  1509. int Index( int val ) const;
  1510. /**
  1511. Inserts single item.
  1512. */
  1513. wxPGChoiceEntry& Insert( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
  1514. /**
  1515. Inserts a single item with full entry information.
  1516. */
  1517. wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
  1518. /**
  1519. Returns @false if this is a constant empty set of choices,
  1520. which should not be modified.
  1521. */
  1522. bool IsOk() const;
  1523. /**
  1524. Returns item at given index.
  1525. */
  1526. const wxPGChoiceEntry& Item( unsigned int i ) const;
  1527. /**
  1528. Returns item at given index.
  1529. */
  1530. wxPGChoiceEntry& Item( unsigned int i );
  1531. /**
  1532. Removes count items starting at position nIndex.
  1533. */
  1534. void RemoveAt(size_t nIndex, size_t count = 1);
  1535. /**
  1536. Sets contents from lists of strings and values.
  1537. */
  1538. void Set( const wxChar** labels, const long* values = NULL );
  1539. /**
  1540. Sets contents from lists of strings and values.
  1541. */
  1542. void Set( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() );
  1543. /**
  1544. Creates exclusive copy of current choices.
  1545. */
  1546. void AllocExclusive();
  1547. /**
  1548. Returns array of choice labels.
  1549. */
  1550. wxArrayString GetLabels() const;
  1551. void operator= (const wxPGChoices& a);
  1552. wxPGChoiceEntry& operator[](unsigned int i);
  1553. const wxPGChoiceEntry& operator[](unsigned int i) const;
  1554. };
  1555. // -----------------------------------------------------------------------