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());
1607 wxPGProperty
* wxPGPropArgCls::GetPtr( wxPropertyGridInterface
* methods
) const
1611 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
1612 return m_ptr
.property
;
1614 else if ( m_isName
== 1 )
1615 return methods
->GetPropertyByNameA(*m_ptr
.name
);
1616 else if ( m_isName
== 2 )
1617 return methods
->GetPropertyByNameA(m_ptr
.rawname
);
1618 // 3 is like 1, but ptr is freed in dtor - only needed by wxPython bindings.
1619 else if ( m_isName
== 3 )
1620 return methods
->GetPropertyByNameA(*m_ptr
.name
);
1622 wxASSERT( m_isName
<= 3 );
1626 // This is used by Insert etc.
1627 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1629 if ( index
< 0 || (size_t)index
>= m_children
.GetCount() )
1631 if ( correct_mode
) prop
->m_arrIndex
= m_children
.GetCount();
1632 m_children
.Add( prop
);
1636 m_children
.Insert( prop
, index
);
1637 if ( correct_mode
) FixIndexesOfChildren( index
);
1640 prop
->m_parent
= this;
1643 // This is used by properties that have fixed sub-properties
1644 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1646 wxASSERT_MSG( prop
->GetBaseName().length(),
1647 "Property's children must have unique, non-empty names within their scope" );
1649 prop
->m_arrIndex
= m_children
.GetCount();
1650 m_children
.Add( prop
);
1652 int custImgHeight
= prop
->OnMeasureImage().y
;
1653 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1654 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1656 prop
->m_parent
= this;
1660 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1662 wxASSERT( GetChildCount() );
1663 wxASSERT( !IsCategory() );
1665 *value
= GetValue();
1667 if ( !list
.GetCount() )
1670 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1672 bool allChildrenSpecified
;
1674 // Don't fully update aggregate properties unless all children have
1676 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1677 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1679 allChildrenSpecified
= true;
1681 wxVariant childValue
= list
[0];
1685 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1687 for ( i
=0; i
<GetChildCount(); i
++ )
1689 const wxPGProperty
* child
= Item(i
);
1691 if ( childValue
.GetName() == child
->GetBaseName() )
1693 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1695 if ( wxPGIsVariantType(childValue
, list
) )
1697 wxVariant
cv2(child
->GetValue());
1698 child
->AdaptListToValue(childValue
, &cv2
);
1702 if ( allChildrenSpecified
)
1703 ChildChanged(*value
, i
, childValue
);
1705 if ( n
== (unsigned int)list
.GetCount() )
1707 childValue
= list
[n
];
1713 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1716 for ( i
=starthere
;i
<GetChildCount();i
++)
1717 Item(i
)->m_arrIndex
= i
;
1721 // Returns (direct) child property with given name (or NULL if not found)
1722 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1726 for ( i
=0; i
<GetChildCount(); i
++ )
1728 wxPGProperty
* p
= Item(i
);
1729 if ( p
->m_name
== name
)
1733 // Does it have point, then?
1734 int pos
= name
.Find(wxS('.'));
1736 return (wxPGProperty
*) NULL
;
1738 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1740 if ( !p
|| !p
->GetChildCount() )
1743 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1746 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1748 unsigned int i
= hintIndex
;
1750 if ( i
>= GetChildCount() )
1753 unsigned int lastIndex
= i
- 1;
1755 if ( lastIndex
>= GetChildCount() )
1756 lastIndex
= GetChildCount() - 1;
1760 wxPGProperty
* p
= Item(i
);
1761 if ( p
->m_name
== name
)
1764 if ( i
== lastIndex
)
1768 if ( i
== GetChildCount() )
1775 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1777 // Returns height of children, recursively, and
1778 // by taking expanded/collapsed status into account.
1780 // iMax is used when finding property y-positions.
1786 iMax_
= GetChildCount();
1788 unsigned int iMax
= iMax_
;
1790 wxASSERT( iMax
<= GetChildCount() );
1792 if ( !IsExpanded() && GetParent() )
1797 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1799 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1801 if ( !pwc
->IsExpanded() ||
1802 pwc
->GetChildCount() == 0 )
1805 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1814 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1816 wxASSERT( nextItemY
);
1818 // Linear search at the moment
1820 // nextItemY = y of next visible property, final value will be written back.
1821 wxPGProperty
* result
= NULL
;
1822 wxPGProperty
* current
= NULL
;
1823 unsigned int iy
= *nextItemY
;
1825 unsigned int iMax
= GetChildCount();
1829 wxPGProperty
* pwc
= Item(i
);
1831 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1842 if ( pwc
->IsExpanded() &&
1843 pwc
->GetChildCount() > 0 )
1845 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1857 if ( !result
&& y
< iy
)
1864 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1866 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1869 return (wxPGProperty
*) result
;
1872 void wxPGProperty::Empty()
1875 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1877 for ( i
=0; i
<GetChildCount(); i
++ )
1879 wxPGProperty
* p
= (wxPGProperty
*) Item(i
);
1887 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1888 int WXUNUSED(childIndex
),
1889 wxVariant
& WXUNUSED(childValue
) ) const
1893 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1897 const wxVariantList
* pList
= NULL
;
1898 wxVariantList::const_iterator node
;
1902 pList
= &pendingList
->GetList();
1903 node
= pList
->begin();
1906 for ( i
=0; i
<GetChildCount(); i
++ )
1908 wxPGProperty
* child
= Item(i
);
1909 const wxVariant
* listValue
= NULL
;
1914 const wxString
& childName
= child
->GetBaseName();
1916 for ( ; node
!= pList
->end(); node
++ )
1918 const wxVariant
& item
= *((const wxVariant
*)*node
);
1919 if ( item
.GetName() == childName
)
1929 value
= child
->GetValue();
1931 if ( value
.IsNull() )
1934 // Check recursively
1935 if ( child
->GetChildCount() )
1937 const wxVariant
* childList
= NULL
;
1939 if ( listValue
&& wxPGIsVariantType(*listValue
, list
) )
1940 childList
= listValue
;
1942 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1950 wxPGProperty
* wxPGProperty::UpdateParentValues()
1952 wxPGProperty
* parent
= m_parent
;
1953 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1954 !parent
->IsCategory() && !parent
->IsRoot() )
1957 parent
->GenerateComposedValue(s
, 0);
1958 parent
->m_value
= s
;
1959 return parent
->UpdateParentValues();
1964 bool wxPGProperty::IsTextEditable() const
1966 if ( HasFlag(wxPG_PROP_READONLY
) )
1969 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1971 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1978 // Call for after sub-properties added with AddChild
1979 void wxPGProperty::PrepareSubProperties()
1981 wxPropertyGridPageState
* state
= GetParentState();
1985 if ( !GetChildCount() )
1988 wxByte depth
= m_depth
+ 1;
1989 wxByte depthBgCol
= m_depthBgCol
;
1991 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1993 wxByte bgColIndex
= m_bgColIndex
;
1994 wxByte fgColIndex
= m_fgColIndex
;
1997 // Set some values to the children
2000 wxPGProperty
* nparent
= this;
2002 while ( i
< nparent
->GetChildCount() )
2004 wxPGProperty
* np
= nparent
->Item(i
);
2006 np
->m_parentState
= state
;
2007 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
2008 np
->m_depth
= depth
;
2009 np
->m_depthBgCol
= depthBgCol
;
2010 np
->m_bgColIndex
= bgColIndex
;
2011 np
->m_fgColIndex
= fgColIndex
;
2013 // Also handle children of children
2014 if ( np
->GetChildCount() > 0 )
2020 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
2021 nparent
->SetExpanded(false);
2030 // After reaching last sibling, go back to processing
2031 // siblings of the parent
2032 while ( i
>= nparent
->GetChildCount() )
2034 // Exit the loop when top parent hit
2035 if ( nparent
== this )
2040 i
= nparent
->GetArrIndex() + 1;
2041 nparent
= nparent
->GetParent();
2046 // Call after fixed sub-properties added/removed after creation.
2047 // if oldSelInd >= 0 and < new max items, then selection is
2048 // moved to it. Note: oldSelInd -2 indicates that this property
2049 // should be selected.
2050 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2052 wxPropertyGridPageState
* state
= GetParentState();
2053 wxPropertyGrid
* grid
= state
->GetGrid();
2055 PrepareSubProperties();
2057 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2058 if ( oldSelInd
>= (int)m_children
.GetCount() )
2059 oldSelInd
= (int)m_children
.GetCount() - 1;
2061 if ( oldSelInd
>= 0 )
2062 sel
= (wxPGProperty
*) m_children
[oldSelInd
];
2063 else if ( oldSelInd
== -2 )
2067 state
->DoSelectProperty(sel
);
2069 if ( state
== grid
->GetState() )
2071 grid
->GetPanel()->Refresh();
2075 // -----------------------------------------------------------------------
2077 // -----------------------------------------------------------------------
2079 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2080 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2083 wxPGRootProperty::wxPGRootProperty()
2087 m_name
= wxS("<root>");
2094 wxPGRootProperty::~wxPGRootProperty()
2099 // -----------------------------------------------------------------------
2100 // wxPropertyCategory
2101 // -----------------------------------------------------------------------
2103 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2104 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2106 void wxPropertyCategory::Init()
2108 // don't set colour - prepareadditem method should do this
2109 SetParentalType(wxPG_PROP_CATEGORY
);
2110 m_capFgColIndex
= 1;
2114 wxPropertyCategory::wxPropertyCategory()
2121 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2122 : wxPGProperty(label
,name
)
2128 wxPropertyCategory::~wxPropertyCategory()
2133 wxString
wxPropertyCategory::GetValueAsString( int ) const
2135 return wxEmptyString
;
2138 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2140 if ( m_textExtent
> 0 )
2141 return m_textExtent
;
2143 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2147 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2150 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2154 // -----------------------------------------------------------------------
2155 // wxPGAttributeStorage
2156 // -----------------------------------------------------------------------
2158 wxPGAttributeStorage::wxPGAttributeStorage()
2162 wxPGAttributeStorage::~wxPGAttributeStorage()
2164 wxPGHashMapS2P::iterator it
;
2166 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2168 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2173 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2175 wxVariantData
* data
= value
.GetData();
2178 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2179 if ( it
!= m_map
.end() )
2180 ((wxVariantData
*)it
->second
)->DecRef();