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 // Remove superfluous semicolon and space
861 if ( text
.EndsWith(wxS("; "), &rest
) )
864 if ( (unsigned int)i
< m_children
.size() )
865 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 bool wasUnspecified
= child
->IsValueUnspecified();
1015 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1017 // Clear unspecified flag only if OnSetValue() didn't
1019 if ( child
->IsValueUnspecified() &&
1020 (wasUnspecified
|| !UsesAutoUnspecified()) )
1022 variant
= child
->GetDefaultValue();
1025 list
.Append(variant
);
1032 // Empty, becomes unspecified
1034 list
.Append(variant
);
1040 if ( curChild
>= iMax
)
1044 tokenStart
= 0xFFFFFF;
1049 // Token is not running
1050 if ( a
!= wxS(' ') )
1053 addOnlyIfNotEmpty
= false;
1055 // Is this a group of tokens?
1056 if ( a
== wxS('[') )
1060 if ( it
!= text
.end() ) it
++;
1062 size_t startPos
= pos
;
1064 // Group item - find end
1065 while ( it
!= text
.end() && depth
> 0 )
1071 if ( a
== wxS(']') )
1073 else if ( a
== wxS('[') )
1077 token
= text
.substr(startPos
,pos
-startPos
-1);
1079 if ( !token
.length() )
1082 const wxPGProperty
* child
= Item(curChild
);
1084 wxVariant oldChildValue
= child
->GetValue();
1085 wxVariant
variant(oldChildValue
);
1087 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1088 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1090 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
1091 if ( stvRes
|| (variant
!= oldChildValue
) )
1098 // Failed, becomes unspecified
1104 variant
.SetName(child
->GetBaseName());
1105 list
.Append(variant
);
1108 if ( curChild
>= iMax
)
1111 addOnlyIfNotEmpty
= true;
1113 tokenStart
= 0xFFFFFF;
1119 if ( a
== delimeter
)
1132 if ( it
!= text
.end() )
1149 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1151 wxVariant
variant(m_value
);
1152 bool res
= StringToValue(variant
, text
, argFlags
);
1158 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1160 wxVariant
variant(m_value
);
1161 bool res
= IntToValue(variant
, number
, argFlags
);
1167 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1169 if ( m_valueBitmap
)
1170 return wxSize(m_valueBitmap
->GetWidth(),-1);
1175 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1177 return wxPGGlobalVars
->m_defaultRenderer
;
1180 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1184 wxBitmap
* bmp
= m_valueBitmap
;
1186 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1188 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1190 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1193 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1195 return wxPGEditor_TextCtrl
;
1198 // Default extra property event handling - that is, none at all.
1199 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1205 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1207 // If auto unspecified values are not wanted (via window or property style),
1208 // then get default value instead of wxNullVariant.
1209 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1210 !UsesAutoUnspecified() )
1212 value
= GetDefaultValue();
1215 if ( !value
.IsNull() )
1217 wxVariant tempListVariant
;
1220 // List variants are reserved a special purpose
1221 // as intermediate containers for child values
1222 // of properties with children.
1223 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1226 // However, situation is different for composed string properties
1227 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1229 tempListVariant
= value
;
1230 pList
= &tempListVariant
;
1234 AdaptListToValue(value
, &newValue
);
1236 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1239 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1240 flags
|= wxPG_SETVAL_AGGREGATED
;
1242 if ( pList
&& !pList
->IsNull() )
1244 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1245 wxASSERT( GetChildCount() );
1246 wxASSERT( !IsCategory() );
1248 wxVariantList
& list
= pList
->GetList();
1249 wxVariantList::iterator node
;
1252 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1254 // Children in list can be in any order, but we will give hint to
1255 // GetPropertyByNameWH(). This optimizes for full list parsing.
1256 for ( node
= list
.begin(); node
!= list
.end(); node
++ )
1258 wxVariant
& childValue
= *((wxVariant
*)*node
);
1259 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1262 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1263 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1265 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1267 wxVariant listRefCopy
= childValue
;
1268 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1272 wxVariant oldVal
= child
->GetValue();
1273 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1276 else if ( child
->GetValue() != childValue
)
1278 // For aggregate properties, we will trust RefreshChildren()
1279 // to update child values.
1280 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1281 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1282 if ( flags
& wxPG_SETVAL_BY_USER
)
1283 child
->SetFlag(wxPG_PROP_MODIFIED
);
1290 if ( !value
.IsNull() )
1295 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1296 UpdateParentValues();
1299 if ( flags
& wxPG_SETVAL_BY_USER
)
1300 SetFlag(wxPG_PROP_MODIFIED
);
1302 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1307 if ( m_commonValue
!= -1 )
1309 wxPropertyGrid
* pg
= GetGrid();
1310 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1316 // Set children to unspecified, but only if aggregate or
1317 // value is <composed>
1318 if ( AreChildrenComponents() )
1321 for ( i
=0; i
<GetChildCount(); i
++ )
1322 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1327 // Update editor control
1330 // We need to check for these, otherwise GetGrid() may fail.
1331 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1336 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1338 GetGrid()->ValueChangeInEvent(value
);
1341 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1349 for ( i
= 0; i
< GetChildCount(); i
++ )
1350 Item(i
)->SetFlagRecursively(flag
, set
);
1353 void wxPGProperty::RefreshEditor()
1355 if ( m_parent
&& GetParentState() )
1357 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1358 if ( pg
->GetSelectedProperty() == this )
1360 wxWindow
* editor
= pg
->GetEditorControl();
1362 GetEditorClass()->UpdateControl( this, editor
);
1368 wxVariant
wxPGProperty::GetDefaultValue() const
1370 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1371 if ( !defVal
.IsNull() )
1374 wxVariant value
= GetValue();
1376 if ( !value
.IsNull() )
1378 wxString
valueType(value
.GetType());
1380 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1381 return wxPGVariant_Zero
;
1382 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1383 return wxPGVariant_EmptyString
;
1384 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1385 return wxPGVariant_False
;
1386 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1387 return wxVariant(0.0);
1388 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1389 return wxVariant(wxArrayString());
1390 if ( valueType
== wxS("wxLongLong") )
1391 return WXVARIANT(wxLongLong(0));
1392 if ( valueType
== wxS("wxULongLong") )
1393 return WXVARIANT(wxULongLong(0));
1394 if ( valueType
== wxS("wxColour") )
1395 return WXVARIANT(*wxBLACK
);
1397 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1398 return wxVariant(wxDateTime::Now());
1400 if ( valueType
== wxS("wxFont") )
1401 return WXVARIANT(*wxNORMAL_FONT
);
1402 if ( valueType
== wxS("wxPoint") )
1403 return WXVARIANT(wxPoint(0, 0));
1404 if ( valueType
== wxS("wxSize") )
1405 return WXVARIANT(wxSize(0, 0));
1411 void wxPGProperty::EnsureCells( unsigned int column
)
1413 if ( column
>= m_cells
.size() )
1415 // Fill empty slots with default cells
1416 wxPropertyGrid
* pg
= GetGrid();
1417 wxPGCell defaultCell
;
1419 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1420 defaultCell
= pg
->GetPropertyDefaultCell();
1422 defaultCell
= pg
->GetCategoryDefaultCell();
1424 // TODO: Replace with resize() call
1425 unsigned int cellCountMax
= column
+1;
1427 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1428 m_cells
.push_back(defaultCell
);
1432 void wxPGProperty::SetCell( int column
,
1433 const wxPGCell
& cell
)
1435 EnsureCells(column
);
1437 m_cells
[column
] = cell
;
1440 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1441 unsigned int lastCol
,
1442 const wxPGCell
& cell
,
1443 const wxPGCell
& srcData
,
1444 wxPGCellData
* unmodCellData
,
1445 FlagType ignoreWithFlags
,
1449 // Sets cell in memory optimizing fashion. That is, if
1450 // current cell data matches unmodCellData, we will
1451 // simply get reference to data from cell. Otherwise,
1452 // cell information from srcData is merged into current.
1455 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1457 EnsureCells(lastCol
);
1459 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1461 if ( m_cells
[col
].GetData() == unmodCellData
)
1463 // Data matches... use cell directly
1464 m_cells
[col
] = cell
;
1468 // Data did not match... merge valid information
1469 m_cells
[col
].MergeFrom(srcData
);
1476 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1477 Item(i
)->AdaptiveSetCell( firstCol
,
1487 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1489 if ( m_cells
.size() > column
)
1490 return m_cells
[column
];
1492 wxPropertyGrid
* pg
= GetGrid();
1495 return pg
->GetCategoryDefaultCell();
1497 return pg
->GetPropertyDefaultCell();
1500 wxPGCell
& wxPGProperty::GetCell( unsigned int column
)
1502 EnsureCells(column
);
1503 return m_cells
[column
];
1506 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1509 wxPGProperty
* firstProp
= this;
1512 // If category is tried to set recursively, skip it and only
1513 // affect the children.
1516 while ( firstProp
->IsCategory() )
1518 if ( !firstProp
->GetChildCount() )
1520 firstProp
= firstProp
->Item(0);
1524 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1525 wxPGCellData
* firstCellData
= firstCell
.GetData();
1527 wxPGCell
newCell(firstCell
);
1528 newCell
.SetBgCol(colour
);
1530 srcCell
.SetBgCol(colour
);
1533 GetParentState()->GetColumnCount()-1,
1537 recursively
? wxPG_PROP_CATEGORY
: 0,
1541 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1544 wxPGProperty
* firstProp
= this;
1547 // If category is tried to set recursively, skip it and only
1548 // affect the children.
1551 while ( firstProp
->IsCategory() )
1553 if ( !firstProp
->GetChildCount() )
1555 firstProp
= firstProp
->Item(0);
1559 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1560 wxPGCellData
* firstCellData
= firstCell
.GetData();
1562 wxPGCell
newCell(firstCell
);
1563 newCell
.SetFgCol(colour
);
1565 srcCell
.SetFgCol(colour
);
1568 GetParentState()->GetColumnCount()-1,
1572 recursively
? wxPG_PROP_CATEGORY
: 0,
1576 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1581 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1586 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1588 if ( DoSetAttribute( name
, value
) )
1590 // Support working without grid, when possible
1591 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1595 m_attributes
.Set( name
, value
);
1598 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1600 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1603 while ( attributes
.GetNext(it
, variant
) )
1604 SetAttribute( variant
.GetName(), variant
);
1607 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1613 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1615 return m_attributes
.FindValue(name
);
1618 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1620 wxVariant variant
= m_attributes
.FindValue(name
);
1622 if ( !variant
.IsNull() )
1623 return variant
.GetString();
1628 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1630 wxVariant variant
= m_attributes
.FindValue(name
);
1632 return wxPGVariantToInt(variant
, defVal
);
1635 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1638 wxVariant variant
= m_attributes
.FindValue(name
);
1640 if ( wxPGVariantToDouble(variant
, &retVal
) )
1646 wxVariant
wxPGProperty::GetAttributesAsList() const
1648 wxVariantList tempList
;
1649 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1651 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1654 while ( m_attributes
.GetNext(it
, variant
) )
1660 // Slots of utility flags are NULL
1661 const unsigned int gs_propFlagToStringSize
= 14;
1663 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1680 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1683 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1687 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1689 if ( relevantFlags
& a
)
1691 const wxChar
* fs
= gs_propFlagToString
[i
];
1703 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1707 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1709 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1711 const wxChar
* fs
= gs_propFlagToString
[i
];
1712 if ( fs
&& str
== fs
)
1718 WX_PG_TOKENIZER1_END()
1720 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1723 wxValidator
* wxPGProperty::DoGetValidator() const
1725 return (wxValidator
*) NULL
;
1728 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1730 wxPropertyGrid
* pg
= GetGrid();
1731 int sel
= GetChoiceSelection();
1735 if ( index
== wxNOT_FOUND
)
1736 index
= m_choices
.GetCount();
1741 m_choices
.Insert(label
, index
, value
);
1743 if ( sel
!= newSel
)
1744 SetChoiceSelection(newSel
);
1746 if ( this == pg
->GetSelection() )
1747 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1753 void wxPGProperty::DeleteChoice( int index
)
1755 wxPropertyGrid
* pg
= GetGrid();
1757 int sel
= GetChoiceSelection();
1760 // Adjust current value
1763 SetValueToUnspecified();
1766 else if ( index
< sel
)
1771 m_choices
.RemoveAt(index
);
1773 if ( sel
!= newSel
)
1774 SetChoiceSelection(newSel
);
1776 if ( this == pg
->GetSelection() )
1777 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1780 int wxPGProperty::GetChoiceSelection() const
1782 wxVariant value
= GetValue();
1783 wxString valueType
= value
.GetType();
1784 int index
= wxNOT_FOUND
;
1786 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1789 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1791 index
= value
.GetLong();
1793 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1795 index
= m_choices
.Index(value
.GetString());
1797 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1799 index
= value
.GetBool()? 1 : 0;
1805 void wxPGProperty::SetChoiceSelection( int newValue
)
1807 // Changes value of a property with choices, but only
1808 // works if the value type is long or string.
1809 wxString valueType
= GetValue().GetType();
1811 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1813 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1815 SetValue( m_choices
.GetLabel(newValue
) );
1817 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1819 SetValue( (long) newValue
);
1823 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1825 m_choices
.Assign(choices
);
1828 // This may be needed to trigger some initialization
1829 // (but don't do it if property is somewhat uninitialized)
1830 wxVariant defVal
= GetDefaultValue();
1831 if ( defVal
.IsNull() )
1841 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1843 const wxPGEditor
* editor
;
1845 if ( !m_customEditor
)
1847 editor
= DoGetEditorClass();
1850 editor
= m_customEditor
;
1853 // Maybe override editor if common value specified
1854 if ( GetDisplayedCommonValueCount() )
1856 // TextCtrlAndButton -> ComboBoxAndButton
1857 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1858 editor
= wxPGEditor_ChoiceAndButton
;
1860 // TextCtrl -> ComboBox
1861 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1862 editor
= wxPGEditor_ComboBox
;
1868 bool wxPGProperty::HasVisibleChildren() const
1872 for ( i
=0; i
<GetChildCount(); i
++ )
1874 wxPGProperty
* child
= Item(i
);
1876 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1883 bool wxPGProperty::RecreateEditor()
1885 wxPropertyGrid
* pg
= GetGrid();
1888 wxPGProperty
* selected
= pg
->GetSelection();
1889 if ( this == selected
)
1891 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1898 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1900 delete m_valueBitmap
;
1902 if ( &bmp
&& bmp
.Ok() )
1905 wxSize maxSz
= GetGrid()->GetImageSize();
1906 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1908 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1910 // Create a memory DC
1911 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1914 dc
.SelectObject(*bmpNew
);
1917 // FIXME: This is ugly - use image or wait for scaling patch.
1918 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1919 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1921 dc
.SetUserScale(scaleX
,scaleY
);
1923 dc
.DrawBitmap( bmp
, 0, 0 );
1925 m_valueBitmap
= bmpNew
;
1929 m_valueBitmap
= new wxBitmap(bmp
);
1932 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1936 m_valueBitmap
= NULL
;
1937 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1942 wxPGProperty
* wxPGProperty::GetMainParent() const
1944 const wxPGProperty
* curChild
= this;
1945 const wxPGProperty
* curParent
= m_parent
;
1947 while ( curParent
&& !curParent
->IsCategory() )
1949 curChild
= curParent
;
1950 curParent
= curParent
->m_parent
;
1953 return (wxPGProperty
*) curChild
;
1957 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1960 // Returns last visible sub-item, recursively.
1961 if ( !IsExpanded() || !GetChildCount() )
1964 return Last()->GetLastVisibleSubItem();
1968 bool wxPGProperty::IsVisible() const
1970 const wxPGProperty
* parent
;
1972 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1975 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1977 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1984 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1986 wxPropertyGridPageState
* state
= GetParentState();
1987 wxPropertyGrid
* propGrid
= state
->GetGrid();
1988 if ( state
== propGrid
->GetState() )
1994 int wxPGProperty::GetY2( int lh
) const
1996 const wxPGProperty
* parent
;
1997 const wxPGProperty
* child
= this;
2001 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2003 if ( !parent
->IsExpanded() )
2005 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2010 y
-= lh
; // need to reduce one level
2016 int wxPGProperty::GetY() const
2018 return GetY2(GetGrid()->GetRowHeight());
2021 // This is used by Insert etc.
2022 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
2024 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2026 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2027 m_children
.push_back( prop
);
2031 m_children
.insert( m_children
.begin()+index
, prop
);
2032 if ( correct_mode
) FixIndicesOfChildren( index
);
2035 prop
->m_parent
= this;
2038 // This is used by properties that have fixed sub-properties
2039 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2041 wxASSERT_MSG( prop
->GetBaseName().length(),
2042 "Property's children must have unique, non-empty names within their scope" );
2044 prop
->m_arrIndex
= m_children
.size();
2045 m_children
.push_back( prop
);
2047 int custImgHeight
= prop
->OnMeasureImage().y
;
2048 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2049 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2051 prop
->m_parent
= this;
2054 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2056 wxArrayPGProperty::iterator it
;
2057 wxArrayPGProperty
& children
= m_children
;
2059 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2063 m_children
.erase(it
);
2069 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2071 wxASSERT( GetChildCount() );
2072 wxASSERT( !IsCategory() );
2074 *value
= GetValue();
2076 if ( !list
.GetCount() )
2079 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2081 bool allChildrenSpecified
;
2083 // Don't fully update aggregate properties unless all children have
2085 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2086 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2088 allChildrenSpecified
= true;
2090 wxVariant childValue
= list
[0];
2094 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2096 for ( i
=0; i
<GetChildCount(); i
++ )
2098 const wxPGProperty
* child
= Item(i
);
2100 if ( childValue
.GetName() == child
->GetBaseName() )
2102 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2104 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2106 wxVariant
cv2(child
->GetValue());
2107 child
->AdaptListToValue(childValue
, &cv2
);
2111 if ( allChildrenSpecified
)
2112 ChildChanged(*value
, i
, childValue
);
2114 if ( n
== (unsigned int)list
.GetCount() )
2116 childValue
= list
[n
];
2122 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2125 for ( i
=starthere
;i
<GetChildCount();i
++)
2126 Item(i
)->m_arrIndex
= i
;
2130 // Returns (direct) child property with given name (or NULL if not found)
2131 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2135 for ( i
=0; i
<GetChildCount(); i
++ )
2137 wxPGProperty
* p
= Item(i
);
2138 if ( p
->m_name
== name
)
2142 // Does it have point, then?
2143 int pos
= name
.Find(wxS('.'));
2145 return (wxPGProperty
*) NULL
;
2147 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2149 if ( !p
|| !p
->GetChildCount() )
2152 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2155 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2157 unsigned int i
= hintIndex
;
2159 if ( i
>= GetChildCount() )
2162 unsigned int lastIndex
= i
- 1;
2164 if ( lastIndex
>= GetChildCount() )
2165 lastIndex
= GetChildCount() - 1;
2169 wxPGProperty
* p
= Item(i
);
2170 if ( p
->m_name
== name
)
2173 if ( i
== lastIndex
)
2177 if ( i
== GetChildCount() )
2184 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2186 // Returns height of children, recursively, and
2187 // by taking expanded/collapsed status into account.
2189 // iMax is used when finding property y-positions.
2195 iMax_
= GetChildCount();
2197 unsigned int iMax
= iMax_
;
2199 wxASSERT( iMax
<= GetChildCount() );
2201 if ( !IsExpanded() && GetParent() )
2206 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2208 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2210 if ( !pwc
->IsExpanded() ||
2211 pwc
->GetChildCount() == 0 )
2214 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2223 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
2225 wxASSERT( nextItemY
);
2227 // Linear search at the moment
2229 // nextItemY = y of next visible property, final value will be written back.
2230 wxPGProperty
* result
= NULL
;
2231 wxPGProperty
* current
= NULL
;
2232 unsigned int iy
= *nextItemY
;
2234 unsigned int iMax
= GetChildCount();
2238 wxPGProperty
* pwc
= Item(i
);
2240 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2251 if ( pwc
->IsExpanded() &&
2252 pwc
->GetChildCount() > 0 )
2254 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2266 if ( !result
&& y
< iy
)
2273 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2275 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2278 return (wxPGProperty
*) result
;
2281 void wxPGProperty::Empty()
2284 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2286 for ( i
=0; i
<GetChildCount(); i
++ )
2288 delete m_children
[i
];
2295 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2296 int WXUNUSED(childIndex
),
2297 wxVariant
& WXUNUSED(childValue
) ) const
2301 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2305 const wxVariantList
* pList
= NULL
;
2306 wxVariantList::const_iterator node
;
2310 pList
= &pendingList
->GetList();
2311 node
= pList
->begin();
2314 for ( i
=0; i
<GetChildCount(); i
++ )
2316 wxPGProperty
* child
= Item(i
);
2317 const wxVariant
* listValue
= NULL
;
2322 const wxString
& childName
= child
->GetBaseName();
2324 for ( ; node
!= pList
->end(); node
++ )
2326 const wxVariant
& item
= *((const wxVariant
*)*node
);
2327 if ( item
.GetName() == childName
)
2337 value
= child
->GetValue();
2339 if ( value
.IsNull() )
2342 // Check recursively
2343 if ( child
->GetChildCount() )
2345 const wxVariant
* childList
= NULL
;
2347 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2348 childList
= listValue
;
2350 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2358 wxPGProperty
* wxPGProperty::UpdateParentValues()
2360 wxPGProperty
* parent
= m_parent
;
2361 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2362 !parent
->IsCategory() && !parent
->IsRoot() )
2365 parent
->DoGenerateComposedValue(s
);
2366 parent
->m_value
= s
;
2367 return parent
->UpdateParentValues();
2372 bool wxPGProperty::IsTextEditable() const
2374 if ( HasFlag(wxPG_PROP_READONLY
) )
2377 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2379 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2386 // Call after fixed sub-properties added/removed after creation.
2387 // if oldSelInd >= 0 and < new max items, then selection is
2388 // moved to it. Note: oldSelInd -2 indicates that this property
2389 // should be selected.
2390 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2392 wxPropertyGridPageState
* state
= GetParentState();
2393 wxPropertyGrid
* grid
= state
->GetGrid();
2396 // Re-repare children (recursively)
2397 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2399 wxPGProperty
* child
= Item(i
);
2400 child
->InitAfterAdded(state
, grid
);
2403 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2404 if ( oldSelInd
>= (int)m_children
.size() )
2405 oldSelInd
= (int)m_children
.size() - 1;
2407 if ( oldSelInd
>= 0 )
2408 sel
= m_children
[oldSelInd
];
2409 else if ( oldSelInd
== -2 )
2413 state
->DoSelectProperty(sel
);
2415 if ( state
== grid
->GetState() )
2417 grid
->GetPanel()->Refresh();
2421 // -----------------------------------------------------------------------
2423 // -----------------------------------------------------------------------
2425 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2426 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2429 wxPGRootProperty::wxPGRootProperty()
2433 m_name
= wxS("<root>");
2440 wxPGRootProperty::~wxPGRootProperty()
2445 // -----------------------------------------------------------------------
2446 // wxPropertyCategory
2447 // -----------------------------------------------------------------------
2449 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2450 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2452 void wxPropertyCategory::Init()
2454 // don't set colour - prepareadditem method should do this
2455 SetParentalType(wxPG_PROP_CATEGORY
);
2456 m_capFgColIndex
= 1;
2460 wxPropertyCategory::wxPropertyCategory()
2467 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2468 : wxPGProperty(label
,name
)
2474 wxPropertyCategory::~wxPropertyCategory()
2479 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2480 int WXUNUSED(argFlags
) ) const
2482 return wxEmptyString
;
2485 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2487 if ( m_textExtent
> 0 )
2488 return m_textExtent
;
2490 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2494 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2497 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2501 // -----------------------------------------------------------------------
2502 // wxPGAttributeStorage
2503 // -----------------------------------------------------------------------
2505 wxPGAttributeStorage::wxPGAttributeStorage()
2509 wxPGAttributeStorage::~wxPGAttributeStorage()
2511 wxPGHashMapS2P::iterator it
;
2513 for ( it
= m_map
.begin(); it
!= m_map
.end(); it
++ )
2515 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2520 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2522 wxVariantData
* data
= value
.GetData();
2525 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2526 if ( it
!= m_map
.end() )
2528 ((wxVariantData
*)it
->second
)->DecRef();
2532 // If Null variant, just remove from set
2546 #endif // wxUSE_PROPGRID