]> git.saurik.com Git - wxWidgets.git/blob - include/wx/propgrid/property.h
Eliminate (or at least reduce) 64-bit build warnings (as described in wxPG sourceforg...
[wxWidgets.git] / include / wx / propgrid / property.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/property.h
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2008-08-23
7 // RCS-ID: $Id$
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROPGRID_PROPERTY_H_
13 #define _WX_PROPGRID_PROPERTY_H_
14
15 #if wxUSE_PROPGRID
16
17 #include "wx/propgrid/propgriddefs.h"
18
19 // -----------------------------------------------------------------------
20
21 #define wxNullProperty ((wxPGProperty*)NULL)
22
23
24 /** @class wxPGPaintData
25
26 Contains information relayed to property's OnCustomPaint.
27 */
28 struct wxPGPaintData
29 {
30 /** wxPropertyGrid. */
31 const wxPropertyGrid* m_parent;
32
33 /**
34 Normally -1, otherwise index to drop-down list item that has to be
35 drawn.
36 */
37 int m_choiceItem;
38
39 /** Set to drawn width in OnCustomPaint (optional). */
40 int m_drawnWidth;
41
42 /**
43 In a measure item call, set this to the height of item at m_choiceItem
44 index.
45 */
46 int m_drawnHeight;
47 };
48
49
50 #ifndef SWIG
51
52
53 // space between vertical sides of a custom image
54 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
55
56 // space between caption and selection rectangle,
57 #define wxPG_CAPRECTXMARGIN 2
58
59 // horizontally and vertically
60 #define wxPG_CAPRECTYMARGIN 1
61
62
63 /** @class wxPGCellRenderer
64
65 Base class for wxPropertyGrid cell renderers.
66 */
67 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
68 {
69 public:
70
71 wxPGCellRenderer( unsigned int refCount = 1 )
72 : m_refCount(refCount) { }
73 virtual ~wxPGCellRenderer() { }
74
75 // Render flags
76 enum
77 {
78 Selected = 0x00010000,
79 Control = 0x00020000
80 };
81
82 virtual void Render( wxDC& dc,
83 const wxRect& rect,
84 const wxPropertyGrid* propertyGrid,
85 wxPGProperty* property,
86 int column,
87 int item,
88 int flags ) const = 0;
89
90 /** Returns size of the image in front of the editable area.
91 @remarks
92 If property is NULL, then this call is for a custom value. In that case
93 the item is index to wxPropertyGrid's custom values.
94 */
95 virtual wxSize GetImageSize( const wxPGProperty* property,
96 int column,
97 int item ) const;
98
99 /** Paints property category selection rectangle.
100 */
101 virtual void DrawCaptionSelectionRect( wxDC& dc,
102 int x, int y,
103 int w, int h ) const;
104
105 /** Utility to draw vertically centered text.
106 */
107 void DrawText( wxDC& dc,
108 const wxRect& rect,
109 int imageWidth,
110 const wxString& text ) const;
111
112 /**
113 Utility to draw editor's value, or vertically aligned text if editor is
114 NULL.
115 */
116 void DrawEditorValue( wxDC& dc, const wxRect& rect,
117 int xOffset, const wxString& text,
118 wxPGProperty* property,
119 const wxPGEditor* editor ) const;
120
121 /** Utility to render cell bitmap and set text colour plus bg brush colour.
122
123 Returns image width that, for instance, can be passed to DrawText.
124 */
125 int PreDrawCell( wxDC& dc,
126 const wxRect& rect,
127 const wxPGCell& cell,
128 int flags ) const;
129
130 void IncRef()
131 {
132 m_refCount++;
133 }
134
135 void DecRef()
136 {
137 m_refCount--;
138 if ( !m_refCount )
139 delete this;
140 }
141 protected:
142
143 private:
144 unsigned int m_refCount;
145 };
146
147
148 /** @class wxPGCell
149
150 Base class for simple wxPropertyGrid cell information.
151 */
152 class WXDLLIMPEXP_PROPGRID wxPGCell
153 {
154 public:
155 wxPGCell();
156 wxPGCell( const wxString& text,
157 const wxBitmap& bitmap = wxNullBitmap,
158 const wxColour& fgCol = wxNullColour,
159 const wxColour& bgCol = wxNullColour );
160
161 virtual ~wxPGCell() { }
162
163 void SetText( const wxString& text ) { m_text = text; }
164 void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
165 void SetFgCol( const wxColour& col ) { m_fgCol = col; }
166 void SetBgCol( const wxColour& col ) { m_bgCol = col; }
167
168 const wxString& GetText() const { return m_text; }
169 const wxBitmap& GetBitmap() const { return m_bitmap; }
170 const wxColour& GetFgCol() const { return m_fgCol; }
171 const wxColour& GetBgCol() const { return m_bgCol; }
172
173 protected:
174 wxString m_text;
175 wxBitmap m_bitmap;
176 wxColour m_fgCol;
177 wxColour m_bgCol;
178 };
179
180
181 /** @class wxPGDefaultRenderer
182
183 Default cell renderer, that can handles the common
184 scenarios.
185 */
186 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
187 {
188 public:
189 virtual void Render( wxDC& dc,
190 const wxRect& rect,
191 const wxPropertyGrid* propertyGrid,
192 wxPGProperty* property,
193 int column,
194 int item,
195 int flags ) const;
196
197 virtual wxSize GetImageSize( const wxPGProperty* property,
198 int column,
199 int item ) const;
200
201 protected:
202 };
203
204 // -----------------------------------------------------------------------
205
206 /** @class wxPGAttributeStorage
207
208 wxPGAttributeStorage is somewhat optimized storage for
209 key=variant pairs (ie. a map).
210 */
211 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
212 {
213 public:
214 wxPGAttributeStorage();
215 ~wxPGAttributeStorage();
216
217 void Set( const wxString& name, const wxVariant& value );
218 unsigned int GetCount() const { return (unsigned int) m_map.size(); }
219 wxVariant FindValue( const wxString& name ) const
220 {
221 wxPGHashMapS2P::const_iterator it = m_map.find(name);
222 if ( it != m_map.end() )
223 {
224 wxVariantData* data = (wxVariantData*) it->second;
225 data->IncRef();
226 return wxVariant(data, it->first);
227 }
228 return wxVariant();
229 }
230
231 typedef wxPGHashMapS2P::const_iterator const_iterator;
232 const_iterator StartIteration() const
233 {
234 return m_map.begin();
235 }
236 bool GetNext( const_iterator& it, wxVariant& variant ) const
237 {
238 if ( it == m_map.end() )
239 return false;
240
241 wxVariantData* data = (wxVariantData*) it->second;
242 data->IncRef();
243 variant.SetData(data);
244 variant.SetName(it->first);
245 it++;
246 return true;
247 }
248
249 protected:
250 wxPGHashMapS2P m_map;
251 };
252
253 #endif // !SWIG
254
255 // -----------------------------------------------------------------------
256
257 /** @section propgrid_propflags wxPGProperty Flags
258 @{
259 */
260
261 enum wxPG_PROPERTY_FLAGS
262 {
263
264 /** Indicates bold font.
265 */
266 wxPG_PROP_MODIFIED = 0x0001,
267
268 /** Disables ('greyed' text and editor does not activate) property.
269 */
270 wxPG_PROP_DISABLED = 0x0002,
271
272 /** Hider button will hide this property.
273 */
274 wxPG_PROP_HIDDEN = 0x0004,
275
276 /** This property has custom paint image just in front of its value.
277 If property only draws custom images into a popup list, then this
278 flag should not be set.
279 */
280 wxPG_PROP_CUSTOMIMAGE = 0x0008,
281
282 /** Do not create text based editor for this property (but button-triggered
283 dialog and choice are ok).
284 */
285 wxPG_PROP_NOEDITOR = 0x0010,
286
287 /** Property is collapsed, ie. it's children are hidden.
288 */
289 wxPG_PROP_COLLAPSED = 0x0020,
290
291 /**
292 If property is selected, then indicates that validation failed for pending
293 value.
294
295 If property is not selected, then indicates that the the actual property
296 value has failed validation (NB: this behavior is not currently supported,
297 but may be used in future).
298 */
299 wxPG_PROP_INVALID_VALUE = 0x0040,
300
301 // 0x0080,
302
303 /** Switched via SetWasModified(). Temporary flag - only used when
304 setting/changing property value.
305 */
306 wxPG_PROP_WAS_MODIFIED = 0x0200,
307
308 /**
309 If set, then child properties (if any) are private, and should be
310 "invisible" to the application.
311 */
312 wxPG_PROP_AGGREGATE = 0x0400,
313
314 /** If set, then child properties (if any) are copies and should not
315 be deleted in dtor.
316 */
317 wxPG_PROP_CHILDREN_ARE_COPIES = 0x0800,
318
319 /**
320 Classifies this item as a non-category.
321
322 Used for faster item type identification.
323 */
324 wxPG_PROP_PROPERTY = 0x1000,
325
326 /**
327 Classifies this item as a category.
328
329 Used for faster item type identification.
330 */
331 wxPG_PROP_CATEGORY = 0x2000,
332
333 /** Classifies this item as a property that has children, but is not aggregate
334 (ie children are not private).
335 */
336 wxPG_PROP_MISC_PARENT = 0x4000,
337
338 /** Property is read-only. Editor is still created.
339 */
340 wxPG_PROP_READONLY = 0x8000,
341
342 //
343 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
344 //
345
346 /** Property's value is composed from values of child properties.
347 @remarks
348 This flag cannot be used with property iterators.
349 */
350 wxPG_PROP_COMPOSED_VALUE = 0x00010000,
351
352 /** Common value of property is selectable in editor.
353 @remarks
354 This flag cannot be used with property iterators.
355 */
356 wxPG_PROP_USES_COMMON_VALUE = 0x00020000,
357
358 /** Property can be set to unspecified value via editor.
359 Currently, this applies to following properties:
360 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
361 Clear the text field
362
363 @remarks
364 This flag cannot be used with property iterators.
365 */
366 wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000,
367
368 /** Indicates the bit useable by derived properties.
369 */
370 wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000,
371
372 /** Indicates the bit useable by derived properties.
373 */
374 wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000
375
376 };
377
378 /** Topmost flag.
379 */
380 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
381
382 /** Property with children must have one of these set, otherwise iterators
383 will not work correctly.
384 Code should automatically take care of this, however.
385 */
386 #define wxPG_PROP_PARENTAL_FLAGS \
387 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
388
389 /** @}
390 */
391
392 // Amalgam of flags that should be inherited by sub-properties
393 #define wxPG_INHERITED_PROPFLAGS (wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR)
394
395 // Combination of flags that can be stored by GetFlagsAsString
396 #define wxPG_STRING_STORED_FLAGS \
397 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
398
399 // -----------------------------------------------------------------------
400
401 #ifndef SWIG
402
403 /**
404 @section propgrid_property_attributes wxPropertyGrid Property Attribute
405 Identifiers.
406
407 wxPGProperty::SetAttribute() and
408 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
409 attribute name argument.
410
411 You can use strings instead of constants. However, some of these
412 constants are redefined to use cached strings which may reduce
413 your binary size by some amount.
414
415 @{
416 */
417
418 /** Set default value for property.
419 */
420 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
421
422 /** Universal, int or double. Minimum value for numeric properties.
423 */
424 #define wxPG_ATTR_MIN wxS("Min")
425
426 /** Universal, int or double. Maximum value for numeric properties.
427 */
428 #define wxPG_ATTR_MAX wxS("Max")
429
430 /** Universal, string. When set, will be shown as text after the displayed
431 text value. Alternatively, if third column is enabled, text will be shown
432 there (for any type of property).
433 */
434 #define wxPG_ATTR_UNITS wxS("Units")
435
436 /** Universal, string. When set, will be shown in property's value cell
437 when displayed value string is empty, or value is unspecified.
438 */
439 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
440
441 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
442 use checkbox instead of choice.
443 */
444 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
445
446 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
447 to cycle on double click (instead of showing the popup listbox).
448 */
449 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
450
451 /**
452 wxFloatProperty (and similar) specific, int, default -1.
453
454 Sets the (max) precision used when floating point value is rendered as
455 text. The default -1 means infinite precision.
456 */
457 #define wxPG_FLOAT_PRECISION wxS("Precision")
458
459 /**
460 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
461 textctrl etc).
462 */
463 #define wxPG_STRING_PASSWORD wxS("Password")
464
465 /** Define base used by a wxUIntProperty. Valid constants are
466 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
467 (lowercase characters).
468 */
469 #define wxPG_UINT_BASE wxS("Base")
470
471 /** Define prefix rendered to wxUIntProperty. Accepted constants
472 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
473 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
474 numbers.
475 */
476 #define wxPG_UINT_PREFIX wxS("Prefix")
477
478 /**
479 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
480 detected/varies.
481 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
482 */
483 #define wxPG_FILE_WILDCARD wxS("Wildcard")
484
485 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
486 When 0, only the file name is shown (i.e. drive and directory are hidden).
487 */
488 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
489
490 /** Specific to wxFileProperty and derived properties, wxString, default empty.
491 If set, then the filename is shown relative to the given path string.
492 */
493 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
494
495 /**
496 Specific to wxFileProperty and derived properties, wxString, default is
497 empty.
498
499 Sets the initial path of where to look for files.
500 */
501 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
502
503 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
504 Sets a specific title for the dir dialog.
505 */
506 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
507
508 /** Specific to wxDirProperty, wxString, default is empty.
509 Sets a specific message for the dir dialog.
510 */
511 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
512
513 /** Sets displayed date format for wxDateProperty.
514 */
515 #define wxPG_DATE_FORMAT wxS("DateFormat")
516
517 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
518 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
519 */
520 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
521
522 /** SpinCtrl editor, int or double. How much number changes when button is
523 pressed (or up/down on keybard).
524 */
525 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
526
527 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
528 */
529 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
530
531 /**
532 wxMultiChoiceProperty, int.
533 If 0, no user strings allowed. If 1, user strings appear before list
534 strings. If 2, user strings appear after list string.
535 */
536 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
537
538 /**
539 wxColourProperty and its kind, int, default 1.
540
541 Setting this attribute to 0 hides custom colour from property's list of
542 choices.
543 */
544 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
545
546 /** @}
547 */
548
549 // Redefine attribute macros to use cached strings
550 #undef wxPG_ATTR_MIN
551 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
552 #undef wxPG_ATTR_MAX
553 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
554 #undef wxPG_ATTR_UNITS
555 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
556 #undef wxPG_ATTR_INLINE_HELP
557 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
558
559 #endif // !SWIG
560
561 // -----------------------------------------------------------------------
562
563 #ifndef SWIG
564
565 /** @class wxPGChoiceEntry
566 Data of a single wxPGChoices choice.
567 */
568 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
569 {
570 public:
571 wxPGChoiceEntry();
572 wxPGChoiceEntry( const wxPGChoiceEntry& entry );
573 wxPGChoiceEntry( const wxString& label,
574 int value = wxPG_INVALID_VALUE )
575 : wxPGCell(), m_value(value)
576 {
577 m_text = label;
578 }
579
580 wxPGChoiceEntry( const wxString& label,
581 int value,
582 const wxBitmap& bitmap,
583 const wxColour& fgCol = wxNullColour,
584 const wxColour& bgCol = wxNullColour )
585 : wxPGCell(label, bitmap, fgCol, bgCol), m_value(value)
586 {
587 }
588
589 virtual ~wxPGChoiceEntry()
590 {
591 }
592
593 void SetValue( int value ) { m_value = value; }
594
595 int GetValue() const { return m_value; }
596
597 bool HasValue() const { return (m_value != wxPG_INVALID_VALUE); }
598
599 protected:
600 int m_value;
601 };
602
603
604 typedef void* wxPGChoicesId;
605
606 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
607 {
608 friend class wxPGChoices;
609 public:
610 // Constructor sets m_refCount to 1.
611 wxPGChoicesData();
612
613 void CopyDataFrom( wxPGChoicesData* data );
614
615 // Takes ownership of 'item'
616 void Insert( int index, wxPGChoiceEntry* item )
617 {
618 wxVector<wxPGChoiceEntry*>::iterator it;
619 if ( index == -1 )
620 {
621 it = m_items.end();
622 index = (int) m_items.size();
623 }
624 else
625 {
626 it = m_items.begin() + index;
627 }
628
629 // Need to fix value?
630 if ( item->GetValue() == wxPG_INVALID_VALUE )
631 item->SetValue(index);
632
633 m_items.insert(it, item);
634 }
635
636 // Delete all entries
637 void Clear();
638
639 unsigned int GetCount() const
640 {
641 return (unsigned int) m_items.size();
642 }
643
644 wxPGChoiceEntry* Item( unsigned int i ) const
645 {
646 wxCHECK_MSG( i < GetCount(), NULL, "invalid index" );
647
648 return m_items[i];
649 }
650
651 void DecRef()
652 {
653 m_refCount--;
654 wxASSERT( m_refCount >= 0 );
655 if ( m_refCount == 0 )
656 delete this;
657 }
658
659 private:
660 wxVector<wxPGChoiceEntry*> m_items;
661
662 // So that multiple properties can use the same set
663 int m_refCount;
664
665 virtual ~wxPGChoicesData();
666 };
667
668 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
669
670 #endif // SWIG
671
672 /** @class wxPGChoices
673
674 Helper class for managing choices of wxPropertyGrid properties.
675 Each entry can have label, value, bitmap, text colour, and background
676 colour.
677
678 @library{wxpropgrid}
679 @category{propgrid}
680 */
681 class WXDLLIMPEXP_PROPGRID wxPGChoices
682 {
683 public:
684 typedef long ValArrItem;
685
686 /** Default constructor. */
687 wxPGChoices()
688 {
689 Init();
690 }
691
692 /** Copy constructor. */
693 wxPGChoices( const wxPGChoices& a )
694 {
695 if ( a.m_data != wxPGChoicesEmptyData )
696 {
697 m_data = a.m_data;
698 m_data->m_refCount++;
699 }
700 }
701
702 /** Constructor. */
703 wxPGChoices( const wxChar** labels, const long* values = NULL )
704 {
705 Init();
706 Set(labels,values);
707 }
708
709 /** Constructor. */
710 wxPGChoices( const wxArrayString& labels,
711 const wxArrayInt& values = wxArrayInt() )
712 {
713 Init();
714 Set(labels,values);
715 }
716
717 /** Simple interface constructor. */
718 wxPGChoices( wxPGChoicesData* data )
719 {
720 wxASSERT(data);
721 m_data = data;
722 data->m_refCount++;
723 }
724
725 /** Destructor. */
726 ~wxPGChoices()
727 {
728 Free();
729 }
730
731 /**
732 Adds to current.
733
734 If did not have own copies, creates them now. If was empty, identical
735 to set except that creates copies.
736 */
737 void Add( const wxChar** labels, const ValArrItem* values = NULL );
738
739 /** Version that works with wxArrayString. */
740 void Add( const wxArrayString& arr, const ValArrItem* values = NULL );
741
742 /** Version that works with wxArrayString and wxArrayInt. */
743 void Add( const wxArrayString& arr, const wxArrayInt& arrint );
744
745 /** Adds single item. */
746 wxPGChoiceEntry& Add( const wxString& label,
747 int value = wxPG_INVALID_VALUE );
748
749 /** Adds a single item, with bitmap. */
750 wxPGChoiceEntry& Add( const wxString& label,
751 const wxBitmap& bitmap,
752 int value = wxPG_INVALID_VALUE );
753
754 /** Adds a single item with full entry information. */
755 wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
756 {
757 return Insert(entry, -1);
758 }
759
760 /** Adds single item. */
761 wxPGChoiceEntry& AddAsSorted( const wxString& label,
762 int value = wxPG_INVALID_VALUE );
763
764 void Assign( const wxPGChoices& a )
765 {
766 AssignData(a.m_data);
767 }
768
769 void AssignData( wxPGChoicesData* data );
770
771 /** Delete all choices. */
772 void Clear()
773 {
774 if ( m_data != wxPGChoicesEmptyData )
775 m_data->Clear();
776 }
777
778 void EnsureData()
779 {
780 if ( m_data == wxPGChoicesEmptyData )
781 m_data = new wxPGChoicesData();
782 }
783
784 /** Gets a unsigned number identifying this list. */
785 wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; };
786
787 const wxString& GetLabel( unsigned int ind ) const
788 {
789 return Item(ind).GetText();
790 }
791
792 unsigned int GetCount () const
793 {
794 if ( !m_data )
795 return 0;
796
797 return m_data->GetCount();
798 }
799
800 int GetValue( unsigned int ind ) const { return Item(ind).GetValue(); }
801
802 /** Returns array of values matching the given strings. Unmatching strings
803 result in wxPG_INVALID_VALUE entry in array.
804 */
805 wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
806
807 /** Returns array of indices matching given strings. Unmatching strings
808 are added to 'unmatched', if not NULL.
809 */
810 wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
811 wxArrayString* unmatched = NULL ) const;
812
813 /** Returns true if choices in general are likely to have values
814 (depens on that all entries have values or none has)
815 */
816 bool HasValues() const;
817
818 bool HasValue( unsigned int i ) const
819 { return (i < m_data->GetCount()) && m_data->Item(i)->HasValue(); }
820
821 int Index( const wxString& str ) const;
822 int Index( int val ) const;
823
824 /** Inserts single item. */
825 wxPGChoiceEntry& Insert( const wxString& label,
826 int index,
827 int value = wxPG_INVALID_VALUE );
828
829 /** Inserts a single item with full entry information. */
830 wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
831
832 /** Returns false if this is a constant empty set of choices,
833 which should not be modified.
834 */
835 bool IsOk() const
836 {
837 return ( m_data != wxPGChoicesEmptyData );
838 }
839
840 const wxPGChoiceEntry& Item( unsigned int i ) const
841 {
842 wxASSERT( IsOk() );
843 return *m_data->Item(i);
844 }
845
846 wxPGChoiceEntry& Item( unsigned int i )
847 {
848 wxASSERT( IsOk() );
849 return *m_data->Item(i);
850 }
851
852 /** Removes count items starting at position nIndex. */
853 void RemoveAt(size_t nIndex, size_t count = 1);
854
855 #ifndef SWIG
856 /** Does not create copies for itself. */
857 void Set( const wxChar** labels, const long* values = NULL )
858 {
859 Free();
860 Add(labels,values);
861 }
862 #endif // SWIG
863
864 /** Version that works with wxArrayString and wxArrayInt. */
865 void Set( const wxArrayString& labels,
866 const wxArrayInt& values = wxArrayInt() )
867 {
868 Free();
869 if ( &values )
870 Add(labels,values);
871 else
872 Add(labels);
873 }
874
875 // Creates exclusive copy of current choices
876 void SetExclusive()
877 {
878 if ( m_data->m_refCount != 1 )
879 {
880 wxPGChoicesData* data = new wxPGChoicesData();
881 data->CopyDataFrom(m_data);
882 Free();
883 m_data = data;
884 }
885 }
886
887 // Returns data, increases refcount.
888 wxPGChoicesData* GetData()
889 {
890 wxASSERT( m_data->m_refCount != 0xFFFFFFF );
891 m_data->m_refCount++;
892 return m_data;
893 }
894
895 // Returns plain data ptr - no refcounting stuff is done.
896 wxPGChoicesData* GetDataPtr() const { return m_data; }
897
898 // Changes ownership of data to you.
899 wxPGChoicesData* ExtractData()
900 {
901 wxPGChoicesData* data = m_data;
902 m_data = wxPGChoicesEmptyData;
903 return data;
904 }
905
906 wxArrayString GetLabels() const;
907
908 #ifndef SWIG
909 void operator= (const wxPGChoices& a)
910 {
911 AssignData(a.m_data);
912 }
913
914 wxPGChoiceEntry& operator[](unsigned int i)
915 {
916 return Item(i);
917 }
918
919 const wxPGChoiceEntry& operator[](unsigned int i) const
920 {
921 return Item(i);
922 }
923
924 protected:
925 wxPGChoicesData* m_data;
926
927 void Init();
928 void Free();
929 #endif // !SWIG
930 };
931
932 // -----------------------------------------------------------------------
933
934 /** @class wxPGProperty
935
936 wxPGProperty is base class for all wxPropertyGrid properties.
937
938 NB: Full class overview is now only present in
939 interface/wx/propgrid/property.h.
940
941 @library{wxpropgrid}
942 @category{propgrid}
943 */
944 class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
945 {
946 friend class wxPropertyGrid;
947 friend class wxPropertyGridInterface;
948 friend class wxPropertyGridPageState;
949 friend class wxPropertyGridPopulator;
950 friend class wxStringProperty; // Proper "<composed>" support requires this
951 #ifndef SWIG
952 DECLARE_ABSTRACT_CLASS(wxPGProperty)
953 #endif
954 public:
955 typedef wxUint32 FlagType;
956
957 /** Basic constructor.
958 */
959 wxPGProperty();
960
961 /** Constructor.
962 Non-abstract property classes should have constructor of this style:
963
964 @code
965
966 // If T is a class, then it should be a constant reference
967 // (e.g. const T& ) instead.
968 MyProperty( const wxString& label, const wxString& name, T value )
969 : wxPGProperty()
970 {
971 // Generally recommended way to set the initial value
972 // (as it should work in pretty much 100% of cases).
973 wxVariant variant;
974 variant << value;
975 SetValue(variant);
976
977 // If has private child properties then create them here, e.g.:
978 // AddChild( new wxStringProperty( "Subprop 1",
979 // wxPG_LABEL,
980 // value.GetSubProp1() ) );
981 }
982
983 @endcode
984 */
985 wxPGProperty( const wxString& label, const wxString& name );
986
987 /**
988 Virtual destructor.
989 It is customary for derived properties to implement this.
990 */
991 virtual ~wxPGProperty();
992
993 /** This virtual function is called after m_value has been set.
994
995 @remarks
996 - If m_value was set to Null variant (ie. unspecified value),
997 OnSetValue() will not be called.
998 - m_value may be of any variant type. Typically properties internally
999 support only one variant type, and as such OnSetValue() provides a
1000 good opportunity to convert
1001 supported values into internal type.
1002 - Default implementation does nothing.
1003 */
1004 virtual void OnSetValue();
1005
1006 /** Override this to return something else than m_value as the value.
1007 */
1008 virtual wxVariant DoGetValue() const { return m_value; }
1009
1010 #if !defined(SWIG) || defined(CREATE_VCW)
1011 /** Implement this function in derived class to check the value.
1012 Return true if it is ok. Returning false prevents property change events
1013 from occurring.
1014
1015 @remarks
1016 - Default implementation always returns true.
1017 */
1018 virtual bool ValidateValue( wxVariant& value,
1019 wxPGValidationInfo& validationInfo ) const;
1020
1021 /**
1022 Converts text into wxVariant value appropriate for this property.
1023
1024 @param variant
1025 On function entry this is the old value (should not be wxNullVariant
1026 in normal cases). Translated value must be assigned back to it.
1027
1028 @param text
1029 Text to be translated into variant.
1030
1031 @param argFlags
1032 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1033 of displayable one (they may be different).
1034 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1035 composite property string value (as generated by GetValueAsString()
1036 called with this same flag).
1037
1038 @return Returns @true if resulting wxVariant value was different.
1039
1040 @remarks Default implementation converts semicolon delimited tokens into
1041 child values. Only works for properties with children.
1042
1043 You might want to take into account that m_value is Null variant
1044 if property value is unspecified (which is usually only case if
1045 you explicitly enabled that sort behavior).
1046 */
1047 virtual bool StringToValue( wxVariant& variant,
1048 const wxString& text,
1049 int argFlags = 0 ) const;
1050
1051 /**
1052 Converts integer (possibly a choice selection) into wxVariant value
1053 appropriate for this property.
1054
1055 @param variant
1056 On function entry this is the old value (should not be wxNullVariant
1057 in normal cases). Translated value must be assigned back to it.
1058
1059 @param number
1060 Integer to be translated into variant.
1061
1062 @param argFlags
1063 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1064 of displayable one.
1065
1066 @return Returns @true if resulting wxVariant value was different.
1067
1068 @remarks
1069 - If property is not supposed to use choice or spinctrl or other editor
1070 with int-based value, it is not necessary to implement this method.
1071 - Default implementation simply assign given int to m_value.
1072 - If property uses choice control, and displays a dialog on some choice
1073 items, then it is preferred to display that dialog in IntToValue
1074 instead of OnEvent.
1075 - You might want to take into account that m_value is Null variant if
1076 property value is unspecified (which is usually only case if you
1077 explicitly enabled that sort behavior).
1078 */
1079 virtual bool IntToValue( wxVariant& value,
1080 int number,
1081 int argFlags = 0 ) const;
1082 #endif // !defined(SWIG) || defined(CREATE_VCW)
1083
1084 public:
1085 /** Returns text representation of property's value.
1086
1087 @param argFlags
1088 If wxPG_FULL_VALUE is set, returns complete, storable string value
1089 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1090 string value that must be editable in textctrl. If
1091 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1092 display as a part of composite property string value.
1093
1094 @remarks
1095 Default implementation returns string composed from text
1096 representations of child properties.
1097 */
1098 virtual wxString GetValueAsString( int argFlags = 0 ) const;
1099
1100 /** Converts string to a value, and if successful, calls SetValue() on it.
1101 Default behavior is to do nothing.
1102 @param text
1103 String to get the value from.
1104 @return
1105 true if value was changed.
1106 */
1107 bool SetValueFromString( const wxString& text, int flags = 0 );
1108
1109 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1110 Default behavior is to do nothing.
1111 @param value
1112 Int to get the value from.
1113 @param flags
1114 If has wxPG_FULL_VALUE, then the value given is a actual value and
1115 not an index.
1116 @return
1117 True if value was changed.
1118 */
1119 bool SetValueFromInt( long value, int flags = 0 );
1120
1121 /**
1122 Returns size of the custom painted image in front of property.
1123
1124 This method must be overridden to return non-default value if
1125 OnCustomPaint is to be called.
1126 @param item
1127 Normally -1, but can be an index to the property's list of items.
1128 @remarks
1129 - Default behavior is to return wxSize(0,0), which means no image.
1130 - Default image width or height is indicated with dimension -1.
1131 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1132 */
1133 virtual wxSize OnMeasureImage( int item = -1 ) const;
1134
1135 /**
1136 Events received by editor widgets are processed here.
1137
1138 Note that editor class usually processes most events. Some, such as
1139 button press events of TextCtrlAndButton class, can be handled here.
1140 Also, if custom handling for regular events is desired, then that can
1141 also be done (for example, wxSystemColourProperty custom handles
1142 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1143 'custom' selection is made).
1144
1145 If the event causes value to be changed, SetValueInEvent()
1146 should be called to set the new value.
1147
1148 @param event
1149 Associated wxEvent.
1150 @return
1151 Should return true if any changes in value should be reported.
1152 @remarks
1153 If property uses choice control, and displays a dialog on some choice
1154 items, then it is preferred to display that dialog in IntToValue
1155 instead of OnEvent.
1156 */
1157 virtual bool OnEvent( wxPropertyGrid* propgrid,
1158 wxWindow* wnd_primary,
1159 wxEvent& event );
1160
1161 /**
1162 Called after value of a child property has been altered.
1163
1164 Note that this function is usually called at the time that value of
1165 this property, or given child property, is still pending for change.
1166
1167 Sample pseudo-code implementation:
1168
1169 @code
1170 void MyProperty::ChildChanged( wxVariant& thisValue,
1171 int childIndex,
1172 wxVariant& childValue ) const
1173 {
1174 // Acquire reference to actual type of data stored in variant
1175 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1176 // were used to create the variant class).
1177 T& data = TFromVariant(thisValue);
1178
1179 // Copy childValue into data.
1180 switch ( childIndex )
1181 {
1182 case 0:
1183 data.SetSubProp1( childvalue.GetLong() );
1184 break;
1185 case 1:
1186 data.SetSubProp2( childvalue.GetString() );
1187 break;
1188 ...
1189 }
1190 }
1191 @endcode
1192
1193 @param thisValue
1194 Value of this property, that should be altered.
1195 @param childIndex
1196 Index of child changed (you can use Item(childIndex) to get).
1197 @param childValue
1198 Value of the child property.
1199 */
1200 virtual void ChildChanged( wxVariant& thisValue,
1201 int childIndex,
1202 wxVariant& childValue ) const;
1203
1204 /** Returns pointer to an instance of used editor.
1205 */
1206 virtual const wxPGEditor* DoGetEditorClass() const;
1207
1208 /** Returns pointer to the wxValidator that should be used
1209 with the editor of this property (NULL for no validator).
1210 Setting validator explicitly via SetPropertyValidator
1211 will override this.
1212
1213 In most situations, code like this should work well
1214 (macros are used to maintain one actual validator instance,
1215 so on the second call the function exits within the first
1216 macro):
1217
1218 @code
1219
1220 wxValidator* wxMyPropertyClass::DoGetValidator () const
1221 {
1222 WX_PG_DOGETVALIDATOR_ENTRY()
1223
1224 wxMyValidator* validator = new wxMyValidator(...);
1225
1226 ... prepare validator...
1227
1228 WX_PG_DOGETVALIDATOR_EXIT(validator)
1229 }
1230
1231 @endcode
1232
1233 @remarks
1234 You can get common filename validator by returning
1235 wxFileProperty::GetClassValidator(). wxDirProperty,
1236 for example, uses it.
1237 */
1238 virtual wxValidator* DoGetValidator () const;
1239
1240 /**
1241 Override to paint an image in front of the property value text or
1242 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1243 overridden as well).
1244
1245 If property's OnMeasureImage() returns size that has height != 0 but
1246 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1247 this method to draw a custom image in a limited area in front of the
1248 editor control or value text/graphics, and if control has drop-down
1249 list, then the image is drawn there as well (even in the case
1250 OnMeasureImage() returned higher height than row height).
1251
1252 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1253 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1254 height items: If rect.x is < 0, then this is a measure item call, which
1255 means that dc is invalid and only thing that should be done is to set
1256 paintdata.m_drawnHeight to the height of the image of item at index
1257 paintdata.m_choiceItem. This call may be done even as often as once
1258 every drop-down popup show.
1259
1260 @param dc
1261 wxDC to paint on.
1262 @param rect
1263 Box reserved for custom graphics. Includes surrounding rectangle,
1264 if any. If x is < 0, then this is a measure item call (see above).
1265 @param paintdata
1266 wxPGPaintData structure with much useful data.
1267
1268 @remarks
1269 - You can actually exceed rect width, but if you do so then
1270 paintdata.m_drawnWidth must be set to the full width drawn in
1271 pixels.
1272 - Due to technical reasons, rect's height will be default even if
1273 custom height was reported during measure call.
1274 - Brush is guaranteed to be default background colour. It has been
1275 already used to clear the background of area being painted. It
1276 can be modified.
1277 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1278 colour) pen for drawing framing rectangle. It can be changed as
1279 well.
1280
1281 @see GetValueAsString()
1282 */
1283 virtual void OnCustomPaint( wxDC& dc,
1284 const wxRect& rect,
1285 wxPGPaintData& paintdata );
1286
1287 /**
1288 Returns used wxPGCellRenderer instance for given property column
1289 (label=0, value=1).
1290
1291 Default implementation returns editor's renderer for all columns.
1292 */
1293 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
1294
1295 /** Returns which choice is currently selected. Only applies to properties
1296 which have choices.
1297
1298 Needs to reimplemented in derived class if property value does not
1299 map directly to a choice. Integer as index, bool, and string usually do.
1300 */
1301 virtual int GetChoiceSelection() const;
1302
1303 /**
1304 Refresh values of child properties.
1305
1306 Automatically called after value is set.
1307 */
1308 virtual void RefreshChildren();
1309
1310 /** Special handling for attributes of this property.
1311
1312 If returns false, then the attribute will be automatically stored in
1313 m_attributes.
1314
1315 Default implementation simply returns false.
1316 */
1317 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
1318
1319 /** Returns value of an attribute.
1320
1321 Override if custom handling of attributes is needed.
1322
1323 Default implementation simply return NULL variant.
1324 */
1325 virtual wxVariant DoGetAttribute( const wxString& name ) const;
1326
1327 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1328 used when user presses the (optional) button next to the editor control;
1329
1330 Default implementation returns NULL (ie. no action is generated when
1331 button is pressed).
1332 */
1333 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
1334
1335 /** Returns wxPGCell of given column, NULL if none. If valid
1336 object is returned, caller will gain its ownership.
1337 */
1338 wxPGCell* AcquireCell( unsigned int column )
1339 {
1340 if ( column >= m_cells.size() )
1341 return NULL;
1342
1343 wxPGCell* cell = (wxPGCell*) m_cells[column];
1344 m_cells[column] = NULL;
1345 return cell;
1346 }
1347
1348 /** Append a new choice to property's list of choices.
1349 */
1350 int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
1351 {
1352 return InsertChoice(label, wxNOT_FOUND, value);
1353 }
1354
1355 /**
1356 Returns true if children of this property are component values (for
1357 instance, points size, face name, and is_underlined are component
1358 values of a font).
1359 */
1360 bool AreChildrenComponents() const
1361 {
1362 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
1363 return true;
1364
1365 return false;
1366 }
1367
1368 /**
1369 Removes entry from property's wxPGChoices and editor control (if it is
1370 active).
1371
1372 If selected item is deleted, then the value is set to unspecified.
1373 */
1374 void DeleteChoice( int index );
1375
1376 /**
1377 Call to enable or disable usage of common value (integer value that can
1378 be selected for properties instead of their normal values) for this
1379 property.
1380
1381 Common values are disabled by the default for all properties.
1382 */
1383 void EnableCommonValue( bool enable = true )
1384 {
1385 if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
1386 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
1387 }
1388
1389 /** Composes text from values of child properties. */
1390 void GenerateComposedValue( wxString& text, int argFlags = 0 ) const;
1391
1392 /** Returns property's label. */
1393 const wxString& GetLabel() const { return m_label; }
1394
1395 /** Returns property's name with all (non-category, non-root) parents. */
1396 wxString GetName() const;
1397
1398 /**
1399 Returns property's base name (ie parent's name is not added in any
1400 case)
1401 */
1402 const wxString& GetBaseName() const { return m_name; }
1403
1404 /** Returns read-only reference to property's list of choices.
1405 */
1406 const wxPGChoices& GetChoices() const
1407 {
1408 return m_choices;
1409 }
1410
1411 /** Returns coordinate to the top y of the property. Note that the
1412 position of scrollbars is not taken into account.
1413 */
1414 int GetY() const;
1415
1416 wxVariant GetValue() const
1417 {
1418 return DoGetValue();
1419 }
1420
1421 #ifndef SWIG
1422 /** Returns reference to the internal stored value. GetValue is preferred
1423 way to get the actual value, since GetValueRef ignores DoGetValue,
1424 which may override stored value.
1425 */
1426 wxVariant& GetValueRef()
1427 {
1428 return m_value;
1429 }
1430
1431 const wxVariant& GetValueRef() const
1432 {
1433 return m_value;
1434 }
1435 #endif
1436
1437 /** To acquire property's value as string, you should use this
1438 function (instead of GetValueAsString()), as it may produce
1439 more accurate value in future versions.
1440 */
1441 wxString GetValueString( int argFlags = 0 ) const;
1442
1443 void UpdateControl( wxWindow* primary );
1444
1445 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
1446 will retain ownership of the cell object.
1447 */
1448 wxPGCell* GetCell( unsigned int column ) const
1449 {
1450 if ( column >= m_cells.size() )
1451 return NULL;
1452
1453 return (wxPGCell*) m_cells[column];
1454 }
1455
1456 /** Return number of displayed common values for this property.
1457 */
1458 int GetDisplayedCommonValueCount() const;
1459
1460 wxString GetDisplayedString() const
1461 {
1462 return GetValueString(0);
1463 }
1464
1465 /** Returns property grid where property lies. */
1466 wxPropertyGrid* GetGrid() const;
1467
1468 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1469 displaying this property. */
1470 wxPropertyGrid* GetGridIfDisplayed() const;
1471
1472 /** Returns highest level non-category, non-root parent. Useful when you
1473 have nested wxCustomProperties/wxParentProperties.
1474 @remarks
1475 Thus, if immediate parent is root or category, this will return the
1476 property itself.
1477 */
1478 wxPGProperty* GetMainParent() const;
1479
1480 /** Return parent of property */
1481 wxPGProperty* GetParent() const { return m_parent; }
1482
1483 /** Returns true if property has editable wxTextCtrl when selected.
1484
1485 @remarks
1486 Altough disabled properties do not displayed editor, they still
1487 return True here as being disabled is considered a temporary
1488 condition (unlike being read-only or having limited editing enabled).
1489 */
1490 bool IsTextEditable() const;
1491
1492 bool IsValueUnspecified() const
1493 {
1494 return m_value.IsNull();
1495 }
1496
1497 FlagType HasFlag( FlagType flag ) const
1498 {
1499 return ( m_flags & flag );
1500 }
1501
1502 /** Returns comma-delimited string of property attributes.
1503 */
1504 const wxPGAttributeStorage& GetAttributes() const
1505 {
1506 return m_attributes;
1507 }
1508
1509 /** Returns m_attributes as list wxVariant.
1510 */
1511 wxVariant GetAttributesAsList() const;
1512
1513 FlagType GetFlags() const
1514 {
1515 return m_flags;
1516 }
1517
1518 const wxPGEditor* GetEditorClass() const;
1519
1520 wxString GetValueType() const
1521 {
1522 return m_value.GetType();
1523 }
1524
1525 /** Returns editor used for given column. NULL for no editor.
1526 */
1527 const wxPGEditor* GetColumnEditor( int column ) const
1528 {
1529 if ( column == 1 )
1530 return GetEditorClass();
1531
1532 return NULL;
1533 }
1534
1535 /** Returns common value selected for this property. -1 for none.
1536 */
1537 int GetCommonValue() const
1538 {
1539 return m_commonValue;
1540 }
1541
1542 /** Returns true if property has even one visible child.
1543 */
1544 bool HasVisibleChildren() const;
1545
1546 /** Inserts a new choice to property's list of choices.
1547 */
1548 int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1549
1550 /**
1551 Returns true if this property is actually a wxPropertyCategory.
1552 */
1553 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
1554
1555 /** Returns true if this property is actually a wxRootProperty.
1556 */
1557 bool IsRoot() const { return (m_parent == NULL); }
1558
1559 /** Returns true if this is a sub-property. */
1560 bool IsSubProperty() const
1561 {
1562 wxPGProperty* parent = (wxPGProperty*)m_parent;
1563 if ( parent && !parent->IsCategory() )
1564 return true;
1565 return false;
1566 }
1567
1568 /** Returns last visible sub-property, recursively.
1569 */
1570 const wxPGProperty* GetLastVisibleSubItem() const;
1571
1572 wxVariant GetDefaultValue() const;
1573
1574 int GetMaxLength() const
1575 {
1576 return (int) m_maxLen;
1577 }
1578
1579 /**
1580 Determines, recursively, if all children are not unspecified.
1581
1582 @param pendingList
1583 Assumes members in this wxVariant list as pending
1584 replacement values.
1585 */
1586 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
1587
1588 /** Updates composed values of parent non-category properties, recursively.
1589 Returns topmost property updated.
1590
1591 @remarks
1592 - Must not call SetValue() (as can be called in it).
1593 */
1594 wxPGProperty* UpdateParentValues();
1595
1596 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1597 */
1598 bool UsesAutoUnspecified() const
1599 {
1600 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false;
1601 }
1602
1603 wxBitmap* GetValueImage() const
1604 {
1605 return m_valueBitmap;
1606 }
1607
1608 wxVariant GetAttribute( const wxString& name ) const;
1609
1610 /**
1611 Returns named attribute, as string, if found.
1612
1613 Otherwise defVal is returned.
1614 */
1615 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
1616
1617 /**
1618 Returns named attribute, as long, if found.
1619
1620 Otherwise defVal is returned.
1621 */
1622 long GetAttributeAsLong( const wxString& name, long defVal ) const;
1623
1624 /**
1625 Returns named attribute, as double, if found.
1626
1627 Otherwise defVal is returned.
1628 */
1629 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
1630
1631 unsigned int GetDepth() const { return (unsigned int)m_depth; }
1632
1633 /** Gets flags as a'|' delimited string. Note that flag names are not
1634 prepended with 'wxPG_PROP_'.
1635 @param flagsMask
1636 String will only be made to include flags combined by this parameter.
1637 */
1638 wxString GetFlagsAsString( FlagType flagsMask ) const;
1639
1640 /** Returns position in parent's array. */
1641 unsigned int GetIndexInParent() const
1642 {
1643 return (unsigned int)m_arrIndex;
1644 }
1645
1646 /** Hides or reveals the property.
1647 @param hide
1648 true for hide, false for reveal.
1649 @param flags
1650 By default changes are applied recursively. Set this paramter
1651 wxPG_DONT_RECURSE to prevent this.
1652 */
1653 inline bool Hide( bool hide, int flags = wxPG_RECURSE );
1654
1655 bool IsExpanded() const
1656 { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
1657
1658 /** Returns true if all parents expanded.
1659 */
1660 bool IsVisible() const;
1661
1662 bool IsEnabled() const { return !(m_flags & wxPG_PROP_DISABLED); }
1663
1664 /** If property's editor is created this forces its recreation.
1665 Useful in SetAttribute etc. Returns true if actually did anything.
1666 */
1667 bool RecreateEditor();
1668
1669 /** If property's editor is active, then update it's value.
1670 */
1671 void RefreshEditor();
1672
1673 /** Sets an attribute for this property.
1674 @param name
1675 Text identifier of attribute. See @ref propgrid_property_attributes.
1676 @param value
1677 Value of attribute.
1678 */
1679 void SetAttribute( const wxString& name, wxVariant value );
1680
1681 void SetAttributes( const wxPGAttributeStorage& attributes );
1682
1683 #ifndef SWIG
1684 /** Sets editor for a property.
1685
1686 @param editor
1687 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1688 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1689 list).
1690
1691 For custom editors, use pointer you received from
1692 wxPropertyGrid::RegisterEditorClass().
1693 */
1694 void SetEditor( const wxPGEditor* editor )
1695 {
1696 m_customEditor = editor;
1697 }
1698 #endif
1699
1700 /** Sets editor for a property.
1701 */
1702 inline void SetEditor( const wxString& editorName );
1703
1704 /** Sets cell information for given column.
1705
1706 Note that the property takes ownership of given wxPGCell instance.
1707 */
1708 void SetCell( int column, wxPGCell* cellObj );
1709
1710 /** Sets common value selected for this property. -1 for none.
1711 */
1712 void SetCommonValue( int commonValue )
1713 {
1714 m_commonValue = commonValue;
1715 }
1716
1717 /** Sets flags from a '|' delimited string. Note that flag names are not
1718 prepended with 'wxPG_PROP_'.
1719 */
1720 void SetFlagsFromString( const wxString& str );
1721
1722 /** Sets property's "is it modified?" flag. Affects children recursively.
1723 */
1724 void SetModifiedStatus( bool modified )
1725 {
1726 SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
1727 }
1728
1729 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1730 based on user input.
1731
1732 @remarks
1733 This method is const since it doesn't actually modify value, but posts
1734 given variant as pending value, stored in wxPropertyGrid.
1735 */
1736 void SetValueInEvent( wxVariant value ) const;
1737
1738 /**
1739 Call this to set value of the property.
1740
1741 Unlike methods in wxPropertyGrid, this does not automatically update
1742 the display.
1743
1744 @remarks
1745 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1746 through validation process and send property change event.
1747
1748 If you need to change property value in event, based on user input, use
1749 SetValueInEvent() instead.
1750
1751 @param pList
1752 Pointer to list variant that contains child values. Used to indicate
1753 which children should be marked as modified.
1754 @param flags
1755 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1756 */
1757 void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
1758
1759 /** Set wxBitmap in front of the value. This bitmap may be ignored
1760 by custom cell renderers.
1761 */
1762 void SetValueImage( wxBitmap& bmp );
1763
1764 /** If property has choices and they are not yet exclusive, new such copy
1765 of them will be created.
1766 */
1767 void SetChoicesExclusive()
1768 {
1769 m_choices.SetExclusive();
1770 }
1771
1772 /** Sets selected choice and changes property value.
1773
1774 Tries to retain value type, although currently if it is not string,
1775 then it is forced to integer.
1776 */
1777 void SetChoiceSelection( int newValue );
1778
1779 void SetExpanded( bool expanded )
1780 {
1781 if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
1782 else m_flags &= ~wxPG_PROP_COLLAPSED;
1783 }
1784
1785 void SetFlag( FlagType flag ) { m_flags |= flag; }
1786
1787 void SetFlagRecursively( FlagType flag, bool set );
1788
1789 void SetHelpString( const wxString& helpString )
1790 {
1791 m_helpString = helpString;
1792 }
1793
1794 void SetLabel( const wxString& label ) { m_label = label; }
1795
1796 inline void SetName( const wxString& newName );
1797
1798 void SetValueToUnspecified()
1799 {
1800 wxVariant val; // Create NULL variant
1801 SetValue(val);
1802 }
1803
1804 #if wxUSE_VALIDATORS
1805 /** Sets wxValidator for a property*/
1806 void SetValidator( const wxValidator& validator )
1807 {
1808 m_validator = wxDynamicCast(validator.Clone(),wxValidator);
1809 }
1810
1811 /** Gets assignable version of property's validator. */
1812 wxValidator* GetValidator() const
1813 {
1814 if ( m_validator )
1815 return m_validator;
1816 return DoGetValidator();
1817 }
1818 #endif // #if wxUSE_VALIDATORS
1819
1820 #ifndef SWIG
1821 /** Returns client data (void*) of a property.
1822 */
1823 void* GetClientData() const
1824 {
1825 return m_clientData;
1826 }
1827
1828 /** Sets client data (void*) of a property.
1829 @remarks
1830 This untyped client data has to be deleted manually.
1831 */
1832 void SetClientData( void* clientData )
1833 {
1834 m_clientData = clientData;
1835 }
1836
1837 /** Returns client object of a property.
1838 */
1839 void SetClientObject(wxClientData* clientObject)
1840 {
1841 delete m_clientObject;
1842 m_clientObject = clientObject;
1843 }
1844
1845 /** Sets managed client object of a property.
1846 */
1847 wxClientData *GetClientObject() const { return m_clientObject; }
1848 #endif
1849
1850 /** Sets new set of choices for property.
1851
1852 @remarks
1853 This operation clears the property value.
1854 */
1855 bool SetChoices( wxPGChoices& choices );
1856
1857 /** Set max length of text in text editor.
1858 */
1859 inline bool SetMaxLength( int maxLen );
1860
1861 /** Call with 'false' in OnSetValue to cancel value changes after all
1862 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1863 */
1864 void SetWasModified( bool set = true )
1865 {
1866 if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
1867 else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
1868 }
1869
1870 const wxString& GetHelpString() const
1871 {
1872 return m_helpString;
1873 }
1874
1875 void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
1876
1877 // Use, for example, to detect if item is inside collapsed section.
1878 bool IsSomeParent( wxPGProperty* candidate_parent ) const;
1879
1880 /**
1881 Adapts list variant into proper value using consecutive
1882 ChildChanged-calls.
1883 */
1884 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
1885
1886 /** This is used by properties that have fixed sub-properties. */
1887 void AddChild( wxPGProperty* prop );
1888
1889 /** Returns height of children, recursively, and
1890 by taking expanded/collapsed status into account.
1891
1892 iMax is used when finding property y-positions.
1893 */
1894 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1895
1896 /** Returns number of child properties */
1897 unsigned int GetChildCount() const
1898 {
1899 return (unsigned int) m_children.size();
1900 }
1901
1902 /** Returns sub-property at index i. */
1903 wxPGProperty* Item( unsigned int i ) const
1904 { return m_children[i]; }
1905
1906 /** Returns last sub-property.
1907 */
1908 wxPGProperty* Last() const { return m_children.back(); }
1909
1910 /** Returns index of given child property. */
1911 int Index( const wxPGProperty* p ) const;
1912
1913 /** Deletes all sub-properties. */
1914 void Empty();
1915
1916 // Puts correct indexes to children
1917 void FixIndexesOfChildren( unsigned int starthere = 0 );
1918
1919 #ifndef SWIG
1920 // Returns wxPropertyGridPageState in which this property resides.
1921 wxPropertyGridPageState* GetParentState() const { return m_parentState; }
1922 #endif
1923
1924 wxPGProperty* GetItemAtY( unsigned int y,
1925 unsigned int lh,
1926 unsigned int* nextItemY ) const;
1927
1928 /** Returns (direct) child property with given name (or NULL if not found).
1929 */
1930 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1931
1932 #ifdef SWIG
1933 %extend {
1934 DocStr(GetClientData,
1935 "Returns the client data object for a property", "");
1936 PyObject* GetClientData() {
1937 wxPyClientData* data = (wxPyClientData*)self->GetClientObject();
1938 if (data) {
1939 Py_INCREF(data->m_obj);
1940 return data->m_obj;
1941 } else {
1942 Py_INCREF(Py_None);
1943 return Py_None;
1944 }
1945 }
1946
1947 DocStr(SetClientData,
1948 "Associate the given client data.", "");
1949 void SetClientData(PyObject* clientData) {
1950 wxPyClientData* data = new wxPyClientData(clientData);
1951 self->SetClientObject(data);
1952 }
1953 }
1954 %pythoncode {
1955 GetClientObject = GetClientData
1956 SetClientObject = SetClientData
1957 }
1958 #endif
1959
1960 #ifndef SWIG
1961
1962 static wxString* sm_wxPG_LABEL;
1963
1964 /** This member is public so scripting language bindings
1965 wrapper code can access it freely.
1966 */
1967 void* m_clientData;
1968
1969 protected:
1970 /** Returns text for given column.
1971 */
1972 wxString GetColumnText( unsigned int col ) const;
1973
1974 /** Returns (direct) child property with given name (or NULL if not found),
1975 with hint index.
1976
1977 @param hintIndex
1978 Start looking for the child at this index.
1979
1980 @remarks
1981 Does not support scope (ie. Parent.Child notation).
1982 */
1983 wxPGProperty* GetPropertyByNameWH( const wxString& name,
1984 unsigned int hintIndex ) const;
1985
1986 /** This is used by Insert etc. */
1987 void AddChild2( wxPGProperty* prop,
1988 int index = -1,
1989 bool correct_mode = true );
1990
1991 void DoSetName(const wxString& str) { m_name = str; }
1992
1993 // Call for after sub-properties added with AddChild
1994 void PrepareSubProperties();
1995
1996 // Removes child property with given pointer. Does not delete it.
1997 void RemoveChild( wxPGProperty* p );
1998
1999 void SetParentalType( int flag )
2000 {
2001 m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
2002 m_flags |= flag;
2003 }
2004
2005 void SetParentState( wxPropertyGridPageState* pstate )
2006 { m_parentState = pstate; }
2007
2008 // Call after fixed sub-properties added/removed after creation.
2009 // if oldSelInd >= 0 and < new max items, then selection is
2010 // moved to it.
2011 void SubPropsChanged( int oldSelInd = -1 );
2012
2013 int GetY2( int lh ) const;
2014
2015 wxString m_label;
2016 wxString m_name;
2017 wxPGProperty* m_parent;
2018 wxPropertyGridPageState* m_parentState;
2019
2020 wxClientData* m_clientObject;
2021
2022 // Overrides editor returned by property class
2023 const wxPGEditor* m_customEditor;
2024 #if wxUSE_VALIDATORS
2025 // Editor is going to get this validator
2026 wxValidator* m_validator;
2027 #endif
2028 // Show this in front of the value
2029 //
2030 // TODO: Can bitmap be implemented with wxPGCell?
2031 wxBitmap* m_valueBitmap;
2032
2033 wxVariant m_value;
2034 wxPGAttributeStorage m_attributes;
2035 wxArrayPGProperty m_children;
2036
2037 // Extended cell information
2038 wxArrayPtrVoid m_cells;
2039
2040 // Choices shown in drop-down list of editor control.
2041 wxPGChoices m_choices;
2042
2043 // Help shown in statusbar or help box.
2044 wxString m_helpString;
2045
2046 // Index in parent's property array.
2047 unsigned int m_arrIndex;
2048
2049 // If not -1, then overrides m_value
2050 int m_commonValue;
2051
2052 FlagType m_flags;
2053
2054 // Maximum length (mainly for string properties). Could be in some sort of
2055 // wxBaseStringProperty, but currently, for maximum flexibility and
2056 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2057 // so short int will fit in just fine.
2058 short m_maxLen;
2059
2060 // Root has 0, categories etc. at that level 1, etc.
2061 unsigned char m_depth;
2062
2063 // m_depthBgCol indicates width of background colour between margin and item
2064 // (essentially this is category's depth, if none then equals m_depth).
2065 unsigned char m_depthBgCol;
2066
2067 unsigned char m_bgColIndex; // Background brush index.
2068 unsigned char m_fgColIndex; // Foreground colour index.
2069
2070 private:
2071 // Called in constructors.
2072 void Init();
2073 void Init( const wxString& label, const wxString& name );
2074 #endif // #ifndef SWIG
2075 };
2076
2077 // -----------------------------------------------------------------------
2078
2079 //
2080 // Property class declaration helper macros
2081 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2082 //
2083
2084 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2085 virtual const wxPGEditor* DoGetEditorClass() const;
2086
2087 #ifndef SWIG
2088 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2089 public: \
2090 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2091 WX_PG_DECLARE_DOGETEDITORCLASS \
2092 private:
2093 #else
2094 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2095 #endif
2096
2097 // Implements sans constructor function. Also, first arg is class name, not
2098 // property name.
2099 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2100 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2101 { \
2102 return wxPGEditor_##EDITOR; \
2103 }
2104
2105 // -----------------------------------------------------------------------
2106
2107 #ifndef SWIG
2108
2109 /** @class wxPGRootProperty
2110 @ingroup classes
2111 Root parent property.
2112 */
2113 class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
2114 {
2115 public:
2116 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
2117 public:
2118
2119 /** Constructor. */
2120 wxPGRootProperty();
2121 virtual ~wxPGRootProperty();
2122
2123 virtual bool StringToValue( wxVariant&, const wxString&, int ) const
2124 {
2125 return false;
2126 }
2127
2128 protected:
2129 };
2130
2131 // -----------------------------------------------------------------------
2132
2133 /** @class wxPropertyCategory
2134 @ingroup classes
2135 Category (caption) property.
2136 */
2137 class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
2138 {
2139 friend class wxPropertyGrid;
2140 friend class wxPropertyGridPageState;
2141 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
2142 public:
2143
2144 /** Default constructor is only used in special cases. */
2145 wxPropertyCategory();
2146
2147 wxPropertyCategory( const wxString& label,
2148 const wxString& name = wxPG_LABEL );
2149 ~wxPropertyCategory();
2150
2151 int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
2152
2153 protected:
2154 virtual wxString GetValueAsString( int argFlags ) const;
2155
2156 void SetTextColIndex( unsigned int colInd )
2157 { m_capFgColIndex = (wxByte) colInd; }
2158 unsigned int GetTextColIndex() const
2159 { return (unsigned int) m_capFgColIndex; }
2160
2161 void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
2162
2163 int m_textExtent; // pre-calculated length of text
2164 wxByte m_capFgColIndex; // caption text colour index
2165
2166 private:
2167 void Init();
2168 };
2169
2170 #endif // !SWIG
2171
2172 // -----------------------------------------------------------------------
2173
2174 #endif // wxUSE_PROPGRID
2175
2176 #endif // _WX_PROPGRID_PROPERTY_H_