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 void wxPGProperty::UpdateControl( wxWindow
* primary
)
645 GetEditorClass()->UpdateControl(this, primary
);
648 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
653 void wxPGProperty::OnSetValue()
657 void wxPGProperty::RefreshChildren ()
661 void wxPGProperty::GetDisplayInfo( unsigned int column
,
665 const wxPGCell
** pCell
)
667 const wxPGCell
* cell
= NULL
;
669 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
671 // Not painting listi of choice popups, so get text from property
672 cell
= &GetCell(column
);
673 if ( cell
->HasText() )
675 *pString
= cell
->GetText();
680 *pString
= GetLabel();
681 else if ( column
== 1 )
682 *pString
= GetDisplayedString();
683 else if ( column
== 2 )
684 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
689 wxASSERT( column
== 1 );
691 if ( choiceIndex
!= wxNOT_FOUND
)
693 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
694 if ( entry
.GetBitmap().IsOk() ||
695 entry
.GetFgCol().IsOk() ||
696 entry
.GetBgCol().IsOk() )
698 *pString
= m_choices
.GetLabel(choiceIndex
);
703 cell
= &GetCell(column
);
705 wxASSERT_MSG( cell
->GetData(),
706 wxString::Format("Invalid cell for property %s",
707 GetName().c_str()) );
713 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
716 if ( col != 1 || choiceIndex == wxNOT_FOUND )
718 const wxPGCell& cell = GetCell(col);
719 if ( cell->HasText() )
721 return cell->GetText();
728 return GetDisplayedString();
730 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
736 return m_choices.GetLabel(choiceIndex);
739 return wxEmptyString;
743 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
745 const wxVariantList
* valueOverrides
,
746 wxPGHashMapS2S
* childResults
) const
749 int iMax
= m_children
.size();
755 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
756 !(argFlags
& wxPG_FULL_VALUE
) )
757 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
759 int iMaxMinusOne
= iMax
-1;
761 if ( !IsTextEditable() )
762 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
764 wxPGProperty
* curChild
= m_children
[0];
766 bool overridesLeft
= false;
767 wxVariant overrideValue
;
768 wxVariantList::const_iterator node
;
770 if ( valueOverrides
)
772 node
= valueOverrides
->begin();
773 if ( node
!= valueOverrides
->end() )
775 overrideValue
= *node
;
776 overridesLeft
= true;
780 for ( i
= 0; i
< iMax
; i
++ )
782 wxVariant childValue
;
784 wxString childLabel
= curChild
->GetLabel();
786 // Check for value override
787 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
789 if ( !overrideValue
.IsNull() )
790 childValue
= overrideValue
;
792 childValue
= curChild
->GetValue();
794 if ( node
!= valueOverrides
->end() )
795 overrideValue
= *node
;
797 overridesLeft
= false;
801 childValue
= curChild
->GetValue();
805 if ( !childValue
.IsNull() )
807 if ( overridesLeft
&&
808 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
809 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
811 wxVariantList
& childList
= childValue
.GetList();
812 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
813 &childList
, childResults
);
817 s
= curChild
->ValueToString(childValue
,
818 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
822 if ( childResults
&& curChild
->GetChildCount() )
823 (*childResults
)[curChild
->GetName()] = s
;
826 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
829 if ( !curChild
->GetChildCount() || skip
)
832 text
+= wxS("[") + s
+ wxS("]");
834 if ( i
< iMaxMinusOne
)
836 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
837 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
838 !(argFlags
& wxPG_FULL_VALUE
) )
843 if ( !curChild
->GetChildCount() )
849 curChild
= m_children
[i
+1];
853 if ( (unsigned int)i
< m_children
.size() )
855 if ( !text
.EndsWith(wxS("; ")) )
856 text
+= wxS("; ...");
862 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
865 wxCHECK_MSG( GetChildCount() > 0,
867 "If user property does not have any children, it must "
868 "override GetValueAsString" );
870 // FIXME: Currently code below only works if value is actually m_value
871 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
872 "Sorry, currently default wxPGProperty::ValueToString() "
873 "implementation only works if value is m_value." );
876 DoGenerateComposedValue(text
, argFlags
);
880 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
882 #if wxPG_COMPATIBILITY_1_4
883 // This is backwards compatibility test
884 // That is, to make sure this function is not overridden
885 // (instead, ValueToString() should be).
886 if ( argFlags
== 0xFFFF )
888 // Do not override! (for backwards compliancy)
889 return g_invalidStringContent
;
893 if ( IsValueUnspecified() )
894 return wxEmptyString
;
896 if ( m_commonValue
== -1 )
898 wxVariant
value(GetValue());
899 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
903 // Return common value's string representation
904 wxPropertyGrid
* pg
= GetGrid();
905 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
907 if ( argFlags
& wxPG_FULL_VALUE
)
909 return cv
->GetLabel();
911 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
913 return cv
->GetEditableText();
917 return cv
->GetLabel();
921 wxString
wxPGProperty::GetValueString( int argFlags
) const
923 return GetValueAsString(argFlags
);
926 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
928 variant
= (long)number
;
932 // Convert semicolon delimited tokens into child values.
933 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
935 if ( !GetChildCount() )
938 unsigned int curChild
= 0;
940 unsigned int iMax
= m_children
.size();
942 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
943 !(argFlags
& wxPG_FULL_VALUE
) )
944 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
946 bool changed
= false;
951 // Its best only to add non-empty group items
952 bool addOnlyIfNotEmpty
= false;
953 const wxChar delimeter
= wxS(';');
955 size_t tokenStart
= 0xFFFFFF;
957 wxVariantList temp_list
;
958 wxVariant
list(temp_list
);
960 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
963 bool debug_print
= false;
968 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text
.c_str());
971 wxString::const_iterator it
= text
.begin();
974 if ( it
!= text
.end() )
981 if ( tokenStart
!= 0xFFFFFF )
984 if ( a
== delimeter
|| a
== 0 )
986 token
= text
.substr(tokenStart
,pos
-tokenStart
);
988 size_t len
= token
.length();
990 if ( !addOnlyIfNotEmpty
|| len
> 0 )
992 const wxPGProperty
* child
= Item(curChild
);
993 wxVariant
variant(child
->GetValue());
994 variant
.SetName(child
->GetBaseName());
998 wxLogDebug(wxT("token = '%s', child = %s"),token
.c_str(),child
->GetLabel().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
, propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1009 list
.Append(variant
);
1016 // Empty, becomes unspecified
1018 list
.Append(variant
);
1024 if ( curChild
>= iMax
)
1028 tokenStart
= 0xFFFFFF;
1033 // Token is not running
1034 if ( a
!= wxS(' ') )
1037 addOnlyIfNotEmpty
= false;
1039 // Is this a group of tokens?
1040 if ( a
== wxS('[') )
1044 if ( it
!= text
.end() ) ++it
;
1046 size_t startPos
= pos
;
1048 // Group item - find end
1049 while ( it
!= text
.end() && depth
> 0 )
1055 if ( a
== wxS(']') )
1057 else if ( a
== wxS('[') )
1061 token
= text
.substr(startPos
,pos
-startPos
-1);
1063 if ( !token
.length() )
1066 const wxPGProperty
* child
= Item(curChild
);
1068 wxVariant oldChildValue
= child
->GetValue();
1069 wxVariant
variant(oldChildValue
);
1071 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1072 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1074 bool stvRes
= child
->StringToValue( variant
, token
, propagatedFlags
);
1075 if ( stvRes
|| (variant
!= oldChildValue
) )
1082 // Failed, becomes unspecified
1088 variant
.SetName(child
->GetBaseName());
1089 list
.Append(variant
);
1092 if ( curChild
>= iMax
)
1095 addOnlyIfNotEmpty
= true;
1097 tokenStart
= 0xFFFFFF;
1103 if ( a
== delimeter
)
1116 if ( it
!= text
.end() )
1133 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1135 wxVariant
variant(m_value
);
1136 bool res
= StringToValue(variant
, text
, argFlags
);
1142 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1144 wxVariant
variant(m_value
);
1145 bool res
= IntToValue(variant
, number
, argFlags
);
1151 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1153 if ( m_valueBitmap
)
1154 return wxSize(m_valueBitmap
->GetWidth(),-1);
1159 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1161 return wxPGGlobalVars
->m_defaultRenderer
;
1164 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1168 wxBitmap
* bmp
= m_valueBitmap
;
1170 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1172 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1174 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1177 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1179 return wxPGEditor_TextCtrl
;
1182 // Default extra property event handling - that is, none at all.
1183 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1189 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1191 // If auto unspecified values are not wanted (via window or property style),
1192 // then get default value instead of wxNullVariant.
1193 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1194 !UsesAutoUnspecified() )
1196 value
= GetDefaultValue();
1199 if ( !value
.IsNull() )
1201 wxVariant tempListVariant
;
1204 // List variants are reserved a special purpose
1205 // as intermediate containers for child values
1206 // of properties with children.
1207 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1210 // However, situation is different for composed string properties
1211 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1213 tempListVariant
= value
;
1214 pList
= &tempListVariant
;
1218 AdaptListToValue(value
, &newValue
);
1220 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1223 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1224 flags
|= wxPG_SETVAL_AGGREGATED
;
1226 if ( pList
&& !pList
->IsNull() )
1228 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1229 wxASSERT( GetChildCount() );
1230 wxASSERT( !IsCategory() );
1232 wxVariantList
& list
= pList
->GetList();
1233 wxVariantList::iterator node
;
1236 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1238 // Children in list can be in any order, but we will give hint to
1239 // GetPropertyByNameWH(). This optimizes for full list parsing.
1240 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1242 wxVariant
& childValue
= *((wxVariant
*)*node
);
1243 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1246 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1247 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1249 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1251 wxVariant listRefCopy
= childValue
;
1252 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1256 wxVariant oldVal
= child
->GetValue();
1257 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1260 else if ( child
->GetValue() != childValue
)
1262 // For aggregate properties, we will trust RefreshChildren()
1263 // to update child values.
1264 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1265 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1266 if ( flags
& wxPG_SETVAL_BY_USER
)
1267 child
->SetFlag(wxPG_PROP_MODIFIED
);
1274 if ( !value
.IsNull() )
1279 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1280 UpdateParentValues();
1283 if ( flags
& wxPG_SETVAL_BY_USER
)
1284 SetFlag(wxPG_PROP_MODIFIED
);
1286 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1291 if ( m_commonValue
!= -1 )
1293 wxPropertyGrid
* pg
= GetGrid();
1294 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1300 // Set children to unspecified, but only if aggregate or
1301 // value is <composed>
1302 if ( AreChildrenComponents() )
1305 for ( i
=0; i
<GetChildCount(); i
++ )
1306 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1311 // Update editor control
1314 // We need to check for these, otherwise GetGrid() may fail.
1315 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1320 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1322 GetGrid()->ValueChangeInEvent(value
);
1325 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1333 for ( i
= 0; i
< GetChildCount(); i
++ )
1334 Item(i
)->SetFlagRecursively(flag
, set
);
1337 void wxPGProperty::RefreshEditor()
1339 if ( m_parent
&& GetParentState() )
1341 wxPropertyGrid
* pg
= GetParentState()->GetGrid();
1342 if ( pg
->GetSelectedProperty() == this )
1344 wxWindow
* editor
= pg
->GetEditorControl();
1346 GetEditorClass()->UpdateControl( this, editor
);
1352 wxVariant
wxPGProperty::GetDefaultValue() const
1354 wxVariant defVal
= GetAttribute(wxS("DefaultValue"));
1355 if ( !defVal
.IsNull() )
1358 wxVariant value
= GetValue();
1360 if ( !value
.IsNull() )
1362 wxString
valueType(value
.GetType());
1364 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1365 return wxPGVariant_Zero
;
1366 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1367 return wxPGVariant_EmptyString
;
1368 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1369 return wxPGVariant_False
;
1370 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1371 return wxVariant(0.0);
1372 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1373 return wxVariant(wxArrayString());
1374 if ( valueType
== wxS("wxLongLong") )
1375 return WXVARIANT(wxLongLong(0));
1376 if ( valueType
== wxS("wxULongLong") )
1377 return WXVARIANT(wxULongLong(0));
1378 if ( valueType
== wxS("wxColour") )
1379 return WXVARIANT(*wxBLACK
);
1381 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1382 return wxVariant(wxDateTime::Now());
1384 if ( valueType
== wxS("wxFont") )
1385 return WXVARIANT(*wxNORMAL_FONT
);
1386 if ( valueType
== wxS("wxPoint") )
1387 return WXVARIANT(wxPoint(0, 0));
1388 if ( valueType
== wxS("wxSize") )
1389 return WXVARIANT(wxSize(0, 0));
1395 void wxPGProperty::EnsureCells( unsigned int column
)
1397 if ( column
>= m_cells
.size() )
1399 // Fill empty slots with default cells
1400 wxPropertyGrid
* pg
= GetGrid();
1401 wxPGCell defaultCell
;
1403 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1404 defaultCell
= pg
->GetPropertyDefaultCell();
1406 defaultCell
= pg
->GetCategoryDefaultCell();
1408 // TODO: Replace with resize() call
1409 unsigned int cellCountMax
= column
+1;
1411 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1412 m_cells
.push_back(defaultCell
);
1416 void wxPGProperty::SetCell( int column
,
1417 const wxPGCell
& cell
)
1419 EnsureCells(column
);
1421 m_cells
[column
] = cell
;
1424 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1425 unsigned int lastCol
,
1426 const wxPGCell
& cell
,
1427 const wxPGCell
& srcData
,
1428 wxPGCellData
* unmodCellData
,
1429 FlagType ignoreWithFlags
,
1433 // Sets cell in memory optimizing fashion. That is, if
1434 // current cell data matches unmodCellData, we will
1435 // simply get reference to data from cell. Otherwise,
1436 // cell information from srcData is merged into current.
1439 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1441 EnsureCells(lastCol
);
1443 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1445 if ( m_cells
[col
].GetData() == unmodCellData
)
1447 // Data matches... use cell directly
1448 m_cells
[col
] = cell
;
1452 // Data did not match... merge valid information
1453 m_cells
[col
].MergeFrom(srcData
);
1460 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1461 Item(i
)->AdaptiveSetCell( firstCol
,
1471 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1473 if ( m_cells
.size() > column
)
1474 return m_cells
[column
];
1476 wxPropertyGrid
* pg
= GetGrid();
1479 return pg
->GetCategoryDefaultCell();
1481 return pg
->GetPropertyDefaultCell();
1484 wxPGCell
& wxPGProperty::GetCell( unsigned int column
)
1486 EnsureCells(column
);
1487 return m_cells
[column
];
1490 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1493 wxPGProperty
* firstProp
= this;
1496 // If category is tried to set recursively, skip it and only
1497 // affect the children.
1500 while ( firstProp
->IsCategory() )
1502 if ( !firstProp
->GetChildCount() )
1504 firstProp
= firstProp
->Item(0);
1508 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1509 wxPGCellData
* firstCellData
= firstCell
.GetData();
1511 wxPGCell
newCell(firstCell
);
1512 newCell
.SetBgCol(colour
);
1514 srcCell
.SetBgCol(colour
);
1517 GetParentState()->GetColumnCount()-1,
1521 recursively
? wxPG_PROP_CATEGORY
: 0,
1525 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1528 wxPGProperty
* firstProp
= this;
1531 // If category is tried to set recursively, skip it and only
1532 // affect the children.
1535 while ( firstProp
->IsCategory() )
1537 if ( !firstProp
->GetChildCount() )
1539 firstProp
= firstProp
->Item(0);
1543 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1544 wxPGCellData
* firstCellData
= firstCell
.GetData();
1546 wxPGCell
newCell(firstCell
);
1547 newCell
.SetFgCol(colour
);
1549 srcCell
.SetFgCol(colour
);
1552 GetParentState()->GetColumnCount()-1,
1556 recursively
? wxPG_PROP_CATEGORY
: 0,
1560 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1565 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1570 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1572 if ( DoSetAttribute( name
, value
) )
1574 // Support working without grid, when possible
1575 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1579 m_attributes
.Set( name
, value
);
1582 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1584 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1587 while ( attributes
.GetNext(it
, variant
) )
1588 SetAttribute( variant
.GetName(), variant
);
1591 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1597 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1599 return m_attributes
.FindValue(name
);
1602 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1604 wxVariant variant
= m_attributes
.FindValue(name
);
1606 if ( !variant
.IsNull() )
1607 return variant
.GetString();
1612 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1614 wxVariant variant
= m_attributes
.FindValue(name
);
1616 return wxPGVariantToInt(variant
, defVal
);
1619 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1622 wxVariant variant
= m_attributes
.FindValue(name
);
1624 if ( wxPGVariantToDouble(variant
, &retVal
) )
1630 wxVariant
wxPGProperty::GetAttributesAsList() const
1632 wxVariantList tempList
;
1633 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1635 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1638 while ( m_attributes
.GetNext(it
, variant
) )
1644 // Slots of utility flags are NULL
1645 const unsigned int gs_propFlagToStringSize
= 14;
1647 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1664 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1667 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1671 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1673 if ( relevantFlags
& a
)
1675 const wxChar
* fs
= gs_propFlagToString
[i
];
1687 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1691 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1693 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1695 const wxChar
* fs
= gs_propFlagToString
[i
];
1696 if ( fs
&& str
== fs
)
1702 WX_PG_TOKENIZER1_END()
1704 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1707 wxValidator
* wxPGProperty::DoGetValidator() const
1709 return (wxValidator
*) NULL
;
1712 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1714 wxPropertyGrid
* pg
= GetGrid();
1715 int sel
= GetChoiceSelection();
1719 if ( index
== wxNOT_FOUND
)
1720 index
= m_choices
.GetCount();
1725 m_choices
.Insert(label
, index
, value
);
1727 if ( sel
!= newSel
)
1728 SetChoiceSelection(newSel
);
1730 if ( this == pg
->GetSelection() )
1731 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1737 void wxPGProperty::DeleteChoice( int index
)
1739 wxPropertyGrid
* pg
= GetGrid();
1741 int sel
= GetChoiceSelection();
1744 // Adjust current value
1747 SetValueToUnspecified();
1750 else if ( index
< sel
)
1755 m_choices
.RemoveAt(index
);
1757 if ( sel
!= newSel
)
1758 SetChoiceSelection(newSel
);
1760 if ( this == pg
->GetSelection() )
1761 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1764 int wxPGProperty::GetChoiceSelection() const
1766 wxVariant value
= GetValue();
1767 wxString valueType
= value
.GetType();
1768 int index
= wxNOT_FOUND
;
1770 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1773 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1775 index
= value
.GetLong();
1777 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1779 index
= m_choices
.Index(value
.GetString());
1781 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1783 index
= value
.GetBool()? 1 : 0;
1789 void wxPGProperty::SetChoiceSelection( int newValue
)
1791 // Changes value of a property with choices, but only
1792 // works if the value type is long or string.
1793 wxString valueType
= GetValue().GetType();
1795 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1797 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1799 SetValue( m_choices
.GetLabel(newValue
) );
1801 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1803 SetValue( (long) newValue
);
1807 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1809 m_choices
.Assign(choices
);
1812 // This may be needed to trigger some initialization
1813 // (but don't do it if property is somewhat uninitialized)
1814 wxVariant defVal
= GetDefaultValue();
1815 if ( defVal
.IsNull() )
1825 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1827 const wxPGEditor
* editor
;
1829 if ( !m_customEditor
)
1831 editor
= DoGetEditorClass();
1834 editor
= m_customEditor
;
1837 // Maybe override editor if common value specified
1838 if ( GetDisplayedCommonValueCount() )
1840 // TextCtrlAndButton -> ComboBoxAndButton
1841 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1842 editor
= wxPGEditor_ChoiceAndButton
;
1844 // TextCtrl -> ComboBox
1845 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1846 editor
= wxPGEditor_ComboBox
;
1852 bool wxPGProperty::HasVisibleChildren() const
1856 for ( i
=0; i
<GetChildCount(); i
++ )
1858 wxPGProperty
* child
= Item(i
);
1860 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1867 bool wxPGProperty::RecreateEditor()
1869 wxPropertyGrid
* pg
= GetGrid();
1872 wxPGProperty
* selected
= pg
->GetSelection();
1873 if ( this == selected
)
1875 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1882 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1884 delete m_valueBitmap
;
1886 if ( &bmp
&& bmp
.Ok() )
1889 wxSize maxSz
= GetGrid()->GetImageSize();
1890 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1892 if ( imSz
.x
!= maxSz
.x
|| imSz
.y
!= maxSz
.y
)
1894 // Create a memory DC
1895 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1898 dc
.SelectObject(*bmpNew
);
1901 // FIXME: This is ugly - use image or wait for scaling patch.
1902 double scaleX
= (double)maxSz
.x
/ (double)imSz
.x
;
1903 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1905 dc
.SetUserScale(scaleX
,scaleY
);
1907 dc
.DrawBitmap( bmp
, 0, 0 );
1909 m_valueBitmap
= bmpNew
;
1913 m_valueBitmap
= new wxBitmap(bmp
);
1916 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1920 m_valueBitmap
= NULL
;
1921 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1926 wxPGProperty
* wxPGProperty::GetMainParent() const
1928 const wxPGProperty
* curChild
= this;
1929 const wxPGProperty
* curParent
= m_parent
;
1931 while ( curParent
&& !curParent
->IsCategory() )
1933 curChild
= curParent
;
1934 curParent
= curParent
->m_parent
;
1937 return (wxPGProperty
*) curChild
;
1941 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1944 // Returns last visible sub-item, recursively.
1945 if ( !IsExpanded() || !GetChildCount() )
1948 return Last()->GetLastVisibleSubItem();
1952 bool wxPGProperty::IsVisible() const
1954 const wxPGProperty
* parent
;
1956 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1959 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1961 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
1968 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
1970 wxPropertyGridPageState
* state
= GetParentState();
1971 wxPropertyGrid
* propGrid
= state
->GetGrid();
1972 if ( state
== propGrid
->GetState() )
1978 int wxPGProperty::GetY2( int lh
) const
1980 const wxPGProperty
* parent
;
1981 const wxPGProperty
* child
= this;
1985 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
1987 if ( !parent
->IsExpanded() )
1989 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
1994 y
-= lh
; // need to reduce one level
2000 int wxPGProperty::GetY() const
2002 return GetY2(GetGrid()->GetRowHeight());
2005 // This is used by Insert etc.
2006 void wxPGProperty::AddChild2( wxPGProperty
* prop
, int index
, bool correct_mode
)
2008 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2010 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2011 m_children
.push_back( prop
);
2015 m_children
.insert( m_children
.begin()+index
, prop
);
2016 if ( correct_mode
) FixIndicesOfChildren( index
);
2019 prop
->m_parent
= this;
2022 // This is used by properties that have fixed sub-properties
2023 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2025 wxASSERT_MSG( prop
->GetBaseName().length(),
2026 "Property's children must have unique, non-empty names within their scope" );
2028 prop
->m_arrIndex
= m_children
.size();
2029 m_children
.push_back( prop
);
2031 int custImgHeight
= prop
->OnMeasureImage().y
;
2032 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2033 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2035 prop
->m_parent
= this;
2038 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2040 wxArrayPGProperty::iterator it
;
2041 wxArrayPGProperty
& children
= m_children
;
2043 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2047 m_children
.erase(it
);
2053 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2055 wxASSERT( GetChildCount() );
2056 wxASSERT( !IsCategory() );
2058 *value
= GetValue();
2060 if ( !list
.GetCount() )
2063 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2065 bool allChildrenSpecified
;
2067 // Don't fully update aggregate properties unless all children have
2069 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2070 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2072 allChildrenSpecified
= true;
2074 wxVariant childValue
= list
[0];
2078 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2080 for ( i
=0; i
<GetChildCount(); i
++ )
2082 const wxPGProperty
* child
= Item(i
);
2084 if ( childValue
.GetName() == child
->GetBaseName() )
2086 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2088 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2090 wxVariant
cv2(child
->GetValue());
2091 child
->AdaptListToValue(childValue
, &cv2
);
2095 if ( allChildrenSpecified
)
2096 ChildChanged(*value
, i
, childValue
);
2098 if ( n
== (unsigned int)list
.GetCount() )
2100 childValue
= list
[n
];
2106 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2109 for ( i
=starthere
;i
<GetChildCount();i
++)
2110 Item(i
)->m_arrIndex
= i
;
2114 // Returns (direct) child property with given name (or NULL if not found)
2115 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2119 for ( i
=0; i
<GetChildCount(); i
++ )
2121 wxPGProperty
* p
= Item(i
);
2122 if ( p
->m_name
== name
)
2126 // Does it have point, then?
2127 int pos
= name
.Find(wxS('.'));
2129 return (wxPGProperty
*) NULL
;
2131 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2133 if ( !p
|| !p
->GetChildCount() )
2136 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2139 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2141 unsigned int i
= hintIndex
;
2143 if ( i
>= GetChildCount() )
2146 unsigned int lastIndex
= i
- 1;
2148 if ( lastIndex
>= GetChildCount() )
2149 lastIndex
= GetChildCount() - 1;
2153 wxPGProperty
* p
= Item(i
);
2154 if ( p
->m_name
== name
)
2157 if ( i
== lastIndex
)
2161 if ( i
== GetChildCount() )
2168 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2170 // Returns height of children, recursively, and
2171 // by taking expanded/collapsed status into account.
2173 // iMax is used when finding property y-positions.
2179 iMax_
= GetChildCount();
2181 unsigned int iMax
= iMax_
;
2183 wxASSERT( iMax
<= GetChildCount() );
2185 if ( !IsExpanded() && GetParent() )
2190 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2192 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2194 if ( !pwc
->IsExpanded() ||
2195 pwc
->GetChildCount() == 0 )
2198 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2207 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const
2209 wxASSERT( nextItemY
);
2211 // Linear search at the moment
2213 // nextItemY = y of next visible property, final value will be written back.
2214 wxPGProperty
* result
= NULL
;
2215 wxPGProperty
* current
= NULL
;
2216 unsigned int iy
= *nextItemY
;
2218 unsigned int iMax
= GetChildCount();
2222 wxPGProperty
* pwc
= Item(i
);
2224 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2235 if ( pwc
->IsExpanded() &&
2236 pwc
->GetChildCount() > 0 )
2238 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2250 if ( !result
&& y
< iy
)
2257 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2259 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2262 return (wxPGProperty
*) result
;
2265 void wxPGProperty::Empty()
2268 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2270 for ( i
=0; i
<GetChildCount(); i
++ )
2272 delete m_children
[i
];
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