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 class WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
28 friend class wxPropertyGridPageState
;
30 wxPropertyGridHitTestResult()
35 m_splitterHitOffset
= 0;
38 ~wxPropertyGridHitTestResult()
43 Returns column hit. -1 for margin.
45 int GetColumn() const { return m_column
; }
48 Returns property hit. NULL if empty space below
49 properties was hit instead.
51 wxPGProperty
* GetProperty() const
57 Returns index of splitter hit, -1 for none.
59 int GetSplitter() const { return m_splitter
; }
62 If splitter hit, then this member function
63 returns offset to the exact splitter position.
65 int GetSplitterHitOffset() const { return m_splitterHitOffset
; }
68 /** Property. NULL if empty space below properties was hit */
69 wxPGProperty
* m_property
;
71 /** Column. -1 for margin. */
74 /** Index of splitter hit, -1 for none. */
77 /** If splitter hit, offset to that */
78 int m_splitterHitOffset
;
81 // -----------------------------------------------------------------------
83 #define wxPG_IT_CHILDREN(A) ((A)<<16)
85 /** @section propgrid_iterator_flags wxPropertyGridIterator Flags
88 NOTES: At lower 16-bits, there are flags to check if item will be included.
89 At higher 16-bits, there are same flags, but to instead check if children
93 enum wxPG_ITERATOR_FLAGS
97 Iterate through 'normal' property items (does not include children of
98 aggregate or hidden items by default).
100 wxPG_ITERATE_PROPERTIES
= wxPG_PROP_PROPERTY
|
101 wxPG_PROP_MISC_PARENT
|
102 wxPG_PROP_AGGREGATE
|
103 wxPG_PROP_COLLAPSED
|
104 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT
) |
105 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
),
107 /** Iterate children of collapsed parents, and individual items that are hidden.
109 wxPG_ITERATE_HIDDEN
= wxPG_PROP_HIDDEN
|
110 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED
),
113 Iterate children of parent that is an aggregate property (ie has fixed
116 wxPG_ITERATE_FIXED_CHILDREN
= wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
) |
117 wxPG_ITERATE_PROPERTIES
,
119 /** Iterate categories.
120 Note that even without this flag, children of categories are still iterated
123 wxPG_ITERATE_CATEGORIES
= wxPG_PROP_CATEGORY
|
124 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY
) |
127 wxPG_ITERATE_ALL_PARENTS
= wxPG_PROP_MISC_PARENT
|
128 wxPG_PROP_AGGREGATE
|
131 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
= wxPG_ITERATE_ALL_PARENTS
|
133 wxPG_ITERATE_ALL_PARENTS
),
135 wxPG_ITERATOR_FLAGS_ALL
= wxPG_PROP_PROPERTY
|
136 wxPG_PROP_MISC_PARENT
|
137 wxPG_PROP_AGGREGATE
|
142 wxPG_ITERATOR_MASK_OP_ITEM
= wxPG_ITERATOR_FLAGS_ALL
,
144 // (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
145 wxPG_ITERATOR_MASK_OP_PARENT
= wxPG_ITERATOR_FLAGS_ALL
,
147 /** Combines all flags needed to iterate through visible properties
148 (ie hidden properties and children of collapsed parents are skipped).
150 wxPG_ITERATE_VISIBLE
= wxPG_ITERATE_PROPERTIES
|
152 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
),
154 /** Iterate all items.
156 wxPG_ITERATE_ALL
= wxPG_ITERATE_VISIBLE
|
159 /** Iterate through individual properties (ie categories and children of
160 aggregate properties are skipped).
162 wxPG_ITERATE_NORMAL
= wxPG_ITERATE_PROPERTIES
|
165 /** Default iterator flags.
167 wxPG_ITERATE_DEFAULT
= wxPG_ITERATE_NORMAL
175 #define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \
176 A = (FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \
177 wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF; \
178 B = ((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \
179 wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF;
182 // Macro to test if children of PWC should be iterated through
183 #define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
185 !(PWC->GetFlags() & PARENTMASK) && \
186 PWC->GetChildCount() \
190 // Base for wxPropertyGridIterator classes.
191 class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
194 wxPropertyGridIteratorBase()
198 void Assign( const wxPropertyGridIteratorBase
& it
);
200 bool AtEnd() const { return m_property
== NULL
; }
202 /** Get current property.
204 wxPGProperty
* GetProperty() const { return m_property
; }
206 void Init( wxPropertyGridPageState
* state
,
208 wxPGProperty
* property
,
211 void Init( wxPropertyGridPageState
* state
,
213 int startPos
= wxTOP
,
216 /** Iterate to the next property.
218 void Next( bool iterateChildren
= true );
220 /** Iterate to the previous property.
225 Set base parent, ie a property when, in which iteration returns, it
228 Default base parent is the root of the used wxPropertyGridPageState.
230 void SetBaseParent( wxPGProperty
* baseParent
)
231 { m_baseParent
= baseParent
; }
235 wxPGProperty
* m_property
;
238 wxPropertyGridPageState
* m_state
;
239 wxPGProperty
* m_baseParent
;
241 // Masks are used to quickly exclude items
247 #define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
248 CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
249 PROPERTY* property = NULL, int dir = 1 ) \
250 : wxPropertyGridIteratorBase() \
251 { Init( (wxPropertyGridPageState*)state, flags, \
252 (wxPGProperty*)property, dir ); } \
253 CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
254 : wxPropertyGridIteratorBase() \
255 { Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
257 : wxPropertyGridIteratorBase() \
261 CLASS( const CLASS& it ) \
262 : wxPropertyGridIteratorBase( ) \
269 const CLASS& operator=( const CLASS& it ) \
275 CLASS& operator++() { Next(); return *this; } \
276 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
277 CLASS& operator--() { Prev(); return *this; } \
278 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
279 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
280 static PROPERTY* OneStep( STATE* state, \
281 int flags = wxPG_ITERATE_DEFAULT, \
282 PROPERTY* property = NULL, \
285 CLASS it( state, flags, property, dir ); \
288 if ( dir == 1 ) it.Next(); \
295 /** @class wxPropertyGridIterator
297 Preferable way to iterate through contents of wxPropertyGrid,
298 wxPropertyGridManager, and wxPropertyGridPage.
300 See wxPropertyGridInterface::GetIterator() for more information about usage.
305 class WXDLLIMPEXP_PROPGRID
306 wxPropertyGridIterator
: public wxPropertyGridIteratorBase
310 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator
,
312 wxPropertyGridPageState
)
318 // Const version of wxPropertyGridIterator.
319 class WXDLLIMPEXP_PROPGRID
320 wxPropertyGridConstIterator
: public wxPropertyGridIteratorBase
323 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator
,
325 const wxPropertyGridPageState
)
328 Additional copy constructor.
330 wxPropertyGridConstIterator( const wxPropertyGridIterator
& other
)
336 Additional assignment operator.
338 const wxPropertyGridConstIterator
& operator=( const wxPropertyGridIterator
& it
)
347 // -----------------------------------------------------------------------
349 /** Base class to derive new viterators.
351 class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
: public wxObjectRefData
353 friend class wxPGVIterator
;
355 wxPGVIteratorBase() { }
356 virtual void Next() = 0;
358 virtual ~wxPGVIteratorBase() { }
360 wxPropertyGridIterator m_it
;
363 /** @class wxPGVIterator
365 Abstract implementation of a simple iterator. Can only be used
366 to iterate in forward order, and only through the entire container.
367 Used to have functions dealing with all properties work with both
368 wxPropertyGrid and wxPropertyGridManager.
370 class WXDLLIMPEXP_PROPGRID wxPGVIterator
373 wxPGVIterator() { m_pIt
= NULL
; }
374 wxPGVIterator( wxPGVIteratorBase
* obj
) { m_pIt
= obj
; }
375 ~wxPGVIterator() { UnRef(); }
376 void UnRef() { if (m_pIt
) m_pIt
->DecRef(); }
377 wxPGVIterator( const wxPGVIterator
& it
)
383 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 // -----------------------------------------------------------------------
404 // We won't need this class from wxPython
406 /** @class wxPropertyGridPageState
408 Contains low-level property page information (properties, column widths,
409 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
410 should not use this class directly, but instead member functions in
411 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
412 wxPropertyGridManager.
415 - In separate wxPropertyGrid component this class was known as
417 - Currently this class is not implemented in wxPython.
422 class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
424 friend class wxPGProperty
;
425 friend class wxPropertyGrid
;
426 friend class wxPGCanvas
;
427 friend class wxPropertyGridInterface
;
428 friend class wxPropertyGridPage
;
429 friend class wxPropertyGridManager
;
432 /** Default constructor. */
433 wxPropertyGridPageState();
436 virtual ~wxPropertyGridPageState();
438 /** Makes sure all columns have minimum width.
440 void CheckColumnWidths( int widthChange
= 0 );
443 Override this member function to add custom behavior on property
446 virtual void DoDelete( wxPGProperty
* item
, bool doDelete
= true );
448 wxSize
DoFitColumns( bool allowGridResize
= false );
450 wxPGProperty
* DoGetItemAtY( int y
) const;
453 Override this member function to add custom behavior on property
456 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
458 wxPGProperty
* property
);
461 This needs to be overridden in grid used the manager so that splitter
462 changes can be propagated to other pages.
464 virtual void DoSetSplitterPosition( int pos
,
465 int splitterColumn
= 0,
466 bool allPages
= false,
467 bool fromAutoCenter
= false );
469 bool EnableCategories( bool enable
);
471 /** Make sure virtual height is up-to-date.
473 void EnsureVirtualHeight()
475 if ( m_vhCalcPending
)
477 RecalculateVirtualHeight();
482 /** Enables or disables given property and its subproperties. */
483 bool DoEnableProperty( wxPGProperty
* p
, bool enable
);
485 /** Returns (precalculated) height of contained visible properties.
487 unsigned int GetVirtualHeight() const
489 wxASSERT( !m_vhCalcPending
);
490 return m_virtualHeight
;
493 /** Returns (precalculated) height of contained visible properties.
495 unsigned int GetVirtualHeight()
497 EnsureVirtualHeight();
498 return m_virtualHeight
;
501 /** Returns actual height of contained visible properties.
503 Mostly used for internal diagnostic purposes.
505 inline unsigned int GetActualVirtualHeight() const;
507 unsigned int GetColumnCount() const
509 return (unsigned int) m_colWidths
.size();
512 int GetColumnMinWidth( int column
) const;
514 int GetColumnWidth( unsigned int column
) const
516 return m_colWidths
[column
];
519 wxPropertyGrid
* GetGrid() const { return m_pPropGrid
; }
521 /** Returns last item which could be iterated using given flags.
523 @link iteratorflags List of iterator flags@endlink
525 wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
);
527 const wxPGProperty
* GetLastItem( int flags
= wxPG_ITERATE_DEFAULT
) const
529 return ((wxPropertyGridPageState
*)this)->GetLastItem(flags
);
533 Returns currently selected property.
535 wxPGProperty
* GetSelection() const
537 if ( m_selection
.size() == 0 )
539 return m_selection
[0];
542 void DoSetSelection( wxPGProperty
* prop
)
546 m_selection
.push_back(prop
);
549 bool DoClearSelection()
551 return DoSelectProperty(NULL
);
554 void DoRemoveFromSelection( wxPGProperty
* prop
);
556 wxPropertyCategory
* GetPropertyCategory( const wxPGProperty
* p
) const;
558 wxPGProperty
* GetPropertyByLabel( const wxString
& name
,
559 wxPGProperty
* parent
= NULL
) const;
561 wxVariant
DoGetPropertyValues( const wxString
& listname
,
562 wxPGProperty
* baseparent
,
565 wxPGProperty
* DoGetRoot() const { return m_properties
; }
567 void DoSetPropertyName( wxPGProperty
* p
, const wxString
& newName
);
569 // Returns combined width of margin and all the columns
570 int GetVirtualWidth() const
576 Returns minimal width for given column so that all images and texts
579 Used by SetSplitterLeft() and DoFitColumns().
581 int GetColumnFitWidth(wxClientDC
& dc
,
584 bool subProps
) const;
587 Returns information about arbitrary position in the grid.
590 Logical coordinates in the virtual grid space. Use
591 wxScrolledWindow::CalcUnscrolledPosition() if you need to
592 translate a scrolled position into a logical one.
594 wxPropertyGridHitTestResult
HitTest( const wxPoint
& pt
) const;
596 /** Returns true if page is visibly displayed.
598 inline bool IsDisplayed() const;
600 bool IsInNonCatMode() const { return (bool)(m_properties
== m_abcArray
); }
602 void DoLimitPropertyEditing( wxPGProperty
* p
, bool limit
= true )
604 p
->SetFlagRecursively(wxPG_PROP_NOEDITOR
, limit
);
607 bool DoSelectProperty( wxPGProperty
* p
, unsigned int flags
= 0 );
609 /** widthChange is non-client.
611 void OnClientWidthChange( int newWidth
,
613 bool fromOnResize
= false );
615 /** Recalculates m_virtualHeight.
617 void RecalculateVirtualHeight()
619 m_virtualHeight
= GetActualVirtualHeight();
622 void SetColumnCount( int colCount
);
624 void PropagateColSizeDec( int column
, int decrease
, int dir
);
626 bool DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
= wxPG_RECURSE
);
628 bool DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
);
630 bool DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
);
632 bool DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
);
633 void DoSetPropertyValues( const wxVariantList
& list
,
634 wxPGProperty
* default_category
);
636 void SetSplitterLeft( bool subProps
= false );
638 /** Set virtual width for this particular page. */
639 void SetVirtualWidth( int width
);
641 void DoSortChildren( wxPGProperty
* p
, int flags
= 0 );
642 void DoSort( int flags
= 0 );
644 bool PrepareAfterItemsAdded();
646 /** Called after virtual height needs to be recalculated.
648 void VirtualHeightChanged()
654 wxPGProperty
* DoAppend( wxPGProperty
* property
);
656 /** Returns property by its name. */
657 wxPGProperty
* BaseGetPropertyByName( const wxString
& name
) const;
659 /** Called in, for example, wxPropertyGrid::Clear. */
662 bool DoIsPropertySelected( wxPGProperty
* prop
) const;
664 bool DoCollapse( wxPGProperty
* p
);
666 bool DoExpand( wxPGProperty
* p
);
668 void CalculateFontAndBitmapStuff( int vspacing
);
672 // Utility to check if two properties are visibly next to each other
673 bool ArePropertiesAdjacent( wxPGProperty
* prop1
,
675 int iterFlags
= wxPG_ITERATE_VISIBLE
) const;
677 int DoGetSplitterPosition( int splitterIndex
= 0 ) const;
679 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
681 Give pointer to int that receives index to splitter that is at x.
682 @param pSplitterHitOffset
683 Distance from said splitter.
685 int HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const;
687 bool PrepareToAddItem( wxPGProperty
* property
,
688 wxPGProperty
* scheduledParent
);
690 /** If visible, then this is pointer to wxPropertyGrid.
691 This shall *never* be NULL to indicate that this state is not visible.
693 wxPropertyGrid
* m_pPropGrid
;
695 /** Pointer to currently used array. */
696 wxPGProperty
* m_properties
;
698 /** Array for categoric mode. */
699 wxPGRootProperty m_regularArray
;
701 /** Array for root of non-categoric mode. */
702 wxPGRootProperty
* m_abcArray
;
704 /** Dictionary for name-based access. */
705 wxPGHashMapS2P m_dictName
;
707 /** List of column widths (first column does not include margin). */
708 wxArrayInt m_colWidths
;
710 /** List of indices of columns the user can edit by clicking it. */
711 wxArrayInt m_editableColumns
;
715 /** Most recently added category. */
716 wxPropertyCategory
* m_currentCategory
;
718 /** Array of selected property. */
719 wxArrayPGProperty m_selection
;
721 /** Virtual width. */
724 /** Indicates total virtual height of visible properties. */
725 unsigned int m_virtualHeight
;
727 /** 1 if m_lastCaption is also the bottommost caption. */
728 unsigned char m_lastCaptionBottomnest
;
730 /** 1 items appended/inserted, so stuff needs to be done before drawing;
731 If m_virtualHeight == 0, then calcylatey's must be done.
734 unsigned char m_itemsAdded
;
736 /** 1 if any value is modified. */
737 unsigned char m_anyModified
;
739 unsigned char m_vhCalcPending
;
741 /** True if splitter has been pre-set by the application. */
742 bool m_isSplitterPreSet
;
744 /** Used to (temporarily) disable splitter centering. */
745 bool m_dontCenterSplitter
;
748 /** Only inits arrays, doesn't migrate things or such. */
749 void InitNonCatMode();
752 #endif // #ifndef SWIG
754 // -----------------------------------------------------------------------
756 #endif // wxUSE_PROPGRID
758 #endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_