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 licence
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 const wxColour
& bgCol
= cell
.GetBgCol();
143 if ( !(flags
& DontUseCellFgCol
) )
145 dc
.SetTextForeground(cell
.GetFgCol());
148 // Draw Background, but only if not rendering in control
149 // (as control already has rendered correct background).
150 if ( !(flags
& (Control
|ChoicePopup
)) )
151 dc
.DrawRectangle(rect
);
153 // Use cell font, if provided
154 const wxFont
& font
= cell
.GetFont();
158 const wxBitmap
& bmp
= cell
.GetBitmap();
160 // Do not draw oversized bitmap outside choice popup
161 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
165 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
166 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
168 imageWidth
= bmp
.GetWidth();
174 void wxPGCellRenderer::PostDrawCell( wxDC
& dc
,
175 const wxPropertyGrid
* propGrid
,
176 const wxPGCell
& cell
,
177 int WXUNUSED(flags
) ) const
180 const wxFont
& font
= cell
.GetFont();
182 dc
.SetFont(propGrid
->GetFont());
185 // -----------------------------------------------------------------------
186 // wxPGDefaultRenderer
187 // -----------------------------------------------------------------------
189 bool wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
190 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
191 int column
, int item
, int flags
) const
193 const wxPGEditor
* editor
= NULL
;
194 const wxPGCell
* cell
= NULL
;
197 bool isUnspecified
= property
->IsValueUnspecified();
199 if ( column
== 1 && item
== -1 )
201 int cmnVal
= property
->GetCommonValue();
205 if ( !isUnspecified
)
207 text
= propertyGrid
->GetCommonValueLabel(cmnVal
);
208 DrawText( dc
, rect
, 0, text
);
217 int preDrawFlags
= flags
;
220 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
222 imageWidth
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
226 editor
= property
->GetColumnEditor(column
);
228 if ( !isUnspecified
)
230 // Regular property value
232 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
234 wxPGPaintData paintdata
;
235 paintdata
.m_parent
= propertyGrid
;
236 paintdata
.m_choiceItem
= item
;
238 if ( imageSize
.x
> 0 )
240 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
241 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
242 wxPG_CUSTOM_IMAGE_WIDTH
,
243 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
245 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
247 paintdata
.m_drawnWidth
= imageSize
.x
;
248 paintdata
.m_drawnHeight
= imageSize
.y
;
250 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
252 imageWidth
= paintdata
.m_drawnWidth
;
255 text
= property
->GetValueAsString();
258 if ( propertyGrid
->GetColumnCount() <= 2 )
260 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
261 if ( unitsString
.length() )
262 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
266 if ( text
.length() == 0 )
268 text
= property
->GetHintText();
269 if ( text
.length() > 0 )
273 const wxColour
& hCol
=
274 propertyGrid
->GetCellDisabledTextColour();
275 dc
.SetTextForeground(hCol
);
277 // Must make the editor NULL to override it's own rendering
288 int imageOffset
= property
->GetImageOffset(imageWidth
);
290 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
292 // active caption gets nice dotted rectangle
293 if ( property
->IsCategory() && column
== 0 )
295 if ( flags
& Selected
)
297 if ( imageOffset
> 0 )
299 imageOffset
-= DEFAULT_IMAGE_OFFSET_INCREMENT
;
300 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
303 DrawCaptionSelectionRect( dc
,
304 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
305 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
306 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
307 propertyGrid
->GetCaptionFont())
308 +(wxPG_CAPRECTXMARGIN
*2),
309 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
313 PostDrawCell(dc
, propertyGrid
, *cell
, preDrawFlags
);
318 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
322 if ( property
&& column
== 1 )
326 wxBitmap
* bmp
= property
->GetValueImage();
328 if ( bmp
&& bmp
->Ok() )
329 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
335 // -----------------------------------------------------------------------
337 // -----------------------------------------------------------------------
339 wxPGCellData::wxPGCellData()
342 m_hasValidText
= false;
345 // -----------------------------------------------------------------------
347 // -----------------------------------------------------------------------
354 wxPGCell::wxPGCell( const wxString
& text
,
355 const wxBitmap
& bitmap
,
356 const wxColour
& fgCol
,
357 const wxColour
& bgCol
)
360 wxPGCellData
* data
= new wxPGCellData();
363 data
->m_bitmap
= bitmap
;
364 data
->m_fgCol
= fgCol
;
365 data
->m_bgCol
= bgCol
;
366 data
->m_hasValidText
= true;
369 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
371 wxPGCellData
* c
= new wxPGCellData();
372 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
373 c
->m_text
= o
->m_text
;
374 c
->m_bitmap
= o
->m_bitmap
;
375 c
->m_fgCol
= o
->m_fgCol
;
376 c
->m_bgCol
= o
->m_bgCol
;
377 c
->m_hasValidText
= o
->m_hasValidText
;
381 void wxPGCell::SetText( const wxString
& text
)
385 GetData()->SetText(text
);
388 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
392 GetData()->SetBitmap(bitmap
);
395 void wxPGCell::SetFgCol( const wxColour
& col
)
399 GetData()->SetFgCol(col
);
402 void wxPGCell::SetFont( const wxFont
& font
)
406 GetData()->SetFont(font
);
409 void wxPGCell::SetBgCol( const wxColour
& col
)
413 GetData()->SetBgCol(col
);
416 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
420 wxPGCellData
* data
= GetData();
422 if ( srcCell
.HasText() )
423 data
->SetText(srcCell
.GetText());
425 if ( srcCell
.GetFgCol().IsOk() )
426 data
->SetFgCol(srcCell
.GetFgCol());
428 if ( srcCell
.GetBgCol().IsOk() )
429 data
->SetBgCol(srcCell
.GetBgCol());
431 if ( srcCell
.GetBitmap().IsOk() )
432 data
->SetBitmap(srcCell
.GetBitmap());
435 void wxPGCell::SetEmptyData()
441 // -----------------------------------------------------------------------
443 // -----------------------------------------------------------------------
445 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
447 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
449 void wxPGProperty::Init()
455 m_parentState
= NULL
;
458 m_clientObject
= NULL
;
460 m_customEditor
= NULL
;
464 m_valueBitmap
= NULL
;
466 m_maxLen
= 0; // infinite maximum length
468 m_flags
= wxPG_PROP_PROPERTY
;
476 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
478 // We really need to check if &label and &name are NULL pointers
479 // (this can if we are called before property grid has been initalized)
481 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
484 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
487 DoSetName( m_label
);
492 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
493 wxPropertyGrid
* propgrid
)
496 // Called after property has been added to grid or page
497 // (so propgrid can be NULL, too).
499 wxPGProperty
* parent
= m_parent
;
500 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
503 // Convert invalid cells to default ones in this grid
504 for ( unsigned int i
=0; i
<m_cells
.size(); i
++ )
506 wxPGCell
& cell
= m_cells
[i
];
507 if ( cell
.IsInvalid() )
509 const wxPGCell
& propDefCell
= propgrid
->GetPropertyDefaultCell();
510 const wxPGCell
& catDefCell
= propgrid
->GetCategoryDefaultCell();
512 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
519 m_parentState
= pageState
;
521 #if wxPG_COMPATIBILITY_1_4
522 // Make sure deprecated virtual functions are not implemented
523 wxString s
= GetValueAsString( 0xFFFF );
524 wxASSERT_MSG( s
== g_invalidStringContent
,
525 "Implement ValueToString() instead of GetValueAsString()" );
528 if ( !parentIsRoot
&& !parent
->IsCategory() )
530 m_cells
= parent
->m_cells
;
533 // If in hideable adding mode, or if assigned parent is hideable, then
534 // make this one hideable.
536 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
537 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
539 SetFlag( wxPG_PROP_HIDDEN
);
541 // Set custom image flag.
542 int custImgHeight
= OnMeasureImage().y
;
543 if ( custImgHeight
< 0 )
545 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
548 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
549 SetFlag(wxPG_PROP_NOEDITOR
);
551 // Make sure parent has some parental flags
552 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
553 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
557 // This is not a category.
561 unsigned char depth
= 1;
564 depth
= parent
->m_depth
;
565 if ( !parent
->IsCategory() )
569 unsigned char greyDepth
= depth
;
573 wxPropertyCategory
* pc
;
575 if ( parent
->IsCategory() )
576 pc
= (wxPropertyCategory
* ) parent
;
578 // This conditional compile is necessary to
579 // bypass some compiler bug.
580 pc
= pageState
->GetPropertyCategory(parent
);
583 greyDepth
= pc
->GetDepth();
585 greyDepth
= parent
->m_depthBgCol
;
588 m_depthBgCol
= greyDepth
;
592 // This is a category.
595 unsigned char depth
= 1;
598 depth
= parent
->m_depth
+ 1;
601 m_depthBgCol
= depth
;
605 // Has initial children
606 if ( GetChildCount() )
608 // Check parental flags
609 wxASSERT_MSG( ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
610 wxPG_PROP_AGGREGATE
) ||
611 ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
612 wxPG_PROP_MISC_PARENT
),
613 "wxPGProperty parental flags set incorrectly at "
616 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
618 // Properties with private children are not expanded by default.
621 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
623 // ...unless it cannot be expanded by user and therefore must
624 // remain visible at all times
629 // Prepare children recursively
630 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
632 wxPGProperty
* child
= Item(i
);
633 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
636 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
637 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
641 void wxPGProperty::OnDetached(wxPropertyGridPageState
* WXUNUSED(state
),
642 wxPropertyGrid
* propgrid
)
646 const wxPGCell
& propDefCell
= propgrid
->GetPropertyDefaultCell();
647 const wxPGCell
& catDefCell
= propgrid
->GetCategoryDefaultCell();
649 // Make default cells invalid
650 for ( unsigned int i
=0; i
<m_cells
.size(); i
++ )
652 wxPGCell
& cell
= m_cells
[i
];
653 if ( cell
.IsSameAs(propDefCell
) ||
654 cell
.IsSameAs(catDefCell
) )
662 wxPGProperty::wxPGProperty()
669 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
676 wxPGProperty::~wxPGProperty()
678 delete m_clientObject
;
680 Empty(); // this deletes items
682 delete m_valueBitmap
;
687 // This makes it easier for us to detect dangling pointers
692 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
694 wxPGProperty
* parent
= m_parent
;
697 if ( parent
== candidate
)
699 parent
= parent
->m_parent
;
704 void wxPGProperty::SetName( const wxString
& newName
)
706 wxPropertyGrid
* pg
= GetGrid();
709 pg
->SetPropertyName(this, newName
);
714 wxString
wxPGProperty::GetName() const
716 wxPGProperty
* parent
= GetParent();
718 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
721 return m_parent
->GetName() + wxS(".") + m_name
;
724 wxPropertyGrid
* wxPGProperty::GetGrid() const
726 if ( !m_parentState
)
728 return m_parentState
->GetGrid();
731 int wxPGProperty::Index( const wxPGProperty
* p
) const
733 return wxPGFindInVector(m_children
, p
);
736 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
741 void wxPGProperty::OnSetValue()
745 void wxPGProperty::RefreshChildren ()
749 void wxPGProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
753 void wxPGProperty::GetDisplayInfo( unsigned int column
,
757 const wxPGCell
** pCell
)
759 const wxPGCell
* cell
= NULL
;
761 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
763 // Not painting list of choice popups, so get text from property
764 if ( column
!= 1 || !IsValueUnspecified() || IsCategory() )
766 cell
= &GetCell(column
);
770 // Use special unspecified value cell
771 cell
= &GetGrid()->GetUnspecifiedValueAppearance();
774 if ( cell
->HasText() )
776 *pString
= cell
->GetText();
781 *pString
= GetLabel();
782 else if ( column
== 1 )
783 *pString
= GetDisplayedString();
784 else if ( column
== 2 )
785 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
790 wxASSERT( column
== 1 );
792 if ( choiceIndex
!= wxNOT_FOUND
)
794 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
795 if ( entry
.GetBitmap().IsOk() ||
796 entry
.GetFgCol().IsOk() ||
797 entry
.GetBgCol().IsOk() )
799 *pString
= m_choices
.GetLabel(choiceIndex
);
804 cell
= &GetCell(column
);
806 wxASSERT_MSG( cell
->GetData(),
807 wxString::Format("Invalid cell for property %s",
808 GetName().c_str()) );
814 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
817 if ( col != 1 || choiceIndex == wxNOT_FOUND )
819 const wxPGCell& cell = GetCell(col);
820 if ( cell->HasText() )
822 return cell->GetText();
829 return GetDisplayedString();
831 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
837 return m_choices.GetLabel(choiceIndex);
840 return wxEmptyString;
844 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
846 const wxVariantList
* valueOverrides
,
847 wxPGHashMapS2S
* childResults
) const
850 int iMax
= m_children
.size();
856 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
857 !(argFlags
& wxPG_FULL_VALUE
) )
858 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
860 int iMaxMinusOne
= iMax
-1;
862 if ( !IsTextEditable() )
863 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
865 wxPGProperty
* curChild
= m_children
[0];
867 bool overridesLeft
= false;
868 wxVariant overrideValue
;
869 wxVariantList::const_iterator node
;
871 if ( valueOverrides
)
873 node
= valueOverrides
->begin();
874 if ( node
!= valueOverrides
->end() )
876 overrideValue
= *node
;
877 overridesLeft
= true;
881 for ( i
= 0; i
< iMax
; i
++ )
883 wxVariant childValue
;
885 wxString childLabel
= curChild
->GetLabel();
887 // Check for value override
888 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
890 if ( !overrideValue
.IsNull() )
891 childValue
= overrideValue
;
893 childValue
= curChild
->GetValue();
895 if ( node
!= valueOverrides
->end() )
896 overrideValue
= *node
;
898 overridesLeft
= false;
902 childValue
= curChild
->GetValue();
906 if ( !childValue
.IsNull() )
908 if ( overridesLeft
&&
909 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
910 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
912 wxVariantList
& childList
= childValue
.GetList();
913 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
914 &childList
, childResults
);
918 s
= curChild
->ValueToString(childValue
,
919 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
923 if ( childResults
&& curChild
->GetChildCount() )
924 (*childResults
)[curChild
->GetName()] = s
;
927 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
930 if ( !curChild
->GetChildCount() || skip
)
933 text
+= wxS("[") + s
+ wxS("]");
935 if ( i
< iMaxMinusOne
)
937 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
938 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
939 !(argFlags
& wxPG_FULL_VALUE
) )
944 if ( !curChild
->GetChildCount() )
950 curChild
= m_children
[i
+1];
954 if ( (unsigned int)i
< m_children
.size() )
956 if ( !text
.EndsWith(wxS("; ")) )
957 text
+= wxS("; ...");
963 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
966 wxCHECK_MSG( GetChildCount() > 0,
968 "If user property does not have any children, it must "
969 "override GetValueAsString" );
971 // FIXME: Currently code below only works if value is actually m_value
972 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
973 "Sorry, currently default wxPGProperty::ValueToString() "
974 "implementation only works if value is m_value." );
977 DoGenerateComposedValue(text
, argFlags
);
981 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
983 #if wxPG_COMPATIBILITY_1_4
984 // This is backwards compatibility test
985 // That is, to make sure this function is not overridden
986 // (instead, ValueToString() should be).
987 if ( argFlags
== 0xFFFF )
989 // Do not override! (for backwards compliancy)
990 return g_invalidStringContent
;
994 wxPropertyGrid
* pg
= GetGrid();
996 if ( IsValueUnspecified() )
997 return pg
->GetUnspecifiedValueText(argFlags
);
999 if ( m_commonValue
== -1 )
1001 wxVariant
value(GetValue());
1002 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
1006 // Return common value's string representation
1007 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
1009 if ( argFlags
& wxPG_FULL_VALUE
)
1011 return cv
->GetLabel();
1013 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
1015 return cv
->GetEditableText();
1019 return cv
->GetLabel();
1023 wxString
wxPGProperty::GetValueString( int argFlags
) const
1025 return GetValueAsString(argFlags
);
1028 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1030 variant
= (long)number
;
1034 // Convert semicolon delimited tokens into child values.
1035 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1037 if ( !GetChildCount() )
1040 unsigned int curChild
= 0;
1042 unsigned int iMax
= m_children
.size();
1044 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
1045 !(argFlags
& wxPG_FULL_VALUE
) )
1046 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
1048 bool changed
= false;
1053 // Its best only to add non-empty group items
1054 bool addOnlyIfNotEmpty
= false;
1055 const wxChar delimeter
= wxS(';');
1057 size_t tokenStart
= 0xFFFFFF;
1059 wxVariantList temp_list
;
1060 wxVariant
list(temp_list
);
1062 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
1064 wxLogTrace("propgrid",
1065 wxT(">> %s.StringToValue('%s')"), GetLabel(), text
);
1067 wxString::const_iterator it
= text
.begin();
1070 if ( it
!= text
.end() )
1077 // How many units we iterate string forward at the end of loop?
1078 // We need to keep track of this or risk going to negative
1079 // with it-- operation.
1080 unsigned int strPosIncrement
= 1;
1082 if ( tokenStart
!= 0xFFFFFF )
1085 if ( a
== delimeter
|| a
== 0 )
1087 token
= text
.substr(tokenStart
,pos
-tokenStart
);
1089 size_t len
= token
.length();
1091 if ( !addOnlyIfNotEmpty
|| len
> 0 )
1093 const wxPGProperty
* child
= Item(curChild
);
1094 wxVariant
variant(child
->GetValue());
1095 wxString childName
= child
->GetBaseName();
1097 wxLogTrace("propgrid",
1098 wxT("token = '%s', child = %s"),
1101 // Add only if editable or setting programmatically
1102 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1103 (!child
->HasFlag(wxPG_PROP_DISABLED
) &&
1104 !child
->HasFlag(wxPG_PROP_READONLY
)) )
1108 if ( child
->StringToValue(variant
, token
,
1109 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1111 // We really need to set the variant's name
1112 // *after* child->StringToValue() has been
1113 // called, since variant's value may be set by
1114 // assigning another variant into it, which
1115 // then usually causes name to be copied (ie.
1116 // usually cleared) as well. wxBoolProperty
1117 // being case in point with its use of
1118 // wxPGVariant_Bool macro as an optimization.
1119 variant
.SetName(childName
);
1120 list
.Append(variant
);
1127 // Empty, becomes unspecified
1129 variant
.SetName(childName
);
1130 list
.Append(variant
);
1136 if ( curChild
>= iMax
)
1140 tokenStart
= 0xFFFFFF;
1145 // Token is not running
1146 if ( a
!= wxS(' ') )
1149 addOnlyIfNotEmpty
= false;
1151 // Is this a group of tokens?
1152 if ( a
== wxS('[') )
1156 if ( it
!= text
.end() ) ++it
;
1158 size_t startPos
= pos
;
1160 // Group item - find end
1161 while ( it
!= text
.end() && depth
> 0 )
1167 if ( a
== wxS(']') )
1169 else if ( a
== wxS('[') )
1173 token
= text
.substr(startPos
,pos
-startPos
-1);
1175 if ( !token
.length() )
1178 const wxPGProperty
* child
= Item(curChild
);
1180 wxVariant oldChildValue
= child
->GetValue();
1181 wxVariant
variant(oldChildValue
);
1183 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1184 (!child
->HasFlag(wxPG_PROP_DISABLED
) &&
1185 !child
->HasFlag(wxPG_PROP_READONLY
)) )
1187 wxString childName
= child
->GetBaseName();
1189 bool stvRes
= child
->StringToValue( variant
, token
,
1191 if ( stvRes
|| (variant
!= oldChildValue
) )
1193 variant
.SetName(childName
);
1194 list
.Append(variant
);
1205 if ( curChild
>= iMax
)
1208 addOnlyIfNotEmpty
= true;
1210 tokenStart
= 0xFFFFFF;
1216 if ( a
== delimeter
)
1217 strPosIncrement
-= 1;
1225 it
+= strPosIncrement
;
1227 if ( it
!= text
.end() )
1236 pos
+= strPosIncrement
;
1245 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1247 wxVariant
variant(m_value
);
1248 bool res
= StringToValue(variant
, text
, argFlags
);
1254 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1256 wxVariant
variant(m_value
);
1257 bool res
= IntToValue(variant
, number
, argFlags
);
1263 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1265 if ( m_valueBitmap
)
1266 return wxSize(m_valueBitmap
->GetWidth(),-1);
1271 int wxPGProperty::GetImageOffset( int imageWidth
) const
1273 int imageOffset
= 0;
1277 // Do not increment offset too much for wide images
1278 if ( imageWidth
<= (wxPG_CUSTOM_IMAGE_WIDTH
+5) )
1279 imageOffset
= imageWidth
+ DEFAULT_IMAGE_OFFSET_INCREMENT
;
1281 imageOffset
= imageWidth
+ 1;
1287 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1289 return wxPGGlobalVars
->m_defaultRenderer
;
1292 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1296 wxBitmap
* bmp
= m_valueBitmap
;
1298 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1300 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1302 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1305 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1307 return wxPGEditor_TextCtrl
;
1310 // Default extra property event handling - that is, none at all.
1311 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1317 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1319 // If auto unspecified values are not wanted (via window or property style),
1320 // then get default value instead of wxNullVariant.
1321 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1322 !UsesAutoUnspecified() )
1324 value
= GetDefaultValue();
1327 if ( !value
.IsNull() )
1329 wxVariant tempListVariant
;
1332 // List variants are reserved a special purpose
1333 // as intermediate containers for child values
1334 // of properties with children.
1335 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1338 // However, situation is different for composed string properties
1339 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1341 tempListVariant
= value
;
1342 pList
= &tempListVariant
;
1346 AdaptListToValue(value
, &newValue
);
1348 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1351 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1352 flags
|= wxPG_SETVAL_AGGREGATED
;
1354 if ( pList
&& !pList
->IsNull() )
1356 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1357 wxASSERT( GetChildCount() );
1358 wxASSERT( !IsCategory() );
1360 wxVariantList
& list
= pList
->GetList();
1361 wxVariantList::iterator node
;
1364 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1366 // Children in list can be in any order, but we will give hint to
1367 // GetPropertyByNameWH(). This optimizes for full list parsing.
1368 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1370 wxVariant
& childValue
= *((wxVariant
*)*node
);
1371 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1374 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1375 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1377 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1379 wxVariant listRefCopy
= childValue
;
1380 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1384 wxVariant oldVal
= child
->GetValue();
1385 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1388 else if ( child
->GetValue() != childValue
)
1390 // For aggregate properties, we will trust RefreshChildren()
1391 // to update child values.
1392 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1393 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1394 if ( flags
& wxPG_SETVAL_BY_USER
)
1395 child
->SetFlag(wxPG_PROP_MODIFIED
);
1401 // Always call OnSetValue() for a parent property (do not call it
1402 // here if the value is non-null because it will then be called
1404 if ( value
.IsNull() )
1408 if ( !value
.IsNull() )
1414 if ( flags
& wxPG_SETVAL_BY_USER
)
1415 SetFlag(wxPG_PROP_MODIFIED
);
1417 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1422 if ( m_commonValue
!= -1 )
1424 wxPropertyGrid
* pg
= GetGrid();
1425 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1431 // Set children to unspecified, but only if aggregate or
1432 // value is <composed>
1433 if ( AreChildrenComponents() )
1436 for ( i
=0; i
<GetChildCount(); i
++ )
1437 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1441 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1442 UpdateParentValues();
1445 // Update editor control.
1446 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1448 wxPropertyGrid
* pg
= GetGridIfDisplayed();
1451 wxPGProperty
* selected
= pg
->GetSelectedProperty();
1453 // Only refresh the control if this was selected, or
1454 // this was some parent of selected, or vice versa)
1455 if ( selected
&& (selected
== this ||
1456 selected
->IsSomeParent(this) ||
1457 this->IsSomeParent(selected
)) )
1460 pg
->DrawItemAndValueRelated(this);
1466 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1468 GetGrid()->ValueChangeInEvent(value
);
1471 void wxPGProperty::SetFlagRecursively( wxPGPropertyFlags flag
, bool set
)
1473 ChangeFlag(flag
, set
);
1476 for ( i
= 0; i
< GetChildCount(); i
++ )
1477 Item(i
)->SetFlagRecursively(flag
, set
);
1480 void wxPGProperty::RefreshEditor()
1485 wxPropertyGrid
* pg
= GetGrid();
1486 if ( pg
&& pg
->GetSelectedProperty() == this )
1487 pg
->RefreshEditor();
1490 wxVariant
wxPGProperty::GetDefaultValue() const
1492 wxVariant defVal
= GetAttribute(wxPG_ATTR_DEFAULT_VALUE
);
1493 if ( !defVal
.IsNull() )
1496 wxVariant value
= GetValue();
1498 if ( !value
.IsNull() )
1500 wxString
valueType(value
.GetType());
1502 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1503 return wxPGVariant_Zero
;
1504 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1505 return wxPGVariant_EmptyString
;
1506 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1507 return wxPGVariant_False
;
1508 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1509 return wxVariant(0.0);
1510 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1511 return wxVariant(wxArrayString());
1512 if ( valueType
== wxS("wxLongLong") )
1513 return WXVARIANT(wxLongLong(0));
1514 if ( valueType
== wxS("wxULongLong") )
1515 return WXVARIANT(wxULongLong(0));
1516 if ( valueType
== wxS("wxColour") )
1517 return WXVARIANT(*wxBLACK
);
1519 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1520 return wxVariant(wxDateTime::Now());
1522 if ( valueType
== wxS("wxFont") )
1523 return WXVARIANT(*wxNORMAL_FONT
);
1524 if ( valueType
== wxS("wxPoint") )
1525 return WXVARIANT(wxPoint(0, 0));
1526 if ( valueType
== wxS("wxSize") )
1527 return WXVARIANT(wxSize(0, 0));
1533 void wxPGProperty::Enable( bool enable
)
1535 wxPropertyGrid
* pg
= GetGrid();
1537 // Preferably call the version in the owning wxPropertyGrid,
1538 // since it handles the editor de-activation.
1540 pg
->EnableProperty(this, enable
);
1545 void wxPGProperty::DoEnable( bool enable
)
1548 ClearFlag(wxPG_PROP_DISABLED
);
1550 SetFlag(wxPG_PROP_DISABLED
);
1552 // Apply same to sub-properties as well
1554 for ( i
= 0; i
< GetChildCount(); i
++ )
1555 Item(i
)->DoEnable( enable
);
1558 void wxPGProperty::EnsureCells( unsigned int column
)
1560 if ( column
>= m_cells
.size() )
1562 // Fill empty slots with default cells
1563 wxPropertyGrid
* pg
= GetGrid();
1564 wxPGCell defaultCell
;
1568 // Work around possible VC6 bug by using intermediate variables
1569 const wxPGCell
& propDefCell
= pg
->GetPropertyDefaultCell();
1570 const wxPGCell
& catDefCell
= pg
->GetCategoryDefaultCell();
1572 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1573 defaultCell
= propDefCell
;
1575 defaultCell
= catDefCell
;
1578 // TODO: Replace with resize() call
1579 unsigned int cellCountMax
= column
+1;
1581 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1582 m_cells
.push_back(defaultCell
);
1586 void wxPGProperty::SetCell( int column
,
1587 const wxPGCell
& cell
)
1589 EnsureCells(column
);
1591 m_cells
[column
] = cell
;
1594 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1595 unsigned int lastCol
,
1596 const wxPGCell
& cell
,
1597 const wxPGCell
& srcData
,
1598 wxPGCellData
* unmodCellData
,
1599 FlagType ignoreWithFlags
,
1603 // Sets cell in memory optimizing fashion. That is, if
1604 // current cell data matches unmodCellData, we will
1605 // simply get reference to data from cell. Otherwise,
1606 // cell information from srcData is merged into current.
1609 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1611 EnsureCells(lastCol
);
1613 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1615 if ( m_cells
[col
].GetData() == unmodCellData
)
1617 // Data matches... use cell directly
1618 m_cells
[col
] = cell
;
1622 // Data did not match... merge valid information
1623 m_cells
[col
].MergeFrom(srcData
);
1630 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1631 Item(i
)->AdaptiveSetCell( firstCol
,
1641 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1643 if ( m_cells
.size() > column
)
1644 return m_cells
[column
];
1646 wxPropertyGrid
* pg
= GetGrid();
1649 return pg
->GetCategoryDefaultCell();
1651 return pg
->GetPropertyDefaultCell();
1654 wxPGCell
& wxPGProperty::GetOrCreateCell( unsigned int column
)
1656 EnsureCells(column
);
1657 return m_cells
[column
];
1660 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1663 wxPGProperty
* firstProp
= this;
1664 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1667 // If category is tried to set recursively, skip it and only
1668 // affect the children.
1671 while ( firstProp
->IsCategory() )
1673 if ( !firstProp
->GetChildCount() )
1675 firstProp
= firstProp
->Item(0);
1679 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1680 wxPGCellData
* firstCellData
= firstCell
.GetData();
1682 wxPGCell
newCell(firstCell
);
1683 newCell
.SetBgCol(colour
);
1685 srcCell
.SetBgCol(colour
);
1688 GetParentState()->GetColumnCount()-1,
1692 recursively
? wxPG_PROP_CATEGORY
: 0,
1696 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1699 wxPGProperty
* firstProp
= this;
1700 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1703 // If category is tried to set recursively, skip it and only
1704 // affect the children.
1707 while ( firstProp
->IsCategory() )
1709 if ( !firstProp
->GetChildCount() )
1711 firstProp
= firstProp
->Item(0);
1715 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1716 wxPGCellData
* firstCellData
= firstCell
.GetData();
1718 wxPGCell
newCell(firstCell
);
1719 newCell
.SetFgCol(colour
);
1721 srcCell
.SetFgCol(colour
);
1724 GetParentState()->GetColumnCount()-1,
1728 recursively
? wxPG_PROP_CATEGORY
: 0,
1732 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1737 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1742 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1744 if ( DoSetAttribute( name
, value
) )
1746 // Support working without grid, when possible
1747 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1751 m_attributes
.Set( name
, value
);
1754 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1756 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1759 while ( attributes
.GetNext(it
, variant
) )
1760 SetAttribute( variant
.GetName(), variant
);
1763 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1769 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1771 return m_attributes
.FindValue(name
);
1774 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1776 wxVariant variant
= m_attributes
.FindValue(name
);
1778 if ( !variant
.IsNull() )
1779 return variant
.GetString();
1784 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1786 wxVariant variant
= m_attributes
.FindValue(name
);
1788 if ( variant
.IsNull() )
1791 return variant
.GetLong();
1794 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1796 wxVariant variant
= m_attributes
.FindValue(name
);
1798 if ( variant
.IsNull() )
1801 return variant
.GetDouble();
1804 wxVariant
wxPGProperty::GetAttributesAsList() const
1806 wxVariantList tempList
;
1807 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1809 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1812 while ( m_attributes
.GetNext(it
, variant
) )
1818 // Slots of utility flags are NULL
1819 const unsigned int gs_propFlagToStringSize
= 14;
1821 static const wxChar
* const gs_propFlagToString
[gs_propFlagToStringSize
] = {
1838 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1841 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1845 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1847 if ( relevantFlags
& a
)
1849 const wxChar
* fs
= gs_propFlagToString
[i
];
1861 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1865 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1867 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1869 const wxChar
* fs
= gs_propFlagToString
[i
];
1870 if ( fs
&& str
== fs
)
1876 WX_PG_TOKENIZER1_END()
1878 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1881 wxValidator
* wxPGProperty::DoGetValidator() const
1886 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1888 wxPropertyGrid
* pg
= GetGrid();
1889 int sel
= GetChoiceSelection();
1893 if ( index
== wxNOT_FOUND
)
1894 index
= m_choices
.GetCount();
1899 m_choices
.Insert(label
, index
, value
);
1901 if ( sel
!= newSel
)
1902 SetChoiceSelection(newSel
);
1904 if ( this == pg
->GetSelection() )
1905 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1911 void wxPGProperty::DeleteChoice( int index
)
1913 wxPropertyGrid
* pg
= GetGrid();
1915 int sel
= GetChoiceSelection();
1918 // Adjust current value
1921 SetValueToUnspecified();
1924 else if ( index
< sel
)
1929 m_choices
.RemoveAt(index
);
1931 if ( sel
!= newSel
)
1932 SetChoiceSelection(newSel
);
1934 if ( this == pg
->GetSelection() )
1935 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1938 int wxPGProperty::GetChoiceSelection() const
1940 wxVariant value
= GetValue();
1941 wxString valueType
= value
.GetType();
1942 int index
= wxNOT_FOUND
;
1944 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1947 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1949 index
= value
.GetLong();
1951 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1953 index
= m_choices
.Index(value
.GetString());
1955 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1957 index
= value
.GetBool()? 1 : 0;
1963 void wxPGProperty::SetChoiceSelection( int newValue
)
1965 // Changes value of a property with choices, but only
1966 // works if the value type is long or string.
1967 wxString valueType
= GetValue().GetType();
1969 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1971 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1973 SetValue( m_choices
.GetLabel(newValue
) );
1975 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1977 SetValue( (long) newValue
);
1981 bool wxPGProperty::SetChoices( const wxPGChoices
& choices
)
1983 // Property must be de-selected first (otherwise choices in
1984 // the control would be de-synced with true choices)
1985 wxPropertyGrid
* pg
= GetGrid();
1986 if ( pg
&& pg
->GetSelection() == this )
1987 pg
->ClearSelection();
1989 m_choices
.Assign(choices
);
1992 // This may be needed to trigger some initialization
1993 // (but don't do it if property is somewhat uninitialized)
1994 wxVariant defVal
= GetDefaultValue();
1995 if ( defVal
.IsNull() )
2005 const wxPGEditor
* wxPGProperty::GetEditorClass() const
2007 const wxPGEditor
* editor
;
2009 if ( !m_customEditor
)
2011 editor
= DoGetEditorClass();
2014 editor
= m_customEditor
;
2017 // Maybe override editor if common value specified
2018 if ( GetDisplayedCommonValueCount() )
2020 // TextCtrlAndButton -> ComboBoxAndButton
2021 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
2022 editor
= wxPGEditor_ChoiceAndButton
;
2024 // TextCtrl -> ComboBox
2025 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
2026 editor
= wxPGEditor_ComboBox
;
2032 bool wxPGProperty::Hide( bool hide
, int flags
)
2034 wxPropertyGrid
* pg
= GetGrid();
2036 return pg
->HideProperty(this, hide
, flags
);
2038 return DoHide( hide
, flags
);
2041 bool wxPGProperty::DoHide( bool hide
, int flags
)
2044 ClearFlag( wxPG_PROP_HIDDEN
);
2046 SetFlag( wxPG_PROP_HIDDEN
);
2048 if ( flags
& wxPG_RECURSE
)
2051 for ( i
= 0; i
< GetChildCount(); i
++ )
2052 Item(i
)->DoHide(hide
, flags
| wxPG_RECURSE_STARTS
);
2058 bool wxPGProperty::HasVisibleChildren() const
2062 for ( i
=0; i
<GetChildCount(); i
++ )
2064 wxPGProperty
* child
= Item(i
);
2066 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
2073 bool wxPGProperty::RecreateEditor()
2075 wxPropertyGrid
* pg
= GetGrid();
2078 wxPGProperty
* selected
= pg
->GetSelection();
2079 if ( this == selected
)
2081 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
2088 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
2090 delete m_valueBitmap
;
2092 if ( &bmp
&& bmp
.Ok() )
2095 wxSize maxSz
= GetGrid()->GetImageSize();
2096 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
2098 if ( imSz
.y
!= maxSz
.y
)
2100 // Create a memory DC
2101 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
2104 dc
.SelectObject(*bmpNew
);
2107 // FIXME: This is ugly - use image or wait for scaling patch.
2108 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
2110 dc
.SetUserScale(scaleY
, scaleY
);
2112 dc
.DrawBitmap(bmp
, 0, 0);
2114 m_valueBitmap
= bmpNew
;
2118 m_valueBitmap
= new wxBitmap(bmp
);
2121 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2125 m_valueBitmap
= NULL
;
2126 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
2131 wxPGProperty
* wxPGProperty::GetMainParent() const
2133 const wxPGProperty
* curChild
= this;
2134 const wxPGProperty
* curParent
= m_parent
;
2136 while ( curParent
&& !curParent
->IsCategory() )
2138 curChild
= curParent
;
2139 curParent
= curParent
->m_parent
;
2142 return (wxPGProperty
*) curChild
;
2146 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
2149 // Returns last visible sub-item, recursively.
2150 if ( !IsExpanded() || !GetChildCount() )
2153 return Last()->GetLastVisibleSubItem();
2157 bool wxPGProperty::IsVisible() const
2159 const wxPGProperty
* parent
;
2161 if ( HasFlag(wxPG_PROP_HIDDEN
) )
2164 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
2166 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
2173 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
2175 wxPropertyGridPageState
* state
= GetParentState();
2178 wxPropertyGrid
* propGrid
= state
->GetGrid();
2179 if ( state
== propGrid
->GetState() )
2185 int wxPGProperty::GetY2( int lh
) const
2187 const wxPGProperty
* parent
;
2188 const wxPGProperty
* child
= this;
2192 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2194 if ( !parent
->IsExpanded() )
2196 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2201 y
-= lh
; // need to reduce one level
2207 int wxPGProperty::GetY() const
2209 return GetY2(GetGrid()->GetRowHeight());
2212 // This is used by Insert etc.
2213 void wxPGProperty::DoAddChild( wxPGProperty
* prop
, int index
,
2216 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2218 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2219 m_children
.push_back( prop
);
2223 m_children
.insert( m_children
.begin()+index
, prop
);
2224 if ( correct_mode
) FixIndicesOfChildren( index
);
2227 prop
->m_parent
= this;
2230 void wxPGProperty::DoPreAddChild( int index
, wxPGProperty
* prop
)
2232 wxASSERT_MSG( prop
->GetBaseName().length(),
2233 "Property's children must have unique, non-empty "
2234 "names within their scope" );
2236 prop
->m_arrIndex
= index
;
2237 m_children
.insert( m_children
.begin()+index
,
2240 int custImgHeight
= prop
->OnMeasureImage().y
;
2241 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2242 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2244 prop
->m_parent
= this;
2247 void wxPGProperty::AddPrivateChild( wxPGProperty
* prop
)
2249 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2250 SetParentalType(wxPG_PROP_AGGREGATE
);
2252 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2253 wxPG_PROP_AGGREGATE
,
2254 "Do not mix up AddPrivateChild() calls with other "
2255 "property adders." );
2257 DoPreAddChild( m_children
.size(), prop
);
2260 #if wxPG_COMPATIBILITY_1_4
2261 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2263 AddPrivateChild(prop
);
2267 wxPGProperty
* wxPGProperty::InsertChild( int index
,
2268 wxPGProperty
* childProperty
)
2271 index
= m_children
.size();
2273 if ( m_parentState
)
2275 m_parentState
->DoInsert(this, index
, childProperty
);
2279 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2280 SetParentalType(wxPG_PROP_MISC_PARENT
);
2282 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2283 wxPG_PROP_MISC_PARENT
,
2284 "Do not mix up AddPrivateChild() calls with other "
2285 "property adders." );
2287 DoPreAddChild( index
, childProperty
);
2290 return childProperty
;
2293 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2295 wxArrayPGProperty::iterator it
;
2296 wxArrayPGProperty
& children
= m_children
;
2298 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2308 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2310 wxASSERT( GetChildCount() );
2311 wxASSERT( !IsCategory() );
2313 *value
= GetValue();
2315 if ( !list
.GetCount() )
2318 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2320 bool allChildrenSpecified
;
2322 // Don't fully update aggregate properties unless all children have
2324 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2325 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2327 allChildrenSpecified
= true;
2329 wxVariant childValue
= list
[0];
2333 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2335 for ( i
=0; i
<GetChildCount(); i
++ )
2337 const wxPGProperty
* child
= Item(i
);
2339 if ( childValue
.GetName() == child
->GetBaseName() )
2341 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2343 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2345 wxVariant
cv2(child
->GetValue());
2346 child
->AdaptListToValue(childValue
, &cv2
);
2350 if ( allChildrenSpecified
)
2352 *value
= ChildChanged(*value
, i
, childValue
);
2356 if ( n
== (unsigned int)list
.GetCount() )
2358 childValue
= list
[n
];
2364 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2367 for ( i
=starthere
;i
<GetChildCount();i
++)
2368 Item(i
)->m_arrIndex
= i
;
2372 // Returns (direct) child property with given name (or NULL if not found)
2373 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2377 for ( i
=0; i
<GetChildCount(); i
++ )
2379 wxPGProperty
* p
= Item(i
);
2380 if ( p
->m_name
== name
)
2384 // Does it have point, then?
2385 int pos
= name
.Find(wxS('.'));
2389 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2391 if ( !p
|| !p
->GetChildCount() )
2394 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2397 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2399 unsigned int i
= hintIndex
;
2401 if ( i
>= GetChildCount() )
2404 unsigned int lastIndex
= i
- 1;
2406 if ( lastIndex
>= GetChildCount() )
2407 lastIndex
= GetChildCount() - 1;
2411 wxPGProperty
* p
= Item(i
);
2412 if ( p
->m_name
== name
)
2415 if ( i
== lastIndex
)
2419 if ( i
== GetChildCount() )
2426 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2428 // Returns height of children, recursively, and
2429 // by taking expanded/collapsed status into account.
2431 // iMax is used when finding property y-positions.
2437 iMax_
= GetChildCount();
2439 unsigned int iMax
= iMax_
;
2441 wxASSERT( iMax
<= GetChildCount() );
2443 if ( !IsExpanded() && GetParent() )
2448 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2450 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2452 if ( !pwc
->IsExpanded() ||
2453 pwc
->GetChildCount() == 0 )
2456 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2465 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
,
2467 unsigned int* nextItemY
) const
2469 wxASSERT( nextItemY
);
2471 // Linear search at the moment
2473 // nextItemY = y of next visible property, final value will be written back.
2474 wxPGProperty
* result
= NULL
;
2475 wxPGProperty
* current
= NULL
;
2476 unsigned int iy
= *nextItemY
;
2478 unsigned int iMax
= GetChildCount();
2482 wxPGProperty
* pwc
= Item(i
);
2484 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2495 if ( pwc
->IsExpanded() &&
2496 pwc
->GetChildCount() > 0 )
2498 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2510 if ( !result
&& y
< iy
)
2518 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2522 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2526 return (wxPGProperty
*) result
;
2529 void wxPGProperty::Empty()
2532 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2534 for ( i
=0; i
<GetChildCount(); i
++ )
2536 delete m_children
[i
];
2543 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
) const
2545 unsigned int nextItem
;
2546 return GetItemAtY( y
, GetGrid()->GetRowHeight(), &nextItem
);
2549 void wxPGProperty::DeleteChildren()
2551 wxPropertyGridPageState
* state
= m_parentState
;
2553 if ( !GetChildCount() )
2556 // Because deletion is sometimes deferred, we have to use
2557 // this sort of code for enumerating the child properties.
2558 unsigned int i
= GetChildCount();
2562 state
->DoDelete(Item(i
), true);
2566 wxVariant
wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2567 int WXUNUSED(childIndex
),
2568 wxVariant
& WXUNUSED(childValue
) ) const
2570 return wxNullVariant
;
2573 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2577 const wxVariantList
* pList
= NULL
;
2578 wxVariantList::const_iterator node
;
2582 pList
= &pendingList
->GetList();
2583 node
= pList
->begin();
2586 for ( i
=0; i
<GetChildCount(); i
++ )
2588 wxPGProperty
* child
= Item(i
);
2589 const wxVariant
* listValue
= NULL
;
2594 const wxString
& childName
= child
->GetBaseName();
2596 for ( ; node
!= pList
->end(); ++node
)
2598 const wxVariant
& item
= *((const wxVariant
*)*node
);
2599 if ( item
.GetName() == childName
)
2609 value
= child
->GetValue();
2611 if ( value
.IsNull() )
2614 // Check recursively
2615 if ( child
->GetChildCount() )
2617 const wxVariant
* childList
= NULL
;
2619 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2620 childList
= listValue
;
2622 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2630 wxPGProperty
* wxPGProperty::UpdateParentValues()
2632 wxPGProperty
* parent
= m_parent
;
2633 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2634 !parent
->IsCategory() && !parent
->IsRoot() )
2637 parent
->DoGenerateComposedValue(s
);
2638 parent
->m_value
= s
;
2639 return parent
->UpdateParentValues();
2644 bool wxPGProperty::IsTextEditable() const
2646 if ( HasFlag(wxPG_PROP_READONLY
) )
2649 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2651 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2658 // Call after fixed sub-properties added/removed after creation.
2659 // if oldSelInd >= 0 and < new max items, then selection is
2660 // moved to it. Note: oldSelInd -2 indicates that this property
2661 // should be selected.
2662 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2664 wxPropertyGridPageState
* state
= GetParentState();
2665 wxPropertyGrid
* grid
= state
->GetGrid();
2668 // Re-repare children (recursively)
2669 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2671 wxPGProperty
* child
= Item(i
);
2672 child
->InitAfterAdded(state
, grid
);
2675 wxPGProperty
* sel
= NULL
;
2676 if ( oldSelInd
>= (int)m_children
.size() )
2677 oldSelInd
= (int)m_children
.size() - 1;
2679 if ( oldSelInd
>= 0 )
2680 sel
= m_children
[oldSelInd
];
2681 else if ( oldSelInd
== -2 )
2685 state
->DoSelectProperty(sel
);
2687 if ( state
== grid
->GetState() )
2689 grid
->GetPanel()->Refresh();
2693 // -----------------------------------------------------------------------
2695 // -----------------------------------------------------------------------
2697 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2698 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2701 wxPGRootProperty::wxPGRootProperty( const wxString
& name
)
2711 wxPGRootProperty::~wxPGRootProperty()
2716 // -----------------------------------------------------------------------
2717 // wxPropertyCategory
2718 // -----------------------------------------------------------------------
2720 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2721 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2723 void wxPropertyCategory::Init()
2725 // don't set colour - prepareadditem method should do this
2726 SetParentalType(wxPG_PROP_CATEGORY
);
2727 m_capFgColIndex
= 1;
2731 wxPropertyCategory::wxPropertyCategory()
2738 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2739 : wxPGProperty(label
,name
)
2745 wxPropertyCategory::~wxPropertyCategory()
2750 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2751 int WXUNUSED(argFlags
) ) const
2753 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_STRING
)
2754 return m_value
.GetString();
2755 return wxEmptyString
;
2758 wxString
wxPropertyCategory::GetValueAsString( int argFlags
) const
2760 #if wxPG_COMPATIBILITY_1_4
2761 // This is backwards compatibility test
2762 // That is, to make sure this function is not overridden
2763 // (instead, ValueToString() should be).
2764 if ( argFlags
== 0xFFFF )
2766 // Do not override! (for backwards compliancy)
2767 return g_invalidStringContent
;
2771 // Unspecified value is always empty string
2772 if ( IsValueUnspecified() )
2773 return wxEmptyString
;
2775 return wxPGProperty::GetValueAsString(argFlags
);
2778 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2780 if ( m_textExtent
> 0 )
2781 return m_textExtent
;
2783 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2787 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2790 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2794 // -----------------------------------------------------------------------
2796 // -----------------------------------------------------------------------
2798 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
2802 wxPGChoiceEntry
entry(label
, value
);
2803 return m_data
->Insert( -1, entry
);
2806 // -----------------------------------------------------------------------
2808 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
2812 wxPGChoiceEntry
entry(label
, value
);
2813 entry
.SetBitmap(bitmap
);
2814 return m_data
->Insert( -1, entry
);
2817 // -----------------------------------------------------------------------
2819 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
2823 return m_data
->Insert( index
, entry
);
2826 // -----------------------------------------------------------------------
2828 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
2832 wxPGChoiceEntry
entry(label
, value
);
2833 return m_data
->Insert( index
, entry
);
2836 // -----------------------------------------------------------------------
2838 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
2844 while ( index
< GetCount() )
2846 int cmpRes
= GetLabel(index
).Cmp(label
);
2852 wxPGChoiceEntry
entry(label
, value
);
2853 return m_data
->Insert( index
, entry
);
2856 // -----------------------------------------------------------------------
2858 void wxPGChoices::Add( const wxChar
* const* labels
, const ValArrItem
* values
)
2862 unsigned int itemcount
= 0;
2863 const wxChar
* const* p
= &labels
[0];
2864 while ( *p
) { p
++; itemcount
++; }
2867 for ( i
= 0; i
< itemcount
; i
++ )
2872 wxPGChoiceEntry
entry(labels
[i
], value
);
2873 m_data
->Insert( i
, entry
);
2877 // -----------------------------------------------------------------------
2879 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
2884 unsigned int itemcount
= arr
.size();
2886 for ( i
= 0; i
< itemcount
; i
++ )
2889 if ( &arrint
&& arrint
.size() )
2891 wxPGChoiceEntry
entry(arr
[i
], value
);
2892 m_data
->Insert( i
, entry
);
2896 // -----------------------------------------------------------------------
2898 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
2902 wxASSERT( m_data
->GetRefCount() != -1 );
2903 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
2904 m_data
->m_items
.begin()+nIndex
+count
);
2907 // -----------------------------------------------------------------------
2909 void wxPGChoices::Clear()
2911 if ( m_data
!= wxPGChoicesEmptyData
)
2918 // -----------------------------------------------------------------------
2920 int wxPGChoices::Index( const wxString
& str
) const
2925 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2927 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2928 if ( entry
.HasText() && entry
.GetText() == str
)
2935 // -----------------------------------------------------------------------
2937 int wxPGChoices::Index( int val
) const
2942 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2944 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2945 if ( entry
.GetValue() == val
)
2952 // -----------------------------------------------------------------------
2954 wxArrayString
wxPGChoices::GetLabels() const
2959 if ( this && IsOk() )
2960 for ( i
=0; i
<GetCount(); i
++ )
2961 arr
.push_back(GetLabel(i
));
2966 // -----------------------------------------------------------------------
2968 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
2975 for ( i
=0; i
< strings
.size(); i
++ )
2977 int index
= Index(strings
[i
]);
2979 arr
.Add(GetValue(index
));
2981 arr
.Add(wxPG_INVALID_VALUE
);
2988 // -----------------------------------------------------------------------
2990 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
2991 wxArrayString
* unmatched
) const
2998 for ( i
=0; i
< strings
.size(); i
++ )
3000 const wxString
& str
= strings
[i
];
3001 int index
= Index(str
);
3004 else if ( unmatched
)
3005 unmatched
->Add(str
);
3012 // -----------------------------------------------------------------------
3014 void wxPGChoices::AllocExclusive()
3018 if ( m_data
->GetRefCount() != 1 )
3020 wxPGChoicesData
* data
= new wxPGChoicesData();
3021 data
->CopyDataFrom(m_data
);
3027 // -----------------------------------------------------------------------
3029 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
3033 if ( data
!= wxPGChoicesEmptyData
)
3040 // -----------------------------------------------------------------------
3042 void wxPGChoices::Init()
3044 m_data
= wxPGChoicesEmptyData
;
3047 // -----------------------------------------------------------------------
3049 void wxPGChoices::Free()
3051 if ( m_data
!= wxPGChoicesEmptyData
)
3054 m_data
= wxPGChoicesEmptyData
;
3058 // -----------------------------------------------------------------------
3059 // wxPGAttributeStorage
3060 // -----------------------------------------------------------------------
3062 wxPGAttributeStorage::wxPGAttributeStorage()
3066 wxPGAttributeStorage::~wxPGAttributeStorage()
3068 wxPGHashMapS2P::iterator it
;
3070 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
3072 wxVariantData
* data
= (wxVariantData
*) it
->second
;
3077 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
3079 wxVariantData
* data
= value
.GetData();
3082 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
3083 if ( it
!= m_map
.end() )
3085 ((wxVariantData
*)it
->second
)->DecRef();
3089 // If Null variant, just remove from set
3103 #endif // wxUSE_PROPGRID