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_
15 #include "wx/propgrid/property.h"
17 // -----------------------------------------------------------------------
19 /** @section propgrid_hittestresult wxPropertyGridHitTestResult
21 A return value from wxPropertyGrid::HitTest(),
22 contains all you need to know about an arbitrary location on the grid.
24 struct WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
26 friend class wxPropertyGridPageState
;
29 wxPGProperty
* GetProperty() const { return property
; }
31 /** Column. -1 for margin. */
34 /** Index of splitter hit, -1 for none. */
37 /** If splitter hit, offset to that */
38 int splitterHitOffset
;
41 /** Property. NULL if empty space below properties was hit */
42 wxPGProperty
* property
;
45 // -----------------------------------------------------------------------
47 #define wxPG_IT_CHILDREN(A) ((A)<<16)
49 /** @section propgrid_iterator_flags wxPropertyGridIterator Flags
52 NOTES: At lower 16-bits, there are flags to check if item will be included.
53 At higher 16-bits, there are same flags, but to instead check if children
57 enum wxPG_ITERATOR_FLAGS
61 Iterate through 'normal' property items (does not include children of
62 aggregate or hidden items by default).
64 wxPG_ITERATE_PROPERTIES
= wxPG_PROP_PROPERTY
|
65 wxPG_PROP_MISC_PARENT
|
68 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT
) |
69 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
),
71 /** Iterate children of collapsed parents, and individual items that are hidden.
73 wxPG_ITERATE_HIDDEN
= wxPG_PROP_HIDDEN
|
74 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED
),
77 Iterate children of parent that is an aggregate property (ie has fixed
80 wxPG_ITERATE_FIXED_CHILDREN
= wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
) |
81 wxPG_ITERATE_PROPERTIES
,
83 /** Iterate categories.
84 Note that even without this flag, children of categories are still iterated
87 wxPG_ITERATE_CATEGORIES
= wxPG_PROP_CATEGORY
|
88 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
) |
91 wxPG_ITERATE_ALL_PARENTS
= wxPG_PROP_MISC_PARENT
|
95 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
= wxPG_ITERATE_ALL_PARENTS
|
97 wxPG_ITERATE_ALL_PARENTS
),
99 wxPG_ITERATOR_FLAGS_ALL
= wxPG_PROP_PROPERTY
|
100 wxPG_PROP_MISC_PARENT
|
101 wxPG_PROP_AGGREGATE
|
106 wxPG_ITERATOR_MASK_OP_ITEM
= wxPG_ITERATOR_FLAGS_ALL
,
108 // (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
109 wxPG_ITERATOR_MASK_OP_PARENT
= wxPG_ITERATOR_FLAGS_ALL
,
111 /** Combines all flags needed to iterate through visible properties
112 (ie hidden properties and children of collapsed parents are skipped).
114 wxPG_ITERATE_VISIBLE
= wxPG_ITERATE_PROPERTIES
|
116 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
),
118 /** Iterate all items.
120 wxPG_ITERATE_ALL
= wxPG_ITERATE_VISIBLE
|
123 /** Iterate through individual properties (ie categories and children of
124 aggregate properties are skipped).
126 wxPG_ITERATE_NORMAL
= wxPG_ITERATE_PROPERTIES
|
129 /** Default iterator flags.
131 wxPG_ITERATE_DEFAULT
= wxPG_ITERATE_NORMAL
139 #define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \
140 A = (FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \
141 wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF; \
142 B = ((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \
143 wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF;
146 // Macro to test if children of PWC should be iterated through
147 #define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
149 !(PWC->GetFlags() & PARENTMASK) && \
150 PWC->GetChildCount() \
154 // Base for wxPropertyGridIterator classes.
155 class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
158 wxPropertyGridIteratorBase()
162 void Assign( const wxPropertyGridIteratorBase
& it
);
164 bool AtEnd() const { return m_property
== NULL
; }
166 /** Get current property.
168 wxPGProperty
* GetProperty() const { return m_property
; }
170 void Init( wxPropertyGridPageState
* state
,
172 wxPGProperty
* property
,
175 void Init( wxPropertyGridPageState
* state
,
177 int startPos
= wxTOP
,
180 /** Iterate to the next property.
182 void Next( bool iterateChildren
= true );
184 /** Iterate to the previous property.
189 Set base parent, ie a property when, in which iteration returns, it
192 Default base parent is the root of the used wxPropertyGridPageState.
194 void SetBaseParent( wxPGProperty
* baseParent
)
195 { m_baseParent
= baseParent
; }
199 wxPGProperty
* m_property
;
202 wxPropertyGridPageState
* m_state
;
203 wxPGProperty
* m_baseParent
;
205 // Masks are used to quickly exclude items
211 #define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
212 CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
213 PROPERTY* property = NULL, int dir = 1 ) \
214 : wxPropertyGridIteratorBase() \
215 { Init( (wxPropertyGridPageState*)state, flags, \
216 (wxPGProperty*)property, dir ); } \
217 CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
218 : wxPropertyGridIteratorBase() \
219 { Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
221 : wxPropertyGridIteratorBase() \
225 CLASS( const CLASS& it ) \
226 : wxPropertyGridIteratorBase( ) \
233 const CLASS& operator=( const CLASS& it ) \
238 CLASS& operator++() { Next(); return *this; } \
239 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
240 CLASS& operator--() { Prev(); return *this; } \
241 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
242 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
243 static PROPERTY* OneStep( STATE* state, \
244 int flags = wxPG_ITERATE_DEFAULT, \
245 PROPERTY* property = NULL, \
248 CLASS it( state, flags, property, dir ); \
251 if ( dir == 1 ) it.Next(); \
258 /** @class wxPropertyGridIterator
260 Preferable way to iterate through contents of wxPropertyGrid,
261 wxPropertyGridManager, and wxPropertyGridPage.
263 See wxPropertyGridInterface::GetIterator() for more information about usage.
268 class WXDLLIMPEXP_PROPGRID
269 wxPropertyGridIterator
: public wxPropertyGridIteratorBase
273 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator
,
275 wxPropertyGridPageState
)
281 // Const version of wxPropertyGridIterator.
282 class WXDLLIMPEXP_PROPGRID
283 wxPropertyGridConstIterator
: public wxPropertyGridIteratorBase
286 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator
,
288 const wxPropertyGridPageState
)
293 // -----------------------------------------------------------------------
295 /** Base class to derive new viterators.
297 class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
299 friend class wxPGVIterator
;
301 wxPGVIteratorBase() { m_refCount
= 1; }
302 virtual void Next() = 0;
310 if ( m_refCount
<= 0 )
314 virtual ~wxPGVIteratorBase() { }
316 wxPropertyGridIterator m_it
;
321 /** @class wxPGVIterator
323 Abstract implementation of a simple iterator. Can only be used
324 to iterate in forward order, and only through the entire container.
325 Used to have functions dealing with all properties work with both
326 wxPropertyGrid and wxPropertyGridManager.
328 class WXDLLIMPEXP_PROPGRID wxPGVIterator
331 wxPGVIterator() { m_pIt
= NULL
; }
332 wxPGVIterator( wxPGVIteratorBase
* obj
) { m_pIt
= obj
; }
333 ~wxPGVIterator() { UnRef(); }
334 void UnRef() { if (m_pIt
) m_pIt
->DecRef(); }
335 wxPGVIterator( const wxPGVIterator
& it
)
341 const wxPGVIterator
& operator=( const wxPGVIterator
& it
)
349 void Next() { m_pIt
->Next(); }
350 bool AtEnd() const { return m_pIt
->m_it
.AtEnd(); }
351 wxPGProperty
* GetProperty() const { return m_pIt
->m_it
.GetProperty(); }
353 wxPGVIteratorBase
* m_pIt
;
356 // -----------------------------------------------------------------------
359 // We won't need this class from wxPython
361 /** @class wxPropertyGridPageState
363 Contains low-level property page information (properties, column widths,
364 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
365 should not use this class directly, but instead member functions in
366 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
367 wxPropertyGridManager.
370 - In separate wxPropertyGrid component this class was known as
372 - Currently this class is not implemented in wxPython.
377 class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
379 friend class wxPGProperty
;
380 friend class wxPropertyGrid
;
381 friend class wxPGCanvas
;
382 friend class wxPropertyGridInterface
;
383 friend class wxPropertyGridPage
;
384 friend class wxPropertyGridManager
;
387 /** Default constructor. */
388 wxPropertyGridPageState();
391 virtual ~wxPropertyGridPageState();
393 /** Makes sure all columns have minimum width.
395 void CheckColumnWidths( int widthChange
= 0 );
398 Override this member function to add custom behavior on property
401 virtual void DoDelete( wxPGProperty
* item
);
403 wxSize
DoFitColumns( bool allowGridResize
= false );
405 wxPGProperty
* DoGetItemAtY( int y
) const;
408 Override this member function to add custom behavior on property
411 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
413 wxPGProperty
* property
);
416 This needs to be overridden in grid used the manager so that splitter
417 changes can be propagated to other pages.
419 virtual void DoSetSplitterPosition( int pos
,
420 int splitterColumn
= 0,
421 bool allPages
= false,
422 bool fromAutoCenter
= false );
424 bool EnableCategories( bool enable
);
426 /** Make sure virtual height is up-to-date.
428 void EnsureVirtualHeight()
430 if ( m_vhCalcPending
)
432 RecalculateVirtualHeight();
437 /** Enables or disables given property and its subproperties. */
438 bool DoEnableProperty( wxPGProperty
* p
, bool enable
);
440 /** Returns (precalculated) height of contained visible properties.
442 unsigned int GetVirtualHeight() const
444 wxASSERT( !m_vhCalcPending
);
445 return m_virtualHeight
;
448 /** Returns (precalculated) height of contained visible properties.
450 unsigned int GetVirtualHeight()
452 EnsureVirtualHeight();
453 return m_virtualHeight
;
456 /** Returns actual height of contained visible properties.
458 Mostly used for internal diagnostic purposes.
460 inline unsigned int GetActualVirtualHeight() const;
462 unsigned int GetColumnCount() const
464 return m_colWidths
.size();
467 wxPGProperty
* GetSelection() const
472 int GetColumnMinWidth( int column
) const;
474 int GetColumnWidth( unsigned int column
) const
476 return m_colWidths
[column
];
479 wxPropertyGrid
* GetGrid() const { return m_pPropGrid
; }
481 /** Returns last item which could be iterated using given flags.
483 @link iteratorflags List of iterator flags@endlink
485 wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
);
487 const wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
) const
489 return ((wxPropertyGridPageState
*)this)->GetLastItem(flags
);
492 wxPropertyCategory
* GetPropertyCategory( const wxPGProperty
* p
) const;
494 wxPGProperty
* GetPropertyByLabel( const wxString
& name
,
495 wxPGProperty
* parent
= NULL
) const;
497 wxVariant
DoGetPropertyValues( const wxString
& listname
,
498 wxPGProperty
* baseparent
,
501 wxPGProperty
* DoGetRoot() const { return m_properties
; }
503 // Returns combined width of margin and all the columns
504 int GetVirtualWidth() const
510 Returns minimal width for given column so that all images and texts
513 Used by SetSplitterLeft() and DoFitColumns().
515 int GetColumnFitWidth(wxClientDC
& dc
,
518 bool subProps
) const;
520 /** Returns information about arbitrary position in the grid.
522 wxPropertyGridHitTestResult definition:
524 struct wxPropertyGridHitTestResult
526 wxPGProperty* GetProperty() const;
528 // column. -1 for margin
531 // Index of splitter hit, -1 for none.
534 // If splitter hit, then offset to that.
535 int splitterHitOffset;
539 wxPropertyGridHitTestResult
HitTest( const wxPoint
& pt
) const;
541 /** Returns true if page is visibly displayed.
543 inline bool IsDisplayed() const;
545 bool IsInNonCatMode() const { return (bool)(m_properties
== m_abcArray
); }
547 /** Only inits arrays, doesn't migrate things or such. */
548 void InitNonCatMode ();
550 void DoLimitPropertyEditing( wxPGProperty
* p
, bool limit
= true )
552 p
->SetFlagRecursively(wxPG_PROP_NOEDITOR
, limit
);
555 bool DoSelectProperty( wxPGProperty
* p
, unsigned int flags
= 0 );
557 /** widthChange is non-client.
559 void OnClientWidthChange( int newWidth
,
561 bool fromOnResize
= false );
563 /** Recalculates m_virtualHeight.
565 void RecalculateVirtualHeight()
567 m_virtualHeight
= GetActualVirtualHeight();
570 void SetColumnCount( int colCount
);
572 void PropagateColSizeDec( int column
, int decrease
, int dir
);
574 bool DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
= wxPG_RECURSE
);
576 bool DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
);
578 bool DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
);
580 bool DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
);
581 void DoSetPropertyValues( const wxVariantList
& list
,
582 wxPGProperty
* default_category
);
584 void DoSetPropertyValueUnspecified( wxPGProperty
* p
);
586 void SetSplitterLeft( bool subProps
= false );
588 /** Set virtual width for this particular page. */
589 void SetVirtualWidth( int width
);
591 void SortChildren( wxPGProperty
* p
);
594 void SetSelection( wxPGProperty
* p
) { m_selected
= p
; }
596 /** Called after virtual height needs to be recalculated.
598 void VirtualHeightChanged()
604 wxPGProperty
* DoAppend( wxPGProperty
* property
);
606 /** Returns property by its name. */
607 wxPGProperty
* BaseGetPropertyByName( const wxString
& name
) const;
609 void DoClearSelection()
614 /** Called in, for example, wxPropertyGrid::Clear. */
617 bool DoCollapse( wxPGProperty
* p
);
619 bool DoExpand( wxPGProperty
* p
);
621 void CalculateFontAndBitmapStuff( int vspacing
);
625 int DoGetSplitterPosition( int splitterIndex
= 0 ) const;
627 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
629 Give pointer to int that receives index to splitter that is at x.
630 @param pSplitterHitOffset
631 Distance from said splitter.
633 int HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const;
635 int PrepareToAddItem ( wxPGProperty
* property
,
636 wxPGProperty
* scheduledParent
);
638 /** If visible, then this is pointer to wxPropertyGrid.
639 This shall *never* be NULL to indicate that this state is not visible.
641 wxPropertyGrid
* m_pPropGrid
;
643 /** Pointer to currently used array. */
644 wxPGProperty
* m_properties
;
646 /** Array for categoric mode. */
647 wxPGRootProperty m_regularArray
;
649 /** Array for root of non-categoric mode. */
650 wxPGRootProperty
* m_abcArray
;
652 /** Dictionary for name-based access. */
653 wxPGHashMapS2P m_dictName
;
655 /** List of column widths (first column does not include margin). */
656 wxArrayInt m_colWidths
;
660 /** Most recently added category. */
661 wxPropertyCategory
* m_currentCategory
;
663 /** Pointer to selected property. */
664 wxPGProperty
* m_selected
;
666 /** Virtual width. */
669 /** Indicates total virtual height of visible properties. */
670 unsigned int m_virtualHeight
;
672 /** 1 if m_lastCaption is also the bottommost caption. */
673 unsigned char m_lastCaptionBottomnest
;
675 /** 1 items appended/inserted, so stuff needs to be done before drawing;
676 If m_virtualHeight == 0, then calcylatey's must be done.
679 unsigned char m_itemsAdded
;
681 /** 1 if any value is modified. */
682 unsigned char m_anyModified
;
684 unsigned char m_vhCalcPending
;
687 #endif // #ifndef SWIG
689 // -----------------------------------------------------------------------
691 #endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_