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"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
52 #include <wx/propgrid/propgrid.h>
57 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
60 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
63 // -----------------------------------------------------------------------
65 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
67 #if defined(__WXMSW__) && !defined(__WXWINCE__)
68 // FIXME: Use DrawFocusRect code above (currently it draws solid line
69 // for caption focus but works ok for other stuff).
70 // Also, it seems that this code may not work in future wx versions.
71 dc
.SetLogicalFunction(wxINVERT
);
73 wxPen
pen(*wxBLACK
,1,wxDOT
);
74 pen
.SetCap(wxCAP_BUTT
);
76 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
78 dc
.DrawRectangle(rect
);
80 dc
.SetLogicalFunction(wxCOPY
);
82 dc
.SetLogicalFunction(wxINVERT
);
84 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
85 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
87 dc
.DrawRectangle(rect
);
89 dc
.SetLogicalFunction(wxCOPY
);
93 // -----------------------------------------------------------------------
95 // -----------------------------------------------------------------------
97 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
99 int WXUNUSED(item
) ) const
104 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
105 int xOffset
, const wxString
& text
) const
108 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
110 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
111 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
114 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
115 int xOffset
, const wxString
& text
,
116 wxPGProperty
* property
,
117 const wxPGEditor
* editor
) const
120 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
122 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
129 rect2
.height
-= yOffset
;
130 editor
->DrawValue( dc
, rect2
, property
, text
);
135 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
140 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
142 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
143 wxPGDrawFocusRect(dc
,focusRect
);
146 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
150 if ( !(flags
& Selected
) )
152 // Draw using wxPGCell information, if available
153 wxColour fgCol
= cell
.GetFgCol();
155 dc
.SetTextForeground(fgCol
);
157 wxColour bgCol
= cell
.GetBgCol();
162 dc
.DrawRectangle(rect
);
166 const wxBitmap
& bmp
= cell
.GetBitmap();
168 // In control, do not draw oversized bitmap
169 (!(flags
& Control
) || bmp
.GetHeight() < rect
.height
)
173 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
174 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
176 imageOffset
= bmp
.GetWidth();
182 // -----------------------------------------------------------------------
183 // wxPGDefaultRenderer
184 // -----------------------------------------------------------------------
186 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
187 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
188 int column
, int item
, int flags
) const
190 bool isUnspecified
= property
->IsValueUnspecified();
192 if ( column
== 1 && item
== -1 )
194 int cmnVal
= property
->GetCommonValue();
198 if ( !isUnspecified
)
199 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
204 const wxPGEditor
* editor
= NULL
;
205 const wxPGCell
* cell
= property
->GetCell(column
);
211 if ( column
== 1 && (flags
& Control
) )
213 const wxPGCell
* ccell
= property
->GetCurrentChoice();
215 ( ccell
->GetBitmap().IsOk() || ccell
->GetFgCol().IsOk() || ccell
->GetBgCol().IsOk() )
222 int preDrawFlags
= flags
;
224 if ( propertyGrid
->GetInternalFlags() & wxPG_FL_CELL_OVERRIDES_SEL
)
225 preDrawFlags
= preDrawFlags
& ~(Selected
);
227 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
228 text
= cell
->GetText();
229 if ( text
== wxS("@!") )
232 text
= property
->GetLabel();
233 else if ( column
== 1 )
234 text
= property
->GetValueString();
236 text
= wxEmptyString
;
239 else if ( column
== 0 )
242 DrawText( dc
, rect
, 0, property
->GetLabel() );
244 else if ( column
== 1 )
246 if ( !isUnspecified
)
248 editor
= property
->GetColumnEditor(column
);
250 // Regular property value
252 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
254 wxPGPaintData paintdata
;
255 paintdata
.m_parent
= propertyGrid
;
256 paintdata
.m_choiceItem
= item
;
258 if ( imageSize
.x
> 0 )
260 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
261 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
262 wxPG_CUSTOM_IMAGE_WIDTH
,
263 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
265 /*if ( imageSize.x == wxPG_FULL_CUSTOM_PAINT_WIDTH )
267 imageRect.width = m_width - imageRect.x;
270 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
272 paintdata
.m_drawnWidth
= imageSize
.x
;
273 paintdata
.m_drawnHeight
= imageSize
.y
;
275 if ( !isUnspecified
)
277 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
281 dc
.SetBrush(*wxWHITE_BRUSH
);
282 dc
.DrawRectangle(imageRect
);
285 imageOffset
= paintdata
.m_drawnWidth
;
288 text
= property
->GetValueString();
291 if ( propertyGrid
->GetColumnCount() <= 2 )
293 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
294 if ( unitsString
.length() )
295 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
299 if ( text
.length() == 0 )
301 // Try to show inline help if no text
302 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
303 if ( !vInlineHelp
.IsNull() )
305 text
= vInlineHelp
.GetString();
306 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
310 else if ( column
== 2 )
313 if ( !text
.length() )
314 text
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
317 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
319 // active caption gets nice dotted rectangle
320 if ( property
->IsCategory() /*&& column == 0*/ )
322 if ( flags
& Selected
)
324 if ( imageOffset
> 0 )
325 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
327 DrawCaptionSelectionRect( dc
,
328 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
329 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
330 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
331 propertyGrid
->GetCaptionFont())
332 +(wxPG_CAPRECTXMARGIN
*2),
333 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
338 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
342 if ( property
&& column
== 1 )
346 wxBitmap
* bmp
= property
->GetValueImage();
348 if ( bmp
&& bmp
->Ok() )
349 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
355 // -----------------------------------------------------------------------
357 // -----------------------------------------------------------------------
363 wxPGCell::wxPGCell( const wxString
& text
,
364 const wxBitmap
& bitmap
,
365 const wxColour
& fgCol
,
366 const wxColour
& bgCol
)
367 : m_bitmap(bitmap
), m_fgCol(fgCol
), m_bgCol(bgCol
)
372 // -----------------------------------------------------------------------
374 // -----------------------------------------------------------------------
376 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
378 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
380 void wxPGProperty::Init()
386 m_parentState
= (wxPropertyGridPageState
*) NULL
;
389 m_clientObject
= NULL
;
391 m_customEditor
= (wxPGEditor
*) NULL
;
393 m_validator
= (wxValidator
*) NULL
;
395 m_valueBitmap
= (wxBitmap
*) NULL
;
397 m_maxLen
= 0; // infinite maximum length
399 m_flags
= wxPG_PROP_PROPERTY
;
409 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
411 // We really need to check if &label and &name are NULL pointers
412 // (this can if we are called before property grid has been initalized)
414 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
417 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
420 DoSetName( m_label
);
425 wxPGProperty::wxPGProperty()
432 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
439 wxPGProperty::~wxPGProperty()
441 delete m_clientObject
;
443 Empty(); // this deletes items
445 delete m_valueBitmap
;
452 for ( i
=0; i
<m_cells
.size(); i
++ )
453 delete (wxPGCell
*) m_cells
[i
];
455 // This makes it easier for us to detect dangling pointers
460 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
462 wxPGProperty
* parent
= m_parent
;
465 if ( parent
== candidate
)
467 parent
= parent
->m_parent
;
473 wxString
wxPGProperty::GetName() const
475 wxPGProperty
* parent
= GetParent();
477 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
480 return m_parent
->GetName() + wxS(".") + m_name
;
483 wxPropertyGrid
* wxPGProperty::GetGrid() const
485 if ( !m_parentState
)
487 return m_parentState
->GetGrid();
491 void wxPGProperty::UpdateControl( wxWindow
* primary
)
494 GetEditorClass()->UpdateControl(this, primary
);
497 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
502 void wxPGProperty::OnSetValue()
506 void wxPGProperty::RefreshChildren ()
510 wxString
wxPGProperty::GetColumnText( unsigned int col
) const
512 wxPGCell
* cell
= GetCell(col
);
515 return cell
->GetText();
522 return GetDisplayedString();
524 return GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
527 return wxEmptyString
;
530 void wxPGProperty::GenerateComposedValue( wxString
& text
, int argFlags
) const
533 int iMax
= m_children
.GetCount();
539 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
540 !(argFlags
& wxPG_FULL_VALUE
) )
541 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
543 int iMaxMinusOne
= iMax
-1;
545 if ( !IsTextEditable() )
546 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
548 wxPGProperty
* curChild
= (wxPGProperty
*) m_children
.Item(0);
550 for ( i
= 0; i
< iMax
; i
++ )
553 if ( !curChild
->IsValueUnspecified() )
554 s
= curChild
->GetValueString(argFlags
|wxPG_COMPOSITE_FRAGMENT
);
557 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
560 if ( !curChild
->GetChildCount() || skip
)
563 text
+= wxS("[") + s
+ wxS("]");
565 if ( i
< iMaxMinusOne
)
567 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
568 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
569 !(argFlags
& wxPG_FULL_VALUE
) )
574 if ( !curChild
->GetChildCount() )
580 curChild
= (wxPGProperty
*) m_children
.Item(i
+1);
584 // Remove superfluous semicolon and space
586 if ( text
.EndsWith(wxS("; "), &rest
) )
589 if ( (unsigned int)i
< m_children
.GetCount() )
590 text
+= wxS("; ...");
593 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
595 wxCHECK_MSG( GetChildCount() > 0,
597 wxT("If user property does not have any children, it must override GetValueAsString") );
600 GenerateComposedValue(text
, argFlags
);
604 wxString
wxPGProperty::GetValueString( int argFlags
) const
606 if ( IsValueUnspecified() )
607 return wxEmptyString
;
609 if ( m_commonValue
== -1 )
610 return GetValueAsString(argFlags
);
613 // Return common value's string representation
614 wxPropertyGrid
* pg
= GetGrid();
615 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
617 if ( argFlags
& wxPG_FULL_VALUE
)
619 return cv
->GetLabel();
621 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
623 return cv
->GetEditableText();
627 return cv
->GetLabel();
631 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
633 variant
= (long)number
;
637 // Convert semicolon delimited tokens into child values.
638 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
640 if ( !GetChildCount() )
643 unsigned int curChild
= 0;
645 unsigned int iMax
= m_children
.GetCount();
647 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
648 !(argFlags
& wxPG_FULL_VALUE
) )
649 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
651 bool changed
= false;
656 // Its best only to add non-empty group items
657 bool addOnlyIfNotEmpty
= false;
658 const wxChar delimeter
= wxS(';');
660 size_t tokenStart
= 0xFFFFFF;
662 wxVariantList temp_list
;
663 wxVariant
list(temp_list
);
665 int propagatedFlags
= argFlags
& wxPG_REPORT_ERROR
;
668 bool debug_print
= false;
673 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
676 wxString::const_iterator it
= text
.begin();
679 if ( it
!= text
.end() )
686 if ( tokenStart
!= 0xFFFFFF )
689 if ( a
== delimeter
|| a
== 0 )
691 token
= text
.substr(tokenStart
,pos
-tokenStart
);
693 size_t len
= token
.length();
695 if ( !addOnlyIfNotEmpty
|| len
> 0 )
697 const wxPGProperty
* child
= Item(curChild
);
700 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().c_str());
705 bool wasUnspecified
= child
->IsValueUnspecified();
707 wxVariant
variant(child
->GetValueRef());
708 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
710 variant
.SetName(child
->GetBaseName());
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
->GetBaseName());
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 oldChildValue
= child
->GetValue();
780 wxVariant
variant(oldChildValue
);
781 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
782 if ( stvRes
|| (variant
!= oldChildValue
) )
789 // Failed, becomes unspecified
794 variant
.SetName(child
->GetBaseName());
795 list
.Append(variant
);
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() )
899 wxVariant tempListVariant
;
902 // List variants are reserved a special purpose
903 // as intermediate containers for child values
904 // of properties with children.
905 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
908 // However, situation is different for composed string properties
909 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
911 tempListVariant
= value
;
912 pList
= &tempListVariant
;
916 AdaptListToValue(value
, &newValue
);
918 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
921 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
922 flags
|= wxPG_SETVAL_AGGREGATED
;
924 if ( pList
&& !pList
->IsNull() )
926 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
927 wxASSERT( GetChildCount() );
928 wxASSERT( !IsCategory() );
930 wxVariantList
& list
= pList
->GetList();
931 wxVariantList::iterator node
;
934 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
936 // Children in list can be in any order, but we will give hint to
937 // GetPropertyByNameWH(). This optimizes for full list parsing.
938 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
940 wxVariant
& childValue
= *((wxVariant
*)*node
);
941 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
944 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
945 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
947 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
949 wxVariant listRefCopy
= childValue
;
950 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
954 wxVariant oldVal
= child
->GetValue();
955 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
958 else if ( child
->GetValue() != childValue
)
960 // For aggregate properties, we will trust RefreshChildren()
961 // to update child values.
962 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
963 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
964 if ( flags
& wxPG_SETVAL_BY_USER
)
965 child
->SetFlag(wxPG_PROP_MODIFIED
);
972 if ( !value
.IsNull() )
977 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
978 UpdateParentValues();
981 if ( flags
& wxPG_SETVAL_BY_USER
)
982 SetFlag(wxPG_PROP_MODIFIED
);
984 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
989 if ( m_commonValue
!= -1 )
991 wxPropertyGrid
* pg
= GetGrid();
992 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
998 // Set children to unspecified, but only if aggregate or
999 // value is <composed>
1000 if ( AreChildrenComponents() )
1003 for ( i
=0; i
<GetChildCount(); i
++ )
1004 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1009 // Update editor control
1012 // We need to check for these, otherwise GetGrid() may fail.
1013 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1018 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1020 GetGrid()->ValueChangeInEvent(value
);
1023 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1031 for ( i
= 0; i
< GetChildCount(); i
++ )
1032 Item(i
)->SetFlagRecursively(flag
, set
);
1035 void wxPGProperty::RefreshEditor()
1037 if ( m_parent
&& GetParentState() )
1039 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1040 if ( pg
->GetSelectedProperty() == this )
1042 wxWindow
* editor
= pg
->GetEditorControl();
1044 GetEditorClass()->UpdateControl( this, editor
);
1050 wxVariant
wxPGProperty::GetDefaultValue() const
1052 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1053 if ( !defVal
.IsNull() )
1056 wxVariant value
= GetValue();
1058 if ( !value
.IsNull() )
1060 wxString
valueType(value
.GetType());
1062 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1063 return wxPGVariant_Zero
;
1064 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1065 return wxPGVariant_EmptyString
;
1066 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1067 return wxPGVariant_False
;
1068 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1069 return wxVariant(0.0);
1070 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1071 return wxVariant(wxArrayString());
1072 if ( valueType
== wxS("wxLongLong") )
1073 return WXVARIANT(wxLongLong(0));
1074 if ( valueType
== wxS("wxULongLong") )
1075 return WXVARIANT(wxULongLong(0));
1076 if ( valueType
== wxS("wxColour") )
1077 return WXVARIANT(*wxBLACK
);
1079 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1080 return wxVariant(wxDateTime::Now());
1082 if ( valueType
== wxS("wxFont") )
1083 return WXVARIANT(*wxNORMAL_FONT
);
1084 if ( valueType
== wxS("wxPoint") )
1085 return WXVARIANT(wxPoint(0, 0));
1086 if ( valueType
== wxS("wxSize") )
1087 return WXVARIANT(wxSize(0, 0));
1093 void wxPGProperty::SetCell( int column
, wxPGCell
* cellObj
)
1095 if ( column
>= (int)m_cells
.size() )
1096 m_cells
.SetCount(column
+1, NULL
);
1098 delete (wxPGCell
*) m_cells
[column
];
1099 m_cells
[column
] = cellObj
;
1102 void wxPGProperty::SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
)
1104 // Changes value of a property with choices, but only
1105 // works if the value type is long or string.
1106 wxString ts
= GetValue().GetType();
1108 wxCHECK_RET( choiceInfo
.m_choices
, wxT("invalid choiceinfo") );
1110 if ( ts
== wxS("long") )
1112 SetValue( (long) newValue
);
1114 else if ( ts
== wxS("string") )
1116 SetValue( choiceInfo
.m_choices
->GetLabel(newValue
) );
1121 wxString
wxPGProperty::GetChoiceString( unsigned int index
)
1125 wxASSERT(ci
.m_choices
);
1126 return ci
.m_choices
->GetLabel(index
);
1129 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1131 wxPropertyGrid
* pg
= GetGrid();
1134 ci
.m_choices
= (wxPGChoices
*) NULL
;
1135 int sel
= GetChoiceInfo(&ci
);
1142 index
= ci
.m_choices
->GetCount();
1147 ci
.m_choices
->Insert(label
, index
, value
);
1149 if ( sel
!= newSel
)
1150 SetChoiceSelection(newSel
, ci
);
1152 if ( this == pg
->GetSelection() )
1153 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1162 void wxPGProperty::DeleteChoice( int index
)
1164 wxPropertyGrid
* pg
= GetGrid();
1167 ci
.m_choices
= (wxPGChoices
*) NULL
;
1168 int sel
= GetChoiceInfo(&ci
);
1174 // Adjust current value
1177 SetValueToUnspecified();
1180 else if ( index
< sel
)
1185 ci
.m_choices
->RemoveAt(index
);
1187 if ( sel
!= newSel
)
1188 SetChoiceSelection(newSel
, ci
);
1190 if ( this == pg
->GetSelection() )
1191 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1195 int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo
* WXUNUSED(info
) )
1200 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1205 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1210 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1212 if ( DoSetAttribute( name
, value
) )
1214 // Support working without grid, when possible
1215 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1219 m_attributes
.Set( name
, value
);
1222 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1224 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1227 while ( attributes
.GetNext(it
, variant
) )
1228 SetAttribute( variant
.GetName(), variant
);
1231 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1237 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1239 return m_attributes
.FindValue(name
);
1242 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1244 wxVariant variant
= m_attributes
.FindValue(name
);
1246 if ( !variant
.IsNull() )
1247 return variant
.GetString();
1252 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1254 wxVariant variant
= m_attributes
.FindValue(name
);
1256 return wxPGVariantToInt(variant
, defVal
);
1259 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1262 wxVariant variant
= m_attributes
.FindValue(name
);
1264 if ( wxPGVariantToDouble(variant
, &retVal
) )
1270 wxVariant
wxPGProperty::GetAttributesAsList() const
1272 wxVariantList tempList
;
1273 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1275 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1278 while ( m_attributes
.GetNext(it
, variant
) )
1284 // Slots of utility flags are NULL
1285 const unsigned int gs_propFlagToStringSize
= 14;
1287 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1304 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1307 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1311 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1313 if ( relevantFlags
& a
)
1315 const wxChar
* fs
= gs_propFlagToString
[i
];
1327 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1331 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1333 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1335 const wxChar
* fs
= gs_propFlagToString
[i
];
1336 if ( fs
&& str
== fs
)
1342 WX_PG_TOKENIZER1_END()
1344 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1347 wxValidator
* wxPGProperty::DoGetValidator() const
1349 return (wxValidator
*) NULL
;
1352 wxPGChoices
& wxPGProperty::GetChoices()
1354 wxPGChoiceInfo choiceInfo
;
1355 choiceInfo
.m_choices
= NULL
;
1356 GetChoiceInfo(&choiceInfo
);
1357 return *choiceInfo
.m_choices
;
1360 const wxPGChoices
& wxPGProperty::GetChoices() const
1362 return (const wxPGChoices
&) ((wxPGProperty
*)this)->GetChoices();
1365 unsigned int wxPGProperty::GetChoiceCount() const
1367 const wxPGChoices
& choices
= GetChoices();
1368 if ( &choices
&& choices
.IsOk() )
1369 return choices
.GetCount();
1373 const wxPGChoiceEntry
* wxPGProperty::GetCurrentChoice() const
1376 ci
.m_choices
= (wxPGChoices
*) NULL
;
1377 int index
= ((wxPGProperty
*)this)->GetChoiceInfo(&ci
);
1378 if ( index
== -1 || !ci
.m_choices
|| index
>= (int)ci
.m_choices
->GetCount() )
1381 return &(*ci
.m_choices
)[index
];
1384 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1387 ci
.m_choices
= (wxPGChoices
*) NULL
;
1393 ci
.m_choices
->Assign(choices
);
1397 // This may be needed to trigger some initialization
1398 // (but don't do it if property is somewhat uninitialized)
1399 wxVariant defVal
= GetDefaultValue();
1400 if ( defVal
.IsNull() )
1412 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1414 const wxPGEditor
* editor
;
1416 if ( !m_customEditor
)
1418 editor
= DoGetEditorClass();
1421 editor
= m_customEditor
;
1424 // Maybe override editor if common value specified
1425 if ( GetDisplayedCommonValueCount() )
1427 // TextCtrlAndButton -> ComboBoxAndButton
1428 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1429 editor
= wxPG_EDITOR(ChoiceAndButton
);
1431 // TextCtrl -> ComboBox
1432 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1433 editor
= wxPG_EDITOR(ComboBox
);
1440 // Privatizes set of choices
1441 void wxPGProperty::SetChoicesExclusive()
1444 ci
.m_choices
= (wxPGChoices
*) NULL
;
1448 ci
.m_choices
->SetExclusive();
1451 bool wxPGProperty::HasVisibleChildren() const
1455 for ( i
=0; i
<GetChildCount(); i
++ )
1457 wxPGProperty
* child
= Item(i
);
1459 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1466 bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid
* propGrid
)
1468 return propGrid
->EditorValidate();
1472 bool wxPGProperty::RecreateEditor()
1474 wxPropertyGrid
* pg
= GetGrid();
1477 wxPGProperty
* selected
= pg
->GetSelection();
1478 if ( this == selected
)
1480 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1487 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1489 delete m_valueBitmap
;
1491 if ( &bmp
&& bmp
.Ok() )
1494 wxSize maxSz
= GetGrid()->GetImageSize();
1495 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1497 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1499 // Create a memory DC
1500 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1503 dc
.SelectObject(*bmpNew
);
1506 // FIXME: This is ugly - use image or wait for scaling patch.
1507 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1508 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1510 dc
.SetUserScale(scaleX
,scaleY
);
1512 dc
.DrawBitmap( bmp
, 0, 0 );
1514 m_valueBitmap
= bmpNew
;
1518 m_valueBitmap
= new wxBitmap(bmp
);
1521 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1525 m_valueBitmap
= NULL
;
1526 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1531 wxPGProperty
* wxPGProperty::GetMainParent() const
1533 const wxPGProperty
* curChild
= this;
1534 const wxPGProperty
* curParent
= m_parent
;
1536 while ( curParent
&& !curParent
->IsCategory() )
1538 curChild
= curParent
;
1539 curParent
= curParent
->m_parent
;
1542 return (wxPGProperty
*) curChild
;
1546 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1549 // Returns last visible sub-item, recursively.
1550 if ( !IsExpanded() || !GetChildCount() )
1553 return Last()->GetLastVisibleSubItem();
1557 bool wxPGProperty::IsVisible() const
1559 const wxPGProperty
* parent
;
1561 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1564 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1566 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1573 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1575 wxPropertyGridPageState
* state
= GetParentState();
1576 wxPropertyGrid
* propGrid
= state
->GetGrid();
1577 if ( state
== propGrid
->GetState() )
1583 int wxPGProperty::GetY2( int lh
) const
1585 const wxPGProperty
* parent
;
1586 const wxPGProperty
* child
= this;
1590 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1592 if ( !parent
->IsExpanded() )
1594 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1599 y
-= lh
; // need to reduce one level
1605 int wxPGProperty::GetY() const
1607 return GetY2(GetGrid()->GetRowHeight());
1610 // This is used by Insert etc.
1611 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1613 if ( index
< 0 || (size_t)index
>= m_children
.GetCount() )
1615 if ( correct_mode
) prop
->m_arrIndex
= m_children
.GetCount();
1616 m_children
.Add( prop
);
1620 m_children
.Insert( prop
, index
);
1621 if ( correct_mode
) FixIndexesOfChildren( index
);
1624 prop
->m_parent
= this;
1627 // This is used by properties that have fixed sub-properties
1628 void wxPGProperty::AddChild( wxPGProperty
* prop
)
1630 wxASSERT_MSG( prop
->GetBaseName().length(),
1631 "Property's children must have unique, non-empty names within their scope" );
1633 prop
->m_arrIndex
= m_children
.GetCount();
1634 m_children
.Add( prop
);
1636 int custImgHeight
= prop
->OnMeasureImage().y
;
1637 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
1638 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1640 prop
->m_parent
= this;
1644 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
1646 wxASSERT( GetChildCount() );
1647 wxASSERT( !IsCategory() );
1649 *value
= GetValue();
1651 if ( !list
.GetCount() )
1654 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
1656 bool allChildrenSpecified
;
1658 // Don't fully update aggregate properties unless all children have
1660 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1661 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
1663 allChildrenSpecified
= true;
1665 wxVariant childValue
= list
[0];
1669 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
1671 for ( i
=0; i
<GetChildCount(); i
++ )
1673 const wxPGProperty
* child
= Item(i
);
1675 if ( childValue
.GetName() == child
->GetBaseName() )
1677 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
1679 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1681 wxVariant
cv2(child
->GetValue());
1682 child
->AdaptListToValue(childValue
, &cv2
);
1686 if ( allChildrenSpecified
)
1687 ChildChanged(*value
, i
, childValue
);
1689 if ( n
== (unsigned int)list
.GetCount() )
1691 childValue
= list
[n
];
1697 void wxPGProperty::FixIndexesOfChildren( size_t starthere
)
1700 for ( i
=starthere
;i
<GetChildCount();i
++)
1701 Item(i
)->m_arrIndex
= i
;
1705 // Returns (direct) child property with given name (or NULL if not found)
1706 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
1710 for ( i
=0; i
<GetChildCount(); i
++ )
1712 wxPGProperty
* p
= Item(i
);
1713 if ( p
->m_name
== name
)
1717 // Does it have point, then?
1718 int pos
= name
.Find(wxS('.'));
1720 return (wxPGProperty
*) NULL
;
1722 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
1724 if ( !p
|| !p
->GetChildCount() )
1727 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
1730 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
1732 unsigned int i
= hintIndex
;
1734 if ( i
>= GetChildCount() )
1737 unsigned int lastIndex
= i
- 1;
1739 if ( lastIndex
>= GetChildCount() )
1740 lastIndex
= GetChildCount() - 1;
1744 wxPGProperty
* p
= Item(i
);
1745 if ( p
->m_name
== name
)
1748 if ( i
== lastIndex
)
1752 if ( i
== GetChildCount() )
1759 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
1761 // Returns height of children, recursively, and
1762 // by taking expanded/collapsed status into account.
1764 // iMax is used when finding property y-positions.
1770 iMax_
= GetChildCount();
1772 unsigned int iMax
= iMax_
;
1774 wxASSERT( iMax
<= GetChildCount() );
1776 if ( !IsExpanded() && GetParent() )
1781 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
1783 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1785 if ( !pwc
->IsExpanded() ||
1786 pwc
->GetChildCount() == 0 )
1789 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
1798 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
1800 wxASSERT( nextItemY
);
1802 // Linear search at the moment
1804 // nextItemY = y of next visible property, final value will be written back.
1805 wxPGProperty
* result
= NULL
;
1806 wxPGProperty
* current
= NULL
;
1807 unsigned int iy
= *nextItemY
;
1809 unsigned int iMax
= GetChildCount();
1813 wxPGProperty
* pwc
= Item(i
);
1815 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
1826 if ( pwc
->IsExpanded() &&
1827 pwc
->GetChildCount() > 0 )
1829 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
1841 if ( !result
&& y
< iy
)
1848 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
1850 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
1853 return (wxPGProperty
*) result
;
1856 void wxPGProperty::Empty()
1859 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
1861 for ( i
=0; i
<GetChildCount(); i
++ )
1863 wxPGProperty
* p
= (wxPGProperty
*) Item(i
);
1871 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
1872 int WXUNUSED(childIndex
),
1873 wxVariant
& WXUNUSED(childValue
) ) const
1877 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
1881 const wxVariantList
* pList
= NULL
;
1882 wxVariantList::const_iterator node
;
1886 pList
= &pendingList
->GetList();
1887 node
= pList
->begin();
1890 for ( i
=0; i
<GetChildCount(); i
++ )
1892 wxPGProperty
* child
= Item(i
);
1893 const wxVariant
* listValue
= NULL
;
1898 const wxString
& childName
= child
->GetBaseName();
1900 for ( ; node
!= pList
->end(); node
++ )
1902 const wxVariant
& item
= *((const wxVariant
*)*node
);
1903 if ( item
.GetName() == childName
)
1913 value
= child
->GetValue();
1915 if ( value
.IsNull() )
1918 // Check recursively
1919 if ( child
->GetChildCount() )
1921 const wxVariant
* childList
= NULL
;
1923 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
1924 childList
= listValue
;
1926 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
1934 wxPGProperty
* wxPGProperty::UpdateParentValues()
1936 wxPGProperty
* parent
= m_parent
;
1937 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
1938 !parent
->IsCategory() && !parent
->IsRoot() )
1941 parent
->GenerateComposedValue(s
, 0);
1942 parent
->m_value
= s
;
1943 return parent
->UpdateParentValues();
1948 bool wxPGProperty::IsTextEditable() const
1950 if ( HasFlag(wxPG_PROP_READONLY
) )
1953 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
1955 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
1962 // Call for after sub-properties added with AddChild
1963 void wxPGProperty::PrepareSubProperties()
1965 wxPropertyGridPageState
* state
= GetParentState();
1969 if ( !GetChildCount() )
1972 wxByte depth
= m_depth
+ 1;
1973 wxByte depthBgCol
= m_depthBgCol
;
1975 FlagType inheritFlags
= m_flags
& wxPG_INHERITED_PROPFLAGS
;
1977 wxByte bgColIndex
= m_bgColIndex
;
1978 wxByte fgColIndex
= m_fgColIndex
;
1981 // Set some values to the children
1984 wxPGProperty
* nparent
= this;
1986 while ( i
< nparent
->GetChildCount() )
1988 wxPGProperty
* np
= nparent
->Item(i
);
1990 np
->m_parentState
= state
;
1991 np
->m_flags
|= inheritFlags
; // Hideable also if parent.
1992 np
->m_depth
= depth
;
1993 np
->m_depthBgCol
= depthBgCol
;
1994 np
->m_bgColIndex
= bgColIndex
;
1995 np
->m_fgColIndex
= fgColIndex
;
1997 // Also handle children of children
1998 if ( np
->GetChildCount() > 0 )
2004 nparent
->SetParentalType(wxPG_PROP_AGGREGATE
);
2005 nparent
->SetExpanded(false);
2014 // After reaching last sibling, go back to processing
2015 // siblings of the parent
2016 while ( i
>= nparent
->GetChildCount() )
2018 // Exit the loop when top parent hit
2019 if ( nparent
== this )
2024 i
= nparent
->GetArrIndex() + 1;
2025 nparent
= nparent
->GetParent();
2030 // Call after fixed sub-properties added/removed after creation.
2031 // if oldSelInd >= 0 and < new max items, then selection is
2032 // moved to it. Note: oldSelInd -2 indicates that this property
2033 // should be selected.
2034 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2036 wxPropertyGridPageState
* state
= GetParentState();
2037 wxPropertyGrid
* grid
= state
->GetGrid();
2039 PrepareSubProperties();
2041 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2042 if ( oldSelInd
>= (int)m_children
.GetCount() )
2043 oldSelInd
= (int)m_children
.GetCount() - 1;
2045 if ( oldSelInd
>= 0 )
2046 sel
= (wxPGProperty
*) m_children
[oldSelInd
];
2047 else if ( oldSelInd
== -2 )
2051 state
->DoSelectProperty(sel
);
2053 if ( state
== grid
->GetState() )
2055 grid
->GetPanel()->Refresh();
2059 // -----------------------------------------------------------------------
2061 // -----------------------------------------------------------------------
2063 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2064 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2067 wxPGRootProperty::wxPGRootProperty()
2071 m_name
= wxS("<root>");
2078 wxPGRootProperty::~wxPGRootProperty()
2083 // -----------------------------------------------------------------------
2084 // wxPropertyCategory
2085 // -----------------------------------------------------------------------
2087 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2088 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2090 void wxPropertyCategory::Init()
2092 // don't set colour - prepareadditem method should do this
2093 SetParentalType(wxPG_PROP_CATEGORY
);
2094 m_capFgColIndex
= 1;
2098 wxPropertyCategory::wxPropertyCategory()
2105 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2106 : wxPGProperty(label
,name
)
2112 wxPropertyCategory::~wxPropertyCategory()
2117 wxString
wxPropertyCategory::GetValueAsString( int ) const
2119 return wxEmptyString
;
2122 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2124 if ( m_textExtent
> 0 )
2125 return m_textExtent
;
2127 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2131 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2134 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2138 // -----------------------------------------------------------------------
2139 // wxPGAttributeStorage
2140 // -----------------------------------------------------------------------
2142 wxPGAttributeStorage::wxPGAttributeStorage()
2146 wxPGAttributeStorage::~wxPGAttributeStorage()
2148 wxPGHashMapS2P::iterator it
;
2150 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2152 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2157 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2159 wxVariantData
* data
= value
.GetData();
2162 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2163 if ( it
!= m_map
.end() )
2164 ((wxVariantData
*)it
->second
)->DecRef();
2172 #endif // wxUSE_PROPGRID