props.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/propgrid/props.h
  3. // Purpose: wxPropertyGrid Property Classes
  4. // Author: Jaakko Salli
  5. // Modified by:
  6. // Created: 2007-03-28
  7. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_PROPGRID_PROPS_H_
  11. #define _WX_PROPGRID_PROPS_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_PROPGRID
  14. // -----------------------------------------------------------------------
  15. class wxPGArrayEditorDialog;
  16. #include "wx/propgrid/editors.h"
  17. #include "wx/filename.h"
  18. #include "wx/dialog.h"
  19. #include "wx/textctrl.h"
  20. #include "wx/button.h"
  21. #include "wx/listbox.h"
  22. #include "wx/valtext.h"
  23. // -----------------------------------------------------------------------
  24. //
  25. // Property class implementation helper macros.
  26. //
  27. #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME, UPCLASS, T, T_AS_ARG, EDITOR) \
  28. IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
  29. WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR)
  30. // -----------------------------------------------------------------------
  31. //
  32. // These macros help creating DoGetValidator
  33. #define WX_PG_DOGETVALIDATOR_ENTRY() \
  34. static wxValidator* s_ptr = NULL; \
  35. if ( s_ptr ) return s_ptr;
  36. // Common function exit
  37. #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
  38. s_ptr = VALIDATOR; \
  39. wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \
  40. return VALIDATOR;
  41. // -----------------------------------------------------------------------
  42. /** @class wxPGInDialogValidator
  43. @ingroup classes
  44. Creates and manages a temporary wxTextCtrl for validation purposes.
  45. Uses wxPropertyGrid's current editor, if available.
  46. */
  47. class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
  48. {
  49. public:
  50. wxPGInDialogValidator()
  51. {
  52. m_textCtrl = NULL;
  53. }
  54. ~wxPGInDialogValidator()
  55. {
  56. if ( m_textCtrl )
  57. m_textCtrl->Destroy();
  58. }
  59. bool DoValidate( wxPropertyGrid* propGrid,
  60. wxValidator* validator,
  61. const wxString& value );
  62. private:
  63. wxTextCtrl* m_textCtrl;
  64. };
  65. // -----------------------------------------------------------------------
  66. // Property classes
  67. // -----------------------------------------------------------------------
  68. #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
  69. /** @class wxStringProperty
  70. @ingroup classes
  71. Basic property with string value.
  72. <b>Supported special attributes:</b>
  73. - "Password": set to 1 in order to enable wxTE_PASSWORD on the editor.
  74. @remarks
  75. - If value "<composed>" is set, then actual value is formed (or composed)
  76. from values of child properties.
  77. */
  78. class WXDLLIMPEXP_PROPGRID wxStringProperty : public wxPGProperty
  79. {
  80. WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty)
  81. public:
  82. wxStringProperty( const wxString& label = wxPG_LABEL,
  83. const wxString& name = wxPG_LABEL,
  84. const wxString& value = wxEmptyString );
  85. virtual ~wxStringProperty();
  86. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  87. virtual bool StringToValue( wxVariant& variant,
  88. const wxString& text,
  89. int argFlags = 0 ) const;
  90. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  91. /** This is updated so "<composed>" special value can be handled.
  92. */
  93. virtual void OnSetValue();
  94. protected:
  95. };
  96. // -----------------------------------------------------------------------
  97. /** Constants used with NumericValidation<>().
  98. */
  99. enum wxPGNumericValidationConstants
  100. {
  101. /** Instead of modifying the value, show an error message.
  102. */
  103. wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE = 0,
  104. /** Modify value, but stick with the limitations.
  105. */
  106. wxPG_PROPERTY_VALIDATION_SATURATE = 1,
  107. /** Modify value, wrap around on overflow.
  108. */
  109. wxPG_PROPERTY_VALIDATION_WRAP = 2
  110. };
  111. // -----------------------------------------------------------------------
  112. #if wxUSE_VALIDATORS
  113. /**
  114. A more comprehensive numeric validator class.
  115. */
  116. class WXDLLIMPEXP_PROPGRID wxNumericPropertyValidator : public wxTextValidator
  117. {
  118. public:
  119. enum NumericType
  120. {
  121. Signed = 0,
  122. Unsigned,
  123. Float
  124. };
  125. wxNumericPropertyValidator( NumericType numericType, int base = 10 );
  126. virtual ~wxNumericPropertyValidator() { }
  127. virtual bool Validate(wxWindow* parent);
  128. };
  129. #endif // wxUSE_VALIDATORS
  130. /** @class wxIntProperty
  131. @ingroup classes
  132. Basic property with integer value.
  133. Seamlessly supports 64-bit integer (wxLongLong) on overflow.
  134. <b>Example how to use seamless 64-bit integer support</b>
  135. Getting value:
  136. @code
  137. wxLongLong_t value = pg->GetPropertyValueAsLongLong();
  138. @endcode
  139. or
  140. @code
  141. wxLongLong_t value;
  142. wxVariant variant = property->GetValue();
  143. if ( variant.GetType() == "wxLongLong" )
  144. value = wxLongLongFromVariant(variant);
  145. else
  146. value = variant.GetLong();
  147. @endcode
  148. Setting value:
  149. @code
  150. pg->SetPropertyValue(longLongVal);
  151. @endcode
  152. or
  153. @code
  154. property->SetValue(WXVARIANT(longLongVal));
  155. @endcode
  156. <b>Supported special attributes:</b>
  157. - "Min", "Max": Specify acceptable value range.
  158. */
  159. class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty
  160. {
  161. WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty)
  162. public:
  163. wxIntProperty( const wxString& label = wxPG_LABEL,
  164. const wxString& name = wxPG_LABEL,
  165. long value = 0 );
  166. virtual ~wxIntProperty();
  167. wxIntProperty( const wxString& label,
  168. const wxString& name,
  169. const wxLongLong& value );
  170. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  171. virtual bool StringToValue( wxVariant& variant,
  172. const wxString& text,
  173. int argFlags = 0 ) const;
  174. virtual bool ValidateValue( wxVariant& value,
  175. wxPGValidationInfo& validationInfo ) const;
  176. virtual bool IntToValue( wxVariant& variant,
  177. int number,
  178. int argFlags = 0 ) const;
  179. static wxValidator* GetClassValidator();
  180. virtual wxValidator* DoGetValidator() const;
  181. /** Validation helper.
  182. */
  183. static bool DoValidation( const wxPGProperty* property,
  184. wxLongLong_t& value,
  185. wxPGValidationInfo* pValidationInfo,
  186. int mode =
  187. wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
  188. protected:
  189. };
  190. // -----------------------------------------------------------------------
  191. /** @class wxUIntProperty
  192. @ingroup classes
  193. Basic property with unsigned integer value.
  194. Seamlessly supports 64-bit integer (wxULongLong) on overflow.
  195. <b>Supported special attributes:</b>
  196. - "Min", "Max": Specify acceptable value range.
  197. - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
  198. wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
  199. are <b>not</b> supported.
  200. - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
  201. wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
  202. numbers.
  203. @remarks
  204. - For example how to use seamless 64-bit integer support, see wxIntProperty
  205. documentation (just use wxULongLong instead of wxLongLong).
  206. */
  207. class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty
  208. {
  209. WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty)
  210. public:
  211. wxUIntProperty( const wxString& label = wxPG_LABEL,
  212. const wxString& name = wxPG_LABEL,
  213. unsigned long value = 0 );
  214. virtual ~wxUIntProperty();
  215. wxUIntProperty( const wxString& label,
  216. const wxString& name,
  217. const wxULongLong& value );
  218. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  219. virtual bool StringToValue( wxVariant& variant,
  220. const wxString& text,
  221. int argFlags = 0 ) const;
  222. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  223. virtual bool ValidateValue( wxVariant& value,
  224. wxPGValidationInfo& validationInfo ) const;
  225. virtual wxValidator* DoGetValidator () const;
  226. virtual bool IntToValue( wxVariant& variant,
  227. int number,
  228. int argFlags = 0 ) const;
  229. protected:
  230. wxByte m_base;
  231. wxByte m_realBase; // translated to 8,16,etc.
  232. wxByte m_prefix;
  233. private:
  234. void Init();
  235. };
  236. // -----------------------------------------------------------------------
  237. /** @class wxFloatProperty
  238. @ingroup classes
  239. Basic property with double-precision floating point value.
  240. <b>Supported special attributes:</b>
  241. - "Precision": Sets the (max) precision used when floating point value is
  242. rendered as text. The default -1 means infinite precision.
  243. */
  244. class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty
  245. {
  246. WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty)
  247. public:
  248. wxFloatProperty( const wxString& label = wxPG_LABEL,
  249. const wxString& name = wxPG_LABEL,
  250. double value = 0.0 );
  251. virtual ~wxFloatProperty();
  252. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  253. virtual bool StringToValue( wxVariant& variant,
  254. const wxString& text,
  255. int argFlags = 0 ) const;
  256. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  257. virtual bool ValidateValue( wxVariant& value,
  258. wxPGValidationInfo& validationInfo ) const;
  259. /** Validation helper.
  260. */
  261. static bool DoValidation( const wxPGProperty* property,
  262. double& value,
  263. wxPGValidationInfo* pValidationInfo,
  264. int mode =
  265. wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
  266. static wxValidator* GetClassValidator();
  267. virtual wxValidator* DoGetValidator () const;
  268. protected:
  269. int m_precision;
  270. };
  271. // -----------------------------------------------------------------------
  272. /** @class wxBoolProperty
  273. @ingroup classes
  274. Basic property with boolean value.
  275. <b>Supported special attributes:</b>
  276. - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
  277. - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
  278. */
  279. class WXDLLIMPEXP_PROPGRID wxBoolProperty : public wxPGProperty
  280. {
  281. WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty)
  282. public:
  283. wxBoolProperty( const wxString& label = wxPG_LABEL,
  284. const wxString& name = wxPG_LABEL,
  285. bool value = false );
  286. virtual ~wxBoolProperty();
  287. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  288. virtual bool StringToValue( wxVariant& variant,
  289. const wxString& text,
  290. int argFlags = 0 ) const;
  291. virtual bool IntToValue( wxVariant& variant,
  292. int number, int argFlags = 0 ) const;
  293. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  294. };
  295. // -----------------------------------------------------------------------
  296. // If set, then selection of choices is static and should not be
  297. // changed (i.e. returns NULL in GetPropertyChoices).
  298. #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
  299. /** @class wxEnumProperty
  300. @ingroup classes
  301. You can derive custom properties with choices from this class. See
  302. wxBaseEnumProperty for remarks.
  303. @remarks
  304. - Updating private index is important. You can do this either by calling
  305. SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
  306. be called (by not implementing it, or by calling super class function in
  307. it) -OR- you can just call SetIndex in OnSetValue.
  308. */
  309. class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty
  310. {
  311. WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
  312. public:
  313. #ifndef SWIG
  314. wxEnumProperty( const wxString& label = wxPG_LABEL,
  315. const wxString& name = wxPG_LABEL,
  316. const wxChar* const* labels = NULL,
  317. const long* values = NULL,
  318. int value = 0 );
  319. wxEnumProperty( const wxString& label,
  320. const wxString& name,
  321. wxPGChoices& choices,
  322. int value = 0 );
  323. // Special constructor for caching choices (used by derived class)
  324. wxEnumProperty( const wxString& label,
  325. const wxString& name,
  326. const wxChar* const* labels,
  327. const long* values,
  328. wxPGChoices* choicesCache,
  329. int value = 0 );
  330. wxEnumProperty( const wxString& label,
  331. const wxString& name,
  332. const wxArrayString& labels,
  333. const wxArrayInt& values = wxArrayInt(),
  334. int value = 0 );
  335. #else
  336. wxEnumProperty( const wxString& label = wxPG_LABEL,
  337. const wxString& name = wxPG_LABEL,
  338. const wxArrayString& labels = wxArrayString(),
  339. const wxArrayInt& values = wxArrayInt(),
  340. int value = 0 );
  341. #endif
  342. virtual ~wxEnumProperty();
  343. size_t GetItemCount() const { return m_choices.GetCount(); }
  344. virtual void OnSetValue();
  345. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  346. virtual bool StringToValue( wxVariant& variant,
  347. const wxString& text,
  348. int argFlags = 0 ) const;
  349. virtual bool ValidateValue( wxVariant& value,
  350. wxPGValidationInfo& validationInfo ) const;
  351. // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
  352. // as index to choices list. Otherwise, it is actual value.
  353. virtual bool IntToValue( wxVariant& variant,
  354. int number,
  355. int argFlags = 0 ) const;
  356. //
  357. // Additional virtuals
  358. // This must be overridden to have non-index based value
  359. virtual int GetIndexForValue( int value ) const;
  360. // GetChoiceSelection needs to overridden since m_index is
  361. // the true index, and various property classes derived from
  362. // this take advantage of it.
  363. virtual int GetChoiceSelection() const { return m_index; }
  364. virtual void OnValidationFailure( wxVariant& pendingValue );
  365. protected:
  366. int GetIndex() const;
  367. void SetIndex( int index );
  368. bool ValueFromString_( wxVariant& value,
  369. const wxString& text,
  370. int argFlags ) const;
  371. bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
  372. static void ResetNextIndex() { ms_nextIndex = -2; }
  373. private:
  374. // This is private so that classes are guaranteed to use GetIndex
  375. // for up-to-date index value.
  376. int m_index;
  377. // Relies on ValidateValue being called always before OnSetValue
  378. static int ms_nextIndex;
  379. };
  380. // -----------------------------------------------------------------------
  381. /** @class wxEditEnumProperty
  382. @ingroup classes
  383. wxEnumProperty with wxString value and writable combo box editor.
  384. @remarks
  385. Uses int value, similar to wxEnumProperty, unless text entered by user is
  386. is not in choices (in which case string value is used).
  387. */
  388. class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty
  389. {
  390. WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty)
  391. public:
  392. wxEditEnumProperty( const wxString& label,
  393. const wxString& name,
  394. const wxChar* const* labels,
  395. const long* values,
  396. const wxString& value );
  397. wxEditEnumProperty( const wxString& label = wxPG_LABEL,
  398. const wxString& name = wxPG_LABEL,
  399. const wxArrayString& labels = wxArrayString(),
  400. const wxArrayInt& values = wxArrayInt(),
  401. const wxString& value = wxEmptyString );
  402. wxEditEnumProperty( const wxString& label,
  403. const wxString& name,
  404. wxPGChoices& choices,
  405. const wxString& value = wxEmptyString );
  406. // Special constructor for caching choices (used by derived class)
  407. wxEditEnumProperty( const wxString& label,
  408. const wxString& name,
  409. const wxChar* const* labels,
  410. const long* values,
  411. wxPGChoices* choicesCache,
  412. const wxString& value );
  413. virtual ~wxEditEnumProperty();
  414. protected:
  415. };
  416. // -----------------------------------------------------------------------
  417. /** @class wxFlagsProperty
  418. @ingroup classes
  419. Represents a bit set that fits in a long integer. wxBoolProperty
  420. sub-properties are created for editing individual bits. Textctrl is created
  421. to manually edit the flags as a text; a continuous sequence of spaces,
  422. commas and semicolons is considered as a flag id separator.
  423. <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
  424. you will need to use SetPropertyChoices - otherwise they will not get
  425. updated properly.
  426. */
  427. class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty
  428. {
  429. WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty)
  430. public:
  431. #ifndef SWIG
  432. wxFlagsProperty( const wxString& label,
  433. const wxString& name,
  434. const wxChar* const* labels,
  435. const long* values = NULL,
  436. long value = 0 );
  437. wxFlagsProperty( const wxString& label,
  438. const wxString& name,
  439. wxPGChoices& choices,
  440. long value = 0 );
  441. #endif
  442. wxFlagsProperty( const wxString& label = wxPG_LABEL,
  443. const wxString& name = wxPG_LABEL,
  444. const wxArrayString& labels = wxArrayString(),
  445. const wxArrayInt& values = wxArrayInt(),
  446. int value = 0 );
  447. virtual ~wxFlagsProperty ();
  448. virtual void OnSetValue();
  449. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  450. virtual bool StringToValue( wxVariant& variant,
  451. const wxString& text,
  452. int flags ) const;
  453. virtual wxVariant ChildChanged( wxVariant& thisValue,
  454. int childIndex,
  455. wxVariant& childValue ) const;
  456. virtual void RefreshChildren();
  457. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  458. // GetChoiceSelection needs to overridden since m_choices is
  459. // used and value is integer, but it is not index.
  460. virtual int GetChoiceSelection() const { return wxNOT_FOUND; }
  461. // helpers
  462. size_t GetItemCount() const { return m_choices.GetCount(); }
  463. const wxString& GetLabel( size_t ind ) const
  464. { return m_choices.GetLabel(static_cast<int>(ind)); }
  465. protected:
  466. // Used to detect if choices have been changed
  467. wxPGChoicesData* m_oldChoicesData;
  468. // Needed to properly mark changed sub-properties
  469. long m_oldValue;
  470. // Converts string id to a relevant bit.
  471. long IdToBit( const wxString& id ) const;
  472. // Creates children and sets value.
  473. void Init();
  474. };
  475. // -----------------------------------------------------------------------
  476. /** @class wxPGFileDialogAdapter
  477. @ingroup classes
  478. */
  479. class WXDLLIMPEXP_PROPGRID
  480. wxPGFileDialogAdapter : public wxPGEditorDialogAdapter
  481. {
  482. public:
  483. virtual bool DoShowDialog( wxPropertyGrid* propGrid,
  484. wxPGProperty* property );
  485. };
  486. // -----------------------------------------------------------------------
  487. // Indicates first bit useable by derived properties.
  488. #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
  489. /** @class wxFileProperty
  490. @ingroup classes
  491. Like wxLongStringProperty, but the button triggers file selector instead.
  492. <b>Supported special attributes:</b>
  493. - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
  494. files..." is default.
  495. - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
  496. and directory are hidden).
  497. - "ShowRelativePath": If set, then the filename is shown relative to the
  498. given path string.
  499. - "InitialPath": Sets the initial path of where to look for files.
  500. - "DialogTitle": Sets a specific title for the dir dialog.
  501. */
  502. class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty
  503. {
  504. friend class wxPGFileDialogAdapter;
  505. WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty)
  506. public:
  507. wxFileProperty( const wxString& label = wxPG_LABEL,
  508. const wxString& name = wxPG_LABEL,
  509. const wxString& value = wxEmptyString );
  510. virtual ~wxFileProperty ();
  511. virtual void OnSetValue();
  512. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  513. virtual bool StringToValue( wxVariant& variant,
  514. const wxString& text,
  515. int argFlags = 0 ) const;
  516. virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
  517. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  518. static wxValidator* GetClassValidator();
  519. virtual wxValidator* DoGetValidator() const;
  520. /**
  521. Returns filename to file represented by current value.
  522. */
  523. wxFileName GetFileName() const;
  524. protected:
  525. wxString m_wildcard;
  526. wxString m_basePath; // If set, then show path relative to it
  527. wxString m_initialPath; // If set, start the file dialog here
  528. wxString m_dlgTitle; // If set, used as title for file dialog
  529. int m_indFilter; // index to the selected filter
  530. };
  531. // -----------------------------------------------------------------------
  532. #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
  533. /** @class wxPGLongStringDialogAdapter
  534. @ingroup classes
  535. */
  536. class WXDLLIMPEXP_PROPGRID
  537. wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter
  538. {
  539. public:
  540. virtual bool DoShowDialog( wxPropertyGrid* propGrid,
  541. wxPGProperty* property );
  542. };
  543. /** @class wxLongStringProperty
  544. @ingroup classes
  545. Like wxStringProperty, but has a button that triggers a small text
  546. editor dialog.
  547. */
  548. class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty
  549. {
  550. WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty)
  551. public:
  552. wxLongStringProperty( const wxString& label = wxPG_LABEL,
  553. const wxString& name = wxPG_LABEL,
  554. const wxString& value = wxEmptyString );
  555. virtual ~wxLongStringProperty();
  556. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  557. virtual bool StringToValue( wxVariant& variant,
  558. const wxString& text,
  559. int argFlags = 0 ) const;
  560. virtual bool OnEvent( wxPropertyGrid* propgrid,
  561. wxWindow* primary, wxEvent& event );
  562. // Shows string editor dialog. Value to be edited should be read from
  563. // value, and if dialog is not cancelled, it should be stored back and true
  564. // should be returned if that was the case.
  565. virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value );
  566. static bool DisplayEditorDialog( wxPGProperty* prop,
  567. wxPropertyGrid* propGrid,
  568. wxString& value );
  569. protected:
  570. };
  571. // -----------------------------------------------------------------------
  572. /** @class wxDirProperty
  573. @ingroup classes
  574. Like wxLongStringProperty, but the button triggers dir selector instead.
  575. <b>Supported special attributes:</b>
  576. - "DialogMessage": Sets specific message in the dir selector.
  577. */
  578. class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty
  579. {
  580. DECLARE_DYNAMIC_CLASS(wxDirProperty)
  581. public:
  582. wxDirProperty( const wxString& name = wxPG_LABEL,
  583. const wxString& label = wxPG_LABEL,
  584. const wxString& value = wxEmptyString );
  585. virtual ~wxDirProperty();
  586. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  587. virtual wxValidator* DoGetValidator() const;
  588. virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value );
  589. protected:
  590. wxString m_dlgMessage;
  591. };
  592. // -----------------------------------------------------------------------
  593. // wxBoolProperty specific flags
  594. #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
  595. // DCC = Double Click Cycles
  596. #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
  597. // -----------------------------------------------------------------------
  598. /** @class wxArrayStringProperty
  599. @ingroup classes
  600. Property that manages a list of strings.
  601. */
  602. class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty
  603. {
  604. WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
  605. public:
  606. wxArrayStringProperty( const wxString& label = wxPG_LABEL,
  607. const wxString& name = wxPG_LABEL,
  608. const wxArrayString& value = wxArrayString() );
  609. virtual ~wxArrayStringProperty();
  610. virtual void OnSetValue();
  611. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  612. virtual bool StringToValue( wxVariant& variant,
  613. const wxString& text,
  614. int argFlags = 0 ) const;
  615. virtual bool OnEvent( wxPropertyGrid* propgrid,
  616. wxWindow* primary, wxEvent& event );
  617. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  618. // Implement in derived class for custom array-to-string conversion.
  619. virtual void ConvertArrayToString(const wxArrayString& arr,
  620. wxString* pString,
  621. const wxUniChar& delimiter) const;
  622. // Shows string editor dialog. Value to be edited should be read from
  623. // value, and if dialog is not cancelled, it should be stored back and true
  624. // should be returned if that was the case.
  625. virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
  626. // Helper.
  627. virtual bool OnButtonClick( wxPropertyGrid* propgrid,
  628. wxWindow* primary,
  629. const wxChar* cbt );
  630. // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
  631. virtual wxPGArrayEditorDialog* CreateEditorDialog();
  632. enum ConversionFlags
  633. {
  634. Escape = 0x01,
  635. QuoteStrings = 0x02
  636. };
  637. /**
  638. Generates contents for string dst based on the contents of
  639. wxArrayString src.
  640. */
  641. static void ArrayStringToString( wxString& dst, const wxArrayString& src,
  642. wxUniChar delimiter, int flags );
  643. protected:
  644. // Previously this was to be implemented in derived class for array-to-
  645. // string conversion. Now you should implement ConvertValueToString()
  646. // instead.
  647. virtual void GenerateValueAsString();
  648. wxString m_display; // Cache for displayed text.
  649. wxUniChar m_delimiter;
  650. };
  651. // -----------------------------------------------------------------------
  652. #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
  653. DECL) \
  654. DECL PROPNAME : public wxArrayStringProperty \
  655. { \
  656. WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
  657. public: \
  658. PROPNAME( const wxString& label = wxPG_LABEL, \
  659. const wxString& name = wxPG_LABEL, \
  660. const wxArrayString& value = wxArrayString() ); \
  661. ~PROPNAME(); \
  662. virtual bool OnEvent( wxPropertyGrid* propgrid, \
  663. wxWindow* primary, wxEvent& event ); \
  664. virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
  665. virtual wxValidator* DoGetValidator() const; \
  666. };
  667. #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
  668. WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
  669. #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
  670. DELIMCHAR, \
  671. CUSTBUTTXT) \
  672. WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
  673. wxArrayString, const wxArrayString&, \
  674. TextCtrlAndButton) \
  675. PROPNAME::PROPNAME( const wxString& label, \
  676. const wxString& name, \
  677. const wxArrayString& value ) \
  678. : wxArrayStringProperty(label,name,value) \
  679. { \
  680. PROPNAME::GenerateValueAsString(); \
  681. m_delimiter = DELIMCHAR; \
  682. } \
  683. PROPNAME::~PROPNAME() { } \
  684. bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
  685. wxWindow* primary, wxEvent& event ) \
  686. { \
  687. if ( event.GetEventType() == wxEVT_BUTTON ) \
  688. return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
  689. return false; \
  690. }
  691. #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
  692. WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
  693. #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
  694. WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
  695. #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
  696. WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
  697. DELIMCHAR, \
  698. CUSTBUTTXT) \
  699. wxValidator* PROPNAME::DoGetValidator () const \
  700. { return NULL; }
  701. // -----------------------------------------------------------------------
  702. // wxPGArrayEditorDialog
  703. // -----------------------------------------------------------------------
  704. #if wxUSE_EDITABLELISTBOX
  705. class WXDLLIMPEXP_FWD_ADV wxEditableListBox;
  706. class WXDLLIMPEXP_FWD_CORE wxListEvent;
  707. #define wxAEDIALOG_STYLE \
  708. (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
  709. class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog : public wxDialog
  710. {
  711. public:
  712. wxPGArrayEditorDialog();
  713. virtual ~wxPGArrayEditorDialog() { }
  714. void Init();
  715. wxPGArrayEditorDialog( wxWindow *parent,
  716. const wxString& message,
  717. const wxString& caption,
  718. long style = wxAEDIALOG_STYLE,
  719. const wxPoint& pos = wxDefaultPosition,
  720. const wxSize& sz = wxDefaultSize );
  721. bool Create( wxWindow *parent,
  722. const wxString& message,
  723. const wxString& caption,
  724. long style = wxAEDIALOG_STYLE,
  725. const wxPoint& pos = wxDefaultPosition,
  726. const wxSize& sz = wxDefaultSize );
  727. void EnableCustomNewAction()
  728. {
  729. m_hasCustomNewAction = true;
  730. }
  731. /** Set value modified by dialog.
  732. */
  733. virtual void SetDialogValue( const wxVariant& WXUNUSED(value) )
  734. {
  735. wxFAIL_MSG(wxT("re-implement this member function in derived class"));
  736. }
  737. /** Return value modified by dialog.
  738. */
  739. virtual wxVariant GetDialogValue() const
  740. {
  741. wxFAIL_MSG(wxT("re-implement this member function in derived class"));
  742. return wxVariant();
  743. }
  744. /** Override to return wxValidator to be used with the wxTextCtrl
  745. in dialog. Note that the validator is used in the standard
  746. wx way, ie. it immediately prevents user from entering invalid
  747. input.
  748. @remarks
  749. Dialog frees the validator.
  750. */
  751. virtual wxValidator* GetTextCtrlValidator() const
  752. {
  753. return NULL;
  754. }
  755. // Returns true if array was actually modified
  756. bool IsModified() const { return m_modified; }
  757. // wxEditableListBox utilities
  758. int GetSelection() const;
  759. // implementation from now on
  760. void OnAddClick(wxCommandEvent& event);
  761. void OnDeleteClick(wxCommandEvent& event);
  762. void OnUpClick(wxCommandEvent& event);
  763. void OnDownClick(wxCommandEvent& event);
  764. void OnEndLabelEdit(wxListEvent& event);
  765. void OnIdle(wxIdleEvent& event);
  766. protected:
  767. wxEditableListBox* m_elb;
  768. // These are used for focus repair
  769. wxWindow* m_elbSubPanel;
  770. wxWindow* m_lastFocused;
  771. // A new item, edited by user, is pending at this index.
  772. // It will be committed once list ctrl item editing is done.
  773. int m_itemPendingAtIndex;
  774. bool m_modified;
  775. bool m_hasCustomNewAction;
  776. // These must be overridden - must return true on success.
  777. virtual wxString ArrayGet( size_t index ) = 0;
  778. virtual size_t ArrayGetCount() = 0;
  779. virtual bool ArrayInsert( const wxString& str, int index ) = 0;
  780. virtual bool ArraySet( size_t index, const wxString& str ) = 0;
  781. virtual void ArrayRemoveAt( int index ) = 0;
  782. virtual void ArraySwap( size_t first, size_t second ) = 0;
  783. virtual bool OnCustomNewAction(wxString* WXUNUSED(resString))
  784. {
  785. return false;
  786. }
  787. private:
  788. DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog)
  789. DECLARE_EVENT_TABLE()
  790. };
  791. #endif // wxUSE_EDITABLELISTBOX
  792. // -----------------------------------------------------------------------
  793. // wxPGArrayStringEditorDialog
  794. // -----------------------------------------------------------------------
  795. class WXDLLIMPEXP_PROPGRID
  796. wxPGArrayStringEditorDialog : public wxPGArrayEditorDialog
  797. {
  798. public:
  799. wxPGArrayStringEditorDialog();
  800. virtual ~wxPGArrayStringEditorDialog() { }
  801. void Init();
  802. virtual void SetDialogValue( const wxVariant& value )
  803. {
  804. m_array = value.GetArrayString();
  805. }
  806. virtual wxVariant GetDialogValue() const
  807. {
  808. return m_array;
  809. }
  810. void SetCustomButton( const wxString& custBtText,
  811. wxArrayStringProperty* pcc )
  812. {
  813. if ( !custBtText.empty() )
  814. {
  815. EnableCustomNewAction();
  816. m_pCallingClass = pcc;
  817. }
  818. }
  819. virtual bool OnCustomNewAction(wxString* resString);
  820. protected:
  821. wxArrayString m_array;
  822. wxArrayStringProperty* m_pCallingClass;
  823. virtual wxString ArrayGet( size_t index );
  824. virtual size_t ArrayGetCount();
  825. virtual bool ArrayInsert( const wxString& str, int index );
  826. virtual bool ArraySet( size_t index, const wxString& str );
  827. virtual void ArrayRemoveAt( int index );
  828. virtual void ArraySwap( size_t first, size_t second );
  829. private:
  830. DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog)
  831. DECLARE_EVENT_TABLE()
  832. };
  833. // -----------------------------------------------------------------------
  834. #endif // wxUSE_PROPGRID
  835. #endif // _WX_PROPGRID_PROPS_H_