]> git.saurik.com Git - wxWidgets.git/blob - include/wx/propgrid/propgridiface.h
Make it easier to define custom wxSizerXmlHandler subclasses.
[wxWidgets.git] / include / wx / propgrid / propgridiface.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgeid/propgridiface.h
3 // Purpose: wxPropertyGridInterface class
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2008-08-24
7 // RCS-ID: $Id$
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WX_PROPGRID_PROPGRIDIFACE_H__
13 #define __WX_PROPGRID_PROPGRIDIFACE_H__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_PROPGRID
18
19 #include "wx/propgrid/property.h"
20 #include "wx/propgrid/propgridpagestate.h"
21
22 // -----------------------------------------------------------------------
23
24 /** @section wxPGPropArgCls
25
26 Most property grid functions have this type as their argument, as it can
27 convey a property by either a pointer or name.
28 */
29 class WXDLLIMPEXP_PROPGRID wxPGPropArgCls
30 {
31 public:
32 wxPGPropArgCls() { }
33 wxPGPropArgCls( const wxPGProperty* property )
34 {
35 m_ptr.property = (wxPGProperty*) property;
36 m_flags = IsProperty;
37 }
38 wxPGPropArgCls( const wxString& str )
39 {
40 m_ptr.stringName = &str;
41 m_flags = IsWxString;
42 }
43 wxPGPropArgCls( const wxPGPropArgCls& id )
44 {
45 m_ptr = id.m_ptr;
46 m_flags = id.m_flags;
47 }
48 // This is only needed for wxPython bindings
49 wxPGPropArgCls( wxString* str, bool WXUNUSED(deallocPtr) )
50 {
51 m_ptr.stringName = str;
52 m_flags = IsWxString | OwnsWxString;
53 }
54 ~wxPGPropArgCls()
55 {
56 if ( m_flags & OwnsWxString )
57 delete m_ptr.stringName;
58 }
59 wxPGProperty* GetPtr() const
60 {
61 wxCHECK( m_flags == IsProperty, NULL );
62 return m_ptr.property;
63 }
64 wxPGPropArgCls( const char* str )
65 {
66 m_ptr.charName = str;
67 m_flags = IsCharPtr;
68 }
69 wxPGPropArgCls( const wchar_t* str )
70 {
71 m_ptr.wcharName = str;
72 m_flags = IsWCharPtr;
73 }
74 /** This constructor is required for NULL. */
75 wxPGPropArgCls( int )
76 {
77 m_ptr.property = NULL;
78 m_flags = IsProperty;
79 }
80 wxPGProperty* GetPtr( wxPropertyGridInterface* iface ) const;
81 wxPGProperty* GetPtr( const wxPropertyGridInterface* iface ) const
82 {
83 return GetPtr((wxPropertyGridInterface*)iface);
84 }
85 wxPGProperty* GetPtr0() const { return m_ptr.property; }
86 bool HasName() const { return (m_flags != IsProperty); }
87 const wxString& GetName() const { return *m_ptr.stringName; }
88 private:
89
90 enum
91 {
92 IsProperty = 0x00,
93 IsWxString = 0x01,
94 IsCharPtr = 0x02,
95 IsWCharPtr = 0x04,
96 OwnsWxString = 0x10
97 };
98
99 union
100 {
101 wxPGProperty* property;
102 const char* charName;
103 const wchar_t* wcharName;
104 const wxString* stringName;
105 } m_ptr;
106 unsigned char m_flags;
107 };
108
109 typedef const wxPGPropArgCls& wxPGPropArg;
110
111 // -----------------------------------------------------------------------
112
113 WXDLLIMPEXP_PROPGRID
114 void wxPGTypeOperationFailed( const wxPGProperty* p,
115 const wxString& typestr,
116 const wxString& op );
117 WXDLLIMPEXP_PROPGRID
118 void wxPGGetFailed( const wxPGProperty* p, const wxString& typestr );
119
120 // -----------------------------------------------------------------------
121
122 // Helper macro that does necessary preparations when calling
123 // some wxPGProperty's member function.
124 #define wxPG_PROP_ARG_CALL_PROLOG_0(PROPERTY) \
125 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
126 if ( !p ) return;
127
128 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(PROPERTY, RETVAL) \
129 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
130 if ( !p ) return RETVAL;
131
132 #define wxPG_PROP_ARG_CALL_PROLOG() \
133 wxPG_PROP_ARG_CALL_PROLOG_0(wxPGProperty)
134
135 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL(RVAL) \
136 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(wxPGProperty, RVAL)
137
138 #define wxPG_PROP_ID_CONST_CALL_PROLOG() \
139 wxPG_PROP_ARG_CALL_PROLOG_0(const wxPGProperty)
140
141 #define wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(RVAL) \
142 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(const wxPGProperty, RVAL)
143
144 // -----------------------------------------------------------------------
145
146
147 /** @class wxPropertyGridInterface
148
149 Most of the shared property manipulation interface shared by wxPropertyGrid,
150 wxPropertyGridPage, and wxPropertyGridManager is defined in this class.
151
152 @remarks
153 - In separate wxPropertyGrid component this class was known as
154 wxPropertyContainerMethods.
155
156 @library{wxpropgrid}
157 @category{propgrid}
158 */
159 class WXDLLIMPEXP_PROPGRID wxPropertyGridInterface
160 {
161 public:
162
163 /** Destructor */
164 virtual ~wxPropertyGridInterface() { }
165
166 /**
167 Appends property to the list.
168
169 wxPropertyGrid assumes ownership of the object.
170 Becomes child of most recently added category.
171 @remarks
172 - wxPropertyGrid takes the ownership of the property pointer.
173 - If appending a category with name identical to a category already in
174 the wxPropertyGrid, then newly created category is deleted, and most
175 recently added category (under which properties are appended) is set
176 to the one with same name. This allows easier adding of items to same
177 categories in multiple passes.
178 - Does not automatically redraw the control, so you may need to call
179 Refresh when calling this function after control has been shown for
180 the first time.
181 */
182 wxPGProperty* Append( wxPGProperty* property );
183
184 wxPGProperty* AppendIn( wxPGPropArg id, wxPGProperty* newproperty );
185
186 /**
187 In order to add new items into a property with fixed children (for
188 instance, wxFlagsProperty), you need to call this method. After
189 populating has been finished, you need to call EndAddChildren.
190 */
191 void BeginAddChildren( wxPGPropArg id );
192
193 /** Deletes all properties.
194 */
195 virtual void Clear() = 0;
196
197 /**
198 Clears current selection, if any.
199
200 @param validation
201 If set to @false, deselecting the property will always work,
202 even if its editor had invalid value in it.
203
204 @return Returns @true if successful or if there was no selection. May
205 fail if validation was enabled and active editor had invalid
206 value.
207
208 @remarks In wxPropertyGrid 1.4, this member function used to send
209 wxPG_EVT_SELECTED. In wxWidgets 2.9 and later, it no longer
210 does that.
211 */
212 bool ClearSelection( bool validation = false );
213
214 /** Resets modified status of all properties.
215 */
216 void ClearModifiedStatus();
217
218 /** Collapses given category or property with children.
219 Returns true if actually collapses.
220 */
221 bool Collapse( wxPGPropArg id );
222
223 /** Collapses all items that can be collapsed.
224
225 @return
226 Return false if failed (may fail if editor value cannot be validated).
227 */
228 bool CollapseAll() { return ExpandAll(false); }
229
230 /**
231 Changes value of a property, as if from an editor.
232 Use this instead of SetPropertyValue() if you need the value to run
233 through validation process, and also send the property change event.
234
235 @return
236 Returns true if value was successfully changed.
237 */
238 bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
239
240 /**
241 Removes and deletes a property and any children.
242
243 @param id
244 Pointer or name of a property.
245
246 @remarks If you delete a property in a wxPropertyGrid event
247 handler, the actual deletion is postponed until the next
248 idle event.
249
250 This functions deselects selected property, if any.
251 Validation failure option wxPG_VFB_STAY_IN_PROPERTY is not
252 respected, ie. selection is cleared even if editor had
253 invalid value.
254 */
255 void DeleteProperty( wxPGPropArg id );
256
257 /**
258 Removes a property. Does not delete the property object, but
259 instead returns it.
260
261 @param id
262 Pointer or name of a property.
263
264 @remarks Removed property cannot have any children.
265
266 Also, if you remove property in a wxPropertyGrid event
267 handler, the actual removal is postponed until the next
268 idle event.
269 */
270 wxPGProperty* RemoveProperty( wxPGPropArg id );
271
272 /**
273 Disables a property.
274
275 @see EnableProperty(), wxPGProperty::Enable()
276 */
277 bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); }
278
279 /**
280 Returns true if all property grid data changes have been committed.
281
282 Usually only returns false if value in active editor has been
283 invalidated by a wxValidator.
284 */
285 bool EditorValidate();
286
287 /**
288 Enables or disables property, depending on whether enable is true or
289 false. Disabled property usually appears as having grey text.
290
291 @param id
292 Name or pointer to a property.
293 @param enable
294 If @false, property is disabled instead.
295
296 @see wxPGProperty::Enable()
297 */
298 bool EnableProperty( wxPGPropArg id, bool enable = true );
299
300 /** Called after population of property with fixed children has finished.
301 */
302 void EndAddChildren( wxPGPropArg id );
303
304 /** Expands given category or property with children.
305 Returns true if actually expands.
306 */
307 bool Expand( wxPGPropArg id );
308
309 /** Expands all items that can be expanded.
310 */
311 bool ExpandAll( bool expand = true );
312
313 /** Returns id of first child of given property.
314 @remarks
315 Does not return sub-properties!
316 */
317 wxPGProperty* GetFirstChild( wxPGPropArg id )
318 {
319 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
320
321 if ( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE) )
322 return wxNullProperty;
323
324 return p->Item(0);
325 }
326
327 //@{
328 /** Returns iterator class instance.
329 @param flags
330 See @ref propgrid_iterator_flags. Value wxPG_ITERATE_DEFAULT causes
331 iteration over everything except private child properties.
332 @param firstProp
333 Property to start iteration from. If NULL, then first child of root
334 is used.
335 @param startPos
336 Either wxTOP or wxBOTTOM. wxTOP will indicate that iterations start
337 from the first property from the top, and wxBOTTOM means that the
338 iteration will instead begin from bottommost valid item.
339 */
340 wxPropertyGridIterator GetIterator( int flags = wxPG_ITERATE_DEFAULT,
341 wxPGProperty* firstProp = NULL )
342 {
343 return wxPropertyGridIterator( m_pState, flags, firstProp );
344 }
345
346 wxPropertyGridConstIterator
347 GetIterator( int flags = wxPG_ITERATE_DEFAULT,
348 wxPGProperty* firstProp = NULL ) const
349 {
350 return wxPropertyGridConstIterator( m_pState, flags, firstProp );
351 }
352
353 wxPropertyGridIterator GetIterator( int flags, int startPos )
354 {
355 return wxPropertyGridIterator( m_pState, flags, startPos );
356 }
357
358 wxPropertyGridConstIterator GetIterator( int flags, int startPos ) const
359 {
360 return wxPropertyGridConstIterator( m_pState, flags, startPos );
361 }
362 //@}
363
364 /** Returns id of first item, whether it is a category or property.
365 @param flags
366 @link iteratorflags List of iterator flags@endlink
367 */
368 wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL )
369 {
370 wxPropertyGridIterator it( m_pState, flags, wxNullProperty, 1 );
371 return *it;
372 }
373
374 const wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL ) const
375 {
376 return ((wxPropertyGridInterface*)this)->GetFirst(flags);
377 }
378
379 /**
380 Returns pointer to a property with given name (case-sensitive).
381 If there is no property with such name, @NULL pointer is returned.
382
383 @remarks Properties which have non-category, non-root parent
384 can not be accessed globally by their name. Instead, use
385 "<property>.<subproperty>" instead of "<subproperty>".
386 */
387 wxPGProperty* GetProperty( const wxString& name ) const
388 {
389 return GetPropertyByName(name);
390 }
391
392 /** Returns map-like storage of property's attributes.
393 @remarks
394 Note that if extra style wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES is set,
395 then builtin-attributes are not included in the storage.
396 */
397 const wxPGAttributeStorage& GetPropertyAttributes( wxPGPropArg id ) const
398 {
399 // If 'id' refers to invalid property, then we will return dummy
400 // attributes (ie. root property's attributes, which contents should
401 // should always be empty and of no consequence).
402 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_pState->DoGetRoot()->GetAttributes());
403 return p->GetAttributes();
404 }
405
406 /** Adds to 'targetArr' pointers to properties that have given
407 flags 'flags' set. However, if 'inverse' is set to true, then
408 only properties without given flags are stored.
409 @param flags
410 Property flags to use.
411 @param iterFlags
412 Iterator flags to use. Default is everything expect private children.
413 */
414 void GetPropertiesWithFlag( wxArrayPGProperty* targetArr,
415 wxPGProperty::FlagType flags,
416 bool inverse = false,
417 int iterFlags = wxPG_ITERATE_PROPERTIES |
418 wxPG_ITERATE_HIDDEN |
419 wxPG_ITERATE_CATEGORIES) const;
420
421 /** Returns value of given attribute. If none found, returns NULL-variant.
422 */
423 wxVariant GetPropertyAttribute( wxPGPropArg id,
424 const wxString& attrName ) const
425 {
426 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullVariant)
427 return p->GetAttribute(attrName);
428 }
429
430 /** Returns pointer of property's nearest parent category. If no category
431 found, returns NULL.
432 */
433 wxPropertyCategory* GetPropertyCategory( wxPGPropArg id ) const
434 {
435 wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(NULL)
436 return m_pState->GetPropertyCategory(p);
437 }
438
439 /** Returns client data (void*) of a property. */
440 void* GetPropertyClientData( wxPGPropArg id ) const
441 {
442 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
443 return p->GetClientData();
444 }
445
446 /**
447 Returns first property which label matches given string.
448
449 NULL if none found. Note that this operation is extremely slow when
450 compared to GetPropertyByName().
451 */
452 wxPGProperty* GetPropertyByLabel( const wxString& label ) const;
453
454 /** Returns property with given name. NULL if none found.
455 */
456 wxPGProperty* GetPropertyByName( const wxString& name ) const;
457
458 /** Returns child property 'subname' of property 'name'. Same as
459 calling GetPropertyByName("name.subname"), albeit slightly faster.
460 */
461 wxPGProperty* GetPropertyByName( const wxString& name,
462 const wxString& subname ) const;
463
464 /** Returns property's editor. */
465 const wxPGEditor* GetPropertyEditor( wxPGPropArg id ) const
466 {
467 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
468 return p->GetEditorClass();
469 }
470
471 /** Returns help string associated with a property. */
472 wxString GetPropertyHelpString( wxPGPropArg id ) const
473 {
474 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
475 return p->GetHelpString();
476 }
477
478 /** Returns property's custom value image (NULL of none). */
479 wxBitmap* GetPropertyImage( wxPGPropArg id ) const
480 {
481 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
482 return p->GetValueImage();
483 }
484
485 /** Returns label of a property. */
486 const wxString& GetPropertyLabel( wxPGPropArg id )
487 {
488 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
489 return p->GetLabel();
490 }
491
492 /** Returns name of a property, by which it is globally accessible. */
493 wxString GetPropertyName( wxPGProperty* property )
494 {
495 return property->GetName();
496 }
497
498 /** Returns parent item of a property. */
499 wxPGProperty* GetPropertyParent( wxPGPropArg id )
500 {
501 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
502 return p->GetParent();
503 }
504
505 #if wxUSE_VALIDATORS
506 /** Returns validator of a property as a reference, which you
507 can pass to any number of SetPropertyValidator.
508 */
509 wxValidator* GetPropertyValidator( wxPGPropArg id )
510 {
511 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
512 return p->GetValidator();
513 }
514 #endif
515
516 /** Returns value as wxVariant. To get wxObject pointer from it,
517 you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro.
518
519 If property value is unspecified, Null variant is returned.
520 */
521 wxVariant GetPropertyValue( wxPGPropArg id )
522 {
523 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant())
524 return p->GetValue();
525 }
526
527 wxString GetPropertyValueAsString( wxPGPropArg id ) const;
528 long GetPropertyValueAsLong( wxPGPropArg id ) const;
529 unsigned long GetPropertyValueAsULong( wxPGPropArg id ) const
530 {
531 return (unsigned long) GetPropertyValueAsLong(id);
532 }
533 int GetPropertyValueAsInt( wxPGPropArg id ) const
534 { return (int)GetPropertyValueAsLong(id); }
535 bool GetPropertyValueAsBool( wxPGPropArg id ) const;
536 double GetPropertyValueAsDouble( wxPGPropArg id ) const;
537
538 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
539 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
540 wxString typeName(wxS(TYPENAME)); \
541 wxVariant value = p->GetValue(); \
542 if ( value.GetType() != typeName ) \
543 { \
544 wxPGGetFailed(p, typeName); \
545 return DEFVAL; \
546 }
547
548 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
549 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
550 wxVariant value = p->GetValue(); \
551 if ( value.GetType() != wxS(TYPENAME) ) \
552 return DEFVAL; \
553
554 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
555 {
556 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("arrstring",
557 wxArrayString())
558 return value.GetArrayString();
559 }
560
561 #ifdef wxLongLong_t
562 wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const
563 {
564 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
565 return p->GetValue().GetLongLong().GetValue();
566 }
567
568 wxULongLong_t GetPropertyValueAsULongLong( wxPGPropArg id ) const
569 {
570 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
571 return p->GetValue().GetULongLong().GetValue();
572 }
573 #endif
574
575 wxArrayInt GetPropertyValueAsArrayInt( wxPGPropArg id ) const
576 {
577 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxArrayInt",
578 wxArrayInt())
579 wxArrayInt arr;
580 arr << value;
581 return arr;
582 }
583
584 #if wxUSE_DATETIME
585 wxDateTime GetPropertyValueAsDateTime( wxPGPropArg id ) const
586 {
587 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("datetime",
588 wxDateTime())
589 return value.GetDateTime();
590 }
591 #endif
592
593 /** Returns a wxVariant list containing wxVariant versions of all
594 property values. Order is not guaranteed.
595 @param flags
596 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
597 category will be its own wxVariantList of wxVariant.
598 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
599 Each attribute will be stored as list variant named
600 "@@<propname>@@attr."
601 @remarks
602 */
603 wxVariant GetPropertyValues( const wxString& listname = wxEmptyString,
604 wxPGProperty* baseparent = NULL, long flags = 0 ) const
605 {
606 return m_pState->DoGetPropertyValues(listname, baseparent, flags);
607 }
608
609 /**
610 Returns currently selected property. NULL if none.
611
612 @remarks When wxPG_EX_MULTIPLE_SELECTION extra style is used, this
613 member function returns the focused property, that is the
614 one which can have active editor.
615 */
616 wxPGProperty* GetSelection() const;
617
618 /**
619 Returns list of currently selected properties.
620
621 @remarks wxArrayPGProperty should be compatible with std::vector API.
622 */
623 const wxArrayPGProperty& GetSelectedProperties() const
624 {
625 return m_pState->m_selection;
626 }
627
628 wxPropertyGridPageState* GetState() const { return m_pState; }
629
630 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
631 which can be useful for forward-iterating through arbitrary property
632 containers.
633
634 @param flags
635 See @ref propgrid_iterator_flags.
636 */
637 virtual wxPGVIterator GetVIterator( int flags ) const;
638
639 /** Hides or reveals a property.
640 @param hide
641 If true, hides property, otherwise reveals it.
642 @param flags
643 By default changes are applied recursively. Set this paramter
644 wxPG_DONT_RECURSE to prevent this.
645 */
646 bool HideProperty( wxPGPropArg id,
647 bool hide = true,
648 int flags = wxPG_RECURSE );
649
650 #if wxPG_INCLUDE_ADVPROPS
651 /** Initializes *all* property types. Causes references to most object
652 files in the library, so calling this may cause significant increase
653 in executable size when linking with static library.
654 */
655 static void InitAllTypeHandlers();
656 #else
657 static void InitAllTypeHandlers() { }
658 #endif
659
660 //@{
661 /** Inserts property to the property container.
662
663 @param priorThis
664 New property is inserted just prior to this. Available only
665 in the first variant. There are two versions of this function
666 to allow this parameter to be either an id or name to
667 a property.
668
669 @param newproperty
670 Pointer to the inserted property. wxPropertyGrid will take
671 ownership of this object.
672
673 @param parent
674 New property is inserted under this category. Available only
675 in the second variant. There are two versions of this function
676 to allow this parameter to be either an id or name to
677 a property.
678
679 @param index
680 Index under category. Available only in the second variant.
681 If index is < 0, property is appended in category.
682
683 @return
684 Returns id for the property,
685
686 @remarks
687
688 - wxPropertyGrid takes the ownership of the property pointer.
689
690 - While Append may be faster way to add items, make note that when
691 both types of data storage (categoric and
692 non-categoric) are active, Insert becomes even more slow. This is
693 especially true if current mode is non-categoric.
694
695 Example of use:
696
697 @code
698
699 // append category
700 wxPGProperty* my_cat_id = propertygrid->Append(
701 new wxPropertyCategory("My Category") );
702
703 ...
704
705 // insert into category - using second variant
706 wxPGProperty* my_item_id_1 = propertygrid->Insert(
707 my_cat_id, 0, new wxStringProperty("My String 1") );
708
709 // insert before to first item - using first variant
710 wxPGProperty* my_item_id_2 = propertygrid->Insert(
711 my_item_id, new wxStringProperty("My String 2") );
712
713 @endcode
714
715 */
716 wxPGProperty* Insert( wxPGPropArg priorThis, wxPGProperty* newproperty );
717 wxPGProperty* Insert( wxPGPropArg parent,
718 int index,
719 wxPGProperty* newproperty );
720 //@}
721
722 /** Returns true if property is a category. */
723 bool IsPropertyCategory( wxPGPropArg id ) const
724 {
725 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
726 return p->IsCategory();
727 }
728
729 /** Returns true if property is enabled. */
730 bool IsPropertyEnabled( wxPGPropArg id ) const
731 {
732 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
733 return (!(p->GetFlags() & wxPG_PROP_DISABLED))?true:false;
734 }
735
736 /**
737 Returns true if given property is expanded.
738
739 Naturally, always returns false for properties that cannot be expanded.
740 */
741 bool IsPropertyExpanded( wxPGPropArg id ) const;
742
743 /**
744 Returns true if property has been modified after value set or modify
745 flag clear by software.
746 */
747 bool IsPropertyModified( wxPGPropArg id ) const
748 {
749 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
750 return ( (p->GetFlags() & wxPG_PROP_MODIFIED) ? true : false );
751 }
752
753 /**
754 Returns true if property is selected.
755 */
756 bool IsPropertySelected( wxPGPropArg id ) const
757 {
758 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
759 return m_pState->DoIsPropertySelected(p);
760 }
761
762 /**
763 Returns true if property is shown (ie hideproperty with true not
764 called for it).
765 */
766 bool IsPropertyShown( wxPGPropArg id ) const
767 {
768 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
769 return (!(p->GetFlags() & wxPG_PROP_HIDDEN))?true:false;
770 }
771
772 /** Returns true if property value is set to unspecified.
773 */
774 bool IsPropertyValueUnspecified( wxPGPropArg id ) const
775 {
776 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
777 return p->IsValueUnspecified();
778 }
779
780 /**
781 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
782 a property, if it is not the sole mean to edit the value.
783 */
784 void LimitPropertyEditing( wxPGPropArg id, bool limit = true );
785
786 /** If state is shown in it's grid, refresh it now.
787 */
788 virtual void RefreshGrid( wxPropertyGridPageState* state = NULL );
789
790 #if wxPG_INCLUDE_ADVPROPS
791 /**
792 Initializes additional property editors (SpinCtrl etc.). Causes
793 references to most object files in the library, so calling this may
794 cause significant increase in executable size when linking with static
795 library.
796 */
797 static void RegisterAdditionalEditors();
798 #else
799 static void RegisterAdditionalEditors() { }
800 #endif
801
802 /** Replaces property with id with newly created property. For example,
803 this code replaces existing property named "Flags" with one that
804 will have different set of items:
805 @code
806 pg->ReplaceProperty("Flags",
807 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
808 @endcode
809 For more info, see wxPropertyGrid::Insert.
810 */
811 wxPGProperty* ReplaceProperty( wxPGPropArg id, wxPGProperty* property );
812
813 /** @anchor propgridinterface_editablestate_flags
814
815 Flags for wxPropertyGridInterface::SaveEditableState() and
816 wxPropertyGridInterface::RestoreEditableState().
817 */
818 enum EditableStateFlags
819 {
820 /** Include selected property. */
821 SelectionState = 0x01,
822 /** Include expanded/collapsed property information. */
823 ExpandedState = 0x02,
824 /** Include scrolled position. */
825 ScrollPosState = 0x04,
826 /** Include selected page information.
827 Only applies to wxPropertyGridManager. */
828 PageState = 0x08,
829 /** Include splitter position. Stored for each page. */
830 SplitterPosState = 0x10,
831 /** Include description box size.
832 Only applies to wxPropertyGridManager. */
833 DescBoxState = 0x20,
834
835 /**
836 Include all supported user editable state information.
837 This is usually the default value. */
838 AllStates = SelectionState |
839 ExpandedState |
840 ScrollPosState |
841 PageState |
842 SplitterPosState |
843 DescBoxState
844 };
845
846 /**
847 Restores user-editable state.
848
849 See also wxPropertyGridInterface::SaveEditableState().
850
851 @param src
852 String generated by SaveEditableState.
853
854 @param restoreStates
855 Which parts to restore from source string. See @ref
856 propgridinterface_editablestate_flags "list of editable state
857 flags".
858
859 @return
860 False if there was problem reading the string.
861
862 @remarks
863 If some parts of state (such as scrolled or splitter position) fail to
864 restore correctly, please make sure that you call this function after
865 wxPropertyGrid size has been set (this may sometimes be tricky when
866 sizers are used).
867 */
868 bool RestoreEditableState( const wxString& src,
869 int restoreStates = AllStates );
870
871 /**
872 Used to acquire user-editable state (selected property, expanded
873 properties, scrolled position, splitter positions).
874
875 @param includedStates
876 Which parts of state to include. See @ref
877 propgridinterface_editablestate_flags "list of editable state flags".
878 */
879 wxString SaveEditableState( int includedStates = AllStates ) const;
880
881 /**
882 Lets user to set the strings listed in the choice dropdown of a
883 wxBoolProperty. Defaults are "True" and "False", so changing them to,
884 say, "Yes" and "No" may be useful in some less technical applications.
885 */
886 static void SetBoolChoices( const wxString& trueChoice,
887 const wxString& falseChoice );
888
889 /**
890 Set proportion of a auto-stretchable column. wxPG_SPLITTER_AUTO_CENTER
891 window style needs to be used to indicate that columns are auto-
892 resizeable.
893
894 @returns Returns @false on failure.
895
896 @remarks You should call this for individual pages of
897 wxPropertyGridManager (if used).
898
899 @see GetColumnProportion()
900 */
901 bool SetColumnProportion( unsigned int column, int proportion );
902
903 /**
904 Returns auto-resize proportion of the given column.
905
906 @see SetColumnProportion()
907 */
908 int GetColumnProportion( unsigned int column ) const
909 {
910 return m_pState->DoGetColumnProportion(column);
911 }
912
913 /** Sets an attribute for this property.
914 @param name
915 Text identifier of attribute. See @ref propgrid_property_attributes.
916 @param value
917 Value of attribute.
918 @param argFlags
919 Optional. Use wxPG_RECURSE to set the attribute to child properties
920 recursively.
921 */
922 void SetPropertyAttribute( wxPGPropArg id,
923 const wxString& attrName,
924 wxVariant value,
925 long argFlags = 0 )
926 {
927 DoSetPropertyAttribute(id,attrName,value,argFlags);
928 }
929
930 /** Sets property attribute for all applicapple properties.
931 Be sure to use this method only after all properties have been
932 added to the grid.
933 */
934 void SetPropertyAttributeAll( const wxString& attrName, wxVariant value );
935
936 /**
937 Sets background colour of a property.
938
939 @param id
940 Property name or pointer.
941
942 @param colour
943 New background colour.
944
945 @param flags
946 Default is wxPG_RECURSE which causes colour to be set recursively.
947 Omit this flag to only set colour for the property in question
948 and not any of its children.
949 */
950 void SetPropertyBackgroundColour( wxPGPropArg id,
951 const wxColour& colour,
952 int flags = wxPG_RECURSE );
953
954 /** Resets text and background colours of given property.
955 */
956 void SetPropertyColoursToDefault( wxPGPropArg id );
957
958 /**
959 Sets text colour of a property.
960
961 @param id
962 Property name or pointer.
963
964 @param colour
965 New background colour.
966
967 @param flags
968 Default is wxPG_RECURSE which causes colour to be set recursively.
969 Omit this flag to only set colour for the property in question
970 and not any of its children.
971 */
972 void SetPropertyTextColour( wxPGPropArg id,
973 const wxColour& col,
974 int flags = wxPG_RECURSE );
975
976 /**
977 Returns background colour of first cell of a property.
978 */
979 wxColour GetPropertyBackgroundColour( wxPGPropArg id ) const
980 {
981 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
982 return p->GetCell(0).GetBgCol();
983 }
984
985 /**
986 Returns text colour of first cell of a property.
987 */
988 wxColour GetPropertyTextColour( wxPGPropArg id ) const
989 {
990 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
991 return p->GetCell(0).GetFgCol();
992 }
993
994 /** Sets text, bitmap, and colours for given column's cell.
995
996 @remarks
997 - You can set label cell by setting column to 0.
998 - You can use wxPG_LABEL as text to use default text for column.
999 */
1000 void SetPropertyCell( wxPGPropArg id,
1001 int column,
1002 const wxString& text = wxEmptyString,
1003 const wxBitmap& bitmap = wxNullBitmap,
1004 const wxColour& fgCol = wxNullColour,
1005 const wxColour& bgCol = wxNullColour );
1006
1007 /** Sets client data (void*) of a property.
1008 @remarks
1009 This untyped client data has to be deleted manually.
1010 */
1011 void SetPropertyClientData( wxPGPropArg id, void* clientData )
1012 {
1013 wxPG_PROP_ARG_CALL_PROLOG()
1014 p->SetClientData(clientData);
1015 }
1016
1017 /** Sets editor for a property.
1018
1019 @param editor
1020 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1021 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1022 list).
1023
1024 For custom editors, use pointer you received from
1025 wxPropertyGrid::RegisterEditorClass().
1026 */
1027 void SetPropertyEditor( wxPGPropArg id, const wxPGEditor* editor )
1028 {
1029 wxPG_PROP_ARG_CALL_PROLOG()
1030 wxCHECK_RET( editor, wxT("unknown/NULL editor") );
1031 p->SetEditor(editor);
1032 RefreshProperty(p);
1033 }
1034
1035 /** Sets editor control of a property. As editor argument, use
1036 editor name string, such as "TextCtrl" or "Choice".
1037 */
1038 void SetPropertyEditor( wxPGPropArg id, const wxString& editorName )
1039 {
1040 SetPropertyEditor(id,GetEditorByName(editorName));
1041 }
1042
1043 /** Sets label of a property.
1044 */
1045 void SetPropertyLabel( wxPGPropArg id, const wxString& newproplabel );
1046
1047 /**
1048 Sets name of a property.
1049
1050 @param id
1051 Name or pointer of property which name to change.
1052
1053 @param newName
1054 New name for property.
1055 */
1056 void SetPropertyName( wxPGPropArg id, const wxString& newName )
1057 {
1058 wxPG_PROP_ARG_CALL_PROLOG()
1059 m_pState->DoSetPropertyName( p, newName );
1060 }
1061
1062 /**
1063 Sets property (and, recursively, its children) to have read-only value.
1064 In other words, user cannot change the value in the editor, but they
1065 can still copy it.
1066 @remarks
1067 This is mainly for use with textctrl editor. Not all other editors fully
1068 support it.
1069 @param flags
1070 By default changes are applied recursively. Set this paramter
1071 wxPG_DONT_RECURSE to prevent this.
1072 */
1073 void SetPropertyReadOnly( wxPGPropArg id,
1074 bool set = true,
1075 int flags = wxPG_RECURSE )
1076 {
1077 wxPG_PROP_ARG_CALL_PROLOG()
1078 if ( flags & wxPG_RECURSE )
1079 p->SetFlagRecursively(wxPG_PROP_READONLY, set);
1080 else
1081 p->ChangeFlag(wxPG_PROP_READONLY, set);
1082 }
1083
1084 /** Sets property's value to unspecified.
1085 If it has children (it may be category), then the same thing is done to
1086 them.
1087 */
1088 void SetPropertyValueUnspecified( wxPGPropArg id )
1089 {
1090 wxPG_PROP_ARG_CALL_PROLOG()
1091 p->SetValueToUnspecified();
1092 }
1093
1094 /**
1095 Sets property values from a list of wxVariants.
1096 */
1097 void SetPropertyValues( const wxVariantList& list,
1098 wxPGPropArg defaultCategory = wxNullProperty )
1099 {
1100 wxPGProperty *p;
1101 if ( defaultCategory.HasName() ) p = defaultCategory.GetPtr(this);
1102 else p = defaultCategory.GetPtr0();
1103 m_pState->DoSetPropertyValues(list, p);
1104 }
1105
1106 /**
1107 Sets property values from a list of wxVariants.
1108 */
1109 void SetPropertyValues( const wxVariant& list,
1110 wxPGPropArg defaultCategory = wxNullProperty )
1111 {
1112 SetPropertyValues(list.GetList(),defaultCategory);
1113 }
1114
1115 /** Associates the help string with property.
1116 @remarks
1117 By default, text is shown either in the manager's "description"
1118 text box or in the status bar. If extra window style
1119 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1120 tooltip.
1121 */
1122 void SetPropertyHelpString( wxPGPropArg id, const wxString& helpString )
1123 {
1124 wxPG_PROP_ARG_CALL_PROLOG()
1125 p->SetHelpString(helpString);
1126 }
1127
1128 /** Set wxBitmap in front of the value.
1129 @remarks
1130 - Bitmap will be scaled to a size returned by
1131 wxPropertyGrid::GetImageSize();
1132 */
1133 void SetPropertyImage( wxPGPropArg id, wxBitmap& bmp )
1134 {
1135 wxPG_PROP_ARG_CALL_PROLOG()
1136 p->SetValueImage(bmp);
1137 RefreshProperty(p);
1138 }
1139
1140 /** Sets max length of property's text.
1141 */
1142 bool SetPropertyMaxLength( wxPGPropArg id, int maxLen );
1143
1144 #if wxUSE_VALIDATORS
1145 /** Sets validator of a property.
1146 */
1147 void SetPropertyValidator( wxPGPropArg id, const wxValidator& validator )
1148 {
1149 wxPG_PROP_ARG_CALL_PROLOG()
1150 p->SetValidator(validator);
1151 }
1152 #endif
1153
1154 /** Sets value (long integer) of a property.
1155 */
1156 void SetPropertyValue( wxPGPropArg id, long value )
1157 {
1158 wxVariant v(value);
1159 SetPropVal( id, v );
1160 }
1161
1162 /** Sets value (integer) of a property.
1163 */
1164 void SetPropertyValue( wxPGPropArg id, int value )
1165 {
1166 wxVariant v((long)value);
1167 SetPropVal( id, v );
1168 }
1169 /** Sets value (floating point) of a property.
1170 */
1171 void SetPropertyValue( wxPGPropArg id, double value )
1172 {
1173 wxVariant v(value);
1174 SetPropVal( id, v );
1175 }
1176 /** Sets value (bool) of a property.
1177 */
1178 void SetPropertyValue( wxPGPropArg id, bool value )
1179 {
1180 wxVariant v(value);
1181 SetPropVal( id, v );
1182 }
1183 void SetPropertyValue( wxPGPropArg id, const wchar_t* value )
1184 {
1185 SetPropertyValueString( id, wxString(value) );
1186 }
1187 void SetPropertyValue( wxPGPropArg id, const char* value )
1188 {
1189 SetPropertyValueString( id, wxString(value) );
1190 }
1191 void SetPropertyValue( wxPGPropArg id, const wxString& value )
1192 {
1193 SetPropertyValueString( id, value );
1194 }
1195
1196 /** Sets value (wxArrayString) of a property.
1197 */
1198 void SetPropertyValue( wxPGPropArg id, const wxArrayString& value )
1199 {
1200 wxVariant v(value);
1201 SetPropVal( id, v );
1202 }
1203
1204 #if wxUSE_DATETIME
1205 void SetPropertyValue( wxPGPropArg id, const wxDateTime& value )
1206 {
1207 wxVariant v(value);
1208 SetPropVal( id, v );
1209 }
1210 #endif
1211
1212 /** Sets value (wxObject*) of a property.
1213 */
1214 void SetPropertyValue( wxPGPropArg id, wxObject* value )
1215 {
1216 wxVariant v(value);
1217 SetPropVal( id, v );
1218 }
1219
1220 void SetPropertyValue( wxPGPropArg id, wxObject& value )
1221 {
1222 wxVariant v(&value);
1223 SetPropVal( id, v );
1224 }
1225
1226 #ifdef wxLongLong_t
1227 /** Sets value (wxLongLong&) of a property.
1228 */
1229 void SetPropertyValue( wxPGPropArg id, wxLongLong_t value )
1230 {
1231 wxVariant v = WXVARIANT(wxLongLong(value));
1232 SetPropVal( id, v );
1233 }
1234 /** Sets value (wxULongLong&) of a property.
1235 */
1236 void SetPropertyValue( wxPGPropArg id, wxULongLong_t value )
1237 {
1238 wxVariant v = WXVARIANT(wxULongLong(value));
1239 SetPropVal( id, v );
1240 }
1241 #endif
1242
1243 /** Sets value (wxArrayInt&) of a property.
1244 */
1245 void SetPropertyValue( wxPGPropArg id, const wxArrayInt& value )
1246 {
1247 wxVariant v = WXVARIANT(value);
1248 SetPropVal( id, v );
1249 }
1250
1251 /** Sets value (wxString) of a property.
1252
1253 @remarks
1254 This method uses wxPGProperty::SetValueFromString, which all properties
1255 should implement. This means that there should not be a type error,
1256 and instead the string is converted to property's actual value type.
1257 */
1258 void SetPropertyValueString( wxPGPropArg id, const wxString& value );
1259
1260 /** Sets value (wxVariant&) of a property.
1261
1262 @remarks
1263 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1264 through validation process and send property change event.
1265 */
1266 void SetPropertyValue( wxPGPropArg id, wxVariant value )
1267 {
1268 SetPropVal( id, value );
1269 }
1270
1271 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1272 accepts reference. */
1273 void SetPropVal( wxPGPropArg id, wxVariant& value );
1274
1275 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1276 in a property.
1277 @param vfbFlags
1278 See @link vfbflags list of valid flags values@endlink
1279 */
1280 void SetValidationFailureBehavior( int vfbFlags );
1281
1282 /**
1283 Sorts all properties recursively.
1284
1285 @param flags
1286 This can contain any of the following options:
1287 wxPG_SORT_TOP_LEVEL_ONLY: Only sort categories and their
1288 immediate children. Sorting done by wxPG_AUTO_SORT option
1289 uses this.
1290
1291 @see SortChildren, wxPropertyGrid::SetSortFunction
1292 */
1293 void Sort( int flags = 0 );
1294
1295 /**
1296 Sorts children of a property.
1297
1298 @param id
1299 Name or pointer to a property.
1300
1301 @param flags
1302 This can contain any of the following options:
1303 wxPG_RECURSE: Sorts recursively.
1304
1305 @see Sort, wxPropertyGrid::SetSortFunction
1306 */
1307 void SortChildren( wxPGPropArg id, int flags = 0 )
1308 {
1309 wxPG_PROP_ARG_CALL_PROLOG()
1310 m_pState->DoSortChildren(p, flags);
1311 }
1312
1313 // GetPropertyByName With nice assertion error message.
1314 wxPGProperty* GetPropertyByNameA( const wxString& name ) const;
1315
1316 static wxPGEditor* GetEditorByName( const wxString& editorName );
1317
1318 // NOTE: This function reselects the property and may cause
1319 // excess flicker, so to just call Refresh() on a rect
1320 // of single property, call DrawItem() instead.
1321 virtual void RefreshProperty( wxPGProperty* p ) = 0;
1322
1323 protected:
1324
1325 bool DoClearSelection( bool validation = false,
1326 int selFlags = 0 );
1327
1328 /**
1329 In derived class, implement to set editable state component with
1330 given name to given value.
1331 */
1332 virtual bool SetEditableStateItem( const wxString& name, wxVariant value )
1333 {
1334 wxUnusedVar(name);
1335 wxUnusedVar(value);
1336 return false;
1337 }
1338
1339 /**
1340 In derived class, implement to return editable state component with
1341 given name.
1342 */
1343 virtual wxVariant GetEditableStateItem( const wxString& name ) const
1344 {
1345 wxUnusedVar(name);
1346 return wxNullVariant;
1347 }
1348
1349 // Returns page state data for given (sub) page (-1 means current page).
1350 virtual wxPropertyGridPageState* GetPageState( int pageIndex ) const
1351 {
1352 if ( pageIndex <= 0 )
1353 return m_pState;
1354 return NULL;
1355 }
1356
1357 virtual bool DoSelectPage( int WXUNUSED(index) ) { return true; }
1358
1359 // Default call's m_pState's BaseGetPropertyByName
1360 virtual wxPGProperty* DoGetPropertyByName( const wxString& name ) const;
1361
1362 // Deriving classes must set this (it must be only or current page).
1363 wxPropertyGridPageState* m_pState;
1364
1365 // Intermediate version needed due to wxVariant copying inefficiency
1366 void DoSetPropertyAttribute( wxPGPropArg id,
1367 const wxString& name,
1368 wxVariant& value, long argFlags );
1369
1370 // Empty string object to return from member functions returning const
1371 // wxString&.
1372 wxString m_emptyString;
1373
1374 private:
1375 // Cannot be GetGrid() due to ambiguity issues.
1376 wxPropertyGrid* GetPropertyGrid()
1377 {
1378 if ( !m_pState )
1379 return NULL;
1380 return m_pState->GetGrid();
1381 }
1382
1383 // Cannot be GetGrid() due to ambiguity issues.
1384 const wxPropertyGrid* GetPropertyGrid() const
1385 {
1386 if ( !m_pState )
1387 return NULL;
1388 return static_cast<const wxPropertyGrid*>(m_pState->GetGrid());
1389 }
1390
1391 friend class wxPropertyGrid;
1392 friend class wxPropertyGridManager;
1393 };
1394
1395 #endif // wxUSE_PROPGRID
1396
1397 #endif // __WX_PROPGRID_PROPGRIDIFACE_H__