1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/propgridpagestate.h
3 // Purpose: wxPropertyGridPageState class
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROPGRID_PROPGRIDPAGESTATE_H_
12 #define _WX_PROPGRID_PROPGRIDPAGESTATE_H_
18 #include "wx/propgrid/property.h"
20 // -----------------------------------------------------------------------
22 /** @section propgrid_hittestresult wxPropertyGridHitTestResult
24 A return value from wxPropertyGrid::HitTest(),
25 contains all you need to know about an arbitrary location on the grid.
27 class WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
29 friend class wxPropertyGridPageState
;
31 wxPropertyGridHitTestResult()
36 m_splitterHitOffset
= 0;
39 ~wxPropertyGridHitTestResult()
44 Returns column hit. -1 for margin.
46 int GetColumn() const { return m_column
; }
49 Returns property hit. NULL if empty space below
50 properties was hit instead.
52 wxPGProperty
* GetProperty() const
58 Returns index of splitter hit, -1 for none.
60 int GetSplitter() const { return m_splitter
; }
63 If splitter hit, then this member function
64 returns offset to the exact splitter position.
66 int GetSplitterHitOffset() const { return m_splitterHitOffset
; }
69 /** Property. NULL if empty space below properties was hit */
70 wxPGProperty
* m_property
;
72 /** Column. -1 for margin. */
75 /** Index of splitter hit, -1 for none. */
78 /** If splitter hit, offset to that */
79 int m_splitterHitOffset
;
82 // -----------------------------------------------------------------------
84 #define wxPG_IT_CHILDREN(A) ((A)<<16)
86 /** @section propgrid_iterator_flags wxPropertyGridIterator Flags
89 NOTES: At lower 16-bits, there are flags to check if item will be included.
90 At higher 16-bits, there are same flags, but to instead check if children
94 enum wxPG_ITERATOR_FLAGS
98 Iterate through 'normal' property items (does not include children of
99 aggregate or hidden items by default).
101 wxPG_ITERATE_PROPERTIES
= wxPG_PROP_PROPERTY
|
102 wxPG_PROP_MISC_PARENT
|
103 wxPG_PROP_AGGREGATE
|
104 wxPG_PROP_COLLAPSED
|
105 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT
) |
106 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
),
108 /** Iterate children of collapsed parents, and individual items that are hidden.
110 wxPG_ITERATE_HIDDEN
= wxPG_PROP_HIDDEN
|
111 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED
),
114 Iterate children of parent that is an aggregate property (ie has fixed
117 wxPG_ITERATE_FIXED_CHILDREN
= wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
) |
118 wxPG_ITERATE_PROPERTIES
,
120 /** Iterate categories.
121 Note that even without this flag, children of categories are still iterated
124 wxPG_ITERATE_CATEGORIES
= wxPG_PROP_CATEGORY
|
125 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
) |
128 wxPG_ITERATE_ALL_PARENTS
= wxPG_PROP_MISC_PARENT
|
129 wxPG_PROP_AGGREGATE
|
132 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
= wxPG_ITERATE_ALL_PARENTS
|
134 wxPG_ITERATE_ALL_PARENTS
),
136 wxPG_ITERATOR_FLAGS_ALL
= wxPG_PROP_PROPERTY
|
137 wxPG_PROP_MISC_PARENT
|
138 wxPG_PROP_AGGREGATE
|
143 wxPG_ITERATOR_MASK_OP_ITEM
= wxPG_ITERATOR_FLAGS_ALL
,
145 // (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
146 wxPG_ITERATOR_MASK_OP_PARENT
= wxPG_ITERATOR_FLAGS_ALL
,
148 /** Combines all flags needed to iterate through visible properties
149 (ie hidden properties and children of collapsed parents are skipped).
151 wxPG_ITERATE_VISIBLE
= wxPG_ITERATE_PROPERTIES
|
153 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
),
155 /** Iterate all items.
157 wxPG_ITERATE_ALL
= wxPG_ITERATE_VISIBLE
|
160 /** Iterate through individual properties (ie categories and children of
161 aggregate properties are skipped).
163 wxPG_ITERATE_NORMAL
= wxPG_ITERATE_PROPERTIES
|
166 /** Default iterator flags.
168 wxPG_ITERATE_DEFAULT
= wxPG_ITERATE_NORMAL
176 #define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \
177 A = (FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \
178 wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF; \
179 B = ((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \
180 wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF;
183 // Macro to test if children of PWC should be iterated through
184 #define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
186 !(PWC->GetFlags() & PARENTMASK) && \
187 PWC->GetChildCount() \
191 // Base for wxPropertyGridIterator classes.
192 class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
195 wxPropertyGridIteratorBase()
199 void Assign( const wxPropertyGridIteratorBase
& it
);
201 bool AtEnd() const { return m_property
== NULL
; }
203 /** Get current property.
205 wxPGProperty
* GetProperty() const { return m_property
; }
207 void Init( wxPropertyGridPageState
* state
,
209 wxPGProperty
* property
,
212 void Init( wxPropertyGridPageState
* state
,
214 int startPos
= wxTOP
,
217 /** Iterate to the next property.
219 void Next( bool iterateChildren
= true );
221 /** Iterate to the previous property.
226 Set base parent, ie a property when, in which iteration returns, it
229 Default base parent is the root of the used wxPropertyGridPageState.
231 void SetBaseParent( wxPGProperty
* baseParent
)
232 { m_baseParent
= baseParent
; }
236 wxPGProperty
* m_property
;
239 wxPropertyGridPageState
* m_state
;
240 wxPGProperty
* m_baseParent
;
242 // Masks are used to quickly exclude items
248 #define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
249 CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
250 PROPERTY* property = NULL, int dir = 1 ) \
251 : wxPropertyGridIteratorBase() \
252 { Init( (wxPropertyGridPageState*)state, flags, \
253 (wxPGProperty*)property, dir ); } \
254 CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
255 : wxPropertyGridIteratorBase() \
256 { Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
258 : wxPropertyGridIteratorBase() \
262 CLASS( const CLASS& it ) \
263 : wxPropertyGridIteratorBase( ) \
270 const CLASS& operator=( const CLASS& it ) \
276 CLASS& operator++() { Next(); return *this; } \
277 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
278 CLASS& operator--() { Prev(); return *this; } \
279 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
280 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
281 static PROPERTY* OneStep( STATE* state, \
282 int flags = wxPG_ITERATE_DEFAULT, \
283 PROPERTY* property = NULL, \
286 CLASS it( state, flags, property, dir ); \
289 if ( dir == 1 ) it.Next(); \
296 /** @class wxPropertyGridIterator
298 Preferable way to iterate through contents of wxPropertyGrid,
299 wxPropertyGridManager, and wxPropertyGridPage.
301 See wxPropertyGridInterface::GetIterator() for more information about usage.
306 class WXDLLIMPEXP_PROPGRID
307 wxPropertyGridIterator
: public wxPropertyGridIteratorBase
311 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator
,
313 wxPropertyGridPageState
)
319 // Const version of wxPropertyGridIterator.
320 class WXDLLIMPEXP_PROPGRID
321 wxPropertyGridConstIterator
: public wxPropertyGridIteratorBase
324 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator
,
326 const wxPropertyGridPageState
)
329 Additional copy constructor.
331 wxPropertyGridConstIterator( const wxPropertyGridIterator
& other
)
337 Additional assignment operator.
339 const wxPropertyGridConstIterator
& operator=( const wxPropertyGridIterator
& it
)
348 // -----------------------------------------------------------------------
350 /** Base class to derive new viterators.
352 class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
: public wxObjectRefData
354 friend class wxPGVIterator
;
356 wxPGVIteratorBase() { }
357 virtual void Next() = 0;
359 virtual ~wxPGVIteratorBase() { }
361 wxPropertyGridIterator m_it
;
364 /** @class wxPGVIterator
366 Abstract implementation of a simple iterator. Can only be used
367 to iterate in forward order, and only through the entire container.
368 Used to have functions dealing with all properties work with both
369 wxPropertyGrid and wxPropertyGridManager.
371 class WXDLLIMPEXP_PROPGRID wxPGVIterator
374 wxPGVIterator() { m_pIt
= NULL
; }
375 wxPGVIterator( wxPGVIteratorBase
* obj
) { m_pIt
= obj
; }
376 ~wxPGVIterator() { UnRef(); }
377 void UnRef() { if (m_pIt
) m_pIt
->DecRef(); }
378 wxPGVIterator( const wxPGVIterator
& it
)
383 const wxPGVIterator
& operator=( const wxPGVIterator
& it
)
393 void Next() { m_pIt
->Next(); }
394 bool AtEnd() const { return m_pIt
->m_it
.AtEnd(); }
395 wxPGProperty
* GetProperty() const { return m_pIt
->m_it
.GetProperty(); }
397 wxPGVIteratorBase
* m_pIt
;
400 // -----------------------------------------------------------------------
402 /** @class wxPropertyGridPageState
404 Contains low-level property page information (properties, column widths,
405 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
406 should not use this class directly, but instead member functions in
407 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
408 wxPropertyGridManager.
411 - In separate wxPropertyGrid component this class was known as
413 - Currently this class is not implemented in wxPython.
418 class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
420 friend class wxPGProperty
;
421 friend class wxPropertyGrid
;
422 friend class wxPGCanvas
;
423 friend class wxPropertyGridInterface
;
424 friend class wxPropertyGridPage
;
425 friend class wxPropertyGridManager
;
428 /** Default constructor. */
429 wxPropertyGridPageState();
432 virtual ~wxPropertyGridPageState();
434 /** Makes sure all columns have minimum width.
436 void CheckColumnWidths( int widthChange
= 0 );
439 Override this member function to add custom behaviour on property
442 virtual void DoDelete( wxPGProperty
* item
, bool doDelete
= true );
444 wxSize
DoFitColumns( bool allowGridResize
= false );
446 wxPGProperty
* DoGetItemAtY( int y
) const;
449 Override this member function to add custom behaviour on property
452 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
454 wxPGProperty
* property
);
457 This needs to be overridden in grid used the manager so that splitter
458 changes can be propagated to other pages.
460 virtual void DoSetSplitterPosition( int pos
,
461 int splitterColumn
= 0,
464 bool EnableCategories( bool enable
);
466 /** Make sure virtual height is up-to-date.
468 void EnsureVirtualHeight()
470 if ( m_vhCalcPending
)
472 RecalculateVirtualHeight();
477 /** Returns (precalculated) height of contained visible properties.
479 unsigned int GetVirtualHeight() const
481 wxASSERT( !m_vhCalcPending
);
482 return m_virtualHeight
;
485 /** Returns (precalculated) height of contained visible properties.
487 unsigned int GetVirtualHeight()
489 EnsureVirtualHeight();
490 return m_virtualHeight
;
493 /** Returns actual height of contained visible properties.
495 Mostly used for internal diagnostic purposes.
497 inline unsigned int GetActualVirtualHeight() const;
499 unsigned int GetColumnCount() const
501 return (unsigned int) m_colWidths
.size();
504 int GetColumnMinWidth( int column
) const;
506 int GetColumnWidth( unsigned int column
) const
508 return m_colWidths
[column
];
511 wxPropertyGrid
* GetGrid() const { return m_pPropGrid
; }
513 /** Returns last item which could be iterated using given flags.
515 @link iteratorflags List of iterator flags@endlink
517 wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
);
519 const wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
) const
521 return ((wxPropertyGridPageState
*)this)->GetLastItem(flags
);
525 Returns currently selected property.
527 wxPGProperty
* GetSelection() const
529 if ( m_selection
.size() == 0 )
531 return m_selection
[0];
534 void DoSetSelection( wxPGProperty
* prop
)
538 m_selection
.push_back(prop
);
541 bool DoClearSelection()
543 return DoSelectProperty(NULL
);
546 void DoRemoveFromSelection( wxPGProperty
* prop
);
548 void DoSetColumnProportion( unsigned int column
, int proportion
);
550 int DoGetColumnProportion( unsigned int column
) const
552 return m_columnProportions
[column
];
555 void ResetColumnSizes( int setSplitterFlags
);
557 wxPropertyCategory
* GetPropertyCategory( const wxPGProperty
* p
) const;
559 wxPGProperty
* GetPropertyByLabel( const wxString
& name
,
560 wxPGProperty
* parent
= NULL
) const;
562 wxVariant
DoGetPropertyValues( const wxString
& listname
,
563 wxPGProperty
* baseparent
,
566 wxPGProperty
* DoGetRoot() const { return m_properties
; }
568 void DoSetPropertyName( wxPGProperty
* p
, const wxString
& newName
);
570 // Returns combined width of margin and all the columns
571 int GetVirtualWidth() const
577 Returns minimal width for given column so that all images and texts
580 Used by SetSplitterLeft() and DoFitColumns().
582 int GetColumnFitWidth(wxClientDC
& dc
,
585 bool subProps
) const;
588 Returns information about arbitrary position in the grid.
591 Logical coordinates in the virtual grid space. Use
592 wxScrolled<T>::CalcUnscrolledPosition() if you need to
593 translate a scrolled position into a logical one.
595 wxPropertyGridHitTestResult
HitTest( const wxPoint
& pt
) const;
597 /** Returns true if page is visibly displayed.
599 inline bool IsDisplayed() const;
601 bool IsInNonCatMode() const { return (bool)(m_properties
== m_abcArray
); }
603 void DoLimitPropertyEditing( wxPGProperty
* p
, bool limit
= true )
605 p
->SetFlagRecursively(wxPG_PROP_NOEDITOR
, limit
);
608 bool DoSelectProperty( wxPGProperty
* p
, unsigned int flags
= 0 );
610 /** widthChange is non-client.
612 void OnClientWidthChange( int newWidth
,
614 bool fromOnResize
= false );
616 /** Recalculates m_virtualHeight.
618 void RecalculateVirtualHeight()
620 m_virtualHeight
= GetActualVirtualHeight();
623 void SetColumnCount( int colCount
);
625 void PropagateColSizeDec( int column
, int decrease
, int dir
);
627 bool DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
= wxPG_RECURSE
);
629 bool DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
);
631 bool DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
);
633 bool DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
);
634 void DoSetPropertyValues( const wxVariantList
& list
,
635 wxPGProperty
* default_category
);
637 void SetSplitterLeft( bool subProps
= false );
639 /** Set virtual width for this particular page. */
640 void SetVirtualWidth( int width
);
642 void DoSortChildren( wxPGProperty
* p
, int flags
= 0 );
643 void DoSort( int flags
= 0 );
645 bool PrepareAfterItemsAdded();
647 /** Called after virtual height needs to be recalculated.
649 void VirtualHeightChanged()
655 wxPGProperty
* DoAppend( wxPGProperty
* property
);
657 /** Returns property by its name. */
658 wxPGProperty
* BaseGetPropertyByName( const wxString
& name
) const;
660 /** Called in, for example, wxPropertyGrid::Clear. */
663 bool DoIsPropertySelected( wxPGProperty
* prop
) const;
665 bool DoCollapse( wxPGProperty
* p
);
667 bool DoExpand( wxPGProperty
* p
);
669 void CalculateFontAndBitmapStuff( int vspacing
);
673 // Utility to check if two properties are visibly next to each other
674 bool ArePropertiesAdjacent( wxPGProperty
* prop1
,
676 int iterFlags
= wxPG_ITERATE_VISIBLE
) const;
678 int DoGetSplitterPosition( int splitterIndex
= 0 ) const;
680 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
682 Give pointer to int that receives index to splitter that is at x.
683 @param pSplitterHitOffset
684 Distance from said splitter.
686 int HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const;
688 bool PrepareToAddItem( wxPGProperty
* property
,
689 wxPGProperty
* scheduledParent
);
691 /** If visible, then this is pointer to wxPropertyGrid.
692 This shall *never* be NULL to indicate that this state is not visible.
694 wxPropertyGrid
* m_pPropGrid
;
696 /** Pointer to currently used array. */
697 wxPGProperty
* m_properties
;
699 /** Array for categoric mode. */
700 wxPGRootProperty m_regularArray
;
702 /** Array for root of non-categoric mode. */
703 wxPGRootProperty
* m_abcArray
;
705 /** Dictionary for name-based access. */
706 wxPGHashMapS2P m_dictName
;
708 /** List of column widths (first column does not include margin). */
709 wxArrayInt m_colWidths
;
711 /** List of indices of columns the user can edit by clicking it. */
712 wxArrayInt m_editableColumns
;
714 /** Column proportions */
715 wxArrayInt m_columnProportions
;
719 /** Most recently added category. */
720 wxPropertyCategory
* m_currentCategory
;
722 /** Array of selected property. */
723 wxArrayPGProperty m_selection
;
725 /** Virtual width. */
728 /** Indicates total virtual height of visible properties. */
729 unsigned int m_virtualHeight
;
731 /** 1 if m_lastCaption is also the bottommost caption. */
732 unsigned char m_lastCaptionBottomnest
;
734 /** 1 items appended/inserted, so stuff needs to be done before drawing;
735 If m_virtualHeight == 0, then calcylatey's must be done.
738 unsigned char m_itemsAdded
;
740 /** 1 if any value is modified. */
741 unsigned char m_anyModified
;
743 unsigned char m_vhCalcPending
;
745 /** True if splitter has been pre-set by the application. */
746 bool m_isSplitterPreSet
;
748 /** Used to (temporarily) disable splitter centering. */
749 bool m_dontCenterSplitter
;
752 /** Only inits arrays, doesn't migrate things or such. */
753 void InitNonCatMode();
756 // -----------------------------------------------------------------------
758 #endif // wxUSE_PROPGRID
760 #endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_