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 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 wxPG_EDITOR(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 ( !value
.IsNull() )
897 wxVariant tempListVariant
;
900 // List variants are reserved a special purpose
901 // as intermediate containers for child values
902 // of properties with children.
903 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
906 // However, situation is different for composed string properties
907 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
909 tempListVariant
= value
;
910 pList
= &tempListVariant
;
914 AdaptListToValue(value
, &newValue
);
916 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
919 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
920 flags
|= wxPG_SETVAL_AGGREGATED
;
922 if ( pList
&& !pList
->IsNull() )
924 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
925 wxASSERT( GetChildCount() );
926 wxASSERT( !IsCategory() );
928 wxVariantList
& list
= pList
->GetList();
929 wxVariantList::iterator node
;
932 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
934 // Children in list can be in any order, but we will give hint to
935 // GetPropertyByNameWH(). This optimizes for full list parsing.
936 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
938 wxVariant
& childValue
= *((wxVariant
*)*node
);
939 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
942 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
943 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
945 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
947 wxVariant listRefCopy
= childValue
;
948 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
952 wxVariant oldVal
= child
->GetValue();
953 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
956 else if ( child
->GetValue() != childValue
)
958 // For aggregate properties, we will trust RefreshChildren()
959 // to update child values.
960 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
961 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
962 if ( flags
& wxPG_SETVAL_BY_USER
)
963 child
->SetFlag(wxPG_PROP_MODIFIED
);
970 if ( !value
.IsNull() )
975 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
976 UpdateParentValues();
979 if ( flags
& wxPG_SETVAL_BY_USER
)
980 SetFlag(wxPG_PROP_MODIFIED
);
982 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
987 if ( m_commonValue
!= -1 )
989 wxPropertyGrid
* pg
= GetGrid();
990 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
996 // Set children to unspecified, but only if aggregate or
997 // value is <composed>
998 if ( AreChildrenComponents() )
1001 for ( i
=0; i
<GetChildCount(); i
++ )
1002 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1007 // Update editor control
1010 // We need to check for these, otherwise GetGrid() may fail.
1011 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1016 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1018 GetGrid()->ValueChangeInEvent(value
);
1021 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1029 for ( i
= 0; i
< GetChildCount(); i
++ )
1030 Item(i
)->SetFlagRecursively(flag
, set
);
1033 void wxPGProperty::RefreshEditor()
1035 if ( m_parent
&& GetParentState() )
1037 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1038 if ( pg
->GetSelectedProperty() == this )
1040 wxWindow
* editor
= pg
->GetEditorControl();
1042 GetEditorClass()->UpdateControl( this, editor
);
1048 wxVariant
wxPGProperty::GetDefaultValue() const
1050 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1051 if ( !defVal
.IsNull() )
1054 wxVariant value
= GetValue();
1056 if ( !value
.IsNull() )
1058 wxString
valueType(value
.GetType());
1060 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1061 return wxPGVariant_Zero
;
1062 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1063 return wxPGVariant_EmptyString
;
1064 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1065 return wxPGVariant_False
;
1066 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1067 return wxVariant(0.0);
1068 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1069 return wxVariant(wxArrayString());
1070 if ( valueType
== wxS("wxLongLong") )
1071 return WXVARIANT(wxLongLong(0));
1072 if ( valueType
== wxS("wxULongLong") )
1073 return WXVARIANT(wxULongLong(0));
1074 if ( valueType
== wxS("wxColour") )
1075 return WXVARIANT(*wxBLACK
);
1077 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1078 return wxVariant(wxDateTime::Now());
1080 if ( valueType
== wxS("wxFont") )
1081 return WXVARIANT(*wxNORMAL_FONT
);
1082 if ( valueType
== wxS("wxPoint") )
1083 return WXVARIANT(wxPoint(0, 0));
1084 if ( valueType
== wxS("wxSize") )
1085 return WXVARIANT(wxSize(0, 0));
1091 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1093 if ( column
>= (int)m_cells
.size() )
1094 m_cells
.SetCount(column
+1, NULL
);
1096 delete (wxPGCell
*) m_cells
[column
];
1097 m_cells
[column
] = cellObj
;
1100 void wxPGProperty::SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
)
1102 // Changes value of a property with choices, but only
1103 // works if the value type is long or string.
1104 wxString ts
= GetValue().GetType();
1106 wxCHECK_RET( choiceInfo
.m_choices
, wxT("invalid choiceinfo") );
1108 if ( ts
== wxS("long") )
1110 SetValue( (long) newValue
);
1112 else if ( ts
== wxS("string") )
1114 SetValue( choiceInfo
.m_choices
->GetLabel(newValue
) );
1119 wxString
wxPGProperty::GetChoiceString( unsigned int index
)
1123 wxASSERT(ci
.m_choices
);
1124 return ci
.m_choices
->GetLabel(index
);
1127 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1129 wxPropertyGrid
* pg
= GetGrid();
1132 ci
.m_choices
= (wxPGChoices
*) NULL
;
1133 int sel
= GetChoiceInfo(&ci
);
1140 index
= ci
.m_choices
->GetCount();
1145 ci
.m_choices
->Insert(label
, index
, value
);
1147 if ( sel
!= newSel
)
1148 SetChoiceSelection(newSel
, ci
);
1150 if ( this == pg
->GetSelection() )
1151 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1160 void wxPGProperty::DeleteChoice( int index
)
1162 wxPropertyGrid
* pg
= GetGrid();
1165 ci
.m_choices
= (wxPGChoices
*) NULL
;
1166 int sel
= GetChoiceInfo(&ci
);
1172 // Adjust current value
1175 SetValueToUnspecified();
1178 else if ( index
< sel
)
1183 ci
.m_choices
->RemoveAt(index
);
1185 if ( sel
!= newSel
)
1186 SetChoiceSelection(newSel
, ci
);
1188 if ( this == pg
->GetSelection() )
1189 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1193 int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo
* WXUNUSED(info
) )
1198 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1203 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1208 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1210 if ( DoSetAttribute( name
, value
) )
1212 // Support working without grid, when possible
1213 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1217 m_attributes
.Set( name
, value
);
1220 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1222 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1225 while ( attributes
.GetNext(it
, variant
) )
1226 SetAttribute( variant
.GetName(), variant
);
1229 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1235 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1237 return m_attributes
.FindValue(name
);
1240 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1242 wxVariant variant
= m_attributes
.FindValue(name
);
1244 if ( !variant
.IsNull() )
1245 return variant
.GetString();
1250 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1252 wxVariant variant
= m_attributes
.FindValue(name
);
1254 return wxPGVariantToInt(variant
, defVal
);
1257 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1260 wxVariant variant
= m_attributes
.FindValue(name
);
1262 if ( wxPGVariantToDouble(variant
, &retVal
) )
1268 wxVariant
wxPGProperty::GetAttributesAsList() const
1270 wxVariantList tempList
;
1271 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1273 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1276 while ( m_attributes
.GetNext(it
, variant
) )
1282 // Slots of utility flags are NULL
1283 const unsigned int gs_propFlagToStringSize
= 14;
1285 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1302 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1305 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1309 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1311 if ( relevantFlags
& a
)
1313 const wxChar
* fs
= gs_propFlagToString
[i
];
1325 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1329 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1331 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1333 const wxChar
* fs
= gs_propFlagToString
[i
];
1334 if ( fs
&& str
== fs
)
1340 WX_PG_TOKENIZER1_END()
1342 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1345 wxValidator
* wxPGProperty::DoGetValidator() const
1347 return (wxValidator
*) NULL
;
1350 wxPGChoices
& wxPGProperty::GetChoices()
1352 wxPGChoiceInfo choiceInfo
;
1353 choiceInfo
.m_choices
= NULL
;
1354 GetChoiceInfo(&choiceInfo
);
1355 return *choiceInfo
.m_choices
;
1358 const wxPGChoices
& wxPGProperty::GetChoices() const
1360 return (const wxPGChoices
&) ((wxPGProperty
*)this)->GetChoices();
1363 unsigned int wxPGProperty::GetChoiceCount() const
1365 const wxPGChoices
& choices
= GetChoices();
1366 if ( &choices
&& choices
.IsOk() )
1367 return choices
.GetCount();
1371 const wxPGChoiceEntry
* wxPGProperty::GetCurrentChoice() const
1374 ci
.m_choices
= (wxPGChoices
*) NULL
;
1375 int index
= ((wxPGProperty
*)this)->GetChoiceInfo(&ci
);
1376 if ( index
== -1 || !ci
.m_choices
|| index
>= (int)ci
.m_choices
->GetCount() )
1379 return &(*ci
.m_choices
)[index
];
1382 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1385 ci
.m_choices
= (wxPGChoices
*) NULL
;
1391 ci
.m_choices
->Assign(choices
);
1395 // This may be needed to trigger some initialization
1396 // (but don't do it if property is somewhat uninitialized)
1397 wxVariant defVal
= GetDefaultValue();
1398 if ( defVal
.IsNull() )
1410 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1412 const wxPGEditor
* editor
;
1414 if ( !m_customEditor
)
1416 editor
= DoGetEditorClass();
1419 editor
= m_customEditor
;
1422 // Maybe override editor if common value specified
1423 if ( GetDisplayedCommonValueCount() )
1425 // TextCtrlAndButton -> ComboBoxAndButton
1426 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1427 editor
= wxPG_EDITOR(ChoiceAndButton
);
1429 // TextCtrl -> ComboBox
1430 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1431 editor
= wxPG_EDITOR(ComboBox
);
1438 // Privatizes set of choices
1439 void wxPGProperty::SetChoicesExclusive()
1442 ci
.m_choices
= (wxPGChoices
*) NULL
;
1446 ci
.m_choices
->SetExclusive();
1449 bool wxPGProperty::HasVisibleChildren() const
1453 for ( i
=0; i
<GetChildCount(); i
++ )
1455 wxPGProperty
* child
= Item(i
);
1457 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1464 bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid
* propGrid
)
1466 return propGrid
->EditorValidate();
1470 bool wxPGProperty::RecreateEditor()
1472 wxPropertyGrid
* pg
= GetGrid();
1475 wxPGProperty
* selected
= pg
->GetSelection();
1476 if ( this == selected
)
1478 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1485 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1487 delete m_valueBitmap
;
1489 if ( &bmp
&& bmp
.Ok() )
1492 wxSize maxSz
= GetGrid()->GetImageSize();
1493 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1495 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1497 // Create a memory DC
1498 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1501 dc
.SelectObject(*bmpNew
);
1504 // FIXME: This is ugly - use image or wait for scaling patch.
1505 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1506 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1508 dc
.SetUserScale(scaleX
,scaleY
);
1510 dc
.DrawBitmap( bmp
, 0, 0 );
1512 m_valueBitmap
= bmpNew
;
1516 m_valueBitmap
= new wxBitmap(bmp
);
1519 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1523 m_valueBitmap
= NULL
;
1524 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1529 wxPGProperty
* wxPGProperty::GetMainParent() const
1531 const wxPGProperty
* curChild
= this;
1532 const wxPGProperty
* curParent
= m_parent
;
1534 while ( curParent
&& !curParent
->IsCategory() )
1536 curChild
= curParent
;
1537 curParent
= curParent
->m_parent
;
1540 return (wxPGProperty
*) curChild
;
1544 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1547 // Returns last visible sub-item, recursively.
1548 if ( !IsExpanded() || !GetChildCount() )
1551 return Last()->GetLastVisibleSubItem();
1555 bool wxPGProperty::IsVisible() const
1557 const wxPGProperty
* parent
;
1559 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1562 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1564 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1571 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1573 wxPropertyGridPageState
* state
= GetParentState();
1574 wxPropertyGrid
* propGrid
= state
->GetGrid();
1575 if ( state
== propGrid
->GetState() )
1581 int wxPGProperty::GetY2( int lh
) const
1583 const wxPGProperty
* parent
;
1584 const wxPGProperty
* child
= this;
1588 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1590 if ( !parent
->IsExpanded() )
1592 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1597 y
-= lh
; // need to reduce one level
1603 int wxPGProperty::GetY() const
1605 return GetY2(GetGrid()->GetRowHeight());
1608 // This is used by Insert etc.
1609 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1611 if ( index
< 0 || (size_t)index
>= m_children
.GetCount() )
1613 if ( correct_mode
) prop
->m_arrIndex
= m_children
.GetCount();
1614 m_children
.Add( prop
);
1618 m_children
.Insert( prop
, index
);
1619 if ( correct_mode
) FixIndexesOfChildren( index
);
1622 prop
->m_parent
= this;
1625 // This is used by properties that have fixed sub-properties
1626 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1628 wxASSERT_MSG( prop
->GetBaseName().length(),
1629 "Property's children must have unique, non-empty names within their scope" );
1631 prop
->m_arrIndex
= m_children
.GetCount();
1632 m_children
.Add( prop
);
1634 int custImgHeight
= prop
->OnMeasureImage().y
;
1635 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1636 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1638 prop
->m_parent
= this;
1642 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1644 wxASSERT( GetChildCount() );
1645 wxASSERT( !IsCategory() );
1647 *value
= GetValue();
1649 if ( !list
.GetCount() )
1652 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1654 bool allChildrenSpecified
;
1656 // Don't fully update aggregate properties unless all children have
1658 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1659 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1661 allChildrenSpecified
= true;
1663 wxVariant childValue
= list
[0];
1667 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1669 for ( i
=0; i
<GetChildCount(); i
++ )
1671 const wxPGProperty
* child
= Item(i
);
1673 if ( childValue
.GetName() == child
->GetBaseName() )
1675 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1677 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1679 wxVariant
cv2(child
->GetValue());
1680 child
->AdaptListToValue(childValue
, &cv2
);
1684 if ( allChildrenSpecified
)
1685 ChildChanged(*value
, i
, childValue
);
1687 if ( n
== (unsigned int)list
.GetCount() )
1689 childValue
= list
[n
];
1695 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1698 for ( i
=starthere
;i
<GetChildCount();i
++)
1699 Item(i
)->m_arrIndex
= i
;
1703 // Returns (direct) child property with given name (or NULL if not found)
1704 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1708 for ( i
=0; i
<GetChildCount(); i
++ )
1710 wxPGProperty
* p
= Item(i
);
1711 if ( p
->m_name
== name
)
1715 // Does it have point, then?
1716 int pos
= name
.Find(wxS('.'));
1718 return (wxPGProperty
*) NULL
;
1720 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1722 if ( !p
|| !p
->GetChildCount() )
1725 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1728 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1730 unsigned int i
= hintIndex
;
1732 if ( i
>= GetChildCount() )
1735 unsigned int lastIndex
= i
- 1;
1737 if ( lastIndex
>= GetChildCount() )
1738 lastIndex
= GetChildCount() - 1;
1742 wxPGProperty
* p
= Item(i
);
1743 if ( p
->m_name
== name
)
1746 if ( i
== lastIndex
)
1750 if ( i
== GetChildCount() )
1757 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1759 // Returns height of children, recursively, and
1760 // by taking expanded/collapsed status into account.
1762 // iMax is used when finding property y-positions.
1768 iMax_
= GetChildCount();
1770 unsigned int iMax
= iMax_
;
1772 wxASSERT( iMax
<= GetChildCount() );
1774 if ( !IsExpanded() && GetParent() )
1779 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1781 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1783 if ( !pwc
->IsExpanded() ||
1784 pwc
->GetChildCount() == 0 )
1787 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1796 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1798 wxASSERT( nextItemY
);
1800 // Linear search at the moment
1802 // nextItemY = y of next visible property, final value will be written back.
1803 wxPGProperty
* result
= NULL
;
1804 wxPGProperty
* current
= NULL
;
1805 unsigned int iy
= *nextItemY
;
1807 unsigned int iMax
= GetChildCount();
1811 wxPGProperty
* pwc
= Item(i
);
1813 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1824 if ( pwc
->IsExpanded() &&
1825 pwc
->GetChildCount() > 0 )
1827 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1839 if ( !result
&& y
< iy
)
1846 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1848 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1851 return (wxPGProperty
*) result
;
1854 void wxPGProperty::Empty()
1857 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1859 for ( i
=0; i
<GetChildCount(); i
++ )
1861 wxPGProperty
* p
= (wxPGProperty
*) Item(i
);
1869 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1870 int WXUNUSED(childIndex
),
1871 wxVariant
& WXUNUSED(childValue
) ) const
1875 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1879 const wxVariantList
* pList
= NULL
;
1880 wxVariantList::const_iterator node
;
1884 pList
= &pendingList
->GetList();
1885 node
= pList
->begin();
1888 for ( i
=0; i
<GetChildCount(); i
++ )
1890 wxPGProperty
* child
= Item(i
);
1891 const wxVariant
* listValue
= NULL
;
1896 const wxString
& childName
= child
->GetBaseName();
1898 for ( ; node
!= pList
->end(); node
++ )
1900 const wxVariant
& item
= *((const wxVariant
*)*node
);
1901 if ( item
.GetName() == childName
)
1911 value
= child
->GetValue();
1913 if ( value
.IsNull() )
1916 // Check recursively
1917 if ( child
->GetChildCount() )
1919 const wxVariant
* childList
= NULL
;
1921 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
1922 childList
= listValue
;
1924 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1932 wxPGProperty
* wxPGProperty::UpdateParentValues()
1934 wxPGProperty
* parent
= m_parent
;
1935 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1936 !parent
->IsCategory() && !parent
->IsRoot() )
1939 parent
->GenerateComposedValue(s
, 0);
1940 parent
->m_value
= s
;
1941 return parent
->UpdateParentValues();
1946 bool wxPGProperty::IsTextEditable() const
1948 if ( HasFlag(wxPG_PROP_READONLY
) )
1951 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1953 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1960 // Call for after sub-properties added with AddChild
1961 void wxPGProperty::PrepareSubProperties()
1963 wxPropertyGridPageState
* state
= GetParentState();
1967 if ( !GetChildCount() )
1970 wxByte depth
= m_depth
+ 1;
1971 wxByte depthBgCol
= m_depthBgCol
;
1973 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1975 wxByte bgColIndex
= m_bgColIndex
;
1976 wxByte fgColIndex
= m_fgColIndex
;
1979 // Set some values to the children
1982 wxPGProperty
* nparent
= this;
1984 while ( i
< nparent
->GetChildCount() )
1986 wxPGProperty
* np
= nparent
->Item(i
);
1988 np
->m_parentState
= state
;
1989 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
1990 np
->m_depth
= depth
;
1991 np
->m_depthBgCol
= depthBgCol
;
1992 np
->m_bgColIndex
= bgColIndex
;
1993 np
->m_fgColIndex
= fgColIndex
;
1995 // Also handle children of children
1996 if ( np
->GetChildCount() > 0 )
2002 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
2003 nparent
->SetExpanded(false);
2012 // After reaching last sibling, go back to processing
2013 // siblings of the parent
2014 while ( i
>= nparent
->GetChildCount() )
2016 // Exit the loop when top parent hit
2017 if ( nparent
== this )
2022 i
= nparent
->GetArrIndex() + 1;
2023 nparent
= nparent
->GetParent();
2028 // Call after fixed sub-properties added/removed after creation.
2029 // if oldSelInd >= 0 and < new max items, then selection is
2030 // moved to it. Note: oldSelInd -2 indicates that this property
2031 // should be selected.
2032 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2034 wxPropertyGridPageState
* state
= GetParentState();
2035 wxPropertyGrid
* grid
= state
->GetGrid();
2037 PrepareSubProperties();
2039 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2040 if ( oldSelInd
>= (int)m_children
.GetCount() )
2041 oldSelInd
= (int)m_children
.GetCount() - 1;
2043 if ( oldSelInd
>= 0 )
2044 sel
= (wxPGProperty
*) m_children
[oldSelInd
];
2045 else if ( oldSelInd
== -2 )
2049 state
->DoSelectProperty(sel
);
2051 if ( state
== grid
->GetState() )
2053 grid
->GetPanel()->Refresh();
2057 // -----------------------------------------------------------------------
2059 // -----------------------------------------------------------------------
2061 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2062 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2065 wxPGRootProperty::wxPGRootProperty()
2069 m_name
= wxS("<root>");
2076 wxPGRootProperty::~wxPGRootProperty()
2081 // -----------------------------------------------------------------------
2082 // wxPropertyCategory
2083 // -----------------------------------------------------------------------
2085 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2086 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2088 void wxPropertyCategory::Init()
2090 // don't set colour - prepareadditem method should do this
2091 SetParentalType(wxPG_PROP_CATEGORY
);
2092 m_capFgColIndex
= 1;
2096 wxPropertyCategory::wxPropertyCategory()
2103 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2104 : wxPGProperty(label
,name
)
2110 wxPropertyCategory::~wxPropertyCategory()
2115 wxString
wxPropertyCategory::GetValueAsString( int ) const
2117 return wxEmptyString
;
2120 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2122 if ( m_textExtent
> 0 )
2123 return m_textExtent
;
2125 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2129 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2132 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2136 // -----------------------------------------------------------------------
2137 // wxPGAttributeStorage
2138 // -----------------------------------------------------------------------
2140 wxPGAttributeStorage::wxPGAttributeStorage()
2144 wxPGAttributeStorage::~wxPGAttributeStorage()
2146 wxPGHashMapS2P::iterator it
;
2148 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2150 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2155 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2157 wxVariantData
* data
= value
.GetData();
2160 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2161 if ( it
!= m_map
.end() )
2162 ((wxVariantData
*)it
->second
)->DecRef();