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 if ( tokenStart
!= 0xFFFFFF )
978 if ( a
== delimeter
|| a
== 0 )
980 token
= text
.substr(tokenStart
,pos
-tokenStart
);
982 size_t len
= token
.length();
984 if ( !addOnlyIfNotEmpty
|| len
> 0 )
986 const wxPGProperty
* child
= Item(curChild
);
987 wxVariant
variant(child
->GetValue());
988 variant
.SetName(child
->GetBaseName());
992 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().c_str());
995 // Add only if editable or setting programmatically
996 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
997 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1001 if ( child
->StringToValue(variant
, token
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1003 list
.Append(variant
);
1010 // Empty, becomes unspecified
1012 list
.Append(variant
);
1018 if ( curChild
>= iMax
)
1022 tokenStart
= 0xFFFFFF;
1027 // Token is not running
1028 if ( a
!= wxS(' ') )
1031 addOnlyIfNotEmpty
= false;
1033 // Is this a group of tokens?
1034 if ( a
== wxS('[') )
1038 if ( it
!= text
.end() ) ++it
;
1040 size_t startPos
= pos
;
1042 // Group item - find end
1043 while ( it
!= text
.end() && depth
> 0 )
1049 if ( a
== wxS(']') )
1051 else if ( a
== wxS('[') )
1055 token
= text
.substr(startPos
,pos
-startPos
-1);
1057 if ( !token
.length() )
1060 const wxPGProperty
* child
= Item(curChild
);
1062 wxVariant oldChildValue
= child
->GetValue();
1063 wxVariant
variant(oldChildValue
);
1065 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1066 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1068 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
1069 if ( stvRes
|| (variant
!= oldChildValue
) )
1076 // Failed, becomes unspecified
1082 variant
.SetName(child
->GetBaseName());
1083 list
.Append(variant
);
1086 if ( curChild
>= iMax
)
1089 addOnlyIfNotEmpty
= true;
1091 tokenStart
= 0xFFFFFF;
1097 if ( a
== delimeter
)
1110 if ( it
!= text
.end() )
1127 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1129 wxVariant
variant(m_value
);
1130 bool res
= StringToValue(variant
, text
, argFlags
);
1136 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1138 wxVariant
variant(m_value
);
1139 bool res
= IntToValue(variant
, number
, argFlags
);
1145 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1147 if ( m_valueBitmap
)
1148 return wxSize(m_valueBitmap
->GetWidth(),-1);
1153 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1155 return wxPGGlobalVars
->m_defaultRenderer
;
1158 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1162 wxBitmap
* bmp
= m_valueBitmap
;
1164 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1166 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1168 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1171 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1173 return wxPGEditor_TextCtrl
;
1176 // Default extra property event handling - that is, none at all.
1177 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1183 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1185 // If auto unspecified values are not wanted (via window or property style),
1186 // then get default value instead of wxNullVariant.
1187 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1188 !UsesAutoUnspecified() )
1190 value
= GetDefaultValue();
1193 if ( !value
.IsNull() )
1195 wxVariant tempListVariant
;
1198 // List variants are reserved a special purpose
1199 // as intermediate containers for child values
1200 // of properties with children.
1201 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1204 // However, situation is different for composed string properties
1205 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1207 tempListVariant
= value
;
1208 pList
= &tempListVariant
;
1212 AdaptListToValue(value
, &newValue
);
1214 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1217 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1218 flags
|= wxPG_SETVAL_AGGREGATED
;
1220 if ( pList
&& !pList
->IsNull() )
1222 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1223 wxASSERT( GetChildCount() );
1224 wxASSERT( !IsCategory() );
1226 wxVariantList
& list
= pList
->GetList();
1227 wxVariantList::iterator node
;
1230 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1232 // Children in list can be in any order, but we will give hint to
1233 // GetPropertyByNameWH(). This optimizes for full list parsing.
1234 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1236 wxVariant
& childValue
= *((wxVariant
*)*node
);
1237 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1240 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1241 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1243 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1245 wxVariant listRefCopy
= childValue
;
1246 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1250 wxVariant oldVal
= child
->GetValue();
1251 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1254 else if ( child
->GetValue() != childValue
)
1256 // For aggregate properties, we will trust RefreshChildren()
1257 // to update child values.
1258 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1259 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1260 if ( flags
& wxPG_SETVAL_BY_USER
)
1261 child
->SetFlag(wxPG_PROP_MODIFIED
);
1268 if ( !value
.IsNull() )
1273 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1274 UpdateParentValues();
1277 if ( flags
& wxPG_SETVAL_BY_USER
)
1278 SetFlag(wxPG_PROP_MODIFIED
);
1280 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1285 if ( m_commonValue
!= -1 )
1287 wxPropertyGrid
* pg
= GetGrid();
1288 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1294 // Set children to unspecified, but only if aggregate or
1295 // value is <composed>
1296 if ( AreChildrenComponents() )
1299 for ( i
=0; i
<GetChildCount(); i
++ )
1300 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1305 // Update editor control
1308 // We need to check for these, otherwise GetGrid() may fail.
1309 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1314 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1316 GetGrid()->ValueChangeInEvent(value
);
1319 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1327 for ( i
= 0; i
< GetChildCount(); i
++ )
1328 Item(i
)->SetFlagRecursively(flag
, set
);
1331 void wxPGProperty::RefreshEditor()
1336 wxPropertyGrid
* pg
= GetGrid();
1337 if ( pg
&& pg
->GetSelectedProperty() == this )
1338 pg
->RefreshEditor();
1341 wxVariant
wxPGProperty::GetDefaultValue() const
1343 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1344 if ( !defVal
.IsNull() )
1347 wxVariant value
= GetValue();
1349 if ( !value
.IsNull() )
1351 wxString
valueType(value
.GetType());
1353 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1354 return wxPGVariant_Zero
;
1355 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1356 return wxPGVariant_EmptyString
;
1357 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1358 return wxPGVariant_False
;
1359 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1360 return wxVariant(0.0);
1361 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1362 return wxVariant(wxArrayString());
1363 if ( valueType
== wxS("wxLongLong") )
1364 return WXVARIANT(wxLongLong(0));
1365 if ( valueType
== wxS("wxULongLong") )
1366 return WXVARIANT(wxULongLong(0));
1367 if ( valueType
== wxS("wxColour") )
1368 return WXVARIANT(*wxBLACK
);
1370 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1371 return wxVariant(wxDateTime::Now());
1373 if ( valueType
== wxS("wxFont") )
1374 return WXVARIANT(*wxNORMAL_FONT
);
1375 if ( valueType
== wxS("wxPoint") )
1376 return WXVARIANT(wxPoint(0, 0));
1377 if ( valueType
== wxS("wxSize") )
1378 return WXVARIANT(wxSize(0, 0));
1384 void wxPGProperty::EnsureCells( unsigned int column
)
1386 if ( column
>= m_cells
.size() )
1388 // Fill empty slots with default cells
1389 wxPropertyGrid
* pg
= GetGrid();
1390 wxPGCell defaultCell
;
1392 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1393 defaultCell
= pg
->GetPropertyDefaultCell();
1395 defaultCell
= pg
->GetCategoryDefaultCell();
1397 // TODO: Replace with resize() call
1398 unsigned int cellCountMax
= column
+1;
1400 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1401 m_cells
.push_back(defaultCell
);
1405 void wxPGProperty::SetCell( int column
,
1406 const wxPGCell
& cell
)
1408 EnsureCells(column
);
1410 m_cells
[column
] = cell
;
1413 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1414 unsigned int lastCol
,
1415 const wxPGCell
& cell
,
1416 const wxPGCell
& srcData
,
1417 wxPGCellData
* unmodCellData
,
1418 FlagType ignoreWithFlags
,
1422 // Sets cell in memory optimizing fashion. That is, if
1423 // current cell data matches unmodCellData, we will
1424 // simply get reference to data from cell. Otherwise,
1425 // cell information from srcData is merged into current.
1428 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1430 EnsureCells(lastCol
);
1432 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1434 if ( m_cells
[col
].GetData() == unmodCellData
)
1436 // Data matches... use cell directly
1437 m_cells
[col
] = cell
;
1441 // Data did not match... merge valid information
1442 m_cells
[col
].MergeFrom(srcData
);
1449 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1450 Item(i
)->AdaptiveSetCell( firstCol
,
1460 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1462 if ( m_cells
.size() > column
)
1463 return m_cells
[column
];
1465 wxPropertyGrid
* pg
= GetGrid();
1468 return pg
->GetCategoryDefaultCell();
1470 return pg
->GetPropertyDefaultCell();
1473 wxPGCell
& wxPGProperty::GetCell( unsigned int column
)
1475 EnsureCells(column
);
1476 return m_cells
[column
];
1479 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1482 wxPGProperty
* firstProp
= this;
1485 // If category is tried to set recursively, skip it and only
1486 // affect the children.
1489 while ( firstProp
->IsCategory() )
1491 if ( !firstProp
->GetChildCount() )
1493 firstProp
= firstProp
->Item(0);
1497 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1498 wxPGCellData
* firstCellData
= firstCell
.GetData();
1500 wxPGCell
newCell(firstCell
);
1501 newCell
.SetBgCol(colour
);
1503 srcCell
.SetBgCol(colour
);
1506 GetParentState()->GetColumnCount()-1,
1510 recursively
? wxPG_PROP_CATEGORY
: 0,
1514 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1517 wxPGProperty
* firstProp
= this;
1520 // If category is tried to set recursively, skip it and only
1521 // affect the children.
1524 while ( firstProp
->IsCategory() )
1526 if ( !firstProp
->GetChildCount() )
1528 firstProp
= firstProp
->Item(0);
1532 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1533 wxPGCellData
* firstCellData
= firstCell
.GetData();
1535 wxPGCell
newCell(firstCell
);
1536 newCell
.SetFgCol(colour
);
1538 srcCell
.SetFgCol(colour
);
1541 GetParentState()->GetColumnCount()-1,
1545 recursively
? wxPG_PROP_CATEGORY
: 0,
1549 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1554 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1559 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1561 if ( DoSetAttribute( name
, value
) )
1563 // Support working without grid, when possible
1564 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1568 m_attributes
.Set( name
, value
);
1571 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1573 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1576 while ( attributes
.GetNext(it
, variant
) )
1577 SetAttribute( variant
.GetName(), variant
);
1580 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1586 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1588 return m_attributes
.FindValue(name
);
1591 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1593 wxVariant variant
= m_attributes
.FindValue(name
);
1595 if ( !variant
.IsNull() )
1596 return variant
.GetString();
1601 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1603 wxVariant variant
= m_attributes
.FindValue(name
);
1605 return wxPGVariantToInt(variant
, defVal
);
1608 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1611 wxVariant variant
= m_attributes
.FindValue(name
);
1613 if ( wxPGVariantToDouble(variant
, &retVal
) )
1619 wxVariant
wxPGProperty::GetAttributesAsList() const
1621 wxVariantList tempList
;
1622 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1624 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1627 while ( m_attributes
.GetNext(it
, variant
) )
1633 // Slots of utility flags are NULL
1634 const unsigned int gs_propFlagToStringSize
= 14;
1636 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1653 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1656 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1660 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1662 if ( relevantFlags
& a
)
1664 const wxChar
* fs
= gs_propFlagToString
[i
];
1676 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1680 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1682 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1684 const wxChar
* fs
= gs_propFlagToString
[i
];
1685 if ( fs
&& str
== fs
)
1691 WX_PG_TOKENIZER1_END()
1693 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1696 wxValidator
* wxPGProperty::DoGetValidator() const
1698 return (wxValidator
*) NULL
;
1701 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1703 wxPropertyGrid
* pg
= GetGrid();
1704 int sel
= GetChoiceSelection();
1708 if ( index
== wxNOT_FOUND
)
1709 index
= m_choices
.GetCount();
1714 m_choices
.Insert(label
, index
, value
);
1716 if ( sel
!= newSel
)
1717 SetChoiceSelection(newSel
);
1719 if ( this == pg
->GetSelection() )
1720 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1726 void wxPGProperty::DeleteChoice( int index
)
1728 wxPropertyGrid
* pg
= GetGrid();
1730 int sel
= GetChoiceSelection();
1733 // Adjust current value
1736 SetValueToUnspecified();
1739 else if ( index
< sel
)
1744 m_choices
.RemoveAt(index
);
1746 if ( sel
!= newSel
)
1747 SetChoiceSelection(newSel
);
1749 if ( this == pg
->GetSelection() )
1750 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1753 int wxPGProperty::GetChoiceSelection() const
1755 wxVariant value
= GetValue();
1756 wxString valueType
= value
.GetType();
1757 int index
= wxNOT_FOUND
;
1759 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1762 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1764 index
= value
.GetLong();
1766 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1768 index
= m_choices
.Index(value
.GetString());
1770 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1772 index
= value
.GetBool()? 1 : 0;
1778 void wxPGProperty::SetChoiceSelection( int newValue
)
1780 // Changes value of a property with choices, but only
1781 // works if the value type is long or string.
1782 wxString valueType
= GetValue().GetType();
1784 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1786 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1788 SetValue( m_choices
.GetLabel(newValue
) );
1790 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1792 SetValue( (long) newValue
);
1796 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1798 m_choices
.Assign(choices
);
1801 // This may be needed to trigger some initialization
1802 // (but don't do it if property is somewhat uninitialized)
1803 wxVariant defVal
= GetDefaultValue();
1804 if ( defVal
.IsNull() )
1814 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1816 const wxPGEditor
* editor
;
1818 if ( !m_customEditor
)
1820 editor
= DoGetEditorClass();
1823 editor
= m_customEditor
;
1826 // Maybe override editor if common value specified
1827 if ( GetDisplayedCommonValueCount() )
1829 // TextCtrlAndButton -> ComboBoxAndButton
1830 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1831 editor
= wxPGEditor_ChoiceAndButton
;
1833 // TextCtrl -> ComboBox
1834 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1835 editor
= wxPGEditor_ComboBox
;
1841 bool wxPGProperty::HasVisibleChildren() const
1845 for ( i
=0; i
<GetChildCount(); i
++ )
1847 wxPGProperty
* child
= Item(i
);
1849 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1856 bool wxPGProperty::RecreateEditor()
1858 wxPropertyGrid
* pg
= GetGrid();
1861 wxPGProperty
* selected
= pg
->GetSelection();
1862 if ( this == selected
)
1864 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1871 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1873 delete m_valueBitmap
;
1875 if ( &bmp
&& bmp
.Ok() )
1878 wxSize maxSz
= GetGrid()->GetImageSize();
1879 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1881 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1883 // Create a memory DC
1884 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1887 dc
.SelectObject(*bmpNew
);
1890 // FIXME: This is ugly - use image or wait for scaling patch.
1891 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1892 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1894 dc
.SetUserScale(scaleX
,scaleY
);
1896 dc
.DrawBitmap( bmp
, 0, 0 );
1898 m_valueBitmap
= bmpNew
;
1902 m_valueBitmap
= new wxBitmap(bmp
);
1905 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1909 m_valueBitmap
= NULL
;
1910 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1915 wxPGProperty
* wxPGProperty::GetMainParent() const
1917 const wxPGProperty
* curChild
= this;
1918 const wxPGProperty
* curParent
= m_parent
;
1920 while ( curParent
&& !curParent
->IsCategory() )
1922 curChild
= curParent
;
1923 curParent
= curParent
->m_parent
;
1926 return (wxPGProperty
*) curChild
;
1930 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1933 // Returns last visible sub-item, recursively.
1934 if ( !IsExpanded() || !GetChildCount() )
1937 return Last()->GetLastVisibleSubItem();
1941 bool wxPGProperty::IsVisible() const
1943 const wxPGProperty
* parent
;
1945 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1948 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1950 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1957 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1959 wxPropertyGridPageState
* state
= GetParentState();
1960 wxPropertyGrid
* propGrid
= state
->GetGrid();
1961 if ( state
== propGrid
->GetState() )
1967 int wxPGProperty::GetY2( int lh
) const
1969 const wxPGProperty
* parent
;
1970 const wxPGProperty
* child
= this;
1974 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1976 if ( !parent
->IsExpanded() )
1978 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1983 y
-= lh
; // need to reduce one level
1989 int wxPGProperty::GetY() const
1991 return GetY2(GetGrid()->GetRowHeight());
1994 // This is used by Insert etc.
1995 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
1997 if ( index
< 0 || (size_t)index
>= m_children
.size() )
1999 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2000 m_children
.push_back( prop
);
2004 m_children
.insert( m_children
.begin()+index
, prop
);
2005 if ( correct_mode
) FixIndicesOfChildren( index
);
2008 prop
->m_parent
= this;
2011 // This is used by properties that have fixed sub-properties
2012 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2014 wxASSERT_MSG( prop
->GetBaseName().length(),
2015 "Property's children must have unique, non-empty names within their scope" );
2017 prop
->m_arrIndex
= m_children
.size();
2018 m_children
.push_back( prop
);
2020 int custImgHeight
= prop
->OnMeasureImage().y
;
2021 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2022 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2024 prop
->m_parent
= this;
2027 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2029 wxArrayPGProperty::iterator it
;
2030 wxArrayPGProperty
& children
= m_children
;
2032 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2036 m_children
.erase(it
);
2042 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2044 wxASSERT( GetChildCount() );
2045 wxASSERT( !IsCategory() );
2047 *value
= GetValue();
2049 if ( !list
.GetCount() )
2052 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2054 bool allChildrenSpecified
;
2056 // Don't fully update aggregate properties unless all children have
2058 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2059 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2061 allChildrenSpecified
= true;
2063 wxVariant childValue
= list
[0];
2067 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2069 for ( i
=0; i
<GetChildCount(); i
++ )
2071 const wxPGProperty
* child
= Item(i
);
2073 if ( childValue
.GetName() == child
->GetBaseName() )
2075 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2077 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2079 wxVariant
cv2(child
->GetValue());
2080 child
->AdaptListToValue(childValue
, &cv2
);
2084 if ( allChildrenSpecified
)
2085 ChildChanged(*value
, i
, childValue
);
2087 if ( n
== (unsigned int)list
.GetCount() )
2089 childValue
= list
[n
];
2095 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2098 for ( i
=starthere
;i
<GetChildCount();i
++)
2099 Item(i
)->m_arrIndex
= i
;
2103 // Returns (direct) child property with given name (or NULL if not found)
2104 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2108 for ( i
=0; i
<GetChildCount(); i
++ )
2110 wxPGProperty
* p
= Item(i
);
2111 if ( p
->m_name
== name
)
2115 // Does it have point, then?
2116 int pos
= name
.Find(wxS('.'));
2118 return (wxPGProperty
*) NULL
;
2120 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2122 if ( !p
|| !p
->GetChildCount() )
2125 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2128 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2130 unsigned int i
= hintIndex
;
2132 if ( i
>= GetChildCount() )
2135 unsigned int lastIndex
= i
- 1;
2137 if ( lastIndex
>= GetChildCount() )
2138 lastIndex
= GetChildCount() - 1;
2142 wxPGProperty
* p
= Item(i
);
2143 if ( p
->m_name
== name
)
2146 if ( i
== lastIndex
)
2150 if ( i
== GetChildCount() )
2157 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2159 // Returns height of children, recursively, and
2160 // by taking expanded/collapsed status into account.
2162 // iMax is used when finding property y-positions.
2168 iMax_
= GetChildCount();
2170 unsigned int iMax
= iMax_
;
2172 wxASSERT( iMax
<= GetChildCount() );
2174 if ( !IsExpanded() && GetParent() )
2179 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2181 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2183 if ( !pwc
->IsExpanded() ||
2184 pwc
->GetChildCount() == 0 )
2187 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2196 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
2198 wxASSERT( nextItemY
);
2200 // Linear search at the moment
2202 // nextItemY = y of next visible property, final value will be written back.
2203 wxPGProperty
* result
= NULL
;
2204 wxPGProperty
* current
= NULL
;
2205 unsigned int iy
= *nextItemY
;
2207 unsigned int iMax
= GetChildCount();
2211 wxPGProperty
* pwc
= Item(i
);
2213 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2224 if ( pwc
->IsExpanded() &&
2225 pwc
->GetChildCount() > 0 )
2227 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2239 if ( !result
&& y
< iy
)
2246 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2248 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2251 return (wxPGProperty
*) result
;
2254 void wxPGProperty::Empty()
2257 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2259 for ( i
=0; i
<GetChildCount(); i
++ )
2261 delete m_children
[i
];
2268 void wxPGProperty::DeleteChildren()
2270 wxPropertyGridPageState
* state
= m_parentState
;
2272 while ( GetChildCount() )
2274 wxPGProperty
* child
= Item(GetChildCount()-1);
2275 state
->DoDelete(child
, true);
2279 void wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2280 int WXUNUSED(childIndex
),
2281 wxVariant
& WXUNUSED(childValue
) ) const
2285 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2289 const wxVariantList
* pList
= NULL
;
2290 wxVariantList::const_iterator node
;
2294 pList
= &pendingList
->GetList();
2295 node
= pList
->begin();
2298 for ( i
=0; i
<GetChildCount(); i
++ )
2300 wxPGProperty
* child
= Item(i
);
2301 const wxVariant
* listValue
= NULL
;
2306 const wxString
& childName
= child
->GetBaseName();
2308 for ( ; node
!= pList
->end(); ++node
)
2310 const wxVariant
& item
= *((const wxVariant
*)*node
);
2311 if ( item
.GetName() == childName
)
2321 value
= child
->GetValue();
2323 if ( value
.IsNull() )
2326 // Check recursively
2327 if ( child
->GetChildCount() )
2329 const wxVariant
* childList
= NULL
;
2331 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2332 childList
= listValue
;
2334 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2342 wxPGProperty
* wxPGProperty::UpdateParentValues()
2344 wxPGProperty
* parent
= m_parent
;
2345 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2346 !parent
->IsCategory() && !parent
->IsRoot() )
2349 parent
->DoGenerateComposedValue(s
);
2350 parent
->m_value
= s
;
2351 return parent
->UpdateParentValues();
2356 bool wxPGProperty::IsTextEditable() const
2358 if ( HasFlag(wxPG_PROP_READONLY
) )
2361 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2363 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2370 // Call after fixed sub-properties added/removed after creation.
2371 // if oldSelInd >= 0 and < new max items, then selection is
2372 // moved to it. Note: oldSelInd -2 indicates that this property
2373 // should be selected.
2374 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2376 wxPropertyGridPageState
* state
= GetParentState();
2377 wxPropertyGrid
* grid
= state
->GetGrid();
2380 // Re-repare children (recursively)
2381 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2383 wxPGProperty
* child
= Item(i
);
2384 child
->InitAfterAdded(state
, grid
);
2387 wxPGProperty
* sel
= (wxPGProperty
*) NULL
;
2388 if ( oldSelInd
>= (int)m_children
.size() )
2389 oldSelInd
= (int)m_children
.size() - 1;
2391 if ( oldSelInd
>= 0 )
2392 sel
= m_children
[oldSelInd
];
2393 else if ( oldSelInd
== -2 )
2397 state
->DoSelectProperty(sel
);
2399 if ( state
== grid
->GetState() )
2401 grid
->GetPanel()->Refresh();
2405 // -----------------------------------------------------------------------
2407 // -----------------------------------------------------------------------
2409 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2410 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2413 wxPGRootProperty::wxPGRootProperty()
2417 m_name
= wxS("<root>");
2424 wxPGRootProperty::~wxPGRootProperty()
2429 // -----------------------------------------------------------------------
2430 // wxPropertyCategory
2431 // -----------------------------------------------------------------------
2433 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2434 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2436 void wxPropertyCategory::Init()
2438 // don't set colour - prepareadditem method should do this
2439 SetParentalType(wxPG_PROP_CATEGORY
);
2440 m_capFgColIndex
= 1;
2444 wxPropertyCategory::wxPropertyCategory()
2451 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2452 : wxPGProperty(label
,name
)
2458 wxPropertyCategory::~wxPropertyCategory()
2463 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2464 int WXUNUSED(argFlags
) ) const
2466 return wxEmptyString
;
2469 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2471 if ( m_textExtent
> 0 )
2472 return m_textExtent
;
2474 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2478 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2481 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2485 // -----------------------------------------------------------------------
2486 // wxPGAttributeStorage
2487 // -----------------------------------------------------------------------
2489 wxPGAttributeStorage::wxPGAttributeStorage()
2493 wxPGAttributeStorage::~wxPGAttributeStorage()
2495 wxPGHashMapS2P::iterator it
;
2497 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
2499 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2504 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2506 wxVariantData
* data
= value
.GetData();
2509 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2510 if ( it
!= m_map
.end() )
2512 ((wxVariantData
*)it
->second
)->DecRef();
2516 // If Null variant, just remove from set
2530 #endif // wxUSE_PROPGRID