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 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
99 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
102 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
103 int xOffset
, const wxString
& text
,
104 wxPGProperty
* property
,
105 const wxPGEditor
* editor
) const
107 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
114 rect2
.height
-= yOffset
;
115 editor
->DrawValue( dc
, rect2
, property
, text
);
120 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
125 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
127 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
128 wxPGDrawFocusRect(dc
,focusRect
);
131 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
135 // If possible, use cell colours
136 if ( !(flags
& DontUseCellBgCol
) )
138 dc
.SetPen(cell
.GetBgCol());
139 dc
.SetBrush(cell
.GetBgCol());
142 if ( !(flags
& DontUseCellFgCol
) )
144 dc
.SetTextForeground(cell
.GetFgCol());
147 // Draw Background, but only if not rendering in control
148 // (as control already has rendered correct background).
149 if ( !(flags
& (Control
|ChoicePopup
)) )
150 dc
.DrawRectangle(rect
);
152 const wxBitmap
& bmp
= cell
.GetBitmap();
154 // Do not draw oversized bitmap outside choice popup
155 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
159 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
160 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
162 imageWidth
= bmp
.GetWidth();
168 // -----------------------------------------------------------------------
169 // wxPGDefaultRenderer
170 // -----------------------------------------------------------------------
172 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
173 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
174 int column
, int item
, int flags
) const
176 bool isUnspecified
= property
->IsValueUnspecified();
178 if ( column
== 1 && item
== -1 )
180 int cmnVal
= property
->GetCommonValue();
184 if ( !isUnspecified
)
185 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
190 const wxPGEditor
* editor
= NULL
;
191 const wxPGCell
* cell
= NULL
;
195 int preDrawFlags
= flags
;
197 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
199 imageWidth
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
203 if ( !isUnspecified
)
205 editor
= property
->GetColumnEditor(column
);
207 // Regular property value
209 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
211 wxPGPaintData paintdata
;
212 paintdata
.m_parent
= propertyGrid
;
213 paintdata
.m_choiceItem
= item
;
215 if ( imageSize
.x
> 0 )
217 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
218 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
219 wxPG_CUSTOM_IMAGE_WIDTH
,
220 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
222 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
224 paintdata
.m_drawnWidth
= imageSize
.x
;
225 paintdata
.m_drawnHeight
= imageSize
.y
;
227 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
229 imageWidth
= paintdata
.m_drawnWidth
;
232 text
= property
->GetValueAsString();
235 if ( propertyGrid
->GetColumnCount() <= 2 )
237 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
238 if ( unitsString
.length() )
239 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
243 if ( text
.length() == 0 )
245 // Try to show inline help if no text
246 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
247 if ( !vInlineHelp
.IsNull() )
249 text
= vInlineHelp
.GetString();
250 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
255 int imageOffset
= property
->GetImageOffset(imageWidth
);
257 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
259 // active caption gets nice dotted rectangle
260 if ( property
->IsCategory() /*&& column == 0*/ )
262 if ( flags
& Selected
)
264 if ( imageWidth
> 0 )
266 imageOffset
-= DEFAULT_IMAGE_OFFSET_INCREMENT
;
267 imageWidth
+= 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
= NULL
;
408 m_clientObject
= NULL
;
410 m_customEditor
= NULL
;
414 m_valueBitmap
= 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 wxPG_PROP_AGGREGATE
) ||
544 ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
545 wxPG_PROP_MISC_PARENT
),
546 "wxPGProperty parental flags set incorrectly at "
549 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
551 // Properties with private children are not expanded by default.
554 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
556 // ...unless it cannot be expanded by user and therefore must
557 // remain visible at all times
562 // Prepare children recursively
563 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
565 wxPGProperty
* child
= Item(i
);
566 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
569 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
570 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
574 wxPGProperty::wxPGProperty()
581 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
588 wxPGProperty::~wxPGProperty()
590 delete m_clientObject
;
592 Empty(); // this deletes items
594 delete m_valueBitmap
;
599 // This makes it easier for us to detect dangling pointers
604 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
606 wxPGProperty
* parent
= m_parent
;
609 if ( parent
== candidate
)
611 parent
= parent
->m_parent
;
616 void wxPGProperty::SetName( const wxString
& newName
)
618 wxPropertyGrid
* pg
= GetGrid();
621 pg
->SetPropertyName(this, newName
);
626 wxString
wxPGProperty::GetName() const
628 wxPGProperty
* parent
= GetParent();
630 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
633 return m_parent
->GetName() + wxS(".") + m_name
;
636 wxPropertyGrid
* wxPGProperty::GetGrid() const
638 if ( !m_parentState
)
640 return m_parentState
->GetGrid();
643 int wxPGProperty::Index( const wxPGProperty
* p
) const
645 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
647 if ( p
== m_children
[i
] )
653 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
658 void wxPGProperty::OnSetValue()
662 void wxPGProperty::RefreshChildren ()
666 void wxPGProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
670 void wxPGProperty::GetDisplayInfo( unsigned int column
,
674 const wxPGCell
** pCell
)
676 const wxPGCell
* cell
= NULL
;
678 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
680 // Not painting listi of choice popups, so get text from property
681 cell
= &GetCell(column
);
682 if ( cell
->HasText() )
684 *pString
= cell
->GetText();
689 *pString
= GetLabel();
690 else if ( column
== 1 )
691 *pString
= GetDisplayedString();
692 else if ( column
== 2 )
693 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
698 wxASSERT( column
== 1 );
700 if ( choiceIndex
!= wxNOT_FOUND
)
702 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
703 if ( entry
.GetBitmap().IsOk() ||
704 entry
.GetFgCol().IsOk() ||
705 entry
.GetBgCol().IsOk() )
707 *pString
= m_choices
.GetLabel(choiceIndex
);
712 cell
= &GetCell(column
);
714 wxASSERT_MSG( cell
->GetData(),
715 wxString::Format("Invalid cell for property %s",
716 GetName().c_str()) );
722 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
725 if ( col != 1 || choiceIndex == wxNOT_FOUND )
727 const wxPGCell& cell = GetCell(col);
728 if ( cell->HasText() )
730 return cell->GetText();
737 return GetDisplayedString();
739 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
745 return m_choices.GetLabel(choiceIndex);
748 return wxEmptyString;
752 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
754 const wxVariantList
* valueOverrides
,
755 wxPGHashMapS2S
* childResults
) const
758 int iMax
= m_children
.size();
764 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
765 !(argFlags
& wxPG_FULL_VALUE
) )
766 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
768 int iMaxMinusOne
= iMax
-1;
770 if ( !IsTextEditable() )
771 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
773 wxPGProperty
* curChild
= m_children
[0];
775 bool overridesLeft
= false;
776 wxVariant overrideValue
;
777 wxVariantList::const_iterator node
;
779 if ( valueOverrides
)
781 node
= valueOverrides
->begin();
782 if ( node
!= valueOverrides
->end() )
784 overrideValue
= *node
;
785 overridesLeft
= true;
789 for ( i
= 0; i
< iMax
; i
++ )
791 wxVariant childValue
;
793 wxString childLabel
= curChild
->GetLabel();
795 // Check for value override
796 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
798 if ( !overrideValue
.IsNull() )
799 childValue
= overrideValue
;
801 childValue
= curChild
->GetValue();
803 if ( node
!= valueOverrides
->end() )
804 overrideValue
= *node
;
806 overridesLeft
= false;
810 childValue
= curChild
->GetValue();
814 if ( !childValue
.IsNull() )
816 if ( overridesLeft
&&
817 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
818 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
820 wxVariantList
& childList
= childValue
.GetList();
821 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
822 &childList
, childResults
);
826 s
= curChild
->ValueToString(childValue
,
827 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
831 if ( childResults
&& curChild
->GetChildCount() )
832 (*childResults
)[curChild
->GetName()] = s
;
835 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
838 if ( !curChild
->GetChildCount() || skip
)
841 text
+= wxS("[") + s
+ wxS("]");
843 if ( i
< iMaxMinusOne
)
845 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
846 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
847 !(argFlags
& wxPG_FULL_VALUE
) )
852 if ( !curChild
->GetChildCount() )
858 curChild
= m_children
[i
+1];
862 if ( (unsigned int)i
< m_children
.size() )
864 if ( !text
.EndsWith(wxS("; ")) )
865 text
+= wxS("; ...");
871 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
874 wxCHECK_MSG( GetChildCount() > 0,
876 "If user property does not have any children, it must "
877 "override GetValueAsString" );
879 // FIXME: Currently code below only works if value is actually m_value
880 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
881 "Sorry, currently default wxPGProperty::ValueToString() "
882 "implementation only works if value is m_value." );
885 DoGenerateComposedValue(text
, argFlags
);
889 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
891 #if wxPG_COMPATIBILITY_1_4
892 // This is backwards compatibility test
893 // That is, to make sure this function is not overridden
894 // (instead, ValueToString() should be).
895 if ( argFlags
== 0xFFFF )
897 // Do not override! (for backwards compliancy)
898 return g_invalidStringContent
;
902 if ( IsValueUnspecified() )
903 return wxEmptyString
;
905 if ( m_commonValue
== -1 )
907 wxVariant
value(GetValue());
908 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
912 // Return common value's string representation
913 wxPropertyGrid
* pg
= GetGrid();
914 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
916 if ( argFlags
& wxPG_FULL_VALUE
)
918 return cv
->GetLabel();
920 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
922 return cv
->GetEditableText();
926 return cv
->GetLabel();
930 wxString
wxPGProperty::GetValueString( int argFlags
) const
932 return GetValueAsString(argFlags
);
935 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
937 variant
= (long)number
;
941 // Convert semicolon delimited tokens into child values.
942 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
944 if ( !GetChildCount() )
947 unsigned int curChild
= 0;
949 unsigned int iMax
= m_children
.size();
951 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
952 !(argFlags
& wxPG_FULL_VALUE
) )
953 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
955 bool changed
= false;
960 // Its best only to add non-empty group items
961 bool addOnlyIfNotEmpty
= false;
962 const wxChar delimeter
= wxS(';');
964 size_t tokenStart
= 0xFFFFFF;
966 wxVariantList temp_list
;
967 wxVariant
list(temp_list
);
969 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
971 wxLogTrace("propgrid",
972 wxT(">> %s.StringToValue('%s')"), GetLabel(), text
);
974 wxString::const_iterator it
= text
.begin();
977 if ( it
!= text
.end() )
984 // How many units we iterate string forward at the end of loop?
985 // We need to keep track of this or risk going to negative
986 // with it-- operation.
987 unsigned int strPosIncrement
= 1;
989 if ( tokenStart
!= 0xFFFFFF )
992 if ( a
== delimeter
|| a
== 0 )
994 token
= text
.substr(tokenStart
,pos
-tokenStart
);
996 size_t len
= token
.length();
998 if ( !addOnlyIfNotEmpty
|| len
> 0 )
1000 const wxPGProperty
* child
= Item(curChild
);
1001 wxVariant
variant(child
->GetValue());
1002 wxString childName
= child
->GetBaseName();
1004 wxLogTrace("propgrid",
1005 wxT("token = '%s', child = %s"),
1008 // Add only if editable or setting programmatically
1009 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1010 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1014 if ( child
->StringToValue(variant
, token
,
1015 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1017 // We really need to set the variant's name
1018 // *after* child->StringToValue() has been
1019 // called, since variant's value may be set by
1020 // assigning another variant into it, which
1021 // then usually causes name to be copied (ie.
1022 // usually cleared) as well. wxBoolProperty
1023 // being case in point with its use of
1024 // wxPGVariant_Bool macro as an optimization.
1025 variant
.SetName(childName
);
1026 list
.Append(variant
);
1033 // Empty, becomes unspecified
1035 variant
.SetName(childName
);
1036 list
.Append(variant
);
1042 if ( curChild
>= iMax
)
1046 tokenStart
= 0xFFFFFF;
1051 // Token is not running
1052 if ( a
!= wxS(' ') )
1055 addOnlyIfNotEmpty
= false;
1057 // Is this a group of tokens?
1058 if ( a
== wxS('[') )
1062 if ( it
!= text
.end() ) ++it
;
1064 size_t startPos
= pos
;
1066 // Group item - find end
1067 while ( it
!= text
.end() && depth
> 0 )
1073 if ( a
== wxS(']') )
1075 else if ( a
== wxS('[') )
1079 token
= text
.substr(startPos
,pos
-startPos
-1);
1081 if ( !token
.length() )
1084 const wxPGProperty
* child
= Item(curChild
);
1086 wxVariant oldChildValue
= child
->GetValue();
1087 wxVariant
variant(oldChildValue
);
1089 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1090 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1092 wxString childName
= child
->GetBaseName();
1094 bool stvRes
= child
->StringToValue( variant
, token
,
1096 if ( stvRes
|| (variant
!= oldChildValue
) )
1098 variant
.SetName(childName
);
1099 list
.Append(variant
);
1110 if ( curChild
>= iMax
)
1113 addOnlyIfNotEmpty
= true;
1115 tokenStart
= 0xFFFFFF;
1121 if ( a
== delimeter
)
1122 strPosIncrement
-= 1;
1130 it
+= strPosIncrement
;
1132 if ( it
!= text
.end() )
1141 pos
+= strPosIncrement
;
1150 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1152 wxVariant
variant(m_value
);
1153 bool res
= StringToValue(variant
, text
, argFlags
);
1159 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1161 wxVariant
variant(m_value
);
1162 bool res
= IntToValue(variant
, number
, argFlags
);
1168 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1170 if ( m_valueBitmap
)
1171 return wxSize(m_valueBitmap
->GetWidth(),-1);
1176 int wxPGProperty::GetImageOffset( int imageWidth
) const
1178 int imageOffset
= 0;
1182 // Do not increment offset too much for wide images
1183 if ( imageWidth
<= (wxPG_CUSTOM_IMAGE_WIDTH
+5) )
1184 imageOffset
= imageWidth
+ DEFAULT_IMAGE_OFFSET_INCREMENT
;
1186 imageOffset
= imageWidth
+ 1;
1192 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1194 return wxPGGlobalVars
->m_defaultRenderer
;
1197 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1201 wxBitmap
* bmp
= m_valueBitmap
;
1203 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1205 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1207 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1210 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1212 return wxPGEditor_TextCtrl
;
1215 // Default extra property event handling - that is, none at all.
1216 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1222 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1224 // If auto unspecified values are not wanted (via window or property style),
1225 // then get default value instead of wxNullVariant.
1226 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1227 !UsesAutoUnspecified() )
1229 value
= GetDefaultValue();
1232 if ( !value
.IsNull() )
1234 wxVariant tempListVariant
;
1237 // List variants are reserved a special purpose
1238 // as intermediate containers for child values
1239 // of properties with children.
1240 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1243 // However, situation is different for composed string properties
1244 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1246 tempListVariant
= value
;
1247 pList
= &tempListVariant
;
1251 AdaptListToValue(value
, &newValue
);
1253 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1256 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1257 flags
|= wxPG_SETVAL_AGGREGATED
;
1259 if ( pList
&& !pList
->IsNull() )
1261 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1262 wxASSERT( GetChildCount() );
1263 wxASSERT( !IsCategory() );
1265 wxVariantList
& list
= pList
->GetList();
1266 wxVariantList::iterator node
;
1269 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1271 // Children in list can be in any order, but we will give hint to
1272 // GetPropertyByNameWH(). This optimizes for full list parsing.
1273 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1275 wxVariant
& childValue
= *((wxVariant
*)*node
);
1276 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1279 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1280 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1282 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1284 wxVariant listRefCopy
= childValue
;
1285 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1289 wxVariant oldVal
= child
->GetValue();
1290 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1293 else if ( child
->GetValue() != childValue
)
1295 // For aggregate properties, we will trust RefreshChildren()
1296 // to update child values.
1297 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1298 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1299 if ( flags
& wxPG_SETVAL_BY_USER
)
1300 child
->SetFlag(wxPG_PROP_MODIFIED
);
1307 if ( !value
.IsNull() )
1313 if ( flags
& wxPG_SETVAL_BY_USER
)
1314 SetFlag(wxPG_PROP_MODIFIED
);
1316 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1321 if ( m_commonValue
!= -1 )
1323 wxPropertyGrid
* pg
= GetGrid();
1324 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1330 // Set children to unspecified, but only if aggregate or
1331 // value is <composed>
1332 if ( AreChildrenComponents() )
1335 for ( i
=0; i
<GetChildCount(); i
++ )
1336 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1340 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1341 UpdateParentValues();
1344 // Update editor control
1347 // We need to check for these, otherwise GetGrid() may fail.
1348 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1351 wxPropertyGrid
* pg
= GetGridIfDisplayed();
1353 pg
->DrawItemAndValueRelated(this);
1358 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1360 GetGrid()->ValueChangeInEvent(value
);
1363 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1365 ChangeFlag(flag
, set
);
1368 for ( i
= 0; i
< GetChildCount(); i
++ )
1369 Item(i
)->SetFlagRecursively(flag
, set
);
1372 void wxPGProperty::RefreshEditor()
1377 wxPropertyGrid
* pg
= GetGrid();
1378 if ( pg
&& pg
->GetSelectedProperty() == this )
1379 pg
->RefreshEditor();
1382 wxVariant
wxPGProperty::GetDefaultValue() const
1384 wxVariant defVal
= GetAttribute(wxPG_ATTR_DEFAULT_VALUE
);
1385 if ( !defVal
.IsNull() )
1388 wxVariant value
= GetValue();
1390 if ( !value
.IsNull() )
1392 wxString
valueType(value
.GetType());
1394 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1395 return wxPGVariant_Zero
;
1396 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1397 return wxPGVariant_EmptyString
;
1398 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1399 return wxPGVariant_False
;
1400 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1401 return wxVariant(0.0);
1402 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1403 return wxVariant(wxArrayString());
1404 if ( valueType
== wxS("wxLongLong") )
1405 return WXVARIANT(wxLongLong(0));
1406 if ( valueType
== wxS("wxULongLong") )
1407 return WXVARIANT(wxULongLong(0));
1408 if ( valueType
== wxS("wxColour") )
1409 return WXVARIANT(*wxBLACK
);
1411 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1412 return wxVariant(wxDateTime::Now());
1414 if ( valueType
== wxS("wxFont") )
1415 return WXVARIANT(*wxNORMAL_FONT
);
1416 if ( valueType
== wxS("wxPoint") )
1417 return WXVARIANT(wxPoint(0, 0));
1418 if ( valueType
== wxS("wxSize") )
1419 return WXVARIANT(wxSize(0, 0));
1425 void wxPGProperty::EnsureCells( unsigned int column
)
1427 if ( column
>= m_cells
.size() )
1429 // Fill empty slots with default cells
1430 wxPropertyGrid
* pg
= GetGrid();
1431 wxPGCell defaultCell
;
1433 // Work around possible VC6 bug by using intermediate variables
1434 const wxPGCell
& propDefCell
= pg
->GetPropertyDefaultCell();
1435 const wxPGCell
& catDefCell
= pg
->GetCategoryDefaultCell();
1437 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1438 defaultCell
= propDefCell
;
1440 defaultCell
= catDefCell
;
1442 // TODO: Replace with resize() call
1443 unsigned int cellCountMax
= column
+1;
1445 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1446 m_cells
.push_back(defaultCell
);
1450 void wxPGProperty::SetCell( int column
,
1451 const wxPGCell
& cell
)
1453 EnsureCells(column
);
1455 m_cells
[column
] = cell
;
1458 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1459 unsigned int lastCol
,
1460 const wxPGCell
& cell
,
1461 const wxPGCell
& srcData
,
1462 wxPGCellData
* unmodCellData
,
1463 FlagType ignoreWithFlags
,
1467 // Sets cell in memory optimizing fashion. That is, if
1468 // current cell data matches unmodCellData, we will
1469 // simply get reference to data from cell. Otherwise,
1470 // cell information from srcData is merged into current.
1473 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1475 EnsureCells(lastCol
);
1477 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1479 if ( m_cells
[col
].GetData() == unmodCellData
)
1481 // Data matches... use cell directly
1482 m_cells
[col
] = cell
;
1486 // Data did not match... merge valid information
1487 m_cells
[col
].MergeFrom(srcData
);
1494 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1495 Item(i
)->AdaptiveSetCell( firstCol
,
1505 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1507 if ( m_cells
.size() > column
)
1508 return m_cells
[column
];
1510 wxPropertyGrid
* pg
= GetGrid();
1513 return pg
->GetCategoryDefaultCell();
1515 return pg
->GetPropertyDefaultCell();
1518 wxPGCell
& wxPGProperty::GetOrCreateCell( unsigned int column
)
1520 EnsureCells(column
);
1521 return m_cells
[column
];
1524 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1527 wxPGProperty
* firstProp
= this;
1530 // If category is tried to set recursively, skip it and only
1531 // affect the children.
1534 while ( firstProp
->IsCategory() )
1536 if ( !firstProp
->GetChildCount() )
1538 firstProp
= firstProp
->Item(0);
1542 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1543 wxPGCellData
* firstCellData
= firstCell
.GetData();
1545 wxPGCell
newCell(firstCell
);
1546 newCell
.SetBgCol(colour
);
1548 srcCell
.SetBgCol(colour
);
1551 GetParentState()->GetColumnCount()-1,
1555 recursively
? wxPG_PROP_CATEGORY
: 0,
1559 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1562 wxPGProperty
* firstProp
= this;
1565 // If category is tried to set recursively, skip it and only
1566 // affect the children.
1569 while ( firstProp
->IsCategory() )
1571 if ( !firstProp
->GetChildCount() )
1573 firstProp
= firstProp
->Item(0);
1577 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1578 wxPGCellData
* firstCellData
= firstCell
.GetData();
1580 wxPGCell
newCell(firstCell
);
1581 newCell
.SetFgCol(colour
);
1583 srcCell
.SetFgCol(colour
);
1586 GetParentState()->GetColumnCount()-1,
1590 recursively
? wxPG_PROP_CATEGORY
: 0,
1594 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1599 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1604 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1606 if ( DoSetAttribute( name
, value
) )
1608 // Support working without grid, when possible
1609 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1613 m_attributes
.Set( name
, value
);
1616 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1618 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1621 while ( attributes
.GetNext(it
, variant
) )
1622 SetAttribute( variant
.GetName(), variant
);
1625 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1631 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1633 return m_attributes
.FindValue(name
);
1636 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1638 wxVariant variant
= m_attributes
.FindValue(name
);
1640 if ( !variant
.IsNull() )
1641 return variant
.GetString();
1646 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1648 wxVariant variant
= m_attributes
.FindValue(name
);
1650 if ( variant
.IsNull() )
1653 return variant
.GetLong();
1656 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1658 wxVariant variant
= m_attributes
.FindValue(name
);
1660 if ( variant
.IsNull() )
1663 return variant
.GetDouble();
1666 wxVariant
wxPGProperty::GetAttributesAsList() const
1668 wxVariantList tempList
;
1669 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1671 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1674 while ( m_attributes
.GetNext(it
, variant
) )
1680 // Slots of utility flags are NULL
1681 const unsigned int gs_propFlagToStringSize
= 14;
1683 static const wxChar
* gs_propFlagToString
[gs_propFlagToStringSize
] = {
1700 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1703 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1707 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1709 if ( relevantFlags
& a
)
1711 const wxChar
* fs
= gs_propFlagToString
[i
];
1723 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1727 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1729 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1731 const wxChar
* fs
= gs_propFlagToString
[i
];
1732 if ( fs
&& str
== fs
)
1738 WX_PG_TOKENIZER1_END()
1740 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1743 wxValidator
* wxPGProperty::DoGetValidator() const
1748 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1750 wxPropertyGrid
* pg
= GetGrid();
1751 int sel
= GetChoiceSelection();
1755 if ( index
== wxNOT_FOUND
)
1756 index
= m_choices
.GetCount();
1761 m_choices
.Insert(label
, index
, value
);
1763 if ( sel
!= newSel
)
1764 SetChoiceSelection(newSel
);
1766 if ( this == pg
->GetSelection() )
1767 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1773 void wxPGProperty::DeleteChoice( int index
)
1775 wxPropertyGrid
* pg
= GetGrid();
1777 int sel
= GetChoiceSelection();
1780 // Adjust current value
1783 SetValueToUnspecified();
1786 else if ( index
< sel
)
1791 m_choices
.RemoveAt(index
);
1793 if ( sel
!= newSel
)
1794 SetChoiceSelection(newSel
);
1796 if ( this == pg
->GetSelection() )
1797 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1800 int wxPGProperty::GetChoiceSelection() const
1802 wxVariant value
= GetValue();
1803 wxString valueType
= value
.GetType();
1804 int index
= wxNOT_FOUND
;
1806 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1809 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1811 index
= value
.GetLong();
1813 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1815 index
= m_choices
.Index(value
.GetString());
1817 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1819 index
= value
.GetBool()? 1 : 0;
1825 void wxPGProperty::SetChoiceSelection( int newValue
)
1827 // Changes value of a property with choices, but only
1828 // works if the value type is long or string.
1829 wxString valueType
= GetValue().GetType();
1831 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1833 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1835 SetValue( m_choices
.GetLabel(newValue
) );
1837 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1839 SetValue( (long) newValue
);
1843 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1845 m_choices
.Assign(choices
);
1848 // This may be needed to trigger some initialization
1849 // (but don't do it if property is somewhat uninitialized)
1850 wxVariant defVal
= GetDefaultValue();
1851 if ( defVal
.IsNull() )
1861 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1863 const wxPGEditor
* editor
;
1865 if ( !m_customEditor
)
1867 editor
= DoGetEditorClass();
1870 editor
= m_customEditor
;
1873 // Maybe override editor if common value specified
1874 if ( GetDisplayedCommonValueCount() )
1876 // TextCtrlAndButton -> ComboBoxAndButton
1877 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1878 editor
= wxPGEditor_ChoiceAndButton
;
1880 // TextCtrl -> ComboBox
1881 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1882 editor
= wxPGEditor_ComboBox
;
1888 bool wxPGProperty::HasVisibleChildren() const
1892 for ( i
=0; i
<GetChildCount(); i
++ )
1894 wxPGProperty
* child
= Item(i
);
1896 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1903 bool wxPGProperty::RecreateEditor()
1905 wxPropertyGrid
* pg
= GetGrid();
1908 wxPGProperty
* selected
= pg
->GetSelection();
1909 if ( this == selected
)
1911 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1918 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1920 delete m_valueBitmap
;
1922 if ( &bmp
&& bmp
.Ok() )
1925 wxSize maxSz
= GetGrid()->GetImageSize();
1926 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1928 if ( imSz
.y
!= maxSz
.y
)
1930 // Create a memory DC
1931 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1934 dc
.SelectObject(*bmpNew
);
1937 // FIXME: This is ugly - use image or wait for scaling patch.
1938 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1940 dc
.SetUserScale(scaleY
, scaleY
);
1942 dc
.DrawBitmap(bmp
, 0, 0);
1944 m_valueBitmap
= bmpNew
;
1948 m_valueBitmap
= new wxBitmap(bmp
);
1951 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1955 m_valueBitmap
= NULL
;
1956 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1961 wxPGProperty
* wxPGProperty::GetMainParent() const
1963 const wxPGProperty
* curChild
= this;
1964 const wxPGProperty
* curParent
= m_parent
;
1966 while ( curParent
&& !curParent
->IsCategory() )
1968 curChild
= curParent
;
1969 curParent
= curParent
->m_parent
;
1972 return (wxPGProperty
*) curChild
;
1976 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
1979 // Returns last visible sub-item, recursively.
1980 if ( !IsExpanded() || !GetChildCount() )
1983 return Last()->GetLastVisibleSubItem();
1987 bool wxPGProperty::IsVisible() const
1989 const wxPGProperty
* parent
;
1991 if ( HasFlag(wxPG_PROP_HIDDEN
) )
1994 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
1996 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
2003 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
2005 wxPropertyGridPageState
* state
= GetParentState();
2008 wxPropertyGrid
* propGrid
= state
->GetGrid();
2009 if ( state
== propGrid
->GetState() )
2015 int wxPGProperty::GetY2( int lh
) const
2017 const wxPGProperty
* parent
;
2018 const wxPGProperty
* child
= this;
2022 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2024 if ( !parent
->IsExpanded() )
2026 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2031 y
-= lh
; // need to reduce one level
2037 int wxPGProperty::GetY() const
2039 return GetY2(GetGrid()->GetRowHeight());
2042 // This is used by Insert etc.
2043 void wxPGProperty::DoAddChild( wxPGProperty
* prop
, int index
,
2046 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2048 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2049 m_children
.push_back( prop
);
2053 m_children
.insert( m_children
.begin()+index
, prop
);
2054 if ( correct_mode
) FixIndicesOfChildren( index
);
2057 prop
->m_parent
= this;
2060 void wxPGProperty::DoPreAddChild( int index
, wxPGProperty
* prop
)
2062 wxASSERT_MSG( prop
->GetBaseName().length(),
2063 "Property's children must have unique, non-empty "
2064 "names within their scope" );
2066 prop
->m_arrIndex
= index
;
2067 m_children
.insert( m_children
.begin()+index
,
2070 int custImgHeight
= prop
->OnMeasureImage().y
;
2071 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2072 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2074 prop
->m_parent
= this;
2077 void wxPGProperty::AddPrivateChild( wxPGProperty
* prop
)
2079 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2080 SetParentalType(wxPG_PROP_AGGREGATE
);
2082 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2083 wxPG_PROP_AGGREGATE
,
2084 "Do not mix up AddPrivateChild() calls with other "
2085 "property adders." );
2087 DoPreAddChild( m_children
.size(), prop
);
2090 #if wxPG_COMPATIBILITY_1_4
2091 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2093 AddPrivateChild(prop
);
2097 wxPGProperty
* wxPGProperty::InsertChild( int index
,
2098 wxPGProperty
* childProperty
)
2101 index
= m_children
.size();
2103 if ( m_parentState
)
2105 m_parentState
->DoInsert(this, index
, childProperty
);
2109 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2110 SetParentalType(wxPG_PROP_MISC_PARENT
);
2112 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2113 wxPG_PROP_MISC_PARENT
,
2114 "Do not mix up AddPrivateChild() calls with other "
2115 "property adders." );
2117 DoPreAddChild( index
, childProperty
);
2120 return childProperty
;
2123 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2125 wxArrayPGProperty::iterator it
;
2126 wxArrayPGProperty
& children
= m_children
;
2128 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2138 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2140 wxASSERT( GetChildCount() );
2141 wxASSERT( !IsCategory() );
2143 *value
= GetValue();
2145 if ( !list
.GetCount() )
2148 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2150 bool allChildrenSpecified
;
2152 // Don't fully update aggregate properties unless all children have
2154 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2155 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2157 allChildrenSpecified
= true;
2159 wxVariant childValue
= list
[0];
2163 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2165 for ( i
=0; i
<GetChildCount(); i
++ )
2167 const wxPGProperty
* child
= Item(i
);
2169 if ( childValue
.GetName() == child
->GetBaseName() )
2171 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2173 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2175 wxVariant
cv2(child
->GetValue());
2176 child
->AdaptListToValue(childValue
, &cv2
);
2180 if ( allChildrenSpecified
)
2182 *value
= ChildChanged(*value
, i
, childValue
);
2186 if ( n
== (unsigned int)list
.GetCount() )
2188 childValue
= list
[n
];
2194 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2197 for ( i
=starthere
;i
<GetChildCount();i
++)
2198 Item(i
)->m_arrIndex
= i
;
2202 // Returns (direct) child property with given name (or NULL if not found)
2203 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2207 for ( i
=0; i
<GetChildCount(); i
++ )
2209 wxPGProperty
* p
= Item(i
);
2210 if ( p
->m_name
== name
)
2214 // Does it have point, then?
2215 int pos
= name
.Find(wxS('.'));
2219 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2221 if ( !p
|| !p
->GetChildCount() )
2224 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2227 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2229 unsigned int i
= hintIndex
;
2231 if ( i
>= GetChildCount() )
2234 unsigned int lastIndex
= i
- 1;
2236 if ( lastIndex
>= GetChildCount() )
2237 lastIndex
= GetChildCount() - 1;
2241 wxPGProperty
* p
= Item(i
);
2242 if ( p
->m_name
== name
)
2245 if ( i
== lastIndex
)
2249 if ( i
== GetChildCount() )
2256 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2258 // Returns height of children, recursively, and
2259 // by taking expanded/collapsed status into account.
2261 // iMax is used when finding property y-positions.
2267 iMax_
= GetChildCount();
2269 unsigned int iMax
= iMax_
;
2271 wxASSERT( iMax
<= GetChildCount() );
2273 if ( !IsExpanded() && GetParent() )
2278 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2280 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2282 if ( !pwc
->IsExpanded() ||
2283 pwc
->GetChildCount() == 0 )
2286 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2295 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
,
2297 unsigned int* nextItemY
) const
2299 wxASSERT( nextItemY
);
2301 // Linear search at the moment
2303 // nextItemY = y of next visible property, final value will be written back.
2304 wxPGProperty
* result
= NULL
;
2305 wxPGProperty
* current
= NULL
;
2306 unsigned int iy
= *nextItemY
;
2308 unsigned int iMax
= GetChildCount();
2312 wxPGProperty
* pwc
= Item(i
);
2314 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2325 if ( pwc
->IsExpanded() &&
2326 pwc
->GetChildCount() > 0 )
2328 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2340 if ( !result
&& y
< iy
)
2348 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2352 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2356 return (wxPGProperty
*) result
;
2359 void wxPGProperty::Empty()
2362 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2364 for ( i
=0; i
<GetChildCount(); i
++ )
2366 delete m_children
[i
];
2373 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
) const
2375 unsigned int nextItem
;
2376 return GetItemAtY( y
, GetGrid()->GetRowHeight(), &nextItem
);
2379 void wxPGProperty::DeleteChildren()
2381 wxPropertyGridPageState
* state
= m_parentState
;
2383 while ( GetChildCount() )
2385 wxPGProperty
* child
= Item(GetChildCount()-1);
2386 state
->DoDelete(child
, true);
2390 wxVariant
wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2391 int WXUNUSED(childIndex
),
2392 wxVariant
& WXUNUSED(childValue
) ) const
2394 return wxNullVariant
;
2397 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2401 const wxVariantList
* pList
= NULL
;
2402 wxVariantList::const_iterator node
;
2406 pList
= &pendingList
->GetList();
2407 node
= pList
->begin();
2410 for ( i
=0; i
<GetChildCount(); i
++ )
2412 wxPGProperty
* child
= Item(i
);
2413 const wxVariant
* listValue
= NULL
;
2418 const wxString
& childName
= child
->GetBaseName();
2420 for ( ; node
!= pList
->end(); ++node
)
2422 const wxVariant
& item
= *((const wxVariant
*)*node
);
2423 if ( item
.GetName() == childName
)
2433 value
= child
->GetValue();
2435 if ( value
.IsNull() )
2438 // Check recursively
2439 if ( child
->GetChildCount() )
2441 const wxVariant
* childList
= NULL
;
2443 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2444 childList
= listValue
;
2446 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2454 wxPGProperty
* wxPGProperty::UpdateParentValues()
2456 wxPGProperty
* parent
= m_parent
;
2457 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2458 !parent
->IsCategory() && !parent
->IsRoot() )
2461 parent
->DoGenerateComposedValue(s
);
2462 parent
->m_value
= s
;
2463 return parent
->UpdateParentValues();
2468 bool wxPGProperty::IsTextEditable() const
2470 if ( HasFlag(wxPG_PROP_READONLY
) )
2473 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2475 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2482 // Call after fixed sub-properties added/removed after creation.
2483 // if oldSelInd >= 0 and < new max items, then selection is
2484 // moved to it. Note: oldSelInd -2 indicates that this property
2485 // should be selected.
2486 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2488 wxPropertyGridPageState
* state
= GetParentState();
2489 wxPropertyGrid
* grid
= state
->GetGrid();
2492 // Re-repare children (recursively)
2493 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2495 wxPGProperty
* child
= Item(i
);
2496 child
->InitAfterAdded(state
, grid
);
2499 wxPGProperty
* sel
= NULL
;
2500 if ( oldSelInd
>= (int)m_children
.size() )
2501 oldSelInd
= (int)m_children
.size() - 1;
2503 if ( oldSelInd
>= 0 )
2504 sel
= m_children
[oldSelInd
];
2505 else if ( oldSelInd
== -2 )
2509 state
->DoSelectProperty(sel
);
2511 if ( state
== grid
->GetState() )
2513 grid
->GetPanel()->Refresh();
2517 // -----------------------------------------------------------------------
2519 // -----------------------------------------------------------------------
2521 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2522 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2525 wxPGRootProperty::wxPGRootProperty( const wxString
& name
)
2535 wxPGRootProperty::~wxPGRootProperty()
2540 // -----------------------------------------------------------------------
2541 // wxPropertyCategory
2542 // -----------------------------------------------------------------------
2544 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2545 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2547 void wxPropertyCategory::Init()
2549 // don't set colour - prepareadditem method should do this
2550 SetParentalType(wxPG_PROP_CATEGORY
);
2551 m_capFgColIndex
= 1;
2555 wxPropertyCategory::wxPropertyCategory()
2562 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2563 : wxPGProperty(label
,name
)
2569 wxPropertyCategory::~wxPropertyCategory()
2574 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2575 int WXUNUSED(argFlags
) ) const
2577 return wxEmptyString
;
2580 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2582 if ( m_textExtent
> 0 )
2583 return m_textExtent
;
2585 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2589 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2592 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2596 // -----------------------------------------------------------------------
2598 // -----------------------------------------------------------------------
2600 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
2604 wxPGChoiceEntry
entry(label
, value
);
2605 return m_data
->Insert( -1, entry
);
2608 // -----------------------------------------------------------------------
2610 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
2614 wxPGChoiceEntry
entry(label
, value
);
2615 entry
.SetBitmap(bitmap
);
2616 return m_data
->Insert( -1, entry
);
2619 // -----------------------------------------------------------------------
2621 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
2625 return m_data
->Insert( index
, entry
);
2628 // -----------------------------------------------------------------------
2630 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
2634 wxPGChoiceEntry
entry(label
, value
);
2635 return m_data
->Insert( index
, entry
);
2638 // -----------------------------------------------------------------------
2640 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
2646 while ( index
< GetCount() )
2648 int cmpRes
= GetLabel(index
).Cmp(label
);
2654 wxPGChoiceEntry
entry(label
, value
);
2655 return m_data
->Insert( index
, entry
);
2658 // -----------------------------------------------------------------------
2660 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
2664 unsigned int itemcount
= 0;
2665 const wxChar
** p
= &labels
[0];
2666 while ( *p
) { p
++; itemcount
++; }
2669 for ( i
= 0; i
< itemcount
; i
++ )
2674 wxPGChoiceEntry
entry(labels
[i
], value
);
2675 m_data
->Insert( i
, entry
);
2679 // -----------------------------------------------------------------------
2681 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
2686 unsigned int itemcount
= arr
.size();
2688 for ( i
= 0; i
< itemcount
; i
++ )
2691 if ( &arrint
&& arrint
.size() )
2693 wxPGChoiceEntry
entry(arr
[i
], value
);
2694 m_data
->Insert( i
, entry
);
2698 // -----------------------------------------------------------------------
2700 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
2704 wxASSERT( m_data
->GetRefCount() != -1 );
2705 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
2706 m_data
->m_items
.begin()+nIndex
+count
);
2709 // -----------------------------------------------------------------------
2711 void wxPGChoices::Clear()
2713 if ( m_data
!= wxPGChoicesEmptyData
)
2720 // -----------------------------------------------------------------------
2722 int wxPGChoices::Index( const wxString
& str
) const
2727 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2729 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2730 if ( entry
.HasText() && entry
.GetText() == str
)
2737 // -----------------------------------------------------------------------
2739 int wxPGChoices::Index( int val
) const
2744 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2746 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2747 if ( entry
.GetValue() == val
)
2754 // -----------------------------------------------------------------------
2756 wxArrayString
wxPGChoices::GetLabels() const
2761 if ( this && IsOk() )
2762 for ( i
=0; i
<GetCount(); i
++ )
2763 arr
.push_back(GetLabel(i
));
2768 // -----------------------------------------------------------------------
2770 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
2777 for ( i
=0; i
< strings
.size(); i
++ )
2779 int index
= Index(strings
[i
]);
2781 arr
.Add(GetValue(index
));
2783 arr
.Add(wxPG_INVALID_VALUE
);
2790 // -----------------------------------------------------------------------
2792 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
2793 wxArrayString
* unmatched
) const
2800 for ( i
=0; i
< strings
.size(); i
++ )
2802 const wxString
& str
= strings
[i
];
2803 int index
= Index(str
);
2806 else if ( unmatched
)
2807 unmatched
->Add(str
);
2814 // -----------------------------------------------------------------------
2816 void wxPGChoices::AllocExclusive()
2820 if ( m_data
->GetRefCount() != 1 )
2822 wxPGChoicesData
* data
= new wxPGChoicesData();
2823 data
->CopyDataFrom(m_data
);
2829 // -----------------------------------------------------------------------
2831 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
2835 if ( data
!= wxPGChoicesEmptyData
)
2842 // -----------------------------------------------------------------------
2844 void wxPGChoices::Init()
2846 m_data
= wxPGChoicesEmptyData
;
2849 // -----------------------------------------------------------------------
2851 void wxPGChoices::Free()
2853 if ( m_data
!= wxPGChoicesEmptyData
)
2856 m_data
= wxPGChoicesEmptyData
;
2860 // -----------------------------------------------------------------------
2861 // wxPGAttributeStorage
2862 // -----------------------------------------------------------------------
2864 wxPGAttributeStorage::wxPGAttributeStorage()
2868 wxPGAttributeStorage::~wxPGAttributeStorage()
2870 wxPGHashMapS2P::iterator it
;
2872 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
2874 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2879 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2881 wxVariantData
* data
= value
.GetData();
2884 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2885 if ( it
!= m_map
.end() )
2887 ((wxVariantData
*)it
->second
)->DecRef();
2891 // If Null variant, just remove from set
2905 #endif // wxUSE_PROPGRID