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