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"
40 #include "wx/propgrid/propgrid.h"
43 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
46 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
48 #if wxPG_COMPATIBILITY_1_4
50 // Used to establish backwards compatiblity
51 const char* g_invalidStringContent
= "@__TOTALLY_INVALID_STRING__@";
55 // -----------------------------------------------------------------------
57 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
59 #if defined(__WXMSW__) && !defined(__WXWINCE__)
60 // FIXME: Use DrawFocusRect code above (currently it draws solid line
61 // for caption focus but works ok for other stuff).
62 // Also, it seems that this code may not work in future wx versions.
63 dc
.SetLogicalFunction(wxINVERT
);
65 wxPen
pen(*wxBLACK
,1,wxDOT
);
66 pen
.SetCap(wxCAP_BUTT
);
68 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
70 dc
.DrawRectangle(rect
);
72 dc
.SetLogicalFunction(wxCOPY
);
74 dc
.SetLogicalFunction(wxINVERT
);
76 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
77 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
79 dc
.DrawRectangle(rect
);
81 dc
.SetLogicalFunction(wxCOPY
);
85 // -----------------------------------------------------------------------
87 // -----------------------------------------------------------------------
89 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
91 int WXUNUSED(item
) ) const
96 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
97 int xOffset
, const wxString
& text
) const
100 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
101 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
104 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
105 int xOffset
, const wxString
& text
,
106 wxPGProperty
* property
,
107 const wxPGEditor
* editor
) const
109 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
116 rect2
.height
-= yOffset
;
117 editor
->DrawValue( dc
, rect2
, property
, text
);
122 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
127 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
129 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
130 wxPGDrawFocusRect(dc
,focusRect
);
133 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
137 // If possible, use cell colours
138 if ( !(flags
& DontUseCellBgCol
) )
140 const wxColour
& bgCol
= cell
.GetBgCol();
145 if ( !(flags
& DontUseCellFgCol
) )
147 dc
.SetTextForeground(cell
.GetFgCol());
150 // Draw Background, but only if not rendering in control
151 // (as control already has rendered correct background).
152 if ( !(flags
& (Control
|ChoicePopup
)) )
153 dc
.DrawRectangle(rect
);
155 // Use cell font, if provided
156 const wxFont
& font
= cell
.GetFont();
160 const wxBitmap
& bmp
= cell
.GetBitmap();
162 // Do not draw oversized bitmap outside choice popup
163 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
167 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
168 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
170 imageWidth
= bmp
.GetWidth();
176 void wxPGCellRenderer::PostDrawCell( wxDC
& dc
,
177 const wxPropertyGrid
* propGrid
,
178 const wxPGCell
& cell
,
179 int WXUNUSED(flags
) ) const
182 const wxFont
& font
= cell
.GetFont();
184 dc
.SetFont(propGrid
->GetFont());
187 // -----------------------------------------------------------------------
188 // wxPGDefaultRenderer
189 // -----------------------------------------------------------------------
191 bool wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
192 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
193 int column
, int item
, int flags
) const
195 const wxPGEditor
* editor
= NULL
;
196 const wxPGCell
* cell
= NULL
;
199 bool isUnspecified
= property
->IsValueUnspecified();
201 if ( column
== 1 && item
== -1 )
203 int cmnVal
= property
->GetCommonValue();
207 if ( !isUnspecified
)
209 text
= propertyGrid
->GetCommonValueLabel(cmnVal
);
210 DrawText( dc
, rect
, 0, text
);
219 int preDrawFlags
= flags
;
222 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
224 imageWidth
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
228 editor
= property
->GetColumnEditor(column
);
230 if ( !isUnspecified
)
232 // Regular property value
234 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
236 wxPGPaintData paintdata
;
237 paintdata
.m_parent
= propertyGrid
;
238 paintdata
.m_choiceItem
= item
;
240 if ( imageSize
.x
> 0 )
242 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
243 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
244 wxPG_CUSTOM_IMAGE_WIDTH
,
245 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
247 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
249 paintdata
.m_drawnWidth
= imageSize
.x
;
250 paintdata
.m_drawnHeight
= imageSize
.y
;
252 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
254 imageWidth
= paintdata
.m_drawnWidth
;
257 text
= property
->GetValueAsString();
260 if ( propertyGrid
->GetColumnCount() <= 2 )
262 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
263 if ( !unitsString
.empty() )
264 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
270 text
= property
->GetHintText();
275 const wxColour
& hCol
=
276 propertyGrid
->GetCellDisabledTextColour();
277 dc
.SetTextForeground(hCol
);
279 // Must make the editor NULL to override its own rendering
290 int imageOffset
= property
->GetImageOffset(imageWidth
);
292 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
294 // active caption gets nice dotted rectangle
295 if ( property
->IsCategory() && column
== 0 )
297 if ( flags
& Selected
)
299 if ( imageOffset
> 0 )
301 imageOffset
-= DEFAULT_IMAGE_OFFSET_INCREMENT
;
302 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
305 DrawCaptionSelectionRect( dc
,
306 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
307 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
308 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
309 propertyGrid
->GetCaptionFont())
310 +(wxPG_CAPRECTXMARGIN
*2),
311 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
315 PostDrawCell(dc
, propertyGrid
, *cell
, preDrawFlags
);
320 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
324 if ( property
&& column
== 1 )
328 wxBitmap
* bmp
= property
->GetValueImage();
330 if ( bmp
&& bmp
->Ok() )
331 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
337 // -----------------------------------------------------------------------
339 // -----------------------------------------------------------------------
341 wxPGCellData::wxPGCellData()
344 m_hasValidText
= false;
347 // -----------------------------------------------------------------------
349 // -----------------------------------------------------------------------
356 wxPGCell::wxPGCell( const wxString
& text
,
357 const wxBitmap
& bitmap
,
358 const wxColour
& fgCol
,
359 const wxColour
& bgCol
)
362 wxPGCellData
* data
= new wxPGCellData();
365 data
->m_bitmap
= bitmap
;
366 data
->m_fgCol
= fgCol
;
367 data
->m_bgCol
= bgCol
;
368 data
->m_hasValidText
= true;
371 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
373 wxPGCellData
* c
= new wxPGCellData();
374 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
375 c
->m_text
= o
->m_text
;
376 c
->m_bitmap
= o
->m_bitmap
;
377 c
->m_fgCol
= o
->m_fgCol
;
378 c
->m_bgCol
= o
->m_bgCol
;
379 c
->m_hasValidText
= o
->m_hasValidText
;
383 void wxPGCell::SetText( const wxString
& text
)
387 GetData()->SetText(text
);
390 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
394 GetData()->SetBitmap(bitmap
);
397 void wxPGCell::SetFgCol( const wxColour
& col
)
401 GetData()->SetFgCol(col
);
404 void wxPGCell::SetFont( const wxFont
& font
)
408 GetData()->SetFont(font
);
411 void wxPGCell::SetBgCol( const wxColour
& col
)
415 GetData()->SetBgCol(col
);
418 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
422 wxPGCellData
* data
= GetData();
424 if ( srcCell
.HasText() )
425 data
->SetText(srcCell
.GetText());
427 if ( srcCell
.GetFgCol().IsOk() )
428 data
->SetFgCol(srcCell
.GetFgCol());
430 if ( srcCell
.GetBgCol().IsOk() )
431 data
->SetBgCol(srcCell
.GetBgCol());
433 if ( srcCell
.GetBitmap().IsOk() )
434 data
->SetBitmap(srcCell
.GetBitmap());
437 void wxPGCell::SetEmptyData()
443 // -----------------------------------------------------------------------
445 // -----------------------------------------------------------------------
447 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
449 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
451 void wxPGProperty::Init()
457 m_parentState
= NULL
;
460 m_clientObject
= NULL
;
462 m_customEditor
= NULL
;
466 m_valueBitmap
= NULL
;
468 m_maxLen
= 0; // infinite maximum length
470 m_flags
= wxPG_PROP_PROPERTY
;
478 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
480 // We really need to check if &label and &name are NULL pointers
481 // (this can if we are called before property grid has been initalized)
483 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
486 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
489 DoSetName( m_label
);
494 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
495 wxPropertyGrid
* propgrid
)
498 // Called after property has been added to grid or page
499 // (so propgrid can be NULL, too).
501 wxPGProperty
* parent
= m_parent
;
502 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
505 // Convert invalid cells to default ones in this grid
506 for ( unsigned int i
=0; i
<m_cells
.size(); i
++ )
508 wxPGCell
& cell
= m_cells
[i
];
509 if ( cell
.IsInvalid() )
511 const wxPGCell
& propDefCell
= propgrid
->GetPropertyDefaultCell();
512 const wxPGCell
& catDefCell
= propgrid
->GetCategoryDefaultCell();
514 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
521 m_parentState
= pageState
;
523 #if wxPG_COMPATIBILITY_1_4
524 // Make sure deprecated virtual functions are not implemented
525 wxString s
= GetValueAsString( 0xFFFF );
526 wxASSERT_MSG( s
== g_invalidStringContent
,
527 "Implement ValueToString() instead of GetValueAsString()" );
530 if ( !parentIsRoot
&& !parent
->IsCategory() )
532 m_cells
= parent
->m_cells
;
535 // If in hideable adding mode, or if assigned parent is hideable, then
536 // make this one hideable.
538 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
539 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
541 SetFlag( wxPG_PROP_HIDDEN
);
543 // Set custom image flag.
544 int custImgHeight
= OnMeasureImage().y
;
545 if ( custImgHeight
< 0 )
547 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
550 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
551 SetFlag(wxPG_PROP_NOEDITOR
);
553 // Make sure parent has some parental flags
554 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
555 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
559 // This is not a category.
563 unsigned char depth
= 1;
566 depth
= parent
->m_depth
;
567 if ( !parent
->IsCategory() )
571 unsigned char greyDepth
= depth
;
575 wxPropertyCategory
* pc
;
577 if ( parent
->IsCategory() )
578 pc
= (wxPropertyCategory
* ) parent
;
580 // This conditional compile is necessary to
581 // bypass some compiler bug.
582 pc
= pageState
->GetPropertyCategory(parent
);
585 greyDepth
= pc
->GetDepth();
587 greyDepth
= parent
->m_depthBgCol
;
590 m_depthBgCol
= greyDepth
;
594 // This is a category.
597 unsigned char depth
= 1;
600 depth
= parent
->m_depth
+ 1;
603 m_depthBgCol
= depth
;
607 // Has initial children
608 if ( GetChildCount() )
610 // Check parental flags
611 wxASSERT_MSG( ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
612 wxPG_PROP_AGGREGATE
) ||
613 ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
614 wxPG_PROP_MISC_PARENT
),
615 "wxPGProperty parental flags set incorrectly at "
618 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
620 // Properties with private children are not expanded by default.
623 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
625 // ...unless it cannot be expanded by user and therefore must
626 // remain visible at all times
631 // Prepare children recursively
632 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
634 wxPGProperty
* child
= Item(i
);
635 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
638 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
639 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
643 void wxPGProperty::OnDetached(wxPropertyGridPageState
* WXUNUSED(state
),
644 wxPropertyGrid
* propgrid
)
648 const wxPGCell
& propDefCell
= propgrid
->GetPropertyDefaultCell();
649 const wxPGCell
& catDefCell
= propgrid
->GetCategoryDefaultCell();
651 // Make default cells invalid
652 for ( unsigned int i
=0; i
<m_cells
.size(); i
++ )
654 wxPGCell
& cell
= m_cells
[i
];
655 if ( cell
.IsSameAs(propDefCell
) ||
656 cell
.IsSameAs(catDefCell
) )
664 wxPGProperty::wxPGProperty()
671 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
678 wxPGProperty::~wxPGProperty()
680 delete m_clientObject
;
682 Empty(); // this deletes items
684 delete m_valueBitmap
;
689 // This makes it easier for us to detect dangling pointers
694 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
696 wxPGProperty
* parent
= m_parent
;
699 if ( parent
== candidate
)
701 parent
= parent
->m_parent
;
706 void wxPGProperty::SetName( const wxString
& newName
)
708 wxPropertyGrid
* pg
= GetGrid();
711 pg
->SetPropertyName(this, newName
);
716 wxString
wxPGProperty::GetName() const
718 wxPGProperty
* parent
= GetParent();
720 if ( m_name
.empty() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
723 return m_parent
->GetName() + wxS(".") + m_name
;
726 wxPropertyGrid
* wxPGProperty::GetGrid() const
728 if ( !m_parentState
)
730 return m_parentState
->GetGrid();
733 int wxPGProperty::Index( const wxPGProperty
* p
) const
735 return wxPGFindInVector(m_children
, p
);
738 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
743 void wxPGProperty::OnSetValue()
747 void wxPGProperty::RefreshChildren ()
751 void wxPGProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
755 void wxPGProperty::GetDisplayInfo( unsigned int column
,
759 const wxPGCell
** pCell
)
761 const wxPGCell
* cell
= NULL
;
763 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
765 // Not painting list of choice popups, so get text from property
766 if ( column
!= 1 || !IsValueUnspecified() || IsCategory() )
768 cell
= &GetCell(column
);
772 // Use special unspecified value cell
773 cell
= &GetGrid()->GetUnspecifiedValueAppearance();
776 if ( cell
->HasText() )
778 *pString
= cell
->GetText();
783 *pString
= GetLabel();
784 else if ( column
== 1 )
785 *pString
= GetDisplayedString();
786 else if ( column
== 2 )
787 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
792 wxASSERT( column
== 1 );
794 if ( choiceIndex
!= wxNOT_FOUND
)
796 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
797 if ( entry
.GetBitmap().IsOk() ||
798 entry
.GetFgCol().IsOk() ||
799 entry
.GetBgCol().IsOk() )
801 *pString
= m_choices
.GetLabel(choiceIndex
);
806 cell
= &GetCell(column
);
808 wxASSERT_MSG( cell
->GetData(),
809 wxString::Format("Invalid cell for property %s",
810 GetName().c_str()) );
816 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
819 if ( col != 1 || choiceIndex == wxNOT_FOUND )
821 const wxPGCell& cell = GetCell(col);
822 if ( cell->HasText() )
824 return cell->GetText();
831 return GetDisplayedString();
833 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
839 return m_choices.GetLabel(choiceIndex);
842 return wxEmptyString;
846 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
848 const wxVariantList
* valueOverrides
,
849 wxPGHashMapS2S
* childResults
) const
852 int iMax
= m_children
.size();
858 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
859 !(argFlags
& wxPG_FULL_VALUE
) )
860 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
862 int iMaxMinusOne
= iMax
-1;
864 if ( !IsTextEditable() )
865 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
867 wxPGProperty
* curChild
= m_children
[0];
869 bool overridesLeft
= false;
870 wxVariant overrideValue
;
871 wxVariantList::const_iterator node
;
873 if ( valueOverrides
)
875 node
= valueOverrides
->begin();
876 if ( node
!= valueOverrides
->end() )
878 overrideValue
= *node
;
879 overridesLeft
= true;
883 for ( i
= 0; i
< iMax
; i
++ )
885 wxVariant childValue
;
887 wxString childLabel
= curChild
->GetLabel();
889 // Check for value override
890 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
892 if ( !overrideValue
.IsNull() )
893 childValue
= overrideValue
;
895 childValue
= curChild
->GetValue();
897 if ( node
!= valueOverrides
->end() )
898 overrideValue
= *node
;
900 overridesLeft
= false;
904 childValue
= curChild
->GetValue();
908 if ( !childValue
.IsNull() )
910 if ( overridesLeft
&&
911 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
912 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
914 wxVariantList
& childList
= childValue
.GetList();
915 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
916 &childList
, childResults
);
920 s
= curChild
->ValueToString(childValue
,
921 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
925 if ( childResults
&& curChild
->GetChildCount() )
926 (*childResults
)[curChild
->GetName()] = s
;
929 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && s
.empty() )
932 if ( !curChild
->GetChildCount() || skip
)
935 text
+= wxS("[") + s
+ wxS("]");
937 if ( i
< iMaxMinusOne
)
939 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
940 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
941 !(argFlags
& wxPG_FULL_VALUE
) )
946 if ( !curChild
->GetChildCount() )
952 curChild
= m_children
[i
+1];
956 if ( (unsigned int)i
< m_children
.size() )
958 if ( !text
.EndsWith(wxS("; ")) )
959 text
+= wxS("; ...");
965 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
968 wxCHECK_MSG( GetChildCount() > 0,
970 "If user property does not have any children, it must "
971 "override GetValueAsString" );
973 // FIXME: Currently code below only works if value is actually m_value
974 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
975 "Sorry, currently default wxPGProperty::ValueToString() "
976 "implementation only works if value is m_value." );
979 DoGenerateComposedValue(text
, argFlags
);
983 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
985 #if wxPG_COMPATIBILITY_1_4
986 // This is backwards compatibility test
987 // That is, to make sure this function is not overridden
988 // (instead, ValueToString() should be).
989 if ( argFlags
== 0xFFFF )
991 // Do not override! (for backwards compliancy)
992 return g_invalidStringContent
;
996 wxPropertyGrid
* pg
= GetGrid();
998 if ( IsValueUnspecified() )
999 return pg
->GetUnspecifiedValueText(argFlags
);
1001 if ( m_commonValue
== -1 )
1003 wxVariant
value(GetValue());
1004 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
1008 // Return common value's string representation
1009 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
1011 if ( argFlags
& wxPG_FULL_VALUE
)
1013 return cv
->GetLabel();
1015 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
1017 return cv
->GetEditableText();
1021 return cv
->GetLabel();
1025 wxString
wxPGProperty::GetValueString( int argFlags
) const
1027 return GetValueAsString(argFlags
);
1030 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1032 variant
= (long)number
;
1036 // Convert semicolon delimited tokens into child values.
1037 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1039 if ( !GetChildCount() )
1042 unsigned int curChild
= 0;
1044 unsigned int iMax
= m_children
.size();
1046 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
1047 !(argFlags
& wxPG_FULL_VALUE
) )
1048 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
1050 bool changed
= false;
1055 // Its best only to add non-empty group items
1056 bool addOnlyIfNotEmpty
= false;
1057 const wxChar delimeter
= wxS(';');
1059 size_t tokenStart
= 0xFFFFFF;
1061 wxVariantList temp_list
;
1062 wxVariant
list(temp_list
);
1064 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
1066 wxLogTrace("propgrid",
1067 wxT(">> %s.StringToValue('%s')"), GetLabel(), text
);
1069 wxString::const_iterator it
= text
.begin();
1072 if ( it
!= text
.end() )
1079 // How many units we iterate string forward at the end of loop?
1080 // We need to keep track of this or risk going to negative
1081 // with it-- operation.
1082 unsigned int strPosIncrement
= 1;
1084 if ( tokenStart
!= 0xFFFFFF )
1087 if ( a
== delimeter
|| a
== 0 )
1089 token
= text
.substr(tokenStart
,pos
-tokenStart
);
1091 size_t len
= token
.length();
1093 if ( !addOnlyIfNotEmpty
|| len
> 0 )
1095 const wxPGProperty
* child
= Item(curChild
);
1096 wxVariant
variant(child
->GetValue());
1097 wxString childName
= child
->GetBaseName();
1099 wxLogTrace("propgrid",
1100 wxT("token = '%s', child = %s"),
1103 // Add only if editable or setting programmatically
1104 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1105 (!child
->HasFlag(wxPG_PROP_DISABLED
) &&
1106 !child
->HasFlag(wxPG_PROP_READONLY
)) )
1110 if ( child
->StringToValue(variant
, token
,
1111 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1113 // We really need to set the variant's name
1114 // *after* child->StringToValue() has been
1115 // called, since variant's value may be set by
1116 // assigning another variant into it, which
1117 // then usually causes name to be copied (ie.
1118 // usually cleared) as well. wxBoolProperty
1119 // being case in point with its use of
1120 // wxPGVariant_Bool macro as an optimization.
1121 variant
.SetName(childName
);
1122 list
.Append(variant
);
1129 // Empty, becomes unspecified
1131 variant
.SetName(childName
);
1132 list
.Append(variant
);
1138 if ( curChild
>= iMax
)
1142 tokenStart
= 0xFFFFFF;
1147 // Token is not running
1148 if ( a
!= wxS(' ') )
1151 addOnlyIfNotEmpty
= false;
1153 // Is this a group of tokens?
1154 if ( a
== wxS('[') )
1158 if ( it
!= text
.end() ) ++it
;
1160 size_t startPos
= pos
;
1162 // Group item - find end
1163 while ( it
!= text
.end() && depth
> 0 )
1169 if ( a
== wxS(']') )
1171 else if ( a
== wxS('[') )
1175 token
= text
.substr(startPos
,pos
-startPos
-1);
1177 if ( token
.empty() )
1180 const wxPGProperty
* child
= Item(curChild
);
1182 wxVariant oldChildValue
= child
->GetValue();
1183 wxVariant
variant(oldChildValue
);
1185 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1186 (!child
->HasFlag(wxPG_PROP_DISABLED
) &&
1187 !child
->HasFlag(wxPG_PROP_READONLY
)) )
1189 wxString childName
= child
->GetBaseName();
1191 bool stvRes
= child
->StringToValue( variant
, token
,
1193 if ( stvRes
|| (variant
!= oldChildValue
) )
1195 variant
.SetName(childName
);
1196 list
.Append(variant
);
1207 if ( curChild
>= iMax
)
1210 addOnlyIfNotEmpty
= true;
1212 tokenStart
= 0xFFFFFF;
1218 if ( a
== delimeter
)
1219 strPosIncrement
-= 1;
1227 it
+= strPosIncrement
;
1229 if ( it
!= text
.end() )
1238 pos
+= strPosIncrement
;
1247 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1249 wxVariant
variant(m_value
);
1250 bool res
= StringToValue(variant
, text
, argFlags
);
1256 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1258 wxVariant
variant(m_value
);
1259 bool res
= IntToValue(variant
, number
, argFlags
);
1265 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1267 if ( m_valueBitmap
)
1268 return wxSize(m_valueBitmap
->GetWidth(),-1);
1273 int wxPGProperty::GetImageOffset( int imageWidth
) const
1275 int imageOffset
= 0;
1279 // Do not increment offset too much for wide images
1280 if ( imageWidth
<= (wxPG_CUSTOM_IMAGE_WIDTH
+5) )
1281 imageOffset
= imageWidth
+ DEFAULT_IMAGE_OFFSET_INCREMENT
;
1283 imageOffset
= imageWidth
+ 1;
1289 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1291 return wxPGGlobalVars
->m_defaultRenderer
;
1294 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1298 wxBitmap
* bmp
= m_valueBitmap
;
1300 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1302 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1304 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1307 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1309 return wxPGEditor_TextCtrl
;
1312 // Default extra property event handling - that is, none at all.
1313 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1319 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1321 // If auto unspecified values are not wanted (via window or property style),
1322 // then get default value instead of wxNullVariant.
1323 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1324 !UsesAutoUnspecified() )
1326 value
= GetDefaultValue();
1329 if ( !value
.IsNull() )
1331 wxVariant tempListVariant
;
1334 // List variants are reserved a special purpose
1335 // as intermediate containers for child values
1336 // of properties with children.
1337 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1340 // However, situation is different for composed string properties
1341 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1343 tempListVariant
= value
;
1344 pList
= &tempListVariant
;
1348 AdaptListToValue(value
, &newValue
);
1350 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1353 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1354 flags
|= wxPG_SETVAL_AGGREGATED
;
1356 if ( pList
&& !pList
->IsNull() )
1358 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1359 wxASSERT( GetChildCount() );
1360 wxASSERT( !IsCategory() );
1362 wxVariantList
& list
= pList
->GetList();
1363 wxVariantList::iterator node
;
1366 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1368 // Children in list can be in any order, but we will give hint to
1369 // GetPropertyByNameWH(). This optimizes for full list parsing.
1370 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1372 wxVariant
& childValue
= *((wxVariant
*)*node
);
1373 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1376 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1377 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1379 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1381 wxVariant listRefCopy
= childValue
;
1382 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1386 wxVariant oldVal
= child
->GetValue();
1387 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1390 else if ( child
->GetValue() != childValue
)
1392 // For aggregate properties, we will trust RefreshChildren()
1393 // to update child values.
1394 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1395 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1396 if ( flags
& wxPG_SETVAL_BY_USER
)
1397 child
->SetFlag(wxPG_PROP_MODIFIED
);
1403 // Always call OnSetValue() for a parent property (do not call it
1404 // here if the value is non-null because it will then be called
1406 if ( value
.IsNull() )
1410 if ( !value
.IsNull() )
1416 if ( flags
& wxPG_SETVAL_BY_USER
)
1417 SetFlag(wxPG_PROP_MODIFIED
);
1419 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1424 if ( m_commonValue
!= -1 )
1426 wxPropertyGrid
* pg
= GetGrid();
1427 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1433 // Set children to unspecified, but only if aggregate or
1434 // value is <composed>
1435 if ( AreChildrenComponents() )
1438 for ( i
=0; i
<GetChildCount(); i
++ )
1439 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1443 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1444 UpdateParentValues();
1447 // Update editor control.
1448 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1450 wxPropertyGrid
* pg
= GetGridIfDisplayed();
1453 wxPGProperty
* selected
= pg
->GetSelectedProperty();
1455 // Only refresh the control if this was selected, or
1456 // this was some parent of selected, or vice versa)
1457 if ( selected
&& (selected
== this ||
1458 selected
->IsSomeParent(this) ||
1459 this->IsSomeParent(selected
)) )
1462 pg
->DrawItemAndValueRelated(this);
1468 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1470 GetGrid()->ValueChangeInEvent(value
);
1473 void wxPGProperty::SetFlagRecursively( wxPGPropertyFlags flag
, bool set
)
1475 ChangeFlag(flag
, set
);
1478 for ( i
= 0; i
< GetChildCount(); i
++ )
1479 Item(i
)->SetFlagRecursively(flag
, set
);
1482 void wxPGProperty::RefreshEditor()
1487 wxPropertyGrid
* pg
= GetGrid();
1488 if ( pg
&& pg
->GetSelectedProperty() == this )
1489 pg
->RefreshEditor();
1492 wxVariant
wxPGProperty::GetDefaultValue() const
1494 wxVariant defVal
= GetAttribute(wxPG_ATTR_DEFAULT_VALUE
);
1495 if ( !defVal
.IsNull() )
1498 wxVariant value
= GetValue();
1500 if ( !value
.IsNull() )
1502 wxString
valueType(value
.GetType());
1504 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1505 return wxPGVariant_Zero
;
1506 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1507 return wxPGVariant_EmptyString
;
1508 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1509 return wxPGVariant_False
;
1510 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1511 return wxVariant(0.0);
1512 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1513 return wxVariant(wxArrayString());
1514 if ( valueType
== wxS("wxLongLong") )
1515 return WXVARIANT(wxLongLong(0));
1516 if ( valueType
== wxS("wxULongLong") )
1517 return WXVARIANT(wxULongLong(0));
1518 if ( valueType
== wxS("wxColour") )
1519 return WXVARIANT(*wxBLACK
);
1521 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1522 return wxVariant(wxDateTime::Now());
1524 if ( valueType
== wxS("wxFont") )
1525 return WXVARIANT(*wxNORMAL_FONT
);
1526 if ( valueType
== wxS("wxPoint") )
1527 return WXVARIANT(wxPoint(0, 0));
1528 if ( valueType
== wxS("wxSize") )
1529 return WXVARIANT(wxSize(0, 0));
1535 void wxPGProperty::Enable( bool enable
)
1537 wxPropertyGrid
* pg
= GetGrid();
1539 // Preferably call the version in the owning wxPropertyGrid,
1540 // since it handles the editor de-activation.
1542 pg
->EnableProperty(this, enable
);
1547 void wxPGProperty::DoEnable( bool enable
)
1550 ClearFlag(wxPG_PROP_DISABLED
);
1552 SetFlag(wxPG_PROP_DISABLED
);
1554 // Apply same to sub-properties as well
1556 for ( i
= 0; i
< GetChildCount(); i
++ )
1557 Item(i
)->DoEnable( enable
);
1560 void wxPGProperty::EnsureCells( unsigned int column
)
1562 if ( column
>= m_cells
.size() )
1564 // Fill empty slots with default cells
1565 wxPropertyGrid
* pg
= GetGrid();
1566 wxPGCell defaultCell
;
1570 // Work around possible VC6 bug by using intermediate variables
1571 const wxPGCell
& propDefCell
= pg
->GetPropertyDefaultCell();
1572 const wxPGCell
& catDefCell
= pg
->GetCategoryDefaultCell();
1574 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1575 defaultCell
= propDefCell
;
1577 defaultCell
= catDefCell
;
1580 // TODO: Replace with resize() call
1581 unsigned int cellCountMax
= column
+1;
1583 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1584 m_cells
.push_back(defaultCell
);
1588 void wxPGProperty::SetCell( int column
,
1589 const wxPGCell
& cell
)
1591 EnsureCells(column
);
1593 m_cells
[column
] = cell
;
1596 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1597 unsigned int lastCol
,
1598 const wxPGCell
& cell
,
1599 const wxPGCell
& srcData
,
1600 wxPGCellData
* unmodCellData
,
1601 FlagType ignoreWithFlags
,
1605 // Sets cell in memory optimizing fashion. That is, if
1606 // current cell data matches unmodCellData, we will
1607 // simply get reference to data from cell. Otherwise,
1608 // cell information from srcData is merged into current.
1611 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1613 EnsureCells(lastCol
);
1615 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1617 if ( m_cells
[col
].GetData() == unmodCellData
)
1619 // Data matches... use cell directly
1620 m_cells
[col
] = cell
;
1624 // Data did not match... merge valid information
1625 m_cells
[col
].MergeFrom(srcData
);
1632 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1633 Item(i
)->AdaptiveSetCell( firstCol
,
1643 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1645 if ( m_cells
.size() > column
)
1646 return m_cells
[column
];
1648 wxPropertyGrid
* pg
= GetGrid();
1651 return pg
->GetCategoryDefaultCell();
1653 return pg
->GetPropertyDefaultCell();
1656 wxPGCell
& wxPGProperty::GetOrCreateCell( unsigned int column
)
1658 EnsureCells(column
);
1659 return m_cells
[column
];
1662 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1665 wxPGProperty
* firstProp
= this;
1666 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1669 // If category is tried to set recursively, skip it and only
1670 // affect the children.
1673 while ( firstProp
->IsCategory() )
1675 if ( !firstProp
->GetChildCount() )
1677 firstProp
= firstProp
->Item(0);
1681 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1682 wxPGCellData
* firstCellData
= firstCell
.GetData();
1684 wxPGCell
newCell(firstCell
);
1685 newCell
.SetBgCol(colour
);
1687 srcCell
.SetBgCol(colour
);
1690 GetParentState()->GetColumnCount()-1,
1694 recursively
? wxPG_PROP_CATEGORY
: 0,
1698 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1701 wxPGProperty
* firstProp
= this;
1702 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1705 // If category is tried to set recursively, skip it and only
1706 // affect the children.
1709 while ( firstProp
->IsCategory() )
1711 if ( !firstProp
->GetChildCount() )
1713 firstProp
= firstProp
->Item(0);
1717 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1718 wxPGCellData
* firstCellData
= firstCell
.GetData();
1720 wxPGCell
newCell(firstCell
);
1721 newCell
.SetFgCol(colour
);
1723 srcCell
.SetFgCol(colour
);
1726 GetParentState()->GetColumnCount()-1,
1730 recursively
? wxPG_PROP_CATEGORY
: 0,
1734 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1739 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1744 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1746 if ( DoSetAttribute( name
, value
) )
1748 // Support working without grid, when possible
1749 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1753 m_attributes
.Set( name
, value
);
1756 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1758 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1761 while ( attributes
.GetNext(it
, variant
) )
1762 SetAttribute( variant
.GetName(), variant
);
1765 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1771 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1773 return m_attributes
.FindValue(name
);
1776 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1778 wxVariant variant
= m_attributes
.FindValue(name
);
1780 if ( !variant
.IsNull() )
1781 return variant
.GetString();
1786 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1788 wxVariant variant
= m_attributes
.FindValue(name
);
1790 if ( variant
.IsNull() )
1793 return variant
.GetLong();
1796 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1798 wxVariant variant
= m_attributes
.FindValue(name
);
1800 if ( variant
.IsNull() )
1803 return variant
.GetDouble();
1806 wxVariant
wxPGProperty::GetAttributesAsList() const
1808 wxVariantList tempList
;
1809 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1811 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1814 while ( m_attributes
.GetNext(it
, variant
) )
1820 // Slots of utility flags are NULL
1821 const unsigned int gs_propFlagToStringSize
= 14;
1823 static const wxChar
* const gs_propFlagToString
[gs_propFlagToStringSize
] = {
1840 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1843 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1847 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1849 if ( relevantFlags
& a
)
1851 const wxChar
* fs
= gs_propFlagToString
[i
];
1863 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1867 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1869 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1871 const wxChar
* fs
= gs_propFlagToString
[i
];
1872 if ( fs
&& str
== fs
)
1878 WX_PG_TOKENIZER1_END()
1880 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1883 wxValidator
* wxPGProperty::DoGetValidator() const
1888 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1890 wxPropertyGrid
* pg
= GetGrid();
1891 int sel
= GetChoiceSelection();
1895 if ( index
== wxNOT_FOUND
)
1896 index
= m_choices
.GetCount();
1901 m_choices
.Insert(label
, index
, value
);
1903 if ( sel
!= newSel
)
1904 SetChoiceSelection(newSel
);
1906 if ( this == pg
->GetSelection() )
1907 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1913 void wxPGProperty::DeleteChoice( int index
)
1915 wxPropertyGrid
* pg
= GetGrid();
1917 int sel
= GetChoiceSelection();
1920 // Adjust current value
1923 SetValueToUnspecified();
1926 else if ( index
< sel
)
1931 m_choices
.RemoveAt(index
);
1933 if ( sel
!= newSel
)
1934 SetChoiceSelection(newSel
);
1936 if ( this == pg
->GetSelection() )
1937 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1940 int wxPGProperty::GetChoiceSelection() const
1942 wxVariant value
= GetValue();
1943 wxString valueType
= value
.GetType();
1944 int index
= wxNOT_FOUND
;
1946 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1949 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1951 index
= value
.GetLong();
1953 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1955 index
= m_choices
.Index(value
.GetString());
1957 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1959 index
= value
.GetBool()? 1 : 0;
1965 void wxPGProperty::SetChoiceSelection( int newValue
)
1967 // Changes value of a property with choices, but only
1968 // works if the value type is long or string.
1969 wxString valueType
= GetValue().GetType();
1971 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1973 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1975 SetValue( m_choices
.GetLabel(newValue
) );
1977 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1979 SetValue( (long) newValue
);
1983 bool wxPGProperty::SetChoices( const wxPGChoices
& choices
)
1985 // Property must be de-selected first (otherwise choices in
1986 // the control would be de-synced with true choices)
1987 wxPropertyGrid
* pg
= GetGrid();
1988 if ( pg
&& pg
->GetSelection() == this )
1989 pg
->ClearSelection();
1991 m_choices
.Assign(choices
);
1994 // This may be needed to trigger some initialization
1995 // (but don't do it if property is somewhat uninitialized)
1996 wxVariant defVal
= GetDefaultValue();
1997 if ( defVal
.IsNull() )
2007 const wxPGEditor
* wxPGProperty::GetEditorClass() const
2009 const wxPGEditor
* editor
;
2011 if ( !m_customEditor
)
2013 editor
= DoGetEditorClass();
2016 editor
= m_customEditor
;
2019 // Maybe override editor if common value specified
2020 if ( GetDisplayedCommonValueCount() )
2022 // TextCtrlAndButton -> ComboBoxAndButton
2023 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
2024 editor
= wxPGEditor_ChoiceAndButton
;
2026 // TextCtrl -> ComboBox
2027 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
2028 editor
= wxPGEditor_ComboBox
;
2034 bool wxPGProperty::Hide( bool hide
, int flags
)
2036 wxPropertyGrid
* pg
= GetGrid();
2038 return pg
->HideProperty(this, hide
, flags
);
2040 return DoHide( hide
, flags
);
2043 bool wxPGProperty::DoHide( bool hide
, int flags
)
2046 ClearFlag( wxPG_PROP_HIDDEN
);
2048 SetFlag( wxPG_PROP_HIDDEN
);
2050 if ( flags
& wxPG_RECURSE
)
2053 for ( i
= 0; i
< GetChildCount(); i
++ )
2054 Item(i
)->DoHide(hide
, flags
| wxPG_RECURSE_STARTS
);
2060 bool wxPGProperty::HasVisibleChildren() const
2064 for ( i
=0; i
<GetChildCount(); i
++ )
2066 wxPGProperty
* child
= Item(i
);
2068 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
2075 bool wxPGProperty::RecreateEditor()
2077 wxPropertyGrid
* pg
= GetGrid();
2080 wxPGProperty
* selected
= pg
->GetSelection();
2081 if ( this == selected
)
2083 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
2090 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
2092 delete m_valueBitmap
;
2094 if ( &bmp
&& bmp
.Ok() )
2097 wxSize maxSz
= GetGrid()->GetImageSize();
2098 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
2100 if ( imSz
.y
!= maxSz
.y
)
2103 // Here we use high-quality wxImage scaling functions available
2104 wxImage img
= bmp
.ConvertToImage();
2105 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
2106 img
.Rescale(((double)bmp
.GetWidth())*scaleY
,
2107 ((double)bmp
.GetHeight())*scaleY
,
2108 wxIMAGE_QUALITY_HIGH
);
2109 wxBitmap
* bmpNew
= new wxBitmap(img
, 32);
2111 // This is the old, deprecated method of scaling the image
2112 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
2114 dc
.SelectObject(*bmpNew
);
2115 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
2116 dc
.SetUserScale(scaleY
, scaleY
);
2117 dc
.DrawBitmap(bmp
, 0, 0);
2120 m_valueBitmap
= bmpNew
;
2124 m_valueBitmap
= new wxBitmap(bmp
);
2127 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2131 m_valueBitmap
= NULL
;
2132 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
2137 wxPGProperty
* wxPGProperty::GetMainParent() const
2139 const wxPGProperty
* curChild
= this;
2140 const wxPGProperty
* curParent
= m_parent
;
2142 while ( curParent
&& !curParent
->IsCategory() )
2144 curChild
= curParent
;
2145 curParent
= curParent
->m_parent
;
2148 return (wxPGProperty
*) curChild
;
2152 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
2155 // Returns last visible sub-item, recursively.
2156 if ( !IsExpanded() || !GetChildCount() )
2159 return Last()->GetLastVisibleSubItem();
2163 bool wxPGProperty::IsVisible() const
2165 const wxPGProperty
* parent
;
2167 if ( HasFlag(wxPG_PROP_HIDDEN
) )
2170 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
2172 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
2179 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
2181 wxPropertyGridPageState
* state
= GetParentState();
2184 wxPropertyGrid
* propGrid
= state
->GetGrid();
2185 if ( state
== propGrid
->GetState() )
2191 int wxPGProperty::GetY2( int lh
) const
2193 const wxPGProperty
* parent
;
2194 const wxPGProperty
* child
= this;
2198 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2200 if ( !parent
->IsExpanded() )
2202 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2207 y
-= lh
; // need to reduce one level
2213 int wxPGProperty::GetY() const
2215 return GetY2(GetGrid()->GetRowHeight());
2218 // This is used by Insert etc.
2219 void wxPGProperty::DoAddChild( wxPGProperty
* prop
, int index
,
2222 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2224 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2225 m_children
.push_back( prop
);
2229 m_children
.insert( m_children
.begin()+index
, prop
);
2230 if ( correct_mode
) FixIndicesOfChildren( index
);
2233 prop
->m_parent
= this;
2236 void wxPGProperty::DoPreAddChild( int index
, wxPGProperty
* prop
)
2238 wxASSERT_MSG( prop
->GetBaseName().length(),
2239 "Property's children must have unique, non-empty "
2240 "names within their scope" );
2242 prop
->m_arrIndex
= index
;
2243 m_children
.insert( m_children
.begin()+index
,
2246 int custImgHeight
= prop
->OnMeasureImage().y
;
2247 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2248 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2250 prop
->m_parent
= this;
2253 void wxPGProperty::AddPrivateChild( wxPGProperty
* prop
)
2255 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2256 SetParentalType(wxPG_PROP_AGGREGATE
);
2258 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2259 wxPG_PROP_AGGREGATE
,
2260 "Do not mix up AddPrivateChild() calls with other "
2261 "property adders." );
2263 DoPreAddChild( m_children
.size(), prop
);
2266 #if wxPG_COMPATIBILITY_1_4
2267 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2269 AddPrivateChild(prop
);
2273 wxPGProperty
* wxPGProperty::InsertChild( int index
,
2274 wxPGProperty
* childProperty
)
2277 index
= m_children
.size();
2279 if ( m_parentState
)
2281 m_parentState
->DoInsert(this, index
, childProperty
);
2285 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2286 SetParentalType(wxPG_PROP_MISC_PARENT
);
2288 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2289 wxPG_PROP_MISC_PARENT
,
2290 "Do not mix up AddPrivateChild() calls with other "
2291 "property adders." );
2293 DoPreAddChild( index
, childProperty
);
2296 return childProperty
;
2299 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2301 wxArrayPGProperty::iterator it
;
2302 wxArrayPGProperty
& children
= m_children
;
2304 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2314 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2316 wxASSERT( GetChildCount() );
2317 wxASSERT( !IsCategory() );
2319 *value
= GetValue();
2321 if ( !list
.GetCount() )
2324 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2326 bool allChildrenSpecified
;
2328 // Don't fully update aggregate properties unless all children have
2330 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2331 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2333 allChildrenSpecified
= true;
2337 wxVariant childValue
= list
[n
];
2339 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2341 for ( i
=0; i
<GetChildCount(); i
++ )
2343 const wxPGProperty
* child
= Item(i
);
2345 if ( childValue
.GetName() == child
->GetBaseName() )
2347 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2349 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2351 wxVariant
cv2(child
->GetValue());
2352 child
->AdaptListToValue(childValue
, &cv2
);
2356 if ( allChildrenSpecified
)
2358 *value
= ChildChanged(*value
, i
, childValue
);
2362 if ( n
== (unsigned int)list
.GetCount() )
2364 childValue
= list
[n
];
2370 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2373 for ( i
=starthere
;i
<GetChildCount();i
++)
2374 Item(i
)->m_arrIndex
= i
;
2378 // Returns (direct) child property with given name (or NULL if not found)
2379 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2383 for ( i
=0; i
<GetChildCount(); i
++ )
2385 wxPGProperty
* p
= Item(i
);
2386 if ( p
->m_name
== name
)
2390 // Does it have point, then?
2391 int pos
= name
.Find(wxS('.'));
2395 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2397 if ( !p
|| !p
->GetChildCount() )
2400 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2403 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2405 unsigned int i
= hintIndex
;
2407 if ( i
>= GetChildCount() )
2410 unsigned int lastIndex
= i
- 1;
2412 if ( lastIndex
>= GetChildCount() )
2413 lastIndex
= GetChildCount() - 1;
2417 wxPGProperty
* p
= Item(i
);
2418 if ( p
->m_name
== name
)
2421 if ( i
== lastIndex
)
2425 if ( i
== GetChildCount() )
2432 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2434 // Returns height of children, recursively, and
2435 // by taking expanded/collapsed status into account.
2437 // iMax is used when finding property y-positions.
2443 iMax_
= GetChildCount();
2445 unsigned int iMax
= iMax_
;
2447 wxASSERT( iMax
<= GetChildCount() );
2449 if ( !IsExpanded() && GetParent() )
2454 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2456 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2458 if ( !pwc
->IsExpanded() ||
2459 pwc
->GetChildCount() == 0 )
2462 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2471 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
,
2473 unsigned int* nextItemY
) const
2475 wxASSERT( nextItemY
);
2477 // Linear search at the moment
2479 // nextItemY = y of next visible property, final value will be written back.
2480 wxPGProperty
* result
= NULL
;
2481 wxPGProperty
* current
= NULL
;
2482 unsigned int iy
= *nextItemY
;
2484 unsigned int iMax
= GetChildCount();
2488 wxPGProperty
* pwc
= Item(i
);
2490 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2501 if ( pwc
->IsExpanded() &&
2502 pwc
->GetChildCount() > 0 )
2504 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2516 if ( !result
&& y
< iy
)
2524 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2528 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2532 return (wxPGProperty
*) result
;
2535 void wxPGProperty::Empty()
2538 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2540 for ( i
=0; i
<GetChildCount(); i
++ )
2542 delete m_children
[i
];
2549 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
) const
2551 unsigned int nextItem
;
2552 return GetItemAtY( y
, GetGrid()->GetRowHeight(), &nextItem
);
2555 void wxPGProperty::DeleteChildren()
2557 wxPropertyGridPageState
* state
= m_parentState
;
2559 if ( !GetChildCount() )
2562 // Because deletion is sometimes deferred, we have to use
2563 // this sort of code for enumerating the child properties.
2564 unsigned int i
= GetChildCount();
2568 state
->DoDelete(Item(i
), true);
2572 wxVariant
wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2573 int WXUNUSED(childIndex
),
2574 wxVariant
& WXUNUSED(childValue
) ) const
2576 return wxNullVariant
;
2579 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2583 const wxVariantList
* pList
= NULL
;
2584 wxVariantList::const_iterator node
;
2588 pList
= &pendingList
->GetList();
2589 node
= pList
->begin();
2592 for ( i
=0; i
<GetChildCount(); i
++ )
2594 wxPGProperty
* child
= Item(i
);
2595 const wxVariant
* listValue
= NULL
;
2600 const wxString
& childName
= child
->GetBaseName();
2602 for ( ; node
!= pList
->end(); ++node
)
2604 const wxVariant
& item
= *((const wxVariant
*)*node
);
2605 if ( item
.GetName() == childName
)
2615 value
= child
->GetValue();
2617 if ( value
.IsNull() )
2620 // Check recursively
2621 if ( child
->GetChildCount() )
2623 const wxVariant
* childList
= NULL
;
2625 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2626 childList
= listValue
;
2628 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2636 wxPGProperty
* wxPGProperty::UpdateParentValues()
2638 wxPGProperty
* parent
= m_parent
;
2639 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2640 !parent
->IsCategory() && !parent
->IsRoot() )
2643 parent
->DoGenerateComposedValue(s
);
2644 parent
->m_value
= s
;
2645 return parent
->UpdateParentValues();
2650 bool wxPGProperty::IsTextEditable() const
2652 if ( HasFlag(wxPG_PROP_READONLY
) )
2655 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2657 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2664 // Call after fixed sub-properties added/removed after creation.
2665 // if oldSelInd >= 0 and < new max items, then selection is
2666 // moved to it. Note: oldSelInd -2 indicates that this property
2667 // should be selected.
2668 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2670 wxPropertyGridPageState
* state
= GetParentState();
2671 wxPropertyGrid
* grid
= state
->GetGrid();
2674 // Re-repare children (recursively)
2675 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2677 wxPGProperty
* child
= Item(i
);
2678 child
->InitAfterAdded(state
, grid
);
2681 wxPGProperty
* sel
= NULL
;
2682 if ( oldSelInd
>= (int)m_children
.size() )
2683 oldSelInd
= (int)m_children
.size() - 1;
2685 if ( oldSelInd
>= 0 )
2686 sel
= m_children
[oldSelInd
];
2687 else if ( oldSelInd
== -2 )
2691 state
->DoSelectProperty(sel
);
2693 if ( state
== grid
->GetState() )
2695 grid
->GetPanel()->Refresh();
2699 // -----------------------------------------------------------------------
2701 // -----------------------------------------------------------------------
2703 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2704 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2707 wxPGRootProperty::wxPGRootProperty( const wxString
& name
)
2717 wxPGRootProperty::~wxPGRootProperty()
2722 // -----------------------------------------------------------------------
2723 // wxPropertyCategory
2724 // -----------------------------------------------------------------------
2726 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2727 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2729 void wxPropertyCategory::Init()
2731 // don't set colour - prepareadditem method should do this
2732 SetParentalType(wxPG_PROP_CATEGORY
);
2733 m_capFgColIndex
= 1;
2737 wxPropertyCategory::wxPropertyCategory()
2744 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2745 : wxPGProperty(label
,name
)
2751 wxPropertyCategory::~wxPropertyCategory()
2756 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2757 int WXUNUSED(argFlags
) ) const
2759 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_STRING
)
2760 return m_value
.GetString();
2761 return wxEmptyString
;
2764 wxString
wxPropertyCategory::GetValueAsString( int argFlags
) const
2766 #if wxPG_COMPATIBILITY_1_4
2767 // This is backwards compatibility test
2768 // That is, to make sure this function is not overridden
2769 // (instead, ValueToString() should be).
2770 if ( argFlags
== 0xFFFF )
2772 // Do not override! (for backwards compliancy)
2773 return g_invalidStringContent
;
2777 // Unspecified value is always empty string
2778 if ( IsValueUnspecified() )
2779 return wxEmptyString
;
2781 return wxPGProperty::GetValueAsString(argFlags
);
2784 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2786 if ( m_textExtent
> 0 )
2787 return m_textExtent
;
2789 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2793 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2796 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2800 // -----------------------------------------------------------------------
2802 // -----------------------------------------------------------------------
2804 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
2808 wxPGChoiceEntry
entry(label
, value
);
2809 return m_data
->Insert( -1, entry
);
2812 // -----------------------------------------------------------------------
2814 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
2818 wxPGChoiceEntry
entry(label
, value
);
2819 entry
.SetBitmap(bitmap
);
2820 return m_data
->Insert( -1, entry
);
2823 // -----------------------------------------------------------------------
2825 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
2829 return m_data
->Insert( index
, entry
);
2832 // -----------------------------------------------------------------------
2834 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
2838 wxPGChoiceEntry
entry(label
, value
);
2839 return m_data
->Insert( index
, entry
);
2842 // -----------------------------------------------------------------------
2844 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
2850 while ( index
< GetCount() )
2852 int cmpRes
= GetLabel(index
).Cmp(label
);
2858 wxPGChoiceEntry
entry(label
, value
);
2859 return m_data
->Insert( index
, entry
);
2862 // -----------------------------------------------------------------------
2864 void wxPGChoices::Add( const wxChar
* const* labels
, const ValArrItem
* values
)
2868 unsigned int itemcount
= 0;
2869 const wxChar
* const* p
= &labels
[0];
2870 while ( *p
) { p
++; itemcount
++; }
2873 for ( i
= 0; i
< itemcount
; i
++ )
2878 wxPGChoiceEntry
entry(labels
[i
], value
);
2879 m_data
->Insert( i
, entry
);
2883 // -----------------------------------------------------------------------
2885 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
2890 unsigned int itemcount
= arr
.size();
2892 for ( i
= 0; i
< itemcount
; i
++ )
2895 if ( &arrint
&& arrint
.size() )
2897 wxPGChoiceEntry
entry(arr
[i
], value
);
2898 m_data
->Insert( i
, entry
);
2902 // -----------------------------------------------------------------------
2904 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
2908 wxASSERT( m_data
->GetRefCount() != -1 );
2909 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
2910 m_data
->m_items
.begin()+nIndex
+count
);
2913 // -----------------------------------------------------------------------
2915 void wxPGChoices::Clear()
2917 if ( m_data
!= wxPGChoicesEmptyData
)
2924 // -----------------------------------------------------------------------
2926 int wxPGChoices::Index( const wxString
& str
) const
2931 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2933 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2934 if ( entry
.HasText() && entry
.GetText() == str
)
2941 // -----------------------------------------------------------------------
2943 int wxPGChoices::Index( int val
) const
2948 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2950 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2951 if ( entry
.GetValue() == val
)
2958 // -----------------------------------------------------------------------
2960 wxArrayString
wxPGChoices::GetLabels() const
2965 if ( this && IsOk() )
2966 for ( i
=0; i
<GetCount(); i
++ )
2967 arr
.push_back(GetLabel(i
));
2972 // -----------------------------------------------------------------------
2974 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
2981 for ( i
=0; i
< strings
.size(); i
++ )
2983 int index
= Index(strings
[i
]);
2985 arr
.Add(GetValue(index
));
2987 arr
.Add(wxPG_INVALID_VALUE
);
2994 // -----------------------------------------------------------------------
2996 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
2997 wxArrayString
* unmatched
) const
3004 for ( i
=0; i
< strings
.size(); i
++ )
3006 const wxString
& str
= strings
[i
];
3007 int index
= Index(str
);
3010 else if ( unmatched
)
3011 unmatched
->Add(str
);
3018 // -----------------------------------------------------------------------
3020 void wxPGChoices::AllocExclusive()
3024 if ( m_data
->GetRefCount() != 1 )
3026 wxPGChoicesData
* data
= new wxPGChoicesData();
3027 data
->CopyDataFrom(m_data
);
3033 // -----------------------------------------------------------------------
3035 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
3039 if ( data
!= wxPGChoicesEmptyData
)
3046 // -----------------------------------------------------------------------
3048 void wxPGChoices::Init()
3050 m_data
= wxPGChoicesEmptyData
;
3053 // -----------------------------------------------------------------------
3055 void wxPGChoices::Free()
3057 if ( m_data
!= wxPGChoicesEmptyData
)
3060 m_data
= wxPGChoicesEmptyData
;
3064 // -----------------------------------------------------------------------
3065 // wxPGAttributeStorage
3066 // -----------------------------------------------------------------------
3068 wxPGAttributeStorage::wxPGAttributeStorage()
3072 wxPGAttributeStorage::~wxPGAttributeStorage()
3074 wxPGHashMapS2P::iterator it
;
3076 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
3078 wxVariantData
* data
= (wxVariantData
*) it
->second
;
3083 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
3085 wxVariantData
* data
= value
.GetData();
3088 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
3089 if ( it
!= m_map
.end() )
3091 ((wxVariantData
*)it
->second
)->DecRef();
3095 // If Null variant, just remove from set
3109 #endif // wxUSE_PROPGRID