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