]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/advprops.h
Resolve GCC's 'type-punned pointer will break strict-aliasing rules' warning by break...
[wxWidgets.git] / include / wx / propgrid / advprops.h
CommitLineData
1c4293cb
VZ
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
ea5af9c5 7// RCS-ID: $Id$
1c4293cb
VZ
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROPGRID_ADVPROPS_H_
13#define _WX_PROPGRID_ADVPROPS_H_
14
f4bc1aa2
JS
15#if wxUSE_PROPGRID
16
1c4293cb
VZ
17#include "wx/propgrid/props.h"
18
19// -----------------------------------------------------------------------
20
1c4293cb
VZ
21//
22// Additional Value Type Handlers
23//
1c4293cb
VZ
24bool WXDLLIMPEXP_PROPGRID
25operator==(const wxArrayInt& array1, const wxArrayInt& array2);
1c4293cb
VZ
26
27//
28// Additional Property Editors
29//
30#if wxUSE_SPINBTN
31WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl,WXDLLIMPEXP_PROPGRID)
32#endif
33
34#if wxUSE_DATEPICKCTRL
35WX_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*/
56class WXDLLIMPEXP_PROPGRID wxColourPropertyValue : public wxObject
57{
58public:
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()
b2c36e35 81 : wxObject()
1c4293cb
VZ
82 {
83 m_type = 0;
84 }
85
86 virtual ~wxColourPropertyValue()
87 {
88 }
89
90 wxColourPropertyValue( const wxColourPropertyValue& v )
b2c36e35 91 : wxObject()
1c4293cb
VZ
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 )
b2c36e35 104 : wxObject()
1c4293cb
VZ
105 {
106 m_type = wxPG_COLOUR_CUSTOM;
107 m_colour = colour;
108 }
109
110 wxColourPropertyValue( wxUint32 type )
b2c36e35 111 : wxObject()
1c4293cb
VZ
112 {
113 m_type = type;
114 }
115
116 wxColourPropertyValue( wxUint32 type, const wxColour& colour )
b2c36e35 117 : wxObject()
1c4293cb
VZ
118 {
119 Init( type, colour );
120 }
121
1c4293cb
VZ
122 void operator=(const wxColourPropertyValue& cpv)
123 {
a09307ab
PC
124 if (this != &cpv)
125 Init( cpv.m_type, cpv.m_colour );
1c4293cb
VZ
126 }
127
128private:
129 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue)
1c4293cb
VZ
130};
131
132
1c4293cb
VZ
133bool WXDLLIMPEXP_PROPGRID
134operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
135
0372d42e
JS
136DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
137
1c4293cb
VZ
138// -----------------------------------------------------------------------
139// Declare part of custom colour property macro pairs.
140
b512ed93 141#if wxUSE_IMAGE
1c4293cb
VZ
142 #include "wx/image.h"
143#endif
144
145// -----------------------------------------------------------------------
146
1c4293cb
VZ
147/** @class wxFontProperty
148 @ingroup classes
149 Property representing wxFont.
150*/
151class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
152{
153 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
154public:
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();
1425eca5 161 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
7eac5c53
JS
162 virtual bool OnEvent( wxPropertyGrid* propgrid,
163 wxWindow* primary, wxEvent& event );
b8b1ff48
JS
164 virtual wxVariant ChildChanged( wxVariant& thisValue,
165 int childIndex,
166 wxVariant& childValue ) const;
7eac5c53 167 virtual void RefreshChildren();
1c4293cb
VZ
168
169protected:
170};
171
1c4293cb
VZ
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*/
184class WXDLLIMPEXP_PROPGRID wxSystemColourProperty : public wxEnumProperty
185{
186 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty)
187public:
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
1425eca5 211 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
7eac5c53
JS
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 );
1c4293cb
VZ
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
232protected:
233
234 // Special constructors to be used by derived classes.
235 wxSystemColourProperty( const wxString& label, const wxString& name,
a243da29 236 const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
1c4293cb
VZ
237 const wxColourPropertyValue& value );
238 wxSystemColourProperty( const wxString& label, const wxString& name,
a243da29 239 const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
1c4293cb
VZ
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
d61d8cff
JS
262class WXDLLIMPEXP_PROPGRID wxColourProperty : public wxSystemColourProperty
263{
264 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty)
265public:
266 wxColourProperty( const wxString& label = wxPG_LABEL,
267 const wxString& name = wxPG_LABEL,
268 const wxColour& value = *wxWHITE );
269 virtual ~wxColourProperty();
1c4293cb 270
1425eca5 271 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
d61d8cff 272 virtual wxColour GetColour( int index ) const;
a09307ab
PC
273
274protected:
d61d8cff
JS
275 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
276
277private:
278 void Init( wxColour colour );
279};
1c4293cb
VZ
280
281// -----------------------------------------------------------------------
282
283/** @class wxCursorProperty
284 @ingroup classes
285 Property representing wxCursor.
286*/
287class 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
7eac5c53
JS
296 virtual wxSize OnMeasureImage( int item ) const;
297 virtual void OnCustomPaint( wxDC& dc,
298 const wxRect& rect, wxPGPaintData& paintdata );
1c4293cb
VZ
299};
300
301// -----------------------------------------------------------------------
302
303#if wxUSE_IMAGE
304
305WXDLLIMPEXP_PROPGRID const wxString& wxPGGetDefaultImageWildcard();
306
307/** @class wxImageFileProperty
308 @ingroup classes
309 Property representing image file(name).
310*/
311class WXDLLIMPEXP_PROPGRID wxImageFileProperty : public wxFileProperty
312{
313 DECLARE_DYNAMIC_CLASS(wxImageFileProperty)
314public:
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
7eac5c53
JS
323 virtual wxSize OnMeasureImage( int item ) const;
324 virtual void OnCustomPaint( wxDC& dc,
325 const wxRect& rect, wxPGPaintData& paintdata );
1c4293cb
VZ
326
327protected:
328 wxBitmap* m_pBitmap; // final thumbnail area
329 wxImage* m_pImage; // intermediate thumbnail area
330};
331
332#endif
333
b512ed93 334#if wxUSE_CHOICEDLG
1c4293cb
VZ
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*/
348class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
349{
350 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
351public:
352
353 wxMultiChoiceProperty( const wxString& label,
354 const wxString& name,
355 const wxArrayString& strings,
356 const wxArrayString& value );
1c4293cb
VZ
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() );
ec3cce5a 365
1c4293cb
VZ
366 virtual ~wxMultiChoiceProperty();
367
368 virtual void OnSetValue();
1425eca5 369 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
1c4293cb
VZ
370 virtual bool StringToValue(wxVariant& variant,
371 const wxString& text,
372 int argFlags = 0) const;
7eac5c53
JS
373 virtual bool OnEvent( wxPropertyGrid* propgrid,
374 wxWindow* primary, wxEvent& event );
1c4293cb 375
1c4293cb
VZ
376 wxArrayInt GetValueAsArrayInt() const
377 {
378 return m_choices.GetValuesForStrings(m_value.GetArrayString());
379 }
380
381protected:
382
102c9a42 383 void GenerateValueAsString( wxVariant& value, wxString* target ) const;
1c4293cb
VZ
384
385 // Returns translation of values into string indices.
386 wxArrayInt GetValueAsIndices() const;
387
388 wxArrayString m_valueAsStrings; // Value as array of strings
389
1c4293cb
VZ
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.
03647350 407 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
b6fd0b42 408 enables additional support for unspecified property value.
1c4293cb
VZ
409*/
410class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
411{
412 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty)
413public:
414
415 wxDateProperty( const wxString& label = wxPG_LABEL,
416 const wxString& name = wxPG_LABEL,
417 const wxDateTime& value = wxDateTime() );
418 virtual ~wxDateProperty();
419
b6fd0b42 420 virtual void OnSetValue();
1425eca5 421 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
1c4293cb
VZ
422 virtual bool StringToValue(wxVariant& variant,
423 const wxString& text,
424 int argFlags = 0) const;
425
7eac5c53 426 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
1c4293cb
VZ
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
455protected:
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
1c4293cb
VZ
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.
489class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor : public wxPGTextCtrlEditor
490{
52cefafe 491 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor)
1c4293cb
VZ
492public:
493 virtual ~wxPGSpinCtrlEditor();
494
52cefafe
JS
495 wxString GetName() const;
496 virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
497 wxPGProperty* property,
498 const wxPoint& pos,
499 const wxSize& size) const;
1c4293cb
VZ
500 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
501 wxWindow* wnd, wxEvent& event ) const;
502
503private:
504 mutable wxString m_tempString;
505};
506
507#endif // wxUSE_SPINBTN
508
509// -----------------------------------------------------------------------
510
f4bc1aa2
JS
511#endif // wxUSE_PROPGRID
512
1c4293cb 513#endif // _WX_PROPGRID_ADVPROPS_H_