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());
271 int imageOffset
= property
->GetImageOffset(imageWidth
);
273 DrawEditorValue( dc
, rect
, imageOffset
, text
, property
, editor
);
275 // active caption gets nice dotted rectangle
276 if ( property
->IsCategory() /*&& column == 0*/ )
278 if ( flags
& Selected
)
280 if ( imageOffset
> 0 )
282 imageOffset
-= DEFAULT_IMAGE_OFFSET_INCREMENT
;
283 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN2
+ 4;
286 DrawCaptionSelectionRect( dc
,
287 rect
.x
+wxPG_XBEFORETEXT
-wxPG_CAPRECTXMARGIN
+imageOffset
,
288 rect
.y
-wxPG_CAPRECTYMARGIN
+1,
289 ((wxPropertyCategory
*)property
)->GetTextExtent(propertyGrid
,
290 propertyGrid
->GetCaptionFont())
291 +(wxPG_CAPRECTXMARGIN
*2),
292 propertyGrid
->GetFontHeight()+(wxPG_CAPRECTYMARGIN
*2) );
296 PostDrawCell(dc
, propertyGrid
, *cell
, preDrawFlags
);
299 wxSize
wxPGDefaultRenderer::GetImageSize( const wxPGProperty
* property
,
303 if ( property
&& column
== 1 )
307 wxBitmap
* bmp
= property
->GetValueImage();
309 if ( bmp
&& bmp
->Ok() )
310 return wxSize(bmp
->GetWidth(),bmp
->GetHeight());
316 // -----------------------------------------------------------------------
318 // -----------------------------------------------------------------------
320 wxPGCellData::wxPGCellData()
323 m_hasValidText
= false;
326 // -----------------------------------------------------------------------
328 // -----------------------------------------------------------------------
335 wxPGCell::wxPGCell( const wxString
& text
,
336 const wxBitmap
& bitmap
,
337 const wxColour
& fgCol
,
338 const wxColour
& bgCol
)
341 wxPGCellData
* data
= new wxPGCellData();
344 data
->m_bitmap
= bitmap
;
345 data
->m_fgCol
= fgCol
;
346 data
->m_bgCol
= bgCol
;
347 data
->m_hasValidText
= true;
350 wxObjectRefData
*wxPGCell::CloneRefData( const wxObjectRefData
*data
) const
352 wxPGCellData
* c
= new wxPGCellData();
353 const wxPGCellData
* o
= (const wxPGCellData
*) data
;
354 c
->m_text
= o
->m_text
;
355 c
->m_bitmap
= o
->m_bitmap
;
356 c
->m_fgCol
= o
->m_fgCol
;
357 c
->m_bgCol
= o
->m_bgCol
;
358 c
->m_hasValidText
= o
->m_hasValidText
;
362 void wxPGCell::SetText( const wxString
& text
)
366 GetData()->SetText(text
);
369 void wxPGCell::SetBitmap( const wxBitmap
& bitmap
)
373 GetData()->SetBitmap(bitmap
);
376 void wxPGCell::SetFgCol( const wxColour
& col
)
380 GetData()->SetFgCol(col
);
383 void wxPGCell::SetFont( const wxFont
& font
)
387 GetData()->SetFont(font
);
390 void wxPGCell::SetBgCol( const wxColour
& col
)
394 GetData()->SetBgCol(col
);
397 void wxPGCell::MergeFrom( const wxPGCell
& srcCell
)
401 wxPGCellData
* data
= GetData();
403 if ( srcCell
.HasText() )
404 data
->SetText(srcCell
.GetText());
406 if ( srcCell
.GetFgCol().IsOk() )
407 data
->SetFgCol(srcCell
.GetFgCol());
409 if ( srcCell
.GetBgCol().IsOk() )
410 data
->SetBgCol(srcCell
.GetBgCol());
412 if ( srcCell
.GetBitmap().IsOk() )
413 data
->SetBitmap(srcCell
.GetBitmap());
416 // -----------------------------------------------------------------------
418 // -----------------------------------------------------------------------
420 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty
, wxObject
)
422 wxString
* wxPGProperty::sm_wxPG_LABEL
= NULL
;
424 void wxPGProperty::Init()
430 m_parentState
= NULL
;
433 m_clientObject
= NULL
;
435 m_customEditor
= NULL
;
439 m_valueBitmap
= NULL
;
441 m_maxLen
= 0; // infinite maximum length
443 m_flags
= wxPG_PROP_PROPERTY
;
451 void wxPGProperty::Init( const wxString
& label
, const wxString
& name
)
453 // We really need to check if &label and &name are NULL pointers
454 // (this can if we are called before property grid has been initalized)
456 if ( (&label
) != NULL
&& label
!= wxPG_LABEL
)
459 if ( (&name
) != NULL
&& name
!= wxPG_LABEL
)
462 DoSetName( m_label
);
467 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState
* pageState
,
468 wxPropertyGrid
* propgrid
)
471 // Called after property has been added to grid or page
472 // (so propgrid can be NULL, too).
474 wxPGProperty
* parent
= m_parent
;
475 bool parentIsRoot
= parent
->IsKindOf(CLASSINFO(wxPGRootProperty
));
477 m_parentState
= pageState
;
479 #if wxPG_COMPATIBILITY_1_4
480 // Make sure deprecated virtual functions are not implemented
481 wxString s
= GetValueAsString( 0xFFFF );
482 wxASSERT_MSG( s
== g_invalidStringContent
,
483 "Implement ValueToString() instead of GetValueAsString()" );
486 if ( !parentIsRoot
&& !parent
->IsCategory() )
488 m_cells
= parent
->m_cells
;
491 // If in hideable adding mode, or if assigned parent is hideable, then
492 // make this one hideable.
494 ( !parentIsRoot
&& parent
->HasFlag(wxPG_PROP_HIDDEN
) ) ||
495 ( propgrid
&& (propgrid
->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES
)) )
497 SetFlag( wxPG_PROP_HIDDEN
);
499 // Set custom image flag.
500 int custImgHeight
= OnMeasureImage().y
;
501 if ( custImgHeight
< 0 )
503 SetFlag(wxPG_PROP_CUSTOMIMAGE
);
506 if ( propgrid
&& (propgrid
->HasFlag(wxPG_LIMITED_EDITING
)) )
507 SetFlag(wxPG_PROP_NOEDITOR
);
509 // Make sure parent has some parental flags
510 if ( !parent
->HasFlag(wxPG_PROP_PARENTAL_FLAGS
) )
511 parent
->SetParentalType(wxPG_PROP_MISC_PARENT
);
515 // This is not a category.
519 unsigned char depth
= 1;
522 depth
= parent
->m_depth
;
523 if ( !parent
->IsCategory() )
527 unsigned char greyDepth
= depth
;
531 wxPropertyCategory
* pc
;
533 if ( parent
->IsCategory() )
534 pc
= (wxPropertyCategory
* ) parent
;
536 // This conditional compile is necessary to
537 // bypass some compiler bug.
538 pc
= pageState
->GetPropertyCategory(parent
);
541 greyDepth
= pc
->GetDepth();
543 greyDepth
= parent
->m_depthBgCol
;
546 m_depthBgCol
= greyDepth
;
550 // This is a category.
553 unsigned char depth
= 1;
556 depth
= parent
->m_depth
+ 1;
559 m_depthBgCol
= depth
;
563 // Has initial children
564 if ( GetChildCount() )
566 // Check parental flags
567 wxASSERT_MSG( ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
568 wxPG_PROP_AGGREGATE
) ||
569 ((m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
570 wxPG_PROP_MISC_PARENT
),
571 "wxPGProperty parental flags set incorrectly at "
574 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
576 // Properties with private children are not expanded by default.
579 else if ( propgrid
&& propgrid
->HasFlag(wxPG_HIDE_MARGIN
) )
581 // ...unless it cannot be expanded by user and therefore must
582 // remain visible at all times
587 // Prepare children recursively
588 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
590 wxPGProperty
* child
= Item(i
);
591 child
->InitAfterAdded(pageState
, pageState
->GetGrid());
594 if ( propgrid
&& (propgrid
->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES
) )
595 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED
, true);
599 wxPGProperty::wxPGProperty()
606 wxPGProperty::wxPGProperty( const wxString
& label
, const wxString
& name
)
613 wxPGProperty::~wxPGProperty()
615 delete m_clientObject
;
617 Empty(); // this deletes items
619 delete m_valueBitmap
;
624 // This makes it easier for us to detect dangling pointers
629 bool wxPGProperty::IsSomeParent( wxPGProperty
* candidate
) const
631 wxPGProperty
* parent
= m_parent
;
634 if ( parent
== candidate
)
636 parent
= parent
->m_parent
;
641 void wxPGProperty::SetName( const wxString
& newName
)
643 wxPropertyGrid
* pg
= GetGrid();
646 pg
->SetPropertyName(this, newName
);
651 wxString
wxPGProperty::GetName() const
653 wxPGProperty
* parent
= GetParent();
655 if ( !m_name
.length() || !parent
|| parent
->IsCategory() || parent
->IsRoot() )
658 return m_parent
->GetName() + wxS(".") + m_name
;
661 wxPropertyGrid
* wxPGProperty::GetGrid() const
663 if ( !m_parentState
)
665 return m_parentState
->GetGrid();
668 int wxPGProperty::Index( const wxPGProperty
* p
) const
670 for ( unsigned int i
= 0; i
<m_children
.size(); i
++ )
672 if ( p
== m_children
[i
] )
678 bool wxPGProperty::ValidateValue( wxVariant
& WXUNUSED(value
), wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
683 void wxPGProperty::OnSetValue()
687 void wxPGProperty::RefreshChildren ()
691 void wxPGProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
695 void wxPGProperty::GetDisplayInfo( unsigned int column
,
699 const wxPGCell
** pCell
)
701 const wxPGCell
* cell
= NULL
;
703 if ( !(flags
& wxPGCellRenderer::ChoicePopup
) )
705 // Not painting listi of choice popups, so get text from property
706 cell
= &GetCell(column
);
707 if ( cell
->HasText() )
709 *pString
= cell
->GetText();
714 *pString
= GetLabel();
715 else if ( column
== 1 )
716 *pString
= GetDisplayedString();
717 else if ( column
== 2 )
718 *pString
= GetAttribute(wxPGGlobalVars
->m_strUnits
, wxEmptyString
);
723 wxASSERT( column
== 1 );
725 if ( choiceIndex
!= wxNOT_FOUND
)
727 const wxPGChoiceEntry
& entry
= m_choices
[choiceIndex
];
728 if ( entry
.GetBitmap().IsOk() ||
729 entry
.GetFgCol().IsOk() ||
730 entry
.GetBgCol().IsOk() )
732 *pString
= m_choices
.GetLabel(choiceIndex
);
737 cell
= &GetCell(column
);
739 wxASSERT_MSG( cell
->GetData(),
740 wxString::Format("Invalid cell for property %s",
741 GetName().c_str()) );
747 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
750 if ( col != 1 || choiceIndex == wxNOT_FOUND )
752 const wxPGCell& cell = GetCell(col);
753 if ( cell->HasText() )
755 return cell->GetText();
762 return GetDisplayedString();
764 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
770 return m_choices.GetLabel(choiceIndex);
773 return wxEmptyString;
777 void wxPGProperty::DoGenerateComposedValue( wxString
& text
,
779 const wxVariantList
* valueOverrides
,
780 wxPGHashMapS2S
* childResults
) const
783 int iMax
= m_children
.size();
789 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
790 !(argFlags
& wxPG_FULL_VALUE
) )
791 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
793 int iMaxMinusOne
= iMax
-1;
795 if ( !IsTextEditable() )
796 argFlags
|= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
;
798 wxPGProperty
* curChild
= m_children
[0];
800 bool overridesLeft
= false;
801 wxVariant overrideValue
;
802 wxVariantList::const_iterator node
;
804 if ( valueOverrides
)
806 node
= valueOverrides
->begin();
807 if ( node
!= valueOverrides
->end() )
809 overrideValue
= *node
;
810 overridesLeft
= true;
814 for ( i
= 0; i
< iMax
; i
++ )
816 wxVariant childValue
;
818 wxString childLabel
= curChild
->GetLabel();
820 // Check for value override
821 if ( overridesLeft
&& overrideValue
.GetName() == childLabel
)
823 if ( !overrideValue
.IsNull() )
824 childValue
= overrideValue
;
826 childValue
= curChild
->GetValue();
828 if ( node
!= valueOverrides
->end() )
829 overrideValue
= *node
;
831 overridesLeft
= false;
835 childValue
= curChild
->GetValue();
839 if ( !childValue
.IsNull() )
841 if ( overridesLeft
&&
842 curChild
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
843 childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
845 wxVariantList
& childList
= childValue
.GetList();
846 DoGenerateComposedValue(s
, argFlags
|wxPG_COMPOSITE_FRAGMENT
,
847 &childList
, childResults
);
851 s
= curChild
->ValueToString(childValue
,
852 argFlags
|wxPG_COMPOSITE_FRAGMENT
);
856 if ( childResults
&& curChild
->GetChildCount() )
857 (*childResults
)[curChild
->GetName()] = s
;
860 if ( (argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
) && !s
.length() )
863 if ( !curChild
->GetChildCount() || skip
)
866 text
+= wxS("[") + s
+ wxS("]");
868 if ( i
< iMaxMinusOne
)
870 if ( text
.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT
&&
871 !(argFlags
& wxPG_EDITABLE_VALUE
) &&
872 !(argFlags
& wxPG_FULL_VALUE
) )
877 if ( !curChild
->GetChildCount() )
883 curChild
= m_children
[i
+1];
887 if ( (unsigned int)i
< m_children
.size() )
889 if ( !text
.EndsWith(wxS("; ")) )
890 text
+= wxS("; ...");
896 wxString
wxPGProperty::ValueToString( wxVariant
& WXUNUSED(value
),
899 wxCHECK_MSG( GetChildCount() > 0,
901 "If user property does not have any children, it must "
902 "override GetValueAsString" );
904 // FIXME: Currently code below only works if value is actually m_value
905 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
906 "Sorry, currently default wxPGProperty::ValueToString() "
907 "implementation only works if value is m_value." );
910 DoGenerateComposedValue(text
, argFlags
);
914 wxString
wxPGProperty::GetValueAsString( int argFlags
) const
916 #if wxPG_COMPATIBILITY_1_4
917 // This is backwards compatibility test
918 // That is, to make sure this function is not overridden
919 // (instead, ValueToString() should be).
920 if ( argFlags
== 0xFFFF )
922 // Do not override! (for backwards compliancy)
923 return g_invalidStringContent
;
927 if ( IsValueUnspecified() )
928 return wxEmptyString
;
930 if ( m_commonValue
== -1 )
932 wxVariant
value(GetValue());
933 return ValueToString(value
, argFlags
|wxPG_VALUE_IS_CURRENT
);
937 // Return common value's string representation
938 wxPropertyGrid
* pg
= GetGrid();
939 const wxPGCommonValue
* cv
= pg
->GetCommonValue(m_commonValue
);
941 if ( argFlags
& wxPG_FULL_VALUE
)
943 return cv
->GetLabel();
945 else if ( argFlags
& wxPG_EDITABLE_VALUE
)
947 return cv
->GetEditableText();
951 return cv
->GetLabel();
955 wxString
wxPGProperty::GetValueString( int argFlags
) const
957 return GetValueAsString(argFlags
);
960 bool wxPGProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
962 variant
= (long)number
;
966 // Convert semicolon delimited tokens into child values.
967 bool wxPGProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
969 if ( !GetChildCount() )
972 unsigned int curChild
= 0;
974 unsigned int iMax
= m_children
.size();
976 if ( iMax
> PWC_CHILD_SUMMARY_LIMIT
&&
977 !(argFlags
& wxPG_FULL_VALUE
) )
978 iMax
= PWC_CHILD_SUMMARY_LIMIT
;
980 bool changed
= false;
985 // Its best only to add non-empty group items
986 bool addOnlyIfNotEmpty
= false;
987 const wxChar delimeter
= wxS(';');
989 size_t tokenStart
= 0xFFFFFF;
991 wxVariantList temp_list
;
992 wxVariant
list(temp_list
);
994 int propagatedFlags
= argFlags
& (wxPG_REPORT_ERROR
|wxPG_PROGRAMMATIC_VALUE
);
996 wxLogTrace("propgrid",
997 wxT(">> %s.StringToValue('%s')"), GetLabel(), text
);
999 wxString::const_iterator it
= text
.begin();
1002 if ( it
!= text
.end() )
1009 // How many units we iterate string forward at the end of loop?
1010 // We need to keep track of this or risk going to negative
1011 // with it-- operation.
1012 unsigned int strPosIncrement
= 1;
1014 if ( tokenStart
!= 0xFFFFFF )
1017 if ( a
== delimeter
|| a
== 0 )
1019 token
= text
.substr(tokenStart
,pos
-tokenStart
);
1021 size_t len
= token
.length();
1023 if ( !addOnlyIfNotEmpty
|| len
> 0 )
1025 const wxPGProperty
* child
= Item(curChild
);
1026 wxVariant
variant(child
->GetValue());
1027 wxString childName
= child
->GetBaseName();
1029 wxLogTrace("propgrid",
1030 wxT("token = '%s', child = %s"),
1033 // Add only if editable or setting programmatically
1034 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1035 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1039 if ( child
->StringToValue(variant
, token
,
1040 propagatedFlags
|wxPG_COMPOSITE_FRAGMENT
) )
1042 // We really need to set the variant's name
1043 // *after* child->StringToValue() has been
1044 // called, since variant's value may be set by
1045 // assigning another variant into it, which
1046 // then usually causes name to be copied (ie.
1047 // usually cleared) as well. wxBoolProperty
1048 // being case in point with its use of
1049 // wxPGVariant_Bool macro as an optimization.
1050 variant
.SetName(childName
);
1051 list
.Append(variant
);
1058 // Empty, becomes unspecified
1060 variant
.SetName(childName
);
1061 list
.Append(variant
);
1067 if ( curChild
>= iMax
)
1071 tokenStart
= 0xFFFFFF;
1076 // Token is not running
1077 if ( a
!= wxS(' ') )
1080 addOnlyIfNotEmpty
= false;
1082 // Is this a group of tokens?
1083 if ( a
== wxS('[') )
1087 if ( it
!= text
.end() ) ++it
;
1089 size_t startPos
= pos
;
1091 // Group item - find end
1092 while ( it
!= text
.end() && depth
> 0 )
1098 if ( a
== wxS(']') )
1100 else if ( a
== wxS('[') )
1104 token
= text
.substr(startPos
,pos
-startPos
-1);
1106 if ( !token
.length() )
1109 const wxPGProperty
* child
= Item(curChild
);
1111 wxVariant oldChildValue
= child
->GetValue();
1112 wxVariant
variant(oldChildValue
);
1114 if ( (argFlags
& wxPG_PROGRAMMATIC_VALUE
) ||
1115 !child
->HasFlag(wxPG_PROP_DISABLED
|wxPG_PROP_READONLY
) )
1117 wxString childName
= child
->GetBaseName();
1119 bool stvRes
= child
->StringToValue( variant
, token
,
1121 if ( stvRes
|| (variant
!= oldChildValue
) )
1123 variant
.SetName(childName
);
1124 list
.Append(variant
);
1135 if ( curChild
>= iMax
)
1138 addOnlyIfNotEmpty
= true;
1140 tokenStart
= 0xFFFFFF;
1146 if ( a
== delimeter
)
1147 strPosIncrement
-= 1;
1155 it
+= strPosIncrement
;
1157 if ( it
!= text
.end() )
1166 pos
+= strPosIncrement
;
1175 bool wxPGProperty::SetValueFromString( const wxString
& text
, int argFlags
)
1177 wxVariant
variant(m_value
);
1178 bool res
= StringToValue(variant
, text
, argFlags
);
1184 bool wxPGProperty::SetValueFromInt( long number
, int argFlags
)
1186 wxVariant
variant(m_value
);
1187 bool res
= IntToValue(variant
, number
, argFlags
);
1193 wxSize
wxPGProperty::OnMeasureImage( int WXUNUSED(item
) ) const
1195 if ( m_valueBitmap
)
1196 return wxSize(m_valueBitmap
->GetWidth(),-1);
1201 int wxPGProperty::GetImageOffset( int imageWidth
) const
1203 int imageOffset
= 0;
1207 // Do not increment offset too much for wide images
1208 if ( imageWidth
<= (wxPG_CUSTOM_IMAGE_WIDTH
+5) )
1209 imageOffset
= imageWidth
+ DEFAULT_IMAGE_OFFSET_INCREMENT
;
1211 imageOffset
= imageWidth
+ 1;
1217 wxPGCellRenderer
* wxPGProperty::GetCellRenderer( int WXUNUSED(column
) ) const
1219 return wxPGGlobalVars
->m_defaultRenderer
;
1222 void wxPGProperty::OnCustomPaint( wxDC
& dc
,
1226 wxBitmap
* bmp
= m_valueBitmap
;
1228 wxCHECK_RET( bmp
&& bmp
->Ok(), wxT("invalid bitmap") );
1230 wxCHECK_RET( rect
.x
>= 0, wxT("unexpected measure call") );
1232 dc
.DrawBitmap(*bmp
,rect
.x
,rect
.y
);
1235 const wxPGEditor
* wxPGProperty::DoGetEditorClass() const
1237 return wxPGEditor_TextCtrl
;
1240 // Default extra property event handling - that is, none at all.
1241 bool wxPGProperty::OnEvent( wxPropertyGrid
*, wxWindow
*, wxEvent
& )
1247 void wxPGProperty::SetValue( wxVariant value
, wxVariant
* pList
, int flags
)
1249 // If auto unspecified values are not wanted (via window or property style),
1250 // then get default value instead of wxNullVariant.
1251 if ( value
.IsNull() && (flags
& wxPG_SETVAL_BY_USER
) &&
1252 !UsesAutoUnspecified() )
1254 value
= GetDefaultValue();
1257 if ( !value
.IsNull() )
1259 wxVariant tempListVariant
;
1262 // List variants are reserved a special purpose
1263 // as intermediate containers for child values
1264 // of properties with children.
1265 if ( value
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1268 // However, situation is different for composed string properties
1269 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
1271 tempListVariant
= value
;
1272 pList
= &tempListVariant
;
1276 AdaptListToValue(value
, &newValue
);
1278 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1281 if ( HasFlag( wxPG_PROP_AGGREGATE
) )
1282 flags
|= wxPG_SETVAL_AGGREGATED
;
1284 if ( pList
&& !pList
->IsNull() )
1286 wxASSERT( pList
->GetType() == wxPG_VARIANT_TYPE_LIST
);
1287 wxASSERT( GetChildCount() );
1288 wxASSERT( !IsCategory() );
1290 wxVariantList
& list
= pList
->GetList();
1291 wxVariantList::iterator node
;
1294 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1296 // Children in list can be in any order, but we will give hint to
1297 // GetPropertyByNameWH(). This optimizes for full list parsing.
1298 for ( node
= list
.begin(); node
!= list
.end(); ++node
)
1300 wxVariant
& childValue
= *((wxVariant
*)*node
);
1301 wxPGProperty
* child
= GetPropertyByNameWH(childValue
.GetName(), i
);
1304 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1305 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
1307 if ( child
->HasFlag(wxPG_PROP_AGGREGATE
) && !(flags
& wxPG_SETVAL_AGGREGATED
) )
1309 wxVariant listRefCopy
= childValue
;
1310 child
->SetValue(childValue
, &listRefCopy
, flags
|wxPG_SETVAL_FROM_PARENT
);
1314 wxVariant oldVal
= child
->GetValue();
1315 child
->SetValue(oldVal
, &childValue
, flags
|wxPG_SETVAL_FROM_PARENT
);
1318 else if ( child
->GetValue() != childValue
)
1320 // For aggregate properties, we will trust RefreshChildren()
1321 // to update child values.
1322 if ( !HasFlag(wxPG_PROP_AGGREGATE
) )
1323 child
->SetValue(childValue
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1324 if ( flags
& wxPG_SETVAL_BY_USER
)
1325 child
->SetFlag(wxPG_PROP_MODIFIED
);
1332 if ( !value
.IsNull() )
1338 if ( flags
& wxPG_SETVAL_BY_USER
)
1339 SetFlag(wxPG_PROP_MODIFIED
);
1341 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
1346 if ( m_commonValue
!= -1 )
1348 wxPropertyGrid
* pg
= GetGrid();
1349 if ( !pg
|| m_commonValue
!= pg
->GetUnspecifiedCommonValue() )
1355 // Set children to unspecified, but only if aggregate or
1356 // value is <composed>
1357 if ( AreChildrenComponents() )
1360 for ( i
=0; i
<GetChildCount(); i
++ )
1361 Item(i
)->SetValue(value
, NULL
, flags
|wxPG_SETVAL_FROM_PARENT
);
1365 if ( !(flags
& wxPG_SETVAL_FROM_PARENT
) )
1366 UpdateParentValues();
1369 // Update editor control.
1370 if ( flags
& wxPG_SETVAL_REFRESH_EDITOR
)
1372 wxPropertyGrid
* pg
= GetGridIfDisplayed();
1375 wxPGProperty
* selected
= pg
->GetSelectedProperty();
1377 // Only refresh the control if this was selected, or
1378 // this was some parent of selected, or vice versa)
1379 if ( selected
&& (selected
== this ||
1380 selected
->IsSomeParent(this) ||
1381 this->IsSomeParent(selected
)) )
1384 pg
->DrawItemAndValueRelated(this);
1390 void wxPGProperty::SetValueInEvent( wxVariant value
) const
1392 GetGrid()->ValueChangeInEvent(value
);
1395 void wxPGProperty::SetFlagRecursively( FlagType flag
, bool set
)
1397 ChangeFlag(flag
, set
);
1400 for ( i
= 0; i
< GetChildCount(); i
++ )
1401 Item(i
)->SetFlagRecursively(flag
, set
);
1404 void wxPGProperty::RefreshEditor()
1409 wxPropertyGrid
* pg
= GetGrid();
1410 if ( pg
&& pg
->GetSelectedProperty() == this )
1411 pg
->RefreshEditor();
1414 wxVariant
wxPGProperty::GetDefaultValue() const
1416 wxVariant defVal
= GetAttribute(wxPG_ATTR_DEFAULT_VALUE
);
1417 if ( !defVal
.IsNull() )
1420 wxVariant value
= GetValue();
1422 if ( !value
.IsNull() )
1424 wxString
valueType(value
.GetType());
1426 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1427 return wxPGVariant_Zero
;
1428 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1429 return wxPGVariant_EmptyString
;
1430 if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1431 return wxPGVariant_False
;
1432 if ( valueType
== wxPG_VARIANT_TYPE_DOUBLE
)
1433 return wxVariant(0.0);
1434 if ( valueType
== wxPG_VARIANT_TYPE_ARRSTRING
)
1435 return wxVariant(wxArrayString());
1436 if ( valueType
== wxS("wxLongLong") )
1437 return WXVARIANT(wxLongLong(0));
1438 if ( valueType
== wxS("wxULongLong") )
1439 return WXVARIANT(wxULongLong(0));
1440 if ( valueType
== wxS("wxColour") )
1441 return WXVARIANT(*wxBLACK
);
1443 if ( valueType
== wxPG_VARIANT_TYPE_DATETIME
)
1444 return wxVariant(wxDateTime::Now());
1446 if ( valueType
== wxS("wxFont") )
1447 return WXVARIANT(*wxNORMAL_FONT
);
1448 if ( valueType
== wxS("wxPoint") )
1449 return WXVARIANT(wxPoint(0, 0));
1450 if ( valueType
== wxS("wxSize") )
1451 return WXVARIANT(wxSize(0, 0));
1457 void wxPGProperty::EnsureCells( unsigned int column
)
1459 if ( column
>= m_cells
.size() )
1461 // Fill empty slots with default cells
1462 wxPropertyGrid
* pg
= GetGrid();
1463 wxPGCell defaultCell
;
1465 // Work around possible VC6 bug by using intermediate variables
1466 const wxPGCell
& propDefCell
= pg
->GetPropertyDefaultCell();
1467 const wxPGCell
& catDefCell
= pg
->GetCategoryDefaultCell();
1469 if ( !HasFlag(wxPG_PROP_CATEGORY
) )
1470 defaultCell
= propDefCell
;
1472 defaultCell
= catDefCell
;
1474 // TODO: Replace with resize() call
1475 unsigned int cellCountMax
= column
+1;
1477 for ( unsigned int i
=m_cells
.size(); i
<cellCountMax
; i
++ )
1478 m_cells
.push_back(defaultCell
);
1482 void wxPGProperty::SetCell( int column
,
1483 const wxPGCell
& cell
)
1485 EnsureCells(column
);
1487 m_cells
[column
] = cell
;
1490 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol
,
1491 unsigned int lastCol
,
1492 const wxPGCell
& cell
,
1493 const wxPGCell
& srcData
,
1494 wxPGCellData
* unmodCellData
,
1495 FlagType ignoreWithFlags
,
1499 // Sets cell in memory optimizing fashion. That is, if
1500 // current cell data matches unmodCellData, we will
1501 // simply get reference to data from cell. Otherwise,
1502 // cell information from srcData is merged into current.
1505 if ( !(m_flags
& ignoreWithFlags
) && !IsRoot() )
1507 EnsureCells(lastCol
);
1509 for ( unsigned int col
=firstCol
; col
<=lastCol
; col
++ )
1511 if ( m_cells
[col
].GetData() == unmodCellData
)
1513 // Data matches... use cell directly
1514 m_cells
[col
] = cell
;
1518 // Data did not match... merge valid information
1519 m_cells
[col
].MergeFrom(srcData
);
1526 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
1527 Item(i
)->AdaptiveSetCell( firstCol
,
1537 const wxPGCell
& wxPGProperty::GetCell( unsigned int column
) const
1539 if ( m_cells
.size() > column
)
1540 return m_cells
[column
];
1542 wxPropertyGrid
* pg
= GetGrid();
1545 return pg
->GetCategoryDefaultCell();
1547 return pg
->GetPropertyDefaultCell();
1550 wxPGCell
& wxPGProperty::GetOrCreateCell( unsigned int column
)
1552 EnsureCells(column
);
1553 return m_cells
[column
];
1556 void wxPGProperty::SetBackgroundColour( const wxColour
& colour
,
1559 wxPGProperty
* firstProp
= this;
1560 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1563 // If category is tried to set recursively, skip it and only
1564 // affect the children.
1567 while ( firstProp
->IsCategory() )
1569 if ( !firstProp
->GetChildCount() )
1571 firstProp
= firstProp
->Item(0);
1575 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1576 wxPGCellData
* firstCellData
= firstCell
.GetData();
1578 wxPGCell
newCell(firstCell
);
1579 newCell
.SetBgCol(colour
);
1581 srcCell
.SetBgCol(colour
);
1584 GetParentState()->GetColumnCount()-1,
1588 recursively
? wxPG_PROP_CATEGORY
: 0,
1592 void wxPGProperty::SetTextColour( const wxColour
& colour
,
1595 wxPGProperty
* firstProp
= this;
1596 bool recursively
= flags
& wxPG_RECURSE
? true : false;
1599 // If category is tried to set recursively, skip it and only
1600 // affect the children.
1603 while ( firstProp
->IsCategory() )
1605 if ( !firstProp
->GetChildCount() )
1607 firstProp
= firstProp
->Item(0);
1611 wxPGCell
& firstCell
= firstProp
->GetCell(0);
1612 wxPGCellData
* firstCellData
= firstCell
.GetData();
1614 wxPGCell
newCell(firstCell
);
1615 newCell
.SetFgCol(colour
);
1617 srcCell
.SetFgCol(colour
);
1620 GetParentState()->GetColumnCount()-1,
1624 recursively
? wxPG_PROP_CATEGORY
: 0,
1628 wxPGEditorDialogAdapter
* wxPGProperty::GetEditorDialog() const
1633 bool wxPGProperty::DoSetAttribute( const wxString
& WXUNUSED(name
), wxVariant
& WXUNUSED(value
) )
1638 void wxPGProperty::SetAttribute( const wxString
& name
, wxVariant value
)
1640 if ( DoSetAttribute( name
, value
) )
1642 // Support working without grid, when possible
1643 if ( wxPGGlobalVars
->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
) )
1647 m_attributes
.Set( name
, value
);
1650 void wxPGProperty::SetAttributes( const wxPGAttributeStorage
& attributes
)
1652 wxPGAttributeStorage::const_iterator it
= attributes
.StartIteration();
1655 while ( attributes
.GetNext(it
, variant
) )
1656 SetAttribute( variant
.GetName(), variant
);
1659 wxVariant
wxPGProperty::DoGetAttribute( const wxString
& WXUNUSED(name
) ) const
1665 wxVariant
wxPGProperty::GetAttribute( const wxString
& name
) const
1667 return m_attributes
.FindValue(name
);
1670 wxString
wxPGProperty::GetAttribute( const wxString
& name
, const wxString
& defVal
) const
1672 wxVariant variant
= m_attributes
.FindValue(name
);
1674 if ( !variant
.IsNull() )
1675 return variant
.GetString();
1680 long wxPGProperty::GetAttributeAsLong( const wxString
& name
, long defVal
) const
1682 wxVariant variant
= m_attributes
.FindValue(name
);
1684 if ( variant
.IsNull() )
1687 return variant
.GetLong();
1690 double wxPGProperty::GetAttributeAsDouble( const wxString
& name
, double defVal
) const
1692 wxVariant variant
= m_attributes
.FindValue(name
);
1694 if ( variant
.IsNull() )
1697 return variant
.GetDouble();
1700 wxVariant
wxPGProperty::GetAttributesAsList() const
1702 wxVariantList tempList
;
1703 wxVariant
v( tempList
, wxString::Format(wxS("@%s@attr"),m_name
.c_str()) );
1705 wxPGAttributeStorage::const_iterator it
= m_attributes
.StartIteration();
1708 while ( m_attributes
.GetNext(it
, variant
) )
1714 // Slots of utility flags are NULL
1715 const unsigned int gs_propFlagToStringSize
= 14;
1717 static const wxChar
* const gs_propFlagToString
[gs_propFlagToStringSize
] = {
1734 wxString
wxPGProperty::GetFlagsAsString( FlagType flagsMask
) const
1737 int relevantFlags
= m_flags
& flagsMask
& wxPG_STRING_STORED_FLAGS
;
1741 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1743 if ( relevantFlags
& a
)
1745 const wxChar
* fs
= gs_propFlagToString
[i
];
1757 void wxPGProperty::SetFlagsFromString( const wxString
& str
)
1761 WX_PG_TOKENIZER1_BEGIN(str
, wxS('|'))
1763 for ( i
=0; i
<gs_propFlagToStringSize
; i
++ )
1765 const wxChar
* fs
= gs_propFlagToString
[i
];
1766 if ( fs
&& str
== fs
)
1772 WX_PG_TOKENIZER1_END()
1774 m_flags
= (m_flags
& ~wxPG_STRING_STORED_FLAGS
) | flags
;
1777 wxValidator
* wxPGProperty::DoGetValidator() const
1782 int wxPGProperty::InsertChoice( const wxString
& label
, int index
, int value
)
1784 wxPropertyGrid
* pg
= GetGrid();
1785 int sel
= GetChoiceSelection();
1789 if ( index
== wxNOT_FOUND
)
1790 index
= m_choices
.GetCount();
1795 m_choices
.Insert(label
, index
, value
);
1797 if ( sel
!= newSel
)
1798 SetChoiceSelection(newSel
);
1800 if ( this == pg
->GetSelection() )
1801 GetEditorClass()->InsertItem(pg
->GetEditorControl(),label
,index
);
1807 void wxPGProperty::DeleteChoice( int index
)
1809 wxPropertyGrid
* pg
= GetGrid();
1811 int sel
= GetChoiceSelection();
1814 // Adjust current value
1817 SetValueToUnspecified();
1820 else if ( index
< sel
)
1825 m_choices
.RemoveAt(index
);
1827 if ( sel
!= newSel
)
1828 SetChoiceSelection(newSel
);
1830 if ( this == pg
->GetSelection() )
1831 GetEditorClass()->DeleteItem(pg
->GetEditorControl(), index
);
1834 int wxPGProperty::GetChoiceSelection() const
1836 wxVariant value
= GetValue();
1837 wxString valueType
= value
.GetType();
1838 int index
= wxNOT_FOUND
;
1840 if ( IsValueUnspecified() || !m_choices
.GetCount() )
1843 if ( valueType
== wxPG_VARIANT_TYPE_LONG
)
1845 index
= value
.GetLong();
1847 else if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1849 index
= m_choices
.Index(value
.GetString());
1851 else if ( valueType
== wxPG_VARIANT_TYPE_BOOL
)
1853 index
= value
.GetBool()? 1 : 0;
1859 void wxPGProperty::SetChoiceSelection( int newValue
)
1861 // Changes value of a property with choices, but only
1862 // works if the value type is long or string.
1863 wxString valueType
= GetValue().GetType();
1865 wxCHECK_RET( m_choices
.IsOk(), wxT("invalid choiceinfo") );
1867 if ( valueType
== wxPG_VARIANT_TYPE_STRING
)
1869 SetValue( m_choices
.GetLabel(newValue
) );
1871 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1873 SetValue( (long) newValue
);
1877 bool wxPGProperty::SetChoices( wxPGChoices
& choices
)
1879 m_choices
.Assign(choices
);
1882 // This may be needed to trigger some initialization
1883 // (but don't do it if property is somewhat uninitialized)
1884 wxVariant defVal
= GetDefaultValue();
1885 if ( defVal
.IsNull() )
1895 const wxPGEditor
* wxPGProperty::GetEditorClass() const
1897 const wxPGEditor
* editor
;
1899 if ( !m_customEditor
)
1901 editor
= DoGetEditorClass();
1904 editor
= m_customEditor
;
1907 // Maybe override editor if common value specified
1908 if ( GetDisplayedCommonValueCount() )
1910 // TextCtrlAndButton -> ComboBoxAndButton
1911 if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor
)) )
1912 editor
= wxPGEditor_ChoiceAndButton
;
1914 // TextCtrl -> ComboBox
1915 else if ( editor
->IsKindOf(CLASSINFO(wxPGTextCtrlEditor
)) )
1916 editor
= wxPGEditor_ComboBox
;
1922 bool wxPGProperty::HasVisibleChildren() const
1926 for ( i
=0; i
<GetChildCount(); i
++ )
1928 wxPGProperty
* child
= Item(i
);
1930 if ( !child
->HasFlag(wxPG_PROP_HIDDEN
) )
1937 bool wxPGProperty::RecreateEditor()
1939 wxPropertyGrid
* pg
= GetGrid();
1942 wxPGProperty
* selected
= pg
->GetSelection();
1943 if ( this == selected
)
1945 pg
->DoSelectProperty(this, wxPG_SEL_FORCE
);
1952 void wxPGProperty::SetValueImage( wxBitmap
& bmp
)
1954 delete m_valueBitmap
;
1956 if ( &bmp
&& bmp
.Ok() )
1959 wxSize maxSz
= GetGrid()->GetImageSize();
1960 wxSize
imSz(bmp
.GetWidth(),bmp
.GetHeight());
1962 if ( imSz
.y
!= maxSz
.y
)
1964 // Create a memory DC
1965 wxBitmap
* bmpNew
= new wxBitmap(maxSz
.x
,maxSz
.y
,bmp
.GetDepth());
1968 dc
.SelectObject(*bmpNew
);
1971 // FIXME: This is ugly - use image or wait for scaling patch.
1972 double scaleY
= (double)maxSz
.y
/ (double)imSz
.y
;
1974 dc
.SetUserScale(scaleY
, scaleY
);
1976 dc
.DrawBitmap(bmp
, 0, 0);
1978 m_valueBitmap
= bmpNew
;
1982 m_valueBitmap
= new wxBitmap(bmp
);
1985 m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
1989 m_valueBitmap
= NULL
;
1990 m_flags
&= ~(wxPG_PROP_CUSTOMIMAGE
);
1995 wxPGProperty
* wxPGProperty::GetMainParent() const
1997 const wxPGProperty
* curChild
= this;
1998 const wxPGProperty
* curParent
= m_parent
;
2000 while ( curParent
&& !curParent
->IsCategory() )
2002 curChild
= curParent
;
2003 curParent
= curParent
->m_parent
;
2006 return (wxPGProperty
*) curChild
;
2010 const wxPGProperty
* wxPGProperty::GetLastVisibleSubItem() const
2013 // Returns last visible sub-item, recursively.
2014 if ( !IsExpanded() || !GetChildCount() )
2017 return Last()->GetLastVisibleSubItem();
2021 bool wxPGProperty::IsVisible() const
2023 const wxPGProperty
* parent
;
2025 if ( HasFlag(wxPG_PROP_HIDDEN
) )
2028 for ( parent
= GetParent(); parent
!= NULL
; parent
= parent
->GetParent() )
2030 if ( !parent
->IsExpanded() || parent
->HasFlag(wxPG_PROP_HIDDEN
) )
2037 wxPropertyGrid
* wxPGProperty::GetGridIfDisplayed() const
2039 wxPropertyGridPageState
* state
= GetParentState();
2042 wxPropertyGrid
* propGrid
= state
->GetGrid();
2043 if ( state
== propGrid
->GetState() )
2049 int wxPGProperty::GetY2( int lh
) const
2051 const wxPGProperty
* parent
;
2052 const wxPGProperty
* child
= this;
2056 for ( parent
= GetParent(); parent
!= NULL
; parent
= child
->GetParent() )
2058 if ( !parent
->IsExpanded() )
2060 y
+= parent
->GetChildrenHeight(lh
, child
->GetIndexInParent());
2065 y
-= lh
; // need to reduce one level
2071 int wxPGProperty::GetY() const
2073 return GetY2(GetGrid()->GetRowHeight());
2076 // This is used by Insert etc.
2077 void wxPGProperty::DoAddChild( wxPGProperty
* prop
, int index
,
2080 if ( index
< 0 || (size_t)index
>= m_children
.size() )
2082 if ( correct_mode
) prop
->m_arrIndex
= m_children
.size();
2083 m_children
.push_back( prop
);
2087 m_children
.insert( m_children
.begin()+index
, prop
);
2088 if ( correct_mode
) FixIndicesOfChildren( index
);
2091 prop
->m_parent
= this;
2094 void wxPGProperty::DoPreAddChild( int index
, wxPGProperty
* prop
)
2096 wxASSERT_MSG( prop
->GetBaseName().length(),
2097 "Property's children must have unique, non-empty "
2098 "names within their scope" );
2100 prop
->m_arrIndex
= index
;
2101 m_children
.insert( m_children
.begin()+index
,
2104 int custImgHeight
= prop
->OnMeasureImage().y
;
2105 if ( custImgHeight
< 0 /*|| custImgHeight > 1*/ )
2106 prop
->m_flags
|= wxPG_PROP_CUSTOMIMAGE
;
2108 prop
->m_parent
= this;
2111 void wxPGProperty::AddPrivateChild( wxPGProperty
* prop
)
2113 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2114 SetParentalType(wxPG_PROP_AGGREGATE
);
2116 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2117 wxPG_PROP_AGGREGATE
,
2118 "Do not mix up AddPrivateChild() calls with other "
2119 "property adders." );
2121 DoPreAddChild( m_children
.size(), prop
);
2124 #if wxPG_COMPATIBILITY_1_4
2125 void wxPGProperty::AddChild( wxPGProperty
* prop
)
2127 AddPrivateChild(prop
);
2131 wxPGProperty
* wxPGProperty::InsertChild( int index
,
2132 wxPGProperty
* childProperty
)
2135 index
= m_children
.size();
2137 if ( m_parentState
)
2139 m_parentState
->DoInsert(this, index
, childProperty
);
2143 if ( !(m_flags
& wxPG_PROP_PARENTAL_FLAGS
) )
2144 SetParentalType(wxPG_PROP_MISC_PARENT
);
2146 wxASSERT_MSG( (m_flags
& wxPG_PROP_PARENTAL_FLAGS
) ==
2147 wxPG_PROP_MISC_PARENT
,
2148 "Do not mix up AddPrivateChild() calls with other "
2149 "property adders." );
2151 DoPreAddChild( index
, childProperty
);
2154 return childProperty
;
2157 void wxPGProperty::RemoveChild( wxPGProperty
* p
)
2159 wxArrayPGProperty::iterator it
;
2160 wxArrayPGProperty
& children
= m_children
;
2162 for ( it
=children
.begin(); it
!= children
.end(); it
++ )
2172 void wxPGProperty::AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const
2174 wxASSERT( GetChildCount() );
2175 wxASSERT( !IsCategory() );
2177 *value
= GetValue();
2179 if ( !list
.GetCount() )
2182 wxASSERT( GetChildCount() >= (unsigned int)list
.GetCount() );
2184 bool allChildrenSpecified
;
2186 // Don't fully update aggregate properties unless all children have
2188 if ( HasFlag(wxPG_PROP_AGGREGATE
) )
2189 allChildrenSpecified
= AreAllChildrenSpecified(&list
);
2191 allChildrenSpecified
= true;
2193 wxVariant childValue
= list
[0];
2197 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2199 for ( i
=0; i
<GetChildCount(); i
++ )
2201 const wxPGProperty
* child
= Item(i
);
2203 if ( childValue
.GetName() == child
->GetBaseName() )
2205 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2207 if ( childValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2209 wxVariant
cv2(child
->GetValue());
2210 child
->AdaptListToValue(childValue
, &cv2
);
2214 if ( allChildrenSpecified
)
2216 *value
= ChildChanged(*value
, i
, childValue
);
2220 if ( n
== (unsigned int)list
.GetCount() )
2222 childValue
= list
[n
];
2228 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere
)
2231 for ( i
=starthere
;i
<GetChildCount();i
++)
2232 Item(i
)->m_arrIndex
= i
;
2236 // Returns (direct) child property with given name (or NULL if not found)
2237 wxPGProperty
* wxPGProperty::GetPropertyByName( const wxString
& name
) const
2241 for ( i
=0; i
<GetChildCount(); i
++ )
2243 wxPGProperty
* p
= Item(i
);
2244 if ( p
->m_name
== name
)
2248 // Does it have point, then?
2249 int pos
= name
.Find(wxS('.'));
2253 wxPGProperty
* p
= GetPropertyByName(name
. substr(0,pos
));
2255 if ( !p
|| !p
->GetChildCount() )
2258 return p
->GetPropertyByName(name
.substr(pos
+1,name
.length()-pos
-1));
2261 wxPGProperty
* wxPGProperty::GetPropertyByNameWH( const wxString
& name
, unsigned int hintIndex
) const
2263 unsigned int i
= hintIndex
;
2265 if ( i
>= GetChildCount() )
2268 unsigned int lastIndex
= i
- 1;
2270 if ( lastIndex
>= GetChildCount() )
2271 lastIndex
= GetChildCount() - 1;
2275 wxPGProperty
* p
= Item(i
);
2276 if ( p
->m_name
== name
)
2279 if ( i
== lastIndex
)
2283 if ( i
== GetChildCount() )
2290 int wxPGProperty::GetChildrenHeight( int lh
, int iMax_
) const
2292 // Returns height of children, recursively, and
2293 // by taking expanded/collapsed status into account.
2295 // iMax is used when finding property y-positions.
2301 iMax_
= GetChildCount();
2303 unsigned int iMax
= iMax_
;
2305 wxASSERT( iMax
<= GetChildCount() );
2307 if ( !IsExpanded() && GetParent() )
2312 wxPGProperty
* pwc
= (wxPGProperty
*) Item(i
);
2314 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2316 if ( !pwc
->IsExpanded() ||
2317 pwc
->GetChildCount() == 0 )
2320 h
+= pwc
->GetChildrenHeight(lh
) + lh
;
2329 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
,
2331 unsigned int* nextItemY
) const
2333 wxASSERT( nextItemY
);
2335 // Linear search at the moment
2337 // nextItemY = y of next visible property, final value will be written back.
2338 wxPGProperty
* result
= NULL
;
2339 wxPGProperty
* current
= NULL
;
2340 unsigned int iy
= *nextItemY
;
2342 unsigned int iMax
= GetChildCount();
2346 wxPGProperty
* pwc
= Item(i
);
2348 if ( !pwc
->HasFlag(wxPG_PROP_HIDDEN
) )
2359 if ( pwc
->IsExpanded() &&
2360 pwc
->GetChildCount() > 0 )
2362 result
= (wxPGProperty
*) pwc
->GetItemAtY( y
, lh
, &iy
);
2374 if ( !result
&& y
< iy
)
2382 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2386 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2390 return (wxPGProperty
*) result
;
2393 void wxPGProperty::Empty()
2396 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES
) )
2398 for ( i
=0; i
<GetChildCount(); i
++ )
2400 delete m_children
[i
];
2407 wxPGProperty
* wxPGProperty::GetItemAtY( unsigned int y
) const
2409 unsigned int nextItem
;
2410 return GetItemAtY( y
, GetGrid()->GetRowHeight(), &nextItem
);
2413 void wxPGProperty::DeleteChildren()
2415 wxPropertyGridPageState
* state
= m_parentState
;
2417 while ( GetChildCount() )
2419 wxPGProperty
* child
= Item(GetChildCount()-1);
2420 state
->DoDelete(child
, true);
2424 wxVariant
wxPGProperty::ChildChanged( wxVariant
& WXUNUSED(thisValue
),
2425 int WXUNUSED(childIndex
),
2426 wxVariant
& WXUNUSED(childValue
) ) const
2428 return wxNullVariant
;
2431 bool wxPGProperty::AreAllChildrenSpecified( wxVariant
* pendingList
) const
2435 const wxVariantList
* pList
= NULL
;
2436 wxVariantList::const_iterator node
;
2440 pList
= &pendingList
->GetList();
2441 node
= pList
->begin();
2444 for ( i
=0; i
<GetChildCount(); i
++ )
2446 wxPGProperty
* child
= Item(i
);
2447 const wxVariant
* listValue
= NULL
;
2452 const wxString
& childName
= child
->GetBaseName();
2454 for ( ; node
!= pList
->end(); ++node
)
2456 const wxVariant
& item
= *((const wxVariant
*)*node
);
2457 if ( item
.GetName() == childName
)
2467 value
= child
->GetValue();
2469 if ( value
.IsNull() )
2472 // Check recursively
2473 if ( child
->GetChildCount() )
2475 const wxVariant
* childList
= NULL
;
2477 if ( listValue
&& listValue
->GetType() == wxPG_VARIANT_TYPE_LIST
)
2478 childList
= listValue
;
2480 if ( !child
->AreAllChildrenSpecified((wxVariant
*)childList
) )
2488 wxPGProperty
* wxPGProperty::UpdateParentValues()
2490 wxPGProperty
* parent
= m_parent
;
2491 if ( parent
&& parent
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) &&
2492 !parent
->IsCategory() && !parent
->IsRoot() )
2495 parent
->DoGenerateComposedValue(s
);
2496 parent
->m_value
= s
;
2497 return parent
->UpdateParentValues();
2502 bool wxPGProperty::IsTextEditable() const
2504 if ( HasFlag(wxPG_PROP_READONLY
) )
2507 if ( HasFlag(wxPG_PROP_NOEDITOR
) &&
2509 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2516 // Call after fixed sub-properties added/removed after creation.
2517 // if oldSelInd >= 0 and < new max items, then selection is
2518 // moved to it. Note: oldSelInd -2 indicates that this property
2519 // should be selected.
2520 void wxPGProperty::SubPropsChanged( int oldSelInd
)
2522 wxPropertyGridPageState
* state
= GetParentState();
2523 wxPropertyGrid
* grid
= state
->GetGrid();
2526 // Re-repare children (recursively)
2527 for ( unsigned int i
=0; i
<GetChildCount(); i
++ )
2529 wxPGProperty
* child
= Item(i
);
2530 child
->InitAfterAdded(state
, grid
);
2533 wxPGProperty
* sel
= NULL
;
2534 if ( oldSelInd
>= (int)m_children
.size() )
2535 oldSelInd
= (int)m_children
.size() - 1;
2537 if ( oldSelInd
>= 0 )
2538 sel
= m_children
[oldSelInd
];
2539 else if ( oldSelInd
== -2 )
2543 state
->DoSelectProperty(sel
);
2545 if ( state
== grid
->GetState() )
2547 grid
->GetPanel()->Refresh();
2551 // -----------------------------------------------------------------------
2553 // -----------------------------------------------------------------------
2555 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty
,none
,TextCtrl
)
2556 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty
, wxPGProperty
)
2559 wxPGRootProperty::wxPGRootProperty( const wxString
& name
)
2569 wxPGRootProperty::~wxPGRootProperty()
2574 // -----------------------------------------------------------------------
2575 // wxPropertyCategory
2576 // -----------------------------------------------------------------------
2578 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory
,none
,TextCtrl
)
2579 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory
, wxPGProperty
)
2581 void wxPropertyCategory::Init()
2583 // don't set colour - prepareadditem method should do this
2584 SetParentalType(wxPG_PROP_CATEGORY
);
2585 m_capFgColIndex
= 1;
2589 wxPropertyCategory::wxPropertyCategory()
2596 wxPropertyCategory::wxPropertyCategory( const wxString
&label
, const wxString
& name
)
2597 : wxPGProperty(label
,name
)
2603 wxPropertyCategory::~wxPropertyCategory()
2608 wxString
wxPropertyCategory::ValueToString( wxVariant
& WXUNUSED(value
),
2609 int WXUNUSED(argFlags
) ) const
2611 return wxEmptyString
;
2614 int wxPropertyCategory::GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const
2616 if ( m_textExtent
> 0 )
2617 return m_textExtent
;
2619 ((wxWindow
*)wnd
)->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2623 void wxPropertyCategory::CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
)
2626 wnd
->GetTextExtent( m_label
, &x
, &y
, 0, 0, &font
);
2630 // -----------------------------------------------------------------------
2632 // -----------------------------------------------------------------------
2634 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
2638 wxPGChoiceEntry
entry(label
, value
);
2639 return m_data
->Insert( -1, entry
);
2642 // -----------------------------------------------------------------------
2644 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
2648 wxPGChoiceEntry
entry(label
, value
);
2649 entry
.SetBitmap(bitmap
);
2650 return m_data
->Insert( -1, entry
);
2653 // -----------------------------------------------------------------------
2655 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
2659 return m_data
->Insert( index
, entry
);
2662 // -----------------------------------------------------------------------
2664 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
2668 wxPGChoiceEntry
entry(label
, value
);
2669 return m_data
->Insert( index
, entry
);
2672 // -----------------------------------------------------------------------
2674 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
2680 while ( index
< GetCount() )
2682 int cmpRes
= GetLabel(index
).Cmp(label
);
2688 wxPGChoiceEntry
entry(label
, value
);
2689 return m_data
->Insert( index
, entry
);
2692 // -----------------------------------------------------------------------
2694 void wxPGChoices::Add( const wxChar
* const* labels
, const ValArrItem
* values
)
2698 unsigned int itemcount
= 0;
2699 const wxChar
* const* p
= &labels
[0];
2700 while ( *p
) { p
++; itemcount
++; }
2703 for ( i
= 0; i
< itemcount
; i
++ )
2708 wxPGChoiceEntry
entry(labels
[i
], value
);
2709 m_data
->Insert( i
, entry
);
2713 // -----------------------------------------------------------------------
2715 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
2720 unsigned int itemcount
= arr
.size();
2722 for ( i
= 0; i
< itemcount
; i
++ )
2725 if ( &arrint
&& arrint
.size() )
2727 wxPGChoiceEntry
entry(arr
[i
], value
);
2728 m_data
->Insert( i
, entry
);
2732 // -----------------------------------------------------------------------
2734 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
2738 wxASSERT( m_data
->GetRefCount() != -1 );
2739 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
2740 m_data
->m_items
.begin()+nIndex
+count
);
2743 // -----------------------------------------------------------------------
2745 void wxPGChoices::Clear()
2747 if ( m_data
!= wxPGChoicesEmptyData
)
2754 // -----------------------------------------------------------------------
2756 int wxPGChoices::Index( const wxString
& str
) const
2761 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2763 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2764 if ( entry
.HasText() && entry
.GetText() == str
)
2771 // -----------------------------------------------------------------------
2773 int wxPGChoices::Index( int val
) const
2778 for ( i
=0; i
< m_data
->GetCount(); i
++ )
2780 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
2781 if ( entry
.GetValue() == val
)
2788 // -----------------------------------------------------------------------
2790 wxArrayString
wxPGChoices::GetLabels() const
2795 if ( this && IsOk() )
2796 for ( i
=0; i
<GetCount(); i
++ )
2797 arr
.push_back(GetLabel(i
));
2802 // -----------------------------------------------------------------------
2804 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
2811 for ( i
=0; i
< strings
.size(); i
++ )
2813 int index
= Index(strings
[i
]);
2815 arr
.Add(GetValue(index
));
2817 arr
.Add(wxPG_INVALID_VALUE
);
2824 // -----------------------------------------------------------------------
2826 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
2827 wxArrayString
* unmatched
) const
2834 for ( i
=0; i
< strings
.size(); i
++ )
2836 const wxString
& str
= strings
[i
];
2837 int index
= Index(str
);
2840 else if ( unmatched
)
2841 unmatched
->Add(str
);
2848 // -----------------------------------------------------------------------
2850 void wxPGChoices::AllocExclusive()
2854 if ( m_data
->GetRefCount() != 1 )
2856 wxPGChoicesData
* data
= new wxPGChoicesData();
2857 data
->CopyDataFrom(m_data
);
2863 // -----------------------------------------------------------------------
2865 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
2869 if ( data
!= wxPGChoicesEmptyData
)
2876 // -----------------------------------------------------------------------
2878 void wxPGChoices::Init()
2880 m_data
= wxPGChoicesEmptyData
;
2883 // -----------------------------------------------------------------------
2885 void wxPGChoices::Free()
2887 if ( m_data
!= wxPGChoicesEmptyData
)
2890 m_data
= wxPGChoicesEmptyData
;
2894 // -----------------------------------------------------------------------
2895 // wxPGAttributeStorage
2896 // -----------------------------------------------------------------------
2898 wxPGAttributeStorage::wxPGAttributeStorage()
2902 wxPGAttributeStorage::~wxPGAttributeStorage()
2904 wxPGHashMapS2P::iterator it
;
2906 for ( it
= m_map
.begin(); it
!= m_map
.end(); ++it
)
2908 wxVariantData
* data
= (wxVariantData
*) it
->second
;
2913 void wxPGAttributeStorage::Set( const wxString
& name
, const wxVariant
& value
)
2915 wxVariantData
* data
= value
.GetData();
2918 wxPGHashMapS2P::iterator it
= m_map
.find(name
);
2919 if ( it
!= m_map
.end() )
2921 ((wxVariantData
*)it
->second
)->DecRef();
2925 // If Null variant, just remove from set
2939 #endif // wxUSE_PROPGRID