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