1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/property.cpp
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcmemory.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/scrolwin.h"
40 #include "wx/dirdlg.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
50 #include <wx/propgrid/propgrid.h>
55 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
58 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
61 // -----------------------------------------------------------------------
63 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
65 #if defined(__WXMSW__) && !defined(__WXWINCE__)
66 // FIXME: Use DrawFocusRect code above (currently it draws solid line
67 // for caption focus but works ok for other stuff).
68 // Also, it seems that this code may not work in future wx versions.
69 dc
.SetLogicalFunction(wxINVERT
);
71 wxPen
pen(*wxBLACK
,1,wxDOT
);
72 pen
.SetCap(wxCAP_BUTT
);
74 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
76 dc
.DrawRectangle(rect
);
78 dc
.SetLogicalFunction(wxCOPY
);
80 dc
.SetLogicalFunction(wxINVERT
);
82 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
83 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
85 dc
.DrawRectangle(rect
);
87 dc
.SetLogicalFunction(wxCOPY
);
91 // -----------------------------------------------------------------------
93 // -----------------------------------------------------------------------
95 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
97 int WXUNUSED(item
) ) const
102 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
103 int xOffset
, const wxString
& text
) const
106 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
108 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
109 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
112 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
113 int xOffset
, const wxString
& text
,
114 wxPGProperty
* property
,
115 const wxPGEditor
* editor
) const
118 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
120 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
127 rect2
.height
-= yOffset
;
128 editor
->DrawValue( dc
, rect2
, property
, text
);
133 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
138 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
140 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
141 wxPGDrawFocusRect(dc
,focusRect
);
144 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
148 if ( !(flags
& Selected
) )
150 // Draw using wxPGCell information, if available
151 wxColour fgCol
= cell
.GetFgCol();
153 dc
.SetTextForeground(fgCol
);
155 wxColour bgCol
= cell
.GetBgCol();
160 dc
.DrawRectangle(rect
);
164 const wxBitmap
& bmp
= cell
.GetBitmap();
166 // In control, do not draw oversized bitmap
167 (!(flags
& Control
) || bmp
.GetHeight() < rect
.height
)
171 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
172 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
174 imageOffset
= bmp
.GetWidth();
180 // -----------------------------------------------------------------------
181 // wxPGDefaultRenderer
182 // -----------------------------------------------------------------------
184 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
185 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
186 int column
, int item
, int flags
) const
188 bool isUnspecified
= property
->IsValueUnspecified();
190 if ( column
== 1 && item
== -1 )
192 int cmnVal
= property
->GetCommonValue();
196 if ( !isUnspecified
)
197 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
202 const wxPGEditor
* editor
= NULL
;
203 const wxPGCell
* cell
= property
->GetCell(column
);
209 if ( column
== 1 && (flags
& Control
) )
211 const wxPGCell
* ccell
= property
->GetCurrentChoice();
213 ( ccell
->GetBitmap().IsOk() || ccell
->GetFgCol().IsOk() || ccell
->GetBgCol().IsOk() )
220 int preDrawFlags
= flags
;
222 if ( propertyGrid
->GetInternalFlags() & wxPG_FL_CELL_OVERRIDES_SEL
)
223 preDrawFlags
= preDrawFlags
& ~(Selected
);
225 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
226 text
= cell
->GetText();
227 if ( text
== wxS("@!") )
230 text
= property
->GetLabel();
231 else if ( column
== 1 )
232 text
= property
->GetValueString();
234 text
= wxEmptyString
;
237 else if ( column
== 0 )
240 DrawText( dc
, rect
, 0, property
->GetLabel() );
242 else if ( column
== 1 )
244 if ( !isUnspecified
)
246 editor
= property
->GetColumnEditor(column
);
248 // Regular property value
250 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
252 wxPGPaintData paintdata
;
253 paintdata
.m_parent
= propertyGrid
;
254 paintdata
.m_choiceItem
= item
;
256 if ( imageSize
.x
> 0 )
258 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
259 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
260 wxPG_CUSTOM_IMAGE_WIDTH
,
261 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
263 /*if ( imageSize.x == wxPG_FULL_CUSTOM_PAINT_WIDTH )
265 imageRect.width = m_width - imageRect.x;
268 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
270 paintdata
.m_drawnWidth
= imageSize
.x
;
271 paintdata
.m_drawnHeight
= imageSize
.y
;
273 if ( !isUnspecified
)
275 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
279 dc
.SetBrush(*wxWHITE_BRUSH
);
280 dc
.DrawRectangle(imageRect
);
283 imageOffset
= paintdata
.m_drawnWidth
;
286 text
= property
->GetValueString();
289 if ( propertyGrid
->GetColumnCount() <= 2 )
291 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
292 if ( unitsString
.length() )
293 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
297 if ( text
.length() == 0 )
299 // Try to show inline help if no text
300 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
301 if ( !vInlineHelp
.IsNull() )
303 text
= vInlineHelp
.GetString();
304 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
308 else if ( column
== 2 )
311 if ( !text
.length() )
312 text
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
315 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
317 // active caption gets nice dotted rectangle
318 if ( property
->IsCategory() /*&& column == 0*/ )
320 if ( flags
& Selected
)
322 if ( imageOffset
> 0 )
323 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
325 DrawCaptionSelectionRect( dc
,
326 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
327 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
328 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
329 propertyGrid
->GetCaptionFont())
330 +(wxPG_CAPRECTXMARGIN
*2),
331 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
336 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
340 if ( property
&& column
== 1 )
344 wxBitmap
* bmp
= property
->GetValueImage();
346 if ( bmp
&& bmp
->Ok() )
347 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
353 // -----------------------------------------------------------------------
355 // -----------------------------------------------------------------------
361 wxPGCell::wxPGCell( const wxString
& text
,
362 const wxBitmap
& bitmap
,
363 const wxColour
& fgCol
,
364 const wxColour
& bgCol
)
365 : m_bitmap(bitmap
), m_fgCol(fgCol
), m_bgCol(bgCol
)
370 // -----------------------------------------------------------------------
372 // -----------------------------------------------------------------------
374 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
376 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
378 void wxPGProperty::Init()
384 m_parentState
= (wxPropertyGridPageState
*) NULL
;
387 m_clientObject
= NULL
;
389 m_customEditor
= (wxPGEditor
*) NULL
;
391 m_validator
= (wxValidator
*) NULL
;
393 m_valueBitmap
= (wxBitmap
*) NULL
;
395 m_maxLen
= 0; // infinite maximum length
397 m_flags
= wxPG_PROP_PROPERTY
;
407 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
409 // We really need to check if &label and &name are NULL pointers
410 // (this can if we are called before property grid has been initalized)
412 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
415 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
418 DoSetName( m_label
);
423 wxPGProperty::wxPGProperty()
430 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
437 wxPGProperty::~wxPGProperty()
439 delete m_clientObject
;
441 Empty(); // this deletes items
443 delete m_valueBitmap
;
450 for ( i
=0; i
<m_cells
.size(); i
++ )
451 delete (wxPGCell
*) m_cells
[i
];
453 // This makes it easier for us to detect dangling pointers
458 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
460 wxPGProperty
* parent
= m_parent
;
463 if ( parent
== candidate
)
465 parent
= parent
->m_parent
;
471 wxString
wxPGProperty::GetName() const
473 wxPGProperty
* parent
= GetParent();
475 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
478 return m_parent
->GetName() + wxS(".") + m_name
;
481 wxPropertyGrid
* wxPGProperty::GetGrid() const
483 if ( !m_parentState
)
485 return m_parentState
->GetGrid();
489 void wxPGProperty::UpdateControl( wxWindow
* primary
)
492 GetEditorClass()->UpdateControl(this, primary
);
495 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
500 void wxPGProperty::OnSetValue()
504 void wxPGProperty::RefreshChildren ()
508 wxString
wxPGProperty::GetColumnText( unsigned int col
) const
510 wxPGCell
* cell
= GetCell(col
);
513 return cell
->GetText();
520 return GetDisplayedString();
522 return GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
525 return wxEmptyString
;
528 void wxPGProperty::GenerateComposedValue( wxString
& text
, int argFlags
) const
531 int iMax
= m_children
.GetCount();
537 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
538 !(argFlags
& wxPG_FULL_VALUE
) )
539 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
541 int iMaxMinusOne
= iMax
-1;
543 if ( !IsTextEditable() )
544 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
546 wxPGProperty
* curChild
= (wxPGProperty
*) m_children
.Item(0);
548 for ( i
= 0; i
< iMax
; i
++ )
551 if ( !curChild
->IsValueUnspecified() )
552 s
= curChild
->GetValueString(argFlags
|wxPG_COMPOSITE_FRAGMENT
);
555 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
558 if ( !curChild
->GetChildCount() || skip
)
561 text
+= wxS("[") + s
+ wxS("]");
563 if ( i
< iMaxMinusOne
)
565 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
566 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
567 !(argFlags
& wxPG_FULL_VALUE
) )
572 if ( !curChild
->GetChildCount() )
578 curChild
= (wxPGProperty
*) m_children
.Item(i
+1);
582 // Remove superfluous semicolon and space
584 if ( text
.EndsWith(wxS("; "), &rest
) )
587 if ( (unsigned int)i
< m_children
.GetCount() )
588 text
+= wxS("; ...");
591 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
593 wxCHECK_MSG( GetChildCount() > 0,
595 wxT("If user property does not have any children, it must override GetValueAsString") );
598 GenerateComposedValue(text
, argFlags
);
602 wxString
wxPGProperty::GetValueString( int argFlags
) const
604 if ( IsValueUnspecified() )
605 return wxEmptyString
;
607 if ( m_commonValue
== -1 )
608 return GetValueAsString(argFlags
);
611 // Return common value's string representation
612 wxPropertyGrid
* pg
= GetGrid();
613 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
615 if ( argFlags
& wxPG_FULL_VALUE
)
617 return cv
->GetLabel();
619 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
621 return cv
->GetEditableText();
625 return cv
->GetLabel();
629 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
631 variant
= (long)number
;
635 // Convert semicolon delimited tokens into child values.
636 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
638 if ( !GetChildCount() )
641 unsigned int curChild
= 0;
643 unsigned int iMax
= m_children
.GetCount();
645 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
646 !(argFlags
& wxPG_FULL_VALUE
) )
647 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
649 bool changed
= false;
654 // Its best only to add non-empty group items
655 bool addOnlyIfNotEmpty
= false;
656 const wxChar delimeter
= wxS(';');
658 size_t tokenStart
= 0xFFFFFF;
660 wxVariantList temp_list
;
661 wxVariant
list(temp_list
);
663 int propagatedFlags
= argFlags
& wxPG_REPORT_ERROR
;
666 bool debug_print
= false;
671 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
674 wxString::const_iterator it
= text
.begin();
677 if ( it
!= text
.end() )
684 if ( tokenStart
!= 0xFFFFFF )
687 if ( a
== delimeter
|| a
== 0 )
689 token
= text
.substr(tokenStart
,pos
-tokenStart
);
691 size_t len
= token
.length();
693 if ( !addOnlyIfNotEmpty
|| len
> 0 )
695 const wxPGProperty
* child
= Item(curChild
);
698 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().c_str());
703 bool wasUnspecified
= child
->IsValueUnspecified();
705 wxVariant
variant(child
->GetValueRef());
706 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
708 variant
.SetName(child
->GetBaseName());
710 // Clear unspecified flag only if OnSetValue() didn't
712 if ( child
->IsValueUnspecified() &&
713 (wasUnspecified
|| !UsesAutoUnspecified()) )
715 variant
= child
->GetDefaultValue();
718 list
.Append(variant
);
725 // Empty, becomes unspecified
727 variant2
.SetName(child
->GetBaseName());
728 list
.Append(variant2
);
733 if ( curChild
>= iMax
)
737 tokenStart
= 0xFFFFFF;
742 // Token is not running
746 addOnlyIfNotEmpty
= false;
748 // Is this a group of tokens?
753 if ( it
!= text
.end() ) it
++;
755 size_t startPos
= pos
;
757 // Group item - find end
758 while ( it
!= text
.end() && depth
> 0 )
766 else if ( a
== wxS('[') )
770 token
= text
.substr(startPos
,pos
-startPos
-1);
772 if ( !token
.length() )
775 const wxPGProperty
* child
= Item(curChild
);
777 wxVariant
variant(child
->GetValueRef());
778 if ( child
->StringToValue( variant
, token
, propagatedFlags
) )
780 variant
.SetName(child
->GetBaseName());
781 list
.Append(variant
);
786 // Failed, becomes unspecified
788 variant2
.SetName(child
->GetBaseName());
789 list
.Append(variant2
);
794 if ( curChild
>= iMax
)
797 addOnlyIfNotEmpty
= true;
799 tokenStart
= 0xFFFFFF;
805 if ( a
== delimeter
)
818 if ( it
!= text
.end() )
835 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
837 wxVariant
variant(m_value
);
838 bool res
= StringToValue(variant
, text
, argFlags
);
844 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
846 wxVariant
variant(m_value
);
847 bool res
= IntToValue(variant
, number
, argFlags
);
853 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
856 return wxSize(m_valueBitmap
->GetWidth(),-1);
861 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
863 return wxPGGlobalVars
->m_defaultRenderer
;
866 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
870 wxBitmap
* bmp
= m_valueBitmap
;
872 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
874 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
876 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
879 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
881 return wxPG_EDITOR(TextCtrl
);
884 // Default extra property event handling - that is, none at all.
885 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
891 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
893 if ( !value
.IsNull() )
895 wxVariant tempListVariant
;
898 // List variants are reserved a special purpose
899 // as intermediate containers for child values
900 // of properties with children.
901 if ( wxPGIsVariantType(value
, list
) )
904 // However, situation is different for composed string properties
905 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
907 tempListVariant
= value
;
908 pList
= &tempListVariant
;
912 AdaptListToValue(value
, &newValue
);
914 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
917 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
918 flags
|= wxPG_SETVAL_AGGREGATED
;
920 if ( pList
&& !pList
->IsNull() )
922 wxASSERT( wxPGIsVariantType(*pList
, list
) );
923 wxASSERT( GetChildCount() );
924 wxASSERT( !IsCategory() );
926 wxVariantList
& list
= pList
->GetList();
927 wxVariantList::iterator node
;
930 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
932 // Children in list can be in any order, but we will give hint to
933 // GetPropertyByNameWH(). This optimizes for full list parsing.
934 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
936 wxVariant
& childValue
= *((wxVariant
*)*node
);
937 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
940 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
941 if ( wxPGIsVariantType(childValue
, list
) )
943 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
945 wxVariant listRefCopy
= childValue
;
946 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
950 wxVariant oldVal
= child
->GetValue();
951 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
954 else if ( !wxPG_VARIANT_EQ(child
->GetValue(), childValue
) )
956 // For aggregate properties, we will trust RefreshChildren()
957 // to update child values.
958 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
959 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
960 if ( flags
& wxPG_SETVAL_BY_USER
)
961 child
->SetFlag(wxPG_PROP_MODIFIED
);
968 if ( !value
.IsNull() )
970 wxPGVariantAssign(m_value
, value
);
973 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
974 UpdateParentValues();
977 if ( flags
& wxPG_SETVAL_BY_USER
)
978 SetFlag(wxPG_PROP_MODIFIED
);
980 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
985 if ( m_commonValue
!= -1 )
987 wxPropertyGrid
* pg
= GetGrid();
988 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
994 // Set children to unspecified, but only if aggregate or
995 // value is <composed>
996 if ( AreChildrenComponents() )
999 for ( i
=0; i
<GetChildCount(); i
++ )
1000 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1005 // Update editor control
1008 // We need to check for these, otherwise GetGrid() may fail.
1009 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1014 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1016 GetGrid()->ValueChangeInEvent(value
);
1019 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1027 for ( i
= 0; i
< GetChildCount(); i
++ )
1028 Item(i
)->SetFlagRecursively(flag
, set
);
1031 void wxPGProperty::RefreshEditor()
1033 if ( m_parent
&& GetParentState() )
1035 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1036 if ( pg
->GetSelectedProperty() == this )
1038 wxWindow
* editor
= pg
->GetEditorControl();
1040 GetEditorClass()->UpdateControl( this, editor
);
1046 wxVariant
wxPGProperty::GetDefaultValue() const
1048 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1049 if ( !defVal
.IsNull() )
1052 wxVariant value
= GetValue();
1054 if ( !value
.IsNull() )
1056 wxPGVariantDataClassInfo classInfo
= wxPGVariantDataGetClassInfo(value
.GetData());
1057 if ( wxPGIsVariantClassInfo(classInfo
, long) )
1058 return wxPGVariant_Zero
;
1059 if ( wxPGIsVariantClassInfo(classInfo
, string
) )
1060 return wxPGVariant_EmptyString
;
1061 if ( wxPGIsVariantClassInfo(classInfo
, bool) )
1062 return wxPGVariant_False
;
1063 if ( wxPGIsVariantClassInfo(classInfo
, double) )
1064 return wxVariant(0.0);
1066 wxPGVariantData
* pgvdata
= wxDynamicCastVariantData(m_value
.GetData(), wxPGVariantData
);
1068 return pgvdata
->GetDefaultValue();
1070 if ( wxPGIsVariantClassInfo(classInfo
, arrstring
) )
1071 return wxVariant(wxArrayString());
1072 if ( wxPGIsVariantClassInfo(classInfo
, wxColour
) )
1073 return WXVARIANT(*wxRED
);
1075 if ( wxPGIsVariantClassInfo(classInfo
, datetime
) )
1076 return wxVariant(wxDateTime::Now());
1080 wxString::Format(wxT("Inorder for value to have default value, it must be added to")
1081 wxT("wxPGProperty::GetDefaultValue or it's variantdata must inherit")
1082 wxT("from wxPGVariantData (unrecognized type was '%s')"),m_value
.GetType().c_str())
1089 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1091 if ( column
>= (int)m_cells
.size() )
1092 m_cells
.SetCount(column
+1, NULL
);
1094 delete (wxPGCell
*) m_cells
[column
];
1095 m_cells
[column
] = cellObj
;
1098 void wxPGProperty::SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
)
1100 // Changes value of a property with choices, but only
1101 // works if the value type is long or string.
1102 wxString ts
= GetValue().GetType();
1104 wxCHECK_RET( choiceInfo
.m_choices
, wxT("invalid choiceinfo") );
1106 if ( ts
== wxS("long") )
1108 SetValue( (long) newValue
);
1110 else if ( ts
== wxS("string") )
1112 SetValue( choiceInfo
.m_choices
->GetLabel(newValue
) );
1117 wxString
wxPGProperty::GetChoiceString( unsigned int index
)
1121 wxASSERT(ci
.m_choices
);
1122 return ci
.m_choices
->GetLabel(index
);
1125 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1127 wxPropertyGrid
* pg
= GetGrid();
1130 ci
.m_choices
= (wxPGChoices
*) NULL
;
1131 int sel
= GetChoiceInfo(&ci
);
1138 index
= ci
.m_choices
->GetCount();
1143 ci
.m_choices
->Insert(label
, index
, value
);
1145 if ( sel
!= newSel
)
1146 SetChoiceSelection(newSel
, ci
);
1148 if ( this == pg
->GetSelection() )
1149 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1158 void wxPGProperty::DeleteChoice( int index
)
1160 wxPropertyGrid
* pg
= GetGrid();
1163 ci
.m_choices
= (wxPGChoices
*) NULL
;
1164 int sel
= GetChoiceInfo(&ci
);
1170 // Adjust current value
1173 SetValueToUnspecified();
1176 else if ( index
< sel
)
1181 ci
.m_choices
->RemoveAt(index
);
1183 if ( sel
!= newSel
)
1184 SetChoiceSelection(newSel
, ci
);
1186 if ( this == pg
->GetSelection() )
1187 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1191 int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo
* WXUNUSED(info
) )
1196 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1201 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1206 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1208 if ( DoSetAttribute( name
, value
) )
1210 // Support working without grid, when possible
1211 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1215 m_attributes
.Set( name
, value
);
1218 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1220 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1223 while ( attributes
.GetNext(it
, variant
) )
1224 SetAttribute( variant
.GetName(), variant
);
1227 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1233 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1235 return m_attributes
.FindValue(name
);
1238 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1240 wxVariant variant
= m_attributes
.FindValue(name
);
1242 if ( !variant
.IsNull() )
1243 return variant
.GetString();
1248 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1250 wxVariant variant
= m_attributes
.FindValue(name
);
1252 return wxPGVariantToInt(variant
, defVal
);
1255 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1258 wxVariant variant
= m_attributes
.FindValue(name
);
1260 if ( wxPGVariantToDouble(variant
, &retVal
) )
1266 wxVariant
wxPGProperty::GetAttributesAsList() const
1268 wxVariantList tempList
;
1269 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1271 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1274 while ( m_attributes
.GetNext(it
, variant
) )
1280 // Slots of utility flags are NULL
1281 const unsigned int gs_propFlagToStringSize
= 14;
1283 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1300 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1303 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1307 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1309 if ( relevantFlags
& a
)
1311 const wxChar
* fs
= gs_propFlagToString
[i
];
1323 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1327 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1329 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1331 const wxChar
* fs
= gs_propFlagToString
[i
];
1332 if ( fs
&& str
== fs
)
1338 WX_PG_TOKENIZER1_END()
1340 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1343 wxValidator
* wxPGProperty::DoGetValidator() const
1345 return (wxValidator
*) NULL
;
1348 wxPGChoices
& wxPGProperty::GetChoices()
1350 wxPGChoiceInfo choiceInfo
;
1351 choiceInfo
.m_choices
= NULL
;
1352 GetChoiceInfo(&choiceInfo
);
1353 return *choiceInfo
.m_choices
;
1356 const wxPGChoices
& wxPGProperty::GetChoices() const
1358 return (const wxPGChoices
&) ((wxPGProperty
*)this)->GetChoices();
1361 unsigned int wxPGProperty::GetChoiceCount() const
1363 const wxPGChoices
& choices
= GetChoices();
1364 if ( &choices
&& choices
.IsOk() )
1365 return choices
.GetCount();
1369 const wxPGChoiceEntry
* wxPGProperty::GetCurrentChoice() const
1372 ci
.m_choices
= (wxPGChoices
*) NULL
;
1373 int index
= ((wxPGProperty
*)this)->GetChoiceInfo(&ci
);
1374 if ( index
== -1 || !ci
.m_choices
|| index
>= (int)ci
.m_choices
->GetCount() )
1377 return &(*ci
.m_choices
)[index
];
1380 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1383 ci
.m_choices
= (wxPGChoices
*) NULL
;
1389 ci
.m_choices
->Assign(choices
);
1393 // This may be needed to trigger some initialization
1394 // (but don't do it if property is somewhat uninitialized)
1395 wxVariant defVal
= GetDefaultValue();
1396 if ( defVal
.IsNull() )
1408 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1410 const wxPGEditor
* editor
;
1412 if ( !m_customEditor
)
1414 editor
= DoGetEditorClass();
1417 editor
= m_customEditor
;
1420 // Maybe override editor if common value specified
1421 if ( GetDisplayedCommonValueCount() )
1423 // TextCtrlAndButton -> ComboBoxAndButton
1424 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1425 editor
= wxPG_EDITOR(ChoiceAndButton
);
1427 // TextCtrl -> ComboBox
1428 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1429 editor
= wxPG_EDITOR(ComboBox
);
1436 // Privatizes set of choices
1437 void wxPGProperty::SetChoicesExclusive()
1440 ci
.m_choices
= (wxPGChoices
*) NULL
;
1444 ci
.m_choices
->SetExclusive();
1447 bool wxPGProperty::HasVisibleChildren() const
1451 for ( i
=0; i
<GetChildCount(); i
++ )
1453 wxPGProperty
* child
= Item(i
);
1455 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1462 bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid
* propGrid
)
1464 return propGrid
->EditorValidate();
1468 bool wxPGProperty::RecreateEditor()
1470 wxPropertyGrid
* pg
= GetGrid();
1473 wxPGProperty
* selected
= pg
->GetSelection();
1474 if ( this == selected
)
1476 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1483 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1485 delete m_valueBitmap
;
1487 if ( &bmp
&& bmp
.Ok() )
1490 wxSize maxSz
= GetGrid()->GetImageSize();
1491 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1493 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1495 // Create a memory DC
1496 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1499 dc
.SelectObject(*bmpNew
);
1502 // FIXME: This is ugly - use image or wait for scaling patch.
1503 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1504 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1506 dc
.SetUserScale(scaleX
,scaleY
);
1508 dc
.DrawBitmap( bmp
, 0, 0 );
1510 m_valueBitmap
= bmpNew
;
1514 m_valueBitmap
= new wxBitmap(bmp
);
1517 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1521 m_valueBitmap
= NULL
;
1522 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1527 wxPGProperty
* wxPGProperty::GetMainParent() const
1529 const wxPGProperty
* curChild
= this;
1530 const wxPGProperty
* curParent
= m_parent
;
1532 while ( curParent
&& !curParent
->IsCategory() )
1534 curChild
= curParent
;
1535 curParent
= curParent
->m_parent
;
1538 return (wxPGProperty
*) curChild
;
1542 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1545 // Returns last visible sub-item, recursively.
1546 if ( !IsExpanded() || !GetChildCount() )
1549 return Last()->GetLastVisibleSubItem();
1553 bool wxPGProperty::IsVisible() const
1555 const wxPGProperty
* parent
;
1557 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1560 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1562 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1569 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1571 wxPropertyGridPageState
* state
= GetParentState();
1572 wxPropertyGrid
* propGrid
= state
->GetGrid();
1573 if ( state
== propGrid
->GetState() )
1579 int wxPGProperty::GetY2( int lh
) const
1581 const wxPGProperty
* parent
;
1582 const wxPGProperty
* child
= this;
1586 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1588 if ( !parent
->IsExpanded() )
1590 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1595 y
-= lh
; // need to reduce one level
1601 int wxPGProperty::GetY() const
1603 return GetY2(GetGrid()->GetRowHeight());
1606 // This is used by Insert etc.
1607 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1609 if ( index
< 0 || (size_t)index
>= m_children
.GetCount() )
1611 if ( correct_mode
) prop
->m_arrIndex
= m_children
.GetCount();
1612 m_children
.Add( prop
);
1616 m_children
.Insert( prop
, index
);
1617 if ( correct_mode
) FixIndexesOfChildren( index
);
1620 prop
->m_parent
= this;
1623 // This is used by properties that have fixed sub-properties
1624 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1626 wxASSERT_MSG( prop
->GetBaseName().length(),
1627 "Property's children must have unique, non-empty names within their scope" );
1629 prop
->m_arrIndex
= m_children
.GetCount();
1630 m_children
.Add( prop
);
1632 int custImgHeight
= prop
->OnMeasureImage().y
;
1633 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1634 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1636 prop
->m_parent
= this;
1640 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1642 wxASSERT( GetChildCount() );
1643 wxASSERT( !IsCategory() );
1645 *value
= GetValue();
1647 if ( !list
.GetCount() )
1650 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1652 bool allChildrenSpecified
;
1654 // Don't fully update aggregate properties unless all children have
1656 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1657 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1659 allChildrenSpecified
= true;
1661 wxVariant childValue
= list
[0];
1665 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1667 for ( i
=0; i
<GetChildCount(); i
++ )
1669 const wxPGProperty
* child
= Item(i
);
1671 if ( childValue
.GetName() == child
->GetBaseName() )
1673 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1675 if ( wxPGIsVariantType(childValue
, list
) )
1677 wxVariant
cv2(child
->GetValue());
1678 child
->AdaptListToValue(childValue
, &cv2
);
1682 if ( allChildrenSpecified
)
1683 ChildChanged(*value
, i
, childValue
);
1685 if ( n
== (unsigned int)list
.GetCount() )
1687 childValue
= list
[n
];
1693 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1696 for ( i
=starthere
;i
<GetChildCount();i
++)
1697 Item(i
)->m_arrIndex
= i
;
1701 // Returns (direct) child property with given name (or NULL if not found)
1702 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1706 for ( i
=0; i
<GetChildCount(); i
++ )
1708 wxPGProperty
* p
= Item(i
);
1709 if ( p
->m_name
== name
)
1713 // Does it have point, then?
1714 int pos
= name
.Find(wxS('.'));
1716 return (wxPGProperty
*) NULL
;
1718 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1720 if ( !p
|| !p
->GetChildCount() )
1723 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1726 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1728 unsigned int i
= hintIndex
;
1730 if ( i
>= GetChildCount() )
1733 unsigned int lastIndex
= i
- 1;
1735 if ( lastIndex
>= GetChildCount() )
1736 lastIndex
= GetChildCount() - 1;
1740 wxPGProperty
* p
= Item(i
);
1741 if ( p
->m_name
== name
)
1744 if ( i
== lastIndex
)
1748 if ( i
== GetChildCount() )
1755 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1757 // Returns height of children, recursively, and
1758 // by taking expanded/collapsed status into account.
1760 // iMax is used when finding property y-positions.
1766 iMax_
= GetChildCount();
1768 unsigned int iMax
= iMax_
;
1770 wxASSERT( iMax
<= GetChildCount() );
1772 if ( !IsExpanded() && GetParent() )
1777 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1779 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1781 if ( !pwc
->IsExpanded() ||
1782 pwc
->GetChildCount() == 0 )
1785 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1794 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1796 wxASSERT( nextItemY
);
1798 // Linear search at the moment
1800 // nextItemY = y of next visible property, final value will be written back.
1801 wxPGProperty
* result
= NULL
;
1802 wxPGProperty
* current
= NULL
;
1803 unsigned int iy
= *nextItemY
;
1805 unsigned int iMax
= GetChildCount();
1809 wxPGProperty
* pwc
= Item(i
);
1811 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1822 if ( pwc
->IsExpanded() &&
1823 pwc
->GetChildCount() > 0 )
1825 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1837 if ( !result
&& y
< iy
)
1844 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1846 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1849 return (wxPGProperty
*) result
;
1852 void wxPGProperty::Empty()
1855 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1857 for ( i
=0; i
<GetChildCount(); i
++ )
1859 wxPGProperty
* p
= (wxPGProperty
*) Item(i
);
1867 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1868 int WXUNUSED(childIndex
),
1869 wxVariant
& WXUNUSED(childValue
) ) const
1873 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1877 const wxVariantList
* pList
= NULL
;
1878 wxVariantList::const_iterator node
;
1882 pList
= &pendingList
->GetList();
1883 node
= pList
->begin();
1886 for ( i
=0; i
<GetChildCount(); i
++ )
1888 wxPGProperty
* child
= Item(i
);
1889 const wxVariant
* listValue
= NULL
;
1894 const wxString
& childName
= child
->GetBaseName();
1896 for ( ; node
!= pList
->end(); node
++ )
1898 const wxVariant
& item
= *((const wxVariant
*)*node
);
1899 if ( item
.GetName() == childName
)
1909 value
= child
->GetValue();
1911 if ( value
.IsNull() )
1914 // Check recursively
1915 if ( child
->GetChildCount() )
1917 const wxVariant
* childList
= NULL
;
1919 if ( listValue
&& wxPGIsVariantType(*listValue
, list
) )
1920 childList
= listValue
;
1922 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1930 wxPGProperty
* wxPGProperty::UpdateParentValues()
1932 wxPGProperty
* parent
= m_parent
;
1933 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1934 !parent
->IsCategory() && !parent
->IsRoot() )
1937 parent
->GenerateComposedValue(s
, 0);
1938 parent
->m_value
= s
;
1939 return parent
->UpdateParentValues();
1944 bool wxPGProperty::IsTextEditable() const
1946 if ( HasFlag(wxPG_PROP_READONLY
) )
1949 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1951 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1958 // Call for after sub-properties added with AddChild
1959 void wxPGProperty::PrepareSubProperties()
1961 wxPropertyGridPageState
* state
= GetParentState();
1965 if ( !GetChildCount() )
1968 wxByte depth
= m_depth
+ 1;
1969 wxByte depthBgCol
= m_depthBgCol
;
1971 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1973 wxByte bgColIndex
= m_bgColIndex
;
1974 wxByte fgColIndex
= m_fgColIndex
;
1977 // Set some values to the children
1980 wxPGProperty
* nparent
= this;
1982 while ( i
< nparent
->GetChildCount() )
1984 wxPGProperty
* np
= nparent
->Item(i
);
1986 np
->m_parentState
= state
;
1987 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
1988 np
->m_depth
= depth
;
1989 np
->m_depthBgCol
= depthBgCol
;
1990 np
->m_bgColIndex
= bgColIndex
;
1991 np
->m_fgColIndex
= fgColIndex
;
1993 // Also handle children of children
1994 if ( np
->GetChildCount() > 0 )
2000 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
2001 nparent
->SetExpanded(false);
2010 // After reaching last sibling, go back to processing
2011 // siblings of the parent
2012 while ( i
>= nparent
->GetChildCount() )
2014 // Exit the loop when top parent hit
2015 if ( nparent
== this )
2020 i
= nparent
->GetArrIndex() + 1;
2021 nparent
= nparent
->GetParent();
2026 // Call after fixed sub-properties added/removed after creation.
2027 // if oldSelInd >= 0 and < new max items, then selection is
2028 // moved to it. Note: oldSelInd -2 indicates that this property
2029 // should be selected.
2030 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2032 wxPropertyGridPageState
* state
= GetParentState();
2033 wxPropertyGrid
* grid
= state
->GetGrid();
2035 PrepareSubProperties();
2037 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2038 if ( oldSelInd
>= (int)m_children
.GetCount() )
2039 oldSelInd
= (int)m_children
.GetCount() - 1;
2041 if ( oldSelInd
>= 0 )
2042 sel
= (wxPGProperty
*) m_children
[oldSelInd
];
2043 else if ( oldSelInd
== -2 )
2047 state
->DoSelectProperty(sel
);
2049 if ( state
== grid
->GetState() )
2051 grid
->GetPanel()->Refresh();
2055 // -----------------------------------------------------------------------
2057 // -----------------------------------------------------------------------
2059 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2060 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2063 wxPGRootProperty::wxPGRootProperty()
2067 m_name
= wxS("<root>");
2074 wxPGRootProperty::~wxPGRootProperty()
2079 // -----------------------------------------------------------------------
2080 // wxPropertyCategory
2081 // -----------------------------------------------------------------------
2083 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2084 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2086 void wxPropertyCategory::Init()
2088 // don't set colour - prepareadditem method should do this
2089 SetParentalType(wxPG_PROP_CATEGORY
);
2090 m_capFgColIndex
= 1;
2094 wxPropertyCategory::wxPropertyCategory()
2101 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2102 : wxPGProperty(label
,name
)
2108 wxPropertyCategory::~wxPropertyCategory()
2113 wxString
wxPropertyCategory::GetValueAsString( int ) const
2115 return wxEmptyString
;
2118 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2120 if ( m_textExtent
> 0 )
2121 return m_textExtent
;
2123 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2127 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2130 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2134 // -----------------------------------------------------------------------
2135 // wxPGAttributeStorage
2136 // -----------------------------------------------------------------------
2138 wxPGAttributeStorage::wxPGAttributeStorage()
2142 wxPGAttributeStorage::~wxPGAttributeStorage()
2144 wxPGHashMapS2P::iterator it
;
2146 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2148 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2153 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2155 wxVariantData
* data
= value
.GetData();
2158 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2159 if ( it
!= m_map
.end() )
2160 ((wxVariantData
*)it
->second
)->DecRef();