1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        advprops.h
3 // Purpose:     interfaces of wxPropertyGrid Advanced Properties (font,
4 //              colour, etc.)
5 // Author:      wxWidgets team
6 // Licence:     wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8 
9 
10 
11 
12 // Web colour is currently unsupported
13 #define wxPG_COLOUR_WEB_BASE        0x10000
14 
15 
16 #define wxPG_COLOUR_CUSTOM      0xFFFFFF
17 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
18 
19 /** @class wxColourPropertyValue
20 
21     Because text, background and other colours tend to differ between
22     platforms, wxSystemColourProperty must be able to select between system
23     colour and, when necessary, to pick a custom one. wxSystemColourProperty
24     value makes this possible.
25 */
26 class wxColourPropertyValue : public wxObject
27 {
28 public:
29     /** An integer value relating to the colour, and which exact
30         meaning depends on the property with which it is used.
31 
32         For wxSystemColourProperty:
33 
34         Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
35         macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
36 
37         For custom colour properties without values array specified:
38 
39         index or wxPG_COLOUR_CUSTOM
40 
41         For custom colour properties <b>with</b> values array specified:
42 
43         m_arrValues[index] or wxPG_COLOUR_CUSTOM
44     */
45     wxUint32    m_type;
46 
47     /** Resulting colour. Should be correct regardless of type. */
48     wxColour    m_colour;
49 
50     wxColourPropertyValue();
51     wxColourPropertyValue( const wxColourPropertyValue& v );
52     wxColourPropertyValue( const wxColour& colour );
53     wxColourPropertyValue( wxUint32 type );
54     wxColourPropertyValue( wxUint32 type, const wxColour& colour );
55 
56     virtual ~wxColourPropertyValue();
57 
58     void Init( wxUint32 type, const wxColour& colour );
59 
60     void operator=(const wxColourPropertyValue& cpv);
61 };
62 
63 
64 
65 /** @class wxFontProperty
66     @ingroup classes
67     Property representing wxFont.
68 */
69 class wxFontProperty : public wxPGProperty
70 {
71 public:
72 
73     wxFontProperty(const wxString& label = wxPG_LABEL,
74                    const wxString& name = wxPG_LABEL,
75                    const wxFont& value = wxFont());
76     virtual ~wxFontProperty();
77     virtual void OnSetValue();
78     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
79     virtual bool OnEvent( wxPropertyGrid* propgrid,
80                           wxWindow* primary, wxEvent& event );
81     virtual wxVariant ChildChanged( wxVariant& thisValue,
82                                     int childIndex,
83                                     wxVariant& childValue ) const;
84     virtual void RefreshChildren();
85 };
86 
87 
88 
89 
90 /** If set, then match from list is searched for a custom colour. */
91 #define wxPG_PROP_TRANSLATE_CUSTOM      wxPG_PROP_CLASS_SPECIFIC_1
92 
93 
94 /** @class wxSystemColourProperty
95     @ingroup classes
96     Has dropdown list of wxWidgets system colours. Value used is
97     of wxColourPropertyValue type.
98 */
99 class wxSystemColourProperty : public wxEnumProperty
100 {
101 public:
102 
103     wxSystemColourProperty( const wxString& label = wxPG_LABEL,
104                             const wxString& name = wxPG_LABEL,
105                             const wxColourPropertyValue&
106                                 value = wxColourPropertyValue() );
107     virtual ~wxSystemColourProperty();
108 
109     virtual void OnSetValue();
110     virtual bool IntToValue(wxVariant& variant,
111                             int number,
112                             int argFlags = 0) const;
113 
114     /**
115         Override in derived class to customize how colours are printed as
116         strings.
117     */
118     virtual wxString ColourToString( const wxColour& col, int index,
119                                      int argFlags = 0 ) const;
120 
121     /** Returns index of entry that triggers colour picker dialog
122         (default is last).
123     */
124     virtual int GetCustomColourIndex() const;
125 
126     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
127     virtual bool StringToValue( wxVariant& variant,
128                                 const wxString& text,
129                                 int argFlags = 0 ) const;
130     virtual bool OnEvent( wxPropertyGrid* propgrid,
131                           wxWindow* primary, wxEvent& event );
132     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
133     virtual wxSize OnMeasureImage( int item ) const;
134     virtual void OnCustomPaint( wxDC& dc,
135                                 const wxRect& rect, wxPGPaintData& paintdata );
136 
137     // Helper function to show the colour dialog
138     bool QueryColourFromUser( wxVariant& variant ) const;
139 
140     /** Default is to use wxSystemSettings::GetColour(index). Override to use
141         custom colour tables etc.
142     */
143     virtual wxColour GetColour( int index ) const;
144 
145     wxColourPropertyValue GetVal( const wxVariant* pVariant = NULL ) const;
146 
147 protected:
148 
149     // Special constructors to be used by derived classes.
150     wxSystemColourProperty( const wxString& label, const wxString& name,
151         const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
152         const wxColourPropertyValue& value );
153 
154     wxSystemColourProperty( const wxString& label, const wxString& name,
155         const wxChar* const* labels, const long* values, wxPGChoices* choicesCache,
156         const wxColour& value );
157 
158     void Init( int type, const wxColour& colour );
159 
160     // Utility functions for internal use
161     virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
162     wxVariant TranslateVal( wxColourPropertyValue& v ) const;
163     wxVariant TranslateVal( int type, const wxColour& colour ) const;
164 
165     // Translates colour to a int value, return wxNOT_FOUND if no match.
166     int ColToInd( const wxColour& colour ) const;
167 };
168 
169 
170 
171 class wxColourProperty : public wxSystemColourProperty
172 {
173 public:
174     wxColourProperty( const wxString& label = wxPG_LABEL,
175                       const wxString& name = wxPG_LABEL,
176                       const wxColour& value = *wxWHITE );
177     virtual ~wxColourProperty();
178 
179     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
180     virtual wxColour GetColour( int index ) const;
181 
182 protected:
183     virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
184 };
185 
186 
187 
188 /** @class wxCursorProperty
189     @ingroup classes
190     Property representing wxCursor.
191 */
192 class wxCursorProperty : public wxEnumProperty
193 {
194 public:
195     wxCursorProperty( const wxString& label= wxPG_LABEL,
196                       const wxString& name= wxPG_LABEL,
197                       int value = 0 );
198     virtual ~wxCursorProperty();
199 
200     virtual wxSize OnMeasureImage( int item ) const;
201     virtual void OnCustomPaint( wxDC& dc,
202                                 const wxRect& rect, wxPGPaintData& paintdata );
203 };
204 
205 
206 const wxString& wxPGGetDefaultImageWildcard();
207 
208 /** @class wxImageFileProperty
209     @ingroup classes
210     Property representing image file(name).
211 */
212 class wxImageFileProperty : public wxFileProperty
213 {
214 public:
215 
216     wxImageFileProperty( const wxString& label= wxPG_LABEL,
217                          const wxString& name = wxPG_LABEL,
218                          const wxString& value = wxEmptyString);
219     virtual ~wxImageFileProperty();
220 
221     virtual void OnSetValue();
222 
223     virtual wxSize OnMeasureImage( int item ) const;
224     virtual void OnCustomPaint( wxDC& dc,
225                                 const wxRect& rect, wxPGPaintData& paintdata );
226 
227 protected:
228     wxBitmap*   m_pBitmap; // final thumbnail area
229     wxImage*    m_pImage; // intermediate thumbnail area
230 };
231 
232 
233 
234 /** @class wxMultiChoiceProperty
235     @ingroup classes
236     Property that manages a value resulting from wxMultiChoiceDialog. Value is
237     array of strings. You can get value as array of choice values/indices by
238     calling wxMultiChoiceProperty::GetValueAsArrayInt().
239 
240     <b>Supported special attributes:</b>
241     - "UserStringMode": If > 0, allow user to manually enter strings that are
242       not in the list of choices. If this value is 1, user strings are
243       preferably placed in front of valid choices. If value is 2, then those
244       strings will placed behind valid choices.
245 */
246 class wxMultiChoiceProperty : public wxPGProperty
247 {
248 public:
249 
250     wxMultiChoiceProperty( const wxString& label,
251                            const wxString& name,
252                            const wxArrayString& strings,
253                            const wxArrayString& value );
254     wxMultiChoiceProperty( const wxString& label,
255                            const wxString& name,
256                            const wxPGChoices& choices,
257                            const wxArrayString& value = wxArrayString() );
258 
259     wxMultiChoiceProperty( const wxString& label = wxPG_LABEL,
260                            const wxString& name = wxPG_LABEL,
261                            const wxArrayString& value = wxArrayString() );
262 
263     virtual ~wxMultiChoiceProperty();
264 
265     virtual void OnSetValue();
266     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
267     virtual bool StringToValue(wxVariant& variant,
268                                const wxString& text,
269                                int argFlags = 0) const;
270     virtual bool OnEvent( wxPropertyGrid* propgrid,
271                           wxWindow* primary, wxEvent& event );
272 
273     wxArrayInt GetValueAsArrayInt() const;
274 
275 protected:
276 
277     void GenerateValueAsString( wxVariant& value, wxString* target ) const;
278 
279     // Returns translation of values into string indices.
280     wxArrayInt GetValueAsIndices() const;
281 
282     wxArrayString       m_valueAsStrings;  // Value as array of strings
283 
284     // Cache displayed text since generating it is relatively complicated.
285     wxString            m_display;
286 };
287 
288 
289 
290 /** @class wxDateProperty
291     @ingroup classes
292     Property representing wxDateTime.
293 
294     <b>Supported special attributes:</b>
295     - "DateFormat": Determines displayed date format.
296     - "PickerStyle": Determines window style used with wxDatePickerCtrl.
297        Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
298        enables additional support for unspecified property value.
299 */
300 class wxDateProperty : public wxPGProperty
301 {
302 public:
303 
304     wxDateProperty( const wxString& label = wxPG_LABEL,
305                     const wxString& name = wxPG_LABEL,
306                     const wxDateTime& value = wxDateTime() );
307     virtual ~wxDateProperty();
308 
309     virtual void OnSetValue();
310     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
311     virtual bool StringToValue(wxVariant& variant,
312                                const wxString& text,
313                                int argFlags = 0) const;
314 
315     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
316 
317     void SetFormat( const wxString& format );
318     const wxString& GetFormat() const;
319 
320     void SetDateValue( const wxDateTime& dt );
321     wxDateTime GetDateValue() const;
322 
323     long GetDatePickerStyle() const;
324 
325 protected:
326     wxString        m_format;
327     long            m_dpStyle;  // DatePicker style
328 
329     static wxString ms_defaultDateFormat;
330     static wxString DetermineDefaultDateFormat( bool showCentury );
331 };
332 
333 
334 
335 class wxPGSpinCtrlEditor : public wxPGTextCtrlEditor
336 {
337 public:
338     virtual ~wxPGSpinCtrlEditor();
339 
340     wxString GetName() const;
341     virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
342                                           wxPGProperty* property,
343                                           const wxPoint& pos,
344                                           const wxSize& size) const;
345     virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
346         wxWindow* wnd, wxEvent& event ) const;
347 };
348 
349 
350 extern wxPGEditor* wxPGEditor_SpinCtrl;
351 extern wxPGEditor* wxPGEditor_DatePickerCtrl;
352