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());
152 // Draw Background, but only if not rendering in control
153 // (as control already has rendered correct background).
154 if ( !(flags
& (Control
|ChoicePopup
)) )
155 dc
.DrawRectangle(rect
);
157 const wxBitmap
& bmp
= cell
.GetBitmap();
159 // Do not draw oversized bitmap outside choice popup
160 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
164 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
165 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
167 imageOffset
= bmp
.GetWidth();
173 // -----------------------------------------------------------------------
174 // wxPGDefaultRenderer
175 // -----------------------------------------------------------------------
177 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
178 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
179 int column
, int item
, int flags
) const
181 bool isUnspecified
= property
->IsValueUnspecified();
183 if ( column
== 1 && item
== -1 )
185 int cmnVal
= property
->GetCommonValue();
189 if ( !isUnspecified
)
190 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
195 const wxPGEditor
* editor
= NULL
;
196 const wxPGCell
* cell
= NULL
;
200 int preDrawFlags
= flags
;
202 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
204 imageOffset
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
208 if ( !isUnspecified
)
210 editor
= property
->GetColumnEditor(column
);
212 // Regular property value
214 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
216 wxPGPaintData paintdata
;
217 paintdata
.m_parent
= propertyGrid
;
218 paintdata
.m_choiceItem
= item
;
220 if ( imageSize
.x
> 0 )
222 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
223 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
224 wxPG_CUSTOM_IMAGE_WIDTH
,
225 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
227 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
229 paintdata
.m_drawnWidth
= imageSize
.x
;
230 paintdata
.m_drawnHeight
= imageSize
.y
;
232 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
234 imageOffset
= paintdata
.m_drawnWidth
;
237 text
= property
->GetValueAsString();
240 if ( propertyGrid
->GetColumnCount() <= 2 )
242 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
243 if ( unitsString
.length() )
244 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
248 if ( text
.length() == 0 )
250 // Try to show inline help if no text
251 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
252 if ( !vInlineHelp
.IsNull() )
254 text
= vInlineHelp
.GetString();
255 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
260 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
262 // active caption gets nice dotted rectangle
263 if ( property
->IsCategory() /*&& column == 0*/ )
265 if ( flags
& Selected
)
267 if ( imageOffset
> 0 )
268 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
270 DrawCaptionSelectionRect( dc
,
271 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
272 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
273 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
274 propertyGrid
->GetCaptionFont())
275 +(wxPG_CAPRECTXMARGIN
*2),
276 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
281 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
285 if ( property
&& column
== 1 )
289 wxBitmap
* bmp
= property
->GetValueImage();
291 if ( bmp
&& bmp
->Ok() )
292 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
298 // -----------------------------------------------------------------------
300 // -----------------------------------------------------------------------
302 wxPGCellData::wxPGCellData()
305 m_hasValidText
= false;
308 // -----------------------------------------------------------------------
310 // -----------------------------------------------------------------------
317 wxPGCell::wxPGCell( const wxString
& text
,
318 const wxBitmap
& bitmap
,
319 const wxColour
& fgCol
,
320 const wxColour
& bgCol
)
323 wxPGCellData
* data
= new wxPGCellData();
326 data
->m_bitmap
= bitmap
;
327 data
->m_fgCol
= fgCol
;
328 data
->m_bgCol
= bgCol
;
329 data
->m_hasValidText
= true;
332 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
334 wxPGCellData
* c
= new wxPGCellData();
335 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
336 c
->m_text
= o
->m_text
;
337 c
->m_bitmap
= o
->m_bitmap
;
338 c
->m_fgCol
= o
->m_fgCol
;
339 c
->m_bgCol
= o
->m_bgCol
;
340 c
->m_hasValidText
= o
->m_hasValidText
;
344 void wxPGCell::SetText( const wxString
& text
)
348 GetData()->SetText(text
);
351 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
355 GetData()->SetBitmap(bitmap
);
358 void wxPGCell::SetFgCol( const wxColour
& col
)
362 GetData()->SetFgCol(col
);
365 void wxPGCell::SetBgCol( const wxColour
& col
)
369 GetData()->SetBgCol(col
);
372 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
376 wxPGCellData
* data
= GetData();
378 if ( srcCell
.HasText() )
379 data
->SetText(srcCell
.GetText());
381 if ( srcCell
.GetFgCol().IsOk() )
382 data
->SetFgCol(srcCell
.GetFgCol());
384 if ( srcCell
.GetBgCol().IsOk() )
385 data
->SetBgCol(srcCell
.GetBgCol());
387 if ( srcCell
.GetBitmap().IsOk() )
388 data
->SetBitmap(srcCell
.GetBitmap());
391 // -----------------------------------------------------------------------
393 // -----------------------------------------------------------------------
395 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
397 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
399 void wxPGProperty::Init()
405 m_parentState
= (wxPropertyGridPageState
*) NULL
;
408 m_clientObject
= NULL
;
410 m_customEditor
= (wxPGEditor
*) NULL
;
412 m_validator
= (wxValidator
*) NULL
;
414 m_valueBitmap
= (wxBitmap
*) NULL
;
416 m_maxLen
= 0; // infinite maximum length
418 m_flags
= wxPG_PROP_PROPERTY
;
426 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
428 // We really need to check if &label and &name are NULL pointers
429 // (this can if we are called before property grid has been initalized)
431 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
434 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
437 DoSetName( m_label
);
442 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
443 wxPropertyGrid
* propgrid
)
446 // Called after property has been added to grid or page
447 // (so propgrid can be NULL, too).
449 wxPGProperty
* parent
= m_parent
;
450 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
452 m_parentState
= pageState
;
454 #if wxPG_COMPATIBILITY_1_4
455 // Make sure deprecated virtual functions are not implemented
456 wxString s
= GetValueAsString( 0xFFFF );
457 wxASSERT_MSG( s
== g_invalidStringContent
,
458 "Implement ValueToString() instead of GetValueAsString()" );
461 if ( !parentIsRoot
&& !parent
->IsCategory() )
463 m_cells
= parent
->m_cells
;
466 // If in hideable adding mode, or if assigned parent is hideable, then
467 // make this one hideable.
469 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
470 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
472 SetFlag( wxPG_PROP_HIDDEN
);
474 // Set custom image flag.
475 int custImgHeight
= OnMeasureImage().y
;
476 if ( custImgHeight
< 0 )
478 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
481 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
482 SetFlag(wxPG_PROP_NOEDITOR
);
484 // Make sure parent has some parental flags
485 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
486 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
490 // This is not a category.
494 unsigned char depth
= 1;
497 depth
= parent
->m_depth
;
498 if ( !parent
->IsCategory() )
502 unsigned char greyDepth
= depth
;
506 wxPropertyCategory
* pc
;
508 if ( parent
->IsCategory() )
509 pc
= (wxPropertyCategory
* ) parent
;
511 // This conditional compile is necessary to
512 // bypass some compiler bug.
513 pc
= pageState
->GetPropertyCategory(parent
);
516 greyDepth
= pc
->GetDepth();
518 greyDepth
= parent
->m_depthBgCol
;
521 m_depthBgCol
= greyDepth
;
525 // This is a category.
528 unsigned char depth
= 1;
531 depth
= parent
->m_depth
+ 1;
534 m_depthBgCol
= depth
;
538 // Has initial children
539 if ( GetChildCount() )
541 // Check parental flags
542 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
),
543 "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
544 "SetFlag(wxPG_PROP_AGGREGATE) before calling"
545 "wxPGProperty::AddChild()." );
547 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
549 // Properties with private children are not expanded by default.
552 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
554 // ...unless it cannot be expanded by user and therefore must
555 // remain visible at all times
560 // Prepare children recursively
561 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
563 wxPGProperty
* child
= Item(i
);
564 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
567 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
568 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
572 wxPGProperty::wxPGProperty()
579 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
586 wxPGProperty::~wxPGProperty()
588 delete m_clientObject
;
590 Empty(); // this deletes items
592 delete m_valueBitmap
;
597 // This makes it easier for us to detect dangling pointers
602 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
604 wxPGProperty
* parent
= m_parent
;
607 if ( parent
== candidate
)
609 parent
= parent
->m_parent
;
615 wxString
wxPGProperty::GetName() const
617 wxPGProperty
* parent
= GetParent();
619 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
622 return m_parent
->GetName() + wxS(".") + m_name
;
625 wxPropertyGrid
* wxPGProperty::GetGrid() const
627 if ( !m_parentState
)
629 return m_parentState
->GetGrid();
632 int wxPGProperty::Index( const wxPGProperty
* p
) const
634 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
636 if ( p
== m_children
[i
] )
642 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
647 void wxPGProperty::OnSetValue()
651 void wxPGProperty::RefreshChildren ()
655 void wxPGProperty::GetDisplayInfo( unsigned int column
,
659 const wxPGCell
** pCell
)
661 const wxPGCell
* cell
= NULL
;
663 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
665 // Not painting listi of choice popups, so get text from property
666 cell
= &GetCell(column
);
667 if ( cell
->HasText() )
669 *pString
= cell
->GetText();
674 *pString
= GetLabel();
675 else if ( column
== 1 )
676 *pString
= GetDisplayedString();
677 else if ( column
== 2 )
678 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
683 wxASSERT( column
== 1 );
685 if ( choiceIndex
!= wxNOT_FOUND
)
687 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
688 if ( entry
.GetBitmap().IsOk() ||
689 entry
.GetFgCol().IsOk() ||
690 entry
.GetBgCol().IsOk() )
692 *pString
= m_choices
.GetLabel(choiceIndex
);
697 cell
= &GetCell(column
);
699 wxASSERT_MSG( cell
->GetData(),
700 wxString::Format("Invalid cell for property %s",
701 GetName().c_str()) );
707 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
710 if ( col != 1 || choiceIndex == wxNOT_FOUND )
712 const wxPGCell& cell = GetCell(col);
713 if ( cell->HasText() )
715 return cell->GetText();
722 return GetDisplayedString();
724 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
730 return m_choices.GetLabel(choiceIndex);
733 return wxEmptyString;
737 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
739 const wxVariantList
* valueOverrides
,
740 wxPGHashMapS2S
* childResults
) const
743 int iMax
= m_children
.size();
749 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
750 !(argFlags
& wxPG_FULL_VALUE
) )
751 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
753 int iMaxMinusOne
= iMax
-1;
755 if ( !IsTextEditable() )
756 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
758 wxPGProperty
* curChild
= m_children
[0];
760 bool overridesLeft
= false;
761 wxVariant overrideValue
;
762 wxVariantList::const_iterator node
;
764 if ( valueOverrides
)
766 node
= valueOverrides
->begin();
767 if ( node
!= valueOverrides
->end() )
769 overrideValue
= *node
;
770 overridesLeft
= true;
774 for ( i
= 0; i
< iMax
; i
++ )
776 wxVariant childValue
;
778 wxString childLabel
= curChild
->GetLabel();
780 // Check for value override
781 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
783 if ( !overrideValue
.IsNull() )
784 childValue
= overrideValue
;
786 childValue
= curChild
->GetValue();
788 if ( node
!= valueOverrides
->end() )
789 overrideValue
= *node
;
791 overridesLeft
= false;
795 childValue
= curChild
->GetValue();
799 if ( !childValue
.IsNull() )
801 if ( overridesLeft
&&
802 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
803 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
805 wxVariantList
& childList
= childValue
.GetList();
806 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
807 &childList
, childResults
);
811 s
= curChild
->ValueToString(childValue
,
812 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
816 if ( childResults
&& curChild
->GetChildCount() )
817 (*childResults
)[curChild
->GetName()] = s
;
820 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
823 if ( !curChild
->GetChildCount() || skip
)
826 text
+= wxS("[") + s
+ wxS("]");
828 if ( i
< iMaxMinusOne
)
830 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
831 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
832 !(argFlags
& wxPG_FULL_VALUE
) )
837 if ( !curChild
->GetChildCount() )
843 curChild
= m_children
[i
+1];
847 if ( (unsigned int)i
< m_children
.size() )
849 if ( !text
.EndsWith(wxS("; ")) )
850 text
+= wxS("; ...");
856 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
859 wxCHECK_MSG( GetChildCount() > 0,
861 "If user property does not have any children, it must "
862 "override GetValueAsString" );
864 // FIXME: Currently code below only works if value is actually m_value
865 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
866 "Sorry, currently default wxPGProperty::ValueToString() "
867 "implementation only works if value is m_value." );
870 DoGenerateComposedValue(text
, argFlags
);
874 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
876 #if wxPG_COMPATIBILITY_1_4
877 // This is backwards compatibility test
878 // That is, to make sure this function is not overridden
879 // (instead, ValueToString() should be).
880 if ( argFlags
== 0xFFFF )
882 // Do not override! (for backwards compliancy)
883 return g_invalidStringContent
;
887 if ( IsValueUnspecified() )
888 return wxEmptyString
;
890 if ( m_commonValue
== -1 )
892 wxVariant
value(GetValue());
893 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
897 // Return common value's string representation
898 wxPropertyGrid
* pg
= GetGrid();
899 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
901 if ( argFlags
& wxPG_FULL_VALUE
)
903 return cv
->GetLabel();
905 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
907 return cv
->GetEditableText();
911 return cv
->GetLabel();
915 wxString
wxPGProperty::GetValueString( int argFlags
) const
917 return GetValueAsString(argFlags
);
920 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
922 variant
= (long)number
;
926 // Convert semicolon delimited tokens into child values.
927 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
929 if ( !GetChildCount() )
932 unsigned int curChild
= 0;
934 unsigned int iMax
= m_children
.size();
936 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
937 !(argFlags
& wxPG_FULL_VALUE
) )
938 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
940 bool changed
= false;
945 // Its best only to add non-empty group items
946 bool addOnlyIfNotEmpty
= false;
947 const wxChar delimeter
= wxS(';');
949 size_t tokenStart
= 0xFFFFFF;
951 wxVariantList temp_list
;
952 wxVariant
list(temp_list
);
954 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
957 bool debug_print
= false;
962 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
965 wxString::const_iterator it
= text
.begin();
968 if ( it
!= text
.end() )
975 // How many units we iterate string forward at the end of loop?
976 // We need to keep track of this or risk going to negative
977 // with it-- operation.
978 unsigned int strPosIncrement
= 1;
980 if ( tokenStart
!= 0xFFFFFF )
983 if ( a
== delimeter
|| a
== 0 )
985 token
= text
.substr(tokenStart
,pos
-tokenStart
);
987 size_t len
= token
.length();
989 if ( !addOnlyIfNotEmpty
|| len
> 0 )
991 const wxPGProperty
* child
= Item(curChild
);
992 wxVariant
variant(child
->GetValue());
993 wxString childName
= child
->GetBaseName();
997 wxLogDebug(wxT("token = '%s', child = %s"),
998 token
.c_str(), childName
.c_str());
1001 // Add only if editable or setting programmatically
1002 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1003 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1007 if ( child
->StringToValue(variant
, token
,
1008 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1010 // We really need to set the variant's name
1011 // *after* child->StringToValue() has been
1012 // called, since variant's value may be set by
1013 // assigning another variant into it, which
1014 // then usually causes name to be copied (ie.
1015 // usually cleared) as well. wxBoolProperty
1016 // being case in point with its use of
1017 // wxPGVariant_Bool macro as an optimization.
1018 variant
.SetName(childName
);
1019 list
.Append(variant
);
1026 // Empty, becomes unspecified
1028 variant
.SetName(childName
);
1029 list
.Append(variant
);
1035 if ( curChild
>= iMax
)
1039 tokenStart
= 0xFFFFFF;
1044 // Token is not running
1045 if ( a
!= wxS(' ') )
1048 addOnlyIfNotEmpty
= false;
1050 // Is this a group of tokens?
1051 if ( a
== wxS('[') )
1055 if ( it
!= text
.end() ) ++it
;
1057 size_t startPos
= pos
;
1059 // Group item - find end
1060 while ( it
!= text
.end() && depth
> 0 )
1066 if ( a
== wxS(']') )
1068 else if ( a
== wxS('[') )
1072 token
= text
.substr(startPos
,pos
-startPos
-1);
1074 if ( !token
.length() )
1077 const wxPGProperty
* child
= Item(curChild
);
1079 wxVariant oldChildValue
= child
->GetValue();
1080 wxVariant
variant(oldChildValue
);
1082 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1083 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1085 wxString childName
= child
->GetBaseName();
1087 bool stvRes
= child
->StringToValue( variant
, token
,
1089 if ( stvRes
|| (variant
!= oldChildValue
) )
1091 variant
.SetName(childName
);
1092 list
.Append(variant
);
1103 if ( curChild
>= iMax
)
1106 addOnlyIfNotEmpty
= true;
1108 tokenStart
= 0xFFFFFF;
1114 if ( a
== delimeter
)
1115 strPosIncrement
-= 1;
1123 it
+= strPosIncrement
;
1125 if ( it
!= text
.end() )
1134 pos
+= strPosIncrement
;
1143 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1145 wxVariant
variant(m_value
);
1146 bool res
= StringToValue(variant
, text
, argFlags
);
1152 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1154 wxVariant
variant(m_value
);
1155 bool res
= IntToValue(variant
, number
, argFlags
);
1161 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1163 if ( m_valueBitmap
)
1164 return wxSize(m_valueBitmap
->GetWidth(),-1);
1169 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1171 return wxPGGlobalVars
->m_defaultRenderer
;
1174 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1178 wxBitmap
* bmp
= m_valueBitmap
;
1180 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1182 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1184 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1187 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1189 return wxPGEditor_TextCtrl
;
1192 // Default extra property event handling - that is, none at all.
1193 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1199 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1201 // If auto unspecified values are not wanted (via window or property style),
1202 // then get default value instead of wxNullVariant.
1203 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1204 !UsesAutoUnspecified() )
1206 value
= GetDefaultValue();
1209 if ( !value
.IsNull() )
1211 wxVariant tempListVariant
;
1214 // List variants are reserved a special purpose
1215 // as intermediate containers for child values
1216 // of properties with children.
1217 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1220 // However, situation is different for composed string properties
1221 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1223 tempListVariant
= value
;
1224 pList
= &tempListVariant
;
1228 AdaptListToValue(value
, &newValue
);
1230 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1233 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1234 flags
|= wxPG_SETVAL_AGGREGATED
;
1236 if ( pList
&& !pList
->IsNull() )
1238 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1239 wxASSERT( GetChildCount() );
1240 wxASSERT( !IsCategory() );
1242 wxVariantList
& list
= pList
->GetList();
1243 wxVariantList::iterator node
;
1246 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1248 // Children in list can be in any order, but we will give hint to
1249 // GetPropertyByNameWH(). This optimizes for full list parsing.
1250 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1252 wxVariant
& childValue
= *((wxVariant
*)*node
);
1253 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1256 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1257 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1259 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1261 wxVariant listRefCopy
= childValue
;
1262 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1266 wxVariant oldVal
= child
->GetValue();
1267 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1270 else if ( child
->GetValue() != childValue
)
1272 // For aggregate properties, we will trust RefreshChildren()
1273 // to update child values.
1274 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1275 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1276 if ( flags
& wxPG_SETVAL_BY_USER
)
1277 child
->SetFlag(wxPG_PROP_MODIFIED
);
1284 if ( !value
.IsNull() )
1290 if ( flags
& wxPG_SETVAL_BY_USER
)
1291 SetFlag(wxPG_PROP_MODIFIED
);
1293 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1298 if ( m_commonValue
!= -1 )
1300 wxPropertyGrid
* pg
= GetGrid();
1301 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1307 // Set children to unspecified, but only if aggregate or
1308 // value is <composed>
1309 if ( AreChildrenComponents() )
1312 for ( i
=0; i
<GetChildCount(); i
++ )
1313 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1317 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1318 UpdateParentValues();
1321 // Update editor control
1324 // We need to check for these, otherwise GetGrid() may fail.
1325 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1330 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1332 GetGrid()->ValueChangeInEvent(value
);
1335 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1343 for ( i
= 0; i
< GetChildCount(); i
++ )
1344 Item(i
)->SetFlagRecursively(flag
, set
);
1347 void wxPGProperty::RefreshEditor()
1352 wxPropertyGrid
* pg
= GetGrid();
1353 if ( pg
&& pg
->GetSelectedProperty() == this )
1354 pg
->RefreshEditor();
1357 wxVariant
wxPGProperty::GetDefaultValue() const
1359 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1360 if ( !defVal
.IsNull() )
1363 wxVariant value
= GetValue();
1365 if ( !value
.IsNull() )
1367 wxString
valueType(value
.GetType());
1369 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1370 return wxPGVariant_Zero
;
1371 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1372 return wxPGVariant_EmptyString
;
1373 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1374 return wxPGVariant_False
;
1375 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1376 return wxVariant(0.0);
1377 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1378 return wxVariant(wxArrayString());
1379 if ( valueType
== wxS("wxLongLong") )
1380 return WXVARIANT(wxLongLong(0));
1381 if ( valueType
== wxS("wxULongLong") )
1382 return WXVARIANT(wxULongLong(0));
1383 if ( valueType
== wxS("wxColour") )
1384 return WXVARIANT(*wxBLACK
);
1386 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1387 return wxVariant(wxDateTime::Now());
1389 if ( valueType
== wxS("wxFont") )
1390 return WXVARIANT(*wxNORMAL_FONT
);
1391 if ( valueType
== wxS("wxPoint") )
1392 return WXVARIANT(wxPoint(0, 0));
1393 if ( valueType
== wxS("wxSize") )
1394 return WXVARIANT(wxSize(0, 0));
1400 void wxPGProperty::EnsureCells( unsigned int column
)
1402 if ( column
>= m_cells
.size() )
1404 // Fill empty slots with default cells
1405 wxPropertyGrid
* pg
= GetGrid();
1406 wxPGCell defaultCell
;
1408 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1409 defaultCell
= pg
->GetPropertyDefaultCell();
1411 defaultCell
= pg
->GetCategoryDefaultCell();
1413 // TODO: Replace with resize() call
1414 unsigned int cellCountMax
= column
+1;
1416 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1417 m_cells
.push_back(defaultCell
);
1421 void wxPGProperty::SetCell( int column
,
1422 const wxPGCell
& cell
)
1424 EnsureCells(column
);
1426 m_cells
[column
] = cell
;
1429 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1430 unsigned int lastCol
,
1431 const wxPGCell
& cell
,
1432 const wxPGCell
& srcData
,
1433 wxPGCellData
* unmodCellData
,
1434 FlagType ignoreWithFlags
,
1438 // Sets cell in memory optimizing fashion. That is, if
1439 // current cell data matches unmodCellData, we will
1440 // simply get reference to data from cell. Otherwise,
1441 // cell information from srcData is merged into current.
1444 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1446 EnsureCells(lastCol
);
1448 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1450 if ( m_cells
[col
].GetData() == unmodCellData
)
1452 // Data matches... use cell directly
1453 m_cells
[col
] = cell
;
1457 // Data did not match... merge valid information
1458 m_cells
[col
].MergeFrom(srcData
);
1465 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1466 Item(i
)->AdaptiveSetCell( firstCol
,
1476 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1478 if ( m_cells
.size() > column
)
1479 return m_cells
[column
];
1481 wxPropertyGrid
* pg
= GetGrid();
1484 return pg
->GetCategoryDefaultCell();
1486 return pg
->GetPropertyDefaultCell();
1489 wxPGCell
& wxPGProperty::GetCell( unsigned int column
)
1491 EnsureCells(column
);
1492 return m_cells
[column
];
1495 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1498 wxPGProperty
* firstProp
= this;
1501 // If category is tried to set recursively, skip it and only
1502 // affect the children.
1505 while ( firstProp
->IsCategory() )
1507 if ( !firstProp
->GetChildCount() )
1509 firstProp
= firstProp
->Item(0);
1513 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1514 wxPGCellData
* firstCellData
= firstCell
.GetData();
1516 wxPGCell
newCell(firstCell
);
1517 newCell
.SetBgCol(colour
);
1519 srcCell
.SetBgCol(colour
);
1522 GetParentState()->GetColumnCount()-1,
1526 recursively
? wxPG_PROP_CATEGORY
: 0,
1530 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1533 wxPGProperty
* firstProp
= this;
1536 // If category is tried to set recursively, skip it and only
1537 // affect the children.
1540 while ( firstProp
->IsCategory() )
1542 if ( !firstProp
->GetChildCount() )
1544 firstProp
= firstProp
->Item(0);
1548 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1549 wxPGCellData
* firstCellData
= firstCell
.GetData();
1551 wxPGCell
newCell(firstCell
);
1552 newCell
.SetFgCol(colour
);
1554 srcCell
.SetFgCol(colour
);
1557 GetParentState()->GetColumnCount()-1,
1561 recursively
? wxPG_PROP_CATEGORY
: 0,
1565 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1570 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1575 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1577 if ( DoSetAttribute( name
, value
) )
1579 // Support working without grid, when possible
1580 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1584 m_attributes
.Set( name
, value
);
1587 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1589 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1592 while ( attributes
.GetNext(it
, variant
) )
1593 SetAttribute( variant
.GetName(), variant
);
1596 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1602 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1604 return m_attributes
.FindValue(name
);
1607 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1609 wxVariant variant
= m_attributes
.FindValue(name
);
1611 if ( !variant
.IsNull() )
1612 return variant
.GetString();
1617 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1619 wxVariant variant
= m_attributes
.FindValue(name
);
1621 return wxPGVariantToInt(variant
, defVal
);
1624 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1627 wxVariant variant
= m_attributes
.FindValue(name
);
1629 if ( wxPGVariantToDouble(variant
, &retVal
) )
1635 wxVariant
wxPGProperty::GetAttributesAsList() const
1637 wxVariantList tempList
;
1638 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1640 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1643 while ( m_attributes
.GetNext(it
, variant
) )
1649 // Slots of utility flags are NULL
1650 const unsigned int gs_propFlagToStringSize
= 14;
1652 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1669 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1672 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1676 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1678 if ( relevantFlags
& a
)
1680 const wxChar
* fs
= gs_propFlagToString
[i
];
1692 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1696 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1698 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1700 const wxChar
* fs
= gs_propFlagToString
[i
];
1701 if ( fs
&& str
== fs
)
1707 WX_PG_TOKENIZER1_END()
1709 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1712 wxValidator
* wxPGProperty::DoGetValidator() const
1714 return (wxValidator
*) NULL
;
1717 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1719 wxPropertyGrid
* pg
= GetGrid();
1720 int sel
= GetChoiceSelection();
1724 if ( index
== wxNOT_FOUND
)
1725 index
= m_choices
.GetCount();
1730 m_choices
.Insert(label
, index
, value
);
1732 if ( sel
!= newSel
)
1733 SetChoiceSelection(newSel
);
1735 if ( this == pg
->GetSelection() )
1736 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1742 void wxPGProperty::DeleteChoice( int index
)
1744 wxPropertyGrid
* pg
= GetGrid();
1746 int sel
= GetChoiceSelection();
1749 // Adjust current value
1752 SetValueToUnspecified();
1755 else if ( index
< sel
)
1760 m_choices
.RemoveAt(index
);
1762 if ( sel
!= newSel
)
1763 SetChoiceSelection(newSel
);
1765 if ( this == pg
->GetSelection() )
1766 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1769 int wxPGProperty::GetChoiceSelection() const
1771 wxVariant value
= GetValue();
1772 wxString valueType
= value
.GetType();
1773 int index
= wxNOT_FOUND
;
1775 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1778 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1780 index
= value
.GetLong();
1782 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1784 index
= m_choices
.Index(value
.GetString());
1786 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1788 index
= value
.GetBool()? 1 : 0;
1794 void wxPGProperty::SetChoiceSelection( int newValue
)
1796 // Changes value of a property with choices, but only
1797 // works if the value type is long or string.
1798 wxString valueType
= GetValue().GetType();
1800 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1802 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1804 SetValue( m_choices
.GetLabel(newValue
) );
1806 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1808 SetValue( (long) newValue
);
1812 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1814 m_choices
.Assign(choices
);
1817 // This may be needed to trigger some initialization
1818 // (but don't do it if property is somewhat uninitialized)
1819 wxVariant defVal
= GetDefaultValue();
1820 if ( defVal
.IsNull() )
1830 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1832 const wxPGEditor
* editor
;
1834 if ( !m_customEditor
)
1836 editor
= DoGetEditorClass();
1839 editor
= m_customEditor
;
1842 // Maybe override editor if common value specified
1843 if ( GetDisplayedCommonValueCount() )
1845 // TextCtrlAndButton -> ComboBoxAndButton
1846 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1847 editor
= wxPGEditor_ChoiceAndButton
;
1849 // TextCtrl -> ComboBox
1850 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1851 editor
= wxPGEditor_ComboBox
;
1857 bool wxPGProperty::HasVisibleChildren() const
1861 for ( i
=0; i
<GetChildCount(); i
++ )
1863 wxPGProperty
* child
= Item(i
);
1865 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1872 bool wxPGProperty::RecreateEditor()
1874 wxPropertyGrid
* pg
= GetGrid();
1877 wxPGProperty
* selected
= pg
->GetSelection();
1878 if ( this == selected
)
1880 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1887 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1889 delete m_valueBitmap
;
1891 if ( &bmp
&& bmp
.Ok() )
1894 wxSize maxSz
= GetGrid()->GetImageSize();
1895 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1897 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1899 // Create a memory DC
1900 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1903 dc
.SelectObject(*bmpNew
);
1906 // FIXME: This is ugly - use image or wait for scaling patch.
1907 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1908 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1910 dc
.SetUserScale(scaleX
,scaleY
);
1912 dc
.DrawBitmap( bmp
, 0, 0 );
1914 m_valueBitmap
= bmpNew
;
1918 m_valueBitmap
= new wxBitmap(bmp
);
1921 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1925 m_valueBitmap
= NULL
;
1926 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1931 wxPGProperty
* wxPGProperty::GetMainParent() const
1933 const wxPGProperty
* curChild
= this;
1934 const wxPGProperty
* curParent
= m_parent
;
1936 while ( curParent
&& !curParent
->IsCategory() )
1938 curChild
= curParent
;
1939 curParent
= curParent
->m_parent
;
1942 return (wxPGProperty
*) curChild
;
1946 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1949 // Returns last visible sub-item, recursively.
1950 if ( !IsExpanded() || !GetChildCount() )
1953 return Last()->GetLastVisibleSubItem();
1957 bool wxPGProperty::IsVisible() const
1959 const wxPGProperty
* parent
;
1961 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1964 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1966 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1973 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1975 wxPropertyGridPageState
* state
= GetParentState();
1976 wxPropertyGrid
* propGrid
= state
->GetGrid();
1977 if ( state
== propGrid
->GetState() )
1983 int wxPGProperty::GetY2( int lh
) const
1985 const wxPGProperty
* parent
;
1986 const wxPGProperty
* child
= this;
1990 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1992 if ( !parent
->IsExpanded() )
1994 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1999 y
-= lh
; // need to reduce one level
2005 int wxPGProperty::GetY() const
2007 return GetY2(GetGrid()->GetRowHeight());
2010 // This is used by Insert etc.
2011 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
2013 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2015 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2016 m_children
.push_back( prop
);
2020 m_children
.insert( m_children
.begin()+index
, prop
);
2021 if ( correct_mode
) FixIndicesOfChildren( index
);
2024 prop
->m_parent
= this;
2027 // This is used by properties that have fixed sub-properties
2028 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2030 wxASSERT_MSG( prop
->GetBaseName().length(),
2031 "Property's children must have unique, non-empty names within their scope" );
2033 prop
->m_arrIndex
= m_children
.size();
2034 m_children
.push_back( prop
);
2036 int custImgHeight
= prop
->OnMeasureImage().y
;
2037 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2038 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2040 prop
->m_parent
= this;
2043 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2045 wxArrayPGProperty::iterator it
;
2046 wxArrayPGProperty
& children
= m_children
;
2048 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2052 m_children
.erase(it
);
2058 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2060 wxASSERT( GetChildCount() );
2061 wxASSERT( !IsCategory() );
2063 *value
= GetValue();
2065 if ( !list
.GetCount() )
2068 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2070 bool allChildrenSpecified
;
2072 // Don't fully update aggregate properties unless all children have
2074 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2075 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2077 allChildrenSpecified
= true;
2079 wxVariant childValue
= list
[0];
2083 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2085 for ( i
=0; i
<GetChildCount(); i
++ )
2087 const wxPGProperty
* child
= Item(i
);
2089 if ( childValue
.GetName() == child
->GetBaseName() )
2091 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2093 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2095 wxVariant
cv2(child
->GetValue());
2096 child
->AdaptListToValue(childValue
, &cv2
);
2100 if ( allChildrenSpecified
)
2101 ChildChanged(*value
, i
, childValue
);
2103 if ( n
== (unsigned int)list
.GetCount() )
2105 childValue
= list
[n
];
2111 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2114 for ( i
=starthere
;i
<GetChildCount();i
++)
2115 Item(i
)->m_arrIndex
= i
;
2119 // Returns (direct) child property with given name (or NULL if not found)
2120 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2124 for ( i
=0; i
<GetChildCount(); i
++ )
2126 wxPGProperty
* p
= Item(i
);
2127 if ( p
->m_name
== name
)
2131 // Does it have point, then?
2132 int pos
= name
.Find(wxS('.'));
2134 return (wxPGProperty
*) NULL
;
2136 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2138 if ( !p
|| !p
->GetChildCount() )
2141 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2144 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2146 unsigned int i
= hintIndex
;
2148 if ( i
>= GetChildCount() )
2151 unsigned int lastIndex
= i
- 1;
2153 if ( lastIndex
>= GetChildCount() )
2154 lastIndex
= GetChildCount() - 1;
2158 wxPGProperty
* p
= Item(i
);
2159 if ( p
->m_name
== name
)
2162 if ( i
== lastIndex
)
2166 if ( i
== GetChildCount() )
2173 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2175 // Returns height of children, recursively, and
2176 // by taking expanded/collapsed status into account.
2178 // iMax is used when finding property y-positions.
2184 iMax_
= GetChildCount();
2186 unsigned int iMax
= iMax_
;
2188 wxASSERT( iMax
<= GetChildCount() );
2190 if ( !IsExpanded() && GetParent() )
2195 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2197 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2199 if ( !pwc
->IsExpanded() ||
2200 pwc
->GetChildCount() == 0 )
2203 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2212 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
2214 wxASSERT( nextItemY
);
2216 // Linear search at the moment
2218 // nextItemY = y of next visible property, final value will be written back.
2219 wxPGProperty
* result
= NULL
;
2220 wxPGProperty
* current
= NULL
;
2221 unsigned int iy
= *nextItemY
;
2223 unsigned int iMax
= GetChildCount();
2227 wxPGProperty
* pwc
= Item(i
);
2229 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2240 if ( pwc
->IsExpanded() &&
2241 pwc
->GetChildCount() > 0 )
2243 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2255 if ( !result
&& y
< iy
)
2262 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2264 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2267 return (wxPGProperty
*) result
;
2270 void wxPGProperty::Empty()
2273 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2275 for ( i
=0; i
<GetChildCount(); i
++ )
2277 delete m_children
[i
];
2284 void wxPGProperty::DeleteChildren()
2286 wxPropertyGridPageState
* state
= m_parentState
;
2288 while ( GetChildCount() )
2290 wxPGProperty
* child
= Item(GetChildCount()-1);
2291 state
->DoDelete(child
, true);
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