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