property.h 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/propgrid/property.h
  3. // Purpose: wxPGProperty and related support classes
  4. // Author: Jaakko Salli
  5. // Modified by:
  6. // Created: 2008-08-23
  7. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_PROPGRID_PROPERTY_H_
  11. #define _WX_PROPGRID_PROPERTY_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_PROPGRID
  14. #include "wx/propgrid/propgriddefs.h"
  15. // -----------------------------------------------------------------------
  16. #define wxNullProperty ((wxPGProperty*)NULL)
  17. /** @class wxPGPaintData
  18. Contains information relayed to property's OnCustomPaint.
  19. */
  20. struct wxPGPaintData
  21. {
  22. /** wxPropertyGrid. */
  23. const wxPropertyGrid* m_parent;
  24. /**
  25. Normally -1, otherwise index to drop-down list item that has to be
  26. drawn.
  27. */
  28. int m_choiceItem;
  29. /** Set to drawn width in OnCustomPaint (optional). */
  30. int m_drawnWidth;
  31. /**
  32. In a measure item call, set this to the height of item at m_choiceItem
  33. index.
  34. */
  35. int m_drawnHeight;
  36. };
  37. // space between vertical sides of a custom image
  38. #define wxPG_CUSTOM_IMAGE_SPACINGY 1
  39. // space between caption and selection rectangle,
  40. #define wxPG_CAPRECTXMARGIN 2
  41. // horizontally and vertically
  42. #define wxPG_CAPRECTYMARGIN 1
  43. /** @class wxPGCellRenderer
  44. Base class for wxPropertyGrid cell renderers.
  45. */
  46. class WXDLLIMPEXP_PROPGRID wxPGCellRenderer : public wxObjectRefData
  47. {
  48. public:
  49. wxPGCellRenderer()
  50. : wxObjectRefData() { }
  51. virtual ~wxPGCellRenderer() { }
  52. // Render flags
  53. enum
  54. {
  55. // We are painting selected item
  56. Selected = 0x00010000,
  57. // We are painting item in choice popup
  58. ChoicePopup = 0x00020000,
  59. // We are rendering wxOwnerDrawnComboBox control
  60. // (or other owner drawn control, but that is only
  61. // officially supported one ATM).
  62. Control = 0x00040000,
  63. // We are painting a disable property
  64. Disabled = 0x00080000,
  65. // We are painting selected, disabled, or similar
  66. // item that dictates fore- and background colours,
  67. // overriding any cell values.
  68. DontUseCellFgCol = 0x00100000,
  69. DontUseCellBgCol = 0x00200000,
  70. DontUseCellColours = DontUseCellFgCol |
  71. DontUseCellBgCol
  72. };
  73. /**
  74. Returns @true if rendered something in the foreground (text or
  75. bitmap.
  76. */
  77. virtual bool Render( wxDC& dc,
  78. const wxRect& rect,
  79. const wxPropertyGrid* propertyGrid,
  80. wxPGProperty* property,
  81. int column,
  82. int item,
  83. int flags ) const = 0;
  84. /** Returns size of the image in front of the editable area.
  85. @remarks
  86. If property is NULL, then this call is for a custom value. In that case
  87. the item is index to wxPropertyGrid's custom values.
  88. */
  89. virtual wxSize GetImageSize( const wxPGProperty* property,
  90. int column,
  91. int item ) const;
  92. /** Paints property category selection rectangle.
  93. */
  94. virtual void DrawCaptionSelectionRect( wxDC& dc,
  95. int x, int y,
  96. int w, int h ) const;
  97. /** Utility to draw vertically centered text.
  98. */
  99. void DrawText( wxDC& dc,
  100. const wxRect& rect,
  101. int imageWidth,
  102. const wxString& text ) const;
  103. /**
  104. Utility to draw editor's value, or vertically aligned text if editor is
  105. NULL.
  106. */
  107. void DrawEditorValue( wxDC& dc, const wxRect& rect,
  108. int xOffset, const wxString& text,
  109. wxPGProperty* property,
  110. const wxPGEditor* editor ) const;
  111. /** Utility to render cell bitmap and set text colour plus bg brush
  112. colour.
  113. @return Returns image width, which, for instance, can be passed to
  114. DrawText.
  115. */
  116. int PreDrawCell( wxDC& dc,
  117. const wxRect& rect,
  118. const wxPGCell& cell,
  119. int flags ) const;
  120. /**
  121. Utility to be called after drawing is done, to revert whatever
  122. changes PreDrawCell() did.
  123. @param flags
  124. Same as those passed to PreDrawCell().
  125. */
  126. void PostDrawCell( wxDC& dc,
  127. const wxPropertyGrid* propGrid,
  128. const wxPGCell& cell,
  129. int flags ) const;
  130. };
  131. /**
  132. @class wxPGDefaultRenderer
  133. Default cell renderer, that can handles the common
  134. scenarios.
  135. */
  136. class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
  137. {
  138. public:
  139. virtual bool Render( wxDC& dc,
  140. const wxRect& rect,
  141. const wxPropertyGrid* propertyGrid,
  142. wxPGProperty* property,
  143. int column,
  144. int item,
  145. int flags ) const;
  146. virtual wxSize GetImageSize( const wxPGProperty* property,
  147. int column,
  148. int item ) const;
  149. protected:
  150. };
  151. class WXDLLIMPEXP_PROPGRID wxPGCellData : public wxObjectRefData
  152. {
  153. friend class wxPGCell;
  154. public:
  155. wxPGCellData();
  156. void SetText( const wxString& text )
  157. {
  158. m_text = text;
  159. m_hasValidText = true;
  160. }
  161. void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
  162. void SetFgCol( const wxColour& col ) { m_fgCol = col; }
  163. void SetBgCol( const wxColour& col ) { m_bgCol = col; }
  164. void SetFont( const wxFont& font ) { m_font = font; }
  165. protected:
  166. virtual ~wxPGCellData() { }
  167. wxString m_text;
  168. wxBitmap m_bitmap;
  169. wxColour m_fgCol;
  170. wxColour m_bgCol;
  171. wxFont m_font;
  172. // True if m_text is valid and specified
  173. bool m_hasValidText;
  174. };
  175. /**
  176. @class wxPGCell
  177. Base class for wxPropertyGrid cell information.
  178. */
  179. class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject
  180. {
  181. public:
  182. wxPGCell();
  183. wxPGCell(const wxPGCell& other)
  184. : wxObject(other)
  185. {
  186. }
  187. wxPGCell( const wxString& text,
  188. const wxBitmap& bitmap = wxNullBitmap,
  189. const wxColour& fgCol = wxNullColour,
  190. const wxColour& bgCol = wxNullColour );
  191. virtual ~wxPGCell() { }
  192. wxPGCellData* GetData()
  193. {
  194. return (wxPGCellData*) m_refData;
  195. }
  196. const wxPGCellData* GetData() const
  197. {
  198. return (const wxPGCellData*) m_refData;
  199. }
  200. bool HasText() const
  201. {
  202. return (m_refData && GetData()->m_hasValidText);
  203. }
  204. /**
  205. Sets empty but valid data to this cell object.
  206. */
  207. void SetEmptyData();
  208. /**
  209. Merges valid data from srcCell into this.
  210. */
  211. void MergeFrom( const wxPGCell& srcCell );
  212. void SetText( const wxString& text );
  213. void SetBitmap( const wxBitmap& bitmap );
  214. void SetFgCol( const wxColour& col );
  215. /**
  216. Sets font of the cell.
  217. @remarks Because wxPropertyGrid does not support rows of
  218. different height, it makes little sense to change
  219. size of the font. Therefore it is recommended
  220. to use return value of wxPropertyGrid::GetFont()
  221. or wxPropertyGrid::GetCaptionFont() as a basis
  222. for the font that, after modifications, is passed
  223. to this member function.
  224. */
  225. void SetFont( const wxFont& font );
  226. void SetBgCol( const wxColour& col );
  227. const wxString& GetText() const { return GetData()->m_text; }
  228. const wxBitmap& GetBitmap() const { return GetData()->m_bitmap; }
  229. const wxColour& GetFgCol() const { return GetData()->m_fgCol; }
  230. /**
  231. Returns font of the cell. If no specific font is set for this
  232. cell, then the font will be invalid.
  233. */
  234. const wxFont& GetFont() const { return GetData()->m_font; }
  235. const wxColour& GetBgCol() const { return GetData()->m_bgCol; }
  236. wxPGCell& operator=( const wxPGCell& other )
  237. {
  238. if ( this != &other )
  239. {
  240. Ref(other);
  241. }
  242. return *this;
  243. }
  244. // Used mostly internally to figure out if this cell is supposed
  245. // to have default values when attached to a grid.
  246. bool IsInvalid() const
  247. {
  248. return ( m_refData == NULL );
  249. }
  250. private:
  251. virtual wxObjectRefData *CreateRefData() const
  252. { return new wxPGCellData(); }
  253. virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
  254. };
  255. // -----------------------------------------------------------------------
  256. /** @class wxPGAttributeStorage
  257. wxPGAttributeStorage is somewhat optimized storage for
  258. key=variant pairs (ie. a map).
  259. */
  260. class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
  261. {
  262. public:
  263. wxPGAttributeStorage();
  264. ~wxPGAttributeStorage();
  265. void Set( const wxString& name, const wxVariant& value );
  266. unsigned int GetCount() const { return (unsigned int) m_map.size(); }
  267. wxVariant FindValue( const wxString& name ) const
  268. {
  269. wxPGHashMapS2P::const_iterator it = m_map.find(name);
  270. if ( it != m_map.end() )
  271. {
  272. wxVariantData* data = (wxVariantData*) it->second;
  273. data->IncRef();
  274. return wxVariant(data, it->first);
  275. }
  276. return wxVariant();
  277. }
  278. typedef wxPGHashMapS2P::const_iterator const_iterator;
  279. const_iterator StartIteration() const
  280. {
  281. return m_map.begin();
  282. }
  283. bool GetNext( const_iterator& it, wxVariant& variant ) const
  284. {
  285. if ( it == m_map.end() )
  286. return false;
  287. wxVariantData* data = (wxVariantData*) it->second;
  288. data->IncRef();
  289. variant.SetData(data);
  290. variant.SetName(it->first);
  291. ++it;
  292. return true;
  293. }
  294. protected:
  295. wxPGHashMapS2P m_map;
  296. };
  297. // -----------------------------------------------------------------------
  298. /** @section propgrid_propflags wxPGProperty Flags
  299. @{
  300. */
  301. enum wxPGPropertyFlags
  302. {
  303. /** Indicates bold font.
  304. */
  305. wxPG_PROP_MODIFIED = 0x0001,
  306. /** Disables ('greyed' text and editor does not activate) property.
  307. */
  308. wxPG_PROP_DISABLED = 0x0002,
  309. /** Hider button will hide this property.
  310. */
  311. wxPG_PROP_HIDDEN = 0x0004,
  312. /** This property has custom paint image just in front of its value.
  313. If property only draws custom images into a popup list, then this
  314. flag should not be set.
  315. */
  316. wxPG_PROP_CUSTOMIMAGE = 0x0008,
  317. /** Do not create text based editor for this property (but button-triggered
  318. dialog and choice are ok).
  319. */
  320. wxPG_PROP_NOEDITOR = 0x0010,
  321. /** Property is collapsed, ie. it's children are hidden.
  322. */
  323. wxPG_PROP_COLLAPSED = 0x0020,
  324. /**
  325. If property is selected, then indicates that validation failed for pending
  326. value.
  327. If property is not selected, that indicates that the actual property
  328. value has failed validation (NB: this behaviour is not currently supported,
  329. but may be used in future).
  330. */
  331. wxPG_PROP_INVALID_VALUE = 0x0040,
  332. // 0x0080,
  333. /** Switched via SetWasModified(). Temporary flag - only used when
  334. setting/changing property value.
  335. */
  336. wxPG_PROP_WAS_MODIFIED = 0x0200,
  337. /**
  338. If set, then child properties (if any) are private, and should be
  339. "invisible" to the application.
  340. */
  341. wxPG_PROP_AGGREGATE = 0x0400,
  342. /** If set, then child properties (if any) are copies and should not
  343. be deleted in dtor.
  344. */
  345. wxPG_PROP_CHILDREN_ARE_COPIES = 0x0800,
  346. /**
  347. Classifies this item as a non-category.
  348. Used for faster item type identification.
  349. */
  350. wxPG_PROP_PROPERTY = 0x1000,
  351. /**
  352. Classifies this item as a category.
  353. Used for faster item type identification.
  354. */
  355. wxPG_PROP_CATEGORY = 0x2000,
  356. /** Classifies this item as a property that has children, but is not aggregate
  357. (ie children are not private).
  358. */
  359. wxPG_PROP_MISC_PARENT = 0x4000,
  360. /** Property is read-only. Editor is still created for wxTextCtrl-based
  361. property editors. For others, editor is not usually created because
  362. they do implement wxTE_READONLY style or equivalent.
  363. */
  364. wxPG_PROP_READONLY = 0x8000,
  365. //
  366. // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
  367. //
  368. /** Property's value is composed from values of child properties.
  369. @remarks
  370. This flag cannot be used with property iterators.
  371. */
  372. wxPG_PROP_COMPOSED_VALUE = 0x00010000,
  373. /** Common value of property is selectable in editor.
  374. @remarks
  375. This flag cannot be used with property iterators.
  376. */
  377. wxPG_PROP_USES_COMMON_VALUE = 0x00020000,
  378. /** Property can be set to unspecified value via editor.
  379. Currently, this applies to following properties:
  380. - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
  381. Clear the text field
  382. @remarks
  383. This flag cannot be used with property iterators.
  384. @see wxPGProperty::SetAutoUnspecified()
  385. */
  386. wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000,
  387. /** Indicates the bit useable by derived properties.
  388. */
  389. wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000,
  390. /** Indicates the bit useable by derived properties.
  391. */
  392. wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000,
  393. /** Indicates that the property is being deleted and should be ignored.
  394. */
  395. wxPG_PROP_BEING_DELETED = 0x00200000
  396. };
  397. /** Topmost flag.
  398. */
  399. #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
  400. /** Property with children must have one of these set, otherwise iterators
  401. will not work correctly.
  402. Code should automatically take care of this, however.
  403. */
  404. #define wxPG_PROP_PARENTAL_FLAGS \
  405. ((wxPGPropertyFlags)(wxPG_PROP_AGGREGATE | \
  406. wxPG_PROP_CATEGORY | \
  407. wxPG_PROP_MISC_PARENT))
  408. /** @}
  409. */
  410. // Combination of flags that can be stored by GetFlagsAsString
  411. #define wxPG_STRING_STORED_FLAGS \
  412. (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
  413. // -----------------------------------------------------------------------
  414. /**
  415. @section propgrid_property_attributes wxPropertyGrid Property Attribute
  416. Identifiers.
  417. wxPGProperty::SetAttribute() and
  418. wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
  419. attribute name argument.
  420. You can use strings instead of constants. However, some of these
  421. constants are redefined to use cached strings which may reduce
  422. your binary size by some amount.
  423. @{
  424. */
  425. /** Set default value for property.
  426. */
  427. #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
  428. /** Universal, int or double. Minimum value for numeric properties.
  429. */
  430. #define wxPG_ATTR_MIN wxS("Min")
  431. /** Universal, int or double. Maximum value for numeric properties.
  432. */
  433. #define wxPG_ATTR_MAX wxS("Max")
  434. /** Universal, string. When set, will be shown as text after the displayed
  435. text value. Alternatively, if third column is enabled, text will be shown
  436. there (for any type of property).
  437. */
  438. #define wxPG_ATTR_UNITS wxS("Units")
  439. /** When set, will be shown as 'greyed' text in property's value cell when
  440. the actual displayed value is blank.
  441. */
  442. #define wxPG_ATTR_HINT wxS("Hint")
  443. #if wxPG_COMPATIBILITY_1_4
  444. /**
  445. @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
  446. */
  447. #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
  448. #endif
  449. /** Universal, wxArrayString. Set to enable auto-completion in any
  450. wxTextCtrl-based property editor.
  451. */
  452. #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
  453. /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
  454. Default value is False.
  455. When set to True, bool property will use check box instead of a
  456. combo box as its editor control. If you set this attribute
  457. for a wxFlagsProperty, it is automatically applied to child
  458. bool properties.
  459. */
  460. #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
  461. /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
  462. Default value is False.
  463. Set to True for the bool property to cycle value on double click
  464. (instead of showing the popup listbox). If you set this attribute
  465. for a wxFlagsProperty, it is automatically applied to child
  466. bool properties.
  467. */
  468. #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
  469. /**
  470. wxFloatProperty (and similar) specific, int, default -1.
  471. Sets the (max) precision used when floating point value is rendered as
  472. text. The default -1 means infinite precision.
  473. */
  474. #define wxPG_FLOAT_PRECISION wxS("Precision")
  475. /**
  476. The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
  477. textctrl etc).
  478. */
  479. #define wxPG_STRING_PASSWORD wxS("Password")
  480. /** Define base used by a wxUIntProperty. Valid constants are
  481. wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
  482. (lowercase characters).
  483. */
  484. #define wxPG_UINT_BASE wxS("Base")
  485. /** Define prefix rendered to wxUIntProperty. Accepted constants
  486. wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
  487. <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
  488. numbers.
  489. */
  490. #define wxPG_UINT_PREFIX wxS("Prefix")
  491. /**
  492. wxFileProperty/wxImageFileProperty specific, wxChar*, default is
  493. detected/varies.
  494. Sets the wildcard used in the triggered wxFileDialog. Format is the same.
  495. */
  496. #define wxPG_FILE_WILDCARD wxS("Wildcard")
  497. /** wxFileProperty/wxImageFileProperty specific, int, default 1.
  498. When 0, only the file name is shown (i.e. drive and directory are hidden).
  499. */
  500. #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
  501. /** Specific to wxFileProperty and derived properties, wxString, default empty.
  502. If set, then the filename is shown relative to the given path string.
  503. */
  504. #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
  505. /**
  506. Specific to wxFileProperty and derived properties, wxString, default is
  507. empty.
  508. Sets the initial path of where to look for files.
  509. */
  510. #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
  511. /** Specific to wxFileProperty and derivatives, wxString, default is empty.
  512. Sets a specific title for the dir dialog.
  513. */
  514. #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
  515. /** Specific to wxFileProperty and derivatives, long, default is 0.
  516. Sets a specific wxFileDialog style for the file dialog.
  517. */
  518. #define wxPG_FILE_DIALOG_STYLE wxS("DialogStyle")
  519. /** Specific to wxDirProperty, wxString, default is empty.
  520. Sets a specific message for the dir dialog.
  521. */
  522. #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
  523. /**
  524. wxArrayStringProperty's string delimiter character. If this is a quotation
  525. mark or hyphen, then strings will be quoted instead (with given
  526. character).
  527. Default delimiter is quotation mark.
  528. */
  529. #define wxPG_ARRAY_DELIMITER wxS("Delimiter")
  530. /** Sets displayed date format for wxDateProperty.
  531. */
  532. #define wxPG_DATE_FORMAT wxS("DateFormat")
  533. /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
  534. is wxDP_DEFAULT | wxDP_SHOWCENTURY.
  535. */
  536. #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
  537. /** SpinCtrl editor, int or double. How much number changes when button is
  538. pressed (or up/down on keyboard).
  539. */
  540. #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
  541. /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
  542. */
  543. #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
  544. /**
  545. wxMultiChoiceProperty, int.
  546. If 0, no user strings allowed. If 1, user strings appear before list
  547. strings. If 2, user strings appear after list string.
  548. */
  549. #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
  550. /**
  551. wxColourProperty and its kind, int, default 1.
  552. Setting this attribute to 0 hides custom colour from property's list of
  553. choices.
  554. */
  555. #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
  556. /**
  557. wxColourProperty and its kind: Set to True in order to support editing
  558. alpha colour component.
  559. */
  560. #define wxPG_COLOUR_HAS_ALPHA wxS("HasAlpha")
  561. /** @}
  562. */
  563. // Redefine attribute macros to use cached strings
  564. #undef wxPG_ATTR_DEFAULT_VALUE
  565. #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
  566. #undef wxPG_ATTR_MIN
  567. #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
  568. #undef wxPG_ATTR_MAX
  569. #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
  570. #undef wxPG_ATTR_UNITS
  571. #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
  572. #undef wxPG_ATTR_HINT
  573. #define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
  574. #if wxPG_COMPATIBILITY_1_4
  575. #undef wxPG_ATTR_INLINE_HELP
  576. #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
  577. #endif
  578. // -----------------------------------------------------------------------
  579. /** @class wxPGChoiceEntry
  580. Data of a single wxPGChoices choice.
  581. */
  582. class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
  583. {
  584. public:
  585. wxPGChoiceEntry();
  586. wxPGChoiceEntry(const wxPGChoiceEntry& other)
  587. : wxPGCell(other)
  588. {
  589. m_value = other.m_value;
  590. }
  591. wxPGChoiceEntry( const wxString& label,
  592. int value = wxPG_INVALID_VALUE )
  593. : wxPGCell(), m_value(value)
  594. {
  595. SetText(label);
  596. }
  597. virtual ~wxPGChoiceEntry() { }
  598. void SetValue( int value ) { m_value = value; }
  599. int GetValue() const { return m_value; }
  600. wxPGChoiceEntry& operator=( const wxPGChoiceEntry& other )
  601. {
  602. if ( this != &other )
  603. {
  604. Ref(other);
  605. }
  606. m_value = other.m_value;
  607. return *this;
  608. }
  609. protected:
  610. int m_value;
  611. };
  612. typedef void* wxPGChoicesId;
  613. class WXDLLIMPEXP_PROPGRID wxPGChoicesData : public wxObjectRefData
  614. {
  615. friend class wxPGChoices;
  616. public:
  617. // Constructor sets m_refCount to 1.
  618. wxPGChoicesData();
  619. void CopyDataFrom( wxPGChoicesData* data );
  620. wxPGChoiceEntry& Insert( int index, const wxPGChoiceEntry& item );
  621. // Delete all entries
  622. void Clear();
  623. unsigned int GetCount() const
  624. {
  625. return (unsigned int) m_items.size();
  626. }
  627. const wxPGChoiceEntry& Item( unsigned int i ) const
  628. {
  629. wxASSERT_MSG( i < GetCount(), "invalid index" );
  630. return m_items[i];
  631. }
  632. wxPGChoiceEntry& Item( unsigned int i )
  633. {
  634. wxASSERT_MSG( i < GetCount(), "invalid index" );
  635. return m_items[i];
  636. }
  637. private:
  638. wxVector<wxPGChoiceEntry> m_items;
  639. virtual ~wxPGChoicesData();
  640. };
  641. #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
  642. /** @class wxPGChoices
  643. Helper class for managing choices of wxPropertyGrid properties.
  644. Each entry can have label, value, bitmap, text colour, and background
  645. colour.
  646. wxPGChoices uses reference counting, similar to other wxWidgets classes.
  647. This means that assignment operator and copy constructor only copy the
  648. reference and not the actual data. Use Copy() member function to create a
  649. real copy.
  650. @remarks If you do not specify value for entry, index is used.
  651. @library{wxpropgrid}
  652. @category{propgrid}
  653. */
  654. class WXDLLIMPEXP_PROPGRID wxPGChoices
  655. {
  656. public:
  657. typedef long ValArrItem;
  658. /** Default constructor. */
  659. wxPGChoices()
  660. {
  661. Init();
  662. }
  663. /**
  664. Copy constructor, uses reference counting. To create a real copy,
  665. use Copy() member function instead.
  666. */
  667. wxPGChoices( const wxPGChoices& a )
  668. {
  669. if ( a.m_data != wxPGChoicesEmptyData )
  670. {
  671. m_data = a.m_data;
  672. m_data->IncRef();
  673. }
  674. }
  675. /**
  676. Constructor.
  677. @param labels
  678. Labels for choices
  679. @param values
  680. Values for choices. If NULL, indexes are used.
  681. */
  682. wxPGChoices( const wxChar* const* labels, const long* values = NULL )
  683. {
  684. Init();
  685. Set(labels,values);
  686. }
  687. /**
  688. Constructor.
  689. @param labels
  690. Labels for choices
  691. @param values
  692. Values for choices. If empty, indexes are used.
  693. */
  694. wxPGChoices( const wxArrayString& labels,
  695. const wxArrayInt& values = wxArrayInt() )
  696. {
  697. Init();
  698. Set(labels,values);
  699. }
  700. /** Simple interface constructor. */
  701. wxPGChoices( wxPGChoicesData* data )
  702. {
  703. wxASSERT(data);
  704. m_data = data;
  705. data->IncRef();
  706. }
  707. /** Destructor. */
  708. ~wxPGChoices()
  709. {
  710. Free();
  711. }
  712. /**
  713. Adds to current.
  714. If did not have own copies, creates them now. If was empty, identical
  715. to set except that creates copies.
  716. @param labels
  717. Labels for added choices.
  718. @param values
  719. Values for added choices. If empty, relevant entry indexes are used.
  720. */
  721. void Add( const wxChar* const* labels, const ValArrItem* values = NULL );
  722. /** Version that works with wxArrayString and wxArrayInt. */
  723. void Add( const wxArrayString& arr, const wxArrayInt& arrint = wxArrayInt() );
  724. /**
  725. Adds a single choice.
  726. @param label
  727. Label for added choice.
  728. @param value
  729. Value for added choice. If unspecified, index is used.
  730. */
  731. wxPGChoiceEntry& Add( const wxString& label,
  732. int value = wxPG_INVALID_VALUE );
  733. /** Adds a single item, with bitmap. */
  734. wxPGChoiceEntry& Add( const wxString& label,
  735. const wxBitmap& bitmap,
  736. int value = wxPG_INVALID_VALUE );
  737. /** Adds a single item with full entry information. */
  738. wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
  739. {
  740. return Insert(entry, -1);
  741. }
  742. /** Adds single item. */
  743. wxPGChoiceEntry& AddAsSorted( const wxString& label,
  744. int value = wxPG_INVALID_VALUE );
  745. /**
  746. Assigns choices data, using reference counting. To create a real copy,
  747. use Copy() member function instead.
  748. */
  749. void Assign( const wxPGChoices& a )
  750. {
  751. AssignData(a.m_data);
  752. }
  753. void AssignData( wxPGChoicesData* data );
  754. /** Delete all choices. */
  755. void Clear();
  756. /**
  757. Returns a real copy of the choices.
  758. */
  759. wxPGChoices Copy() const
  760. {
  761. wxPGChoices dst;
  762. dst.EnsureData();
  763. dst.m_data->CopyDataFrom(m_data);
  764. return dst;
  765. }
  766. void EnsureData()
  767. {
  768. if ( m_data == wxPGChoicesEmptyData )
  769. m_data = new wxPGChoicesData();
  770. }
  771. /** Gets a unsigned number identifying this list. */
  772. wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; }
  773. const wxString& GetLabel( unsigned int ind ) const
  774. {
  775. return Item(ind).GetText();
  776. }
  777. unsigned int GetCount () const
  778. {
  779. if ( !m_data )
  780. return 0;
  781. return m_data->GetCount();
  782. }
  783. int GetValue( unsigned int ind ) const { return Item(ind).GetValue(); }
  784. /** Returns array of values matching the given strings. Unmatching strings
  785. result in wxPG_INVALID_VALUE entry in array.
  786. */
  787. wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
  788. /** Returns array of indices matching given strings. Unmatching strings
  789. are added to 'unmatched', if not NULL.
  790. */
  791. wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
  792. wxArrayString* unmatched = NULL ) const;
  793. int Index( const wxString& str ) const;
  794. int Index( int val ) const;
  795. /** Inserts single item. */
  796. wxPGChoiceEntry& Insert( const wxString& label,
  797. int index,
  798. int value = wxPG_INVALID_VALUE );
  799. /** Inserts a single item with full entry information. */
  800. wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
  801. /** Returns false if this is a constant empty set of choices,
  802. which should not be modified.
  803. */
  804. bool IsOk() const
  805. {
  806. return ( m_data != wxPGChoicesEmptyData );
  807. }
  808. const wxPGChoiceEntry& Item( unsigned int i ) const
  809. {
  810. wxASSERT( IsOk() );
  811. return m_data->Item(i);
  812. }
  813. wxPGChoiceEntry& Item( unsigned int i )
  814. {
  815. wxASSERT( IsOk() );
  816. return m_data->Item(i);
  817. }
  818. /** Removes count items starting at position nIndex. */
  819. void RemoveAt(size_t nIndex, size_t count = 1);
  820. /** Does not create copies for itself.
  821. TODO: Deprecate.
  822. */
  823. void Set( const wxChar* const* labels, const long* values = NULL )
  824. {
  825. Free();
  826. Add(labels,values);
  827. }
  828. /** Version that works with wxArrayString and wxArrayInt. */
  829. void Set( const wxArrayString& labels,
  830. const wxArrayInt& values = wxArrayInt() )
  831. {
  832. Free();
  833. if ( &values )
  834. Add(labels,values);
  835. else
  836. Add(labels);
  837. }
  838. // Creates exclusive copy of current choices
  839. void AllocExclusive();
  840. // Returns data, increases refcount.
  841. wxPGChoicesData* GetData()
  842. {
  843. wxASSERT( m_data->GetRefCount() != -1 );
  844. m_data->IncRef();
  845. return m_data;
  846. }
  847. // Returns plain data ptr - no refcounting stuff is done.
  848. wxPGChoicesData* GetDataPtr() const { return m_data; }
  849. // Changes ownership of data to you.
  850. wxPGChoicesData* ExtractData()
  851. {
  852. wxPGChoicesData* data = m_data;
  853. m_data = wxPGChoicesEmptyData;
  854. return data;
  855. }
  856. wxArrayString GetLabels() const;
  857. void operator= (const wxPGChoices& a)
  858. {
  859. if (this != &a)
  860. AssignData(a.m_data);
  861. }
  862. wxPGChoiceEntry& operator[](unsigned int i)
  863. {
  864. return Item(i);
  865. }
  866. const wxPGChoiceEntry& operator[](unsigned int i) const
  867. {
  868. return Item(i);
  869. }
  870. protected:
  871. wxPGChoicesData* m_data;
  872. void Init();
  873. void Free();
  874. };
  875. // -----------------------------------------------------------------------
  876. /** @class wxPGProperty
  877. wxPGProperty is base class for all wxPropertyGrid properties.
  878. NB: Full class overview is now only present in
  879. interface/wx/propgrid/property.h.
  880. @library{wxpropgrid}
  881. @category{propgrid}
  882. */
  883. class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
  884. {
  885. friend class wxPropertyGrid;
  886. friend class wxPropertyGridInterface;
  887. friend class wxPropertyGridPageState;
  888. friend class wxPropertyGridPopulator;
  889. friend class wxStringProperty; // Proper "<composed>" support requires this
  890. DECLARE_ABSTRACT_CLASS(wxPGProperty)
  891. public:
  892. typedef wxUint32 FlagType;
  893. /**
  894. Default constructor.
  895. */
  896. wxPGProperty();
  897. /**
  898. Constructor.
  899. All non-abstract property classes should have a constructor with
  900. the same first two arguments as this one.
  901. */
  902. wxPGProperty( const wxString& label, const wxString& name );
  903. /**
  904. Virtual destructor.
  905. It is customary for derived properties to implement this.
  906. */
  907. virtual ~wxPGProperty();
  908. /** This virtual function is called after m_value has been set.
  909. @remarks
  910. - If m_value was set to Null variant (ie. unspecified value),
  911. OnSetValue() will not be called.
  912. - m_value may be of any variant type. Typically properties internally
  913. support only one variant type, and as such OnSetValue() provides a
  914. good opportunity to convert
  915. supported values into internal type.
  916. - Default implementation does nothing.
  917. */
  918. virtual void OnSetValue();
  919. /** Override this to return something else than m_value as the value.
  920. */
  921. virtual wxVariant DoGetValue() const { return m_value; }
  922. /** Implement this function in derived class to check the value.
  923. Return true if it is ok. Returning false prevents property change events
  924. from occurring.
  925. @remarks
  926. - Default implementation always returns true.
  927. */
  928. virtual bool ValidateValue( wxVariant& value,
  929. wxPGValidationInfo& validationInfo ) const;
  930. /**
  931. Converts text into wxVariant value appropriate for this property.
  932. @param variant
  933. On function entry this is the old value (should not be wxNullVariant
  934. in normal cases). Translated value must be assigned back to it.
  935. @param text
  936. Text to be translated into variant.
  937. @param argFlags
  938. If wxPG_FULL_VALUE is set, returns complete, storable value instead
  939. of displayable one (they may be different).
  940. If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
  941. composite property string value (as generated by ValueToString()
  942. called with this same flag).
  943. @return Returns @true if resulting wxVariant value was different.
  944. @remarks Default implementation converts semicolon delimited tokens into
  945. child values. Only works for properties with children.
  946. You might want to take into account that m_value is Null variant
  947. if property value is unspecified (which is usually only case if
  948. you explicitly enabled that sort behaviour).
  949. */
  950. virtual bool StringToValue( wxVariant& variant,
  951. const wxString& text,
  952. int argFlags = 0 ) const;
  953. /**
  954. Converts integer (possibly a choice selection) into wxVariant value
  955. appropriate for this property.
  956. @param variant
  957. On function entry this is the old value (should not be wxNullVariant
  958. in normal cases). Translated value must be assigned back to it.
  959. @param number
  960. Integer to be translated into variant.
  961. @param argFlags
  962. If wxPG_FULL_VALUE is set, returns complete, storable value instead
  963. of displayable one.
  964. @return Returns @true if resulting wxVariant value was different.
  965. @remarks
  966. - If property is not supposed to use choice or spinctrl or other editor
  967. with int-based value, it is not necessary to implement this method.
  968. - Default implementation simply assign given int to m_value.
  969. - If property uses choice control, and displays a dialog on some choice
  970. items, then it is preferred to display that dialog in IntToValue
  971. instead of OnEvent.
  972. - You might want to take into account that m_value is Null variant if
  973. property value is unspecified (which is usually only case if you
  974. explicitly enabled that sort behaviour).
  975. */
  976. virtual bool IntToValue( wxVariant& value,
  977. int number,
  978. int argFlags = 0 ) const;
  979. /**
  980. Converts property value into a text representation.
  981. @param value
  982. Value to be converted.
  983. @param argFlags
  984. If 0 (default value), then displayed string is returned.
  985. If wxPG_FULL_VALUE is set, returns complete, storable string value
  986. instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
  987. string value that must be editable in textctrl. If
  988. wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
  989. display as a part of string property's composite text
  990. representation.
  991. @remarks Default implementation calls GenerateComposedValue().
  992. */
  993. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  994. /** Converts string to a value, and if successful, calls SetValue() on it.
  995. Default behaviour is to do nothing.
  996. @param text
  997. String to get the value from.
  998. @return
  999. true if value was changed.
  1000. */
  1001. bool SetValueFromString( const wxString& text, int flags = wxPG_PROGRAMMATIC_VALUE );
  1002. /** Converts integer to a value, and if successful, calls SetValue() on it.
  1003. Default behaviour is to do nothing.
  1004. @param value
  1005. Int to get the value from.
  1006. @param flags
  1007. If has wxPG_FULL_VALUE, then the value given is a actual value and
  1008. not an index.
  1009. @return
  1010. True if value was changed.
  1011. */
  1012. bool SetValueFromInt( long value, int flags = 0 );
  1013. /**
  1014. Returns size of the custom painted image in front of property.
  1015. This method must be overridden to return non-default value if
  1016. OnCustomPaint is to be called.
  1017. @param item
  1018. Normally -1, but can be an index to the property's list of items.
  1019. @remarks
  1020. - Default behaviour is to return wxSize(0,0), which means no image.
  1021. - Default image width or height is indicated with dimension -1.
  1022. - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
  1023. */
  1024. virtual wxSize OnMeasureImage( int item = -1 ) const;
  1025. /**
  1026. Events received by editor widgets are processed here.
  1027. Note that editor class usually processes most events. Some, such as
  1028. button press events of TextCtrlAndButton class, can be handled here.
  1029. Also, if custom handling for regular events is desired, then that can
  1030. also be done (for example, wxSystemColourProperty custom handles
  1031. wxEVT_CHOICE to display colour picker dialog when
  1032. 'custom' selection is made).
  1033. If the event causes value to be changed, SetValueInEvent()
  1034. should be called to set the new value.
  1035. @param event
  1036. Associated wxEvent.
  1037. @return
  1038. Should return true if any changes in value should be reported.
  1039. @remarks
  1040. If property uses choice control, and displays a dialog on some choice
  1041. items, then it is preferred to display that dialog in IntToValue
  1042. instead of OnEvent.
  1043. */
  1044. virtual bool OnEvent( wxPropertyGrid* propgrid,
  1045. wxWindow* wnd_primary,
  1046. wxEvent& event );
  1047. /**
  1048. Called after value of a child property has been altered. Must return
  1049. new value of the whole property (after any alterations warranted by
  1050. child's new value).
  1051. Note that this function is usually called at the time that value of
  1052. this property, or given child property, is still pending for change,
  1053. and as such, result of GetValue() or m_value should not be relied
  1054. on.
  1055. Sample pseudo-code implementation:
  1056. @code
  1057. wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
  1058. int childIndex,
  1059. wxVariant& childValue ) const
  1060. {
  1061. // Acquire reference to actual type of data stored in variant
  1062. // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
  1063. // were used to create the variant class).
  1064. T& data = TFromVariant(thisValue);
  1065. // Copy childValue into data.
  1066. switch ( childIndex )
  1067. {
  1068. case 0:
  1069. data.SetSubProp1( childvalue.GetLong() );
  1070. break;
  1071. case 1:
  1072. data.SetSubProp2( childvalue.GetString() );
  1073. break;
  1074. ...
  1075. }
  1076. // Return altered data
  1077. return data;
  1078. }
  1079. @endcode
  1080. @param thisValue
  1081. Value of this property. Changed value should be returned (in
  1082. previous versions of wxPropertyGrid it was only necessary to
  1083. write value back to this argument).
  1084. @param childIndex
  1085. Index of child changed (you can use Item(childIndex) to get
  1086. child property).
  1087. @param childValue
  1088. (Pending) value of the child property.
  1089. @return
  1090. Modified value of the whole property.
  1091. */
  1092. virtual wxVariant ChildChanged( wxVariant& thisValue,
  1093. int childIndex,
  1094. wxVariant& childValue ) const;
  1095. /** Returns pointer to an instance of used editor.
  1096. */
  1097. virtual const wxPGEditor* DoGetEditorClass() const;
  1098. /** Returns pointer to the wxValidator that should be used
  1099. with the editor of this property (NULL for no validator).
  1100. Setting validator explicitly via SetPropertyValidator
  1101. will override this.
  1102. In most situations, code like this should work well
  1103. (macros are used to maintain one actual validator instance,
  1104. so on the second call the function exits within the first
  1105. macro):
  1106. @code
  1107. wxValidator* wxMyPropertyClass::DoGetValidator () const
  1108. {
  1109. WX_PG_DOGETVALIDATOR_ENTRY()
  1110. wxMyValidator* validator = new wxMyValidator(...);
  1111. ... prepare validator...
  1112. WX_PG_DOGETVALIDATOR_EXIT(validator)
  1113. }
  1114. @endcode
  1115. @remarks
  1116. You can get common filename validator by returning
  1117. wxFileProperty::GetClassValidator(). wxDirProperty,
  1118. for example, uses it.
  1119. */
  1120. virtual wxValidator* DoGetValidator () const;
  1121. /**
  1122. Override to paint an image in front of the property value text or
  1123. drop-down list item (but only if wxPGProperty::OnMeasureImage is
  1124. overridden as well).
  1125. If property's OnMeasureImage() returns size that has height != 0 but
  1126. less than row height ( < 0 has special meanings), wxPropertyGrid calls
  1127. this method to draw a custom image in a limited area in front of the
  1128. editor control or value text/graphics, and if control has drop-down
  1129. list, then the image is drawn there as well (even in the case
  1130. OnMeasureImage() returned higher height than row height).
  1131. NOTE: Following applies when OnMeasureImage() returns a "flexible"
  1132. height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
  1133. height items: If rect.x is < 0, then this is a measure item call, which
  1134. means that dc is invalid and only thing that should be done is to set
  1135. paintdata.m_drawnHeight to the height of the image of item at index
  1136. paintdata.m_choiceItem. This call may be done even as often as once
  1137. every drop-down popup show.
  1138. @param dc
  1139. wxDC to paint on.
  1140. @param rect
  1141. Box reserved for custom graphics. Includes surrounding rectangle,
  1142. if any. If x is < 0, then this is a measure item call (see above).
  1143. @param paintdata
  1144. wxPGPaintData structure with much useful data.
  1145. @remarks
  1146. - You can actually exceed rect width, but if you do so then
  1147. paintdata.m_drawnWidth must be set to the full width drawn in
  1148. pixels.
  1149. - Due to technical reasons, rect's height will be default even if
  1150. custom height was reported during measure call.
  1151. - Brush is guaranteed to be default background colour. It has been
  1152. already used to clear the background of area being painted. It
  1153. can be modified.
  1154. - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
  1155. colour) pen for drawing framing rectangle. It can be changed as
  1156. well.
  1157. @see ValueToString()
  1158. */
  1159. virtual void OnCustomPaint( wxDC& dc,
  1160. const wxRect& rect,
  1161. wxPGPaintData& paintdata );
  1162. /**
  1163. Returns used wxPGCellRenderer instance for given property column
  1164. (label=0, value=1).
  1165. Default implementation returns editor's renderer for all columns.
  1166. */
  1167. virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
  1168. /** Returns which choice is currently selected. Only applies to properties
  1169. which have choices.
  1170. Needs to reimplemented in derived class if property value does not
  1171. map directly to a choice. Integer as index, bool, and string usually do.
  1172. */
  1173. virtual int GetChoiceSelection() const;
  1174. /**
  1175. Refresh values of child properties.
  1176. Automatically called after value is set.
  1177. */
  1178. virtual void RefreshChildren();
  1179. /**
  1180. Reimplement this member function to add special handling for
  1181. attributes of this property.
  1182. @return Return @false to have the attribute automatically stored in
  1183. m_attributes. Default implementation simply does that and
  1184. nothing else.
  1185. @remarks To actually set property attribute values from the
  1186. application, use wxPGProperty::SetAttribute() instead.
  1187. */
  1188. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  1189. /** Returns value of an attribute.
  1190. Override if custom handling of attributes is needed.
  1191. Default implementation simply return NULL variant.
  1192. */
  1193. virtual wxVariant DoGetAttribute( const wxString& name ) const;
  1194. /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
  1195. used when user presses the (optional) button next to the editor control;
  1196. Default implementation returns NULL (ie. no action is generated when
  1197. button is pressed).
  1198. */
  1199. virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
  1200. /**
  1201. Called whenever validation has failed with given pending value.
  1202. @remarks If you implement this in your custom property class, please
  1203. remember to call the baser implementation as well, since they
  1204. may use it to revert property into pre-change state.
  1205. */
  1206. virtual void OnValidationFailure( wxVariant& pendingValue );
  1207. /** Append a new choice to property's list of choices.
  1208. */
  1209. int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
  1210. {
  1211. return InsertChoice(label, wxNOT_FOUND, value);
  1212. }
  1213. /**
  1214. Returns true if children of this property are component values (for
  1215. instance, points size, face name, and is_underlined are component
  1216. values of a font).
  1217. */
  1218. bool AreChildrenComponents() const
  1219. {
  1220. if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
  1221. return true;
  1222. return false;
  1223. }
  1224. /**
  1225. Deletes children of the property.
  1226. */
  1227. void DeleteChildren();
  1228. /**
  1229. Removes entry from property's wxPGChoices and editor control (if it is
  1230. active).
  1231. If selected item is deleted, then the value is set to unspecified.
  1232. */
  1233. void DeleteChoice( int index );
  1234. /**
  1235. Enables or disables the property. Disabled property usually appears
  1236. as having grey text.
  1237. @param enable
  1238. If @false, property is disabled instead.
  1239. @see wxPropertyGridInterface::EnableProperty()
  1240. */
  1241. void Enable( bool enable = true );
  1242. /**
  1243. Call to enable or disable usage of common value (integer value that can
  1244. be selected for properties instead of their normal values) for this
  1245. property.
  1246. Common values are disabled by the default for all properties.
  1247. */
  1248. void EnableCommonValue( bool enable = true )
  1249. {
  1250. if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
  1251. else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
  1252. }
  1253. /**
  1254. Composes text from values of child properties.
  1255. */
  1256. wxString GenerateComposedValue() const
  1257. {
  1258. wxString s;
  1259. DoGenerateComposedValue(s);
  1260. return s;
  1261. }
  1262. /** Returns property's label. */
  1263. const wxString& GetLabel() const { return m_label; }
  1264. /** Returns property's name with all (non-category, non-root) parents. */
  1265. wxString GetName() const;
  1266. /**
  1267. Returns property's base name (ie parent's name is not added in any
  1268. case)
  1269. */
  1270. const wxString& GetBaseName() const { return m_name; }
  1271. /** Returns read-only reference to property's list of choices.
  1272. */
  1273. const wxPGChoices& GetChoices() const
  1274. {
  1275. return m_choices;
  1276. }
  1277. /** Returns coordinate to the top y of the property. Note that the
  1278. position of scrollbars is not taken into account.
  1279. */
  1280. int GetY() const;
  1281. wxVariant GetValue() const
  1282. {
  1283. return DoGetValue();
  1284. }
  1285. /** Returns reference to the internal stored value. GetValue is preferred
  1286. way to get the actual value, since GetValueRef ignores DoGetValue,
  1287. which may override stored value.
  1288. */
  1289. wxVariant& GetValueRef()
  1290. {
  1291. return m_value;
  1292. }
  1293. const wxVariant& GetValueRef() const
  1294. {
  1295. return m_value;
  1296. }
  1297. // Helper function (for wxPython bindings and such) for settings protected
  1298. // m_value.
  1299. wxVariant GetValuePlain() const
  1300. {
  1301. return m_value;
  1302. }
  1303. /** Returns text representation of property's value.
  1304. @param argFlags
  1305. If 0 (default value), then displayed string is returned.
  1306. If wxPG_FULL_VALUE is set, returns complete, storable string value
  1307. instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
  1308. string value that must be editable in textctrl. If
  1309. wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
  1310. display as a part of string property's composite text
  1311. representation.
  1312. @remarks In older versions, this function used to be overridden to convert
  1313. property's value into a string representation. This function is
  1314. now handled by ValueToString(), and overriding this function now
  1315. will result in run-time assertion failure.
  1316. */
  1317. virtual wxString GetValueAsString( int argFlags = 0 ) const;
  1318. /** Synonymous to GetValueAsString().
  1319. @deprecated Use GetValueAsString() instead.
  1320. @see GetValueAsString()
  1321. */
  1322. wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
  1323. /**
  1324. Returns wxPGCell of given column.
  1325. @remarks const version of this member function returns 'default'
  1326. wxPGCell object if the property itself didn't hold
  1327. cell data.
  1328. */
  1329. const wxPGCell& GetCell( unsigned int column ) const;
  1330. /**
  1331. Returns wxPGCell of given column, creating one if necessary.
  1332. */
  1333. wxPGCell& GetCell( unsigned int column )
  1334. {
  1335. return GetOrCreateCell(column);
  1336. }
  1337. /**
  1338. Returns wxPGCell of given column, creating one if necessary.
  1339. */
  1340. wxPGCell& GetOrCreateCell( unsigned int column );
  1341. /** Return number of displayed common values for this property.
  1342. */
  1343. int GetDisplayedCommonValueCount() const;
  1344. wxString GetDisplayedString() const
  1345. {
  1346. return GetValueAsString(0);
  1347. }
  1348. /**
  1349. Returns property's hint text (shown in empty value cell).
  1350. */
  1351. inline wxString GetHintText() const;
  1352. /** Returns property grid where property lies. */
  1353. wxPropertyGrid* GetGrid() const;
  1354. /** Returns owner wxPropertyGrid, but only if one is currently on a page
  1355. displaying this property. */
  1356. wxPropertyGrid* GetGridIfDisplayed() const;
  1357. /** Returns highest level non-category, non-root parent. Useful when you
  1358. have nested wxCustomProperties/wxParentProperties.
  1359. @remarks
  1360. Thus, if immediate parent is root or category, this will return the
  1361. property itself.
  1362. */
  1363. wxPGProperty* GetMainParent() const;
  1364. /** Return parent of property */
  1365. wxPGProperty* GetParent() const { return m_parent; }
  1366. /** Returns true if property has editable wxTextCtrl when selected.
  1367. @remarks
  1368. Although disabled properties do not displayed editor, they still
  1369. return True here as being disabled is considered a temporary
  1370. condition (unlike being read-only or having limited editing enabled).
  1371. */
  1372. bool IsTextEditable() const;
  1373. bool IsValueUnspecified() const
  1374. {
  1375. return m_value.IsNull();
  1376. }
  1377. /**
  1378. Returns non-zero if property has given flag set.
  1379. @see propgrid_propflags
  1380. */
  1381. FlagType HasFlag( wxPGPropertyFlags flag ) const
  1382. {
  1383. return ( m_flags & flag );
  1384. }
  1385. /** Returns comma-delimited string of property attributes.
  1386. */
  1387. const wxPGAttributeStorage& GetAttributes() const
  1388. {
  1389. return m_attributes;
  1390. }
  1391. /** Returns m_attributes as list wxVariant.
  1392. */
  1393. wxVariant GetAttributesAsList() const;
  1394. /**
  1395. Returns property flags.
  1396. */
  1397. FlagType GetFlags() const
  1398. {
  1399. return m_flags;
  1400. }
  1401. const wxPGEditor* GetEditorClass() const;
  1402. wxString GetValueType() const
  1403. {
  1404. return m_value.GetType();
  1405. }
  1406. /** Returns editor used for given column. NULL for no editor.
  1407. */
  1408. const wxPGEditor* GetColumnEditor( int column ) const
  1409. {
  1410. if ( column == 1 )
  1411. return GetEditorClass();
  1412. return NULL;
  1413. }
  1414. /** Returns common value selected for this property. -1 for none.
  1415. */
  1416. int GetCommonValue() const
  1417. {
  1418. return m_commonValue;
  1419. }
  1420. /** Returns true if property has even one visible child.
  1421. */
  1422. bool HasVisibleChildren() const;
  1423. /**
  1424. Use this member function to add independent (ie. regular) children to
  1425. a property.
  1426. @return Inserted childProperty.
  1427. @remarks wxPropertyGrid is not automatically refreshed by this
  1428. function.
  1429. @see AddPrivateChild()
  1430. */
  1431. wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
  1432. /** Inserts a new choice to property's list of choices.
  1433. */
  1434. int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
  1435. /**
  1436. Returns true if this property is actually a wxPropertyCategory.
  1437. */
  1438. bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
  1439. /** Returns true if this property is actually a wxRootProperty.
  1440. */
  1441. bool IsRoot() const { return (m_parent == NULL); }
  1442. /** Returns true if this is a sub-property. */
  1443. bool IsSubProperty() const
  1444. {
  1445. wxPGProperty* parent = (wxPGProperty*)m_parent;
  1446. if ( parent && !parent->IsCategory() )
  1447. return true;
  1448. return false;
  1449. }
  1450. /** Returns last visible sub-property, recursively.
  1451. */
  1452. const wxPGProperty* GetLastVisibleSubItem() const;
  1453. wxVariant GetDefaultValue() const;
  1454. int GetMaxLength() const
  1455. {
  1456. return (int) m_maxLen;
  1457. }
  1458. /**
  1459. Determines, recursively, if all children are not unspecified.
  1460. @param pendingList
  1461. Assumes members in this wxVariant list as pending
  1462. replacement values.
  1463. */
  1464. bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
  1465. /** Updates composed values of parent non-category properties, recursively.
  1466. Returns topmost property updated.
  1467. @remarks
  1468. - Must not call SetValue() (as can be called in it).
  1469. */
  1470. wxPGProperty* UpdateParentValues();
  1471. /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
  1472. */
  1473. bool UsesAutoUnspecified() const
  1474. {
  1475. return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false;
  1476. }
  1477. wxBitmap* GetValueImage() const
  1478. {
  1479. return m_valueBitmap;
  1480. }
  1481. wxVariant GetAttribute( const wxString& name ) const;
  1482. /**
  1483. Returns named attribute, as string, if found.
  1484. Otherwise defVal is returned.
  1485. */
  1486. wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
  1487. /**
  1488. Returns named attribute, as long, if found.
  1489. Otherwise defVal is returned.
  1490. */
  1491. long GetAttributeAsLong( const wxString& name, long defVal ) const;
  1492. /**
  1493. Returns named attribute, as double, if found.
  1494. Otherwise defVal is returned.
  1495. */
  1496. double GetAttributeAsDouble( const wxString& name, double defVal ) const;
  1497. unsigned int GetDepth() const { return (unsigned int)m_depth; }
  1498. /** Gets flags as a'|' delimited string. Note that flag names are not
  1499. prepended with 'wxPG_PROP_'.
  1500. @param flagsMask
  1501. String will only be made to include flags combined by this parameter.
  1502. */
  1503. wxString GetFlagsAsString( FlagType flagsMask ) const;
  1504. /** Returns position in parent's array. */
  1505. unsigned int GetIndexInParent() const
  1506. {
  1507. return (unsigned int)m_arrIndex;
  1508. }
  1509. /** Hides or reveals the property.
  1510. @param hide
  1511. true for hide, false for reveal.
  1512. @param flags
  1513. By default changes are applied recursively. Set this paramter
  1514. wxPG_DONT_RECURSE to prevent this.
  1515. */
  1516. bool Hide( bool hide, int flags = wxPG_RECURSE );
  1517. bool IsExpanded() const
  1518. { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
  1519. /** Returns true if all parents expanded.
  1520. */
  1521. bool IsVisible() const;
  1522. bool IsEnabled() const { return !(m_flags & wxPG_PROP_DISABLED); }
  1523. /** If property's editor is created this forces its recreation.
  1524. Useful in SetAttribute etc. Returns true if actually did anything.
  1525. */
  1526. bool RecreateEditor();
  1527. /** If property's editor is active, then update it's value.
  1528. */
  1529. void RefreshEditor();
  1530. /** Sets an attribute for this property.
  1531. @param name
  1532. Text identifier of attribute. See @ref propgrid_property_attributes.
  1533. @param value
  1534. Value of attribute.
  1535. */
  1536. void SetAttribute( const wxString& name, wxVariant value );
  1537. void SetAttributes( const wxPGAttributeStorage& attributes );
  1538. /**
  1539. Set if user can change the property's value to unspecified by
  1540. modifying the value of the editor control (usually by clearing
  1541. it). Currently, this can work with following properties:
  1542. wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty.
  1543. @param enable
  1544. Whether to enable or disable this behaviour (it is disabled by
  1545. default).
  1546. */
  1547. void SetAutoUnspecified( bool enable = true )
  1548. {
  1549. ChangeFlag(wxPG_PROP_AUTO_UNSPECIFIED, enable);
  1550. }
  1551. /**
  1552. Sets property's background colour.
  1553. @param colour
  1554. Background colour to use.
  1555. @param flags
  1556. Default is wxPG_RECURSE which causes colour to be set recursively.
  1557. Omit this flag to only set colour for the property in question
  1558. and not any of its children.
  1559. */
  1560. void SetBackgroundColour( const wxColour& colour,
  1561. int flags = wxPG_RECURSE );
  1562. /**
  1563. Sets property's text colour.
  1564. @param colour
  1565. Text colour to use.
  1566. @param flags
  1567. Default is wxPG_RECURSE which causes colour to be set recursively.
  1568. Omit this flag to only set colour for the property in question
  1569. and not any of its children.
  1570. */
  1571. void SetTextColour( const wxColour& colour,
  1572. int flags = wxPG_RECURSE );
  1573. /** Set default value of a property. Synonymous to
  1574. @code
  1575. SetAttribute("DefaultValue", value);
  1576. @endcode
  1577. */
  1578. void SetDefaultValue( wxVariant& value );
  1579. /** Sets editor for a property.
  1580. @param editor
  1581. For builtin editors, use wxPGEditor_X, where X is builtin editor's
  1582. name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
  1583. list).
  1584. For custom editors, use pointer you received from
  1585. wxPropertyGrid::RegisterEditorClass().
  1586. */
  1587. void SetEditor( const wxPGEditor* editor )
  1588. {
  1589. m_customEditor = editor;
  1590. }
  1591. /** Sets editor for a property.
  1592. */
  1593. inline void SetEditor( const wxString& editorName );
  1594. /**
  1595. Sets cell information for given column.
  1596. */
  1597. void SetCell( int column, const wxPGCell& cell );
  1598. /** Sets common value selected for this property. -1 for none.
  1599. */
  1600. void SetCommonValue( int commonValue )
  1601. {
  1602. m_commonValue = commonValue;
  1603. }
  1604. /** Sets flags from a '|' delimited string. Note that flag names are not
  1605. prepended with 'wxPG_PROP_'.
  1606. */
  1607. void SetFlagsFromString( const wxString& str );
  1608. /** Sets property's "is it modified?" flag. Affects children recursively.
  1609. */
  1610. void SetModifiedStatus( bool modified )
  1611. {
  1612. SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
  1613. }
  1614. /** Call in OnEvent(), OnButtonClick() etc. to change the property value
  1615. based on user input.
  1616. @remarks
  1617. This method is const since it doesn't actually modify value, but posts
  1618. given variant as pending value, stored in wxPropertyGrid.
  1619. */
  1620. void SetValueInEvent( wxVariant value ) const;
  1621. /**
  1622. Call this to set value of the property.
  1623. Unlike methods in wxPropertyGrid, this does not automatically update
  1624. the display.
  1625. @remarks
  1626. Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
  1627. through validation process and send property change event.
  1628. If you need to change property value in event, based on user input, use
  1629. SetValueInEvent() instead.
  1630. @param pList
  1631. Pointer to list variant that contains child values. Used to
  1632. indicate which children should be marked as modified.
  1633. @param flags
  1634. Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
  1635. enabled by default).
  1636. */
  1637. void SetValue( wxVariant value, wxVariant* pList = NULL,
  1638. int flags = wxPG_SETVAL_REFRESH_EDITOR );
  1639. /** Set wxBitmap in front of the value. This bitmap may be ignored
  1640. by custom cell renderers.
  1641. */
  1642. void SetValueImage( wxBitmap& bmp );
  1643. /** Sets selected choice and changes property value.
  1644. Tries to retain value type, although currently if it is not string,
  1645. then it is forced to integer.
  1646. */
  1647. void SetChoiceSelection( int newValue );
  1648. void SetExpanded( bool expanded )
  1649. {
  1650. if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
  1651. else m_flags &= ~wxPG_PROP_COLLAPSED;
  1652. }
  1653. /**
  1654. Sets or clears given property flag. Mainly for internal use.
  1655. @remarks Setting a property flag never has any side-effect, and is
  1656. intended almost exclusively for internal use. So, for
  1657. example, if you want to disable a property, call
  1658. Enable(false) instead of setting wxPG_PROP_DISABLED flag.
  1659. @see HasFlag(), GetFlags()
  1660. */
  1661. void ChangeFlag( wxPGPropertyFlags flag, bool set )
  1662. {
  1663. if ( set )
  1664. m_flags |= flag;
  1665. else
  1666. m_flags &= ~flag;
  1667. }
  1668. /**
  1669. Sets or clears given property flag, recursively. This function is
  1670. primarily intended for internal use.
  1671. @see ChangeFlag()
  1672. */
  1673. void SetFlagRecursively( wxPGPropertyFlags flag, bool set );
  1674. void SetHelpString( const wxString& helpString )
  1675. {
  1676. m_helpString = helpString;
  1677. }
  1678. void SetLabel( const wxString& label ) { m_label = label; }
  1679. void SetName( const wxString& newName );
  1680. /**
  1681. Changes what sort of parent this property is for its children.
  1682. @param flag
  1683. Use one of the following values: wxPG_PROP_MISC_PARENT (for
  1684. generic parents), wxPG_PROP_CATEGORY (for categories), or
  1685. wxPG_PROP_AGGREGATE (for derived property classes with private
  1686. children).
  1687. @remarks You generally do not need to call this function.
  1688. */
  1689. void SetParentalType( int flag )
  1690. {
  1691. m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
  1692. m_flags |= flag;
  1693. }
  1694. void SetValueToUnspecified()
  1695. {
  1696. wxVariant val; // Create NULL variant
  1697. SetValue(val, NULL, wxPG_SETVAL_REFRESH_EDITOR);
  1698. }
  1699. // Helper function (for wxPython bindings and such) for settings protected
  1700. // m_value.
  1701. void SetValuePlain( wxVariant value )
  1702. {
  1703. m_value = value;
  1704. }
  1705. #if wxUSE_VALIDATORS
  1706. /** Sets wxValidator for a property*/
  1707. void SetValidator( const wxValidator& validator )
  1708. {
  1709. m_validator = wxDynamicCast(validator.Clone(),wxValidator);
  1710. }
  1711. /** Gets assignable version of property's validator. */
  1712. wxValidator* GetValidator() const
  1713. {
  1714. if ( m_validator )
  1715. return m_validator;
  1716. return DoGetValidator();
  1717. }
  1718. #endif // wxUSE_VALIDATORS
  1719. /** Returns client data (void*) of a property.
  1720. */
  1721. void* GetClientData() const
  1722. {
  1723. return m_clientData;
  1724. }
  1725. /** Sets client data (void*) of a property.
  1726. @remarks
  1727. This untyped client data has to be deleted manually.
  1728. */
  1729. void SetClientData( void* clientData )
  1730. {
  1731. m_clientData = clientData;
  1732. }
  1733. /** Returns client object of a property.
  1734. */
  1735. void SetClientObject(wxClientData* clientObject)
  1736. {
  1737. delete m_clientObject;
  1738. m_clientObject = clientObject;
  1739. }
  1740. /** Sets managed client object of a property.
  1741. */
  1742. wxClientData *GetClientObject() const { return m_clientObject; }
  1743. /**
  1744. Sets new set of choices for the property.
  1745. @remarks This operation deselects the property and clears its
  1746. value.
  1747. */
  1748. bool SetChoices( const wxPGChoices& choices );
  1749. /** Set max length of text in text editor.
  1750. */
  1751. inline bool SetMaxLength( int maxLen );
  1752. /** Call with 'false' in OnSetValue to cancel value changes after all
  1753. (ie. cancel 'true' returned by StringToValue() or IntToValue()).
  1754. */
  1755. void SetWasModified( bool set = true )
  1756. {
  1757. if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
  1758. else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
  1759. }
  1760. const wxString& GetHelpString() const
  1761. {
  1762. return m_helpString;
  1763. }
  1764. // Use, for example, to detect if item is inside collapsed section.
  1765. bool IsSomeParent( wxPGProperty* candidate_parent ) const;
  1766. /**
  1767. Adapts list variant into proper value using consecutive
  1768. ChildChanged-calls.
  1769. */
  1770. void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
  1771. #if wxPG_COMPATIBILITY_1_4
  1772. /**
  1773. Adds a private child property.
  1774. @deprecated Use AddPrivateChild() instead.
  1775. @see AddPrivateChild()
  1776. */
  1777. wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
  1778. #endif
  1779. /**
  1780. Adds a private child property. If you use this instead of
  1781. wxPropertyGridInterface::Insert() or
  1782. wxPropertyGridInterface::AppendIn(), then property's parental
  1783. type will automatically be set up to wxPG_PROP_AGGREGATE. In other
  1784. words, all properties of this property will become private.
  1785. */
  1786. void AddPrivateChild( wxPGProperty* prop );
  1787. /**
  1788. Appends a new child property.
  1789. */
  1790. wxPGProperty* AppendChild( wxPGProperty* prop )
  1791. {
  1792. return InsertChild(-1, prop);
  1793. }
  1794. /** Returns height of children, recursively, and
  1795. by taking expanded/collapsed status into account.
  1796. iMax is used when finding property y-positions.
  1797. */
  1798. int GetChildrenHeight( int lh, int iMax = -1 ) const;
  1799. /** Returns number of child properties */
  1800. unsigned int GetChildCount() const
  1801. {
  1802. return (unsigned int) m_children.size();
  1803. }
  1804. /** Returns sub-property at index i. */
  1805. wxPGProperty* Item( unsigned int i ) const
  1806. { return m_children[i]; }
  1807. /** Returns last sub-property.
  1808. */
  1809. wxPGProperty* Last() const { return m_children.back(); }
  1810. /** Returns index of given child property. */
  1811. int Index( const wxPGProperty* p ) const;
  1812. // Puts correct indexes to children
  1813. void FixIndicesOfChildren( unsigned int starthere = 0 );
  1814. /**
  1815. Converts image width into full image offset, with margins.
  1816. */
  1817. int GetImageOffset( int imageWidth ) const;
  1818. // Returns wxPropertyGridPageState in which this property resides.
  1819. wxPropertyGridPageState* GetParentState() const { return m_parentState; }
  1820. wxPGProperty* GetItemAtY( unsigned int y,
  1821. unsigned int lh,
  1822. unsigned int* nextItemY ) const;
  1823. /** Returns property at given virtual y coordinate.
  1824. */
  1825. wxPGProperty* GetItemAtY( unsigned int y ) const;
  1826. /** Returns (direct) child property with given name (or NULL if not found).
  1827. */
  1828. wxPGProperty* GetPropertyByName( const wxString& name ) const;
  1829. // Returns various display-related information for given column
  1830. void GetDisplayInfo( unsigned int column,
  1831. int choiceIndex,
  1832. int flags,
  1833. wxString* pString,
  1834. const wxPGCell** pCell );
  1835. static wxString* sm_wxPG_LABEL;
  1836. /** This member is public so scripting language bindings
  1837. wrapper code can access it freely.
  1838. */
  1839. void* m_clientData;
  1840. protected:
  1841. /**
  1842. Sets property cell in fashion that reduces number of exclusive
  1843. copies of cell data. Used when setting, for instance, same
  1844. background colour for a number of properties.
  1845. @param firstCol
  1846. First column to affect.
  1847. @param lastCol
  1848. Last column to affect.
  1849. @param preparedCell
  1850. Pre-prepared cell that is used for those which cell data
  1851. before this matched unmodCellData.
  1852. @param srcData
  1853. If unmodCellData did not match, valid cell data from this
  1854. is merged into cell (usually generating new exclusive copy
  1855. of cell's data).
  1856. @param unmodCellData
  1857. If cell's cell data matches this, its cell is now set to
  1858. preparedCell.
  1859. @param ignoreWithFlags
  1860. Properties with any one of these flags are skipped.
  1861. @param recursively
  1862. If @true, apply this operation recursively in child properties.
  1863. */
  1864. void AdaptiveSetCell( unsigned int firstCol,
  1865. unsigned int lastCol,
  1866. const wxPGCell& preparedCell,
  1867. const wxPGCell& srcData,
  1868. wxPGCellData* unmodCellData,
  1869. FlagType ignoreWithFlags,
  1870. bool recursively );
  1871. /**
  1872. Makes sure m_cells has size of column+1 (or more).
  1873. */
  1874. void EnsureCells( unsigned int column );
  1875. /** Returns (direct) child property with given name (or NULL if not found),
  1876. with hint index.
  1877. @param hintIndex
  1878. Start looking for the child at this index.
  1879. @remarks
  1880. Does not support scope (ie. Parent.Child notation).
  1881. */
  1882. wxPGProperty* GetPropertyByNameWH( const wxString& name,
  1883. unsigned int hintIndex ) const;
  1884. /** This is used by Insert etc. */
  1885. void DoAddChild( wxPGProperty* prop,
  1886. int index = -1,
  1887. bool correct_mode = true );
  1888. void DoGenerateComposedValue( wxString& text,
  1889. int argFlags = wxPG_VALUE_IS_CURRENT,
  1890. const wxVariantList* valueOverrides = NULL,
  1891. wxPGHashMapS2S* childResults = NULL ) const;
  1892. bool DoHide( bool hide, int flags );
  1893. void DoSetName(const wxString& str) { m_name = str; }
  1894. /** Deletes all sub-properties. */
  1895. void Empty();
  1896. bool HasCell( unsigned int column ) const
  1897. {
  1898. if ( m_cells.size() > column )
  1899. return true;
  1900. return false;
  1901. }
  1902. void InitAfterAdded( wxPropertyGridPageState* pageState,
  1903. wxPropertyGrid* propgrid );
  1904. /**
  1905. Returns true if child property is selected.
  1906. */
  1907. bool IsChildSelected( bool recursive = false ) const;
  1908. // Removes child property with given pointer. Does not delete it.
  1909. void RemoveChild( wxPGProperty* p );
  1910. void DoEnable( bool enable );
  1911. void DoPreAddChild( int index, wxPGProperty* prop );
  1912. void SetParentState( wxPropertyGridPageState* pstate )
  1913. { m_parentState = pstate; }
  1914. void SetFlag( wxPGPropertyFlags flag )
  1915. {
  1916. //
  1917. // NB: While using wxPGPropertyFlags here makes it difficult to
  1918. // combine different flags, it usefully prevents user from
  1919. // using incorrect flags (say, wxWindow styles).
  1920. m_flags |= flag;
  1921. }
  1922. void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
  1923. // Called when the property is being removed from the grid and/or
  1924. // page state (but *not* when it is also deleted).
  1925. void OnDetached(wxPropertyGridPageState* state,
  1926. wxPropertyGrid* propgrid);
  1927. // Call after fixed sub-properties added/removed after creation.
  1928. // if oldSelInd >= 0 and < new max items, then selection is
  1929. // moved to it.
  1930. void SubPropsChanged( int oldSelInd = -1 );
  1931. int GetY2( int lh ) const;
  1932. wxString m_label;
  1933. wxString m_name;
  1934. wxPGProperty* m_parent;
  1935. wxPropertyGridPageState* m_parentState;
  1936. wxClientData* m_clientObject;
  1937. // Overrides editor returned by property class
  1938. const wxPGEditor* m_customEditor;
  1939. #if wxUSE_VALIDATORS
  1940. // Editor is going to get this validator
  1941. wxValidator* m_validator;
  1942. #endif
  1943. // Show this in front of the value
  1944. //
  1945. // TODO: Can bitmap be implemented with wxPGCell?
  1946. wxBitmap* m_valueBitmap;
  1947. wxVariant m_value;
  1948. wxPGAttributeStorage m_attributes;
  1949. wxArrayPGProperty m_children;
  1950. // Extended cell information
  1951. wxVector<wxPGCell> m_cells;
  1952. // Choices shown in drop-down list of editor control.
  1953. wxPGChoices m_choices;
  1954. // Help shown in statusbar or help box.
  1955. wxString m_helpString;
  1956. // Index in parent's property array.
  1957. unsigned int m_arrIndex;
  1958. // If not -1, then overrides m_value
  1959. int m_commonValue;
  1960. FlagType m_flags;
  1961. // Maximum length (mainly for string properties). Could be in some sort of
  1962. // wxBaseStringProperty, but currently, for maximum flexibility and
  1963. // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
  1964. // so short int will fit in just fine.
  1965. short m_maxLen;
  1966. // Root has 0, categories etc. at that level 1, etc.
  1967. unsigned char m_depth;
  1968. // m_depthBgCol indicates width of background colour between margin and item
  1969. // (essentially this is category's depth, if none then equals m_depth).
  1970. unsigned char m_depthBgCol;
  1971. private:
  1972. // Called in constructors.
  1973. void Init();
  1974. void Init( const wxString& label, const wxString& name );
  1975. };
  1976. // -----------------------------------------------------------------------
  1977. //
  1978. // Property class declaration helper macros
  1979. // (wxPGRootPropertyClass and wxPropertyCategory require this).
  1980. //
  1981. #define WX_PG_DECLARE_DOGETEDITORCLASS \
  1982. virtual const wxPGEditor* DoGetEditorClass() const;
  1983. #ifndef WX_PG_DECLARE_PROPERTY_CLASS
  1984. #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
  1985. public: \
  1986. DECLARE_DYNAMIC_CLASS(CLASSNAME) \
  1987. WX_PG_DECLARE_DOGETEDITORCLASS \
  1988. private:
  1989. #endif
  1990. // Implements sans constructor function. Also, first arg is class name, not
  1991. // property name.
  1992. #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
  1993. const wxPGEditor* PROPNAME::DoGetEditorClass() const \
  1994. { \
  1995. return wxPGEditor_##EDITOR; \
  1996. }
  1997. // -----------------------------------------------------------------------
  1998. /** @class wxPGRootProperty
  1999. @ingroup classes
  2000. Root parent property.
  2001. */
  2002. class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
  2003. {
  2004. public:
  2005. WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
  2006. public:
  2007. /** Constructor. */
  2008. wxPGRootProperty( const wxString& name = wxS("<Root>") );
  2009. virtual ~wxPGRootProperty();
  2010. virtual bool StringToValue( wxVariant&, const wxString&, int ) const
  2011. {
  2012. return false;
  2013. }
  2014. protected:
  2015. };
  2016. // -----------------------------------------------------------------------
  2017. /** @class wxPropertyCategory
  2018. @ingroup classes
  2019. Category (caption) property.
  2020. */
  2021. class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
  2022. {
  2023. friend class wxPropertyGrid;
  2024. friend class wxPropertyGridPageState;
  2025. WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
  2026. public:
  2027. /** Default constructor is only used in special cases. */
  2028. wxPropertyCategory();
  2029. wxPropertyCategory( const wxString& label,
  2030. const wxString& name = wxPG_LABEL );
  2031. ~wxPropertyCategory();
  2032. int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
  2033. virtual wxString ValueToString( wxVariant& value, int argFlags ) const;
  2034. virtual wxString GetValueAsString( int argFlags = 0 ) const;
  2035. protected:
  2036. void SetTextColIndex( unsigned int colInd )
  2037. { m_capFgColIndex = (wxByte) colInd; }
  2038. unsigned int GetTextColIndex() const
  2039. { return (unsigned int) m_capFgColIndex; }
  2040. void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
  2041. int m_textExtent; // pre-calculated length of text
  2042. wxByte m_capFgColIndex; // caption text colour index
  2043. private:
  2044. void Init();
  2045. };
  2046. // -----------------------------------------------------------------------
  2047. #endif // wxUSE_PROPGRID
  2048. #endif // _WX_PROPGRID_PROPERTY_H_