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"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
34 #include "wx/settings.h"
38 #include "wx/propgrid/propgrid.h"
41 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
44 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
46 #if wxPG_COMPATIBILITY_1_4
48 // Used to establish backwards compatiblity
49 const char* g_invalidStringContent
= "@__TOTALLY_INVALID_STRING__@";
53 // -----------------------------------------------------------------------
55 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
57 #if defined(__WXMSW__) && !defined(__WXWINCE__)
58 // FIXME: Use DrawFocusRect code above (currently it draws solid line
59 // for caption focus but works ok for other stuff).
60 // Also, it seems that this code may not work in future wx versions.
61 dc
.SetLogicalFunction(wxINVERT
);
63 wxPen
pen(*wxBLACK
,1,wxDOT
);
64 pen
.SetCap(wxCAP_BUTT
);
66 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
68 dc
.DrawRectangle(rect
);
70 dc
.SetLogicalFunction(wxCOPY
);
72 dc
.SetLogicalFunction(wxINVERT
);
74 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
75 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
77 dc
.DrawRectangle(rect
);
79 dc
.SetLogicalFunction(wxCOPY
);
83 // -----------------------------------------------------------------------
85 // -----------------------------------------------------------------------
87 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
89 int WXUNUSED(item
) ) const
94 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
95 int xOffset
, const wxString
& text
) const
98 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
100 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
101 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
104 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
105 int xOffset
, const wxString
& text
,
106 wxPGProperty
* property
,
107 const wxPGEditor
* editor
) const
110 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
112 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
119 rect2
.height
-= yOffset
;
120 editor
->DrawValue( dc
, rect2
, property
, text
);
125 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
130 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
132 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
133 wxPGDrawFocusRect(dc
,focusRect
);
136 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
140 if ( !(flags
& Selected
) )
142 // Draw using wxPGCell information, if available
143 wxColour fgCol
= cell
.GetFgCol();
145 dc
.SetTextForeground(fgCol
);
147 wxColour bgCol
= cell
.GetBgCol();
152 dc
.DrawRectangle(rect
);
156 const wxBitmap
& bmp
= cell
.GetBitmap();
158 // In control, do not draw oversized bitmap
159 (!(flags
& Control
) || bmp
.GetHeight() < rect
.height
)
163 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
164 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
166 imageOffset
= bmp
.GetWidth();
172 // -----------------------------------------------------------------------
173 // wxPGDefaultRenderer
174 // -----------------------------------------------------------------------
176 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
177 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
178 int column
, int item
, int flags
) const
180 bool isUnspecified
= property
->IsValueUnspecified();
182 if ( column
== 1 && item
== -1 )
184 int cmnVal
= property
->GetCommonValue();
188 if ( !isUnspecified
)
189 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
194 const wxPGEditor
* editor
= NULL
;
195 const wxPGCell
* cell
= property
->GetCell(column
);
201 if ( column
== 1 && (flags
& Control
) )
203 int selectedIndex
= property
->GetChoiceSelection();
204 if ( selectedIndex
!= wxNOT_FOUND
)
206 const wxPGChoices
& choices
= property
->GetChoices();
207 const wxPGCell
* ccell
= &choices
[selectedIndex
];
209 ( ccell
->GetBitmap().IsOk() || ccell
->GetFgCol().IsOk() || ccell
->GetBgCol().IsOk() )
217 int preDrawFlags
= flags
;
219 if ( propertyGrid
->GetInternalFlags() & wxPG_FL_CELL_OVERRIDES_SEL
)
220 preDrawFlags
= preDrawFlags
& ~(Selected
);
222 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
223 text
= cell
->GetText();
224 if ( text
== wxS("@!") )
227 text
= property
->GetLabel();
228 else if ( column
== 1 )
229 text
= property
->GetValueAsString();
231 text
= wxEmptyString
;
234 else if ( column
== 0 )
237 DrawText( dc
, rect
, 0, property
->GetLabel() );
239 else if ( column
== 1 )
241 if ( !isUnspecified
)
243 editor
= property
->GetColumnEditor(column
);
245 // Regular property value
247 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
249 wxPGPaintData paintdata
;
250 paintdata
.m_parent
= propertyGrid
;
251 paintdata
.m_choiceItem
= item
;
253 if ( imageSize
.x
> 0 )
255 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
256 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
257 wxPG_CUSTOM_IMAGE_WIDTH
,
258 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
260 /*if ( imageSize.x == wxPG_FULL_CUSTOM_PAINT_WIDTH )
262 imageRect.width = m_width - imageRect.x;
265 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
267 paintdata
.m_drawnWidth
= imageSize
.x
;
268 paintdata
.m_drawnHeight
= imageSize
.y
;
270 if ( !isUnspecified
)
272 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
276 dc
.SetBrush(*wxWHITE_BRUSH
);
277 dc
.DrawRectangle(imageRect
);
280 imageOffset
= paintdata
.m_drawnWidth
;
283 text
= property
->GetValueAsString();
286 if ( propertyGrid
->GetColumnCount() <= 2 )
288 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
289 if ( unitsString
.length() )
290 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
294 if ( text
.length() == 0 )
296 // Try to show inline help if no text
297 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
298 if ( !vInlineHelp
.IsNull() )
300 text
= vInlineHelp
.GetString();
301 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
305 else if ( column
== 2 )
308 if ( !text
.length() )
309 text
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
312 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
314 // active caption gets nice dotted rectangle
315 if ( property
->IsCategory() /*&& column == 0*/ )
317 if ( flags
& Selected
)
319 if ( imageOffset
> 0 )
320 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
322 DrawCaptionSelectionRect( dc
,
323 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
324 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
325 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
326 propertyGrid
->GetCaptionFont())
327 +(wxPG_CAPRECTXMARGIN
*2),
328 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
333 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
337 if ( property
&& column
== 1 )
341 wxBitmap
* bmp
= property
->GetValueImage();
343 if ( bmp
&& bmp
->Ok() )
344 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
350 // -----------------------------------------------------------------------
352 // -----------------------------------------------------------------------
358 wxPGCell::wxPGCell( const wxString
& text
,
359 const wxBitmap
& bitmap
,
360 const wxColour
& fgCol
,
361 const wxColour
& bgCol
)
362 : m_bitmap(bitmap
), m_fgCol(fgCol
), m_bgCol(bgCol
)
367 // -----------------------------------------------------------------------
369 // -----------------------------------------------------------------------
371 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
373 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
375 void wxPGProperty::Init()
381 m_parentState
= (wxPropertyGridPageState
*) NULL
;
384 m_clientObject
= NULL
;
386 m_customEditor
= (wxPGEditor
*) NULL
;
388 m_validator
= (wxValidator
*) NULL
;
390 m_valueBitmap
= (wxBitmap
*) NULL
;
392 m_maxLen
= 0; // infinite maximum length
394 m_flags
= wxPG_PROP_PROPERTY
;
404 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
406 // We really need to check if &label and &name are NULL pointers
407 // (this can if we are called before property grid has been initalized)
409 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
412 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
415 DoSetName( m_label
);
420 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
421 wxPropertyGrid
* propgrid
)
424 // Called after property has been added to grid or page
425 // (so propgrid can be NULL, too).
427 wxPGProperty
* parent
= m_parent
;
428 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
430 m_parentState
= pageState
;
432 #if wxPG_COMPATIBILITY_1_4
433 // Make sure deprecated virtual functions are not implemented
434 wxString s
= GetValueAsString( 0xFFFF );
435 wxASSERT_MSG( s
== g_invalidStringContent
,
436 "Implement ValueToString() instead of GetValueAsString()" );
441 m_bgColIndex
= parent
->m_bgColIndex
;
442 m_fgColIndex
= parent
->m_fgColIndex
;
445 // If in hideable adding mode, or if assigned parent is hideable, then
446 // make this one hideable.
448 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
449 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
451 SetFlag( wxPG_PROP_HIDDEN
);
453 // Set custom image flag.
454 int custImgHeight
= OnMeasureImage().y
;
455 if ( custImgHeight
< 0 )
457 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
460 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
461 SetFlag(wxPG_PROP_NOEDITOR
);
463 // Make sure parent has some parental flags
464 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
465 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
469 // This is not a category.
473 unsigned char depth
= 1;
476 depth
= parent
->m_depth
;
477 if ( !parent
->IsCategory() )
481 unsigned char greyDepth
= depth
;
485 wxPropertyCategory
* pc
;
487 if ( parent
->IsCategory() )
488 pc
= (wxPropertyCategory
* ) parent
;
490 // This conditional compile is necessary to
491 // bypass some compiler bug.
492 pc
= pageState
->GetPropertyCategory(parent
);
495 greyDepth
= pc
->GetDepth();
497 greyDepth
= parent
->m_depthBgCol
;
500 m_depthBgCol
= greyDepth
;
504 // This is a category.
507 unsigned char depth
= 1;
510 depth
= parent
->m_depth
+ 1;
513 m_depthBgCol
= depth
;
517 // Has initial children
518 if ( GetChildCount() )
520 FlagType parentalFlags
= m_flags
& wxPG_PROP_PARENTAL_FLAGS
;
522 // Check parental flags
523 wxASSERT_MSG( parentalFlags
,
524 "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
525 "SetFlag(wxPG_PROP_AGGREGATE) before calling"
526 "wxPGProperty::AddChild()." );
528 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
530 // Properties with private children are not expanded by default.
533 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
535 // ...unless it cannot be expanded by user and therefore must
536 // remain visible at all times
541 // Prepare children recursively
542 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
544 wxPGProperty
* child
= Item(i
);
545 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
548 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
549 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
553 wxPGProperty::wxPGProperty()
560 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
567 wxPGProperty::~wxPGProperty()
569 delete m_clientObject
;
571 Empty(); // this deletes items
573 delete m_valueBitmap
;
580 for ( i
=0; i
<m_cells
.size(); i
++ )
581 delete (wxPGCell
*) m_cells
[i
];
583 // This makes it easier for us to detect dangling pointers
588 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
590 wxPGProperty
* parent
= m_parent
;
593 if ( parent
== candidate
)
595 parent
= parent
->m_parent
;
601 wxString
wxPGProperty::GetName() const
603 wxPGProperty
* parent
= GetParent();
605 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
608 return m_parent
->GetName() + wxS(".") + m_name
;
611 wxPropertyGrid
* wxPGProperty::GetGrid() const
613 if ( !m_parentState
)
615 return m_parentState
->GetGrid();
618 int wxPGProperty::Index( const wxPGProperty
* p
) const
620 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
622 if ( p
== m_children
[i
] )
628 void wxPGProperty::UpdateControl( wxWindow
* primary
)
631 GetEditorClass()->UpdateControl(this, primary
);
634 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
639 void wxPGProperty::OnSetValue()
643 void wxPGProperty::RefreshChildren ()
647 wxString
wxPGProperty::GetColumnText( unsigned int col
) const
649 wxPGCell
* cell
= GetCell(col
);
652 return cell
->GetText();
659 return GetDisplayedString();
661 return GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
664 return wxEmptyString
;
667 void wxPGProperty::GenerateComposedValue( wxString
& text
,
669 const wxVariantList
* valueOverrides
,
670 wxPGHashMapS2S
* childResults
) const
673 int iMax
= m_children
.size();
679 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
680 !(argFlags
& wxPG_FULL_VALUE
) )
681 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
683 int iMaxMinusOne
= iMax
-1;
685 if ( !IsTextEditable() )
686 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
688 wxPGProperty
* curChild
= m_children
[0];
690 bool overridesLeft
= false;
691 wxVariant overrideValue
;
692 wxVariantList::const_iterator node
;
694 if ( valueOverrides
)
696 node
= valueOverrides
->begin();
697 if ( node
!= valueOverrides
->end() )
699 overrideValue
= *node
;
700 overridesLeft
= true;
704 for ( i
= 0; i
< iMax
; i
++ )
706 wxVariant childValue
;
708 wxString childLabel
= curChild
->GetLabel();
710 // Check for value override
711 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
713 if ( !overrideValue
.IsNull() )
714 childValue
= overrideValue
;
716 childValue
= curChild
->GetValue();
718 if ( node
!= valueOverrides
->end() )
719 overrideValue
= *node
;
721 overridesLeft
= false;
725 childValue
= curChild
->GetValue();
729 if ( !childValue
.IsNull() )
731 if ( overridesLeft
&&
732 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
733 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
735 wxVariantList
& childList
= childValue
.GetList();
736 GenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
737 &childList
, childResults
);
741 s
= curChild
->ValueToString(childValue
,
742 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
746 if ( childResults
&& curChild
->GetChildCount() )
747 (*childResults
)[curChild
->GetName()] = s
;
750 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
753 if ( !curChild
->GetChildCount() || skip
)
756 text
+= wxS("[") + s
+ wxS("]");
758 if ( i
< iMaxMinusOne
)
760 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
761 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
762 !(argFlags
& wxPG_FULL_VALUE
) )
767 if ( !curChild
->GetChildCount() )
773 curChild
= m_children
[i
+1];
777 // Remove superfluous semicolon and space
779 if ( text
.EndsWith(wxS("; "), &rest
) )
782 if ( (unsigned int)i
< m_children
.size() )
783 text
+= wxS("; ...");
786 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
789 wxCHECK_MSG( GetChildCount() > 0,
791 "If user property does not have any children, it must "
792 "override GetValueAsString" );
794 // FIXME: Currently code below only works if value is actually m_value
795 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
796 "Sorry, currently default wxPGProperty::ValueToString() "
797 "implementation only works if value is m_value." );
800 GenerateComposedValue(text
, argFlags
);
804 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
806 #if wxPG_COMPATIBILITY_1_4
807 // This is backwards compatibility test
808 // That is, to make sure this function is not overridden
809 // (instead, ValueToString() should be).
810 if ( argFlags
== 0xFFFF )
812 // Do not override! (for backwards compliancy)
813 return g_invalidStringContent
;
817 if ( IsValueUnspecified() )
818 return wxEmptyString
;
820 if ( m_commonValue
== -1 )
822 wxVariant
value(GetValue());
823 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
827 // Return common value's string representation
828 wxPropertyGrid
* pg
= GetGrid();
829 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
831 if ( argFlags
& wxPG_FULL_VALUE
)
833 return cv
->GetLabel();
835 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
837 return cv
->GetEditableText();
841 return cv
->GetLabel();
845 wxString
wxPGProperty::GetValueString( int argFlags
) const
847 return GetValueAsString(argFlags
);
850 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
852 variant
= (long)number
;
856 // Convert semicolon delimited tokens into child values.
857 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
859 if ( !GetChildCount() )
862 unsigned int curChild
= 0;
864 unsigned int iMax
= m_children
.size();
866 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
867 !(argFlags
& wxPG_FULL_VALUE
) )
868 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
870 bool changed
= false;
875 // Its best only to add non-empty group items
876 bool addOnlyIfNotEmpty
= false;
877 const wxChar delimeter
= wxS(';');
879 size_t tokenStart
= 0xFFFFFF;
881 wxVariantList temp_list
;
882 wxVariant
list(temp_list
);
884 int propagatedFlags
= argFlags
& wxPG_REPORT_ERROR
;
887 bool debug_print
= false;
892 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
895 wxString::const_iterator it
= text
.begin();
898 if ( it
!= text
.end() )
905 if ( tokenStart
!= 0xFFFFFF )
908 if ( a
== delimeter
|| a
== 0 )
910 token
= text
.substr(tokenStart
,pos
-tokenStart
);
912 size_t len
= token
.length();
914 if ( !addOnlyIfNotEmpty
|| len
> 0 )
916 const wxPGProperty
* child
= Item(curChild
);
919 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().c_str());
924 bool wasUnspecified
= child
->IsValueUnspecified();
926 wxVariant
variant(child
->GetValueRef());
927 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
929 variant
.SetName(child
->GetBaseName());
931 // Clear unspecified flag only if OnSetValue() didn't
933 if ( child
->IsValueUnspecified() &&
934 (wasUnspecified
|| !UsesAutoUnspecified()) )
936 variant
= child
->GetDefaultValue();
939 list
.Append(variant
);
946 // Empty, becomes unspecified
948 variant2
.SetName(child
->GetBaseName());
949 list
.Append(variant2
);
954 if ( curChild
>= iMax
)
958 tokenStart
= 0xFFFFFF;
963 // Token is not running
967 addOnlyIfNotEmpty
= false;
969 // Is this a group of tokens?
974 if ( it
!= text
.end() ) it
++;
976 size_t startPos
= pos
;
978 // Group item - find end
979 while ( it
!= text
.end() && depth
> 0 )
987 else if ( a
== wxS('[') )
991 token
= text
.substr(startPos
,pos
-startPos
-1);
993 if ( !token
.length() )
996 const wxPGProperty
* child
= Item(curChild
);
998 wxVariant oldChildValue
= child
->GetValue();
999 wxVariant
variant(oldChildValue
);
1000 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
1001 if ( stvRes
|| (variant
!= oldChildValue
) )
1008 // Failed, becomes unspecified
1013 variant
.SetName(child
->GetBaseName());
1014 list
.Append(variant
);
1017 if ( curChild
>= iMax
)
1020 addOnlyIfNotEmpty
= true;
1022 tokenStart
= 0xFFFFFF;
1028 if ( a
== delimeter
)
1041 if ( it
!= text
.end() )
1058 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1060 wxVariant
variant(m_value
);
1061 bool res
= StringToValue(variant
, text
, argFlags
);
1067 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1069 wxVariant
variant(m_value
);
1070 bool res
= IntToValue(variant
, number
, argFlags
);
1076 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1078 if ( m_valueBitmap
)
1079 return wxSize(m_valueBitmap
->GetWidth(),-1);
1084 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1086 return wxPGGlobalVars
->m_defaultRenderer
;
1089 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1093 wxBitmap
* bmp
= m_valueBitmap
;
1095 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1097 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1099 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1102 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1104 return wxPGEditor_TextCtrl
;
1107 // Default extra property event handling - that is, none at all.
1108 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1114 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1116 // If auto unspecified values are not wanted (via window or property style),
1117 // then get default value instead of wxNullVariant.
1118 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1119 !UsesAutoUnspecified() )
1121 value
= GetDefaultValue();
1124 if ( !value
.IsNull() )
1126 wxVariant tempListVariant
;
1129 // List variants are reserved a special purpose
1130 // as intermediate containers for child values
1131 // of properties with children.
1132 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1135 // However, situation is different for composed string properties
1136 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1138 tempListVariant
= value
;
1139 pList
= &tempListVariant
;
1143 AdaptListToValue(value
, &newValue
);
1145 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1148 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1149 flags
|= wxPG_SETVAL_AGGREGATED
;
1151 if ( pList
&& !pList
->IsNull() )
1153 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1154 wxASSERT( GetChildCount() );
1155 wxASSERT( !IsCategory() );
1157 wxVariantList
& list
= pList
->GetList();
1158 wxVariantList::iterator node
;
1161 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1163 // Children in list can be in any order, but we will give hint to
1164 // GetPropertyByNameWH(). This optimizes for full list parsing.
1165 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
1167 wxVariant
& childValue
= *((wxVariant
*)*node
);
1168 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1171 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1172 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1174 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1176 wxVariant listRefCopy
= childValue
;
1177 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1181 wxVariant oldVal
= child
->GetValue();
1182 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1185 else if ( child
->GetValue() != childValue
)
1187 // For aggregate properties, we will trust RefreshChildren()
1188 // to update child values.
1189 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1190 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1191 if ( flags
& wxPG_SETVAL_BY_USER
)
1192 child
->SetFlag(wxPG_PROP_MODIFIED
);
1199 if ( !value
.IsNull() )
1204 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1205 UpdateParentValues();
1208 if ( flags
& wxPG_SETVAL_BY_USER
)
1209 SetFlag(wxPG_PROP_MODIFIED
);
1211 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1216 if ( m_commonValue
!= -1 )
1218 wxPropertyGrid
* pg
= GetGrid();
1219 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1225 // Set children to unspecified, but only if aggregate or
1226 // value is <composed>
1227 if ( AreChildrenComponents() )
1230 for ( i
=0; i
<GetChildCount(); i
++ )
1231 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1236 // Update editor control
1239 // We need to check for these, otherwise GetGrid() may fail.
1240 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1245 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1247 GetGrid()->ValueChangeInEvent(value
);
1250 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1258 for ( i
= 0; i
< GetChildCount(); i
++ )
1259 Item(i
)->SetFlagRecursively(flag
, set
);
1262 void wxPGProperty::RefreshEditor()
1264 if ( m_parent
&& GetParentState() )
1266 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1267 if ( pg
->GetSelectedProperty() == this )
1269 wxWindow
* editor
= pg
->GetEditorControl();
1271 GetEditorClass()->UpdateControl( this, editor
);
1277 wxVariant
wxPGProperty::GetDefaultValue() const
1279 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1280 if ( !defVal
.IsNull() )
1283 wxVariant value
= GetValue();
1285 if ( !value
.IsNull() )
1287 wxString
valueType(value
.GetType());
1289 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1290 return wxPGVariant_Zero
;
1291 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1292 return wxPGVariant_EmptyString
;
1293 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1294 return wxPGVariant_False
;
1295 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1296 return wxVariant(0.0);
1297 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1298 return wxVariant(wxArrayString());
1299 if ( valueType
== wxS("wxLongLong") )
1300 return WXVARIANT(wxLongLong(0));
1301 if ( valueType
== wxS("wxULongLong") )
1302 return WXVARIANT(wxULongLong(0));
1303 if ( valueType
== wxS("wxColour") )
1304 return WXVARIANT(*wxBLACK
);
1306 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1307 return wxVariant(wxDateTime::Now());
1309 if ( valueType
== wxS("wxFont") )
1310 return WXVARIANT(*wxNORMAL_FONT
);
1311 if ( valueType
== wxS("wxPoint") )
1312 return WXVARIANT(wxPoint(0, 0));
1313 if ( valueType
== wxS("wxSize") )
1314 return WXVARIANT(wxSize(0, 0));
1320 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1322 if ( column
>= (int)m_cells
.size() )
1323 m_cells
.SetCount(column
+1, NULL
);
1325 delete (wxPGCell
*) m_cells
[column
];
1326 m_cells
[column
] = cellObj
;
1329 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1334 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1339 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1341 if ( DoSetAttribute( name
, value
) )
1343 // Support working without grid, when possible
1344 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1348 m_attributes
.Set( name
, value
);
1351 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1353 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1356 while ( attributes
.GetNext(it
, variant
) )
1357 SetAttribute( variant
.GetName(), variant
);
1360 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1366 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1368 return m_attributes
.FindValue(name
);
1371 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1373 wxVariant variant
= m_attributes
.FindValue(name
);
1375 if ( !variant
.IsNull() )
1376 return variant
.GetString();
1381 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1383 wxVariant variant
= m_attributes
.FindValue(name
);
1385 return wxPGVariantToInt(variant
, defVal
);
1388 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1391 wxVariant variant
= m_attributes
.FindValue(name
);
1393 if ( wxPGVariantToDouble(variant
, &retVal
) )
1399 wxVariant
wxPGProperty::GetAttributesAsList() const
1401 wxVariantList tempList
;
1402 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1404 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1407 while ( m_attributes
.GetNext(it
, variant
) )
1413 // Slots of utility flags are NULL
1414 const unsigned int gs_propFlagToStringSize
= 14;
1416 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1433 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1436 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1440 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1442 if ( relevantFlags
& a
)
1444 const wxChar
* fs
= gs_propFlagToString
[i
];
1456 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1460 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1462 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1464 const wxChar
* fs
= gs_propFlagToString
[i
];
1465 if ( fs
&& str
== fs
)
1471 WX_PG_TOKENIZER1_END()
1473 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1476 wxValidator
* wxPGProperty::DoGetValidator() const
1478 return (wxValidator
*) NULL
;
1481 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1483 wxPropertyGrid
* pg
= GetGrid();
1484 int sel
= GetChoiceSelection();
1488 if ( index
== wxNOT_FOUND
)
1489 index
= m_choices
.GetCount();
1494 m_choices
.Insert(label
, index
, value
);
1496 if ( sel
!= newSel
)
1497 SetChoiceSelection(newSel
);
1499 if ( this == pg
->GetSelection() )
1500 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1506 void wxPGProperty::DeleteChoice( int index
)
1508 wxPropertyGrid
* pg
= GetGrid();
1510 int sel
= GetChoiceSelection();
1513 // Adjust current value
1516 SetValueToUnspecified();
1519 else if ( index
< sel
)
1524 m_choices
.RemoveAt(index
);
1526 if ( sel
!= newSel
)
1527 SetChoiceSelection(newSel
);
1529 if ( this == pg
->GetSelection() )
1530 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1533 int wxPGProperty::GetChoiceSelection() const
1535 wxVariant value
= GetValue();
1536 wxString valueType
= value
.GetType();
1537 int index
= wxNOT_FOUND
;
1539 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1542 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1544 index
= value
.GetLong();
1546 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1548 index
= m_choices
.Index(value
.GetString());
1550 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1552 index
= value
.GetBool()? 1 : 0;
1558 void wxPGProperty::SetChoiceSelection( int newValue
)
1560 // Changes value of a property with choices, but only
1561 // works if the value type is long or string.
1562 wxString valueType
= GetValue().GetType();
1564 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1566 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1568 SetValue( m_choices
.GetLabel(newValue
) );
1570 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1572 SetValue( (long) newValue
);
1576 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1578 m_choices
.Assign(choices
);
1581 // This may be needed to trigger some initialization
1582 // (but don't do it if property is somewhat uninitialized)
1583 wxVariant defVal
= GetDefaultValue();
1584 if ( defVal
.IsNull() )
1594 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1596 const wxPGEditor
* editor
;
1598 if ( !m_customEditor
)
1600 editor
= DoGetEditorClass();
1603 editor
= m_customEditor
;
1606 // Maybe override editor if common value specified
1607 if ( GetDisplayedCommonValueCount() )
1609 // TextCtrlAndButton -> ComboBoxAndButton
1610 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1611 editor
= wxPGEditor_ChoiceAndButton
;
1613 // TextCtrl -> ComboBox
1614 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1615 editor
= wxPGEditor_ComboBox
;
1621 bool wxPGProperty::HasVisibleChildren() const
1625 for ( i
=0; i
<GetChildCount(); i
++ )
1627 wxPGProperty
* child
= Item(i
);
1629 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1636 bool wxPGProperty::RecreateEditor()
1638 wxPropertyGrid
* pg
= GetGrid();
1641 wxPGProperty
* selected
= pg
->GetSelection();
1642 if ( this == selected
)
1644 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1651 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1653 delete m_valueBitmap
;
1655 if ( &bmp
&& bmp
.Ok() )
1658 wxSize maxSz
= GetGrid()->GetImageSize();
1659 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1661 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1663 // Create a memory DC
1664 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1667 dc
.SelectObject(*bmpNew
);
1670 // FIXME: This is ugly - use image or wait for scaling patch.
1671 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1672 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1674 dc
.SetUserScale(scaleX
,scaleY
);
1676 dc
.DrawBitmap( bmp
, 0, 0 );
1678 m_valueBitmap
= bmpNew
;
1682 m_valueBitmap
= new wxBitmap(bmp
);
1685 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1689 m_valueBitmap
= NULL
;
1690 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1695 wxPGProperty
* wxPGProperty::GetMainParent() const
1697 const wxPGProperty
* curChild
= this;
1698 const wxPGProperty
* curParent
= m_parent
;
1700 while ( curParent
&& !curParent
->IsCategory() )
1702 curChild
= curParent
;
1703 curParent
= curParent
->m_parent
;
1706 return (wxPGProperty
*) curChild
;
1710 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1713 // Returns last visible sub-item, recursively.
1714 if ( !IsExpanded() || !GetChildCount() )
1717 return Last()->GetLastVisibleSubItem();
1721 bool wxPGProperty::IsVisible() const
1723 const wxPGProperty
* parent
;
1725 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1728 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1730 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1737 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1739 wxPropertyGridPageState
* state
= GetParentState();
1740 wxPropertyGrid
* propGrid
= state
->GetGrid();
1741 if ( state
== propGrid
->GetState() )
1747 int wxPGProperty::GetY2( int lh
) const
1749 const wxPGProperty
* parent
;
1750 const wxPGProperty
* child
= this;
1754 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1756 if ( !parent
->IsExpanded() )
1758 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1763 y
-= lh
; // need to reduce one level
1769 int wxPGProperty::GetY() const
1771 return GetY2(GetGrid()->GetRowHeight());
1774 // This is used by Insert etc.
1775 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1777 if ( index
< 0 || (size_t)index
>= m_children
.size() )
1779 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
1780 m_children
.push_back( prop
);
1784 m_children
.insert( m_children
.begin()+index
, prop
);
1785 if ( correct_mode
) FixIndicesOfChildren( index
);
1788 prop
->m_parent
= this;
1791 // This is used by properties that have fixed sub-properties
1792 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1794 wxASSERT_MSG( prop
->GetBaseName().length(),
1795 "Property's children must have unique, non-empty names within their scope" );
1797 prop
->m_arrIndex
= m_children
.size();
1798 m_children
.push_back( prop
);
1800 int custImgHeight
= prop
->OnMeasureImage().y
;
1801 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1802 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1804 prop
->m_parent
= this;
1807 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
1809 wxArrayPGProperty::iterator it
;
1810 wxArrayPGProperty
& children
= m_children
;
1812 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
1816 m_children
.erase(it
);
1822 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1824 wxASSERT( GetChildCount() );
1825 wxASSERT( !IsCategory() );
1827 *value
= GetValue();
1829 if ( !list
.GetCount() )
1832 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1834 bool allChildrenSpecified
;
1836 // Don't fully update aggregate properties unless all children have
1838 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1839 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1841 allChildrenSpecified
= true;
1843 wxVariant childValue
= list
[0];
1847 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1849 for ( i
=0; i
<GetChildCount(); i
++ )
1851 const wxPGProperty
* child
= Item(i
);
1853 if ( childValue
.GetName() == child
->GetBaseName() )
1855 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1857 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1859 wxVariant
cv2(child
->GetValue());
1860 child
->AdaptListToValue(childValue
, &cv2
);
1864 if ( allChildrenSpecified
)
1865 ChildChanged(*value
, i
, childValue
);
1867 if ( n
== (unsigned int)list
.GetCount() )
1869 childValue
= list
[n
];
1875 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
1878 for ( i
=starthere
;i
<GetChildCount();i
++)
1879 Item(i
)->m_arrIndex
= i
;
1883 // Returns (direct) child property with given name (or NULL if not found)
1884 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1888 for ( i
=0; i
<GetChildCount(); i
++ )
1890 wxPGProperty
* p
= Item(i
);
1891 if ( p
->m_name
== name
)
1895 // Does it have point, then?
1896 int pos
= name
.Find(wxS('.'));
1898 return (wxPGProperty
*) NULL
;
1900 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1902 if ( !p
|| !p
->GetChildCount() )
1905 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1908 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1910 unsigned int i
= hintIndex
;
1912 if ( i
>= GetChildCount() )
1915 unsigned int lastIndex
= i
- 1;
1917 if ( lastIndex
>= GetChildCount() )
1918 lastIndex
= GetChildCount() - 1;
1922 wxPGProperty
* p
= Item(i
);
1923 if ( p
->m_name
== name
)
1926 if ( i
== lastIndex
)
1930 if ( i
== GetChildCount() )
1937 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1939 // Returns height of children, recursively, and
1940 // by taking expanded/collapsed status into account.
1942 // iMax is used when finding property y-positions.
1948 iMax_
= GetChildCount();
1950 unsigned int iMax
= iMax_
;
1952 wxASSERT( iMax
<= GetChildCount() );
1954 if ( !IsExpanded() && GetParent() )
1959 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1961 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1963 if ( !pwc
->IsExpanded() ||
1964 pwc
->GetChildCount() == 0 )
1967 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1976 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1978 wxASSERT( nextItemY
);
1980 // Linear search at the moment
1982 // nextItemY = y of next visible property, final value will be written back.
1983 wxPGProperty
* result
= NULL
;
1984 wxPGProperty
* current
= NULL
;
1985 unsigned int iy
= *nextItemY
;
1987 unsigned int iMax
= GetChildCount();
1991 wxPGProperty
* pwc
= Item(i
);
1993 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2004 if ( pwc
->IsExpanded() &&
2005 pwc
->GetChildCount() > 0 )
2007 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2019 if ( !result
&& y
< iy
)
2026 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2028 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2031 return (wxPGProperty
*) result
;
2034 void wxPGProperty::Empty()
2037 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2039 for ( i
=0; i
<GetChildCount(); i
++ )
2041 delete m_children
[i
];
2048 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2049 int WXUNUSED(childIndex
),
2050 wxVariant
& WXUNUSED(childValue
) ) const
2054 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2058 const wxVariantList
* pList
= NULL
;
2059 wxVariantList::const_iterator node
;
2063 pList
= &pendingList
->GetList();
2064 node
= pList
->begin();
2067 for ( i
=0; i
<GetChildCount(); i
++ )
2069 wxPGProperty
* child
= Item(i
);
2070 const wxVariant
* listValue
= NULL
;
2075 const wxString
& childName
= child
->GetBaseName();
2077 for ( ; node
!= pList
->end(); node
++ )
2079 const wxVariant
& item
= *((const wxVariant
*)*node
);
2080 if ( item
.GetName() == childName
)
2090 value
= child
->GetValue();
2092 if ( value
.IsNull() )
2095 // Check recursively
2096 if ( child
->GetChildCount() )
2098 const wxVariant
* childList
= NULL
;
2100 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2101 childList
= listValue
;
2103 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2111 wxPGProperty
* wxPGProperty::UpdateParentValues()
2113 wxPGProperty
* parent
= m_parent
;
2114 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2115 !parent
->IsCategory() && !parent
->IsRoot() )
2118 parent
->GenerateComposedValue(s
);
2119 parent
->m_value
= s
;
2120 return parent
->UpdateParentValues();
2125 bool wxPGProperty::IsTextEditable() const
2127 if ( HasFlag(wxPG_PROP_READONLY
) )
2130 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2132 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2139 // Call after fixed sub-properties added/removed after creation.
2140 // if oldSelInd >= 0 and < new max items, then selection is
2141 // moved to it. Note: oldSelInd -2 indicates that this property
2142 // should be selected.
2143 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2145 wxPropertyGridPageState
* state
= GetParentState();
2146 wxPropertyGrid
* grid
= state
->GetGrid();
2149 // Re-repare children (recursively)
2150 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2152 wxPGProperty
* child
= Item(i
);
2153 child
->InitAfterAdded(state
, grid
);
2156 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2157 if ( oldSelInd
>= (int)m_children
.size() )
2158 oldSelInd
= (int)m_children
.size() - 1;
2160 if ( oldSelInd
>= 0 )
2161 sel
= m_children
[oldSelInd
];
2162 else if ( oldSelInd
== -2 )
2166 state
->DoSelectProperty(sel
);
2168 if ( state
== grid
->GetState() )
2170 grid
->GetPanel()->Refresh();
2174 // -----------------------------------------------------------------------
2176 // -----------------------------------------------------------------------
2178 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2179 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2182 wxPGRootProperty::wxPGRootProperty()
2186 m_name
= wxS("<root>");
2193 wxPGRootProperty::~wxPGRootProperty()
2198 // -----------------------------------------------------------------------
2199 // wxPropertyCategory
2200 // -----------------------------------------------------------------------
2202 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2203 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2205 void wxPropertyCategory::Init()
2207 // don't set colour - prepareadditem method should do this
2208 SetParentalType(wxPG_PROP_CATEGORY
);
2209 m_capFgColIndex
= 1;
2213 wxPropertyCategory::wxPropertyCategory()
2220 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2221 : wxPGProperty(label
,name
)
2227 wxPropertyCategory::~wxPropertyCategory()
2232 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2233 int WXUNUSED(argFlags
) ) const
2235 return wxEmptyString
;
2238 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2240 if ( m_textExtent
> 0 )
2241 return m_textExtent
;
2243 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2247 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2250 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2254 // -----------------------------------------------------------------------
2255 // wxPGAttributeStorage
2256 // -----------------------------------------------------------------------
2258 wxPGAttributeStorage::wxPGAttributeStorage()
2262 wxPGAttributeStorage::~wxPGAttributeStorage()
2264 wxPGHashMapS2P::iterator it
;
2266 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2268 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2273 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2275 wxVariantData
* data
= value
.GetData();
2278 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2279 if ( it
!= m_map
.end() )
2281 ((wxVariantData
*)it
->second
)->DecRef();
2285 // If Null variant, just remove from set
2299 #endif // wxUSE_PROPGRID