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