advprops.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/propgrid/advprops.h
  3. // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
  4. // Author: Jaakko Salli
  5. // Modified by:
  6. // Created: 2004-09-25
  7. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_PROPGRID_ADVPROPS_H_
  11. #define _WX_PROPGRID_ADVPROPS_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_PROPGRID
  14. #include "wx/propgrid/props.h"
  15. // -----------------------------------------------------------------------
  16. //
  17. // Additional Value Type Handlers
  18. //
  19. bool WXDLLIMPEXP_PROPGRID
  20. operator==(const wxArrayInt& array1, const wxArrayInt& array2);
  21. //
  22. // Additional Property Editors
  23. //
  24. #if wxUSE_SPINBTN
  25. WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl,WXDLLIMPEXP_PROPGRID)
  26. #endif
  27. #if wxUSE_DATEPICKCTRL
  28. WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl,WXDLLIMPEXP_PROPGRID)
  29. #endif
  30. // -----------------------------------------------------------------------
  31. // Web colour is currently unsupported
  32. #define wxPG_COLOUR_WEB_BASE 0x10000
  33. //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
  34. #define wxPG_COLOUR_CUSTOM 0xFFFFFF
  35. #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
  36. /** @class wxColourPropertyValue
  37. Because text, background and other colours tend to differ between
  38. platforms, wxSystemColourProperty must be able to select between system
  39. colour and, when necessary, to pick a custom one. wxSystemColourProperty
  40. value makes this possible.
  41. */
  42. class WXDLLIMPEXP_PROPGRID wxColourPropertyValue : public wxObject
  43. {
  44. public:
  45. /** An integer value relating to the colour, and which exact
  46. meaning depends on the property with which it is used.
  47. For wxSystemColourProperty:
  48. Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
  49. macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
  50. For custom colour properties without values array specified:
  51. index or wxPG_COLOUR_CUSTOM
  52. For custom colour properties <b>with</b> values array specified:
  53. m_arrValues[index] or wxPG_COLOUR_CUSTOM
  54. */
  55. wxUint32 m_type;
  56. /** Resulting colour. Should be correct regardless of type. */
  57. wxColour m_colour;
  58. wxColourPropertyValue()
  59. : wxObject()
  60. {
  61. m_type = 0;
  62. }
  63. virtual ~wxColourPropertyValue()
  64. {
  65. }
  66. wxColourPropertyValue( const wxColourPropertyValue& v )
  67. : wxObject()
  68. {
  69. m_type = v.m_type;
  70. m_colour = v.m_colour;
  71. }
  72. void Init( wxUint32 type, const wxColour& colour )
  73. {
  74. m_type = type;
  75. m_colour = colour;
  76. }
  77. wxColourPropertyValue( const wxColour& colour )
  78. : wxObject()
  79. {
  80. m_type = wxPG_COLOUR_CUSTOM;
  81. m_colour = colour;
  82. }
  83. wxColourPropertyValue( wxUint32 type )
  84. : wxObject()
  85. {
  86. m_type = type;
  87. }
  88. wxColourPropertyValue( wxUint32 type, const wxColour& colour )
  89. : wxObject()
  90. {
  91. Init( type, colour );
  92. }
  93. void operator=(const wxColourPropertyValue& cpv)
  94. {
  95. if (this != &cpv)
  96. Init( cpv.m_type, cpv.m_colour );
  97. }
  98. private:
  99. DECLARE_DYNAMIC_CLASS(wxColourPropertyValue)
  100. };
  101. bool WXDLLIMPEXP_PROPGRID
  102. operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
  103. DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
  104. // -----------------------------------------------------------------------
  105. // Declare part of custom colour property macro pairs.
  106. #if wxUSE_IMAGE
  107. #include "wx/image.h"
  108. #endif
  109. // -----------------------------------------------------------------------
  110. /** @class wxFontProperty
  111. @ingroup classes
  112. Property representing wxFont.
  113. */
  114. class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
  115. {
  116. WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
  117. public:
  118. wxFontProperty(const wxString& label = wxPG_LABEL,
  119. const wxString& name = wxPG_LABEL,
  120. const wxFont& value = wxFont());
  121. virtual ~wxFontProperty();
  122. virtual void OnSetValue();
  123. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  124. virtual bool OnEvent( wxPropertyGrid* propgrid,
  125. wxWindow* primary, wxEvent& event );
  126. virtual wxVariant ChildChanged( wxVariant& thisValue,
  127. int childIndex,
  128. wxVariant& childValue ) const;
  129. virtual void RefreshChildren();
  130. protected:
  131. };
  132. // -----------------------------------------------------------------------
  133. /** If set, then match from list is searched for a custom colour. */
  134. #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
  135. /** @class wxSystemColourProperty
  136. @ingroup classes
  137. Has dropdown list of wxWidgets system colours. Value used is
  138. of wxColourPropertyValue type.
  139. */
  140. class WXDLLIMPEXP_PROPGRID wxSystemColourProperty : public wxEnumProperty
  141. {
  142. WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty)
  143. public:
  144. wxSystemColourProperty( const wxString& label = wxPG_LABEL,
  145. const wxString& name = wxPG_LABEL,
  146. const wxColourPropertyValue&
  147. value = wxColourPropertyValue() );
  148. virtual ~wxSystemColourProperty();
  149. virtual void OnSetValue();
  150. virtual bool IntToValue(wxVariant& variant,
  151. int number,
  152. int argFlags = 0) const;
  153. /**
  154. Override in derived class to customize how colours are printed as
  155. strings.
  156. */
  157. virtual wxString ColourToString( const wxColour& col, int index,
  158. int argFlags = 0 ) const;
  159. /** Returns index of entry that triggers colour picker dialog
  160. (default is last).
  161. */
  162. virtual int GetCustomColourIndex() const;
  163. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  164. virtual bool StringToValue( wxVariant& variant,
  165. const wxString& text,
  166. int argFlags = 0 ) const;
  167. virtual bool OnEvent( wxPropertyGrid* propgrid,
  168. wxWindow* primary, wxEvent& event );
  169. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  170. virtual wxSize OnMeasureImage( int item ) const;
  171. virtual void OnCustomPaint( wxDC& dc,
  172. const wxRect& rect, wxPGPaintData& paintdata );
  173. // Helper function to show the colour dialog
  174. bool QueryColourFromUser( wxVariant& variant ) const;
  175. /** Default is to use wxSystemSettings::GetColour(index). Override to use
  176. custom colour tables etc.
  177. */
  178. virtual wxColour GetColour( int index ) const;
  179. wxColourPropertyValue GetVal( const wxVariant* pVariant = NULL ) const;
  180. protected:
  181. // Special constructors to be used by derived classes.
  182. wxSystemColourProperty( const wxString& label, const wxString& name,
  183. const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
  184. const wxColourPropertyValue& value );
  185. wxSystemColourProperty( const wxString& label, const wxString& name,
  186. const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
  187. const wxColour& value );
  188. void Init( int type, const wxColour& colour );
  189. // Utility functions for internal use
  190. virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
  191. wxVariant TranslateVal( wxColourPropertyValue& v ) const
  192. {
  193. return DoTranslateVal( v );
  194. }
  195. wxVariant TranslateVal( int type, const wxColour& colour ) const
  196. {
  197. wxColourPropertyValue v(type, colour);
  198. return DoTranslateVal( v );
  199. }
  200. // Translates colour to a int value, return wxNOT_FOUND if no match.
  201. int ColToInd( const wxColour& colour ) const;
  202. };
  203. // -----------------------------------------------------------------------
  204. class WXDLLIMPEXP_PROPGRID wxColourProperty : public wxSystemColourProperty
  205. {
  206. WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty)
  207. public:
  208. wxColourProperty( const wxString& label = wxPG_LABEL,
  209. const wxString& name = wxPG_LABEL,
  210. const wxColour& value = *wxWHITE );
  211. virtual ~wxColourProperty();
  212. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  213. virtual wxColour GetColour( int index ) const;
  214. protected:
  215. virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
  216. private:
  217. void Init( wxColour colour );
  218. };
  219. // -----------------------------------------------------------------------
  220. /** @class wxCursorProperty
  221. @ingroup classes
  222. Property representing wxCursor.
  223. */
  224. class WXDLLIMPEXP_PROPGRID wxCursorProperty : public wxEnumProperty
  225. {
  226. DECLARE_DYNAMIC_CLASS(wxCursorProperty)
  227. wxCursorProperty( const wxString& label= wxPG_LABEL,
  228. const wxString& name= wxPG_LABEL,
  229. int value = 0 );
  230. virtual ~wxCursorProperty();
  231. virtual wxSize OnMeasureImage( int item ) const;
  232. virtual void OnCustomPaint( wxDC& dc,
  233. const wxRect& rect, wxPGPaintData& paintdata );
  234. };
  235. // -----------------------------------------------------------------------
  236. #if wxUSE_IMAGE
  237. WXDLLIMPEXP_PROPGRID const wxString& wxPGGetDefaultImageWildcard();
  238. /** @class wxImageFileProperty
  239. @ingroup classes
  240. Property representing image file(name).
  241. */
  242. class WXDLLIMPEXP_PROPGRID wxImageFileProperty : public wxFileProperty
  243. {
  244. DECLARE_DYNAMIC_CLASS(wxImageFileProperty)
  245. public:
  246. wxImageFileProperty( const wxString& label= wxPG_LABEL,
  247. const wxString& name = wxPG_LABEL,
  248. const wxString& value = wxEmptyString);
  249. virtual ~wxImageFileProperty();
  250. virtual void OnSetValue();
  251. virtual wxSize OnMeasureImage( int item ) const;
  252. virtual void OnCustomPaint( wxDC& dc,
  253. const wxRect& rect, wxPGPaintData& paintdata );
  254. protected:
  255. wxBitmap* m_pBitmap; // final thumbnail area
  256. wxImage* m_pImage; // intermediate thumbnail area
  257. private:
  258. // Initialize m_pImage using the current file name.
  259. void LoadImageFromFile();
  260. };
  261. #endif
  262. #if wxUSE_CHOICEDLG
  263. /** @class wxMultiChoiceProperty
  264. @ingroup classes
  265. Property that manages a value resulting from wxMultiChoiceDialog. Value is
  266. array of strings. You can get value as array of choice values/indices by
  267. calling wxMultiChoiceProperty::GetValueAsArrayInt().
  268. <b>Supported special attributes:</b>
  269. - "UserStringMode": If > 0, allow user to manually enter strings that are
  270. not in the list of choices. If this value is 1, user strings are
  271. preferably placed in front of valid choices. If value is 2, then those
  272. strings will placed behind valid choices.
  273. */
  274. class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
  275. {
  276. WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
  277. public:
  278. wxMultiChoiceProperty( const wxString& label,
  279. const wxString& name,
  280. const wxArrayString& strings,
  281. const wxArrayString& value );
  282. wxMultiChoiceProperty( const wxString& label,
  283. const wxString& name,
  284. const wxPGChoices& choices,
  285. const wxArrayString& value = wxArrayString() );
  286. wxMultiChoiceProperty( const wxString& label = wxPG_LABEL,
  287. const wxString& name = wxPG_LABEL,
  288. const wxArrayString& value = wxArrayString() );
  289. virtual ~wxMultiChoiceProperty();
  290. virtual void OnSetValue();
  291. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  292. virtual bool StringToValue(wxVariant& variant,
  293. const wxString& text,
  294. int argFlags = 0) const;
  295. virtual bool OnEvent( wxPropertyGrid* propgrid,
  296. wxWindow* primary, wxEvent& event );
  297. wxArrayInt GetValueAsArrayInt() const
  298. {
  299. return m_choices.GetValuesForStrings(m_value.GetArrayString());
  300. }
  301. protected:
  302. void GenerateValueAsString( wxVariant& value, wxString* target ) const;
  303. // Returns translation of values into string indices.
  304. wxArrayInt GetValueAsIndices() const;
  305. wxArrayString m_valueAsStrings; // Value as array of strings
  306. // Cache displayed text since generating it is relatively complicated.
  307. wxString m_display;
  308. };
  309. #endif // wxUSE_CHOICEDLG
  310. // -----------------------------------------------------------------------
  311. #if wxUSE_DATETIME
  312. /** @class wxDateProperty
  313. @ingroup classes
  314. Property representing wxDateTime.
  315. <b>Supported special attributes:</b>
  316. - "DateFormat": Determines displayed date format.
  317. - "PickerStyle": Determines window style used with wxDatePickerCtrl.
  318. Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
  319. enables additional support for unspecified property value.
  320. */
  321. class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
  322. {
  323. WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty)
  324. public:
  325. wxDateProperty( const wxString& label = wxPG_LABEL,
  326. const wxString& name = wxPG_LABEL,
  327. const wxDateTime& value = wxDateTime() );
  328. virtual ~wxDateProperty();
  329. virtual void OnSetValue();
  330. virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
  331. virtual bool StringToValue(wxVariant& variant,
  332. const wxString& text,
  333. int argFlags = 0) const;
  334. virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
  335. void SetFormat( const wxString& format )
  336. {
  337. m_format = format;
  338. }
  339. const wxString& GetFormat() const
  340. {
  341. return m_format;
  342. }
  343. void SetDateValue( const wxDateTime& dt )
  344. {
  345. //m_valueDateTime = dt;
  346. m_value = dt;
  347. }
  348. wxDateTime GetDateValue() const
  349. {
  350. //return m_valueDateTime;
  351. return m_value;
  352. }
  353. long GetDatePickerStyle() const
  354. {
  355. return m_dpStyle;
  356. }
  357. protected:
  358. wxString m_format;
  359. long m_dpStyle; // DatePicker style
  360. static wxString ms_defaultDateFormat;
  361. static wxString DetermineDefaultDateFormat( bool showCentury );
  362. };
  363. #endif // wxUSE_DATETIME
  364. // -----------------------------------------------------------------------
  365. #if wxUSE_SPINBTN
  366. //
  367. // Implement an editor control that allows using wxSpinCtrl (actually, a
  368. // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
  369. // and wxFloatProperty (and similar).
  370. //
  371. // Note that new editor classes needs to be registered before use. This can be
  372. // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
  373. // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
  374. // Registration can also be performed in a constructor of a property that is
  375. // likely to require the editor in question.
  376. //
  377. #include "wx/spinbutt.h"
  378. #include "wx/propgrid/editors.h"
  379. // NOTE: Regardless that this class inherits from a working editor, it has
  380. // all necessary methods to work independently. wxTextCtrl stuff is only
  381. // used for event handling here.
  382. class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor : public wxPGTextCtrlEditor
  383. {
  384. DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor)
  385. public:
  386. virtual ~wxPGSpinCtrlEditor();
  387. wxString GetName() const;
  388. virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
  389. wxPGProperty* property,
  390. const wxPoint& pos,
  391. const wxSize& size) const;
  392. virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
  393. wxWindow* wnd, wxEvent& event ) const;
  394. private:
  395. mutable wxString m_tempString;
  396. };
  397. #endif // wxUSE_SPINBTN
  398. // -----------------------------------------------------------------------
  399. #endif // wxUSE_PROPGRID
  400. #endif // _WX_PROPGRID_ADVPROPS_H_