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 // Use label instead of name, as name can be empty string, but
709 // label in practice never is.
710 variant
.SetName(child
->GetLabel());
712 // Clear unspecified flag only if OnSetValue() didn't
714 if ( child
->IsValueUnspecified() &&
715 (wasUnspecified
|| !UsesAutoUnspecified()) )
717 variant
= child
->GetDefaultValue();
720 list
.Append(variant
);
727 // Empty, becomes unspecified
729 variant2
.SetName(child
->GetLabel());
730 list
.Append(variant2
);
735 if ( curChild
>= iMax
)
739 tokenStart
= 0xFFFFFF;
744 // Token is not running
748 addOnlyIfNotEmpty
= false;
750 // Is this a group of tokens?
755 if ( it
!= text
.end() ) it
++;
757 size_t startPos
= pos
;
759 // Group item - find end
760 while ( it
!= text
.end() && depth
> 0 )
768 else if ( a
== wxS('[') )
772 token
= text
.substr(startPos
,pos
-startPos
-1);
774 if ( !token
.length() )
777 const wxPGProperty
* child
= Item(curChild
);
779 wxVariant
variant(child
->GetValueRef());
780 if ( child
->StringToValue( variant
, token
, propagatedFlags
) )
782 // Use label instead of name, as name can be empty string, but
783 // label in practice never is.
784 variant
.SetName(child
->GetLabel());
785 list
.Append(variant
);
790 // Failed, becomes unspecified
792 variant2
.SetName(child
->GetLabel());
793 list
.Append(variant2
);
798 if ( curChild
>= iMax
)
801 addOnlyIfNotEmpty
= true;
803 tokenStart
= 0xFFFFFF;
809 if ( a
== delimeter
)
822 if ( it
!= text
.end() )
839 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
841 wxVariant
variant(m_value
);
842 bool res
= StringToValue(variant
, text
, argFlags
);
848 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
850 wxVariant
variant(m_value
);
851 bool res
= IntToValue(variant
, number
, argFlags
);
857 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
860 return wxSize(m_valueBitmap
->GetWidth(),-1);
865 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
867 return wxPGGlobalVars
->m_defaultRenderer
;
870 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
874 wxBitmap
* bmp
= m_valueBitmap
;
876 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
878 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
880 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
883 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
885 return wxPG_EDITOR(TextCtrl
);
888 // Default extra property event handling - that is, none at all.
889 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
895 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
897 if ( !value
.IsNull() )
900 // List variants are reserved a special purpose
901 // as intermediate containers for child values
902 // of properties with children.
903 if ( wxPGIsVariantType(value
, list
) )
906 AdaptListToValue(value
, &newValue
);
908 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
911 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
912 flags
|= wxPG_SETVAL_AGGREGATED
;
914 if ( pList
&& !pList
->IsNull() )
916 wxASSERT( wxPGIsVariantType(*pList
, list
) );
917 wxASSERT( GetChildCount() );
918 wxASSERT( !IsCategory() );
920 wxVariantList
& list
= pList
->GetList();
921 wxVariantList::iterator node
;
924 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
926 // Children in list can be in any order, but we will give hint to
927 // GetPropertyByLabelWH(). This optimizes for full list parsing.
928 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
930 wxVariant
& childValue
= *((wxVariant
*)*node
);
931 wxPGProperty
* child
= GetPropertyByLabelWH(childValue
.GetName(), i
);
934 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetLabel().c_str(),childValue.GetType().c_str());
935 if ( wxPGIsVariantType(childValue
, list
) )
937 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
939 wxVariant listRefCopy
= childValue
;
940 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
944 wxVariant oldVal
= child
->GetValue();
945 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
948 else if ( !wxPG_VARIANT_EQ(child
->GetValue(), childValue
) )
949 // This flag is not normally set when setting value programmatically.
950 // However, this loop is usually only executed when called from
951 // DoPropertyChanged, which should set this flag.
953 // For aggregate properties, we will trust RefreshChildren()
954 // to update child values.
955 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
956 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
957 child
->SetFlag(wxPG_PROP_MODIFIED
);
964 if ( !value
.IsNull() )
966 wxPGVariantAssign(m_value
, value
);
969 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
970 UpdateParentValues();
974 SetFlag(wxPG_PROP_MODIFIED
);
976 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
981 if ( m_commonValue
!= -1 )
983 wxPropertyGrid
* pg
= GetGrid();
984 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
990 // Set children to unspecified, but only if aggregate or
991 // value is <composed>
992 if ( AreChildrenComponents() )
995 for ( i
=0; i
<GetChildCount(); i
++ )
996 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1001 // Update editor control
1004 // We need to check for these, otherwise GetGrid() may fail.
1005 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1010 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1012 GetGrid()->ValueChangeInEvent(value
);
1015 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1023 for ( i
= 0; i
< GetChildCount(); i
++ )
1024 Item(i
)->SetFlagRecursively(flag
, set
);
1027 void wxPGProperty::RefreshEditor()
1029 if ( m_parent
&& GetParentState() )
1031 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1032 if ( pg
->GetSelectedProperty() == this )
1034 wxWindow
* editor
= pg
->GetEditorControl();
1036 GetEditorClass()->UpdateControl( this, editor
);
1042 wxVariant
wxPGProperty::GetDefaultValue() const
1044 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1045 if ( !defVal
.IsNull() )
1048 wxVariant value
= GetValue();
1050 if ( !value
.IsNull() )
1052 wxPGVariantDataClassInfo classInfo
= wxPGVariantDataGetClassInfo(value
.GetData());
1053 if ( wxPGIsVariantClassInfo(classInfo
, long) )
1054 return wxPGVariant_Zero
;
1055 if ( wxPGIsVariantClassInfo(classInfo
, string
) )
1056 return wxPGVariant_EmptyString
;
1057 if ( wxPGIsVariantClassInfo(classInfo
, bool) )
1058 return wxPGVariant_False
;
1059 if ( wxPGIsVariantClassInfo(classInfo
, double) )
1060 return wxVariant(0.0);
1062 wxPGVariantData
* pgvdata
= wxDynamicCastVariantData(m_value
.GetData(), wxPGVariantData
);
1064 return pgvdata
->GetDefaultValue();
1066 if ( wxPGIsVariantClassInfo(classInfo
, arrstring
) )
1067 return wxVariant(wxArrayString());
1068 if ( wxPGIsVariantClassInfo(classInfo
, wxColour
) )
1069 return WXVARIANT(*wxRED
);
1071 if ( wxPGIsVariantClassInfo(classInfo
, datetime
) )
1072 return wxVariant(wxDateTime::Now());
1076 wxString::Format(wxT("Inorder for value to have default value, it must be added to")
1077 wxT("wxPGProperty::GetDefaultValue or it's variantdata must inherit")
1078 wxT("from wxPGVariantData (unrecognized type was '%s')"),m_value
.GetType().c_str())
1085 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1087 if ( column
>= (int)m_cells
.size() )
1088 m_cells
.SetCount(column
+1, NULL
);
1090 delete (wxPGCell
*) m_cells
[column
];
1091 m_cells
[column
] = cellObj
;
1094 void wxPGProperty::SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
)
1096 // Changes value of a property with choices, but only
1097 // works if the value type is long or string.
1098 wxString ts
= GetValue().GetType();
1100 wxCHECK_RET( choiceInfo
.m_choices
, wxT("invalid choiceinfo") );
1102 if ( ts
== wxS("long") )
1104 SetValue( (long) newValue
);
1106 else if ( ts
== wxS("string") )
1108 SetValue( choiceInfo
.m_choices
->GetLabel(newValue
) );
1113 wxString
wxPGProperty::GetChoiceString( unsigned int index
)
1117 wxASSERT(ci
.m_choices
);
1118 return ci
.m_choices
->GetLabel(index
);
1121 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1123 wxPropertyGrid
* pg
= GetGrid();
1126 ci
.m_choices
= (wxPGChoices
*) NULL
;
1127 int sel
= GetChoiceInfo(&ci
);
1134 index
= ci
.m_choices
->GetCount();
1139 ci
.m_choices
->Insert(label
, index
, value
);
1141 if ( sel
!= newSel
)
1142 SetChoiceSelection(newSel
, ci
);
1144 if ( this == pg
->GetSelection() )
1145 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1154 void wxPGProperty::DeleteChoice( int index
)
1156 wxPropertyGrid
* pg
= GetGrid();
1159 ci
.m_choices
= (wxPGChoices
*) NULL
;
1160 int sel
= GetChoiceInfo(&ci
);
1166 // Adjust current value
1169 SetValueToUnspecified();
1172 else if ( index
< sel
)
1177 ci
.m_choices
->RemoveAt(index
);
1179 if ( sel
!= newSel
)
1180 SetChoiceSelection(newSel
, ci
);
1182 if ( this == pg
->GetSelection() )
1183 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1187 int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo
* WXUNUSED(info
) )
1192 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1197 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1202 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1204 if ( DoSetAttribute( name
, value
) )
1206 // Support working without grid, when possible
1207 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1211 m_attributes
.Set( name
, value
);
1214 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1216 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1219 while ( attributes
.GetNext(it
, variant
) )
1220 SetAttribute( variant
.GetName(), variant
);
1223 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1229 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1231 return m_attributes
.FindValue(name
);
1234 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1236 wxVariant variant
= m_attributes
.FindValue(name
);
1238 if ( !variant
.IsNull() )
1239 return variant
.GetString();
1244 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1246 wxVariant variant
= m_attributes
.FindValue(name
);
1248 return wxPGVariantToInt(variant
, defVal
);
1251 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1254 wxVariant variant
= m_attributes
.FindValue(name
);
1256 if ( wxPGVariantToDouble(variant
, &retVal
) )
1262 wxVariant
wxPGProperty::GetAttributesAsList() const
1264 wxVariantList tempList
;
1265 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1267 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1270 while ( m_attributes
.GetNext(it
, variant
) )
1276 // Slots of utility flags are NULL
1277 const unsigned int gs_propFlagToStringSize
= 14;
1279 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1296 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1299 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1303 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1305 if ( relevantFlags
& a
)
1307 const wxChar
* fs
= gs_propFlagToString
[i
];
1319 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1323 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1325 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1327 const wxChar
* fs
= gs_propFlagToString
[i
];
1328 if ( fs
&& str
== fs
)
1334 WX_PG_TOKENIZER1_END()
1336 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1339 wxValidator
* wxPGProperty::DoGetValidator() const
1341 return (wxValidator
*) NULL
;
1344 wxPGChoices
& wxPGProperty::GetChoices()
1346 wxPGChoiceInfo choiceInfo
;
1347 choiceInfo
.m_choices
= NULL
;
1348 GetChoiceInfo(&choiceInfo
);
1349 return *choiceInfo
.m_choices
;
1352 const wxPGChoices
& wxPGProperty::GetChoices() const
1354 return (const wxPGChoices
&) ((wxPGProperty
*)this)->GetChoices();
1357 unsigned int wxPGProperty::GetChoiceCount() const
1359 const wxPGChoices
& choices
= GetChoices();
1360 if ( &choices
&& choices
.IsOk() )
1361 return choices
.GetCount();
1365 const wxPGChoiceEntry
* wxPGProperty::GetCurrentChoice() const
1368 ci
.m_choices
= (wxPGChoices
*) NULL
;
1369 int index
= ((wxPGProperty
*)this)->GetChoiceInfo(&ci
);
1370 if ( index
== -1 || !ci
.m_choices
|| index
>= (int)ci
.m_choices
->GetCount() )
1373 return &(*ci
.m_choices
)[index
];
1376 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1379 ci
.m_choices
= (wxPGChoices
*) NULL
;
1385 ci
.m_choices
->Assign(choices
);
1389 // This may be needed to trigger some initialization
1390 // (but don't do it if property is somewhat uninitialized)
1391 wxVariant defVal
= GetDefaultValue();
1392 if ( defVal
.IsNull() )
1404 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1406 const wxPGEditor
* editor
;
1408 if ( !m_customEditor
)
1410 editor
= DoGetEditorClass();
1413 editor
= m_customEditor
;
1416 // Maybe override editor if common value specified
1417 if ( GetDisplayedCommonValueCount() )
1419 // TextCtrlAndButton -> ComboBoxAndButton
1420 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1421 editor
= wxPG_EDITOR(ChoiceAndButton
);
1423 // TextCtrl -> ComboBox
1424 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1425 editor
= wxPG_EDITOR(ComboBox
);
1432 // Privatizes set of choices
1433 void wxPGProperty::SetChoicesExclusive()
1436 ci
.m_choices
= (wxPGChoices
*) NULL
;
1440 ci
.m_choices
->SetExclusive();
1443 bool wxPGProperty::HasVisibleChildren() const
1447 for ( i
=0; i
<GetChildCount(); i
++ )
1449 wxPGProperty
* child
= Item(i
);
1451 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1458 bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid
* propGrid
)
1460 return propGrid
->EditorValidate();
1464 bool wxPGProperty::RecreateEditor()
1466 wxPropertyGrid
* pg
= GetGrid();
1469 wxPGProperty
* selected
= pg
->GetSelection();
1470 if ( this == selected
)
1472 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1479 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1481 delete m_valueBitmap
;
1483 if ( &bmp
&& bmp
.Ok() )
1486 wxSize maxSz
= GetGrid()->GetImageSize();
1487 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1489 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1491 // Create a memory DC
1492 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1495 dc
.SelectObject(*bmpNew
);
1498 // FIXME: This is ugly - use image or wait for scaling patch.
1499 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1500 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1502 dc
.SetUserScale(scaleX
,scaleY
);
1504 dc
.DrawBitmap( bmp
, 0, 0 );
1506 m_valueBitmap
= bmpNew
;
1510 m_valueBitmap
= new wxBitmap(bmp
);
1513 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1517 m_valueBitmap
= NULL
;
1518 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1523 wxPGProperty
* wxPGProperty::GetMainParent() const
1525 const wxPGProperty
* curChild
= this;
1526 const wxPGProperty
* curParent
= m_parent
;
1528 while ( curParent
&& !curParent
->IsCategory() )
1530 curChild
= curParent
;
1531 curParent
= curParent
->m_parent
;
1534 return (wxPGProperty
*) curChild
;
1538 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1541 // Returns last visible sub-item, recursively.
1542 if ( !IsExpanded() || !GetChildCount() )
1545 return Last()->GetLastVisibleSubItem();
1549 bool wxPGProperty::IsVisible() const
1551 const wxPGProperty
* parent
;
1553 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1556 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1558 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1565 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1567 wxPropertyGridPageState
* state
= GetParentState();
1568 wxPropertyGrid
* propGrid
= state
->GetGrid();
1569 if ( state
== propGrid
->GetState() )
1575 int wxPGProperty::GetY2( int lh
) const
1577 const wxPGProperty
* parent
;
1578 const wxPGProperty
* child
= this;
1582 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1584 if ( !parent
->IsExpanded() )
1586 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1591 y
-= lh
; // need to reduce one level
1597 int wxPGProperty::GetY() const
1599 return GetY2(GetGrid()->GetRowHeight());
1603 wxPGProperty
* wxPGPropArgCls::GetPtr( wxPropertyGridInterface
* methods
) const
1607 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
1608 return m_ptr
.property
;
1610 else if ( m_isName
== 1 )
1611 return methods
->GetPropertyByNameA(*m_ptr
.name
);
1612 else if ( m_isName
== 2 )
1613 return methods
->GetPropertyByNameA(m_ptr
.rawname
);
1614 // 3 is like 1, but ptr is freed in dtor - only needed by wxPython bindings.
1615 else if ( m_isName
== 3 )
1616 return methods
->GetPropertyByNameA(*m_ptr
.name
);
1618 wxASSERT( m_isName
<= 3 );
1622 // This is used by Insert etc.
1623 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1625 if ( index
< 0 || (size_t)index
>= m_children
.GetCount() )
1627 if ( correct_mode
) prop
->m_arrIndex
= m_children
.GetCount();
1628 m_children
.Add( prop
);
1632 m_children
.Insert( prop
, index
);
1633 if ( correct_mode
) FixIndexesOfChildren( index
);
1636 prop
->m_parent
= this;
1639 // This is used by properties that have fixed sub-properties
1640 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1642 prop
->m_arrIndex
= m_children
.GetCount();
1643 m_children
.Add( prop
);
1645 int custImgHeight
= prop
->OnMeasureImage().y
;
1646 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1647 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1649 prop
->m_parent
= this;
1653 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1655 wxASSERT( GetChildCount() );
1656 wxASSERT( !IsCategory() );
1658 *value
= GetValue();
1660 if ( !list
.GetCount() )
1663 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1665 bool allChildrenSpecified
;
1667 // Don't fully update aggregate properties unless all children have
1669 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1670 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1672 allChildrenSpecified
= true;
1674 wxVariant childValue
= list
[0];
1678 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetLabel().c_str());
1680 for ( i
=0; i
<GetChildCount(); i
++ )
1682 const wxPGProperty
* child
= Item(i
);
1684 if ( childValue
.GetName() == child
->GetLabel() )
1686 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1688 if ( wxPGIsVariantType(childValue
, list
) )
1690 wxVariant
cv2(child
->GetValue());
1691 child
->AdaptListToValue(childValue
, &cv2
);
1695 if ( allChildrenSpecified
)
1696 ChildChanged(*value
, i
, childValue
);
1698 if ( n
== (unsigned int)list
.GetCount() )
1700 childValue
= list
[n
];
1706 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1709 for ( i
=starthere
;i
<GetChildCount();i
++)
1710 Item(i
)->m_arrIndex
= i
;
1714 // Returns (direct) child property with given name (or NULL if not found)
1715 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1719 for ( i
=0; i
<GetChildCount(); i
++ )
1721 wxPGProperty
* p
= Item(i
);
1722 if ( p
->m_name
== name
)
1726 // Does it have point, then?
1727 int pos
= name
.Find(wxS('.'));
1729 return (wxPGProperty
*) NULL
;
1731 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1733 if ( !p
|| !p
->GetChildCount() )
1736 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1739 wxPGProperty
* wxPGProperty::GetPropertyByLabelWH( const wxString
& label
, unsigned int hintIndex
) const
1741 unsigned int i
= hintIndex
;
1743 if ( i
>= GetChildCount() )
1746 unsigned int lastIndex
= i
- 1;
1748 if ( lastIndex
>= GetChildCount() )
1749 lastIndex
= GetChildCount() - 1;
1753 wxPGProperty
* p
= Item(i
);
1754 if ( p
->m_label
== label
)
1757 if ( i
== lastIndex
)
1761 if ( i
== GetChildCount() )
1768 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1770 // Returns height of children, recursively, and
1771 // by taking expanded/collapsed status into account.
1773 // iMax is used when finding property y-positions.
1779 iMax_
= GetChildCount();
1781 unsigned int iMax
= iMax_
;
1783 wxASSERT( iMax
<= GetChildCount() );
1785 if ( !IsExpanded() && GetParent() )
1790 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1792 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1794 if ( !pwc
->IsExpanded() ||
1795 pwc
->GetChildCount() == 0 )
1798 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1807 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1809 wxASSERT( nextItemY
);
1811 // Linear search at the moment
1813 // nextItemY = y of next visible property, final value will be written back.
1814 wxPGProperty
* result
= NULL
;
1815 wxPGProperty
* current
= NULL
;
1816 unsigned int iy
= *nextItemY
;
1818 unsigned int iMax
= GetChildCount();
1822 wxPGProperty
* pwc
= Item(i
);
1824 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1835 if ( pwc
->IsExpanded() &&
1836 pwc
->GetChildCount() > 0 )
1838 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1850 if ( !result
&& y
< iy
)
1857 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1859 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1862 return (wxPGProperty
*) result
;
1865 void wxPGProperty::Empty()
1868 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1870 for ( i
=0; i
<GetChildCount(); i
++ )
1872 wxPGProperty
* p
= (wxPGProperty
*) Item(i
);
1880 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1881 int WXUNUSED(childIndex
),
1882 wxVariant
& WXUNUSED(childValue
) ) const
1886 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1890 const wxVariantList
* pList
= NULL
;
1891 wxVariantList::const_iterator node
;
1895 pList
= &pendingList
->GetList();
1896 node
= pList
->begin();
1899 // Children in list can be in any order, but we will give hint to
1900 // GetPropertyByLabelWH(). This optimizes for full list parsing.
1901 for ( i
=0; i
<GetChildCount(); i
++ )
1903 wxPGProperty
* child
= Item(i
);
1904 const wxVariant
* listValue
= NULL
;
1909 const wxString
& childLabel
= child
->GetLabel();
1911 for ( ; node
!= pList
->end(); node
++ )
1913 const wxVariant
& item
= *((const wxVariant
*)*node
);
1914 if ( item
.GetName() == childLabel
)
1924 value
= child
->GetValue();
1926 if ( value
.IsNull() )
1929 // Check recursively
1930 if ( child
->GetChildCount() )
1932 const wxVariant
* childList
= NULL
;
1934 if ( listValue
&& wxPGIsVariantType(*listValue
, list
) )
1935 childList
= listValue
;
1937 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1945 wxPGProperty
* wxPGProperty::UpdateParentValues()
1947 wxPGProperty
* parent
= m_parent
;
1948 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1949 !parent
->IsCategory() && !parent
->IsRoot() )
1952 parent
->GenerateComposedValue(s
, 0);
1953 parent
->m_value
= s
;
1954 return parent
->UpdateParentValues();
1959 bool wxPGProperty::IsTextEditable() const
1961 if ( HasFlag(wxPG_PROP_READONLY
) )
1964 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1966 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1973 // Call for after sub-properties added with AddChild
1974 void wxPGProperty::PrepareSubProperties()
1976 wxPropertyGridPageState
* state
= GetParentState();
1980 if ( !GetChildCount() )
1983 wxByte depth
= m_depth
+ 1;
1984 wxByte depthBgCol
= m_depthBgCol
;
1986 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1988 wxByte bgColIndex
= m_bgColIndex
;
1989 wxByte fgColIndex
= m_fgColIndex
;
1992 // Set some values to the children
1995 wxPGProperty
* nparent
= this;
1997 while ( i
< nparent
->GetChildCount() )
1999 wxPGProperty
* np
= nparent
->Item(i
);
2001 np
->m_parentState
= state
;
2002 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
2003 np
->m_depth
= depth
;
2004 np
->m_depthBgCol
= depthBgCol
;
2005 np
->m_bgColIndex
= bgColIndex
;
2006 np
->m_fgColIndex
= fgColIndex
;
2008 // Also handle children of children
2009 if ( np
->GetChildCount() > 0 )
2015 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
2016 nparent
->SetExpanded(false);
2025 // After reaching last sibling, go back to processing
2026 // siblings of the parent
2027 while ( i
>= nparent
->GetChildCount() )
2029 // Exit the loop when top parent hit
2030 if ( nparent
== this )
2035 i
= nparent
->GetArrIndex() + 1;
2036 nparent
= nparent
->GetParent();
2041 // Call after fixed sub-properties added/removed after creation.
2042 // if oldSelInd >= 0 and < new max items, then selection is
2043 // moved to it. Note: oldSelInd -2 indicates that this property
2044 // should be selected.
2045 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2047 wxPropertyGridPageState
* state
= GetParentState();
2048 wxPropertyGrid
* grid
= state
->GetGrid();
2050 PrepareSubProperties();
2052 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2053 if ( oldSelInd
>= (int)m_children
.GetCount() )
2054 oldSelInd
= (int)m_children
.GetCount() - 1;
2056 if ( oldSelInd
>= 0 )
2057 sel
= (wxPGProperty
*) m_children
[oldSelInd
];
2058 else if ( oldSelInd
== -2 )
2062 state
->DoSelectProperty(sel
);
2064 if ( state
== grid
->GetState() )
2066 grid
->GetPanel()->Refresh();
2070 // -----------------------------------------------------------------------
2072 // -----------------------------------------------------------------------
2074 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2075 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2078 wxPGRootProperty::wxPGRootProperty()
2082 m_name
= wxS("<root>");
2089 wxPGRootProperty::~wxPGRootProperty()
2094 // -----------------------------------------------------------------------
2095 // wxPropertyCategory
2096 // -----------------------------------------------------------------------
2098 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2099 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2101 void wxPropertyCategory::Init()
2103 // don't set colour - prepareadditem method should do this
2104 SetParentalType(wxPG_PROP_CATEGORY
);
2105 m_capFgColIndex
= 1;
2109 wxPropertyCategory::wxPropertyCategory()
2116 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2117 : wxPGProperty(label
,name
)
2123 wxPropertyCategory::~wxPropertyCategory()
2128 wxString
wxPropertyCategory::GetValueAsString( int ) const
2130 return wxEmptyString
;
2133 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2135 if ( m_textExtent
> 0 )
2136 return m_textExtent
;
2138 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2142 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2145 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2149 // -----------------------------------------------------------------------
2150 // wxPGAttributeStorage
2151 // -----------------------------------------------------------------------
2153 wxPGAttributeStorage::wxPGAttributeStorage()
2157 wxPGAttributeStorage::~wxPGAttributeStorage()
2159 wxPGHashMapS2P::iterator it
;
2161 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2163 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2168 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2170 wxVariantData
* data
= value
.GetData();
2173 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2174 if ( it
!= m_map
.end() )
2175 ((wxVariantData
*)it
->second
)->DecRef();