1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/propgridpagestate.h
3 // Purpose: wxPropertyGridPageState class
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPGRIDPAGESTATE_H_
13 #define _WX_PROPGRID_PROPGRIDPAGESTATE_H_
17 #include "wx/propgrid/property.h"
19 // -----------------------------------------------------------------------
21 /** @section propgrid_hittestresult wxPropertyGridHitTestResult
23 A return value from wxPropertyGrid::HitTest(),
24 contains all you need to know about an arbitrary location on the grid.
26 struct WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
28 friend class wxPropertyGridPageState
;
31 wxPGProperty
* GetProperty() const { return property
; }
33 /** Column. -1 for margin. */
36 /** Index of splitter hit, -1 for none. */
39 /** If splitter hit, offset to that */
40 int splitterHitOffset
;
43 /** Property. NULL if empty space below properties was hit */
44 wxPGProperty
* property
;
47 // -----------------------------------------------------------------------
49 #define wxPG_IT_CHILDREN(A) ((A)<<16)
51 /** @section propgrid_iterator_flags wxPropertyGridIterator Flags
54 NOTES: At lower 16-bits, there are flags to check if item will be included.
55 At higher 16-bits, there are same flags, but to instead check if children
59 enum wxPG_ITERATOR_FLAGS
63 Iterate through 'normal' property items (does not include children of
64 aggregate or hidden items by default).
66 wxPG_ITERATE_PROPERTIES
= wxPG_PROP_PROPERTY
|
67 wxPG_PROP_MISC_PARENT
|
70 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT
) |
71 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
),
73 /** Iterate children of collapsed parents, and individual items that are hidden.
75 wxPG_ITERATE_HIDDEN
= wxPG_PROP_HIDDEN
|
76 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED
),
79 Iterate children of parent that is an aggregate property (ie has fixed
82 wxPG_ITERATE_FIXED_CHILDREN
= wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
) |
83 wxPG_ITERATE_PROPERTIES
,
85 /** Iterate categories.
86 Note that even without this flag, children of categories are still iterated
89 wxPG_ITERATE_CATEGORIES
= wxPG_PROP_CATEGORY
|
90 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
) |
93 wxPG_ITERATE_ALL_PARENTS
= wxPG_PROP_MISC_PARENT
|
97 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
= wxPG_ITERATE_ALL_PARENTS
|
99 wxPG_ITERATE_ALL_PARENTS
),
101 wxPG_ITERATOR_FLAGS_ALL
= wxPG_PROP_PROPERTY
|
102 wxPG_PROP_MISC_PARENT
|
103 wxPG_PROP_AGGREGATE
|
108 wxPG_ITERATOR_MASK_OP_ITEM
= wxPG_ITERATOR_FLAGS_ALL
,
110 // (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
111 wxPG_ITERATOR_MASK_OP_PARENT
= wxPG_ITERATOR_FLAGS_ALL
,
113 /** Combines all flags needed to iterate through visible properties
114 (ie hidden properties and children of collapsed parents are skipped).
116 wxPG_ITERATE_VISIBLE
= wxPG_ITERATE_PROPERTIES
|
118 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
),
120 /** Iterate all items.
122 wxPG_ITERATE_ALL
= wxPG_ITERATE_VISIBLE
|
125 /** Iterate through individual properties (ie categories and children of
126 aggregate properties are skipped).
128 wxPG_ITERATE_NORMAL
= wxPG_ITERATE_PROPERTIES
|
131 /** Default iterator flags.
133 wxPG_ITERATE_DEFAULT
= wxPG_ITERATE_NORMAL
141 #define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \
142 A = (FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \
143 wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF; \
144 B = ((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \
145 wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF;
148 // Macro to test if children of PWC should be iterated through
149 #define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
151 !(PWC->GetFlags() & PARENTMASK) && \
152 PWC->GetChildCount() \
156 // Base for wxPropertyGridIterator classes.
157 class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
160 wxPropertyGridIteratorBase()
164 void Assign( const wxPropertyGridIteratorBase
& it
);
166 bool AtEnd() const { return m_property
== NULL
; }
168 /** Get current property.
170 wxPGProperty
* GetProperty() const { return m_property
; }
172 void Init( wxPropertyGridPageState
* state
,
174 wxPGProperty
* property
,
177 void Init( wxPropertyGridPageState
* state
,
179 int startPos
= wxTOP
,
182 /** Iterate to the next property.
184 void Next( bool iterateChildren
= true );
186 /** Iterate to the previous property.
191 Set base parent, ie a property when, in which iteration returns, it
194 Default base parent is the root of the used wxPropertyGridPageState.
196 void SetBaseParent( wxPGProperty
* baseParent
)
197 { m_baseParent
= baseParent
; }
201 wxPGProperty
* m_property
;
204 wxPropertyGridPageState
* m_state
;
205 wxPGProperty
* m_baseParent
;
207 // Masks are used to quickly exclude items
213 #define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
214 CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
215 PROPERTY* property = NULL, int dir = 1 ) \
216 : wxPropertyGridIteratorBase() \
217 { Init( (wxPropertyGridPageState*)state, flags, \
218 (wxPGProperty*)property, dir ); } \
219 CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
220 : wxPropertyGridIteratorBase() \
221 { Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
223 : wxPropertyGridIteratorBase() \
227 CLASS( const CLASS& it ) \
228 : wxPropertyGridIteratorBase( ) \
235 const CLASS& operator=( const CLASS& it ) \
241 CLASS& operator++() { Next(); return *this; } \
242 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
243 CLASS& operator--() { Prev(); return *this; } \
244 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
245 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
246 static PROPERTY* OneStep( STATE* state, \
247 int flags = wxPG_ITERATE_DEFAULT, \
248 PROPERTY* property = NULL, \
251 CLASS it( state, flags, property, dir ); \
254 if ( dir == 1 ) it.Next(); \
261 /** @class wxPropertyGridIterator
263 Preferable way to iterate through contents of wxPropertyGrid,
264 wxPropertyGridManager, and wxPropertyGridPage.
266 See wxPropertyGridInterface::GetIterator() for more information about usage.
271 class WXDLLIMPEXP_PROPGRID
272 wxPropertyGridIterator
: public wxPropertyGridIteratorBase
276 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator
,
278 wxPropertyGridPageState
)
284 // Const version of wxPropertyGridIterator.
285 class WXDLLIMPEXP_PROPGRID
286 wxPropertyGridConstIterator
: public wxPropertyGridIteratorBase
289 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator
,
291 const wxPropertyGridPageState
)
294 Additional copy constructor.
296 wxPropertyGridConstIterator( const wxPropertyGridIterator
& other
)
302 Additional assignment operator.
304 const wxPropertyGridConstIterator
& operator=( const wxPropertyGridIterator
& it
)
313 // -----------------------------------------------------------------------
315 /** Base class to derive new viterators.
317 class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
319 friend class wxPGVIterator
;
321 wxPGVIteratorBase() { m_refCount
= 1; }
322 virtual void Next() = 0;
330 if ( m_refCount
<= 0 )
334 virtual ~wxPGVIteratorBase() { }
336 wxPropertyGridIterator m_it
;
341 /** @class wxPGVIterator
343 Abstract implementation of a simple iterator. Can only be used
344 to iterate in forward order, and only through the entire container.
345 Used to have functions dealing with all properties work with both
346 wxPropertyGrid and wxPropertyGridManager.
348 class WXDLLIMPEXP_PROPGRID wxPGVIterator
351 wxPGVIterator() { m_pIt
= NULL
; }
352 wxPGVIterator( wxPGVIteratorBase
* obj
) { m_pIt
= obj
; }
353 ~wxPGVIterator() { UnRef(); }
354 void UnRef() { if (m_pIt
) m_pIt
->DecRef(); }
355 wxPGVIterator( const wxPGVIterator
& it
)
361 const wxPGVIterator
& operator=( const wxPGVIterator
& it
)
372 void Next() { m_pIt
->Next(); }
373 bool AtEnd() const { return m_pIt
->m_it
.AtEnd(); }
374 wxPGProperty
* GetProperty() const { return m_pIt
->m_it
.GetProperty(); }
376 wxPGVIteratorBase
* m_pIt
;
379 // -----------------------------------------------------------------------
382 // We won't need this class from wxPython
384 /** @class wxPropertyGridPageState
386 Contains low-level property page information (properties, column widths,
387 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
388 should not use this class directly, but instead member functions in
389 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
390 wxPropertyGridManager.
393 - In separate wxPropertyGrid component this class was known as
395 - Currently this class is not implemented in wxPython.
400 class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
402 friend class wxPGProperty
;
403 friend class wxPropertyGrid
;
404 friend class wxPGCanvas
;
405 friend class wxPropertyGridInterface
;
406 friend class wxPropertyGridPage
;
407 friend class wxPropertyGridManager
;
410 /** Default constructor. */
411 wxPropertyGridPageState();
414 virtual ~wxPropertyGridPageState();
416 /** Makes sure all columns have minimum width.
418 void CheckColumnWidths( int widthChange
= 0 );
421 Override this member function to add custom behavior on property
424 virtual void DoDelete( wxPGProperty
* item
, bool doDelete
= true );
426 wxSize
DoFitColumns( bool allowGridResize
= false );
428 wxPGProperty
* DoGetItemAtY( int y
) const;
431 Override this member function to add custom behavior on property
434 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
436 wxPGProperty
* property
);
439 This needs to be overridden in grid used the manager so that splitter
440 changes can be propagated to other pages.
442 virtual void DoSetSplitterPosition( int pos
,
443 int splitterColumn
= 0,
444 bool allPages
= false,
445 bool fromAutoCenter
= false );
447 bool EnableCategories( bool enable
);
449 /** Make sure virtual height is up-to-date.
451 void EnsureVirtualHeight()
453 if ( m_vhCalcPending
)
455 RecalculateVirtualHeight();
460 /** Enables or disables given property and its subproperties. */
461 bool DoEnableProperty( wxPGProperty
* p
, bool enable
);
463 /** Returns (precalculated) height of contained visible properties.
465 unsigned int GetVirtualHeight() const
467 wxASSERT( !m_vhCalcPending
);
468 return m_virtualHeight
;
471 /** Returns (precalculated) height of contained visible properties.
473 unsigned int GetVirtualHeight()
475 EnsureVirtualHeight();
476 return m_virtualHeight
;
479 /** Returns actual height of contained visible properties.
481 Mostly used for internal diagnostic purposes.
483 inline unsigned int GetActualVirtualHeight() const;
485 unsigned int GetColumnCount() const
487 return (unsigned int) m_colWidths
.size();
490 wxPGProperty
* GetSelection() const
495 int GetColumnMinWidth( int column
) const;
497 int GetColumnWidth( unsigned int column
) const
499 return m_colWidths
[column
];
502 wxPropertyGrid
* GetGrid() const { return m_pPropGrid
; }
504 /** Returns last item which could be iterated using given flags.
506 @link iteratorflags List of iterator flags@endlink
508 wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
);
510 const wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
) const
512 return ((wxPropertyGridPageState
*)this)->GetLastItem(flags
);
515 wxPropertyCategory
* GetPropertyCategory( const wxPGProperty
* p
) const;
517 wxPGProperty
* GetPropertyByLabel( const wxString
& name
,
518 wxPGProperty
* parent
= NULL
) const;
520 wxVariant
DoGetPropertyValues( const wxString
& listname
,
521 wxPGProperty
* baseparent
,
524 wxPGProperty
* DoGetRoot() const { return m_properties
; }
526 void DoSetPropertyName( wxPGProperty
* p
, const wxString
& newName
);
528 // Returns combined width of margin and all the columns
529 int GetVirtualWidth() const
535 Returns minimal width for given column so that all images and texts
538 Used by SetSplitterLeft() and DoFitColumns().
540 int GetColumnFitWidth(wxClientDC
& dc
,
543 bool subProps
) const;
545 /** Returns information about arbitrary position in the grid.
547 wxPropertyGridHitTestResult definition:
549 struct wxPropertyGridHitTestResult
551 wxPGProperty* GetProperty() const;
553 // column. -1 for margin
556 // Index of splitter hit, -1 for none.
559 // If splitter hit, then offset to that.
560 int splitterHitOffset;
564 wxPropertyGridHitTestResult
HitTest( const wxPoint
& pt
) const;
566 /** Returns true if page is visibly displayed.
568 inline bool IsDisplayed() const;
570 bool IsInNonCatMode() const { return (bool)(m_properties
== m_abcArray
); }
572 /** Only inits arrays, doesn't migrate things or such. */
573 void InitNonCatMode ();
575 void DoLimitPropertyEditing( wxPGProperty
* p
, bool limit
= true )
577 p
->SetFlagRecursively(wxPG_PROP_NOEDITOR
, limit
);
580 bool DoSelectProperty( wxPGProperty
* p
, unsigned int flags
= 0 );
582 /** widthChange is non-client.
584 void OnClientWidthChange( int newWidth
,
586 bool fromOnResize
= false );
588 /** Recalculates m_virtualHeight.
590 void RecalculateVirtualHeight()
592 m_virtualHeight
= GetActualVirtualHeight();
595 void SetColumnCount( int colCount
);
597 void PropagateColSizeDec( int column
, int decrease
, int dir
);
599 bool DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
= wxPG_RECURSE
);
601 bool DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
);
603 bool DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
);
605 bool DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
);
606 void DoSetPropertyValues( const wxVariantList
& list
,
607 wxPGProperty
* default_category
);
609 void SetSplitterLeft( bool subProps
= false );
611 /** Set virtual width for this particular page. */
612 void SetVirtualWidth( int width
);
614 void DoSortChildren( wxPGProperty
* p
, int flags
= 0 );
615 void DoSort( int flags
= 0 );
617 bool PrepareAfterItemsAdded();
619 void SetSelection( wxPGProperty
* p
) { m_selected
= p
; }
621 /** Called after virtual height needs to be recalculated.
623 void VirtualHeightChanged()
629 wxPGProperty
* DoAppend( wxPGProperty
* property
);
631 /** Returns property by its name. */
632 wxPGProperty
* BaseGetPropertyByName( const wxString
& name
) const;
634 void DoClearSelection()
639 /** Called in, for example, wxPropertyGrid::Clear. */
642 bool DoCollapse( wxPGProperty
* p
);
644 bool DoExpand( wxPGProperty
* p
);
646 void CalculateFontAndBitmapStuff( int vspacing
);
650 int DoGetSplitterPosition( int splitterIndex
= 0 ) const;
652 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
654 Give pointer to int that receives index to splitter that is at x.
655 @param pSplitterHitOffset
656 Distance from said splitter.
658 int HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const;
660 bool PrepareToAddItem( wxPGProperty
* property
,
661 wxPGProperty
* scheduledParent
);
663 /** If visible, then this is pointer to wxPropertyGrid.
664 This shall *never* be NULL to indicate that this state is not visible.
666 wxPropertyGrid
* m_pPropGrid
;
668 /** Pointer to currently used array. */
669 wxPGProperty
* m_properties
;
671 /** Array for categoric mode. */
672 wxPGRootProperty m_regularArray
;
674 /** Array for root of non-categoric mode. */
675 wxPGRootProperty
* m_abcArray
;
677 /** Dictionary for name-based access. */
678 wxPGHashMapS2P m_dictName
;
680 /** List of column widths (first column does not include margin). */
681 wxArrayInt m_colWidths
;
685 /** Most recently added category. */
686 wxPropertyCategory
* m_currentCategory
;
688 /** Pointer to selected property. */
689 wxPGProperty
* m_selected
;
691 /** Virtual width. */
694 /** Indicates total virtual height of visible properties. */
695 unsigned int m_virtualHeight
;
697 /** 1 if m_lastCaption is also the bottommost caption. */
698 unsigned char m_lastCaptionBottomnest
;
700 /** 1 items appended/inserted, so stuff needs to be done before drawing;
701 If m_virtualHeight == 0, then calcylatey's must be done.
704 unsigned char m_itemsAdded
;
706 /** 1 if any value is modified. */
707 unsigned char m_anyModified
;
709 unsigned char m_vhCalcPending
;
712 #endif // #ifndef SWIG
714 // -----------------------------------------------------------------------
716 #endif // wxUSE_PROPGRID
718 #endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_