1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/property.cpp
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
34 #include "wx/settings.h"
38 #include "wx/propgrid/propgrid.h"
41 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
44 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
46 #if wxPG_COMPATIBILITY_1_4
48 // Used to establish backwards compatiblity
49 const char* g_invalidStringContent
= "@__TOTALLY_INVALID_STRING__@";
53 // -----------------------------------------------------------------------
55 static void wxPGDrawFocusRect( wxDC
& dc
, const wxRect
& rect
)
57 #if defined(__WXMSW__) && !defined(__WXWINCE__)
58 // FIXME: Use DrawFocusRect code above (currently it draws solid line
59 // for caption focus but works ok for other stuff).
60 // Also, it seems that this code may not work in future wx versions.
61 dc
.SetLogicalFunction(wxINVERT
);
63 wxPen
pen(*wxBLACK
,1,wxDOT
);
64 pen
.SetCap(wxCAP_BUTT
);
66 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
68 dc
.DrawRectangle(rect
);
70 dc
.SetLogicalFunction(wxCOPY
);
72 dc
.SetLogicalFunction(wxINVERT
);
74 dc
.SetPen(wxPen(*wxBLACK
,1,wxDOT
));
75 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
77 dc
.DrawRectangle(rect
);
79 dc
.SetLogicalFunction(wxCOPY
);
83 // -----------------------------------------------------------------------
85 // -----------------------------------------------------------------------
87 wxSize
wxPGCellRenderer::GetImageSize( const wxPGProperty
* WXUNUSED(property
),
89 int WXUNUSED(item
) ) const
94 void wxPGCellRenderer::DrawText( wxDC
& dc
, const wxRect
& rect
,
95 int xOffset
, const wxString
& text
) const
98 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
99 rect
.y
+((rect
.height
-dc
.GetCharHeight())/2) );
102 void wxPGCellRenderer::DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
103 int xOffset
, const wxString
& text
,
104 wxPGProperty
* property
,
105 const wxPGEditor
* editor
) const
107 int yOffset
= ((rect
.height
-dc
.GetCharHeight())/2);
114 rect2
.height
-= yOffset
;
115 editor
->DrawValue( dc
, rect2
, property
, text
);
120 rect
.x
+xOffset
+wxPG_XBEFORETEXT
,
125 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC
& dc
, int x
, int y
, int w
, int h
) const
127 wxRect
focusRect(x
,y
+((h
-dc
.GetCharHeight())/2),w
,h
);
128 wxPGDrawFocusRect(dc
,focusRect
);
131 int wxPGCellRenderer::PreDrawCell( wxDC
& dc
, const wxRect
& rect
, const wxPGCell
& cell
, int flags
) const
135 // If possible, use cell colours
136 if ( !(flags
& DontUseCellBgCol
) )
138 dc
.SetPen(cell
.GetBgCol());
139 dc
.SetBrush(cell
.GetBgCol());
142 if ( !(flags
& DontUseCellFgCol
) )
144 dc
.SetTextForeground(cell
.GetFgCol());
147 // Draw Background, but only if not rendering in control
148 // (as control already has rendered correct background).
149 if ( !(flags
& (Control
|ChoicePopup
)) )
150 dc
.DrawRectangle(rect
);
152 // Use cell font, if provided
153 const wxFont
& font
= cell
.GetFont();
157 const wxBitmap
& bmp
= cell
.GetBitmap();
159 // Do not draw oversized bitmap outside choice popup
160 ((flags
& ChoicePopup
) || bmp
.GetHeight() < rect
.height
)
164 rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
165 rect
.y
+ wxPG_CUSTOM_IMAGE_SPACINGY
,
167 imageWidth
= bmp
.GetWidth();
173 void wxPGCellRenderer::PostDrawCell( wxDC
& dc
,
174 const wxPropertyGrid
* propGrid
,
175 const wxPGCell
& cell
,
176 int WXUNUSED(flags
) ) const
179 const wxFont
& font
= cell
.GetFont();
181 dc
.SetFont(propGrid
->GetFont());
184 // -----------------------------------------------------------------------
185 // wxPGDefaultRenderer
186 // -----------------------------------------------------------------------
188 void wxPGDefaultRenderer::Render( wxDC
& dc
, const wxRect
& rect
,
189 const wxPropertyGrid
* propertyGrid
, wxPGProperty
* property
,
190 int column
, int item
, int flags
) const
192 bool isUnspecified
= property
->IsValueUnspecified();
194 if ( column
== 1 && item
== -1 )
196 int cmnVal
= property
->GetCommonValue();
200 if ( !isUnspecified
)
201 DrawText( dc
, rect
, 0, propertyGrid
->GetCommonValueLabel(cmnVal
) );
206 const wxPGEditor
* editor
= NULL
;
207 const wxPGCell
* cell
= NULL
;
211 int preDrawFlags
= flags
;
213 property
->GetDisplayInfo(column
, item
, flags
, &text
, &cell
);
215 imageWidth
= PreDrawCell( dc
, rect
, *cell
, preDrawFlags
);
219 editor
= property
->GetColumnEditor(column
);
221 if ( !isUnspecified
)
223 // Regular property value
225 wxSize imageSize
= propertyGrid
->GetImageSize(property
, item
);
227 wxPGPaintData paintdata
;
228 paintdata
.m_parent
= propertyGrid
;
229 paintdata
.m_choiceItem
= item
;
231 if ( imageSize
.x
> 0 )
233 wxRect
imageRect(rect
.x
+ wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
234 rect
.y
+wxPG_CUSTOM_IMAGE_SPACINGY
,
235 wxPG_CUSTOM_IMAGE_WIDTH
,
236 rect
.height
-(wxPG_CUSTOM_IMAGE_SPACINGY
*2));
238 dc
.SetPen( wxPen(propertyGrid
->GetCellTextColour(), 1, wxSOLID
) );
240 paintdata
.m_drawnWidth
= imageSize
.x
;
241 paintdata
.m_drawnHeight
= imageSize
.y
;
243 property
->OnCustomPaint( dc
, imageRect
, paintdata
);
245 imageWidth
= paintdata
.m_drawnWidth
;
248 text
= property
->GetValueAsString();
251 if ( propertyGrid
->GetColumnCount() <= 2 )
253 wxString unitsString
= property
->GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
254 if ( unitsString
.length() )
255 text
= wxString::Format(wxS("%s %s"), text
.c_str(), unitsString
.c_str() );
259 if ( text
.length() == 0 )
261 // Try to show inline help if no text
262 wxVariant vInlineHelp
= property
->GetAttribute(wxPGGlobalVars
->m_strInlineHelp
);
263 if ( !vInlineHelp
.IsNull() )
265 text
= vInlineHelp
.GetString();
266 dc
.SetTextForeground(propertyGrid
->GetCellDisabledTextColour());
268 // Must make the editor NULL to override it's own rendering
275 int imageOffset
= property
->GetImageOffset(imageWidth
);
277 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
279 // active caption gets nice dotted rectangle
280 if ( property
->IsCategory() /*&& column == 0*/ )
282 if ( flags
& Selected
)
284 if ( imageOffset
> 0 )
286 imageOffset
-= DEFAULT_IMAGE_OFFSET_INCREMENT
;
287 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
290 DrawCaptionSelectionRect( dc
,
291 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
292 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
293 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
294 propertyGrid
->GetCaptionFont())
295 +(wxPG_CAPRECTXMARGIN
*2),
296 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
300 PostDrawCell(dc
, propertyGrid
, *cell
, preDrawFlags
);
303 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
307 if ( property
&& column
== 1 )
311 wxBitmap
* bmp
= property
->GetValueImage();
313 if ( bmp
&& bmp
->Ok() )
314 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
320 // -----------------------------------------------------------------------
322 // -----------------------------------------------------------------------
324 wxPGCellData::wxPGCellData()
327 m_hasValidText
= false;
330 // -----------------------------------------------------------------------
332 // -----------------------------------------------------------------------
339 wxPGCell::wxPGCell( const wxString
& text
,
340 const wxBitmap
& bitmap
,
341 const wxColour
& fgCol
,
342 const wxColour
& bgCol
)
345 wxPGCellData
* data
= new wxPGCellData();
348 data
->m_bitmap
= bitmap
;
349 data
->m_fgCol
= fgCol
;
350 data
->m_bgCol
= bgCol
;
351 data
->m_hasValidText
= true;
354 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
356 wxPGCellData
* c
= new wxPGCellData();
357 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
358 c
->m_text
= o
->m_text
;
359 c
->m_bitmap
= o
->m_bitmap
;
360 c
->m_fgCol
= o
->m_fgCol
;
361 c
->m_bgCol
= o
->m_bgCol
;
362 c
->m_hasValidText
= o
->m_hasValidText
;
366 void wxPGCell::SetText( const wxString
& text
)
370 GetData()->SetText(text
);
373 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
377 GetData()->SetBitmap(bitmap
);
380 void wxPGCell::SetFgCol( const wxColour
& col
)
384 GetData()->SetFgCol(col
);
387 void wxPGCell::SetFont( const wxFont
& font
)
391 GetData()->SetFont(font
);
394 void wxPGCell::SetBgCol( const wxColour
& col
)
398 GetData()->SetBgCol(col
);
401 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
405 wxPGCellData
* data
= GetData();
407 if ( srcCell
.HasText() )
408 data
->SetText(srcCell
.GetText());
410 if ( srcCell
.GetFgCol().IsOk() )
411 data
->SetFgCol(srcCell
.GetFgCol());
413 if ( srcCell
.GetBgCol().IsOk() )
414 data
->SetBgCol(srcCell
.GetBgCol());
416 if ( srcCell
.GetBitmap().IsOk() )
417 data
->SetBitmap(srcCell
.GetBitmap());
420 // -----------------------------------------------------------------------
422 // -----------------------------------------------------------------------
424 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
426 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
428 void wxPGProperty::Init()
434 m_parentState
= NULL
;
437 m_clientObject
= NULL
;
439 m_customEditor
= NULL
;
443 m_valueBitmap
= NULL
;
445 m_maxLen
= 0; // infinite maximum length
447 m_flags
= wxPG_PROP_PROPERTY
;
455 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
457 // We really need to check if &label and &name are NULL pointers
458 // (this can if we are called before property grid has been initalized)
460 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
463 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
466 DoSetName( m_label
);
471 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
472 wxPropertyGrid
* propgrid
)
475 // Called after property has been added to grid or page
476 // (so propgrid can be NULL, too).
478 wxPGProperty
* parent
= m_parent
;
479 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
481 m_parentState
= pageState
;
483 #if wxPG_COMPATIBILITY_1_4
484 // Make sure deprecated virtual functions are not implemented
485 wxString s
= GetValueAsString( 0xFFFF );
486 wxASSERT_MSG( s
== g_invalidStringContent
,
487 "Implement ValueToString() instead of GetValueAsString()" );
490 if ( !parentIsRoot
&& !parent
->IsCategory() )
492 m_cells
= parent
->m_cells
;
495 // If in hideable adding mode, or if assigned parent is hideable, then
496 // make this one hideable.
498 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
499 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
501 SetFlag( wxPG_PROP_HIDDEN
);
503 // Set custom image flag.
504 int custImgHeight
= OnMeasureImage().y
;
505 if ( custImgHeight
< 0 )
507 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
510 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
511 SetFlag(wxPG_PROP_NOEDITOR
);
513 // Make sure parent has some parental flags
514 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
515 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
519 // This is not a category.
523 unsigned char depth
= 1;
526 depth
= parent
->m_depth
;
527 if ( !parent
->IsCategory() )
531 unsigned char greyDepth
= depth
;
535 wxPropertyCategory
* pc
;
537 if ( parent
->IsCategory() )
538 pc
= (wxPropertyCategory
* ) parent
;
540 // This conditional compile is necessary to
541 // bypass some compiler bug.
542 pc
= pageState
->GetPropertyCategory(parent
);
545 greyDepth
= pc
->GetDepth();
547 greyDepth
= parent
->m_depthBgCol
;
550 m_depthBgCol
= greyDepth
;
554 // This is a category.
557 unsigned char depth
= 1;
560 depth
= parent
->m_depth
+ 1;
563 m_depthBgCol
= depth
;
567 // Has initial children
568 if ( GetChildCount() )
570 // Check parental flags
571 wxASSERT_MSG( ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
572 wxPG_PROP_AGGREGATE
) ||
573 ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
574 wxPG_PROP_MISC_PARENT
),
575 "wxPGProperty parental flags set incorrectly at "
578 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
580 // Properties with private children are not expanded by default.
583 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
585 // ...unless it cannot be expanded by user and therefore must
586 // remain visible at all times
591 // Prepare children recursively
592 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
594 wxPGProperty
* child
= Item(i
);
595 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
598 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
599 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
603 wxPGProperty::wxPGProperty()
610 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
617 wxPGProperty::~wxPGProperty()
619 delete m_clientObject
;
621 Empty(); // this deletes items
623 delete m_valueBitmap
;
628 // This makes it easier for us to detect dangling pointers
633 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
635 wxPGProperty
* parent
= m_parent
;
638 if ( parent
== candidate
)
640 parent
= parent
->m_parent
;
645 void wxPGProperty::SetName( const wxString
& newName
)
647 wxPropertyGrid
* pg
= GetGrid();
650 pg
->SetPropertyName(this, newName
);
655 wxString
wxPGProperty::GetName() const
657 wxPGProperty
* parent
= GetParent();
659 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
662 return m_parent
->GetName() + wxS(".") + m_name
;
665 wxPropertyGrid
* wxPGProperty::GetGrid() const
667 if ( !m_parentState
)
669 return m_parentState
->GetGrid();
672 int wxPGProperty::Index( const wxPGProperty
* p
) const
674 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
676 if ( p
== m_children
[i
] )
682 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
687 void wxPGProperty::OnSetValue()
691 void wxPGProperty::RefreshChildren ()
695 void wxPGProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
699 void wxPGProperty::GetDisplayInfo( unsigned int column
,
703 const wxPGCell
** pCell
)
705 const wxPGCell
* cell
= NULL
;
707 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
709 // Not painting listi of choice popups, so get text from property
710 cell
= &GetCell(column
);
711 if ( cell
->HasText() )
713 *pString
= cell
->GetText();
718 *pString
= GetLabel();
719 else if ( column
== 1 )
720 *pString
= GetDisplayedString();
721 else if ( column
== 2 )
722 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
727 wxASSERT( column
== 1 );
729 if ( choiceIndex
!= wxNOT_FOUND
)
731 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
732 if ( entry
.GetBitmap().IsOk() ||
733 entry
.GetFgCol().IsOk() ||
734 entry
.GetBgCol().IsOk() )
736 *pString
= m_choices
.GetLabel(choiceIndex
);
741 cell
= &GetCell(column
);
743 wxASSERT_MSG( cell
->GetData(),
744 wxString::Format("Invalid cell for property %s",
745 GetName().c_str()) );
751 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
754 if ( col != 1 || choiceIndex == wxNOT_FOUND )
756 const wxPGCell& cell = GetCell(col);
757 if ( cell->HasText() )
759 return cell->GetText();
766 return GetDisplayedString();
768 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
774 return m_choices.GetLabel(choiceIndex);
777 return wxEmptyString;
781 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
783 const wxVariantList
* valueOverrides
,
784 wxPGHashMapS2S
* childResults
) const
787 int iMax
= m_children
.size();
793 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
794 !(argFlags
& wxPG_FULL_VALUE
) )
795 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
797 int iMaxMinusOne
= iMax
-1;
799 if ( !IsTextEditable() )
800 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
802 wxPGProperty
* curChild
= m_children
[0];
804 bool overridesLeft
= false;
805 wxVariant overrideValue
;
806 wxVariantList::const_iterator node
;
808 if ( valueOverrides
)
810 node
= valueOverrides
->begin();
811 if ( node
!= valueOverrides
->end() )
813 overrideValue
= *node
;
814 overridesLeft
= true;
818 for ( i
= 0; i
< iMax
; i
++ )
820 wxVariant childValue
;
822 wxString childLabel
= curChild
->GetLabel();
824 // Check for value override
825 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
827 if ( !overrideValue
.IsNull() )
828 childValue
= overrideValue
;
830 childValue
= curChild
->GetValue();
832 if ( node
!= valueOverrides
->end() )
833 overrideValue
= *node
;
835 overridesLeft
= false;
839 childValue
= curChild
->GetValue();
843 if ( !childValue
.IsNull() )
845 if ( overridesLeft
&&
846 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
847 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
849 wxVariantList
& childList
= childValue
.GetList();
850 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
851 &childList
, childResults
);
855 s
= curChild
->ValueToString(childValue
,
856 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
860 if ( childResults
&& curChild
->GetChildCount() )
861 (*childResults
)[curChild
->GetName()] = s
;
864 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
867 if ( !curChild
->GetChildCount() || skip
)
870 text
+= wxS("[") + s
+ wxS("]");
872 if ( i
< iMaxMinusOne
)
874 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
875 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
876 !(argFlags
& wxPG_FULL_VALUE
) )
881 if ( !curChild
->GetChildCount() )
887 curChild
= m_children
[i
+1];
891 if ( (unsigned int)i
< m_children
.size() )
893 if ( !text
.EndsWith(wxS("; ")) )
894 text
+= wxS("; ...");
900 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
903 wxCHECK_MSG( GetChildCount() > 0,
905 "If user property does not have any children, it must "
906 "override GetValueAsString" );
908 // FIXME: Currently code below only works if value is actually m_value
909 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
910 "Sorry, currently default wxPGProperty::ValueToString() "
911 "implementation only works if value is m_value." );
914 DoGenerateComposedValue(text
, argFlags
);
918 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
920 #if wxPG_COMPATIBILITY_1_4
921 // This is backwards compatibility test
922 // That is, to make sure this function is not overridden
923 // (instead, ValueToString() should be).
924 if ( argFlags
== 0xFFFF )
926 // Do not override! (for backwards compliancy)
927 return g_invalidStringContent
;
931 if ( IsValueUnspecified() )
932 return wxEmptyString
;
934 if ( m_commonValue
== -1 )
936 wxVariant
value(GetValue());
937 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
941 // Return common value's string representation
942 wxPropertyGrid
* pg
= GetGrid();
943 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
945 if ( argFlags
& wxPG_FULL_VALUE
)
947 return cv
->GetLabel();
949 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
951 return cv
->GetEditableText();
955 return cv
->GetLabel();
959 wxString
wxPGProperty::GetValueString( int argFlags
) const
961 return GetValueAsString(argFlags
);
964 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
966 variant
= (long)number
;
970 // Convert semicolon delimited tokens into child values.
971 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
973 if ( !GetChildCount() )
976 unsigned int curChild
= 0;
978 unsigned int iMax
= m_children
.size();
980 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
981 !(argFlags
& wxPG_FULL_VALUE
) )
982 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
984 bool changed
= false;
989 // Its best only to add non-empty group items
990 bool addOnlyIfNotEmpty
= false;
991 const wxChar delimeter
= wxS(';');
993 size_t tokenStart
= 0xFFFFFF;
995 wxVariantList temp_list
;
996 wxVariant
list(temp_list
);
998 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
1000 wxLogTrace("propgrid",
1001 wxT(">> %s.StringToValue('%s')"), GetLabel(), text
);
1003 wxString::const_iterator it
= text
.begin();
1006 if ( it
!= text
.end() )
1013 // How many units we iterate string forward at the end of loop?
1014 // We need to keep track of this or risk going to negative
1015 // with it-- operation.
1016 unsigned int strPosIncrement
= 1;
1018 if ( tokenStart
!= 0xFFFFFF )
1021 if ( a
== delimeter
|| a
== 0 )
1023 token
= text
.substr(tokenStart
,pos
-tokenStart
);
1025 size_t len
= token
.length();
1027 if ( !addOnlyIfNotEmpty
|| len
> 0 )
1029 const wxPGProperty
* child
= Item(curChild
);
1030 wxVariant
variant(child
->GetValue());
1031 wxString childName
= child
->GetBaseName();
1033 wxLogTrace("propgrid",
1034 wxT("token = '%s', child = %s"),
1037 // Add only if editable or setting programmatically
1038 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1039 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1043 if ( child
->StringToValue(variant
, token
,
1044 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1046 // We really need to set the variant's name
1047 // *after* child->StringToValue() has been
1048 // called, since variant's value may be set by
1049 // assigning another variant into it, which
1050 // then usually causes name to be copied (ie.
1051 // usually cleared) as well. wxBoolProperty
1052 // being case in point with its use of
1053 // wxPGVariant_Bool macro as an optimization.
1054 variant
.SetName(childName
);
1055 list
.Append(variant
);
1062 // Empty, becomes unspecified
1064 variant
.SetName(childName
);
1065 list
.Append(variant
);
1071 if ( curChild
>= iMax
)
1075 tokenStart
= 0xFFFFFF;
1080 // Token is not running
1081 if ( a
!= wxS(' ') )
1084 addOnlyIfNotEmpty
= false;
1086 // Is this a group of tokens?
1087 if ( a
== wxS('[') )
1091 if ( it
!= text
.end() ) ++it
;
1093 size_t startPos
= pos
;
1095 // Group item - find end
1096 while ( it
!= text
.end() && depth
> 0 )
1102 if ( a
== wxS(']') )
1104 else if ( a
== wxS('[') )
1108 token
= text
.substr(startPos
,pos
-startPos
-1);
1110 if ( !token
.length() )
1113 const wxPGProperty
* child
= Item(curChild
);
1115 wxVariant oldChildValue
= child
->GetValue();
1116 wxVariant
variant(oldChildValue
);
1118 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1119 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1121 wxString childName
= child
->GetBaseName();
1123 bool stvRes
= child
->StringToValue( variant
, token
,
1125 if ( stvRes
|| (variant
!= oldChildValue
) )
1127 variant
.SetName(childName
);
1128 list
.Append(variant
);
1139 if ( curChild
>= iMax
)
1142 addOnlyIfNotEmpty
= true;
1144 tokenStart
= 0xFFFFFF;
1150 if ( a
== delimeter
)
1151 strPosIncrement
-= 1;
1159 it
+= strPosIncrement
;
1161 if ( it
!= text
.end() )
1170 pos
+= strPosIncrement
;
1179 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1181 wxVariant
variant(m_value
);
1182 bool res
= StringToValue(variant
, text
, argFlags
);
1188 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1190 wxVariant
variant(m_value
);
1191 bool res
= IntToValue(variant
, number
, argFlags
);
1197 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1199 if ( m_valueBitmap
)
1200 return wxSize(m_valueBitmap
->GetWidth(),-1);
1205 int wxPGProperty::GetImageOffset( int imageWidth
) const
1207 int imageOffset
= 0;
1211 // Do not increment offset too much for wide images
1212 if ( imageWidth
<= (wxPG_CUSTOM_IMAGE_WIDTH
+5) )
1213 imageOffset
= imageWidth
+ DEFAULT_IMAGE_OFFSET_INCREMENT
;
1215 imageOffset
= imageWidth
+ 1;
1221 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1223 return wxPGGlobalVars
->m_defaultRenderer
;
1226 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1230 wxBitmap
* bmp
= m_valueBitmap
;
1232 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1234 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1236 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1239 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1241 return wxPGEditor_TextCtrl
;
1244 // Default extra property event handling - that is, none at all.
1245 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1251 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1253 // If auto unspecified values are not wanted (via window or property style),
1254 // then get default value instead of wxNullVariant.
1255 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1256 !UsesAutoUnspecified() )
1258 value
= GetDefaultValue();
1261 if ( !value
.IsNull() )
1263 wxVariant tempListVariant
;
1266 // List variants are reserved a special purpose
1267 // as intermediate containers for child values
1268 // of properties with children.
1269 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1272 // However, situation is different for composed string properties
1273 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1275 tempListVariant
= value
;
1276 pList
= &tempListVariant
;
1280 AdaptListToValue(value
, &newValue
);
1282 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1285 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1286 flags
|= wxPG_SETVAL_AGGREGATED
;
1288 if ( pList
&& !pList
->IsNull() )
1290 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1291 wxASSERT( GetChildCount() );
1292 wxASSERT( !IsCategory() );
1294 wxVariantList
& list
= pList
->GetList();
1295 wxVariantList::iterator node
;
1298 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1300 // Children in list can be in any order, but we will give hint to
1301 // GetPropertyByNameWH(). This optimizes for full list parsing.
1302 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1304 wxVariant
& childValue
= *((wxVariant
*)*node
);
1305 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1308 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1309 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1311 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1313 wxVariant listRefCopy
= childValue
;
1314 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1318 wxVariant oldVal
= child
->GetValue();
1319 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1322 else if ( child
->GetValue() != childValue
)
1324 // For aggregate properties, we will trust RefreshChildren()
1325 // to update child values.
1326 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1327 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1328 if ( flags
& wxPG_SETVAL_BY_USER
)
1329 child
->SetFlag(wxPG_PROP_MODIFIED
);
1336 if ( !value
.IsNull() )
1342 if ( flags
& wxPG_SETVAL_BY_USER
)
1343 SetFlag(wxPG_PROP_MODIFIED
);
1345 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1350 if ( m_commonValue
!= -1 )
1352 wxPropertyGrid
* pg
= GetGrid();
1353 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1359 // Set children to unspecified, but only if aggregate or
1360 // value is <composed>
1361 if ( AreChildrenComponents() )
1364 for ( i
=0; i
<GetChildCount(); i
++ )
1365 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1369 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1370 UpdateParentValues();
1373 // Update editor control.
1374 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1376 wxPropertyGrid
* pg
= GetGridIfDisplayed();
1379 wxPGProperty
* selected
= pg
->GetSelectedProperty();
1381 // Only refresh the control if this was selected, or
1382 // this was some parent of selected, or vice versa)
1383 if ( selected
&& (selected
== this ||
1384 selected
->IsSomeParent(this) ||
1385 this->IsSomeParent(selected
)) )
1388 pg
->DrawItemAndValueRelated(this);
1394 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1396 GetGrid()->ValueChangeInEvent(value
);
1399 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1401 ChangeFlag(flag
, set
);
1404 for ( i
= 0; i
< GetChildCount(); i
++ )
1405 Item(i
)->SetFlagRecursively(flag
, set
);
1408 void wxPGProperty::RefreshEditor()
1413 wxPropertyGrid
* pg
= GetGrid();
1414 if ( pg
&& pg
->GetSelectedProperty() == this )
1415 pg
->RefreshEditor();
1418 wxVariant
wxPGProperty::GetDefaultValue() const
1420 wxVariant defVal
= GetAttribute(wxPG_ATTR_DEFAULT_VALUE
);
1421 if ( !defVal
.IsNull() )
1424 wxVariant value
= GetValue();
1426 if ( !value
.IsNull() )
1428 wxString
valueType(value
.GetType());
1430 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1431 return wxPGVariant_Zero
;
1432 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1433 return wxPGVariant_EmptyString
;
1434 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1435 return wxPGVariant_False
;
1436 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1437 return wxVariant(0.0);
1438 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1439 return wxVariant(wxArrayString());
1440 if ( valueType
== wxS("wxLongLong") )
1441 return WXVARIANT(wxLongLong(0));
1442 if ( valueType
== wxS("wxULongLong") )
1443 return WXVARIANT(wxULongLong(0));
1444 if ( valueType
== wxS("wxColour") )
1445 return WXVARIANT(*wxBLACK
);
1447 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1448 return wxVariant(wxDateTime::Now());
1450 if ( valueType
== wxS("wxFont") )
1451 return WXVARIANT(*wxNORMAL_FONT
);
1452 if ( valueType
== wxS("wxPoint") )
1453 return WXVARIANT(wxPoint(0, 0));
1454 if ( valueType
== wxS("wxSize") )
1455 return WXVARIANT(wxSize(0, 0));
1461 void wxPGProperty::EnsureCells( unsigned int column
)
1463 if ( column
>= m_cells
.size() )
1465 // Fill empty slots with default cells
1466 wxPropertyGrid
* pg
= GetGrid();
1467 wxPGCell defaultCell
;
1469 // Work around possible VC6 bug by using intermediate variables
1470 const wxPGCell
& propDefCell
= pg
->GetPropertyDefaultCell();
1471 const wxPGCell
& catDefCell
= pg
->GetCategoryDefaultCell();
1473 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1474 defaultCell
= propDefCell
;
1476 defaultCell
= catDefCell
;
1478 // TODO: Replace with resize() call
1479 unsigned int cellCountMax
= column
+1;
1481 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1482 m_cells
.push_back(defaultCell
);
1486 void wxPGProperty::SetCell( int column
,
1487 const wxPGCell
& cell
)
1489 EnsureCells(column
);
1491 m_cells
[column
] = cell
;
1494 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1495 unsigned int lastCol
,
1496 const wxPGCell
& cell
,
1497 const wxPGCell
& srcData
,
1498 wxPGCellData
* unmodCellData
,
1499 FlagType ignoreWithFlags
,
1503 // Sets cell in memory optimizing fashion. That is, if
1504 // current cell data matches unmodCellData, we will
1505 // simply get reference to data from cell. Otherwise,
1506 // cell information from srcData is merged into current.
1509 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1511 EnsureCells(lastCol
);
1513 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1515 if ( m_cells
[col
].GetData() == unmodCellData
)
1517 // Data matches... use cell directly
1518 m_cells
[col
] = cell
;
1522 // Data did not match... merge valid information
1523 m_cells
[col
].MergeFrom(srcData
);
1530 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1531 Item(i
)->AdaptiveSetCell( firstCol
,
1541 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1543 if ( m_cells
.size() > column
)
1544 return m_cells
[column
];
1546 wxPropertyGrid
* pg
= GetGrid();
1549 return pg
->GetCategoryDefaultCell();
1551 return pg
->GetPropertyDefaultCell();
1554 wxPGCell
& wxPGProperty::GetOrCreateCell( unsigned int column
)
1556 EnsureCells(column
);
1557 return m_cells
[column
];
1560 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1563 wxPGProperty
* firstProp
= this;
1564 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1567 // If category is tried to set recursively, skip it and only
1568 // affect the children.
1571 while ( firstProp
->IsCategory() )
1573 if ( !firstProp
->GetChildCount() )
1575 firstProp
= firstProp
->Item(0);
1579 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1580 wxPGCellData
* firstCellData
= firstCell
.GetData();
1582 wxPGCell
newCell(firstCell
);
1583 newCell
.SetBgCol(colour
);
1585 srcCell
.SetBgCol(colour
);
1588 GetParentState()->GetColumnCount()-1,
1592 recursively
? wxPG_PROP_CATEGORY
: 0,
1596 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1599 wxPGProperty
* firstProp
= this;
1600 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1603 // If category is tried to set recursively, skip it and only
1604 // affect the children.
1607 while ( firstProp
->IsCategory() )
1609 if ( !firstProp
->GetChildCount() )
1611 firstProp
= firstProp
->Item(0);
1615 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1616 wxPGCellData
* firstCellData
= firstCell
.GetData();
1618 wxPGCell
newCell(firstCell
);
1619 newCell
.SetFgCol(colour
);
1621 srcCell
.SetFgCol(colour
);
1624 GetParentState()->GetColumnCount()-1,
1628 recursively
? wxPG_PROP_CATEGORY
: 0,
1632 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1637 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1642 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1644 if ( DoSetAttribute( name
, value
) )
1646 // Support working without grid, when possible
1647 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1651 m_attributes
.Set( name
, value
);
1654 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1656 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1659 while ( attributes
.GetNext(it
, variant
) )
1660 SetAttribute( variant
.GetName(), variant
);
1663 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1669 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1671 return m_attributes
.FindValue(name
);
1674 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1676 wxVariant variant
= m_attributes
.FindValue(name
);
1678 if ( !variant
.IsNull() )
1679 return variant
.GetString();
1684 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1686 wxVariant variant
= m_attributes
.FindValue(name
);
1688 if ( variant
.IsNull() )
1691 return variant
.GetLong();
1694 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1696 wxVariant variant
= m_attributes
.FindValue(name
);
1698 if ( variant
.IsNull() )
1701 return variant
.GetDouble();
1704 wxVariant
wxPGProperty::GetAttributesAsList() const
1706 wxVariantList tempList
;
1707 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1709 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1712 while ( m_attributes
.GetNext(it
, variant
) )
1718 // Slots of utility flags are NULL
1719 const unsigned int gs_propFlagToStringSize
= 14;
1721 static const wxChar
* const gs_propFlagToString
[gs_propFlagToStringSize
] = {
1738 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1741 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1745 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1747 if ( relevantFlags
& a
)
1749 const wxChar
* fs
= gs_propFlagToString
[i
];
1761 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1765 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1767 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1769 const wxChar
* fs
= gs_propFlagToString
[i
];
1770 if ( fs
&& str
== fs
)
1776 WX_PG_TOKENIZER1_END()
1778 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1781 wxValidator
* wxPGProperty::DoGetValidator() const
1786 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1788 wxPropertyGrid
* pg
= GetGrid();
1789 int sel
= GetChoiceSelection();
1793 if ( index
== wxNOT_FOUND
)
1794 index
= m_choices
.GetCount();
1799 m_choices
.Insert(label
, index
, value
);
1801 if ( sel
!= newSel
)
1802 SetChoiceSelection(newSel
);
1804 if ( this == pg
->GetSelection() )
1805 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1811 void wxPGProperty::DeleteChoice( int index
)
1813 wxPropertyGrid
* pg
= GetGrid();
1815 int sel
= GetChoiceSelection();
1818 // Adjust current value
1821 SetValueToUnspecified();
1824 else if ( index
< sel
)
1829 m_choices
.RemoveAt(index
);
1831 if ( sel
!= newSel
)
1832 SetChoiceSelection(newSel
);
1834 if ( this == pg
->GetSelection() )
1835 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1838 int wxPGProperty::GetChoiceSelection() const
1840 wxVariant value
= GetValue();
1841 wxString valueType
= value
.GetType();
1842 int index
= wxNOT_FOUND
;
1844 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1847 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1849 index
= value
.GetLong();
1851 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1853 index
= m_choices
.Index(value
.GetString());
1855 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1857 index
= value
.GetBool()? 1 : 0;
1863 void wxPGProperty::SetChoiceSelection( int newValue
)
1865 // Changes value of a property with choices, but only
1866 // works if the value type is long or string.
1867 wxString valueType
= GetValue().GetType();
1869 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1871 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1873 SetValue( m_choices
.GetLabel(newValue
) );
1875 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1877 SetValue( (long) newValue
);
1881 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1883 m_choices
.Assign(choices
);
1886 // This may be needed to trigger some initialization
1887 // (but don't do it if property is somewhat uninitialized)
1888 wxVariant defVal
= GetDefaultValue();
1889 if ( defVal
.IsNull() )
1899 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1901 const wxPGEditor
* editor
;
1903 if ( !m_customEditor
)
1905 editor
= DoGetEditorClass();
1908 editor
= m_customEditor
;
1911 // Maybe override editor if common value specified
1912 if ( GetDisplayedCommonValueCount() )
1914 // TextCtrlAndButton -> ComboBoxAndButton
1915 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1916 editor
= wxPGEditor_ChoiceAndButton
;
1918 // TextCtrl -> ComboBox
1919 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1920 editor
= wxPGEditor_ComboBox
;
1926 bool wxPGProperty::HasVisibleChildren() const
1930 for ( i
=0; i
<GetChildCount(); i
++ )
1932 wxPGProperty
* child
= Item(i
);
1934 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1941 bool wxPGProperty::RecreateEditor()
1943 wxPropertyGrid
* pg
= GetGrid();
1946 wxPGProperty
* selected
= pg
->GetSelection();
1947 if ( this == selected
)
1949 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1956 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1958 delete m_valueBitmap
;
1960 if ( &bmp
&& bmp
.Ok() )
1963 wxSize maxSz
= GetGrid()->GetImageSize();
1964 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1966 if ( imSz
.y
!= maxSz
.y
)
1968 // Create a memory DC
1969 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1972 dc
.SelectObject(*bmpNew
);
1975 // FIXME: This is ugly - use image or wait for scaling patch.
1976 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1978 dc
.SetUserScale(scaleY
, scaleY
);
1980 dc
.DrawBitmap(bmp
, 0, 0);
1982 m_valueBitmap
= bmpNew
;
1986 m_valueBitmap
= new wxBitmap(bmp
);
1989 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1993 m_valueBitmap
= NULL
;
1994 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1999 wxPGProperty
* wxPGProperty::GetMainParent() const
2001 const wxPGProperty
* curChild
= this;
2002 const wxPGProperty
* curParent
= m_parent
;
2004 while ( curParent
&& !curParent
->IsCategory() )
2006 curChild
= curParent
;
2007 curParent
= curParent
->m_parent
;
2010 return (wxPGProperty
*) curChild
;
2014 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
2017 // Returns last visible sub-item, recursively.
2018 if ( !IsExpanded() || !GetChildCount() )
2021 return Last()->GetLastVisibleSubItem();
2025 bool wxPGProperty::IsVisible() const
2027 const wxPGProperty
* parent
;
2029 if ( HasFlag(wxPG_PROP_HIDDEN
) )
2032 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
2034 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
2041 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
2043 wxPropertyGridPageState
* state
= GetParentState();
2046 wxPropertyGrid
* propGrid
= state
->GetGrid();
2047 if ( state
== propGrid
->GetState() )
2053 int wxPGProperty::GetY2( int lh
) const
2055 const wxPGProperty
* parent
;
2056 const wxPGProperty
* child
= this;
2060 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2062 if ( !parent
->IsExpanded() )
2064 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2069 y
-= lh
; // need to reduce one level
2075 int wxPGProperty::GetY() const
2077 return GetY2(GetGrid()->GetRowHeight());
2080 // This is used by Insert etc.
2081 void wxPGProperty::DoAddChild( wxPGProperty
* prop
, int index
,
2084 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2086 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2087 m_children
.push_back( prop
);
2091 m_children
.insert( m_children
.begin()+index
, prop
);
2092 if ( correct_mode
) FixIndicesOfChildren( index
);
2095 prop
->m_parent
= this;
2098 void wxPGProperty::DoPreAddChild( int index
, wxPGProperty
* prop
)
2100 wxASSERT_MSG( prop
->GetBaseName().length(),
2101 "Property's children must have unique, non-empty "
2102 "names within their scope" );
2104 prop
->m_arrIndex
= index
;
2105 m_children
.insert( m_children
.begin()+index
,
2108 int custImgHeight
= prop
->OnMeasureImage().y
;
2109 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2110 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2112 prop
->m_parent
= this;
2115 void wxPGProperty::AddPrivateChild( wxPGProperty
* prop
)
2117 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2118 SetParentalType(wxPG_PROP_AGGREGATE
);
2120 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2121 wxPG_PROP_AGGREGATE
,
2122 "Do not mix up AddPrivateChild() calls with other "
2123 "property adders." );
2125 DoPreAddChild( m_children
.size(), prop
);
2128 #if wxPG_COMPATIBILITY_1_4
2129 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2131 AddPrivateChild(prop
);
2135 wxPGProperty
* wxPGProperty::InsertChild( int index
,
2136 wxPGProperty
* childProperty
)
2139 index
= m_children
.size();
2141 if ( m_parentState
)
2143 m_parentState
->DoInsert(this, index
, childProperty
);
2147 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2148 SetParentalType(wxPG_PROP_MISC_PARENT
);
2150 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2151 wxPG_PROP_MISC_PARENT
,
2152 "Do not mix up AddPrivateChild() calls with other "
2153 "property adders." );
2155 DoPreAddChild( index
, childProperty
);
2158 return childProperty
;
2161 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2163 wxArrayPGProperty::iterator it
;
2164 wxArrayPGProperty
& children
= m_children
;
2166 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2176 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2178 wxASSERT( GetChildCount() );
2179 wxASSERT( !IsCategory() );
2181 *value
= GetValue();
2183 if ( !list
.GetCount() )
2186 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2188 bool allChildrenSpecified
;
2190 // Don't fully update aggregate properties unless all children have
2192 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2193 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2195 allChildrenSpecified
= true;
2197 wxVariant childValue
= list
[0];
2201 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2203 for ( i
=0; i
<GetChildCount(); i
++ )
2205 const wxPGProperty
* child
= Item(i
);
2207 if ( childValue
.GetName() == child
->GetBaseName() )
2209 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2211 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2213 wxVariant
cv2(child
->GetValue());
2214 child
->AdaptListToValue(childValue
, &cv2
);
2218 if ( allChildrenSpecified
)
2220 *value
= ChildChanged(*value
, i
, childValue
);
2224 if ( n
== (unsigned int)list
.GetCount() )
2226 childValue
= list
[n
];
2232 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2235 for ( i
=starthere
;i
<GetChildCount();i
++)
2236 Item(i
)->m_arrIndex
= i
;
2240 // Returns (direct) child property with given name (or NULL if not found)
2241 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2245 for ( i
=0; i
<GetChildCount(); i
++ )
2247 wxPGProperty
* p
= Item(i
);
2248 if ( p
->m_name
== name
)
2252 // Does it have point, then?
2253 int pos
= name
.Find(wxS('.'));
2257 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2259 if ( !p
|| !p
->GetChildCount() )
2262 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2265 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2267 unsigned int i
= hintIndex
;
2269 if ( i
>= GetChildCount() )
2272 unsigned int lastIndex
= i
- 1;
2274 if ( lastIndex
>= GetChildCount() )
2275 lastIndex
= GetChildCount() - 1;
2279 wxPGProperty
* p
= Item(i
);
2280 if ( p
->m_name
== name
)
2283 if ( i
== lastIndex
)
2287 if ( i
== GetChildCount() )
2294 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2296 // Returns height of children, recursively, and
2297 // by taking expanded/collapsed status into account.
2299 // iMax is used when finding property y-positions.
2305 iMax_
= GetChildCount();
2307 unsigned int iMax
= iMax_
;
2309 wxASSERT( iMax
<= GetChildCount() );
2311 if ( !IsExpanded() && GetParent() )
2316 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2318 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2320 if ( !pwc
->IsExpanded() ||
2321 pwc
->GetChildCount() == 0 )
2324 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2333 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
,
2335 unsigned int* nextItemY
) const
2337 wxASSERT( nextItemY
);
2339 // Linear search at the moment
2341 // nextItemY = y of next visible property, final value will be written back.
2342 wxPGProperty
* result
= NULL
;
2343 wxPGProperty
* current
= NULL
;
2344 unsigned int iy
= *nextItemY
;
2346 unsigned int iMax
= GetChildCount();
2350 wxPGProperty
* pwc
= Item(i
);
2352 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2363 if ( pwc
->IsExpanded() &&
2364 pwc
->GetChildCount() > 0 )
2366 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2378 if ( !result
&& y
< iy
)
2386 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2390 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2394 return (wxPGProperty
*) result
;
2397 void wxPGProperty::Empty()
2400 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2402 for ( i
=0; i
<GetChildCount(); i
++ )
2404 delete m_children
[i
];
2411 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
) const
2413 unsigned int nextItem
;
2414 return GetItemAtY( y
, GetGrid()->GetRowHeight(), &nextItem
);
2417 void wxPGProperty::DeleteChildren()
2419 wxPropertyGridPageState
* state
= m_parentState
;
2421 while ( GetChildCount() )
2423 wxPGProperty
* child
= Item(GetChildCount()-1);
2424 state
->DoDelete(child
, true);
2428 wxVariant
wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2429 int WXUNUSED(childIndex
),
2430 wxVariant
& WXUNUSED(childValue
) ) const
2432 return wxNullVariant
;
2435 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2439 const wxVariantList
* pList
= NULL
;
2440 wxVariantList::const_iterator node
;
2444 pList
= &pendingList
->GetList();
2445 node
= pList
->begin();
2448 for ( i
=0; i
<GetChildCount(); i
++ )
2450 wxPGProperty
* child
= Item(i
);
2451 const wxVariant
* listValue
= NULL
;
2456 const wxString
& childName
= child
->GetBaseName();
2458 for ( ; node
!= pList
->end(); ++node
)
2460 const wxVariant
& item
= *((const wxVariant
*)*node
);
2461 if ( item
.GetName() == childName
)
2471 value
= child
->GetValue();
2473 if ( value
.IsNull() )
2476 // Check recursively
2477 if ( child
->GetChildCount() )
2479 const wxVariant
* childList
= NULL
;
2481 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2482 childList
= listValue
;
2484 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2492 wxPGProperty
* wxPGProperty::UpdateParentValues()
2494 wxPGProperty
* parent
= m_parent
;
2495 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2496 !parent
->IsCategory() && !parent
->IsRoot() )
2499 parent
->DoGenerateComposedValue(s
);
2500 parent
->m_value
= s
;
2501 return parent
->UpdateParentValues();
2506 bool wxPGProperty::IsTextEditable() const
2508 if ( HasFlag(wxPG_PROP_READONLY
) )
2511 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2513 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2520 // Call after fixed sub-properties added/removed after creation.
2521 // if oldSelInd >= 0 and < new max items, then selection is
2522 // moved to it. Note: oldSelInd -2 indicates that this property
2523 // should be selected.
2524 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2526 wxPropertyGridPageState
* state
= GetParentState();
2527 wxPropertyGrid
* grid
= state
->GetGrid();
2530 // Re-repare children (recursively)
2531 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2533 wxPGProperty
* child
= Item(i
);
2534 child
->InitAfterAdded(state
, grid
);
2537 wxPGProperty
* sel
= NULL
;
2538 if ( oldSelInd
>= (int)m_children
.size() )
2539 oldSelInd
= (int)m_children
.size() - 1;
2541 if ( oldSelInd
>= 0 )
2542 sel
= m_children
[oldSelInd
];
2543 else if ( oldSelInd
== -2 )
2547 state
->DoSelectProperty(sel
);
2549 if ( state
== grid
->GetState() )
2551 grid
->GetPanel()->Refresh();
2555 // -----------------------------------------------------------------------
2557 // -----------------------------------------------------------------------
2559 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2560 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2563 wxPGRootProperty::wxPGRootProperty( const wxString
& name
)
2573 wxPGRootProperty::~wxPGRootProperty()
2578 // -----------------------------------------------------------------------
2579 // wxPropertyCategory
2580 // -----------------------------------------------------------------------
2582 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2583 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2585 void wxPropertyCategory::Init()
2587 // don't set colour - prepareadditem method should do this
2588 SetParentalType(wxPG_PROP_CATEGORY
);
2589 m_capFgColIndex
= 1;
2593 wxPropertyCategory::wxPropertyCategory()
2600 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2601 : wxPGProperty(label
,name
)
2607 wxPropertyCategory::~wxPropertyCategory()
2612 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2613 int WXUNUSED(argFlags
) ) const
2615 return wxEmptyString
;
2618 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2620 if ( m_textExtent
> 0 )
2621 return m_textExtent
;
2623 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2627 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2630 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2634 // -----------------------------------------------------------------------
2636 // -----------------------------------------------------------------------
2638 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
2642 wxPGChoiceEntry
entry(label
, value
);
2643 return m_data
->Insert( -1, entry
);
2646 // -----------------------------------------------------------------------
2648 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
2652 wxPGChoiceEntry
entry(label
, value
);
2653 entry
.SetBitmap(bitmap
);
2654 return m_data
->Insert( -1, entry
);
2657 // -----------------------------------------------------------------------
2659 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
2663 return m_data
->Insert( index
, entry
);
2666 // -----------------------------------------------------------------------
2668 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
2672 wxPGChoiceEntry
entry(label
, value
);
2673 return m_data
->Insert( index
, entry
);
2676 // -----------------------------------------------------------------------
2678 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
2684 while ( index
< GetCount() )
2686 int cmpRes
= GetLabel(index
).Cmp(label
);
2692 wxPGChoiceEntry
entry(label
, value
);
2693 return m_data
->Insert( index
, entry
);
2696 // -----------------------------------------------------------------------
2698 void wxPGChoices::Add( const wxChar
* const* labels
, const ValArrItem
* values
)
2702 unsigned int itemcount
= 0;
2703 const wxChar
* const* p
= &labels
[0];
2704 while ( *p
) { p
++; itemcount
++; }
2707 for ( i
= 0; i
< itemcount
; i
++ )
2712 wxPGChoiceEntry
entry(labels
[i
], value
);
2713 m_data
->Insert( i
, entry
);
2717 // -----------------------------------------------------------------------
2719 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
2724 unsigned int itemcount
= arr
.size();
2726 for ( i
= 0; i
< itemcount
; i
++ )
2729 if ( &arrint
&& arrint
.size() )
2731 wxPGChoiceEntry
entry(arr
[i
], value
);
2732 m_data
->Insert( i
, entry
);
2736 // -----------------------------------------------------------------------
2738 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
2742 wxASSERT( m_data
->GetRefCount() != -1 );
2743 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
2744 m_data
->m_items
.begin()+nIndex
+count
);
2747 // -----------------------------------------------------------------------
2749 void wxPGChoices::Clear()
2751 if ( m_data
!= wxPGChoicesEmptyData
)
2758 // -----------------------------------------------------------------------
2760 int wxPGChoices::Index( const wxString
& str
) const
2765 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2767 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2768 if ( entry
.HasText() && entry
.GetText() == str
)
2775 // -----------------------------------------------------------------------
2777 int wxPGChoices::Index( int val
) const
2782 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2784 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2785 if ( entry
.GetValue() == val
)
2792 // -----------------------------------------------------------------------
2794 wxArrayString
wxPGChoices::GetLabels() const
2799 if ( this && IsOk() )
2800 for ( i
=0; i
<GetCount(); i
++ )
2801 arr
.push_back(GetLabel(i
));
2806 // -----------------------------------------------------------------------
2808 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
2815 for ( i
=0; i
< strings
.size(); i
++ )
2817 int index
= Index(strings
[i
]);
2819 arr
.Add(GetValue(index
));
2821 arr
.Add(wxPG_INVALID_VALUE
);
2828 // -----------------------------------------------------------------------
2830 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
2831 wxArrayString
* unmatched
) const
2838 for ( i
=0; i
< strings
.size(); i
++ )
2840 const wxString
& str
= strings
[i
];
2841 int index
= Index(str
);
2844 else if ( unmatched
)
2845 unmatched
->Add(str
);
2852 // -----------------------------------------------------------------------
2854 void wxPGChoices::AllocExclusive()
2858 if ( m_data
->GetRefCount() != 1 )
2860 wxPGChoicesData
* data
= new wxPGChoicesData();
2861 data
->CopyDataFrom(m_data
);
2867 // -----------------------------------------------------------------------
2869 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
2873 if ( data
!= wxPGChoicesEmptyData
)
2880 // -----------------------------------------------------------------------
2882 void wxPGChoices::Init()
2884 m_data
= wxPGChoicesEmptyData
;
2887 // -----------------------------------------------------------------------
2889 void wxPGChoices::Free()
2891 if ( m_data
!= wxPGChoicesEmptyData
)
2894 m_data
= wxPGChoicesEmptyData
;
2898 // -----------------------------------------------------------------------
2899 // wxPGAttributeStorage
2900 // -----------------------------------------------------------------------
2902 wxPGAttributeStorage::wxPGAttributeStorage()
2906 wxPGAttributeStorage::~wxPGAttributeStorage()
2908 wxPGHashMapS2P::iterator it
;
2910 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
2912 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2917 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2919 wxVariantData
* data
= value
.GetData();
2922 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2923 if ( it
!= m_map
.end() )
2925 ((wxVariantData
*)it
->second
)->DecRef();
2929 // If Null variant, just remove from set
2943 #endif // wxUSE_PROPGRID