1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/propgridpagestate.h
3 // Purpose: wxPropertyGridPageState class
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPGRIDPAGESTATE_H_
13 #define _WX_PROPGRID_PROPGRIDPAGESTATE_H_
19 #include "wx/propgrid/property.h"
21 // -----------------------------------------------------------------------
23 /** @section propgrid_hittestresult wxPropertyGridHitTestResult
25 A return value from wxPropertyGrid::HitTest(),
26 contains all you need to know about an arbitrary location on the grid.
28 class WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
30 friend class wxPropertyGridPageState
;
32 wxPropertyGridHitTestResult()
37 m_splitterHitOffset
= 0;
40 ~wxPropertyGridHitTestResult()
45 Returns column hit. -1 for margin.
47 int GetColumn() const { return m_column
; }
50 Returns property hit. NULL if empty space below
51 properties was hit instead.
53 wxPGProperty
* GetProperty() const
59 Returns index of splitter hit, -1 for none.
61 int GetSplitter() const { return m_splitter
; }
64 If splitter hit, then this member function
65 returns offset to the exact splitter position.
67 int GetSplitterHitOffset() const { return m_splitterHitOffset
; }
70 /** Property. NULL if empty space below properties was hit */
71 wxPGProperty
* m_property
;
73 /** Column. -1 for margin. */
76 /** Index of splitter hit, -1 for none. */
79 /** If splitter hit, offset to that */
80 int m_splitterHitOffset
;
83 // -----------------------------------------------------------------------
85 #define wxPG_IT_CHILDREN(A) ((A)<<16)
87 /** @section propgrid_iterator_flags wxPropertyGridIterator Flags
90 NOTES: At lower 16-bits, there are flags to check if item will be included.
91 At higher 16-bits, there are same flags, but to instead check if children
95 enum wxPG_ITERATOR_FLAGS
99 Iterate through 'normal' property items (does not include children of
100 aggregate or hidden items by default).
102 wxPG_ITERATE_PROPERTIES
= wxPG_PROP_PROPERTY
|
103 wxPG_PROP_MISC_PARENT
|
104 wxPG_PROP_AGGREGATE
|
105 wxPG_PROP_COLLAPSED
|
106 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT
) |
107 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
),
109 /** Iterate children of collapsed parents, and individual items that are hidden.
111 wxPG_ITERATE_HIDDEN
= wxPG_PROP_HIDDEN
|
112 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED
),
115 Iterate children of parent that is an aggregate property (ie has fixed
118 wxPG_ITERATE_FIXED_CHILDREN
= wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
) |
119 wxPG_ITERATE_PROPERTIES
,
121 /** Iterate categories.
122 Note that even without this flag, children of categories are still iterated
125 wxPG_ITERATE_CATEGORIES
= wxPG_PROP_CATEGORY
|
126 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
) |
129 wxPG_ITERATE_ALL_PARENTS
= wxPG_PROP_MISC_PARENT
|
130 wxPG_PROP_AGGREGATE
|
133 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
= wxPG_ITERATE_ALL_PARENTS
|
135 wxPG_ITERATE_ALL_PARENTS
),
137 wxPG_ITERATOR_FLAGS_ALL
= wxPG_PROP_PROPERTY
|
138 wxPG_PROP_MISC_PARENT
|
139 wxPG_PROP_AGGREGATE
|
144 wxPG_ITERATOR_MASK_OP_ITEM
= wxPG_ITERATOR_FLAGS_ALL
,
146 // (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
147 wxPG_ITERATOR_MASK_OP_PARENT
= wxPG_ITERATOR_FLAGS_ALL
,
149 /** Combines all flags needed to iterate through visible properties
150 (ie hidden properties and children of collapsed parents are skipped).
152 wxPG_ITERATE_VISIBLE
= wxPG_ITERATE_PROPERTIES
|
154 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
),
156 /** Iterate all items.
158 wxPG_ITERATE_ALL
= wxPG_ITERATE_VISIBLE
|
161 /** Iterate through individual properties (ie categories and children of
162 aggregate properties are skipped).
164 wxPG_ITERATE_NORMAL
= wxPG_ITERATE_PROPERTIES
|
167 /** Default iterator flags.
169 wxPG_ITERATE_DEFAULT
= wxPG_ITERATE_NORMAL
177 #define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \
178 A = (FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \
179 wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF; \
180 B = ((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \
181 wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF;
184 // Macro to test if children of PWC should be iterated through
185 #define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
187 !(PWC->GetFlags() & PARENTMASK) && \
188 PWC->GetChildCount() \
192 // Base for wxPropertyGridIterator classes.
193 class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
196 wxPropertyGridIteratorBase()
200 void Assign( const wxPropertyGridIteratorBase
& it
);
202 bool AtEnd() const { return m_property
== NULL
; }
204 /** Get current property.
206 wxPGProperty
* GetProperty() const { return m_property
; }
208 void Init( wxPropertyGridPageState
* state
,
210 wxPGProperty
* property
,
213 void Init( wxPropertyGridPageState
* state
,
215 int startPos
= wxTOP
,
218 /** Iterate to the next property.
220 void Next( bool iterateChildren
= true );
222 /** Iterate to the previous property.
227 Set base parent, ie a property when, in which iteration returns, it
230 Default base parent is the root of the used wxPropertyGridPageState.
232 void SetBaseParent( wxPGProperty
* baseParent
)
233 { m_baseParent
= baseParent
; }
237 wxPGProperty
* m_property
;
240 wxPropertyGridPageState
* m_state
;
241 wxPGProperty
* m_baseParent
;
243 // Masks are used to quickly exclude items
249 #define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
250 CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
251 PROPERTY* property = NULL, int dir = 1 ) \
252 : wxPropertyGridIteratorBase() \
253 { Init( (wxPropertyGridPageState*)state, flags, \
254 (wxPGProperty*)property, dir ); } \
255 CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
256 : wxPropertyGridIteratorBase() \
257 { Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
259 : wxPropertyGridIteratorBase() \
263 CLASS( const CLASS& it ) \
264 : wxPropertyGridIteratorBase( ) \
271 const CLASS& operator=( const CLASS& it ) \
277 CLASS& operator++() { Next(); return *this; } \
278 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
279 CLASS& operator--() { Prev(); return *this; } \
280 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
281 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
282 static PROPERTY* OneStep( STATE* state, \
283 int flags = wxPG_ITERATE_DEFAULT, \
284 PROPERTY* property = NULL, \
287 CLASS it( state, flags, property, dir ); \
290 if ( dir == 1 ) it.Next(); \
297 /** @class wxPropertyGridIterator
299 Preferable way to iterate through contents of wxPropertyGrid,
300 wxPropertyGridManager, and wxPropertyGridPage.
302 See wxPropertyGridInterface::GetIterator() for more information about usage.
307 class WXDLLIMPEXP_PROPGRID
308 wxPropertyGridIterator
: public wxPropertyGridIteratorBase
312 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator
,
314 wxPropertyGridPageState
)
320 // Const version of wxPropertyGridIterator.
321 class WXDLLIMPEXP_PROPGRID
322 wxPropertyGridConstIterator
: public wxPropertyGridIteratorBase
325 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator
,
327 const wxPropertyGridPageState
)
330 Additional copy constructor.
332 wxPropertyGridConstIterator( const wxPropertyGridIterator
& other
)
338 Additional assignment operator.
340 const wxPropertyGridConstIterator
& operator=( const wxPropertyGridIterator
& it
)
349 // -----------------------------------------------------------------------
351 /** Base class to derive new viterators.
353 class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
: public wxObjectRefData
355 friend class wxPGVIterator
;
357 wxPGVIteratorBase() { }
358 virtual void Next() = 0;
360 virtual ~wxPGVIteratorBase() { }
362 wxPropertyGridIterator m_it
;
365 /** @class wxPGVIterator
367 Abstract implementation of a simple iterator. Can only be used
368 to iterate in forward order, and only through the entire container.
369 Used to have functions dealing with all properties work with both
370 wxPropertyGrid and wxPropertyGridManager.
372 class WXDLLIMPEXP_PROPGRID wxPGVIterator
375 wxPGVIterator() { m_pIt
= NULL
; }
376 wxPGVIterator( wxPGVIteratorBase
* obj
) { m_pIt
= obj
; }
377 ~wxPGVIterator() { UnRef(); }
378 void UnRef() { if (m_pIt
) m_pIt
->DecRef(); }
379 wxPGVIterator( const wxPGVIterator
& it
)
384 const wxPGVIterator
& operator=( const wxPGVIterator
& it
)
394 void Next() { m_pIt
->Next(); }
395 bool AtEnd() const { return m_pIt
->m_it
.AtEnd(); }
396 wxPGProperty
* GetProperty() const { return m_pIt
->m_it
.GetProperty(); }
398 wxPGVIteratorBase
* m_pIt
;
401 // -----------------------------------------------------------------------
403 /** @class wxPropertyGridPageState
405 Contains low-level property page information (properties, column widths,
406 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
407 should not use this class directly, but instead member functions in
408 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
409 wxPropertyGridManager.
412 - In separate wxPropertyGrid component this class was known as
414 - Currently this class is not implemented in wxPython.
419 class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
421 friend class wxPGProperty
;
422 friend class wxPropertyGrid
;
423 friend class wxPGCanvas
;
424 friend class wxPropertyGridInterface
;
425 friend class wxPropertyGridPage
;
426 friend class wxPropertyGridManager
;
429 /** Default constructor. */
430 wxPropertyGridPageState();
433 virtual ~wxPropertyGridPageState();
435 /** Makes sure all columns have minimum width.
437 void CheckColumnWidths( int widthChange
= 0 );
440 Override this member function to add custom behaviour on property
443 virtual void DoDelete( wxPGProperty
* item
, bool doDelete
= true );
445 wxSize
DoFitColumns( bool allowGridResize
= false );
447 wxPGProperty
* DoGetItemAtY( int y
) const;
450 Override this member function to add custom behaviour on property
453 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
455 wxPGProperty
* property
);
458 This needs to be overridden in grid used the manager so that splitter
459 changes can be propagated to other pages.
461 virtual void DoSetSplitterPosition( int pos
,
462 int splitterColumn
= 0,
465 bool EnableCategories( bool enable
);
467 /** Make sure virtual height is up-to-date.
469 void EnsureVirtualHeight()
471 if ( m_vhCalcPending
)
473 RecalculateVirtualHeight();
478 /** Returns (precalculated) height of contained visible properties.
480 unsigned int GetVirtualHeight() const
482 wxASSERT( !m_vhCalcPending
);
483 return m_virtualHeight
;
486 /** Returns (precalculated) height of contained visible properties.
488 unsigned int GetVirtualHeight()
490 EnsureVirtualHeight();
491 return m_virtualHeight
;
494 /** Returns actual height of contained visible properties.
496 Mostly used for internal diagnostic purposes.
498 inline unsigned int GetActualVirtualHeight() const;
500 unsigned int GetColumnCount() const
502 return (unsigned int) m_colWidths
.size();
505 int GetColumnMinWidth( int column
) const;
507 int GetColumnWidth( unsigned int column
) const
509 return m_colWidths
[column
];
512 wxPropertyGrid
* GetGrid() const { return m_pPropGrid
; }
514 /** Returns last item which could be iterated using given flags.
516 @link iteratorflags List of iterator flags@endlink
518 wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
);
520 const wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
) const
522 return ((wxPropertyGridPageState
*)this)->GetLastItem(flags
);
526 Returns currently selected property.
528 wxPGProperty
* GetSelection() const
530 if ( m_selection
.size() == 0 )
532 return m_selection
[0];
535 void DoSetSelection( wxPGProperty
* prop
)
539 m_selection
.push_back(prop
);
542 bool DoClearSelection()
544 return DoSelectProperty(NULL
);
547 void DoRemoveFromSelection( wxPGProperty
* prop
);
549 void DoSetColumnProportion( unsigned int column
, int proportion
);
551 int DoGetColumnProportion( unsigned int column
) const
553 return m_columnProportions
[column
];
556 void ResetColumnSizes( int setSplitterFlags
);
558 wxPropertyCategory
* GetPropertyCategory( const wxPGProperty
* p
) const;
560 wxPGProperty
* GetPropertyByLabel( const wxString
& name
,
561 wxPGProperty
* parent
= NULL
) const;
563 wxVariant
DoGetPropertyValues( const wxString
& listname
,
564 wxPGProperty
* baseparent
,
567 wxPGProperty
* DoGetRoot() const { return m_properties
; }
569 void DoSetPropertyName( wxPGProperty
* p
, const wxString
& newName
);
571 // Returns combined width of margin and all the columns
572 int GetVirtualWidth() const
578 Returns minimal width for given column so that all images and texts
581 Used by SetSplitterLeft() and DoFitColumns().
583 int GetColumnFitWidth(wxClientDC
& dc
,
586 bool subProps
) const;
589 Returns information about arbitrary position in the grid.
592 Logical coordinates in the virtual grid space. Use
593 wxScrolled<T>::CalcUnscrolledPosition() if you need to
594 translate a scrolled position into a logical one.
596 wxPropertyGridHitTestResult
HitTest( const wxPoint
& pt
) const;
598 /** Returns true if page is visibly displayed.
600 inline bool IsDisplayed() const;
602 bool IsInNonCatMode() const { return (bool)(m_properties
== m_abcArray
); }
604 void DoLimitPropertyEditing( wxPGProperty
* p
, bool limit
= true )
606 p
->SetFlagRecursively(wxPG_PROP_NOEDITOR
, limit
);
609 bool DoSelectProperty( wxPGProperty
* p
, unsigned int flags
= 0 );
611 /** widthChange is non-client.
613 void OnClientWidthChange( int newWidth
,
615 bool fromOnResize
= false );
617 /** Recalculates m_virtualHeight.
619 void RecalculateVirtualHeight()
621 m_virtualHeight
= GetActualVirtualHeight();
624 void SetColumnCount( int colCount
);
626 void PropagateColSizeDec( int column
, int decrease
, int dir
);
628 bool DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
= wxPG_RECURSE
);
630 bool DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
);
632 bool DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
);
634 bool DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
);
635 void DoSetPropertyValues( const wxVariantList
& list
,
636 wxPGProperty
* default_category
);
638 void SetSplitterLeft( bool subProps
= false );
640 /** Set virtual width for this particular page. */
641 void SetVirtualWidth( int width
);
643 void DoSortChildren( wxPGProperty
* p
, int flags
= 0 );
644 void DoSort( int flags
= 0 );
646 bool PrepareAfterItemsAdded();
648 /** Called after virtual height needs to be recalculated.
650 void VirtualHeightChanged()
656 wxPGProperty
* DoAppend( wxPGProperty
* property
);
658 /** Returns property by its name. */
659 wxPGProperty
* BaseGetPropertyByName( const wxString
& name
) const;
661 /** Called in, for example, wxPropertyGrid::Clear. */
664 bool DoIsPropertySelected( wxPGProperty
* prop
) const;
666 bool DoCollapse( wxPGProperty
* p
);
668 bool DoExpand( wxPGProperty
* p
);
670 void CalculateFontAndBitmapStuff( int vspacing
);
674 // Utility to check if two properties are visibly next to each other
675 bool ArePropertiesAdjacent( wxPGProperty
* prop1
,
677 int iterFlags
= wxPG_ITERATE_VISIBLE
) const;
679 int DoGetSplitterPosition( int splitterIndex
= 0 ) const;
681 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
683 Give pointer to int that receives index to splitter that is at x.
684 @param pSplitterHitOffset
685 Distance from said splitter.
687 int HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const;
689 bool PrepareToAddItem( wxPGProperty
* property
,
690 wxPGProperty
* scheduledParent
);
692 /** If visible, then this is pointer to wxPropertyGrid.
693 This shall *never* be NULL to indicate that this state is not visible.
695 wxPropertyGrid
* m_pPropGrid
;
697 /** Pointer to currently used array. */
698 wxPGProperty
* m_properties
;
700 /** Array for categoric mode. */
701 wxPGRootProperty m_regularArray
;
703 /** Array for root of non-categoric mode. */
704 wxPGRootProperty
* m_abcArray
;
706 /** Dictionary for name-based access. */
707 wxPGHashMapS2P m_dictName
;
709 /** List of column widths (first column does not include margin). */
710 wxArrayInt m_colWidths
;
712 /** List of indices of columns the user can edit by clicking it. */
713 wxArrayInt m_editableColumns
;
715 /** Column proportions */
716 wxArrayInt m_columnProportions
;
720 /** Most recently added category. */
721 wxPropertyCategory
* m_currentCategory
;
723 /** Array of selected property. */
724 wxArrayPGProperty m_selection
;
726 /** Virtual width. */
729 /** Indicates total virtual height of visible properties. */
730 unsigned int m_virtualHeight
;
732 /** 1 if m_lastCaption is also the bottommost caption. */
733 unsigned char m_lastCaptionBottomnest
;
735 /** 1 items appended/inserted, so stuff needs to be done before drawing;
736 If m_virtualHeight == 0, then calcylatey's must be done.
739 unsigned char m_itemsAdded
;
741 /** 1 if any value is modified. */
742 unsigned char m_anyModified
;
744 unsigned char m_vhCalcPending
;
746 /** True if splitter has been pre-set by the application. */
747 bool m_isSplitterPreSet
;
749 /** Used to (temporarily) disable splitter centering. */
750 bool m_dontCenterSplitter
;
753 /** Only inits arrays, doesn't migrate things or such. */
754 void InitNonCatMode();
757 // -----------------------------------------------------------------------
759 #endif // wxUSE_PROPGRID
761 #endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_