1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgridpagestate.cpp
3 // Purpose: wxPropertyGridPageState class
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
22 #include "wx/object.h"
24 #include "wx/string.h"
27 #include "wx/window.h"
30 #include "wx/dcmemory.h"
34 #include "wx/stopwatch.h"
37 // This define is necessary to prevent macro clearing
38 #define __wxPG_SOURCE_FILE__
40 #include "wx/propgrid/propgridpagestate.h"
41 #include "wx/propgrid/propgrid.h"
42 #include "wx/propgrid/editors.h"
44 #define wxPG_DEFAULT_SPLITTERX 110
47 // -----------------------------------------------------------------------
48 // wxPropertyGridIterator
49 // -----------------------------------------------------------------------
51 void wxPropertyGridIteratorBase::Init( wxPropertyGridPageState
* state
, int flags
, wxPGProperty
* property
, int dir
)
53 wxASSERT( dir
== 1 || dir
== -1 );
56 m_baseParent
= state
->DoGetRoot();
57 if ( !property
&& m_baseParent
->GetChildCount() )
58 property
= m_baseParent
->Item(0);
60 m_property
= property
;
62 wxPG_ITERATOR_CREATE_MASKS(flags
, m_itemExMask
, m_parentExMask
)
64 // Need to skip first?
65 if ( property
&& (property
->GetFlags() & m_itemExMask
) )
74 void wxPropertyGridIteratorBase::Init( wxPropertyGridPageState
* state
, int flags
, int startPos
, int dir
)
76 wxPGProperty
* property
= NULL
;
78 if ( startPos
== wxTOP
)
83 else if ( startPos
== wxBOTTOM
)
85 property
= state
->GetLastItem(flags
);
91 wxFAIL_MSG("Only supported starting positions are wxTOP and wxBOTTOM");
94 Init( state
, flags
, property
, dir
);
97 void wxPropertyGridIteratorBase::Assign( const wxPropertyGridIteratorBase
& it
)
99 m_property
= it
.m_property
;
100 m_state
= it
.m_state
;
101 m_baseParent
= it
.m_baseParent
;
102 m_itemExMask
= it
.m_itemExMask
;
103 m_parentExMask
= it
.m_parentExMask
;
106 void wxPropertyGridIteratorBase::Prev()
108 wxPGProperty
* property
= m_property
;
112 wxPGProperty
* parent
= property
->GetParent();
114 unsigned int index
= property
->GetIndexInParent();
121 property
= parent
->Item(index
);
123 // Go to last children?
124 if ( property
->GetChildCount() &&
125 wxPG_ITERATOR_PARENTEXMASK_TEST(property
, m_parentExMask
) )
128 property
= property
->Last();
134 if ( parent
== m_baseParent
)
145 m_property
= property
;
147 // If property does not match our criteria, skip it
148 if ( property
->GetFlags() & m_itemExMask
)
152 void wxPropertyGridIteratorBase::Next( bool iterateChildren
)
154 wxPGProperty
* property
= m_property
;
158 if ( property
->GetChildCount() &&
159 wxPG_ITERATOR_PARENTEXMASK_TEST(property
, m_parentExMask
) &&
163 property
= property
->Item(0);
167 wxPGProperty
* parent
= property
->GetParent();
169 unsigned int index
= property
->GetIndexInParent() + 1;
171 if ( index
< parent
->GetChildCount() )
174 property
= parent
->Item(index
);
178 // Next sibling of parent
179 if ( parent
== m_baseParent
)
192 m_property
= property
;
194 // If property does not match our criteria, skip it
195 if ( property
->GetFlags() & m_itemExMask
)
199 // -----------------------------------------------------------------------
200 // wxPropertyGridPageState
201 // -----------------------------------------------------------------------
203 wxPropertyGridPageState::wxPropertyGridPageState()
206 m_regularArray
.SetParentState(this);
207 m_properties
= &m_regularArray
;
209 m_currentCategory
= NULL
;
212 m_lastCaptionBottomnest
= 1;
216 m_colWidths
.push_back( wxPG_DEFAULT_SPLITTERX
);
217 m_colWidths
.push_back( wxPG_DEFAULT_SPLITTERX
);
218 m_fSplitterX
= wxPG_DEFAULT_SPLITTERX
;
220 m_columnProportions
.push_back(1);
221 m_columnProportions
.push_back(1);
223 m_isSplitterPreSet
= false;
224 m_dontCenterSplitter
= false;
226 // By default, we only have the 'value' column editable
227 m_editableColumns
.push_back(1);
230 // -----------------------------------------------------------------------
232 wxPropertyGridPageState::~wxPropertyGridPageState()
237 // -----------------------------------------------------------------------
239 void wxPropertyGridPageState::InitNonCatMode()
243 m_abcArray
= new wxPGRootProperty(wxS("<Root_NonCat>"));
244 m_abcArray
->SetParentState(this);
245 m_abcArray
->SetFlag(wxPG_PROP_CHILDREN_ARE_COPIES
);
248 // Must be called when state::m_properties still points to regularArray.
249 wxPGProperty
* oldProperties
= m_properties
;
251 // Must use temp value in state::m_properties for item iteration loop
252 // to run as expected.
253 m_properties
= &m_regularArray
;
255 if ( m_properties
->GetChildCount() )
258 // Prepare m_abcArray
259 wxPropertyGridIterator
it( this, wxPG_ITERATE_PROPERTIES
);
261 for ( ; !it
.AtEnd(); it
.Next() )
263 wxPGProperty
* p
= it
.GetProperty();
264 wxPGProperty
* parent
= p
->GetParent();
265 if ( parent
->IsCategory() || parent
->IsRoot() )
267 m_abcArray
->DoAddChild(p
);
268 p
->m_parent
= &m_regularArray
;
273 m_properties
= oldProperties
;
276 // -----------------------------------------------------------------------
278 void wxPropertyGridPageState::DoClear()
280 if ( m_pPropGrid
&& m_pPropGrid
->GetState() == this )
282 m_pPropGrid
->ClearSelection(false);
289 m_regularArray
.Empty();
295 m_currentCategory
= NULL
;
296 m_lastCaptionBottomnest
= 1;
303 // -----------------------------------------------------------------------
305 void wxPropertyGridPageState::CalculateFontAndBitmapStuff( int WXUNUSED(vspacing
) )
307 wxPropertyGrid
* propGrid
= GetGrid();
309 VirtualHeightChanged();
311 // Recalculate caption text extents.
314 for ( i
=0;i
<m_regularArray
.GetChildCount();i
++ )
316 wxPGProperty
* p
=m_regularArray
.Item(i
);
318 if ( p
->IsCategory() )
319 ((wxPropertyCategory
*)p
)->CalculateTextExtent(propGrid
, propGrid
->GetCaptionFont());
323 // -----------------------------------------------------------------------
325 void wxPropertyGridPageState::SetVirtualWidth( int width
)
327 // Sometimes width less than 0 is offered. Let's make things easy for
328 // everybody and deal with it here.
332 wxPropertyGrid
* pg
= GetGrid();
333 int gw
= pg
->GetClientSize().x
;
340 // -----------------------------------------------------------------------
342 void wxPropertyGridPageState::OnClientWidthChange( int newWidth
, int widthChange
, bool fromOnResize
)
344 wxPropertyGrid
* pg
= GetGrid();
346 if ( pg
->HasVirtualWidth() )
348 if ( m_width
< newWidth
)
349 SetVirtualWidth( newWidth
);
351 CheckColumnWidths(widthChange
);
355 SetVirtualWidth( newWidth
);
357 // This should be done before splitter auto centering
358 // NOTE: Splitter auto-centering is done in this function.
361 CheckColumnWidths(widthChange
);
363 if ( !m_isSplitterPreSet
&& m_dontCenterSplitter
)
365 long timeSinceCreation
= (::wxGetLocalTimeMillis() - GetGrid()->m_timeCreated
).ToLong();
367 // If too long, don't set splitter
368 if ( timeSinceCreation
< 250 )
370 if ( m_properties
->GetChildCount() )
372 SetSplitterLeft( false );
376 DoSetSplitterPosition( newWidth
/ 2 );
377 m_isSplitterPreSet
= false;
384 // -----------------------------------------------------------------------
385 // wxPropertyGridPageState item iteration methods
386 // -----------------------------------------------------------------------
388 wxPGProperty
* wxPropertyGridPageState::GetLastItem( int flags
)
390 if ( !m_properties
->GetChildCount() )
393 wxPG_ITERATOR_CREATE_MASKS(flags
, int itemExMask
, int parentExMask
)
395 // First, get last child of last parent
396 wxPGProperty
* pwc
= (wxPGProperty
*)m_properties
->Last();
397 while ( pwc
->GetChildCount() &&
398 wxPG_ITERATOR_PARENTEXMASK_TEST(pwc
, parentExMask
) )
399 pwc
= (wxPGProperty
*) pwc
->Last();
401 // Then, if it doesn't fit our criteria, back up until we find something that does
402 if ( pwc
->GetFlags() & itemExMask
)
404 wxPropertyGridIterator
it( this, flags
, pwc
);
405 for ( ; !it
.AtEnd(); it
.Prev() )
407 pwc
= (wxPGProperty
*) it
.GetProperty();
413 wxPropertyCategory
* wxPropertyGridPageState::GetPropertyCategory( const wxPGProperty
* p
) const
415 const wxPGProperty
* parent
= (const wxPGProperty
*)p
;
416 const wxPGProperty
* grandparent
= (const wxPGProperty
*)parent
->GetParent();
419 parent
= grandparent
;
420 grandparent
= (wxPGProperty
*)parent
->GetParent();
421 if ( parent
->IsCategory() && grandparent
)
422 return (wxPropertyCategory
*)parent
;
423 } while ( grandparent
);
428 // -----------------------------------------------------------------------
429 // wxPropertyGridPageState GetPropertyXXX methods
430 // -----------------------------------------------------------------------
432 wxPGProperty
* wxPropertyGridPageState::GetPropertyByLabel( const wxString
& label
,
433 wxPGProperty
* parent
) const
438 if ( !parent
) parent
= (wxPGProperty
*) &m_regularArray
;
440 for ( i
=0; i
<parent
->GetChildCount(); i
++ )
442 wxPGProperty
* p
= parent
->Item(i
);
443 if ( p
->m_label
== label
)
445 // Check children recursively.
446 if ( p
->GetChildCount() )
448 p
= GetPropertyByLabel(label
,(wxPGProperty
*)p
);
457 // -----------------------------------------------------------------------
459 wxPGProperty
* wxPropertyGridPageState::BaseGetPropertyByName( const wxString
& name
) const
461 wxPGHashMapS2P::const_iterator it
;
462 it
= m_dictName
.find(name
);
463 if ( it
!= m_dictName
.end() )
464 return (wxPGProperty
*) it
->second
;
468 // -----------------------------------------------------------------------
470 void wxPropertyGridPageState::DoSetPropertyName( wxPGProperty
* p
,
471 const wxString
& newName
)
473 wxCHECK_RET( p
, wxT("invalid property id") );
475 wxPGProperty
* parent
= p
->GetParent();
477 if ( parent
->IsCategory() || parent
->IsRoot() )
479 if ( !p
->GetBaseName().empty() )
480 m_dictName
.erase( p
->GetBaseName() );
481 if ( !newName
.empty() )
482 m_dictName
[newName
] = (void*) p
;
485 p
->DoSetName(newName
);
488 // -----------------------------------------------------------------------
489 // wxPropertyGridPageState global operations
490 // -----------------------------------------------------------------------
492 // -----------------------------------------------------------------------
493 // Item iteration macros
494 // NB: Nowadays only needed for alphabetic/categoric mode switching.
495 // -----------------------------------------------------------------------
497 //#define II_INVALID_I 0x00FFFFFF
499 #define ITEM_ITERATION_VARIABLES \
500 wxPGProperty* parent; \
504 #define ITEM_ITERATION_INIT_FROM_THE_TOP \
505 parent = m_properties; \
509 #define ITEM_ITERATION_INIT(startparent, startindex, state) \
510 parent = startparent; \
511 i = (unsigned int)startindex; \
512 if ( parent == NULL ) \
514 parent = state->m_properties; \
519 #define ITEM_ITERATION_LOOP_BEGIN \
522 iMax = parent->GetChildCount(); \
525 wxPGProperty* p = parent->Item(i);
527 #define ITEM_ITERATION_LOOP_END \
528 if ( p->GetChildCount() ) \
531 parent = (wxPGProperty*)p; \
532 iMax = parent->GetChildCount(); \
537 i = parent->m_arrIndex + 1; \
538 parent = parent->m_parent; \
540 while ( parent != NULL );
542 bool wxPropertyGridPageState::EnableCategories( bool enable
)
545 // NB: We can't use wxPropertyGridIterator in this
546 // function, since it depends on m_arrIndexes,
547 // which, among other things, is being fixed here.
549 ITEM_ITERATION_VARIABLES
557 if ( !IsInNonCatMode() )
560 m_properties
= &m_regularArray
;
562 // fix parents, indexes, and depths
563 ITEM_ITERATION_INIT_FROM_THE_TOP
565 ITEM_ITERATION_LOOP_BEGIN
569 p
->m_parent
= parent
;
571 // If parent was category, and this is not,
572 // then the depth stays the same.
573 if ( parent
->IsCategory() &&
575 p
->m_depth
= parent
->m_depth
;
577 p
->m_depth
= parent
->m_depth
+ 1;
579 ITEM_ITERATION_LOOP_END
585 // Disable categories
588 if ( IsInNonCatMode() )
591 // Create array, if necessary.
595 m_properties
= m_abcArray
;
597 // fix parents, indexes, and depths
598 ITEM_ITERATION_INIT_FROM_THE_TOP
600 ITEM_ITERATION_LOOP_BEGIN
604 p
->m_parent
= parent
;
606 p
->m_depth
= parent
->m_depth
+ 1;
608 ITEM_ITERATION_LOOP_END
611 VirtualHeightChanged();
613 if ( m_pPropGrid
->GetState() == this )
614 m_pPropGrid
->RecalculateVirtualSize();
619 // -----------------------------------------------------------------------
621 static int wxPG_SortFunc_ByFunction(wxPGProperty
**pp1
, wxPGProperty
**pp2
)
623 wxPGProperty
*p1
= *pp1
;
624 wxPGProperty
*p2
= *pp2
;
625 wxPropertyGrid
* pg
= p1
->GetGrid();
626 wxPGSortCallback sortFunction
= pg
->GetSortFunction();
627 return sortFunction(pg
, p1
, p2
);
630 static int wxPG_SortFunc_ByLabel(wxPGProperty
**pp1
, wxPGProperty
**pp2
)
632 wxPGProperty
*p1
= *pp1
;
633 wxPGProperty
*p2
= *pp2
;
634 return p1
->GetLabel().CmpNoCase( p2
->GetLabel() );
639 // For wxVector w/ wxUSE_STL=1, you would use code like this instead:
644 static bool wxPG_SortFunc_ByFunction(wxPGProperty
*p1
, wxPGProperty
*p2
)
646 wxPropertyGrid
* pg
= p1
->GetGrid();
647 wxPGSortCallback sortFunction
= pg
->GetSortFunction();
648 return sortFunction(pg
, p1
, p2
) < 0;
651 static bool wxPG_SortFunc_ByLabel(wxPGProperty
*p1
, wxPGProperty
*p2
)
653 return p1
->GetLabel().CmpNoCase( p2
->GetLabel() ) < 0;
657 void wxPropertyGridPageState::DoSortChildren( wxPGProperty
* p
,
663 // Can only sort items with children
664 if ( !p
->GetChildCount() )
667 // Never sort children of aggregate properties
668 if ( p
->HasFlag(wxPG_PROP_AGGREGATE
) )
671 if ( (flags
& wxPG_SORT_TOP_LEVEL_ONLY
)
672 && !p
->IsCategory() && !p
->IsRoot() )
675 if ( GetGrid()->GetSortFunction() )
676 p
->m_children
.Sort( wxPG_SortFunc_ByFunction
);
678 p
->m_children
.Sort( wxPG_SortFunc_ByLabel
);
682 // For wxVector w/ wxUSE_STL=1, you would use code like this instead:
684 if ( GetGrid()->GetSortFunction() )
685 std::sort(p
->m_children
.begin(), p
->m_children
.end(),
686 wxPG_SortFunc_ByFunction
);
688 std::sort(p
->m_children
.begin(), p
->m_children
.end(),
689 wxPG_SortFunc_ByLabel
);
693 p
->FixIndicesOfChildren();
695 if ( flags
& wxPG_RECURSE
)
697 // Apply sort recursively
698 for ( unsigned int i
=0; i
<p
->GetChildCount(); i
++ )
699 DoSortChildren(p
->Item(i
), flags
);
703 // -----------------------------------------------------------------------
705 void wxPropertyGridPageState::DoSort( int flags
)
707 DoSortChildren( m_properties
, flags
| wxPG_RECURSE
);
709 // We used to sort categories as well here also if in non-categorized
710 // mode, but doing would naturally cause child indices to become
714 // -----------------------------------------------------------------------
716 bool wxPropertyGridPageState::PrepareAfterItemsAdded()
718 if ( !m_itemsAdded
) return false;
720 wxPropertyGrid
* pg
= GetGrid();
724 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
725 DoSort(wxPG_SORT_TOP_LEVEL_ONLY
);
730 // -----------------------------------------------------------------------
731 // wxPropertyGridPageState splitter, column and hittest functions
732 // -----------------------------------------------------------------------
734 wxPGProperty
* wxPropertyGridPageState::DoGetItemAtY( int y
) const
741 return m_properties
->GetItemAtY(y
, GetGrid()->m_lineHeight
, &a
);
744 // -----------------------------------------------------------------------
746 wxPropertyGridHitTestResult
747 wxPropertyGridPageState::HitTest( const wxPoint
&pt
) const
749 wxPropertyGridHitTestResult result
;
750 result
.m_column
= HitTestH( pt
.x
, &result
.m_splitter
,
751 &result
.m_splitterHitOffset
);
752 result
.m_property
= DoGetItemAtY( pt
.y
);
756 // -----------------------------------------------------------------------
758 // Used by SetSplitterLeft() and DotFitColumns()
759 int wxPropertyGridPageState::GetColumnFitWidth(wxClientDC
& dc
,
764 wxPropertyGrid
* pg
= m_pPropGrid
;
769 for ( i
=0; i
<pwc
->GetChildCount(); i
++ )
771 wxPGProperty
* p
= pwc
->Item(i
);
772 if ( !p
->IsCategory() )
774 const wxPGCell
* cell
= NULL
;
776 p
->GetDisplayInfo(col
, -1, 0, &text
, &cell
);
777 dc
.GetTextExtent(text
, &w
, &h
);
779 w
+= ( ((int)p
->m_depth
-1) * pg
->m_subgroup_extramargin
);
781 // account for the bitmap
783 w
+= p
->GetImageOffset(pg
->GetImageRect(p
, -1).GetWidth());
786 w
+= (wxPG_XBEFORETEXT
*2);
792 if ( p
->GetChildCount() &&
793 ( subProps
|| p
->IsCategory() ) )
795 w
= GetColumnFitWidth( dc
, p
, col
, subProps
);
805 int wxPropertyGridPageState::GetColumnFullWidth( wxClientDC
&dc
, wxPGProperty
*p
, unsigned int col
)
807 if ( p
->IsCategory() )
810 const wxPGCell
* cell
= NULL
;
812 p
->GetDisplayInfo(col
, -1, 0, &text
, &cell
);
813 int w
= dc
.GetTextExtent(text
).x
;
816 w
+= (int)p
->m_depth
* m_pPropGrid
->m_subgroup_extramargin
;
818 // account for the bitmap
820 w
+= p
->GetImageOffset(m_pPropGrid
->GetImageRect(p
, -1).GetWidth());
822 w
+= (wxPG_XBEFORETEXT
*2);
826 int wxPropertyGridPageState::DoGetSplitterPosition( int splitterColumn
) const
828 int n
= GetGrid()->m_marginWidth
;
830 for ( i
=0; i
<=splitterColumn
; i
++ )
835 int wxPropertyGridPageState::GetColumnMinWidth( int WXUNUSED(column
) ) const
837 return wxPG_DRAG_MARGIN
;
840 void wxPropertyGridPageState::PropagateColSizeDec( int column
,
844 int origWidth
= m_colWidths
[column
];
845 m_colWidths
[column
] -= decrease
;
846 int min
= GetColumnMinWidth(column
);
848 if ( m_colWidths
[column
] < min
)
850 more
= decrease
- (origWidth
- min
);
851 m_colWidths
[column
] = min
;
855 // FIXME: Causes erratic splitter changing, so as a workaround
856 // disabled if two or less columns.
858 if ( m_colWidths
.size() <= 2 )
862 if ( more
&& column
< (int)m_colWidths
.size() && column
>= 0 )
863 PropagateColSizeDec( column
, more
, dir
);
866 void wxPropertyGridPageState::DoSetSplitterPosition( int newXPos
,
870 wxPropertyGrid
* pg
= GetGrid();
872 int adjust
= newXPos
- DoGetSplitterPosition(splitterColumn
);
874 if ( !pg
->HasVirtualWidth() )
880 otherColumn
= splitterColumn
+ 1;
881 if ( otherColumn
== (int)m_colWidths
.size() )
883 m_colWidths
[splitterColumn
] += adjust
;
884 PropagateColSizeDec( otherColumn
, adjust
, 1 );
888 otherColumn
= splitterColumn
+ 1;
889 if ( otherColumn
== (int)m_colWidths
.size() )
891 m_colWidths
[otherColumn
] -= adjust
;
892 PropagateColSizeDec( splitterColumn
, -adjust
, -1 );
897 m_colWidths
[splitterColumn
] += adjust
;
900 if ( splitterColumn
== 0 )
901 m_fSplitterX
= (double) newXPos
;
903 if ( !(flags
& wxPG_SPLITTER_FROM_AUTO_CENTER
) &&
904 !(flags
& wxPG_SPLITTER_FROM_EVENT
) )
906 // Don't allow initial splitter auto-positioning after this.
907 m_isSplitterPreSet
= true;
913 // Moves splitter so that all labels are visible, but just.
914 void wxPropertyGridPageState::SetSplitterLeft( bool subProps
)
916 wxPropertyGrid
* pg
= GetGrid();
918 dc
.SetFont(pg
->GetFont());
920 int maxW
= GetColumnFitWidth(dc
, m_properties
, 0, subProps
);
924 maxW
+= pg
->m_marginWidth
;
925 DoSetSplitterPosition( maxW
);
928 m_dontCenterSplitter
= true;
931 wxSize
wxPropertyGridPageState::DoFitColumns( bool WXUNUSED(allowGridResize
) )
933 wxPropertyGrid
* pg
= GetGrid();
935 dc
.SetFont(pg
->GetFont());
937 int marginWidth
= pg
->m_marginWidth
;
938 int accWid
= marginWidth
;
939 int maxColWidth
= 500;
941 for ( unsigned int col
=0; col
< GetColumnCount(); col
++ )
943 int fitWid
= GetColumnFitWidth(dc
, m_properties
, col
, true);
944 int colMinWidth
= GetColumnMinWidth(col
);
945 if ( fitWid
< colMinWidth
)
946 fitWid
= colMinWidth
;
947 else if ( fitWid
> maxColWidth
)
948 fitWid
= maxColWidth
;
950 m_colWidths
[col
] = fitWid
;
955 // Expand last one to fill the width
956 int remaining
= m_width
- accWid
;
957 m_colWidths
[GetColumnCount()-1] += remaining
;
959 m_dontCenterSplitter
= true;
961 int firstSplitterX
= marginWidth
+ m_colWidths
[0];
962 m_fSplitterX
= (double) firstSplitterX
;
964 // Don't allow initial splitter auto-positioning after this.
965 if ( pg
->GetState() == this )
967 pg
->SetSplitterPosition(firstSplitterX
, false);
972 pg
->GetVirtualSize(&x
, &y
);
974 return wxSize(accWid
, y
);
977 void wxPropertyGridPageState::CheckColumnWidths( int widthChange
)
982 wxPropertyGrid
* pg
= GetGrid();
985 unsigned int lastColumn
= m_colWidths
.size() - 1;
987 int clientWidth
= pg
->GetClientSize().x
;
990 // Column to reduce, if needed. Take last one that exceeds minimum width.
993 wxLogTrace("propgrid",
994 wxS("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"),
999 for ( i
=0; i
<m_colWidths
.size(); i
++ )
1001 int min
= GetColumnMinWidth(i
);
1002 if ( m_colWidths
[i
] <= min
)
1004 m_colWidths
[i
] = min
;
1008 // Always reduce the last column that is larger than minimum size
1009 // (looks nicer, even with auto-centering enabled).
1014 int colsWidth
= pg
->m_marginWidth
;
1015 for ( i
=0; i
<m_colWidths
.size(); i
++ )
1016 colsWidth
+= m_colWidths
[i
];
1018 wxLogTrace("propgrid",
1019 wxS(" HasVirtualWidth: %i colsWidth: %i"),
1020 (int)pg
->HasVirtualWidth(), colsWidth
);
1022 // Then mode-based requirement
1023 if ( !pg
->HasVirtualWidth() )
1025 int widthHigher
= width
- colsWidth
;
1027 // Adapt colsWidth to width
1028 if ( colsWidth
< width
)
1031 wxLogTrace("propgrid",
1032 wxS(" Adjust last column to %i"),
1033 m_colWidths
[lastColumn
] + widthHigher
);
1034 m_colWidths
[lastColumn
] = m_colWidths
[lastColumn
] + widthHigher
;
1036 else if ( colsWidth
> width
)
1039 if ( reduceCol
!= -1 )
1041 wxLogTrace("propgrid",
1042 wxT(" Reduce column %i (by %i)"),
1043 reduceCol
, -widthHigher
);
1045 // Reduce widest column, and recheck
1046 m_colWidths
[reduceCol
] = m_colWidths
[reduceCol
] + widthHigher
;
1047 CheckColumnWidths();
1053 // Only check colsWidth against clientWidth
1054 if ( colsWidth
< clientWidth
)
1056 m_colWidths
[lastColumn
] = m_colWidths
[lastColumn
] + (clientWidth
-colsWidth
);
1059 m_width
= colsWidth
;
1061 // If width changed, recalculate virtual size
1062 if ( pg
->GetState() == this )
1063 pg
->RecalculateVirtualSize();
1066 for ( i
=0; i
<m_colWidths
.size(); i
++ )
1068 wxLogTrace("propgrid", wxS("col%i: %i"), i
, m_colWidths
[i
]);
1071 // Auto center splitter
1072 if ( !m_dontCenterSplitter
)
1074 if ( m_colWidths
.size() == 2 &&
1075 m_columnProportions
[0] == m_columnProportions
[1] )
1078 // When we have two columns of equal proportion, then use this
1079 // code. It will look nicer when the scrollbar visibility is
1080 // toggled on and off.
1082 // TODO: Adapt this to generic recenter code.
1084 float centerX
= (float)(pg
->m_width
/2);
1087 if ( m_fSplitterX
< 0.0 )
1089 splitterX
= centerX
;
1091 else if ( widthChange
)
1093 //float centerX = float(pg->GetSize().x) * 0.5;
1096 splitterX
= m_fSplitterX
+ (float(widthChange
) * 0.5);
1097 float deviation
= fabs(centerX
- splitterX
);
1099 // If deviating from center, adjust towards it
1100 if ( deviation
> 20.0 )
1102 if ( splitterX
> centerX
)
1110 // No width change, just keep sure we keep splitter position intact
1111 splitterX
= m_fSplitterX
;
1112 float deviation
= fabs(centerX
- splitterX
);
1113 if ( deviation
> 50.0 )
1115 splitterX
= centerX
;
1119 DoSetSplitterPosition((int)splitterX
, 0,
1120 wxPG_SPLITTER_FROM_AUTO_CENTER
);
1122 m_fSplitterX
= splitterX
; // needed to retain accuracy
1127 // Generic re-center code
1129 ResetColumnSizes(wxPG_SPLITTER_FROM_AUTO_CENTER
);
1134 void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags
)
1137 // Calculate sum of proportions
1139 for ( i
=0; i
<m_colWidths
.size(); i
++ )
1140 psum
+= m_columnProportions
[i
];
1141 int puwid
= (m_pPropGrid
->m_width
*256) / psum
;
1144 // Convert proportion to splitter positions
1145 for ( i
=0; i
<(m_colWidths
.size() - 1); i
++ )
1147 int cwid
= (puwid
*m_columnProportions
[i
]) / 256;
1149 DoSetSplitterPosition(cpos
, i
,
1154 void wxPropertyGridPageState::SetColumnCount( int colCount
)
1156 wxASSERT( colCount
>= 2 );
1157 m_colWidths
.SetCount( colCount
, wxPG_DRAG_MARGIN
);
1158 m_columnProportions
.SetCount( colCount
, 1 );
1159 if ( m_colWidths
.size() > (unsigned int)colCount
)
1160 m_colWidths
.RemoveAt( m_colWidths
.size()-1,
1161 m_colWidths
.size() - colCount
);
1163 if ( m_pPropGrid
->GetState() == this )
1164 m_pPropGrid
->RecalculateVirtualSize();
1166 CheckColumnWidths();
1169 void wxPropertyGridPageState::DoSetColumnProportion( unsigned int column
,
1172 wxASSERT_MSG( proportion
>= 1,
1173 "Column proportion must 1 or higher" );
1175 if ( proportion
< 1 )
1178 while ( m_columnProportions
.size() <= column
)
1179 m_columnProportions
.push_back(1);
1181 m_columnProportions
[column
] = proportion
;
1184 // Returns column index, -1 for margin
1185 int wxPropertyGridPageState::HitTestH( int x
, int* pSplitterHit
, int* pSplitterHitOffset
) const
1187 int cx
= GetGrid()->m_marginWidth
;
1189 int prevSplitter
= -1;
1194 if ( col
>= (int)m_colWidths
.size() )
1200 cx
+= m_colWidths
[col
];
1203 // Near prev. splitter
1206 int diff
= x
- prevSplitter
;
1207 if ( abs(diff
) < wxPG_SPLITTERX_DETECTMARGIN1
)
1209 *pSplitterHit
= col
- 1;
1210 *pSplitterHitOffset
= diff
;
1215 // Near next splitter
1216 int nextSplitter
= cx
;
1217 if ( col
< (int)(m_colWidths
.size()-1) )
1219 int diff
= x
- nextSplitter
;
1220 if ( abs(diff
) < wxPG_SPLITTERX_DETECTMARGIN1
)
1222 *pSplitterHit
= col
;
1223 *pSplitterHitOffset
= diff
;
1232 bool wxPropertyGridPageState::ArePropertiesAdjacent( wxPGProperty
* prop1
,
1233 wxPGProperty
* prop2
,
1234 int iterFlags
) const
1236 const wxPGProperty
* ap1
=
1237 wxPropertyGridConstIterator::OneStep(this,
1241 if ( ap1
&& ap1
== prop2
)
1244 const wxPGProperty
* ap2
=
1245 wxPropertyGridConstIterator::OneStep(this,
1249 if ( ap2
&& ap2
== prop2
)
1255 // -----------------------------------------------------------------------
1256 // wxPropertyGridPageState property value setting and getting
1257 // -----------------------------------------------------------------------
1259 bool wxPropertyGridPageState::DoSetPropertyValueString( wxPGProperty
* p
, const wxString
& value
)
1263 int flags
= wxPG_REPORT_ERROR
|wxPG_FULL_VALUE
|wxPG_PROGRAMMATIC_VALUE
;
1265 wxVariant variant
= p
->GetValueRef();
1268 if ( p
->GetMaxLength() <= 0 )
1269 res
= p
->StringToValue( variant
, value
, flags
);
1271 res
= p
->StringToValue( variant
, value
.Mid(0,p
->GetMaxLength()), flags
);
1275 p
->SetValue(variant
);
1276 if ( p
== m_pPropGrid
->GetSelection() &&
1277 this == m_pPropGrid
->GetState() )
1278 m_pPropGrid
->RefreshEditor();
1286 // -----------------------------------------------------------------------
1288 bool wxPropertyGridPageState::DoSetPropertyValue( wxPGProperty
* p
, wxVariant
& value
)
1293 if ( p
== m_pPropGrid
->GetSelection() &&
1294 this == m_pPropGrid
->GetState() )
1295 m_pPropGrid
->RefreshEditor();
1302 // -----------------------------------------------------------------------
1304 bool wxPropertyGridPageState::DoSetPropertyValueWxObjectPtr( wxPGProperty
* p
, wxObject
* value
)
1308 // wnd_primary has to be given so the control can be updated as well.
1310 DoSetPropertyValue(p
, v
);
1316 // -----------------------------------------------------------------------
1317 // wxPropertyGridPageState property operations
1318 // -----------------------------------------------------------------------
1320 bool wxPropertyGridPageState::DoIsPropertySelected( wxPGProperty
* prop
) const
1322 if ( wxPGFindInVector(m_selection
, prop
) != wxNOT_FOUND
)
1328 // -----------------------------------------------------------------------
1330 void wxPropertyGridPageState::DoRemoveFromSelection( wxPGProperty
* prop
)
1332 for ( unsigned int i
=0; i
<m_selection
.size(); i
++ )
1334 if ( m_selection
[i
] == prop
)
1336 wxPropertyGrid
* pg
= m_pPropGrid
;
1337 if ( i
== 0 && pg
->GetState() == this )
1339 // If first item (ie. one with the active editor) was
1340 // deselected, then we need to take some extra measures.
1341 wxArrayPGProperty sel
= m_selection
;
1342 sel
.erase( sel
.begin() + i
);
1344 wxPGProperty
* newFirst
;
1350 pg
->DoSelectProperty(newFirst
,
1351 wxPG_SEL_DONT_SEND_EVENT
);
1359 m_selection
.erase( m_selection
.begin() + i
);
1366 // -----------------------------------------------------------------------
1368 bool wxPropertyGridPageState::DoCollapse( wxPGProperty
* p
)
1370 wxCHECK_MSG( p
, false, wxT("invalid property id") );
1372 if ( !p
->GetChildCount() ) return false;
1374 if ( !p
->IsExpanded() ) return false;
1376 p
->SetExpanded(false);
1378 VirtualHeightChanged();
1383 // -----------------------------------------------------------------------
1385 bool wxPropertyGridPageState::DoExpand( wxPGProperty
* p
)
1387 wxCHECK_MSG( p
, false, wxT("invalid property id") );
1389 if ( !p
->GetChildCount() ) return false;
1391 if ( p
->IsExpanded() ) return false;
1393 p
->SetExpanded(true);
1395 VirtualHeightChanged();
1400 // -----------------------------------------------------------------------
1402 bool wxPropertyGridPageState::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
1404 if ( this == m_pPropGrid
->GetState() )
1405 return m_pPropGrid
->DoSelectProperty( p
, flags
);
1411 // -----------------------------------------------------------------------
1413 bool wxPropertyGridPageState::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
1415 p
->DoHide(hide
, flags
);
1416 VirtualHeightChanged();
1421 // -----------------------------------------------------------------------
1422 // wxPropertyGridPageState wxVariant related routines
1423 // -----------------------------------------------------------------------
1425 // Returns list of wxVariant objects (non-categories and non-sub-properties only).
1426 // Never includes sub-properties (unless they are parented by wxParentProperty).
1427 wxVariant
wxPropertyGridPageState::DoGetPropertyValues( const wxString
& listname
,
1428 wxPGProperty
* baseparent
,
1431 wxPGProperty
* pwc
= (wxPGProperty
*) baseparent
;
1433 // Root is the default base-parent.
1437 wxVariantList tempList
;
1438 wxVariant
v( tempList
, listname
);
1440 if ( pwc
->GetChildCount() )
1442 if ( flags
& wxPG_KEEP_STRUCTURE
)
1444 wxASSERT( !pwc
->HasFlag(wxPG_PROP_AGGREGATE
) );
1447 for ( i
=0; i
<pwc
->GetChildCount(); i
++ )
1449 wxPGProperty
* p
= pwc
->Item(i
);
1450 if ( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
) )
1452 wxVariant variant
= p
->GetValue();
1453 variant
.SetName( p
->GetBaseName() );
1454 v
.Append( variant
);
1458 v
.Append( DoGetPropertyValues(p
->m_name
,p
,flags
|wxPG_KEEP_STRUCTURE
) );
1460 if ( (flags
& wxPG_INC_ATTRIBUTES
) && p
->m_attributes
.GetCount() )
1461 v
.Append( p
->GetAttributesAsList() );
1466 wxPropertyGridConstIterator
it( this, wxPG_ITERATE_DEFAULT
, pwc
->Item(0) );
1467 it
.SetBaseParent( pwc
);
1469 for ( ; !it
.AtEnd(); it
.Next() )
1471 const wxPGProperty
* p
= it
.GetProperty();
1473 // Use a trick to ignore wxParentProperty itself, but not its sub-properties.
1474 if ( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
) )
1476 wxVariant variant
= p
->GetValue();
1477 variant
.SetName( p
->GetName() );
1478 v
.Append( variant
);
1479 if ( (flags
& wxPG_INC_ATTRIBUTES
) && p
->m_attributes
.GetCount() )
1480 v
.Append( p
->GetAttributesAsList() );
1489 // -----------------------------------------------------------------------
1491 void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList
& list
, wxPGProperty
* defaultCategory
)
1493 unsigned char origFrozen
= 1;
1495 if ( m_pPropGrid
->GetState() == this )
1497 origFrozen
= m_pPropGrid
->m_frozen
;
1498 if ( !origFrozen
) m_pPropGrid
->Freeze();
1501 wxPropertyCategory
* use_category
= (wxPropertyCategory
*)defaultCategory
;
1503 if ( !use_category
)
1504 use_category
= (wxPropertyCategory
*)m_properties
;
1506 // Let's iterate over the list of variants.
1507 wxVariantList::const_iterator node
;
1508 int numSpecialEntries
= 0;
1511 // Second pass for special entries
1512 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1514 wxVariant
*current
= (wxVariant
*)*node
;
1516 // Make sure it is wxVariant.
1517 wxASSERT( current
);
1518 wxASSERT( wxStrcmp(current
->GetClassInfo()->GetClassName(),wxT("wxVariant")) == 0 );
1520 const wxString
& name
= current
->GetName();
1521 if ( !name
.empty() )
1524 // '@' signified a special entry
1525 if ( name
[0] == wxS('@') )
1527 numSpecialEntries
++;
1531 wxPGProperty
* foundProp
= BaseGetPropertyByName(name
);
1534 wxPGProperty
* p
= foundProp
;
1536 // If it was a list, we still have to go through it.
1537 if ( wxStrcmp(current
->GetType(), wxS("list")) == 0 )
1539 DoSetPropertyValues( current
->GetList(),
1540 p
->IsCategory()?p
:(NULL
)
1545 wxASSERT_LEVEL_2_MSG(
1546 wxStrcmp(current
->GetType(), p
->GetValue().GetType()) == 0,
1548 wxS("setting value of property \"%s\" from variant"),
1549 p
->GetName().c_str())
1552 p
->SetValue(*current
);
1558 if ( current
->GetType() != wxS("list") )
1564 // Yes, it is; create a sub category and append contents there.
1565 wxPGProperty
* newCat
= DoInsert(use_category
,-1,new wxPropertyCategory(current
->GetName(),wxPG_LABEL
));
1566 DoSetPropertyValues( current
->GetList(), newCat
);
1573 if ( numSpecialEntries
)
1575 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1577 wxVariant
*current
= (wxVariant
*)*node
;
1579 const wxString
& name
= current
->GetName();
1580 if ( !name
.empty() )
1583 // '@' signified a special entry
1584 if ( name
[0] == wxS('@') )
1586 numSpecialEntries
--;
1588 size_t pos2
= name
.rfind(wxS('@'));
1589 if ( pos2
> 0 && pos2
< (name
.size()-1) )
1591 wxString propName
= name
.substr(1, pos2
-1);
1592 wxString entryType
= name
.substr(pos2
+1, wxString::npos
);
1594 if ( entryType
== wxS("attr") )
1597 // List of attributes
1598 wxPGProperty
* foundProp
= BaseGetPropertyByName(propName
);
1601 wxASSERT( current
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1603 wxVariantList
& list2
= current
->GetList();
1604 wxVariantList::const_iterator node2
;
1606 for ( node2
= list2
.begin(); node2
!= list2
.end(); ++node2
)
1608 wxVariant
*attr
= (wxVariant
*)*node2
;
1609 foundProp
->SetAttribute( attr
->GetName(), *attr
);
1614 // ERROR: No such property: 'propName'
1620 // ERROR: Special entry requires name of format @<propname>@<entrytype>
1625 if ( !numSpecialEntries
)
1632 m_pPropGrid
->Thaw();
1634 if ( this == m_pPropGrid
->GetState() )
1635 m_pPropGrid
->RefreshEditor();
1640 // -----------------------------------------------------------------------
1641 // wxPropertyGridPageState property adding and removal
1642 // -----------------------------------------------------------------------
1644 bool wxPropertyGridPageState::PrepareToAddItem( wxPGProperty
* property
,
1645 wxPGProperty
* scheduledParent
)
1647 wxPropertyGrid
* propGrid
= m_pPropGrid
;
1649 // This will allow better behaviour.
1650 if ( scheduledParent
== m_properties
)
1651 scheduledParent
= NULL
;
1653 if ( scheduledParent
&& !scheduledParent
->IsCategory() )
1655 wxASSERT_MSG( property
->GetBaseName().length(),
1656 "Property's children must have unique, non-empty names within their scope" );
1659 property
->m_parentState
= this;
1661 if ( property
->IsCategory() )
1664 // Parent of a category must be either root or another category
1665 // (otherwise Bad Things might happen).
1666 wxASSERT_MSG( scheduledParent
== NULL
||
1667 scheduledParent
== m_properties
||
1668 scheduledParent
->IsCategory(),
1669 wxT("Parent of a category must be either root or another category."));
1671 // If we already have category with same name, delete given property
1672 // and use it instead as most recent caption item.
1673 wxPGProperty
* found_id
= BaseGetPropertyByName( property
->GetBaseName() );
1676 wxPropertyCategory
* pwc
= (wxPropertyCategory
*) found_id
;
1677 if ( pwc
->IsCategory() ) // Must be a category.
1680 m_currentCategory
= pwc
;
1687 // Warn for identical names in debug mode.
1688 if ( BaseGetPropertyByName(property
->GetName()) &&
1689 (!scheduledParent
|| scheduledParent
->IsCategory()) )
1691 wxFAIL_MSG(wxString::Format(
1692 "wxPropertyGrid item with name \"%s\" already exists",
1693 property
->GetName()));
1695 wxPGGlobalVars
->m_warnings
++;
1697 #endif // wxDEBUG_LEVEL
1699 // NULL parent == root parent
1700 if ( !scheduledParent
)
1701 scheduledParent
= DoGetRoot();
1703 property
->m_parent
= scheduledParent
;
1705 property
->InitAfterAdded(this, propGrid
);
1707 if ( property
->IsCategory() )
1709 wxPropertyCategory
* pc
= wxStaticCast(property
, wxPropertyCategory
);
1711 m_currentCategory
= pc
;
1713 // Calculate text extent for category caption
1715 pc
->CalculateTextExtent(propGrid
, propGrid
->GetCaptionFont());
1721 // -----------------------------------------------------------------------
1723 wxPGProperty
* wxPropertyGridPageState::DoAppend( wxPGProperty
* property
)
1725 wxPropertyCategory
* cur_cat
= m_currentCategory
;
1726 if ( property
->IsCategory() )
1729 return DoInsert( cur_cat
, -1, property
);
1732 // -----------------------------------------------------------------------
1734 wxPGProperty
* wxPropertyGridPageState::DoInsert( wxPGProperty
* parent
, int index
, wxPGProperty
* property
)
1737 parent
= m_properties
;
1739 wxCHECK_MSG( !parent
->HasFlag(wxPG_PROP_AGGREGATE
),
1741 wxT("when adding properties to fixed parents, use BeginAddChildren and EndAddChildren.") );
1743 bool res
= PrepareToAddItem( property
, (wxPropertyCategory
*)parent
);
1745 // PrepareToAddItem() may just decide to use current category
1746 // instead of adding new one.
1748 return m_currentCategory
;
1750 bool parentIsRoot
= parent
->IsRoot();
1751 bool parentIsCategory
= parent
->IsCategory();
1753 // Note that item must be added into current mode later.
1755 // If parent is wxParentProperty, just stick it in...
1756 // If parent is root (m_properties), then...
1757 // In categoric mode: Add as last item in m_abcArray (if not category).
1758 // Add to given index in m_regularArray.
1759 // In non-cat mode: Add as last item in m_regularArray.
1760 // Add to given index in m_abcArray.
1761 // If parent is category, then...
1762 // 1) Add to given category in given index.
1763 // 2) Add as last item in m_abcArray.
1765 if ( m_properties
== &m_regularArray
)
1767 // We are currently in Categorized mode
1769 // Only add non-categories to m_abcArray.
1770 if ( m_abcArray
&& !property
->IsCategory() &&
1771 (parentIsCategory
|| parentIsRoot
) )
1773 m_abcArray
->DoAddChild( property
, -1, false );
1776 // Add to current mode.
1777 parent
->DoAddChild( property
, index
, true );
1781 // We are currently in Non-categorized/Alphabetic mode
1783 if ( parentIsCategory
)
1784 // Parent is category.
1785 parent
->DoAddChild( property
, index
, false );
1786 else if ( parentIsRoot
)
1788 m_regularArray
.DoAddChild( property
, -1, false );
1790 // Add to current mode
1791 if ( !property
->IsCategory() )
1792 m_abcArray
->DoAddChild( property
, index
, true );
1796 if ( property
->IsCategory() )
1798 // This is a category caption item.
1800 // Last caption is not the bottom one (this info required by append)
1801 m_lastCaptionBottomnest
= 0;
1804 // Only add name to hashmap if parent is root or category
1805 if ( !property
->m_name
.empty() &&
1806 (parentIsCategory
|| parentIsRoot
) )
1807 m_dictName
[property
->m_name
] = (void*) property
;
1809 VirtualHeightChanged();
1811 property
->UpdateParentValues();
1818 // -----------------------------------------------------------------------
1820 void wxPropertyGridPageState::DoDelete( wxPGProperty
* item
, bool doDelete
)
1822 wxCHECK_RET( item
->GetParent(),
1823 wxT("this property was already deleted") );
1825 wxCHECK_RET( item
!= &m_regularArray
&& item
!= m_abcArray
,
1826 wxT("wxPropertyGrid: Do not attempt to remove the root item.") );
1828 wxPropertyGrid
* pg
= GetGrid();
1830 // Must defer deletion? Yes, if handling a wxPG event.
1831 if ( pg
&& pg
->m_processedEvent
)
1834 pg
->m_deletedProperties
.push_back(item
);
1836 pg
->m_removedProperties
.push_back(item
);
1838 // Rename the property so it won't remain in the way
1839 // of the user code.
1841 // Let's trust that no sane property uses prefix like
1842 // this. It would be anyway fairly inconvenient (in
1843 // current code) to check whether a new name is used
1844 // by another property with parent (due to the child
1846 wxString newName
= wxS("_&/_%$") + item
->GetBaseName();
1847 DoSetPropertyName(item
, newName
);
1852 unsigned int indinparent
= item
->GetIndexInParent();
1854 wxPGProperty
* pwc
= (wxPGProperty
*)item
;
1855 wxPGProperty
* parent
= item
->GetParent();
1857 wxCHECK_RET( !parent
->HasFlag(wxPG_PROP_AGGREGATE
),
1858 wxT("wxPropertyGrid: Do not attempt to remove sub-properties.") );
1860 wxASSERT( item
->GetParentState() == this );
1862 if ( DoIsPropertySelected(item
) )
1864 if ( pg
&& pg
->GetState() == this )
1866 pg
->DoRemoveFromSelection(item
,
1867 wxPG_SEL_DELETING
|wxPG_SEL_NOVALIDATE
);
1871 DoRemoveFromSelection(item
);
1875 item
->SetFlag(wxPG_PROP_BEING_DELETED
);
1878 if ( item
->GetChildCount() && !item
->HasFlag(wxPG_PROP_AGGREGATE
) )
1880 // deleting a category
1881 if ( item
->IsCategory() )
1883 if ( pwc
== m_currentCategory
)
1884 m_currentCategory
= NULL
;
1887 item
->DeleteChildren();
1890 if ( !IsInNonCatMode() )
1892 // categorized mode - non-categorized array
1894 // Remove from non-cat array
1895 if ( !item
->IsCategory() &&
1896 (parent
->IsCategory() || parent
->IsRoot()) )
1899 m_abcArray
->RemoveChild(item
);
1902 // categorized mode - categorized array
1903 wxArrayPGProperty
& parentsChildren
= parent
->m_children
;
1904 parentsChildren
.erase( parentsChildren
.begin() + indinparent
);
1905 item
->m_parent
->FixIndicesOfChildren();
1909 // non-categorized mode - categorized array
1911 // We need to find location of item.
1912 wxPGProperty
* cat_parent
= &m_regularArray
;
1913 int cat_index
= m_regularArray
.GetChildCount();
1915 for ( i
= 0; i
< m_regularArray
.GetChildCount(); i
++ )
1917 wxPGProperty
* p
= m_regularArray
.Item(i
);
1918 if ( p
== item
) { cat_index
= i
; break; }
1919 if ( p
->IsCategory() )
1921 int subind
= ((wxPGProperty
*)p
)->Index(item
);
1922 if ( subind
!= wxNOT_FOUND
)
1924 cat_parent
= ((wxPGProperty
*)p
);
1930 cat_parent
->m_children
.erase(cat_parent
->m_children
.begin()+cat_index
);
1932 // non-categorized mode - non-categorized array
1933 if ( !item
->IsCategory() )
1935 wxASSERT( item
->m_parent
== m_abcArray
);
1936 wxArrayPGProperty
& parentsChildren
= item
->m_parent
->m_children
;
1937 parentsChildren
.erase(parentsChildren
.begin() + indinparent
);
1938 item
->m_parent
->FixIndicesOfChildren(indinparent
);
1942 if ( !item
->GetBaseName().empty() &&
1943 (parent
->IsCategory() || parent
->IsRoot()) )
1944 m_dictName
.erase(item
->GetBaseName());
1946 // We need to clear parent grid's m_propHover, if it matches item
1947 if ( pg
&& pg
->m_propHover
== item
)
1948 pg
->m_propHover
= NULL
;
1950 // Mark the property as 'unattached'
1951 item
->m_parentState
= NULL
;
1952 item
->m_parent
= NULL
;
1954 // We can actually delete it now
1958 item
->OnDetached(this, pg
);
1960 m_itemsAdded
= 1; // Not a logical assignment (but required nonetheless).
1962 VirtualHeightChanged();
1965 // -----------------------------------------------------------------------
1967 #endif // wxUSE_PROPGRID