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
47 // -----------------------------------------------------------------------
49 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
51 #if defined(__WXMSW__) && !defined(__WXWINCE__)
52 // FIXME: Use DrawFocusRect code above (currently it draws solid line
53 // for caption focus but works ok for other stuff).
54 // Also, it seems that this code may not work in future wx versions.
55 dc
.SetLogicalFunction(wxINVERT
);
57 wxPen
pen(*wxBLACK
,1,wxDOT
);
58 pen
.SetCap(wxCAP_BUTT
);
60 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
62 dc
.DrawRectangle(rect
);
64 dc
.SetLogicalFunction(wxCOPY
);
66 dc
.SetLogicalFunction(wxINVERT
);
68 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
69 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
71 dc
.DrawRectangle(rect
);
73 dc
.SetLogicalFunction(wxCOPY
);
77 // -----------------------------------------------------------------------
79 // -----------------------------------------------------------------------
81 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
83 int WXUNUSED(item
) ) const
88 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
89 int xOffset
, const wxString
& text
) const
92 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
94 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
95 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
98 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
99 int xOffset
, const wxString
& text
,
100 wxPGProperty
* property
,
101 const wxPGEditor
* editor
) const
104 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
106 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
113 rect2
.height
-= yOffset
;
114 editor
->DrawValue( dc
, rect2
, property
, text
);
119 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
124 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
126 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
127 wxPGDrawFocusRect(dc
,focusRect
);
130 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
134 if ( !(flags
& Selected
) )
136 // Draw using wxPGCell information, if available
137 wxColour fgCol
= cell
.GetFgCol();
139 dc
.SetTextForeground(fgCol
);
141 wxColour bgCol
= cell
.GetBgCol();
146 dc
.DrawRectangle(rect
);
150 const wxBitmap
& bmp
= cell
.GetBitmap();
152 // In control, do not draw oversized bitmap
153 (!(flags
& Control
) || bmp
.GetHeight() < rect
.height
)
157 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
158 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
160 imageOffset
= bmp
.GetWidth();
166 // -----------------------------------------------------------------------
167 // wxPGDefaultRenderer
168 // -----------------------------------------------------------------------
170 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
171 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
172 int column
, int item
, int flags
) const
174 bool isUnspecified
= property
->IsValueUnspecified();
176 if ( column
== 1 && item
== -1 )
178 int cmnVal
= property
->GetCommonValue();
182 if ( !isUnspecified
)
183 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
188 const wxPGEditor
* editor
= NULL
;
189 const wxPGCell
* cell
= property
->GetCell(column
);
195 if ( column
== 1 && (flags
& Control
) )
197 int selectedIndex
= property
->GetChoiceSelection();
198 if ( selectedIndex
!= wxNOT_FOUND
)
200 const wxPGChoices
& choices
= property
->GetChoices();
201 const wxPGCell
* ccell
= &choices
[selectedIndex
];
203 ( ccell
->GetBitmap().IsOk() || ccell
->GetFgCol().IsOk() || ccell
->GetBgCol().IsOk() )
211 int preDrawFlags
= flags
;
213 if ( propertyGrid
->GetInternalFlags() & wxPG_FL_CELL_OVERRIDES_SEL
)
214 preDrawFlags
= preDrawFlags
& ~(Selected
);
216 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
217 text
= cell
->GetText();
218 if ( text
== wxS("@!") )
221 text
= property
->GetLabel();
222 else if ( column
== 1 )
223 text
= property
->GetValueString();
225 text
= wxEmptyString
;
228 else if ( column
== 0 )
231 DrawText( dc
, rect
, 0, property
->GetLabel() );
233 else if ( column
== 1 )
235 if ( !isUnspecified
)
237 editor
= property
->GetColumnEditor(column
);
239 // Regular property value
241 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
243 wxPGPaintData paintdata
;
244 paintdata
.m_parent
= propertyGrid
;
245 paintdata
.m_choiceItem
= item
;
247 if ( imageSize
.x
> 0 )
249 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
250 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
251 wxPG_CUSTOM_IMAGE_WIDTH
,
252 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
254 /*if ( imageSize.x == wxPG_FULL_CUSTOM_PAINT_WIDTH )
256 imageRect.width = m_width - imageRect.x;
259 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
261 paintdata
.m_drawnWidth
= imageSize
.x
;
262 paintdata
.m_drawnHeight
= imageSize
.y
;
264 if ( !isUnspecified
)
266 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
270 dc
.SetBrush(*wxWHITE_BRUSH
);
271 dc
.DrawRectangle(imageRect
);
274 imageOffset
= paintdata
.m_drawnWidth
;
277 text
= property
->GetValueString();
280 if ( propertyGrid
->GetColumnCount() <= 2 )
282 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
283 if ( unitsString
.length() )
284 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
288 if ( text
.length() == 0 )
290 // Try to show inline help if no text
291 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
292 if ( !vInlineHelp
.IsNull() )
294 text
= vInlineHelp
.GetString();
295 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
299 else if ( column
== 2 )
302 if ( !text
.length() )
303 text
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
306 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
308 // active caption gets nice dotted rectangle
309 if ( property
->IsCategory() /*&& column == 0*/ )
311 if ( flags
& Selected
)
313 if ( imageOffset
> 0 )
314 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
316 DrawCaptionSelectionRect( dc
,
317 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
318 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
319 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
320 propertyGrid
->GetCaptionFont())
321 +(wxPG_CAPRECTXMARGIN
*2),
322 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
327 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
331 if ( property
&& column
== 1 )
335 wxBitmap
* bmp
= property
->GetValueImage();
337 if ( bmp
&& bmp
->Ok() )
338 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
344 // -----------------------------------------------------------------------
346 // -----------------------------------------------------------------------
352 wxPGCell::wxPGCell( const wxString
& text
,
353 const wxBitmap
& bitmap
,
354 const wxColour
& fgCol
,
355 const wxColour
& bgCol
)
356 : m_bitmap(bitmap
), m_fgCol(fgCol
), m_bgCol(bgCol
)
361 // -----------------------------------------------------------------------
363 // -----------------------------------------------------------------------
365 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
367 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
369 void wxPGProperty::Init()
375 m_parentState
= (wxPropertyGridPageState
*) NULL
;
378 m_clientObject
= NULL
;
380 m_customEditor
= (wxPGEditor
*) NULL
;
382 m_validator
= (wxValidator
*) NULL
;
384 m_valueBitmap
= (wxBitmap
*) NULL
;
386 m_maxLen
= 0; // infinite maximum length
388 m_flags
= wxPG_PROP_PROPERTY
;
398 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
400 // We really need to check if &label and &name are NULL pointers
401 // (this can if we are called before property grid has been initalized)
403 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
406 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
409 DoSetName( m_label
);
414 wxPGProperty::wxPGProperty()
421 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
428 wxPGProperty::~wxPGProperty()
430 delete m_clientObject
;
432 Empty(); // this deletes items
434 delete m_valueBitmap
;
441 for ( i
=0; i
<m_cells
.size(); i
++ )
442 delete (wxPGCell
*) m_cells
[i
];
444 // This makes it easier for us to detect dangling pointers
449 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
451 wxPGProperty
* parent
= m_parent
;
454 if ( parent
== candidate
)
456 parent
= parent
->m_parent
;
462 wxString
wxPGProperty::GetName() const
464 wxPGProperty
* parent
= GetParent();
466 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
469 return m_parent
->GetName() + wxS(".") + m_name
;
472 wxPropertyGrid
* wxPGProperty::GetGrid() const
474 if ( !m_parentState
)
476 return m_parentState
->GetGrid();
479 int wxPGProperty::Index( const wxPGProperty
* p
) const
481 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
483 if ( p
== m_children
[i
] )
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
.size();
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
= m_children
[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
= m_children
[i
+1];
582 // Remove superfluous semicolon and space
584 if ( text
.EndsWith(wxS("; "), &rest
) )
587 if ( (unsigned int)i
< m_children
.size() )
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
.size();
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 oldChildValue
= child
->GetValue();
778 wxVariant
variant(oldChildValue
);
779 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
780 if ( stvRes
|| (variant
!= oldChildValue
) )
787 // Failed, becomes unspecified
792 variant
.SetName(child
->GetBaseName());
793 list
.Append(variant
);
796 if ( curChild
>= iMax
)
799 addOnlyIfNotEmpty
= true;
801 tokenStart
= 0xFFFFFF;
807 if ( a
== delimeter
)
820 if ( it
!= text
.end() )
837 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
839 wxVariant
variant(m_value
);
840 bool res
= StringToValue(variant
, text
, argFlags
);
846 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
848 wxVariant
variant(m_value
);
849 bool res
= IntToValue(variant
, number
, argFlags
);
855 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
858 return wxSize(m_valueBitmap
->GetWidth(),-1);
863 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
865 return wxPGGlobalVars
->m_defaultRenderer
;
868 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
872 wxBitmap
* bmp
= m_valueBitmap
;
874 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
876 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
878 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
881 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
883 return wxPGEditor_TextCtrl
;
886 // Default extra property event handling - that is, none at all.
887 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
893 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
895 // If auto unspecified values are not wanted (via window or property style),
896 // then get default value instead of wxNullVariant.
897 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
898 !UsesAutoUnspecified() )
900 value
= GetDefaultValue();
903 if ( !value
.IsNull() )
905 wxVariant tempListVariant
;
908 // List variants are reserved a special purpose
909 // as intermediate containers for child values
910 // of properties with children.
911 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
914 // However, situation is different for composed string properties
915 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
917 tempListVariant
= value
;
918 pList
= &tempListVariant
;
922 AdaptListToValue(value
, &newValue
);
924 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
927 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
928 flags
|= wxPG_SETVAL_AGGREGATED
;
930 if ( pList
&& !pList
->IsNull() )
932 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
933 wxASSERT( GetChildCount() );
934 wxASSERT( !IsCategory() );
936 wxVariantList
& list
= pList
->GetList();
937 wxVariantList::iterator node
;
940 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
942 // Children in list can be in any order, but we will give hint to
943 // GetPropertyByNameWH(). This optimizes for full list parsing.
944 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
946 wxVariant
& childValue
= *((wxVariant
*)*node
);
947 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
950 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
951 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
953 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
955 wxVariant listRefCopy
= childValue
;
956 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
960 wxVariant oldVal
= child
->GetValue();
961 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
964 else if ( child
->GetValue() != childValue
)
966 // For aggregate properties, we will trust RefreshChildren()
967 // to update child values.
968 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
969 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
970 if ( flags
& wxPG_SETVAL_BY_USER
)
971 child
->SetFlag(wxPG_PROP_MODIFIED
);
978 if ( !value
.IsNull() )
983 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
984 UpdateParentValues();
987 if ( flags
& wxPG_SETVAL_BY_USER
)
988 SetFlag(wxPG_PROP_MODIFIED
);
990 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
995 if ( m_commonValue
!= -1 )
997 wxPropertyGrid
* pg
= GetGrid();
998 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1004 // Set children to unspecified, but only if aggregate or
1005 // value is <composed>
1006 if ( AreChildrenComponents() )
1009 for ( i
=0; i
<GetChildCount(); i
++ )
1010 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1015 // Update editor control
1018 // We need to check for these, otherwise GetGrid() may fail.
1019 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1024 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1026 GetGrid()->ValueChangeInEvent(value
);
1029 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1037 for ( i
= 0; i
< GetChildCount(); i
++ )
1038 Item(i
)->SetFlagRecursively(flag
, set
);
1041 void wxPGProperty::RefreshEditor()
1043 if ( m_parent
&& GetParentState() )
1045 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1046 if ( pg
->GetSelectedProperty() == this )
1048 wxWindow
* editor
= pg
->GetEditorControl();
1050 GetEditorClass()->UpdateControl( this, editor
);
1056 wxVariant
wxPGProperty::GetDefaultValue() const
1058 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1059 if ( !defVal
.IsNull() )
1062 wxVariant value
= GetValue();
1064 if ( !value
.IsNull() )
1066 wxString
valueType(value
.GetType());
1068 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1069 return wxPGVariant_Zero
;
1070 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1071 return wxPGVariant_EmptyString
;
1072 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1073 return wxPGVariant_False
;
1074 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1075 return wxVariant(0.0);
1076 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1077 return wxVariant(wxArrayString());
1078 if ( valueType
== wxS("wxLongLong") )
1079 return WXVARIANT(wxLongLong(0));
1080 if ( valueType
== wxS("wxULongLong") )
1081 return WXVARIANT(wxULongLong(0));
1082 if ( valueType
== wxS("wxColour") )
1083 return WXVARIANT(*wxBLACK
);
1085 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1086 return wxVariant(wxDateTime::Now());
1088 if ( valueType
== wxS("wxFont") )
1089 return WXVARIANT(*wxNORMAL_FONT
);
1090 if ( valueType
== wxS("wxPoint") )
1091 return WXVARIANT(wxPoint(0, 0));
1092 if ( valueType
== wxS("wxSize") )
1093 return WXVARIANT(wxSize(0, 0));
1099 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1101 if ( column
>= (int)m_cells
.size() )
1102 m_cells
.SetCount(column
+1, NULL
);
1104 delete (wxPGCell
*) m_cells
[column
];
1105 m_cells
[column
] = cellObj
;
1108 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1113 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1118 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1120 if ( DoSetAttribute( name
, value
) )
1122 // Support working without grid, when possible
1123 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1127 m_attributes
.Set( name
, value
);
1130 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1132 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1135 while ( attributes
.GetNext(it
, variant
) )
1136 SetAttribute( variant
.GetName(), variant
);
1139 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1145 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1147 return m_attributes
.FindValue(name
);
1150 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1152 wxVariant variant
= m_attributes
.FindValue(name
);
1154 if ( !variant
.IsNull() )
1155 return variant
.GetString();
1160 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1162 wxVariant variant
= m_attributes
.FindValue(name
);
1164 return wxPGVariantToInt(variant
, defVal
);
1167 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1170 wxVariant variant
= m_attributes
.FindValue(name
);
1172 if ( wxPGVariantToDouble(variant
, &retVal
) )
1178 wxVariant
wxPGProperty::GetAttributesAsList() const
1180 wxVariantList tempList
;
1181 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1183 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1186 while ( m_attributes
.GetNext(it
, variant
) )
1192 // Slots of utility flags are NULL
1193 const unsigned int gs_propFlagToStringSize
= 14;
1195 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1212 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1215 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1219 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1221 if ( relevantFlags
& a
)
1223 const wxChar
* fs
= gs_propFlagToString
[i
];
1235 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1239 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1241 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1243 const wxChar
* fs
= gs_propFlagToString
[i
];
1244 if ( fs
&& str
== fs
)
1250 WX_PG_TOKENIZER1_END()
1252 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1255 wxValidator
* wxPGProperty::DoGetValidator() const
1257 return (wxValidator
*) NULL
;
1260 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1262 wxPropertyGrid
* pg
= GetGrid();
1263 int sel
= GetChoiceSelection();
1267 if ( index
== wxNOT_FOUND
)
1268 index
= m_choices
.GetCount();
1273 m_choices
.Insert(label
, index
, value
);
1275 if ( sel
!= newSel
)
1276 SetChoiceSelection(newSel
);
1278 if ( this == pg
->GetSelection() )
1279 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1285 void wxPGProperty::DeleteChoice( int index
)
1287 wxPropertyGrid
* pg
= GetGrid();
1289 int sel
= GetChoiceSelection();
1292 // Adjust current value
1295 SetValueToUnspecified();
1298 else if ( index
< sel
)
1303 m_choices
.RemoveAt(index
);
1305 if ( sel
!= newSel
)
1306 SetChoiceSelection(newSel
);
1308 if ( this == pg
->GetSelection() )
1309 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1312 int wxPGProperty::GetChoiceSelection() const
1314 wxVariant value
= GetValue();
1315 wxString valueType
= value
.GetType();
1316 int index
= wxNOT_FOUND
;
1318 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1321 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1323 index
= value
.GetLong();
1325 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1327 index
= m_choices
.Index(value
.GetString());
1329 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1331 index
= value
.GetBool()? 1 : 0;
1337 void wxPGProperty::SetChoiceSelection( int newValue
)
1339 // Changes value of a property with choices, but only
1340 // works if the value type is long or string.
1341 wxString valueType
= GetValue().GetType();
1343 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1345 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1347 SetValue( m_choices
.GetLabel(newValue
) );
1349 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1351 SetValue( (long) newValue
);
1355 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1357 m_choices
.Assign(choices
);
1360 // This may be needed to trigger some initialization
1361 // (but don't do it if property is somewhat uninitialized)
1362 wxVariant defVal
= GetDefaultValue();
1363 if ( defVal
.IsNull() )
1373 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1375 const wxPGEditor
* editor
;
1377 if ( !m_customEditor
)
1379 editor
= DoGetEditorClass();
1382 editor
= m_customEditor
;
1385 // Maybe override editor if common value specified
1386 if ( GetDisplayedCommonValueCount() )
1388 // TextCtrlAndButton -> ComboBoxAndButton
1389 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1390 editor
= wxPGEditor_ChoiceAndButton
;
1392 // TextCtrl -> ComboBox
1393 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1394 editor
= wxPGEditor_ComboBox
;
1400 bool wxPGProperty::HasVisibleChildren() const
1404 for ( i
=0; i
<GetChildCount(); i
++ )
1406 wxPGProperty
* child
= Item(i
);
1408 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1415 bool wxPGProperty::RecreateEditor()
1417 wxPropertyGrid
* pg
= GetGrid();
1420 wxPGProperty
* selected
= pg
->GetSelection();
1421 if ( this == selected
)
1423 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1430 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1432 delete m_valueBitmap
;
1434 if ( &bmp
&& bmp
.Ok() )
1437 wxSize maxSz
= GetGrid()->GetImageSize();
1438 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1440 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1442 // Create a memory DC
1443 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1446 dc
.SelectObject(*bmpNew
);
1449 // FIXME: This is ugly - use image or wait for scaling patch.
1450 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1451 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1453 dc
.SetUserScale(scaleX
,scaleY
);
1455 dc
.DrawBitmap( bmp
, 0, 0 );
1457 m_valueBitmap
= bmpNew
;
1461 m_valueBitmap
= new wxBitmap(bmp
);
1464 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1468 m_valueBitmap
= NULL
;
1469 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1474 wxPGProperty
* wxPGProperty::GetMainParent() const
1476 const wxPGProperty
* curChild
= this;
1477 const wxPGProperty
* curParent
= m_parent
;
1479 while ( curParent
&& !curParent
->IsCategory() )
1481 curChild
= curParent
;
1482 curParent
= curParent
->m_parent
;
1485 return (wxPGProperty
*) curChild
;
1489 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1492 // Returns last visible sub-item, recursively.
1493 if ( !IsExpanded() || !GetChildCount() )
1496 return Last()->GetLastVisibleSubItem();
1500 bool wxPGProperty::IsVisible() const
1502 const wxPGProperty
* parent
;
1504 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1507 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1509 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1516 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1518 wxPropertyGridPageState
* state
= GetParentState();
1519 wxPropertyGrid
* propGrid
= state
->GetGrid();
1520 if ( state
== propGrid
->GetState() )
1526 int wxPGProperty::GetY2( int lh
) const
1528 const wxPGProperty
* parent
;
1529 const wxPGProperty
* child
= this;
1533 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1535 if ( !parent
->IsExpanded() )
1537 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1542 y
-= lh
; // need to reduce one level
1548 int wxPGProperty::GetY() const
1550 return GetY2(GetGrid()->GetRowHeight());
1553 // This is used by Insert etc.
1554 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1556 if ( index
< 0 || (size_t)index
>= m_children
.size() )
1558 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
1559 m_children
.push_back( prop
);
1563 m_children
.insert( m_children
.begin()+index
, prop
);
1564 if ( correct_mode
) FixIndexesOfChildren( index
);
1567 prop
->m_parent
= this;
1570 // This is used by properties that have fixed sub-properties
1571 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1573 wxASSERT_MSG( prop
->GetBaseName().length(),
1574 "Property's children must have unique, non-empty names within their scope" );
1576 prop
->m_arrIndex
= m_children
.size();
1577 m_children
.push_back( prop
);
1579 int custImgHeight
= prop
->OnMeasureImage().y
;
1580 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1581 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1583 prop
->m_parent
= this;
1586 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
1588 wxArrayPGProperty::iterator it
;
1589 wxArrayPGProperty
& children
= m_children
;
1591 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
1595 m_children
.erase(it
);
1601 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1603 wxASSERT( GetChildCount() );
1604 wxASSERT( !IsCategory() );
1606 *value
= GetValue();
1608 if ( !list
.GetCount() )
1611 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1613 bool allChildrenSpecified
;
1615 // Don't fully update aggregate properties unless all children have
1617 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1618 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1620 allChildrenSpecified
= true;
1622 wxVariant childValue
= list
[0];
1626 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1628 for ( i
=0; i
<GetChildCount(); i
++ )
1630 const wxPGProperty
* child
= Item(i
);
1632 if ( childValue
.GetName() == child
->GetBaseName() )
1634 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1636 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1638 wxVariant
cv2(child
->GetValue());
1639 child
->AdaptListToValue(childValue
, &cv2
);
1643 if ( allChildrenSpecified
)
1644 ChildChanged(*value
, i
, childValue
);
1646 if ( n
== (unsigned int)list
.GetCount() )
1648 childValue
= list
[n
];
1654 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1657 for ( i
=starthere
;i
<GetChildCount();i
++)
1658 Item(i
)->m_arrIndex
= i
;
1662 // Returns (direct) child property with given name (or NULL if not found)
1663 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1667 for ( i
=0; i
<GetChildCount(); i
++ )
1669 wxPGProperty
* p
= Item(i
);
1670 if ( p
->m_name
== name
)
1674 // Does it have point, then?
1675 int pos
= name
.Find(wxS('.'));
1677 return (wxPGProperty
*) NULL
;
1679 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1681 if ( !p
|| !p
->GetChildCount() )
1684 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1687 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1689 unsigned int i
= hintIndex
;
1691 if ( i
>= GetChildCount() )
1694 unsigned int lastIndex
= i
- 1;
1696 if ( lastIndex
>= GetChildCount() )
1697 lastIndex
= GetChildCount() - 1;
1701 wxPGProperty
* p
= Item(i
);
1702 if ( p
->m_name
== name
)
1705 if ( i
== lastIndex
)
1709 if ( i
== GetChildCount() )
1716 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1718 // Returns height of children, recursively, and
1719 // by taking expanded/collapsed status into account.
1721 // iMax is used when finding property y-positions.
1727 iMax_
= GetChildCount();
1729 unsigned int iMax
= iMax_
;
1731 wxASSERT( iMax
<= GetChildCount() );
1733 if ( !IsExpanded() && GetParent() )
1738 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1740 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1742 if ( !pwc
->IsExpanded() ||
1743 pwc
->GetChildCount() == 0 )
1746 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1755 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1757 wxASSERT( nextItemY
);
1759 // Linear search at the moment
1761 // nextItemY = y of next visible property, final value will be written back.
1762 wxPGProperty
* result
= NULL
;
1763 wxPGProperty
* current
= NULL
;
1764 unsigned int iy
= *nextItemY
;
1766 unsigned int iMax
= GetChildCount();
1770 wxPGProperty
* pwc
= Item(i
);
1772 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1783 if ( pwc
->IsExpanded() &&
1784 pwc
->GetChildCount() > 0 )
1786 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1798 if ( !result
&& y
< iy
)
1805 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1807 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1810 return (wxPGProperty
*) result
;
1813 void wxPGProperty::Empty()
1816 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1818 for ( i
=0; i
<GetChildCount(); i
++ )
1820 delete m_children
[i
];
1827 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1828 int WXUNUSED(childIndex
),
1829 wxVariant
& WXUNUSED(childValue
) ) const
1833 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1837 const wxVariantList
* pList
= NULL
;
1838 wxVariantList::const_iterator node
;
1842 pList
= &pendingList
->GetList();
1843 node
= pList
->begin();
1846 for ( i
=0; i
<GetChildCount(); i
++ )
1848 wxPGProperty
* child
= Item(i
);
1849 const wxVariant
* listValue
= NULL
;
1854 const wxString
& childName
= child
->GetBaseName();
1856 for ( ; node
!= pList
->end(); node
++ )
1858 const wxVariant
& item
= *((const wxVariant
*)*node
);
1859 if ( item
.GetName() == childName
)
1869 value
= child
->GetValue();
1871 if ( value
.IsNull() )
1874 // Check recursively
1875 if ( child
->GetChildCount() )
1877 const wxVariant
* childList
= NULL
;
1879 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
1880 childList
= listValue
;
1882 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1890 wxPGProperty
* wxPGProperty::UpdateParentValues()
1892 wxPGProperty
* parent
= m_parent
;
1893 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1894 !parent
->IsCategory() && !parent
->IsRoot() )
1897 parent
->GenerateComposedValue(s
, 0);
1898 parent
->m_value
= s
;
1899 return parent
->UpdateParentValues();
1904 bool wxPGProperty::IsTextEditable() const
1906 if ( HasFlag(wxPG_PROP_READONLY
) )
1909 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1911 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1918 // Call for after sub-properties added with AddChild
1919 void wxPGProperty::PrepareSubProperties()
1921 wxPropertyGridPageState
* state
= GetParentState();
1925 if ( !GetChildCount() )
1928 wxByte depth
= m_depth
+ 1;
1929 wxByte depthBgCol
= m_depthBgCol
;
1931 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1933 wxByte bgColIndex
= m_bgColIndex
;
1934 wxByte fgColIndex
= m_fgColIndex
;
1937 // Set some values to the children
1940 wxPGProperty
* nparent
= this;
1942 while ( i
< nparent
->GetChildCount() )
1944 wxPGProperty
* np
= nparent
->Item(i
);
1946 np
->m_parentState
= state
;
1947 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
1948 np
->m_depth
= depth
;
1949 np
->m_depthBgCol
= depthBgCol
;
1950 np
->m_bgColIndex
= bgColIndex
;
1951 np
->m_fgColIndex
= fgColIndex
;
1953 // Also handle children of children
1954 if ( np
->GetChildCount() > 0 )
1960 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
1961 nparent
->SetExpanded(false);
1970 // After reaching last sibling, go back to processing
1971 // siblings of the parent
1972 while ( i
>= nparent
->GetChildCount() )
1974 // Exit the loop when top parent hit
1975 if ( nparent
== this )
1980 i
= nparent
->GetIndexInParent() + 1;
1981 nparent
= nparent
->GetParent();
1986 // Call after fixed sub-properties added/removed after creation.
1987 // if oldSelInd >= 0 and < new max items, then selection is
1988 // moved to it. Note: oldSelInd -2 indicates that this property
1989 // should be selected.
1990 void wxPGProperty::SubPropsChanged( int oldSelInd
)
1992 wxPropertyGridPageState
* state
= GetParentState();
1993 wxPropertyGrid
* grid
= state
->GetGrid();
1995 PrepareSubProperties();
1997 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
1998 if ( oldSelInd
>= (int)m_children
.size() )
1999 oldSelInd
= (int)m_children
.size() - 1;
2001 if ( oldSelInd
>= 0 )
2002 sel
= m_children
[oldSelInd
];
2003 else if ( oldSelInd
== -2 )
2007 state
->DoSelectProperty(sel
);
2009 if ( state
== grid
->GetState() )
2011 grid
->GetPanel()->Refresh();
2015 // -----------------------------------------------------------------------
2017 // -----------------------------------------------------------------------
2019 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2020 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2023 wxPGRootProperty::wxPGRootProperty()
2027 m_name
= wxS("<root>");
2034 wxPGRootProperty::~wxPGRootProperty()
2039 // -----------------------------------------------------------------------
2040 // wxPropertyCategory
2041 // -----------------------------------------------------------------------
2043 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2044 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2046 void wxPropertyCategory::Init()
2048 // don't set colour - prepareadditem method should do this
2049 SetParentalType(wxPG_PROP_CATEGORY
);
2050 m_capFgColIndex
= 1;
2054 wxPropertyCategory::wxPropertyCategory()
2061 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2062 : wxPGProperty(label
,name
)
2068 wxPropertyCategory::~wxPropertyCategory()
2073 wxString
wxPropertyCategory::GetValueAsString( int ) const
2075 return wxEmptyString
;
2078 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2080 if ( m_textExtent
> 0 )
2081 return m_textExtent
;
2083 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2087 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2090 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2094 // -----------------------------------------------------------------------
2095 // wxPGAttributeStorage
2096 // -----------------------------------------------------------------------
2098 wxPGAttributeStorage::wxPGAttributeStorage()
2102 wxPGAttributeStorage::~wxPGAttributeStorage()
2104 wxPGHashMapS2P::iterator it
;
2106 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2108 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2113 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2115 wxVariantData
* data
= value
.GetData();
2118 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2119 if ( it
!= m_map
.end() )
2121 ((wxVariantData
*)it
->second
)->DecRef();
2125 // If Null variant, just remove from set
2139 #endif // wxUSE_PROPGRID