]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/propgridpagestate.h
define wxHAS_CONFIG_TEMPLATE_RW if template wxConfig::Read/Write() are available...
[wxWidgets.git] / include / wx / propgrid / propgridpagestate.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/propgrid/propgridpagestate.h
3// Purpose: wxPropertyGridPageState class
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2008-08-24
ea5af9c5 7// RCS-ID: $Id$
1c4293cb
VZ
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROPGRID_PROPGRIDPAGESTATE_H_
13#define _WX_PROPGRID_PROPGRIDPAGESTATE_H_
14
f4bc1aa2
JS
15#if wxUSE_PROPGRID
16
1c4293cb
VZ
17#include "wx/propgrid/property.h"
18
19// -----------------------------------------------------------------------
20
21/** @section propgrid_hittestresult wxPropertyGridHitTestResult
22
23 A return value from wxPropertyGrid::HitTest(),
24 contains all you need to know about an arbitrary location on the grid.
25*/
26struct WXDLLIMPEXP_PROPGRID wxPropertyGridHitTestResult
27{
28 friend class wxPropertyGridPageState;
29public:
30
31 wxPGProperty* GetProperty() const { return property; }
32
33 /** Column. -1 for margin. */
34 int column;
35
36 /** Index of splitter hit, -1 for none. */
37 int splitter;
38
39 /** If splitter hit, offset to that */
40 int splitterHitOffset;
41
42private:
43 /** Property. NULL if empty space below properties was hit */
44 wxPGProperty* property;
45};
46
47// -----------------------------------------------------------------------
48
49#define wxPG_IT_CHILDREN(A) ((A)<<16)
50
51/** @section propgrid_iterator_flags wxPropertyGridIterator Flags
52 @{
53
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
56 will be included.
57*/
58
59enum wxPG_ITERATOR_FLAGS
60{
61
62/**
63 Iterate through 'normal' property items (does not include children of
64 aggregate or hidden items by default).
65*/
66wxPG_ITERATE_PROPERTIES = wxPG_PROP_PROPERTY |
67 wxPG_PROP_MISC_PARENT |
68 wxPG_PROP_AGGREGATE |
69 wxPG_PROP_COLLAPSED |
70 wxPG_IT_CHILDREN(wxPG_PROP_MISC_PARENT) |
71 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY),
72
73/** Iterate children of collapsed parents, and individual items that are hidden.
74*/
75wxPG_ITERATE_HIDDEN = wxPG_PROP_HIDDEN |
76 wxPG_IT_CHILDREN(wxPG_PROP_COLLAPSED),
77
78/**
79 Iterate children of parent that is an aggregate property (ie has fixed
80 children).
81*/
82wxPG_ITERATE_FIXED_CHILDREN = wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE) |
83 wxPG_ITERATE_PROPERTIES,
84
85/** Iterate categories.
86 Note that even without this flag, children of categories are still iterated
87 through.
88*/
89wxPG_ITERATE_CATEGORIES = wxPG_PROP_CATEGORY |
90 wxPG_IT_CHILDREN(wxPG_PROP_CATEGORY) |
91 wxPG_PROP_COLLAPSED,
92
93wxPG_ITERATE_ALL_PARENTS = wxPG_PROP_MISC_PARENT |
94 wxPG_PROP_AGGREGATE |
95 wxPG_PROP_CATEGORY,
96
97wxPG_ITERATE_ALL_PARENTS_RECURSIVELY = wxPG_ITERATE_ALL_PARENTS |
98 wxPG_IT_CHILDREN(
99 wxPG_ITERATE_ALL_PARENTS),
100
101wxPG_ITERATOR_FLAGS_ALL = wxPG_PROP_PROPERTY |
102 wxPG_PROP_MISC_PARENT |
103 wxPG_PROP_AGGREGATE |
104 wxPG_PROP_HIDDEN |
105 wxPG_PROP_CATEGORY |
106 wxPG_PROP_COLLAPSED,
107
108wxPG_ITERATOR_MASK_OP_ITEM = wxPG_ITERATOR_FLAGS_ALL,
109
110// (wxPG_PROP_MISC_PARENT|wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY)
111wxPG_ITERATOR_MASK_OP_PARENT = wxPG_ITERATOR_FLAGS_ALL,
112
113/** Combines all flags needed to iterate through visible properties
114 (ie hidden properties and children of collapsed parents are skipped).
115*/
116wxPG_ITERATE_VISIBLE = wxPG_ITERATE_PROPERTIES |
117 wxPG_PROP_CATEGORY |
118 wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE),
119
120/** Iterate all items.
121*/
122wxPG_ITERATE_ALL = wxPG_ITERATE_VISIBLE |
123 wxPG_ITERATE_HIDDEN,
124
125/** Iterate through individual properties (ie categories and children of
126 aggregate properties are skipped).
127*/
128wxPG_ITERATE_NORMAL = wxPG_ITERATE_PROPERTIES |
129 wxPG_ITERATE_HIDDEN,
130
131/** Default iterator flags.
132*/
133wxPG_ITERATE_DEFAULT = wxPG_ITERATE_NORMAL
134
135};
136
137/** @}
138*/
139
140
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;
146
147
148// Macro to test if children of PWC should be iterated through
149#define wxPG_ITERATOR_PARENTEXMASK_TEST(PWC, PARENTMASK) \
150 ( \
151 !(PWC->GetFlags() & PARENTMASK) && \
152 PWC->GetChildCount() \
153 )
154
155
156// Base for wxPropertyGridIterator classes.
157class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase
158{
159public:
160 wxPropertyGridIteratorBase()
161 {
162 }
163
164 void Assign( const wxPropertyGridIteratorBase& it );
165
166 bool AtEnd() const { return m_property == NULL; }
167
168 /** Get current property.
169 */
170 wxPGProperty* GetProperty() const { return m_property; }
171
172 void Init( wxPropertyGridPageState* state,
173 int flags,
174 wxPGProperty* property,
175 int dir = 1 );
176
177 void Init( wxPropertyGridPageState* state,
178 int flags,
179 int startPos = wxTOP,
180 int dir = 0 );
181
182 /** Iterate to the next property.
183 */
184 void Next( bool iterateChildren = true );
185
186 /** Iterate to the previous property.
187 */
188 void Prev();
189
190 /**
191 Set base parent, ie a property when, in which iteration returns, it
192 ends.
193
194 Default base parent is the root of the used wxPropertyGridPageState.
195 */
196 void SetBaseParent( wxPGProperty* baseParent )
197 { m_baseParent = baseParent; }
198
199protected:
200
201 wxPGProperty* m_property;
202
203private:
204 wxPropertyGridPageState* m_state;
205 wxPGProperty* m_baseParent;
206
207 // Masks are used to quickly exclude items
208 int m_itemExMask;
209 int m_parentExMask;
210};
211
212
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 ); } \
222 CLASS() \
223 : wxPropertyGridIteratorBase() \
224 { \
225 m_property = NULL; \
226 } \
227 CLASS( const CLASS& it ) \
228 : wxPropertyGridIteratorBase( ) \
229 { \
230 Assign(it); \
231 } \
232 ~CLASS() \
233 { \
234 } \
235 const CLASS& operator=( const CLASS& it ) \
236 { \
237 Assign(it); \
238 return *this; \
239 } \
240 CLASS& operator++() { Next(); return *this; } \
241 CLASS operator++(int) { CLASS it=*this;Next();return it; } \
242 CLASS& operator--() { Prev(); return *this; } \
243 CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
244 PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
245 static PROPERTY* OneStep( STATE* state, \
246 int flags = wxPG_ITERATE_DEFAULT, \
247 PROPERTY* property = NULL, \
248 int dir = 1 ) \
249 { \
250 CLASS it( state, flags, property, dir ); \
251 if ( property ) \
252 { \
253 if ( dir == 1 ) it.Next(); \
254 else it.Prev(); \
255 } \
256 return *it; \
257 }
258
259
260/** @class wxPropertyGridIterator
261
262 Preferable way to iterate through contents of wxPropertyGrid,
263 wxPropertyGridManager, and wxPropertyGridPage.
264
265 See wxPropertyGridInterface::GetIterator() for more information about usage.
266
267 @library{wxpropgrid}
268 @category{propgrid}
269*/
270class WXDLLIMPEXP_PROPGRID
271 wxPropertyGridIterator : public wxPropertyGridIteratorBase
272{
273public:
274
275 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator,
276 wxPGProperty,
277 wxPropertyGridPageState)
278
279protected:
280};
281
282
283// Const version of wxPropertyGridIterator.
284class WXDLLIMPEXP_PROPGRID
285 wxPropertyGridConstIterator : public wxPropertyGridIteratorBase
286{
287public:
288 wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator,
289 const wxPGProperty,
290 const wxPropertyGridPageState)
291
1d882226
JS
292 /**
293 Additional copy constructor.
294 */
295 wxPropertyGridConstIterator( const wxPropertyGridIterator& other )
296 {
297 Assign(other);
298 }
299
c724444f
JS
300 /**
301 Additional assignment operator.
302 */
303 const wxPropertyGridConstIterator& operator=( const wxPropertyGridIterator& it )
304 {
305 Assign(it);
306 return *this;
307 }
308
1c4293cb
VZ
309protected:
310};
311
312// -----------------------------------------------------------------------
313
314/** Base class to derive new viterators.
315*/
316class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
317{
318 friend class wxPGVIterator;
319public:
320 wxPGVIteratorBase() { m_refCount = 1; }
321 virtual void Next() = 0;
322 void IncRef()
323 {
324 m_refCount++;
325 }
326 void DecRef()
327 {
328 m_refCount--;
329 if ( m_refCount <= 0 )
330 delete this;
331 }
332protected:
333 virtual ~wxPGVIteratorBase() { }
334
335 wxPropertyGridIterator m_it;
336private:
337 int m_refCount;
338};
339
340/** @class wxPGVIterator
341
342 Abstract implementation of a simple iterator. Can only be used
343 to iterate in forward order, and only through the entire container.
344 Used to have functions dealing with all properties work with both
345 wxPropertyGrid and wxPropertyGridManager.
346*/
347class WXDLLIMPEXP_PROPGRID wxPGVIterator
348{
349public:
350 wxPGVIterator() { m_pIt = NULL; }
351 wxPGVIterator( wxPGVIteratorBase* obj ) { m_pIt = obj; }
352 ~wxPGVIterator() { UnRef(); }
353 void UnRef() { if (m_pIt) m_pIt->DecRef(); }
354 wxPGVIterator( const wxPGVIterator& it )
355 {
356 m_pIt = it.m_pIt;
357 m_pIt->IncRef();
358 }
359#ifndef SWIG
360 const wxPGVIterator& operator=( const wxPGVIterator& it )
361 {
362 UnRef();
363 m_pIt = it.m_pIt;
364 m_pIt->IncRef();
365 return *this;
366 }
367#endif
368 void Next() { m_pIt->Next(); }
369 bool AtEnd() const { return m_pIt->m_it.AtEnd(); }
370 wxPGProperty* GetProperty() const { return m_pIt->m_it.GetProperty(); }
371protected:
372 wxPGVIteratorBase* m_pIt;
373};
374
375// -----------------------------------------------------------------------
376
377#ifndef SWIG
378// We won't need this class from wxPython
379
380/** @class wxPropertyGridPageState
381
382 Contains low-level property page information (properties, column widths,
383 etc) of a single wxPropertyGrid or single wxPropertyGridPage. Generally you
384 should not use this class directly, but instead member functions in
385 wxPropertyGridInterface, wxPropertyGrid, wxPropertyGridPage, and
386 wxPropertyGridManager.
387
388 @remarks
389 - In separate wxPropertyGrid component this class was known as
390 wxPropertyGridState.
391 - Currently this class is not implemented in wxPython.
392
393 @library{wxpropgrid}
394 @category{propgrid}
395*/
396class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
397{
398 friend class wxPGProperty;
399 friend class wxPropertyGrid;
400 friend class wxPGCanvas;
401 friend class wxPropertyGridInterface;
402 friend class wxPropertyGridPage;
403 friend class wxPropertyGridManager;
404public:
405
406 /** Default constructor. */
407 wxPropertyGridPageState();
408
409 /** Destructor. */
410 virtual ~wxPropertyGridPageState();
411
412 /** Makes sure all columns have minimum width.
413 */
414 void CheckColumnWidths( int widthChange = 0 );
415
416 /**
417 Override this member function to add custom behavior on property
418 deletion.
419 */
420 virtual void DoDelete( wxPGProperty* item );
421
422 wxSize DoFitColumns( bool allowGridResize = false );
423
424 wxPGProperty* DoGetItemAtY( int y ) const;
425
426 /**
427 Override this member function to add custom behavior on property
428 insertion.
429 */
430 virtual wxPGProperty* DoInsert( wxPGProperty* parent,
431 int index,
432 wxPGProperty* property );
433
434 /**
435 This needs to be overridden in grid used the manager so that splitter
436 changes can be propagated to other pages.
437 */
438 virtual void DoSetSplitterPosition( int pos,
439 int splitterColumn = 0,
440 bool allPages = false,
441 bool fromAutoCenter = false );
442
443 bool EnableCategories( bool enable );
444
445 /** Make sure virtual height is up-to-date.
446 */
447 void EnsureVirtualHeight()
448 {
449 if ( m_vhCalcPending )
450 {
451 RecalculateVirtualHeight();
452 m_vhCalcPending = 0;
453 }
454 }
455
456 /** Enables or disables given property and its subproperties. */
457 bool DoEnableProperty( wxPGProperty* p, bool enable );
458
459 /** Returns (precalculated) height of contained visible properties.
460 */
461 unsigned int GetVirtualHeight() const
462 {
463 wxASSERT( !m_vhCalcPending );
464 return m_virtualHeight;
465 }
466
467 /** Returns (precalculated) height of contained visible properties.
468 */
469 unsigned int GetVirtualHeight()
470 {
471 EnsureVirtualHeight();
472 return m_virtualHeight;
473 }
474
475 /** Returns actual height of contained visible properties.
476 @remarks
477 Mostly used for internal diagnostic purposes.
478 */
479 inline unsigned int GetActualVirtualHeight() const;
480
481 unsigned int GetColumnCount() const
482 {
68bcfd2c 483 return (unsigned int) m_colWidths.size();
1c4293cb
VZ
484 }
485
486 wxPGProperty* GetSelection() const
487 {
488 return m_selected;
489 }
490
491 int GetColumnMinWidth( int column ) const;
492
493 int GetColumnWidth( unsigned int column ) const
494 {
495 return m_colWidths[column];
496 }
497
498 wxPropertyGrid* GetGrid() const { return m_pPropGrid; }
499
500 /** Returns last item which could be iterated using given flags.
501 @param flags
502 @link iteratorflags List of iterator flags@endlink
503 */
504 wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT );
505
506 const wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT ) const
507 {
508 return ((wxPropertyGridPageState*)this)->GetLastItem(flags);
509 }
510
511 wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
512
513 wxPGProperty* GetPropertyByLabel( const wxString& name,
514 wxPGProperty* parent = NULL ) const;
515
516 wxVariant DoGetPropertyValues( const wxString& listname,
517 wxPGProperty* baseparent,
518 long flags ) const;
519
520 wxPGProperty* DoGetRoot() const { return m_properties; }
521
020b0041
JS
522 void DoSetPropertyName( wxPGProperty* p, const wxString& newName );
523
1c4293cb
VZ
524 // Returns combined width of margin and all the columns
525 int GetVirtualWidth() const
526 {
527 return m_width;
528 }
529
530 /**
531 Returns minimal width for given column so that all images and texts
532 will fit entirely.
533
534 Used by SetSplitterLeft() and DoFitColumns().
535 */
536 int GetColumnFitWidth(wxClientDC& dc,
537 wxPGProperty* pwc,
538 unsigned int col,
539 bool subProps) const;
540
541 /** Returns information about arbitrary position in the grid.
542
543 wxPropertyGridHitTestResult definition:
544 @code
545 struct wxPropertyGridHitTestResult
546 {
547 wxPGProperty* GetProperty() const;
548
549 // column. -1 for margin
550 int column;
551
552 // Index of splitter hit, -1 for none.
553 int splitter;
554
555 // If splitter hit, then offset to that.
556 int splitterHitOffset;
557 };
558 @endcode
559 */
560 wxPropertyGridHitTestResult HitTest( const wxPoint& pt ) const;
561
562 /** Returns true if page is visibly displayed.
563 */
564 inline bool IsDisplayed() const;
565
566 bool IsInNonCatMode() const { return (bool)(m_properties == m_abcArray); }
567
568 /** Only inits arrays, doesn't migrate things or such. */
569 void InitNonCatMode ();
570
571 void DoLimitPropertyEditing( wxPGProperty* p, bool limit = true )
572 {
573 p->SetFlagRecursively(wxPG_PROP_NOEDITOR, limit);
574 }
575
576 bool DoSelectProperty( wxPGProperty* p, unsigned int flags = 0 );
577
578 /** widthChange is non-client.
579 */
580 void OnClientWidthChange( int newWidth,
581 int widthChange,
582 bool fromOnResize = false );
583
584 /** Recalculates m_virtualHeight.
585 */
586 void RecalculateVirtualHeight()
587 {
588 m_virtualHeight = GetActualVirtualHeight();
589 }
590
591 void SetColumnCount( int colCount );
592
593 void PropagateColSizeDec( int column, int decrease, int dir );
594
595 bool DoHideProperty( wxPGProperty* p, bool hide, int flags = wxPG_RECURSE );
596
597 bool DoSetPropertyValueString( wxPGProperty* p, const wxString& value );
598
599 bool DoSetPropertyValue( wxPGProperty* p, wxVariant& value );
600
601 bool DoSetPropertyValueWxObjectPtr( wxPGProperty* p, wxObject* value );
602 void DoSetPropertyValues( const wxVariantList& list,
603 wxPGProperty* default_category );
604
605 void DoSetPropertyValueUnspecified( wxPGProperty* p );
606
607 void SetSplitterLeft( bool subProps = false );
608
609 /** Set virtual width for this particular page. */
610 void SetVirtualWidth( int width );
611
612 void SortChildren( wxPGProperty* p );
613 void Sort();
614
615 void SetSelection( wxPGProperty* p ) { m_selected = p; }
616
617 /** Called after virtual height needs to be recalculated.
618 */
619 void VirtualHeightChanged()
620 {
621 m_vhCalcPending = 1;
622 }
623
624 /** Base append. */
625 wxPGProperty* DoAppend( wxPGProperty* property );
626
627 /** Returns property by its name. */
628 wxPGProperty* BaseGetPropertyByName( const wxString& name ) const;
629
630 void DoClearSelection()
631 {
632 m_selected = NULL;
633 }
634
635 /** Called in, for example, wxPropertyGrid::Clear. */
636 void DoClear();
637
638 bool DoCollapse( wxPGProperty* p );
639
640 bool DoExpand( wxPGProperty* p );
641
642 void CalculateFontAndBitmapStuff( int vspacing );
643
644protected:
645
646 int DoGetSplitterPosition( int splitterIndex = 0 ) const;
647
648 /** Returns column at x coordinate (in GetGrid()->GetPanel()).
649 @param pSplitterHit
650 Give pointer to int that receives index to splitter that is at x.
651 @param pSplitterHitOffset
652 Distance from said splitter.
653 */
654 int HitTestH( int x, int* pSplitterHit, int* pSplitterHitOffset ) const;
655
2fd4a524 656 bool PrepareToAddItem( wxPGProperty* property,
1c4293cb
VZ
657 wxPGProperty* scheduledParent );
658
659 /** If visible, then this is pointer to wxPropertyGrid.
660 This shall *never* be NULL to indicate that this state is not visible.
661 */
662 wxPropertyGrid* m_pPropGrid;
663
664 /** Pointer to currently used array. */
665 wxPGProperty* m_properties;
666
667 /** Array for categoric mode. */
668 wxPGRootProperty m_regularArray;
669
670 /** Array for root of non-categoric mode. */
671 wxPGRootProperty* m_abcArray;
672
673 /** Dictionary for name-based access. */
674 wxPGHashMapS2P m_dictName;
675
676 /** List of column widths (first column does not include margin). */
677 wxArrayInt m_colWidths;
678
679 double m_fSplitterX;
680
681 /** Most recently added category. */
682 wxPropertyCategory* m_currentCategory;
683
684 /** Pointer to selected property. */
685 wxPGProperty* m_selected;
686
687 /** Virtual width. */
688 int m_width;
689
690 /** Indicates total virtual height of visible properties. */
691 unsigned int m_virtualHeight;
692
693 /** 1 if m_lastCaption is also the bottommost caption. */
694 unsigned char m_lastCaptionBottomnest;
695
696 /** 1 items appended/inserted, so stuff needs to be done before drawing;
697 If m_virtualHeight == 0, then calcylatey's must be done.
698 Otherwise just sort.
699 */
700 unsigned char m_itemsAdded;
701
702 /** 1 if any value is modified. */
703 unsigned char m_anyModified;
704
705 unsigned char m_vhCalcPending;
706};
707
708#endif // #ifndef SWIG
709
710// -----------------------------------------------------------------------
711
f4bc1aa2
JS
712#endif // wxUSE_PROPGRID
713
1c4293cb
VZ
714#endif // _WX_PROPGRID_PROPGRIDPAGESTATE_H_
715