]>
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 | |
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 | ||
21 | ||
22 | // | |
23 | // Additional Value Type Handlers | |
24 | // | |
25 | #ifndef SWIG | |
26 | bool WXDLLIMPEXP_PROPGRID operator==(const wxFont&, const wxFont&); | |
27 | ||
28 | bool WXDLLIMPEXP_PROPGRID | |
29 | operator==(const wxArrayInt& array1, const wxArrayInt& array2); | |
30 | #endif | |
31 | ||
32 | ||
33 | // | |
34 | // Additional Property Editors | |
35 | // | |
36 | #if wxUSE_SPINBTN | |
37 | WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl,WXDLLIMPEXP_PROPGRID) | |
38 | #endif | |
39 | ||
40 | #if wxUSE_DATEPICKCTRL | |
41 | WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl,WXDLLIMPEXP_PROPGRID) | |
42 | #endif | |
43 | ||
44 | // ----------------------------------------------------------------------- | |
45 | ||
46 | ||
47 | // Web colour is currently unsupported | |
48 | #define wxPG_COLOUR_WEB_BASE 0x10000 | |
49 | //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE)) | |
50 | ||
51 | ||
52 | #define wxPG_COLOUR_CUSTOM 0xFFFFFF | |
53 | #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1) | |
54 | ||
55 | /** @class wxColourPropertyValue | |
56 | ||
57 | Because text, background and other colours tend to differ between | |
58 | platforms, wxSystemColourProperty must be able to select between system | |
59 | colour and, when necessary, to pick a custom one. wxSystemColourProperty | |
60 | value makes this possible. | |
61 | */ | |
62 | class WXDLLIMPEXP_PROPGRID wxColourPropertyValue : public wxObject | |
63 | { | |
64 | public: | |
65 | /** An integer value relating to the colour, and which exact | |
66 | meaning depends on the property with which it is used. | |
67 | ||
68 | For wxSystemColourProperty: | |
69 | ||
70 | Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR | |
71 | macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM. | |
72 | ||
73 | For custom colour properties without values array specified: | |
74 | ||
75 | index or wxPG_COLOUR_CUSTOM | |
76 | ||
77 | For custom colour properties <b>with</b> values array specified: | |
78 | ||
79 | m_arrValues[index] or wxPG_COLOUR_CUSTOM | |
80 | */ | |
81 | wxUint32 m_type; | |
82 | ||
83 | /** Resulting colour. Should be correct regardless of type. */ | |
84 | wxColour m_colour; | |
85 | ||
86 | wxColourPropertyValue() | |
b2c36e35 | 87 | : wxObject() |
1c4293cb VZ |
88 | { |
89 | m_type = 0; | |
90 | } | |
91 | ||
92 | virtual ~wxColourPropertyValue() | |
93 | { | |
94 | } | |
95 | ||
96 | wxColourPropertyValue( const wxColourPropertyValue& v ) | |
b2c36e35 | 97 | : wxObject() |
1c4293cb VZ |
98 | { |
99 | m_type = v.m_type; | |
100 | m_colour = v.m_colour; | |
101 | } | |
102 | ||
103 | void Init( wxUint32 type, const wxColour& colour ) | |
104 | { | |
105 | m_type = type; | |
106 | m_colour = colour; | |
107 | } | |
108 | ||
109 | wxColourPropertyValue( const wxColour& colour ) | |
b2c36e35 | 110 | : wxObject() |
1c4293cb VZ |
111 | { |
112 | m_type = wxPG_COLOUR_CUSTOM; | |
113 | m_colour = colour; | |
114 | } | |
115 | ||
116 | wxColourPropertyValue( wxUint32 type ) | |
b2c36e35 | 117 | : wxObject() |
1c4293cb VZ |
118 | { |
119 | m_type = type; | |
120 | } | |
121 | ||
122 | wxColourPropertyValue( wxUint32 type, const wxColour& colour ) | |
b2c36e35 | 123 | : wxObject() |
1c4293cb VZ |
124 | { |
125 | Init( type, colour ); | |
126 | } | |
127 | ||
128 | #ifndef SWIG | |
129 | void operator=(const wxColourPropertyValue& cpv) | |
130 | { | |
131 | Init( cpv.m_type, cpv.m_colour ); | |
132 | } | |
133 | ||
134 | private: | |
135 | DECLARE_DYNAMIC_CLASS(wxColourPropertyValue) | |
136 | #endif | |
137 | }; | |
138 | ||
139 | ||
140 | #ifndef SWIG | |
141 | bool WXDLLIMPEXP_PROPGRID | |
142 | operator==(const wxColourPropertyValue&, const wxColourPropertyValue&); | |
143 | ||
0372d42e JS |
144 | DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID) |
145 | ||
1c4293cb VZ |
146 | #endif |
147 | ||
148 | #ifndef SWIG | |
149 | #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL)) | |
150 | #define wxPG_NORMAL_FONT (*wxNORMAL_FONT) | |
151 | #else | |
152 | #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY | |
153 | #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT | |
154 | #endif | |
155 | ||
156 | ||
157 | // ----------------------------------------------------------------------- | |
158 | // Declare part of custom colour property macro pairs. | |
159 | ||
160 | #if wxUSE_IMAGE || defined(SWIG) | |
161 | #include "wx/image.h" | |
162 | #endif | |
163 | ||
164 | // ----------------------------------------------------------------------- | |
165 | ||
166 | // Exclude class from wxPython bindings | |
167 | #ifndef SWIG | |
168 | ||
169 | /** @class wxFontProperty | |
170 | @ingroup classes | |
171 | Property representing wxFont. | |
172 | */ | |
173 | class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty | |
174 | { | |
175 | WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty) | |
176 | public: | |
177 | ||
178 | wxFontProperty(const wxString& label = wxPG_LABEL, | |
179 | const wxString& name = wxPG_LABEL, | |
180 | const wxFont& value = wxFont()); | |
181 | virtual ~wxFontProperty(); | |
182 | virtual void OnSetValue(); | |
183 | virtual wxString GetValueAsString( int argFlags = 0 ) const; | |
7eac5c53 JS |
184 | virtual bool OnEvent( wxPropertyGrid* propgrid, |
185 | wxWindow* primary, wxEvent& event ); | |
186 | virtual void ChildChanged( wxVariant& thisValue, | |
187 | int childIndex, wxVariant& childValue ) const; | |
188 | virtual void RefreshChildren(); | |
1c4293cb VZ |
189 | |
190 | protected: | |
191 | }; | |
192 | ||
193 | #endif // !SWIG | |
194 | ||
195 | // ----------------------------------------------------------------------- | |
196 | ||
197 | ||
198 | /** If set, then match from list is searched for a custom colour. */ | |
199 | #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1 | |
200 | ||
201 | ||
202 | /** @class wxSystemColourProperty | |
203 | @ingroup classes | |
204 | Has dropdown list of wxWidgets system colours. Value used is | |
205 | of wxColourPropertyValue type. | |
206 | */ | |
207 | class WXDLLIMPEXP_PROPGRID wxSystemColourProperty : public wxEnumProperty | |
208 | { | |
209 | WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty) | |
210 | public: | |
211 | ||
212 | wxSystemColourProperty( const wxString& label = wxPG_LABEL, | |
213 | const wxString& name = wxPG_LABEL, | |
214 | const wxColourPropertyValue& | |
215 | value = wxColourPropertyValue() ); | |
216 | virtual ~wxSystemColourProperty(); | |
217 | ||
218 | virtual void OnSetValue(); | |
219 | virtual bool IntToValue(wxVariant& variant, | |
220 | int number, | |
221 | int argFlags = 0) const; | |
222 | ||
223 | /** | |
224 | Override in derived class to customize how colours are printed as | |
225 | strings. | |
226 | */ | |
227 | virtual wxString ColourToString( const wxColour& col, int index ) const; | |
228 | ||
229 | /** Returns index of entry that triggers colour picker dialog | |
230 | (default is last). | |
231 | */ | |
232 | virtual int GetCustomColourIndex() const; | |
233 | ||
7eac5c53 JS |
234 | virtual wxString GetValueAsString( int argFlags = 0 ) const; |
235 | virtual bool StringToValue( wxVariant& variant, | |
236 | const wxString& text, | |
237 | int argFlags = 0 ) const; | |
238 | virtual bool OnEvent( wxPropertyGrid* propgrid, | |
239 | wxWindow* primary, wxEvent& event ); | |
240 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
241 | virtual wxSize OnMeasureImage( int item ) const; | |
242 | virtual void OnCustomPaint( wxDC& dc, | |
243 | const wxRect& rect, wxPGPaintData& paintdata ); | |
1c4293cb VZ |
244 | |
245 | // Helper function to show the colour dialog | |
246 | bool QueryColourFromUser( wxVariant& variant ) const; | |
247 | ||
248 | /** Default is to use wxSystemSettings::GetColour(index). Override to use | |
249 | custom colour tables etc. | |
250 | */ | |
251 | virtual wxColour GetColour( int index ) const; | |
252 | ||
253 | wxColourPropertyValue GetVal( const wxVariant* pVariant = NULL ) const; | |
254 | ||
255 | protected: | |
256 | ||
257 | // Special constructors to be used by derived classes. | |
258 | wxSystemColourProperty( const wxString& label, const wxString& name, | |
259 | const wxChar** labels, const long* values, wxPGChoices* choicesCache, | |
260 | const wxColourPropertyValue& value ); | |
261 | wxSystemColourProperty( const wxString& label, const wxString& name, | |
262 | const wxChar** labels, const long* values, wxPGChoices* choicesCache, | |
263 | const wxColour& value ); | |
264 | ||
265 | void Init( int type, const wxColour& colour ); | |
266 | ||
267 | // Utility functions for internal use | |
268 | virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; | |
269 | wxVariant TranslateVal( wxColourPropertyValue& v ) const | |
270 | { | |
271 | return DoTranslateVal( v ); | |
272 | } | |
273 | wxVariant TranslateVal( int type, const wxColour& colour ) const | |
274 | { | |
275 | wxColourPropertyValue v(type, colour); | |
276 | return DoTranslateVal( v ); | |
277 | } | |
278 | ||
279 | // Translates colour to a int value, return wxNOT_FOUND if no match. | |
280 | int ColToInd( const wxColour& colour ) const; | |
281 | }; | |
282 | ||
283 | // ----------------------------------------------------------------------- | |
284 | ||
d61d8cff JS |
285 | class WXDLLIMPEXP_PROPGRID wxColourProperty : public wxSystemColourProperty |
286 | { | |
287 | WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty) | |
288 | public: | |
289 | wxColourProperty( const wxString& label = wxPG_LABEL, | |
290 | const wxString& name = wxPG_LABEL, | |
291 | const wxColour& value = *wxWHITE ); | |
292 | virtual ~wxColourProperty(); | |
1c4293cb | 293 | |
d61d8cff JS |
294 | protected: |
295 | virtual wxString GetValueAsString( int argFlags ) const; | |
296 | virtual wxColour GetColour( int index ) const; | |
297 | virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; | |
298 | ||
299 | private: | |
300 | void Init( wxColour colour ); | |
301 | }; | |
1c4293cb VZ |
302 | |
303 | // ----------------------------------------------------------------------- | |
304 | ||
d61d8cff JS |
305 | // Exclude classes from wxPython bindings |
306 | #ifndef SWIG | |
307 | ||
1c4293cb VZ |
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 | ||
7eac5c53 JS |
321 | virtual wxSize OnMeasureImage( int item ) const; |
322 | virtual void OnCustomPaint( wxDC& dc, | |
323 | const wxRect& rect, wxPGPaintData& paintdata ); | |
1c4293cb VZ |
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 | ||
7eac5c53 JS |
348 | virtual wxSize OnMeasureImage( int item ) const; |
349 | virtual void OnCustomPaint( wxDC& dc, | |
350 | const wxRect& rect, wxPGPaintData& paintdata ); | |
1c4293cb VZ |
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 || defined(SWIG) | |
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 GetValueAsString( int flags = 0 ) const; | |
396 | virtual bool StringToValue(wxVariant& variant, | |
397 | const wxString& text, | |
398 | int argFlags = 0) const; | |
7eac5c53 JS |
399 | virtual bool OnEvent( wxPropertyGrid* propgrid, |
400 | wxWindow* primary, wxEvent& event ); | |
1c4293cb | 401 | |
1c4293cb VZ |
402 | wxArrayInt GetValueAsArrayInt() const |
403 | { | |
404 | return m_choices.GetValuesForStrings(m_value.GetArrayString()); | |
405 | } | |
406 | ||
407 | protected: | |
408 | ||
409 | void GenerateValueAsString(); | |
410 | ||
411 | // Returns translation of values into string indices. | |
412 | wxArrayInt GetValueAsIndices() const; | |
413 | ||
414 | wxArrayString m_valueAsStrings; // Value as array of strings | |
415 | ||
1c4293cb VZ |
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. | |
434 | */ | |
435 | class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty | |
436 | { | |
437 | WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty) | |
438 | public: | |
439 | ||
440 | wxDateProperty( const wxString& label = wxPG_LABEL, | |
441 | const wxString& name = wxPG_LABEL, | |
442 | const wxDateTime& value = wxDateTime() ); | |
443 | virtual ~wxDateProperty(); | |
444 | ||
445 | virtual wxString GetValueAsString( int flags = 0 ) const; | |
446 | virtual bool StringToValue(wxVariant& variant, | |
447 | const wxString& text, | |
448 | int argFlags = 0) const; | |
449 | ||
7eac5c53 | 450 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); |
1c4293cb VZ |
451 | |
452 | void SetFormat( const wxString& format ) | |
453 | { | |
454 | m_format = format; | |
455 | } | |
456 | ||
457 | const wxString& GetFormat() const | |
458 | { | |
459 | return m_format; | |
460 | } | |
461 | ||
462 | void SetDateValue( const wxDateTime& dt ) | |
463 | { | |
464 | //m_valueDateTime = dt; | |
465 | m_value = dt; | |
466 | } | |
467 | ||
468 | wxDateTime GetDateValue() const | |
469 | { | |
470 | //return m_valueDateTime; | |
471 | return m_value; | |
472 | } | |
473 | ||
474 | long GetDatePickerStyle() const | |
475 | { | |
476 | return m_dpStyle; | |
477 | } | |
478 | ||
479 | protected: | |
480 | wxString m_format; | |
481 | long m_dpStyle; // DatePicker style | |
482 | ||
483 | static wxString ms_defaultDateFormat; | |
484 | static wxString DetermineDefaultDateFormat( bool showCentury ); | |
485 | }; | |
486 | ||
487 | #endif // wxUSE_DATETIME | |
488 | ||
489 | #endif // !SWIG | |
490 | ||
491 | // ----------------------------------------------------------------------- | |
492 | ||
493 | #if wxUSE_SPINBTN | |
494 | ||
495 | // | |
496 | // Implement an editor control that allows using wxSpinCtrl (actually, a | |
497 | // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty | |
498 | // and wxFloatProperty (and similar). | |
499 | // | |
500 | // Note that new editor classes needs to be registered before use. This can be | |
501 | // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl | |
502 | // in wxPropertyGridInterface::RegisterAdditionalEditors (see below). | |
503 | // Registration can also be performed in a constructor of a property that is | |
504 | // likely to require the editor in question. | |
505 | // | |
506 | ||
507 | ||
508 | #include "wx/spinbutt.h" | |
509 | #include "wx/propgrid/editors.h" | |
510 | ||
511 | ||
512 | // NOTE: Regardless that this class inherits from a working editor, it has | |
513 | // all necessary methods to work independently. wxTextCtrl stuff is only | |
514 | // used for event handling here. | |
515 | class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor : public wxPGTextCtrlEditor | |
516 | { | |
52cefafe | 517 | DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor) |
1c4293cb VZ |
518 | public: |
519 | virtual ~wxPGSpinCtrlEditor(); | |
520 | ||
52cefafe JS |
521 | wxString GetName() const; |
522 | virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid, | |
523 | wxPGProperty* property, | |
524 | const wxPoint& pos, | |
525 | const wxSize& size) const; | |
1c4293cb VZ |
526 | virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property, |
527 | wxWindow* wnd, wxEvent& event ) const; | |
528 | ||
529 | private: | |
530 | mutable wxString m_tempString; | |
531 | }; | |
532 | ||
533 | #endif // wxUSE_SPINBTN | |
534 | ||
535 | // ----------------------------------------------------------------------- | |
536 | ||
f4bc1aa2 JS |
537 | #endif // wxUSE_PROPGRID |
538 | ||
1c4293cb | 539 | #endif // _WX_PROPGRID_ADVPROPS_H_ |