]>
Commit | Line | Data |
---|---|---|
1c4293cb VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/propgrid/props.h | |
3 | // Purpose: wxPropertyGrid Property Classes | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2007-03-28 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PROPGRID_PROPS_H_ | |
13 | #define _WX_PROPGRID_PROPS_H_ | |
14 | ||
f4bc1aa2 JS |
15 | #if wxUSE_PROPGRID |
16 | ||
1c4293cb VZ |
17 | // ----------------------------------------------------------------------- |
18 | ||
19 | class wxArrayEditorDialog; | |
20 | ||
21 | #include "wx/propgrid/editors.h" | |
22 | ||
23 | // ----------------------------------------------------------------------- | |
24 | ||
25 | // | |
26 | // Additional property class declaration helper macros | |
27 | // | |
28 | ||
29 | // | |
30 | // Property class implementation helper macros. | |
31 | // | |
32 | ||
33 | #define WX_PG_DECLARE_BASIC_TYPE_METHODS() \ | |
34 | virtual wxString GetValueAsString( int argFlags = 0 ) const; \ | |
35 | virtual bool StringToValue( wxVariant& variant, \ | |
36 | const wxString& text, \ | |
37 | int argFlags = 0 ) const; | |
38 | ||
39 | #define WX_PG_DECLARE_CHOICE_METHODS() \ | |
40 | virtual bool IntToValue( wxVariant& variant, \ | |
41 | int number, int argFlags = 0 ) const; \ | |
42 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
43 | ||
44 | #define WX_PG_DECLARE_EVENT_METHODS() \ | |
45 | virtual bool OnEvent( wxPropertyGrid* propgrid, \ | |
46 | wxWindow* primary, wxEvent& event ); | |
47 | ||
48 | #define WX_PG_DECLARE_PARENTAL_METHODS() \ | |
49 | virtual void ChildChanged( wxVariant& thisValue, \ | |
50 | int childIndex, wxVariant& childValue ) const; \ | |
51 | virtual void RefreshChildren(); | |
52 | ||
53 | #define WX_PG_DECLARE_CUSTOM_PAINT_METHODS() \ | |
54 | virtual wxSize OnMeasureImage( int item ) const; \ | |
55 | virtual void OnCustomPaint( wxDC& dc, \ | |
56 | const wxRect& rect, wxPGPaintData& paintdata ); | |
57 | ||
58 | #define WX_PG_DECLARE_ATTRIBUTE_METHODS() \ | |
59 | virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); | |
60 | ||
61 | #define WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
62 | virtual wxValidator* DoGetValidator() const; | |
63 | ||
64 | // Adds constructor function as well. | |
65 | #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\ | |
66 | UPCLASS,T,T_AS_ARG,EDITOR) \ | |
67 | IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \ | |
68 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR) | |
69 | ||
70 | // A regular property | |
71 | #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \ | |
72 | WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR) | |
73 | ||
74 | #define WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(CLASSNAME) \ | |
75 | DECLARE_DYNAMIC_CLASS(CLASSNAME) | |
76 | ||
77 | // Derived property class is one that inherits from an existing working property | |
78 | // class, but assumes same value and editor type. | |
79 | #define WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,UPNAME,T_AS_ARG) \ | |
80 | IMPLEMENT_DYNAMIC_CLASS(NAME, UPNAME) | |
81 | ||
82 | // ----------------------------------------------------------------------- | |
83 | ||
84 | #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences | |
85 | #define wxPG_ESCAPE 0 // Escape sequences | |
86 | ||
87 | #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \ | |
88 | DECL NAME : public wxLongStringProperty \ | |
89 | { \ | |
90 | WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(NAME) \ | |
91 | public: \ | |
92 | NAME( const wxString& name = wxPG_LABEL, \ | |
93 | const wxString& label = wxPG_LABEL, \ | |
94 | const wxString& value = wxEmptyString); \ | |
95 | virtual ~NAME(); \ | |
96 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \ | |
97 | WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
98 | }; | |
99 | ||
100 | #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \ | |
101 | WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \ | |
102 | ||
103 | #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \ | |
104 | WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,wxLongStringProperty,\ | |
105 | const wxString&) \ | |
106 | NAME::NAME( const wxString& name, \ | |
107 | const wxString& label, \ | |
108 | const wxString& value ) \ | |
109 | : wxLongStringProperty(name,label,value) \ | |
110 | { \ | |
111 | m_flags |= FLAGS; \ | |
112 | } \ | |
113 | NAME::~NAME() { } | |
114 | ||
115 | #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \ | |
116 | WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \ | |
117 | wxValidator* NAME::DoGetValidator () const \ | |
118 | { return (wxValidator*) NULL; } | |
119 | ||
120 | // ----------------------------------------------------------------------- | |
121 | ||
122 | #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \ | |
123 | DECL CLASSNAME : public wxFlagsProperty \ | |
124 | { \ | |
125 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
126 | public: \ | |
127 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
128 | const wxString& name = wxPG_LABEL, \ | |
129 | long value = -1 ); \ | |
130 | virtual ~CLASSNAME(); \ | |
131 | }; | |
132 | ||
133 | #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \ | |
134 | WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class) | |
135 | ||
136 | // This will create interface for wxFlagsProperty derived class | |
137 | // named CLASSNAME. | |
138 | #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \ | |
139 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\ | |
140 | long,TextCtrl) \ | |
141 | CLASSNAME::CLASSNAME( const wxString& label, \ | |
142 | const wxString& name, \ | |
143 | long value ) \ | |
144 | : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \ | |
145 | { \ | |
146 | m_flags |= wxPG_PROP_STATIC_CHOICES; \ | |
147 | } \ | |
148 | CLASSNAME::~CLASSNAME() { } | |
149 | ||
150 | ||
151 | // ----------------------------------------------------------------------- | |
152 | ||
153 | #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \ | |
154 | class CLASSNAME : public wxEnumProperty \ | |
155 | { \ | |
156 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
157 | public: \ | |
158 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
159 | const wxString& name = wxPG_LABEL, \ | |
160 | int value = -1 ); \ | |
161 | virtual ~CLASSNAME(); \ | |
162 | }; | |
163 | ||
164 | #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \ | |
165 | WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class) | |
166 | ||
167 | #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \ | |
168 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \ | |
169 | int, Choice) \ | |
170 | CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \ | |
171 | : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \ | |
172 | { \ | |
173 | m_flags |= wxPG_PROP_STATIC_CHOICES; \ | |
174 | } \ | |
175 | CLASSNAME::~CLASSNAME() { } | |
176 | ||
177 | ||
178 | // ----------------------------------------------------------------------- | |
179 | ||
180 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \ | |
181 | DECL CLASSNAME : public wxSystemColourProperty \ | |
182 | { \ | |
183 | DECLARE_DYNAMIC_CLASS(CLASSNAME) \ | |
184 | public: \ | |
185 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
186 | const wxString& name = wxPG_LABEL, \ | |
187 | const wxColourPropertyValue& value = wxColourPropertyValue() ); \ | |
188 | virtual ~CLASSNAME(); \ | |
189 | virtual wxColour GetColour( int index ) const; \ | |
190 | }; | |
191 | ||
192 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \ | |
193 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class) | |
194 | ||
195 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\ | |
196 | LABELS,VALUES,COLOURS) \ | |
197 | static wxPGChoices gs_##CLASSNAME##_choicesCache; \ | |
198 | WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \ | |
199 | const wxColourPropertyValue&) \ | |
200 | CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \ | |
201 | const wxColourPropertyValue& value ) \ | |
202 | : wxSystemColourProperty(label, name, LABELS, VALUES, \ | |
203 | &gs_##CLASSNAME##_choicesCache, value ) \ | |
204 | { \ | |
205 | m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \ | |
206 | } \ | |
207 | CLASSNAME::~CLASSNAME () { } \ | |
208 | wxColour CLASSNAME::GetColour ( int index ) const \ | |
209 | { \ | |
210 | if ( !m_choices.HasValue(index) ) \ | |
211 | { \ | |
212 | wxASSERT( index < (int)m_choices.GetCount() ); \ | |
213 | return COLOURS[index]; \ | |
214 | } \ | |
215 | return COLOURS[m_choices.GetValue(index)]; \ | |
216 | } | |
217 | ||
218 | // ----------------------------------------------------------------------- | |
219 | ||
220 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\ | |
221 | DECL) \ | |
222 | DECL CLASSNAME : public wxSystemColourProperty \ | |
223 | { \ | |
224 | WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \ | |
225 | public: \ | |
226 | CLASSNAME( const wxString& label = wxPG_LABEL, \ | |
227 | const wxString& name = wxPG_LABEL, \ | |
228 | const wxColour& value = wxColour() ); \ | |
229 | virtual ~CLASSNAME(); \ | |
230 | virtual wxString GetValueAsString( int argFlags ) const; \ | |
231 | virtual wxColour GetColour( int index ) const; \ | |
232 | virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \ | |
233 | void Init( wxColour colour ); \ | |
234 | }; | |
235 | ||
236 | #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \ | |
237 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class) | |
238 | ||
239 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \ | |
240 | LABELS, \ | |
241 | VALUES, \ | |
242 | COLOURS, \ | |
243 | EDITOR) \ | |
244 | static wxPGChoices gs_##CLASSNAME##_choicesCache; \ | |
245 | WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \ | |
246 | wxColour, const wxColour&,EDITOR) \ | |
247 | CLASSNAME::CLASSNAME( const wxString& label, \ | |
248 | const wxString& name, \ | |
249 | const wxColour& value ) \ | |
250 | : wxSystemColourProperty(label, name, LABELS, VALUES, \ | |
251 | &gs_##CLASSNAME##_choicesCache, value ) \ | |
252 | { \ | |
253 | if ( &value ) \ | |
254 | Init( value ); \ | |
255 | else \ | |
256 | Init( *wxWHITE ); \ | |
257 | m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \ | |
258 | } \ | |
259 | CLASSNAME::~CLASSNAME() { } \ | |
260 | void CLASSNAME::Init( wxColour colour ) \ | |
261 | { \ | |
262 | if ( !colour.Ok() ) \ | |
263 | colour = *wxWHITE; \ | |
264 | wxVariant variant; \ | |
265 | variant << colour; \ | |
266 | m_value = variant; \ | |
267 | int ind = ColToInd(colour); \ | |
268 | if ( ind < 0 ) \ | |
269 | ind = m_choices.GetCount() - 1; \ | |
270 | SetIndex( ind ); \ | |
271 | } \ | |
272 | wxString CLASSNAME::GetValueAsString( int argFlags ) const \ | |
273 | { \ | |
274 | const wxPGEditor* editor = GetEditorClass(); \ | |
275 | if ( editor != wxPG_EDITOR(Choice) && \ | |
276 | editor != wxPG_EDITOR(ChoiceAndButton) && \ | |
277 | editor != wxPG_EDITOR(ComboBox) ) \ | |
278 | argFlags |= wxPG_PROPERTY_SPECIFIC; \ | |
279 | return wxSystemColourProperty::GetValueAsString(argFlags); \ | |
280 | } \ | |
281 | wxColour CLASSNAME::GetColour( int index ) const \ | |
282 | { \ | |
283 | if ( !m_choices.HasValue(index) ) \ | |
284 | { \ | |
285 | wxASSERT( index < (int)GetItemCount() ); \ | |
286 | return COLOURS[index]; \ | |
287 | } \ | |
288 | return COLOURS[m_choices.GetValue(index)]; \ | |
289 | } \ | |
290 | wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \ | |
291 | { \ | |
292 | wxVariant variant; \ | |
293 | variant << v.m_colour; \ | |
294 | return variant; \ | |
295 | } | |
296 | ||
297 | ||
298 | #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \ | |
299 | LABELS, \ | |
300 | VALUES, \ | |
301 | COLOURS) \ | |
302 | WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \ | |
303 | LABELS, \ | |
304 | VALUES, \ | |
305 | COLOURS, \ | |
306 | Choice) | |
307 | ||
308 | // ----------------------------------------------------------------------- | |
309 | ||
310 | // | |
311 | // These macros help creating DoGetValidator | |
312 | #define WX_PG_DOGETVALIDATOR_ENTRY() \ | |
313 | static wxValidator* s_ptr = (wxValidator*) NULL; \ | |
314 | if ( s_ptr ) return s_ptr; | |
315 | ||
316 | // Common function exit | |
317 | #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \ | |
318 | s_ptr = VALIDATOR; \ | |
319 | wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \ | |
320 | return VALIDATOR; | |
321 | ||
322 | // ----------------------------------------------------------------------- | |
323 | ||
324 | #ifndef SWIG | |
325 | ||
326 | /** @class wxPGInDialogValidator | |
327 | @ingroup classes | |
328 | Creates and manages a temporary wxTextCtrl for validation purposes. | |
329 | Uses wxPropertyGrid's current editor, if available. | |
330 | */ | |
331 | class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator | |
332 | { | |
333 | public: | |
334 | wxPGInDialogValidator() | |
335 | { | |
336 | m_textCtrl = NULL; | |
337 | } | |
338 | ||
339 | ~wxPGInDialogValidator() | |
340 | { | |
341 | if ( m_textCtrl ) | |
342 | m_textCtrl->Destroy(); | |
343 | } | |
344 | ||
345 | bool DoValidate( wxPropertyGrid* propGrid, | |
346 | wxValidator* validator, | |
347 | const wxString& value ); | |
348 | ||
349 | private: | |
350 | wxTextCtrl* m_textCtrl; | |
351 | }; | |
352 | ||
353 | #endif // SWIG | |
354 | ||
355 | ||
356 | // ----------------------------------------------------------------------- | |
357 | // Property classes | |
358 | // ----------------------------------------------------------------------- | |
359 | ||
360 | #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2 | |
361 | ||
362 | /** @class wxStringProperty | |
363 | @ingroup classes | |
364 | Basic property with string value. | |
365 | ||
366 | <b>Supported special attributes:</b> | |
367 | - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor. | |
368 | ||
369 | @remarks | |
370 | - If value "<composed>" is set, then actual value is formed (or composed) | |
371 | from values of child properties. | |
372 | */ | |
373 | class WXDLLIMPEXP_PROPGRID wxStringProperty : public wxPGProperty | |
374 | { | |
375 | WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty) | |
376 | public: | |
377 | wxStringProperty( const wxString& label = wxPG_LABEL, | |
378 | const wxString& name = wxPG_LABEL, | |
379 | const wxString& value = wxEmptyString ); | |
380 | virtual ~wxStringProperty(); | |
381 | ||
382 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
383 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
384 | ||
385 | /** This is updated so "<composed>" special value can be handled. | |
386 | */ | |
387 | virtual void OnSetValue(); | |
388 | ||
389 | protected: | |
390 | }; | |
391 | ||
392 | // ----------------------------------------------------------------------- | |
393 | ||
394 | #ifndef SWIG | |
395 | /** Constants used with DoValidation() methods. | |
396 | */ | |
397 | enum | |
398 | { | |
399 | /** Instead of modifying the value, show an error message. | |
400 | */ | |
401 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE = 0, | |
402 | ||
403 | /** Modify value, but stick with the limitations. | |
404 | */ | |
405 | wxPG_PROPERTY_VALIDATION_SATURATE = 1, | |
406 | ||
407 | /** Modify value, wrap around on overflow. | |
408 | */ | |
409 | wxPG_PROPERTY_VALIDATION_WRAP = 2 | |
410 | }; | |
411 | #endif | |
412 | ||
413 | // ----------------------------------------------------------------------- | |
414 | ||
415 | /** @class wxIntProperty | |
416 | @ingroup classes | |
417 | Basic property with integer value. | |
418 | ||
419 | Seamlessly supports 64-bit integer (wxLongLong) on overflow. | |
420 | ||
421 | <b>Example how to use seamless 64-bit integer support</b> | |
422 | ||
423 | Getting value: | |
424 | ||
425 | @code | |
426 | wxLongLong_t value = pg->GetPropertyValueAsLongLong(); | |
427 | @endcode | |
428 | ||
429 | or | |
430 | ||
431 | @code | |
432 | wxLongLong_t value; | |
433 | wxVariant variant = property->GetValue(); | |
434 | if ( variant.GetType() == "wxLongLong" ) | |
435 | value = wxLongLongFromVariant(variant); | |
436 | else | |
437 | value = variant.GetLong(); | |
438 | @endcode | |
439 | ||
440 | Setting value: | |
441 | ||
442 | @code | |
443 | pg->SetPropertyValue(longLongVal); | |
444 | @endcode | |
445 | ||
446 | or | |
447 | ||
448 | @code | |
449 | property->SetValue(WXVARIANT(longLongVal)); | |
450 | @endcode | |
451 | ||
452 | ||
453 | <b>Supported special attributes:</b> | |
454 | - "Min", "Max": Specify acceptable value range. | |
455 | */ | |
456 | class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty | |
457 | { | |
458 | WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty) | |
459 | public: | |
460 | wxIntProperty( const wxString& label = wxPG_LABEL, | |
461 | const wxString& name = wxPG_LABEL, | |
462 | long value = 0 ); | |
463 | virtual ~wxIntProperty(); | |
464 | ||
465 | wxIntProperty( const wxString& label, | |
466 | const wxString& name, | |
467 | const wxLongLong& value ); | |
468 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
469 | virtual bool ValidateValue( wxVariant& value, | |
470 | wxPGValidationInfo& validationInfo ) const; | |
471 | virtual bool IntToValue( wxVariant& variant, | |
472 | int number, | |
473 | int argFlags = 0 ) const; | |
474 | static wxValidator* GetClassValidator(); | |
475 | virtual wxValidator* DoGetValidator() const; | |
476 | ||
477 | /** Validation helper. | |
478 | */ | |
479 | static bool DoValidation( const wxPGProperty* property, | |
480 | wxLongLong_t& value, | |
481 | wxPGValidationInfo* pValidationInfo, | |
482 | int mode = | |
483 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
484 | ||
485 | protected: | |
486 | }; | |
487 | ||
488 | // ----------------------------------------------------------------------- | |
489 | ||
490 | /** @class wxUIntProperty | |
491 | @ingroup classes | |
492 | Basic property with unsigned integer value. | |
493 | Seamlessly supports 64-bit integer (wxULongLong) on overflow. | |
494 | ||
495 | <b>Supported special attributes:</b> | |
496 | - "Min", "Max": Specify acceptable value range. | |
497 | - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC, | |
498 | wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases | |
499 | are <b>not</b> supported. | |
500 | - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and | |
501 | wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal | |
502 | numbers. | |
503 | ||
504 | @remarks | |
505 | - For example how to use seamless 64-bit integer support, see wxIntProperty | |
506 | documentation (just use wxULongLong instead of wxLongLong). | |
507 | */ | |
508 | class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty | |
509 | { | |
510 | WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty) | |
511 | public: | |
512 | wxUIntProperty( const wxString& label = wxPG_LABEL, | |
513 | const wxString& name = wxPG_LABEL, | |
514 | unsigned long value = 0 ); | |
515 | virtual ~wxUIntProperty(); | |
516 | wxUIntProperty( const wxString& label, | |
517 | const wxString& name, | |
518 | const wxULongLong& value ); | |
519 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
520 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
521 | virtual bool ValidateValue( wxVariant& value, | |
522 | wxPGValidationInfo& validationInfo ) const; | |
523 | virtual bool IntToValue( wxVariant& variant, | |
524 | int number, | |
525 | int argFlags = 0 ) const; | |
526 | protected: | |
527 | wxByte m_base; | |
528 | wxByte m_realBase; // translated to 8,16,etc. | |
529 | wxByte m_prefix; | |
530 | private: | |
531 | void Init(); | |
532 | }; | |
533 | ||
534 | // ----------------------------------------------------------------------- | |
535 | ||
536 | /** @class wxFloatProperty | |
537 | @ingroup classes | |
538 | Basic property with double-precision floating point value. | |
539 | ||
540 | <b>Supported special attributes:</b> | |
541 | - "Precision": Sets the (max) precision used when floating point value is | |
542 | rendered as text. The default -1 means infinite precision. | |
543 | */ | |
544 | class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty | |
545 | { | |
546 | WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty) | |
547 | public: | |
548 | wxFloatProperty( const wxString& label = wxPG_LABEL, | |
549 | const wxString& name = wxPG_LABEL, | |
550 | double value = 0.0 ); | |
551 | virtual ~wxFloatProperty(); | |
552 | ||
553 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
554 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
555 | virtual bool ValidateValue( wxVariant& value, | |
556 | wxPGValidationInfo& validationInfo ) const; | |
557 | ||
558 | /** Validation helper. | |
559 | */ | |
560 | static bool DoValidation( const wxPGProperty* property, | |
561 | double& value, | |
562 | wxPGValidationInfo* pValidationInfo, | |
563 | int mode = | |
564 | wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); | |
565 | ||
566 | protected: | |
567 | int m_precision; | |
568 | virtual wxValidator* DoGetValidator () const; | |
569 | }; | |
570 | ||
571 | // ----------------------------------------------------------------------- | |
572 | ||
573 | // Exclude class from wxPython bindings | |
574 | #ifndef SWIG | |
575 | ||
576 | /** @class wxBoolProperty | |
577 | @ingroup classes | |
578 | Basic property with boolean value. | |
579 | ||
580 | <b>Supported special attributes:</b> | |
581 | - "UseCheckbox": Set to 1 to use check box editor instead of combo box. | |
582 | - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list. | |
583 | */ | |
584 | class WXDLLIMPEXP_PROPGRID wxBoolProperty : public wxPGProperty | |
585 | { | |
586 | WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty) | |
587 | public: | |
588 | wxBoolProperty( const wxString& label = wxPG_LABEL, | |
589 | const wxString& name = wxPG_LABEL, | |
590 | bool value = false ); | |
591 | virtual ~wxBoolProperty(); | |
592 | ||
593 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
594 | WX_PG_DECLARE_CHOICE_METHODS() | |
595 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
596 | }; | |
597 | ||
598 | #endif // !SWIG | |
599 | ||
600 | // ----------------------------------------------------------------------- | |
601 | ||
602 | /** @class wxBaseEnumProperty | |
603 | @ingroup classes | |
604 | Derive dynamic custom properties with choices from this class. | |
605 | ||
606 | @remarks | |
607 | - Updating private index is important. You can do this either by calling | |
608 | SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue | |
609 | be called (by not implementing it, or by calling super class function in | |
610 | it) -OR- you can just call SetIndex in OnSetValue. | |
611 | */ | |
612 | class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty : public wxPGProperty | |
613 | { | |
614 | public: | |
615 | wxBaseEnumProperty( const wxString& label = wxPG_LABEL, | |
616 | const wxString& name = wxPG_LABEL ); | |
617 | ||
618 | virtual void OnSetValue(); | |
619 | virtual wxString GetValueAsString( int argFlags ) const; | |
620 | virtual bool StringToValue( wxVariant& variant, | |
621 | const wxString& text, | |
622 | int argFlags = 0 ) const; | |
623 | virtual bool ValidateValue( wxVariant& value, | |
624 | wxPGValidationInfo& validationInfo ) const; | |
625 | ||
626 | // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted | |
627 | // as index to choices list. Otherwise, it is actual value. | |
628 | virtual bool IntToValue( wxVariant& variant, | |
629 | int number, | |
630 | int argFlags = 0 ) const; | |
631 | ||
632 | // | |
633 | // Additional virtuals | |
634 | ||
635 | // This must be overridden to have non-index based value | |
636 | virtual int GetIndexForValue( int value ) const; | |
637 | ||
638 | // This returns string and value for index | |
639 | // Returns NULL if beyond last item | |
640 | // pvalue is never NULL - always set it. | |
641 | virtual const wxString* GetEntry( size_t index, int* pvalue ) const = 0; | |
642 | ||
643 | int GetValueForIndex( size_t index ) const | |
644 | { | |
645 | int v; | |
646 | GetEntry( index, &v ); | |
647 | return v; | |
648 | } | |
649 | ||
650 | protected: | |
651 | ||
652 | int GetIndex() const; | |
653 | void SetIndex( int index ); | |
654 | ||
655 | bool ValueFromString_( wxVariant& value, | |
656 | const wxString& text, | |
657 | int argFlags ) const; | |
658 | bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const; | |
659 | ||
660 | static void ResetNextIndex() { ms_nextIndex = -2; } | |
661 | ||
662 | private: | |
663 | // This is private so that classes are guaranteed to use GetIndex | |
664 | // for up-to-date index value. | |
665 | int m_index; | |
666 | ||
667 | // Relies on ValidateValue being called always before OnSetValue | |
668 | static int ms_nextIndex; | |
669 | }; | |
670 | ||
671 | // ----------------------------------------------------------------------- | |
672 | ||
673 | // If set, then selection of choices is static and should not be | |
674 | // changed (i.e. returns NULL in GetPropertyChoices). | |
675 | #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1 | |
676 | ||
677 | /** @class wxEnumProperty | |
678 | @ingroup classes | |
679 | You can derive custom properties with choices from this class. See | |
680 | wxBaseEnumProperty for remarks. | |
681 | */ | |
682 | class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxBaseEnumProperty | |
683 | { | |
684 | WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty) | |
685 | public: | |
686 | ||
687 | #ifndef SWIG | |
688 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
689 | const wxString& name = wxPG_LABEL, | |
690 | const wxChar** labels = NULL, | |
691 | const long* values = NULL, | |
692 | int value = 0 ); | |
693 | wxEnumProperty( const wxString& label, | |
694 | const wxString& name, | |
695 | wxPGChoices& choices, | |
696 | int value = 0 ); | |
697 | ||
698 | // Special constructor for caching choices (used by derived class) | |
699 | wxEnumProperty( const wxString& label, | |
700 | const wxString& name, | |
701 | const wxChar** labels, | |
702 | const long* values, | |
703 | wxPGChoices* choicesCache, | |
704 | int value = 0 ); | |
705 | ||
706 | wxEnumProperty( const wxString& label, | |
707 | const wxString& name, | |
708 | const wxArrayString& labels, | |
709 | const wxArrayInt& values = wxArrayInt(), | |
710 | int value = 0 ); | |
711 | #else | |
712 | wxEnumProperty( const wxString& label = wxPG_LABEL, | |
713 | const wxString& name = wxPG_LABEL, | |
714 | const wxArrayString& labels = wxArrayString(), | |
715 | const wxArrayInt& values = wxArrayInt(), | |
716 | int value = 0 ); | |
717 | #endif | |
718 | ||
719 | virtual ~wxEnumProperty(); | |
720 | ||
721 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
722 | virtual int GetIndexForValue( int value ) const; | |
723 | virtual const wxString* GetEntry( size_t index, int* pvalue ) const; | |
724 | ||
725 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
726 | const wxPGChoices& GetChoices() const { return m_choices; } | |
727 | ||
728 | protected: | |
729 | wxPGChoices m_choices; | |
730 | }; | |
731 | ||
732 | // ----------------------------------------------------------------------- | |
733 | ||
734 | /** @class wxEditEnumProperty | |
735 | @ingroup classes | |
736 | wxEnumProperty with wxString value and writable combo box editor. | |
737 | ||
738 | @remarks | |
739 | Uses int value, similar to wxEnumProperty, unless text entered by user is | |
740 | is not in choices (in which case string value is used). | |
741 | */ | |
742 | class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty | |
743 | { | |
744 | WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty) | |
745 | public: | |
746 | ||
747 | wxEditEnumProperty( const wxString& label, | |
748 | const wxString& name, | |
749 | const wxChar** labels, | |
750 | const long* values, | |
751 | const wxString& value ); | |
752 | wxEditEnumProperty( const wxString& label = wxPG_LABEL, | |
753 | const wxString& name = wxPG_LABEL, | |
754 | const wxArrayString& labels = wxArrayString(), | |
755 | const wxArrayInt& values = wxArrayInt(), | |
756 | const wxString& value = wxEmptyString ); | |
757 | wxEditEnumProperty( const wxString& label, | |
758 | const wxString& name, | |
759 | wxPGChoices& choices, | |
760 | const wxString& value = wxEmptyString ); | |
761 | ||
762 | // Special constructor for caching choices (used by derived class) | |
763 | wxEditEnumProperty( const wxString& label, | |
764 | const wxString& name, | |
765 | const wxChar** labels, | |
766 | const long* values, | |
767 | wxPGChoices* choicesCache, | |
768 | const wxString& value ); | |
769 | ||
770 | virtual ~wxEditEnumProperty(); | |
771 | ||
772 | protected: | |
773 | }; | |
774 | ||
775 | // ----------------------------------------------------------------------- | |
776 | ||
777 | /** @class wxFlagsProperty | |
778 | @ingroup classes | |
779 | Represents a bit set that fits in a long integer. wxBoolProperty | |
780 | sub-properties are created for editing individual bits. Textctrl is created | |
781 | to manually edit the flags as a text; a continous sequence of spaces, | |
782 | commas and semicolons is considered as a flag id separator. | |
783 | <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty, | |
784 | you will need to use SetPropertyChoices - otherwise they will not get | |
785 | updated properly. | |
786 | */ | |
787 | class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty | |
788 | { | |
789 | WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty) | |
790 | public: | |
791 | ||
792 | #ifndef SWIG | |
793 | wxFlagsProperty( const wxString& label, | |
794 | const wxString& name, | |
795 | const wxChar** labels, | |
796 | const long* values = NULL, | |
797 | long value = 0 ); | |
798 | wxFlagsProperty( const wxString& label, | |
799 | const wxString& name, | |
800 | wxPGChoices& choices, | |
801 | long value = 0 ); | |
802 | #endif | |
803 | wxFlagsProperty( const wxString& label = wxPG_LABEL, | |
804 | const wxString& name = wxPG_LABEL, | |
805 | const wxArrayString& labels = wxArrayString(), | |
806 | const wxArrayInt& values = wxArrayInt(), | |
807 | int value = 0 ); | |
808 | virtual ~wxFlagsProperty (); | |
809 | ||
810 | virtual void OnSetValue(); | |
811 | virtual wxString GetValueAsString( int argFlags ) const; | |
812 | virtual bool StringToValue( wxVariant& variant, | |
813 | const wxString& text, | |
814 | int flags ) const; | |
815 | virtual void ChildChanged( wxVariant& thisValue, | |
816 | int childIndex, | |
817 | wxVariant& childValue ) const; | |
818 | virtual void RefreshChildren(); | |
819 | ||
820 | // this is necessary for conveying m_choices | |
821 | virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo ); | |
822 | ||
823 | // helpers | |
824 | size_t GetItemCount() const { return m_choices.GetCount(); } | |
825 | const wxString& GetLabel( size_t ind ) const | |
826 | { return m_choices.GetLabel(ind); } | |
827 | ||
828 | protected: | |
829 | wxPGChoices m_choices; | |
830 | ||
831 | // Used to detect if choices have been changed | |
832 | wxPGChoicesData* m_oldChoicesData; | |
833 | ||
834 | // Needed to properly mark changed sub-properties | |
835 | long m_oldValue; | |
836 | ||
837 | // Converts string id to a relevant bit. | |
838 | long IdToBit( const wxString& id ) const; | |
839 | ||
840 | // Creates children and sets value. | |
841 | void Init(); | |
842 | }; | |
843 | ||
844 | // ----------------------------------------------------------------------- | |
845 | ||
846 | /** @class wxPGFileDialogAdapter | |
847 | @ingroup classes | |
848 | */ | |
849 | class WXDLLIMPEXP_PROPGRID | |
850 | wxPGFileDialogAdapter : public wxPGEditorDialogAdapter | |
851 | { | |
852 | public: | |
853 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
854 | wxPGProperty* property ); | |
855 | }; | |
856 | ||
857 | // ----------------------------------------------------------------------- | |
858 | ||
859 | #include "wx/filename.h" | |
860 | ||
861 | // Indicates first bit useable by derived properties. | |
862 | #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1 | |
863 | ||
864 | /** @class wxFileProperty | |
865 | @ingroup classes | |
866 | Like wxLongStringProperty, but the button triggers file selector instead. | |
867 | ||
868 | <b>Supported special attributes:</b> | |
869 | - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All | |
870 | files..." is default. | |
871 | - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive | |
872 | and directory are hidden). | |
873 | - "ShowRelativePath": If set, then the filename is shown relative to the | |
874 | given path string. | |
875 | - "InitialPath": Sets the initial path of where to look for files. | |
876 | - "DialogTitle": Sets a specific title for the dir dialog. | |
877 | */ | |
878 | class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty | |
879 | { | |
880 | friend class wxPGFileDialogAdapter; | |
881 | WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty) | |
882 | public: | |
883 | ||
884 | wxFileProperty( const wxString& label = wxPG_LABEL, | |
885 | const wxString& name = wxPG_LABEL, | |
886 | const wxString& value = wxEmptyString ); | |
887 | virtual ~wxFileProperty (); | |
888 | ||
889 | virtual void OnSetValue(); | |
890 | virtual wxString GetValueAsString( int argFlags ) const; | |
891 | virtual bool StringToValue( wxVariant& variant, | |
892 | const wxString& text, | |
893 | int argFlags = 0 ) const; | |
894 | virtual wxPGEditorDialogAdapter* GetEditorDialog() const; | |
895 | ||
896 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
897 | ||
898 | static wxValidator* GetClassValidator(); | |
899 | virtual wxValidator* DoGetValidator() const; | |
900 | ||
901 | protected: | |
902 | wxString m_wildcard; | |
903 | wxString m_basePath; // If set, then show path relative to it | |
904 | wxString m_initialPath; // If set, start the file dialog here | |
905 | wxString m_dlgTitle; // If set, used as title for file dialog | |
906 | wxFileName m_filename; // used as primary storage | |
907 | int m_indFilter; // index to the selected filter | |
908 | }; | |
909 | ||
910 | // ----------------------------------------------------------------------- | |
911 | ||
912 | #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1 | |
913 | ||
914 | ||
915 | /** @class wxPGLongStringDialogAdapter | |
916 | @ingroup classes | |
917 | */ | |
918 | class WXDLLIMPEXP_PROPGRID | |
919 | wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter | |
920 | { | |
921 | public: | |
922 | virtual bool DoShowDialog( wxPropertyGrid* propGrid, | |
923 | wxPGProperty* property ); | |
924 | }; | |
925 | ||
926 | ||
927 | /** @class wxLongStringProperty | |
928 | @ingroup classes | |
929 | Like wxStringProperty, but has a button that triggers a small text | |
930 | editor dialog. | |
931 | */ | |
932 | class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty | |
933 | { | |
934 | WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty) | |
935 | public: | |
936 | ||
937 | wxLongStringProperty( const wxString& label = wxPG_LABEL, | |
938 | const wxString& name = wxPG_LABEL, | |
939 | const wxString& value = wxEmptyString ); | |
940 | virtual ~wxLongStringProperty(); | |
941 | ||
942 | virtual wxString GetValueAsString( int argFlags = 0 ) const; | |
943 | virtual bool StringToValue( wxVariant& variant, | |
944 | const wxString& text, | |
945 | int argFlags = 0 ) const; | |
946 | ||
947 | WX_PG_DECLARE_EVENT_METHODS() | |
948 | ||
949 | // Shows string editor dialog. Value to be edited should be read from | |
950 | // value, and if dialog is not cancelled, it should be stored back and true | |
951 | // should be returned if that was the case. | |
952 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); | |
953 | ||
954 | static bool DisplayEditorDialog( wxPGProperty* prop, | |
955 | wxPropertyGrid* propGrid, | |
956 | wxString& value ); | |
957 | ||
958 | protected: | |
959 | }; | |
960 | ||
961 | // ----------------------------------------------------------------------- | |
962 | ||
963 | ||
964 | // Exclude class from wxPython bindings | |
965 | #ifndef SWIG | |
966 | ||
967 | /** @class wxDirProperty | |
968 | @ingroup classes | |
969 | Like wxLongStringProperty, but the button triggers dir selector instead. | |
970 | ||
971 | <b>Supported special attributes:</b> | |
972 | - "DialogMessage": Sets specific message in the dir selector. | |
973 | */ | |
974 | class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty | |
975 | { | |
976 | #ifndef SWIG | |
977 | DECLARE_DYNAMIC_CLASS(wxDirProperty) | |
978 | #endif | |
979 | public: | |
980 | wxDirProperty( const wxString& name = wxPG_LABEL, | |
981 | const wxString& label = wxPG_LABEL, | |
982 | const wxString& value = wxEmptyString ); | |
983 | virtual ~wxDirProperty(); | |
984 | ||
985 | WX_PG_DECLARE_ATTRIBUTE_METHODS() | |
986 | WX_PG_DECLARE_VALIDATOR_METHODS() | |
987 | ||
988 | virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value ); | |
989 | ||
990 | protected: | |
991 | wxString m_dlgMessage; | |
992 | }; | |
993 | ||
994 | #endif // !SWIG | |
995 | ||
996 | // ----------------------------------------------------------------------- | |
997 | ||
998 | // wxBoolProperty specific flags | |
999 | #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1 | |
1000 | // DCC = Double Click Cycles | |
1001 | #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2 | |
1002 | ||
1003 | ||
1004 | // ----------------------------------------------------------------------- | |
1005 | ||
1006 | /** @class wxArrayStringProperty | |
1007 | @ingroup classes | |
1008 | Property that manages a list of strings. | |
1009 | */ | |
1010 | class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty | |
1011 | { | |
1012 | WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty) | |
1013 | public: | |
1014 | ||
1015 | wxArrayStringProperty( const wxString& label = wxPG_LABEL, | |
1016 | const wxString& name = wxPG_LABEL, | |
1017 | const wxArrayString& value = wxArrayString() ); | |
1018 | virtual ~wxArrayStringProperty(); | |
1019 | ||
1020 | virtual void OnSetValue(); | |
1021 | WX_PG_DECLARE_BASIC_TYPE_METHODS() | |
1022 | WX_PG_DECLARE_EVENT_METHODS() | |
1023 | ||
1024 | virtual void GenerateValueAsString(); | |
1025 | ||
1026 | // Shows string editor dialog. Value to be edited should be read from | |
1027 | // value, and if dialog is not cancelled, it should be stored back and true | |
1028 | // should be returned if that was the case. | |
1029 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); | |
1030 | ||
1031 | // Helper. | |
1032 | virtual bool OnButtonClick( wxPropertyGrid* propgrid, | |
1033 | wxWindow* primary, | |
1034 | const wxChar* cbt ); | |
1035 | ||
1036 | #ifndef SWIG | |
1037 | // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick. | |
1038 | virtual wxArrayEditorDialog* CreateEditorDialog(); | |
1039 | #endif | |
1040 | ||
1041 | protected: | |
1042 | wxString m_display; // Cache for displayed text. | |
1043 | }; | |
1044 | ||
1045 | // ----------------------------------------------------------------------- | |
1046 | ||
1047 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \ | |
1048 | DECL) \ | |
1049 | DECL PROPNAME : public wxArrayStringProperty \ | |
1050 | { \ | |
1051 | WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \ | |
1052 | public: \ | |
1053 | PROPNAME( const wxString& label = wxPG_LABEL, \ | |
1054 | const wxString& name = wxPG_LABEL, \ | |
1055 | const wxArrayString& value = wxArrayString() ); \ | |
1056 | ~PROPNAME(); \ | |
1057 | virtual void GenerateValueAsString(); \ | |
1058 | virtual bool StringToValue( wxVariant& value, \ | |
1059 | const wxString& text, int = 0 ) const; \ | |
1060 | virtual bool OnEvent( wxPropertyGrid* propgrid, \ | |
1061 | wxWindow* primary, wxEvent& event ); \ | |
1062 | virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \ | |
1063 | WX_PG_DECLARE_VALIDATOR_METHODS() \ | |
1064 | }; | |
1065 | ||
1066 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \ | |
1067 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class) | |
1068 | ||
1069 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
1070 | DELIMCHAR, \ | |
1071 | CUSTBUTTXT) \ | |
1072 | WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \ | |
1073 | wxArrayString, const wxArrayString&, \ | |
1074 | TextCtrlAndButton) \ | |
1075 | PROPNAME::PROPNAME( const wxString& label, \ | |
1076 | const wxString& name, \ | |
1077 | const wxArrayString& value ) \ | |
1078 | : wxArrayStringProperty(label,name,value) \ | |
1079 | { \ | |
1080 | PROPNAME::GenerateValueAsString(); \ | |
1081 | } \ | |
1082 | PROPNAME::~PROPNAME() { } \ | |
1083 | void PROPNAME::GenerateValueAsString() \ | |
1084 | { \ | |
1085 | wxChar delimChar = DELIMCHAR; \ | |
1086 | if ( delimChar == wxS('"') ) \ | |
1087 | wxArrayStringProperty::GenerateValueAsString(); \ | |
1088 | else \ | |
1089 | wxPropertyGrid::ArrayStringToString(m_display, \ | |
1090 | m_value.GetArrayString(), \ | |
1091 | 0,DELIMCHAR,0); \ | |
1092 | } \ | |
1093 | bool PROPNAME::StringToValue( wxVariant& variant, \ | |
1094 | const wxString& text, int ) const \ | |
1095 | { \ | |
1096 | wxChar delimChar = DELIMCHAR; \ | |
1097 | if ( delimChar == wxS('"') ) \ | |
1098 | return wxArrayStringProperty::StringToValue(variant, text, 0); \ | |
1099 | \ | |
1100 | wxArrayString arr; \ | |
1101 | WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \ | |
1102 | arr.Add( token ); \ | |
1103 | WX_PG_TOKENIZER1_END() \ | |
1104 | variant = arr; \ | |
1105 | return true; \ | |
1106 | } \ | |
1107 | bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \ | |
1108 | wxWindow* primary, wxEvent& event ) \ | |
1109 | { \ | |
1110 | if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \ | |
1111 | return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \ | |
1112 | return false; \ | |
1113 | } | |
1114 | ||
1115 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \ | |
1116 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME) | |
1117 | ||
1118 | #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \ | |
1119 | WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL) | |
1120 | ||
1121 | #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \ | |
1122 | WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \ | |
1123 | DELIMCHAR, \ | |
1124 | CUSTBUTTXT) \ | |
1125 | wxValidator* PROPNAME::DoGetValidator () const \ | |
1126 | { return (wxValidator*) NULL; } | |
1127 | ||
1128 | ||
1129 | // ----------------------------------------------------------------------- | |
1130 | // wxArrayEditorDialog | |
1131 | // ----------------------------------------------------------------------- | |
1132 | ||
1133 | #include "wx/textctrl.h" | |
1134 | #include "wx/button.h" | |
1135 | #include "wx/listbox.h" | |
1136 | ||
1137 | #define wxAEDIALOG_STYLE \ | |
1138 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
1139 | ||
1140 | class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog : public wxDialog | |
1141 | { | |
1142 | public: | |
1143 | wxArrayEditorDialog(); | |
1144 | virtual ~wxArrayEditorDialog() { } | |
1145 | ||
1146 | void Init(); | |
1147 | ||
1148 | wxArrayEditorDialog( wxWindow *parent, | |
1149 | const wxString& message, | |
1150 | const wxString& caption, | |
1151 | long style = wxAEDIALOG_STYLE, | |
1152 | const wxPoint& pos = wxDefaultPosition, | |
1153 | const wxSize& sz = wxDefaultSize ); | |
1154 | ||
1155 | bool Create( wxWindow *parent, | |
1156 | const wxString& message, | |
1157 | const wxString& caption, | |
1158 | long style = wxAEDIALOG_STYLE, | |
1159 | const wxPoint& pos = wxDefaultPosition, | |
1160 | const wxSize& sz = wxDefaultSize ); | |
1161 | ||
1162 | /** Set value modified by dialog. | |
1163 | */ | |
1164 | virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) | |
1165 | { | |
1166 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
1167 | } | |
1168 | ||
1169 | /** Return value modified by dialog. | |
1170 | */ | |
1171 | virtual wxVariant GetDialogValue() const | |
1172 | { | |
1173 | wxFAIL_MSG(wxT("re-implement this member function in derived class")); | |
1174 | return wxVariant(); | |
1175 | } | |
1176 | ||
1177 | /** Override to return wxValidator to be used with the wxTextCtrl | |
1178 | in dialog. Note that the validator is used in the standard | |
1179 | wx way, ie. it immediately prevents user from entering invalid | |
1180 | input. | |
1181 | ||
1182 | @remarks | |
1183 | Dialog frees the validator. | |
1184 | */ | |
1185 | virtual wxValidator* GetTextCtrlValidator() const | |
1186 | { | |
1187 | return (wxValidator*) NULL; | |
1188 | } | |
1189 | ||
1190 | // Returns true if array was actually modified | |
1191 | bool IsModified() const { return m_modified; } | |
1192 | ||
1193 | //const wxArrayString& GetStrings() const { return m_array; } | |
1194 | ||
1195 | // implementation from now on | |
1196 | void OnUpdateClick(wxCommandEvent& event); | |
1197 | void OnAddClick(wxCommandEvent& event); | |
1198 | void OnDeleteClick(wxCommandEvent& event); | |
1199 | void OnListBoxClick(wxCommandEvent& event); | |
1200 | void OnUpClick(wxCommandEvent& event); | |
1201 | void OnDownClick(wxCommandEvent& event); | |
1202 | //void OnCustomEditClick(wxCommandEvent& event); | |
1203 | void OnIdle(wxIdleEvent& event); | |
1204 | ||
1205 | protected: | |
1206 | wxTextCtrl* m_edValue; | |
1207 | wxListBox* m_lbStrings; | |
1208 | ||
1209 | wxButton* m_butAdd; // Button pointers | |
1210 | wxButton* m_butCustom; // required for disabling/enabling changing. | |
1211 | wxButton* m_butUpdate; | |
1212 | wxButton* m_butRemove; | |
1213 | wxButton* m_butUp; | |
1214 | wxButton* m_butDown; | |
1215 | ||
1216 | //wxArrayString m_array; | |
1217 | ||
1218 | const wxChar* m_custBtText; | |
1219 | //wxArrayStringPropertyClass* m_pCallingClass; | |
1220 | ||
1221 | bool m_modified; | |
1222 | ||
1223 | unsigned char m_curFocus; | |
1224 | ||
1225 | // These must be overridden - must return true on success. | |
1226 | virtual wxString ArrayGet( size_t index ) = 0; | |
1227 | virtual size_t ArrayGetCount() = 0; | |
1228 | virtual bool ArrayInsert( const wxString& str, int index ) = 0; | |
1229 | virtual bool ArraySet( size_t index, const wxString& str ) = 0; | |
1230 | virtual void ArrayRemoveAt( int index ) = 0; | |
1231 | virtual void ArraySwap( size_t first, size_t second ) = 0; | |
1232 | ||
1233 | private: | |
1234 | #ifndef SWIG | |
1235 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog) | |
1236 | DECLARE_EVENT_TABLE() | |
1237 | #endif | |
1238 | }; | |
1239 | ||
1240 | // ----------------------------------------------------------------------- | |
1241 | // wxPGArrayStringEditorDialog | |
1242 | // ----------------------------------------------------------------------- | |
1243 | ||
1244 | class WXDLLIMPEXP_PROPGRID | |
1245 | wxPGArrayStringEditorDialog : public wxArrayEditorDialog | |
1246 | { | |
1247 | public: | |
1248 | wxPGArrayStringEditorDialog(); | |
1249 | virtual ~wxPGArrayStringEditorDialog() { } | |
1250 | ||
1251 | void Init(); | |
1252 | ||
1253 | virtual void SetDialogValue( const wxVariant& value ) | |
1254 | { | |
1255 | m_array = value.GetArrayString(); | |
1256 | } | |
1257 | ||
1258 | virtual wxVariant GetDialogValue() const | |
1259 | { | |
1260 | return m_array; | |
1261 | } | |
1262 | ||
1263 | void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc ) | |
1264 | { | |
1265 | m_custBtText = custBtText; | |
1266 | m_pCallingClass = pcc; | |
1267 | } | |
1268 | ||
1269 | void OnCustomEditClick(wxCommandEvent& event); | |
1270 | ||
1271 | protected: | |
1272 | wxArrayString m_array; | |
1273 | ||
1274 | wxArrayStringProperty* m_pCallingClass; | |
1275 | ||
1276 | virtual wxString ArrayGet( size_t index ); | |
1277 | virtual size_t ArrayGetCount(); | |
1278 | virtual bool ArrayInsert( const wxString& str, int index ); | |
1279 | virtual bool ArraySet( size_t index, const wxString& str ); | |
1280 | virtual void ArrayRemoveAt( int index ); | |
1281 | virtual void ArraySwap( size_t first, size_t second ); | |
1282 | ||
1283 | private: | |
1284 | #ifndef SWIG | |
1285 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog) | |
1286 | DECLARE_EVENT_TABLE() | |
1287 | #endif | |
1288 | }; | |
1289 | ||
1290 | // ----------------------------------------------------------------------- | |
1291 | ||
f4bc1aa2 JS |
1292 | #endif // wxUSE_PROPGRID |
1293 | ||
1c4293cb | 1294 | #endif // _WX_PROPGRID_PROPS_H_ |