1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/property.cpp
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
34 #include "wx/settings.h"
38 #include "wx/propgrid/propgrid.h"
41 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
44 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
46 #if wxPG_COMPATIBILITY_1_4
48 // Used to establish backwards compatiblity
49 const char* g_invalidStringContent
= "@__TOTALLY_INVALID_STRING__@";
53 // -----------------------------------------------------------------------
55 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
57 #if defined(__WXMSW__) && !defined(__WXWINCE__)
58 // FIXME: Use DrawFocusRect code above (currently it draws solid line
59 // for caption focus but works ok for other stuff).
60 // Also, it seems that this code may not work in future wx versions.
61 dc
.SetLogicalFunction(wxINVERT
);
63 wxPen
pen(*wxBLACK
,1,wxDOT
);
64 pen
.SetCap(wxCAP_BUTT
);
66 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
68 dc
.DrawRectangle(rect
);
70 dc
.SetLogicalFunction(wxCOPY
);
72 dc
.SetLogicalFunction(wxINVERT
);
74 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
75 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
77 dc
.DrawRectangle(rect
);
79 dc
.SetLogicalFunction(wxCOPY
);
83 // -----------------------------------------------------------------------
85 // -----------------------------------------------------------------------
87 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
89 int WXUNUSED(item
) ) const
94 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
95 int xOffset
, const wxString
& text
) const
98 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
100 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
101 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
104 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
105 int xOffset
, const wxString
& text
,
106 wxPGProperty
* property
,
107 const wxPGEditor
* editor
) const
110 xOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
112 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
119 rect2
.height
-= yOffset
;
120 editor
->DrawValue( dc
, rect2
, property
, text
);
125 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
130 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
132 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
133 wxPGDrawFocusRect(dc
,focusRect
);
136 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
140 // If possible, use cell colours
141 if ( !(flags
& DontUseCellBgCol
) )
143 dc
.SetPen(cell
.GetBgCol());
144 dc
.SetBrush(cell
.GetBgCol());
147 if ( !(flags
& DontUseCellFgCol
) )
149 dc
.SetTextForeground(cell
.GetFgCol());
153 dc
.DrawRectangle(rect
);
155 const wxBitmap
& bmp
= cell
.GetBitmap();
157 // Do not draw oversized bitmap outside choice popup
158 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
162 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
163 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
165 imageOffset
= bmp
.GetWidth();
171 // -----------------------------------------------------------------------
172 // wxPGDefaultRenderer
173 // -----------------------------------------------------------------------
175 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
176 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
177 int column
, int item
, int flags
) const
179 bool isUnspecified
= property
->IsValueUnspecified();
181 if ( column
== 1 && item
== -1 )
183 int cmnVal
= property
->GetCommonValue();
187 if ( !isUnspecified
)
188 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
193 const wxPGEditor
* editor
= NULL
;
194 const wxPGCell
* cell
= NULL
;
198 int preDrawFlags
= flags
;
200 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
202 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
206 if ( !isUnspecified
)
208 editor
= property
->GetColumnEditor(column
);
210 // Regular property value
212 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
214 wxPGPaintData paintdata
;
215 paintdata
.m_parent
= propertyGrid
;
216 paintdata
.m_choiceItem
= item
;
218 if ( imageSize
.x
> 0 )
220 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
221 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
222 wxPG_CUSTOM_IMAGE_WIDTH
,
223 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
225 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
227 paintdata
.m_drawnWidth
= imageSize
.x
;
228 paintdata
.m_drawnHeight
= imageSize
.y
;
230 if ( !isUnspecified
)
232 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
236 dc
.SetBrush(*wxWHITE_BRUSH
);
237 dc
.DrawRectangle(imageRect
);
240 imageOffset
= paintdata
.m_drawnWidth
;
243 text
= property
->GetValueAsString();
246 if ( propertyGrid
->GetColumnCount() <= 2 )
248 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
249 if ( unitsString
.length() )
250 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
254 if ( text
.length() == 0 )
256 // Try to show inline help if no text
257 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
258 if ( !vInlineHelp
.IsNull() )
260 text
= vInlineHelp
.GetString();
261 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
266 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
268 // active caption gets nice dotted rectangle
269 if ( property
->IsCategory() /*&& column == 0*/ )
271 if ( flags
& Selected
)
273 if ( imageOffset
> 0 )
274 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
276 DrawCaptionSelectionRect( dc
,
277 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
278 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
279 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
280 propertyGrid
->GetCaptionFont())
281 +(wxPG_CAPRECTXMARGIN
*2),
282 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
287 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
291 if ( property
&& column
== 1 )
295 wxBitmap
* bmp
= property
->GetValueImage();
297 if ( bmp
&& bmp
->Ok() )
298 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
304 // -----------------------------------------------------------------------
306 // -----------------------------------------------------------------------
308 wxPGCellData::wxPGCellData()
311 m_hasValidText
= false;
314 // -----------------------------------------------------------------------
316 // -----------------------------------------------------------------------
323 wxPGCell::wxPGCell( const wxString
& text
,
324 const wxBitmap
& bitmap
,
325 const wxColour
& fgCol
,
326 const wxColour
& bgCol
)
329 wxPGCellData
* data
= new wxPGCellData();
332 data
->m_bitmap
= bitmap
;
333 data
->m_fgCol
= fgCol
;
334 data
->m_bgCol
= bgCol
;
335 data
->m_hasValidText
= true;
338 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
340 wxPGCellData
* c
= new wxPGCellData();
341 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
342 c
->m_text
= o
->m_text
;
343 c
->m_bitmap
= o
->m_bitmap
;
344 c
->m_fgCol
= o
->m_fgCol
;
345 c
->m_bgCol
= o
->m_bgCol
;
346 c
->m_hasValidText
= o
->m_hasValidText
;
350 void wxPGCell::SetText( const wxString
& text
)
354 GetData()->SetText(text
);
357 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
361 GetData()->SetBitmap(bitmap
);
364 void wxPGCell::SetFgCol( const wxColour
& col
)
368 GetData()->SetFgCol(col
);
371 void wxPGCell::SetBgCol( const wxColour
& col
)
375 GetData()->SetBgCol(col
);
378 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
382 wxPGCellData
* data
= GetData();
384 if ( srcCell
.HasText() )
385 data
->SetText(srcCell
.GetText());
387 if ( srcCell
.GetFgCol().IsOk() )
388 data
->SetFgCol(srcCell
.GetFgCol());
390 if ( srcCell
.GetBgCol().IsOk() )
391 data
->SetBgCol(srcCell
.GetBgCol());
393 if ( srcCell
.GetBitmap().IsOk() )
394 data
->SetBitmap(srcCell
.GetBitmap());
397 // -----------------------------------------------------------------------
399 // -----------------------------------------------------------------------
401 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
403 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
405 void wxPGProperty::Init()
411 m_parentState
= (wxPropertyGridPageState
*) NULL
;
414 m_clientObject
= NULL
;
416 m_customEditor
= (wxPGEditor
*) NULL
;
418 m_validator
= (wxValidator
*) NULL
;
420 m_valueBitmap
= (wxBitmap
*) NULL
;
422 m_maxLen
= 0; // infinite maximum length
424 m_flags
= wxPG_PROP_PROPERTY
;
432 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
434 // We really need to check if &label and &name are NULL pointers
435 // (this can if we are called before property grid has been initalized)
437 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
440 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
443 DoSetName( m_label
);
448 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
449 wxPropertyGrid
* propgrid
)
452 // Called after property has been added to grid or page
453 // (so propgrid can be NULL, too).
455 wxPGProperty
* parent
= m_parent
;
456 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
458 m_parentState
= pageState
;
460 #if wxPG_COMPATIBILITY_1_4
461 // Make sure deprecated virtual functions are not implemented
462 wxString s
= GetValueAsString( 0xFFFF );
463 wxASSERT_MSG( s
== g_invalidStringContent
,
464 "Implement ValueToString() instead of GetValueAsString()" );
467 if ( !parentIsRoot
&& !parent
->IsCategory() )
469 m_cells
= parent
->m_cells
;
472 // If in hideable adding mode, or if assigned parent is hideable, then
473 // make this one hideable.
475 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
476 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
478 SetFlag( wxPG_PROP_HIDDEN
);
480 // Set custom image flag.
481 int custImgHeight
= OnMeasureImage().y
;
482 if ( custImgHeight
< 0 )
484 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
487 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
488 SetFlag(wxPG_PROP_NOEDITOR
);
490 // Make sure parent has some parental flags
491 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
492 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
496 // This is not a category.
500 unsigned char depth
= 1;
503 depth
= parent
->m_depth
;
504 if ( !parent
->IsCategory() )
508 unsigned char greyDepth
= depth
;
512 wxPropertyCategory
* pc
;
514 if ( parent
->IsCategory() )
515 pc
= (wxPropertyCategory
* ) parent
;
517 // This conditional compile is necessary to
518 // bypass some compiler bug.
519 pc
= pageState
->GetPropertyCategory(parent
);
522 greyDepth
= pc
->GetDepth();
524 greyDepth
= parent
->m_depthBgCol
;
527 m_depthBgCol
= greyDepth
;
531 // This is a category.
534 unsigned char depth
= 1;
537 depth
= parent
->m_depth
+ 1;
540 m_depthBgCol
= depth
;
544 // Has initial children
545 if ( GetChildCount() )
547 // Check parental flags
548 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
),
549 "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
550 "SetFlag(wxPG_PROP_AGGREGATE) before calling"
551 "wxPGProperty::AddChild()." );
553 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
555 // Properties with private children are not expanded by default.
558 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
560 // ...unless it cannot be expanded by user and therefore must
561 // remain visible at all times
566 // Prepare children recursively
567 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
569 wxPGProperty
* child
= Item(i
);
570 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
573 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
574 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
578 wxPGProperty::wxPGProperty()
585 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
592 wxPGProperty::~wxPGProperty()
594 delete m_clientObject
;
596 Empty(); // this deletes items
598 delete m_valueBitmap
;
603 // This makes it easier for us to detect dangling pointers
608 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
610 wxPGProperty
* parent
= m_parent
;
613 if ( parent
== candidate
)
615 parent
= parent
->m_parent
;
621 wxString
wxPGProperty::GetName() const
623 wxPGProperty
* parent
= GetParent();
625 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
628 return m_parent
->GetName() + wxS(".") + m_name
;
631 wxPropertyGrid
* wxPGProperty::GetGrid() const
633 if ( !m_parentState
)
635 return m_parentState
->GetGrid();
638 int wxPGProperty::Index( const wxPGProperty
* p
) const
640 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
642 if ( p
== m_children
[i
] )
648 void wxPGProperty::UpdateControl( wxWindow
* primary
)
651 GetEditorClass()->UpdateControl(this, primary
);
654 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
659 void wxPGProperty::OnSetValue()
663 void wxPGProperty::RefreshChildren ()
667 void wxPGProperty::GetDisplayInfo( unsigned int column
,
671 const wxPGCell
** pCell
)
673 const wxPGCell
* cell
= NULL
;
675 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
677 // Not painting listi of choice popups, so get text from property
678 cell
= &GetCell(column
);
679 if ( cell
->HasText() )
681 *pString
= cell
->GetText();
686 *pString
= GetLabel();
687 else if ( column
== 1 )
688 *pString
= GetDisplayedString();
689 else if ( column
== 2 )
690 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
695 wxASSERT( column
== 1 );
697 if ( choiceIndex
!= wxNOT_FOUND
)
699 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
700 if ( entry
.GetBitmap().IsOk() ||
701 entry
.GetFgCol().IsOk() ||
702 entry
.GetBgCol().IsOk() )
704 *pString
= m_choices
.GetLabel(choiceIndex
);
709 cell
= &GetCell(column
);
711 wxASSERT_MSG( cell
->GetData(),
712 wxString::Format("Invalid cell for property %s",
713 GetName().c_str()) );
719 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
722 if ( col != 1 || choiceIndex == wxNOT_FOUND )
724 const wxPGCell& cell = GetCell(col);
725 if ( cell->HasText() )
727 return cell->GetText();
734 return GetDisplayedString();
736 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
742 return m_choices.GetLabel(choiceIndex);
745 return wxEmptyString;
749 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
751 const wxVariantList
* valueOverrides
,
752 wxPGHashMapS2S
* childResults
) const
755 int iMax
= m_children
.size();
761 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
762 !(argFlags
& wxPG_FULL_VALUE
) )
763 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
765 int iMaxMinusOne
= iMax
-1;
767 if ( !IsTextEditable() )
768 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
770 wxPGProperty
* curChild
= m_children
[0];
772 bool overridesLeft
= false;
773 wxVariant overrideValue
;
774 wxVariantList::const_iterator node
;
776 if ( valueOverrides
)
778 node
= valueOverrides
->begin();
779 if ( node
!= valueOverrides
->end() )
781 overrideValue
= *node
;
782 overridesLeft
= true;
786 for ( i
= 0; i
< iMax
; i
++ )
788 wxVariant childValue
;
790 wxString childLabel
= curChild
->GetLabel();
792 // Check for value override
793 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
795 if ( !overrideValue
.IsNull() )
796 childValue
= overrideValue
;
798 childValue
= curChild
->GetValue();
800 if ( node
!= valueOverrides
->end() )
801 overrideValue
= *node
;
803 overridesLeft
= false;
807 childValue
= curChild
->GetValue();
811 if ( !childValue
.IsNull() )
813 if ( overridesLeft
&&
814 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
815 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
817 wxVariantList
& childList
= childValue
.GetList();
818 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
819 &childList
, childResults
);
823 s
= curChild
->ValueToString(childValue
,
824 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
828 if ( childResults
&& curChild
->GetChildCount() )
829 (*childResults
)[curChild
->GetName()] = s
;
832 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
835 if ( !curChild
->GetChildCount() || skip
)
838 text
+= wxS("[") + s
+ wxS("]");
840 if ( i
< iMaxMinusOne
)
842 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
843 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
844 !(argFlags
& wxPG_FULL_VALUE
) )
849 if ( !curChild
->GetChildCount() )
855 curChild
= m_children
[i
+1];
859 if ( (unsigned int)i
< m_children
.size() )
861 if ( !text
.EndsWith(wxS("; ")) )
862 text
+= wxS("; ...");
868 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
871 wxCHECK_MSG( GetChildCount() > 0,
873 "If user property does not have any children, it must "
874 "override GetValueAsString" );
876 // FIXME: Currently code below only works if value is actually m_value
877 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
878 "Sorry, currently default wxPGProperty::ValueToString() "
879 "implementation only works if value is m_value." );
882 DoGenerateComposedValue(text
, argFlags
);
886 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
888 #if wxPG_COMPATIBILITY_1_4
889 // This is backwards compatibility test
890 // That is, to make sure this function is not overridden
891 // (instead, ValueToString() should be).
892 if ( argFlags
== 0xFFFF )
894 // Do not override! (for backwards compliancy)
895 return g_invalidStringContent
;
899 if ( IsValueUnspecified() )
900 return wxEmptyString
;
902 if ( m_commonValue
== -1 )
904 wxVariant
value(GetValue());
905 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
909 // Return common value's string representation
910 wxPropertyGrid
* pg
= GetGrid();
911 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
913 if ( argFlags
& wxPG_FULL_VALUE
)
915 return cv
->GetLabel();
917 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
919 return cv
->GetEditableText();
923 return cv
->GetLabel();
927 wxString
wxPGProperty::GetValueString( int argFlags
) const
929 return GetValueAsString(argFlags
);
932 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
934 variant
= (long)number
;
938 // Convert semicolon delimited tokens into child values.
939 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
941 if ( !GetChildCount() )
944 unsigned int curChild
= 0;
946 unsigned int iMax
= m_children
.size();
948 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
949 !(argFlags
& wxPG_FULL_VALUE
) )
950 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
952 bool changed
= false;
957 // Its best only to add non-empty group items
958 bool addOnlyIfNotEmpty
= false;
959 const wxChar delimeter
= wxS(';');
961 size_t tokenStart
= 0xFFFFFF;
963 wxVariantList temp_list
;
964 wxVariant
list(temp_list
);
966 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
969 bool debug_print
= false;
974 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
977 wxString::const_iterator it
= text
.begin();
980 if ( it
!= text
.end() )
987 if ( tokenStart
!= 0xFFFFFF )
990 if ( a
== delimeter
|| a
== 0 )
992 token
= text
.substr(tokenStart
,pos
-tokenStart
);
994 size_t len
= token
.length();
996 if ( !addOnlyIfNotEmpty
|| len
> 0 )
998 const wxPGProperty
* child
= Item(curChild
);
999 wxVariant
variant(child
->GetValue());
1000 variant
.SetName(child
->GetBaseName());
1004 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().c_str());
1007 // Add only if editable or setting programmatically
1008 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1009 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1013 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1015 list
.Append(variant
);
1022 // Empty, becomes unspecified
1024 list
.Append(variant
);
1030 if ( curChild
>= iMax
)
1034 tokenStart
= 0xFFFFFF;
1039 // Token is not running
1040 if ( a
!= wxS(' ') )
1043 addOnlyIfNotEmpty
= false;
1045 // Is this a group of tokens?
1046 if ( a
== wxS('[') )
1050 if ( it
!= text
.end() ) it
++;
1052 size_t startPos
= pos
;
1054 // Group item - find end
1055 while ( it
!= text
.end() && depth
> 0 )
1061 if ( a
== wxS(']') )
1063 else if ( a
== wxS('[') )
1067 token
= text
.substr(startPos
,pos
-startPos
-1);
1069 if ( !token
.length() )
1072 const wxPGProperty
* child
= Item(curChild
);
1074 wxVariant oldChildValue
= child
->GetValue();
1075 wxVariant
variant(oldChildValue
);
1077 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1078 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1080 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
1081 if ( stvRes
|| (variant
!= oldChildValue
) )
1088 // Failed, becomes unspecified
1094 variant
.SetName(child
->GetBaseName());
1095 list
.Append(variant
);
1098 if ( curChild
>= iMax
)
1101 addOnlyIfNotEmpty
= true;
1103 tokenStart
= 0xFFFFFF;
1109 if ( a
== delimeter
)
1122 if ( it
!= text
.end() )
1139 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1141 wxVariant
variant(m_value
);
1142 bool res
= StringToValue(variant
, text
, argFlags
);
1148 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1150 wxVariant
variant(m_value
);
1151 bool res
= IntToValue(variant
, number
, argFlags
);
1157 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1159 if ( m_valueBitmap
)
1160 return wxSize(m_valueBitmap
->GetWidth(),-1);
1165 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1167 return wxPGGlobalVars
->m_defaultRenderer
;
1170 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1174 wxBitmap
* bmp
= m_valueBitmap
;
1176 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1178 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1180 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1183 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1185 return wxPGEditor_TextCtrl
;
1188 // Default extra property event handling - that is, none at all.
1189 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1195 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1197 // If auto unspecified values are not wanted (via window or property style),
1198 // then get default value instead of wxNullVariant.
1199 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1200 !UsesAutoUnspecified() )
1202 value
= GetDefaultValue();
1205 if ( !value
.IsNull() )
1207 wxVariant tempListVariant
;
1210 // List variants are reserved a special purpose
1211 // as intermediate containers for child values
1212 // of properties with children.
1213 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1216 // However, situation is different for composed string properties
1217 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1219 tempListVariant
= value
;
1220 pList
= &tempListVariant
;
1224 AdaptListToValue(value
, &newValue
);
1226 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1229 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1230 flags
|= wxPG_SETVAL_AGGREGATED
;
1232 if ( pList
&& !pList
->IsNull() )
1234 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1235 wxASSERT( GetChildCount() );
1236 wxASSERT( !IsCategory() );
1238 wxVariantList
& list
= pList
->GetList();
1239 wxVariantList::iterator node
;
1242 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1244 // Children in list can be in any order, but we will give hint to
1245 // GetPropertyByNameWH(). This optimizes for full list parsing.
1246 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
1248 wxVariant
& childValue
= *((wxVariant
*)*node
);
1249 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1252 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1253 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1255 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1257 wxVariant listRefCopy
= childValue
;
1258 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1262 wxVariant oldVal
= child
->GetValue();
1263 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1266 else if ( child
->GetValue() != childValue
)
1268 // For aggregate properties, we will trust RefreshChildren()
1269 // to update child values.
1270 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1271 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1272 if ( flags
& wxPG_SETVAL_BY_USER
)
1273 child
->SetFlag(wxPG_PROP_MODIFIED
);
1280 if ( !value
.IsNull() )
1285 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1286 UpdateParentValues();
1289 if ( flags
& wxPG_SETVAL_BY_USER
)
1290 SetFlag(wxPG_PROP_MODIFIED
);
1292 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1297 if ( m_commonValue
!= -1 )
1299 wxPropertyGrid
* pg
= GetGrid();
1300 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1306 // Set children to unspecified, but only if aggregate or
1307 // value is <composed>
1308 if ( AreChildrenComponents() )
1311 for ( i
=0; i
<GetChildCount(); i
++ )
1312 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1317 // Update editor control
1320 // We need to check for these, otherwise GetGrid() may fail.
1321 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1326 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1328 GetGrid()->ValueChangeInEvent(value
);
1331 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1339 for ( i
= 0; i
< GetChildCount(); i
++ )
1340 Item(i
)->SetFlagRecursively(flag
, set
);
1343 void wxPGProperty::RefreshEditor()
1345 if ( m_parent
&& GetParentState() )
1347 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1348 if ( pg
->GetSelectedProperty() == this )
1350 wxWindow
* editor
= pg
->GetEditorControl();
1352 GetEditorClass()->UpdateControl( this, editor
);
1358 wxVariant
wxPGProperty::GetDefaultValue() const
1360 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1361 if ( !defVal
.IsNull() )
1364 wxVariant value
= GetValue();
1366 if ( !value
.IsNull() )
1368 wxString
valueType(value
.GetType());
1370 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1371 return wxPGVariant_Zero
;
1372 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1373 return wxPGVariant_EmptyString
;
1374 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1375 return wxPGVariant_False
;
1376 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1377 return wxVariant(0.0);
1378 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1379 return wxVariant(wxArrayString());
1380 if ( valueType
== wxS("wxLongLong") )
1381 return WXVARIANT(wxLongLong(0));
1382 if ( valueType
== wxS("wxULongLong") )
1383 return WXVARIANT(wxULongLong(0));
1384 if ( valueType
== wxS("wxColour") )
1385 return WXVARIANT(*wxBLACK
);
1387 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1388 return wxVariant(wxDateTime::Now());
1390 if ( valueType
== wxS("wxFont") )
1391 return WXVARIANT(*wxNORMAL_FONT
);
1392 if ( valueType
== wxS("wxPoint") )
1393 return WXVARIANT(wxPoint(0, 0));
1394 if ( valueType
== wxS("wxSize") )
1395 return WXVARIANT(wxSize(0, 0));
1401 void wxPGProperty::EnsureCells( unsigned int column
)
1403 if ( column
>= m_cells
.size() )
1405 // Fill empty slots with default cells
1406 wxPropertyGrid
* pg
= GetGrid();
1407 wxPGCell defaultCell
;
1409 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1410 defaultCell
= pg
->GetPropertyDefaultCell();
1412 defaultCell
= pg
->GetCategoryDefaultCell();
1414 // TODO: Replace with resize() call
1415 unsigned int cellCountMax
= column
+1;
1417 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1418 m_cells
.push_back(defaultCell
);
1422 void wxPGProperty::SetCell( int column
,
1423 const wxPGCell
& cell
)
1425 EnsureCells(column
);
1427 m_cells
[column
] = cell
;
1430 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1431 unsigned int lastCol
,
1432 const wxPGCell
& cell
,
1433 const wxPGCell
& srcData
,
1434 wxPGCellData
* unmodCellData
,
1435 FlagType ignoreWithFlags
,
1439 // Sets cell in memory optimizing fashion. That is, if
1440 // current cell data matches unmodCellData, we will
1441 // simply get reference to data from cell. Otherwise,
1442 // cell information from srcData is merged into current.
1445 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1447 EnsureCells(lastCol
);
1449 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1451 if ( m_cells
[col
].GetData() == unmodCellData
)
1453 // Data matches... use cell directly
1454 m_cells
[col
] = cell
;
1458 // Data did not match... merge valid information
1459 m_cells
[col
].MergeFrom(srcData
);
1466 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1467 Item(i
)->AdaptiveSetCell( firstCol
,
1477 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1479 if ( m_cells
.size() > column
)
1480 return m_cells
[column
];
1482 wxPropertyGrid
* pg
= GetGrid();
1485 return pg
->GetCategoryDefaultCell();
1487 return pg
->GetPropertyDefaultCell();
1490 wxPGCell
& wxPGProperty::GetCell( unsigned int column
)
1492 EnsureCells(column
);
1493 return m_cells
[column
];
1496 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1499 wxPGProperty
* firstProp
= this;
1502 // If category is tried to set recursively, skip it and only
1503 // affect the children.
1506 while ( firstProp
->IsCategory() )
1508 if ( !firstProp
->GetChildCount() )
1510 firstProp
= firstProp
->Item(0);
1514 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1515 wxPGCellData
* firstCellData
= firstCell
.GetData();
1517 wxPGCell
newCell(firstCell
);
1518 newCell
.SetBgCol(colour
);
1520 srcCell
.SetBgCol(colour
);
1523 GetParentState()->GetColumnCount()-1,
1527 recursively
? wxPG_PROP_CATEGORY
: 0,
1531 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1534 wxPGProperty
* firstProp
= this;
1537 // If category is tried to set recursively, skip it and only
1538 // affect the children.
1541 while ( firstProp
->IsCategory() )
1543 if ( !firstProp
->GetChildCount() )
1545 firstProp
= firstProp
->Item(0);
1549 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1550 wxPGCellData
* firstCellData
= firstCell
.GetData();
1552 wxPGCell
newCell(firstCell
);
1553 newCell
.SetFgCol(colour
);
1555 srcCell
.SetFgCol(colour
);
1558 GetParentState()->GetColumnCount()-1,
1562 recursively
? wxPG_PROP_CATEGORY
: 0,
1566 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1571 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1576 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1578 if ( DoSetAttribute( name
, value
) )
1580 // Support working without grid, when possible
1581 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1585 m_attributes
.Set( name
, value
);
1588 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1590 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1593 while ( attributes
.GetNext(it
, variant
) )
1594 SetAttribute( variant
.GetName(), variant
);
1597 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1603 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1605 return m_attributes
.FindValue(name
);
1608 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1610 wxVariant variant
= m_attributes
.FindValue(name
);
1612 if ( !variant
.IsNull() )
1613 return variant
.GetString();
1618 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1620 wxVariant variant
= m_attributes
.FindValue(name
);
1622 return wxPGVariantToInt(variant
, defVal
);
1625 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1628 wxVariant variant
= m_attributes
.FindValue(name
);
1630 if ( wxPGVariantToDouble(variant
, &retVal
) )
1636 wxVariant
wxPGProperty::GetAttributesAsList() const
1638 wxVariantList tempList
;
1639 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1641 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1644 while ( m_attributes
.GetNext(it
, variant
) )
1650 // Slots of utility flags are NULL
1651 const unsigned int gs_propFlagToStringSize
= 14;
1653 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1670 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1673 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1677 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1679 if ( relevantFlags
& a
)
1681 const wxChar
* fs
= gs_propFlagToString
[i
];
1693 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1697 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1699 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1701 const wxChar
* fs
= gs_propFlagToString
[i
];
1702 if ( fs
&& str
== fs
)
1708 WX_PG_TOKENIZER1_END()
1710 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1713 wxValidator
* wxPGProperty::DoGetValidator() const
1715 return (wxValidator
*) NULL
;
1718 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1720 wxPropertyGrid
* pg
= GetGrid();
1721 int sel
= GetChoiceSelection();
1725 if ( index
== wxNOT_FOUND
)
1726 index
= m_choices
.GetCount();
1731 m_choices
.Insert(label
, index
, value
);
1733 if ( sel
!= newSel
)
1734 SetChoiceSelection(newSel
);
1736 if ( this == pg
->GetSelection() )
1737 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1743 void wxPGProperty::DeleteChoice( int index
)
1745 wxPropertyGrid
* pg
= GetGrid();
1747 int sel
= GetChoiceSelection();
1750 // Adjust current value
1753 SetValueToUnspecified();
1756 else if ( index
< sel
)
1761 m_choices
.RemoveAt(index
);
1763 if ( sel
!= newSel
)
1764 SetChoiceSelection(newSel
);
1766 if ( this == pg
->GetSelection() )
1767 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1770 int wxPGProperty::GetChoiceSelection() const
1772 wxVariant value
= GetValue();
1773 wxString valueType
= value
.GetType();
1774 int index
= wxNOT_FOUND
;
1776 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1779 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1781 index
= value
.GetLong();
1783 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1785 index
= m_choices
.Index(value
.GetString());
1787 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1789 index
= value
.GetBool()? 1 : 0;
1795 void wxPGProperty::SetChoiceSelection( int newValue
)
1797 // Changes value of a property with choices, but only
1798 // works if the value type is long or string.
1799 wxString valueType
= GetValue().GetType();
1801 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1803 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1805 SetValue( m_choices
.GetLabel(newValue
) );
1807 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1809 SetValue( (long) newValue
);
1813 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1815 m_choices
.Assign(choices
);
1818 // This may be needed to trigger some initialization
1819 // (but don't do it if property is somewhat uninitialized)
1820 wxVariant defVal
= GetDefaultValue();
1821 if ( defVal
.IsNull() )
1831 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1833 const wxPGEditor
* editor
;
1835 if ( !m_customEditor
)
1837 editor
= DoGetEditorClass();
1840 editor
= m_customEditor
;
1843 // Maybe override editor if common value specified
1844 if ( GetDisplayedCommonValueCount() )
1846 // TextCtrlAndButton -> ComboBoxAndButton
1847 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1848 editor
= wxPGEditor_ChoiceAndButton
;
1850 // TextCtrl -> ComboBox
1851 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1852 editor
= wxPGEditor_ComboBox
;
1858 bool wxPGProperty::HasVisibleChildren() const
1862 for ( i
=0; i
<GetChildCount(); i
++ )
1864 wxPGProperty
* child
= Item(i
);
1866 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1873 bool wxPGProperty::RecreateEditor()
1875 wxPropertyGrid
* pg
= GetGrid();
1878 wxPGProperty
* selected
= pg
->GetSelection();
1879 if ( this == selected
)
1881 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1888 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1890 delete m_valueBitmap
;
1892 if ( &bmp
&& bmp
.Ok() )
1895 wxSize maxSz
= GetGrid()->GetImageSize();
1896 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1898 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1900 // Create a memory DC
1901 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1904 dc
.SelectObject(*bmpNew
);
1907 // FIXME: This is ugly - use image or wait for scaling patch.
1908 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1909 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1911 dc
.SetUserScale(scaleX
,scaleY
);
1913 dc
.DrawBitmap( bmp
, 0, 0 );
1915 m_valueBitmap
= bmpNew
;
1919 m_valueBitmap
= new wxBitmap(bmp
);
1922 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1926 m_valueBitmap
= NULL
;
1927 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1932 wxPGProperty
* wxPGProperty::GetMainParent() const
1934 const wxPGProperty
* curChild
= this;
1935 const wxPGProperty
* curParent
= m_parent
;
1937 while ( curParent
&& !curParent
->IsCategory() )
1939 curChild
= curParent
;
1940 curParent
= curParent
->m_parent
;
1943 return (wxPGProperty
*) curChild
;
1947 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1950 // Returns last visible sub-item, recursively.
1951 if ( !IsExpanded() || !GetChildCount() )
1954 return Last()->GetLastVisibleSubItem();
1958 bool wxPGProperty::IsVisible() const
1960 const wxPGProperty
* parent
;
1962 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1965 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1967 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1974 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1976 wxPropertyGridPageState
* state
= GetParentState();
1977 wxPropertyGrid
* propGrid
= state
->GetGrid();
1978 if ( state
== propGrid
->GetState() )
1984 int wxPGProperty::GetY2( int lh
) const
1986 const wxPGProperty
* parent
;
1987 const wxPGProperty
* child
= this;
1991 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1993 if ( !parent
->IsExpanded() )
1995 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2000 y
-= lh
; // need to reduce one level
2006 int wxPGProperty::GetY() const
2008 return GetY2(GetGrid()->GetRowHeight());
2011 // This is used by Insert etc.
2012 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
2014 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2016 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2017 m_children
.push_back( prop
);
2021 m_children
.insert( m_children
.begin()+index
, prop
);
2022 if ( correct_mode
) FixIndicesOfChildren( index
);
2025 prop
->m_parent
= this;
2028 // This is used by properties that have fixed sub-properties
2029 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2031 wxASSERT_MSG( prop
->GetBaseName().length(),
2032 "Property's children must have unique, non-empty names within their scope" );
2034 prop
->m_arrIndex
= m_children
.size();
2035 m_children
.push_back( prop
);
2037 int custImgHeight
= prop
->OnMeasureImage().y
;
2038 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2039 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2041 prop
->m_parent
= this;
2044 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2046 wxArrayPGProperty::iterator it
;
2047 wxArrayPGProperty
& children
= m_children
;
2049 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2053 m_children
.erase(it
);
2059 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2061 wxASSERT( GetChildCount() );
2062 wxASSERT( !IsCategory() );
2064 *value
= GetValue();
2066 if ( !list
.GetCount() )
2069 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2071 bool allChildrenSpecified
;
2073 // Don't fully update aggregate properties unless all children have
2075 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2076 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2078 allChildrenSpecified
= true;
2080 wxVariant childValue
= list
[0];
2084 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2086 for ( i
=0; i
<GetChildCount(); i
++ )
2088 const wxPGProperty
* child
= Item(i
);
2090 if ( childValue
.GetName() == child
->GetBaseName() )
2092 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2094 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2096 wxVariant
cv2(child
->GetValue());
2097 child
->AdaptListToValue(childValue
, &cv2
);
2101 if ( allChildrenSpecified
)
2102 ChildChanged(*value
, i
, childValue
);
2104 if ( n
== (unsigned int)list
.GetCount() )
2106 childValue
= list
[n
];
2112 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2115 for ( i
=starthere
;i
<GetChildCount();i
++)
2116 Item(i
)->m_arrIndex
= i
;
2120 // Returns (direct) child property with given name (or NULL if not found)
2121 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2125 for ( i
=0; i
<GetChildCount(); i
++ )
2127 wxPGProperty
* p
= Item(i
);
2128 if ( p
->m_name
== name
)
2132 // Does it have point, then?
2133 int pos
= name
.Find(wxS('.'));
2135 return (wxPGProperty
*) NULL
;
2137 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2139 if ( !p
|| !p
->GetChildCount() )
2142 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2145 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2147 unsigned int i
= hintIndex
;
2149 if ( i
>= GetChildCount() )
2152 unsigned int lastIndex
= i
- 1;
2154 if ( lastIndex
>= GetChildCount() )
2155 lastIndex
= GetChildCount() - 1;
2159 wxPGProperty
* p
= Item(i
);
2160 if ( p
->m_name
== name
)
2163 if ( i
== lastIndex
)
2167 if ( i
== GetChildCount() )
2174 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2176 // Returns height of children, recursively, and
2177 // by taking expanded/collapsed status into account.
2179 // iMax is used when finding property y-positions.
2185 iMax_
= GetChildCount();
2187 unsigned int iMax
= iMax_
;
2189 wxASSERT( iMax
<= GetChildCount() );
2191 if ( !IsExpanded() && GetParent() )
2196 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2198 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2200 if ( !pwc
->IsExpanded() ||
2201 pwc
->GetChildCount() == 0 )
2204 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2213 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
2215 wxASSERT( nextItemY
);
2217 // Linear search at the moment
2219 // nextItemY = y of next visible property, final value will be written back.
2220 wxPGProperty
* result
= NULL
;
2221 wxPGProperty
* current
= NULL
;
2222 unsigned int iy
= *nextItemY
;
2224 unsigned int iMax
= GetChildCount();
2228 wxPGProperty
* pwc
= Item(i
);
2230 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2241 if ( pwc
->IsExpanded() &&
2242 pwc
->GetChildCount() > 0 )
2244 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2256 if ( !result
&& y
< iy
)
2263 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2265 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2268 return (wxPGProperty
*) result
;
2271 void wxPGProperty::Empty()
2274 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2276 for ( i
=0; i
<GetChildCount(); i
++ )
2278 delete m_children
[i
];
2285 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2286 int WXUNUSED(childIndex
),
2287 wxVariant
& WXUNUSED(childValue
) ) const
2291 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2295 const wxVariantList
* pList
= NULL
;
2296 wxVariantList::const_iterator node
;
2300 pList
= &pendingList
->GetList();
2301 node
= pList
->begin();
2304 for ( i
=0; i
<GetChildCount(); i
++ )
2306 wxPGProperty
* child
= Item(i
);
2307 const wxVariant
* listValue
= NULL
;
2312 const wxString
& childName
= child
->GetBaseName();
2314 for ( ; node
!= pList
->end(); node
++ )
2316 const wxVariant
& item
= *((const wxVariant
*)*node
);
2317 if ( item
.GetName() == childName
)
2327 value
= child
->GetValue();
2329 if ( value
.IsNull() )
2332 // Check recursively
2333 if ( child
->GetChildCount() )
2335 const wxVariant
* childList
= NULL
;
2337 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2338 childList
= listValue
;
2340 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2348 wxPGProperty
* wxPGProperty::UpdateParentValues()
2350 wxPGProperty
* parent
= m_parent
;
2351 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2352 !parent
->IsCategory() && !parent
->IsRoot() )
2355 parent
->DoGenerateComposedValue(s
);
2356 parent
->m_value
= s
;
2357 return parent
->UpdateParentValues();
2362 bool wxPGProperty::IsTextEditable() const
2364 if ( HasFlag(wxPG_PROP_READONLY
) )
2367 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2369 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2376 // Call after fixed sub-properties added/removed after creation.
2377 // if oldSelInd >= 0 and < new max items, then selection is
2378 // moved to it. Note: oldSelInd -2 indicates that this property
2379 // should be selected.
2380 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2382 wxPropertyGridPageState
* state
= GetParentState();
2383 wxPropertyGrid
* grid
= state
->GetGrid();
2386 // Re-repare children (recursively)
2387 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2389 wxPGProperty
* child
= Item(i
);
2390 child
->InitAfterAdded(state
, grid
);
2393 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2394 if ( oldSelInd
>= (int)m_children
.size() )
2395 oldSelInd
= (int)m_children
.size() - 1;
2397 if ( oldSelInd
>= 0 )
2398 sel
= m_children
[oldSelInd
];
2399 else if ( oldSelInd
== -2 )
2403 state
->DoSelectProperty(sel
);
2405 if ( state
== grid
->GetState() )
2407 grid
->GetPanel()->Refresh();
2411 // -----------------------------------------------------------------------
2413 // -----------------------------------------------------------------------
2415 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2416 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2419 wxPGRootProperty::wxPGRootProperty()
2423 m_name
= wxS("<root>");
2430 wxPGRootProperty::~wxPGRootProperty()
2435 // -----------------------------------------------------------------------
2436 // wxPropertyCategory
2437 // -----------------------------------------------------------------------
2439 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2440 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2442 void wxPropertyCategory::Init()
2444 // don't set colour - prepareadditem method should do this
2445 SetParentalType(wxPG_PROP_CATEGORY
);
2446 m_capFgColIndex
= 1;
2450 wxPropertyCategory::wxPropertyCategory()
2457 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2458 : wxPGProperty(label
,name
)
2464 wxPropertyCategory::~wxPropertyCategory()
2469 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2470 int WXUNUSED(argFlags
) ) const
2472 return wxEmptyString
;
2475 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2477 if ( m_textExtent
> 0 )
2478 return m_textExtent
;
2480 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2484 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2487 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2491 // -----------------------------------------------------------------------
2492 // wxPGAttributeStorage
2493 // -----------------------------------------------------------------------
2495 wxPGAttributeStorage::wxPGAttributeStorage()
2499 wxPGAttributeStorage::~wxPGAttributeStorage()
2501 wxPGHashMapS2P::iterator it
;
2503 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2505 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2510 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2512 wxVariantData
* data
= value
.GetData();
2515 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2516 if ( it
!= m_map
.end() )
2518 ((wxVariantData
*)it
->second
)->DecRef();
2522 // If Null variant, just remove from set
2536 #endif // wxUSE_PROPGRID