X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40924780ea265ba9430b59348c563d78b8c40a71..f1a736636c32fa9cda80447c9f17287484ea8094:/include/wx/propgrid/property.h diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 682732813c..d8dcf5363f 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -4,7 +4,7 @@ // Author: Jaakko Salli // Modified by: // Created: 2008-08-23 -// RCS-ID: $Id: +// RCS-ID: $Id$ // Copyright: (c) Jaakko Salli // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -75,8 +75,27 @@ public: // Render flags enum { + // We are painting selected item Selected = 0x00010000, - Control = 0x00020000 + + // We are painting item in choice popup + ChoicePopup = 0x00020000, + + // We are rendering wxOwnerDrawnComboBox control + // (or other owner drawn control, but that is only + // officially supported one ATM). + Control = 0x00040000, + + // We are painting a disable property + Disabled = 0x00080000, + + // We are painting selected, disabled, or similar + // item that dictates fore- and background colours, + // overriding any cell values. + DontUseCellFgCol = 0x00100000, + DontUseCellBgCol = 0x00200000, + DontUseCellColours = DontUseCellFgCol | + DontUseCellBgCol }; virtual void Render( wxDC& dc, @@ -145,14 +164,46 @@ private: }; +class WXDLLIMPEXP_PROPGRID wxPGCellData : public wxObjectRefData +{ + friend class wxPGCell; +public: + wxPGCellData(); + + void SetText( const wxString& text ) + { + m_text = text; + m_hasValidText = true; + } + void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; } + void SetFgCol( const wxColour& col ) { m_fgCol = col; } + void SetBgCol( const wxColour& col ) { m_bgCol = col; } + +protected: + virtual ~wxPGCellData() { } + + wxString m_text; + wxBitmap m_bitmap; + wxColour m_fgCol; + wxColour m_bgCol; + + // True if m_text is valid and specified + bool m_hasValidText; +}; + /** @class wxPGCell Base class for simple wxPropertyGrid cell information. */ -class WXDLLIMPEXP_PROPGRID wxPGCell +class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject { public: wxPGCell(); + wxPGCell(const wxPGCell& other) + : wxObject(other) + { + } + wxPGCell( const wxString& text, const wxBitmap& bitmap = wxNullBitmap, const wxColour& fgCol = wxNullColour, @@ -160,21 +211,50 @@ public: virtual ~wxPGCell() { } - void SetText( const wxString& text ) { m_text = text; } - void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; } - void SetFgCol( const wxColour& col ) { m_fgCol = col; } - void SetBgCol( const wxColour& col ) { m_bgCol = col; } + wxPGCellData* GetData() + { + return (wxPGCellData*) m_refData; + } - const wxString& GetText() const { return m_text; } - const wxBitmap& GetBitmap() const { return m_bitmap; } - const wxColour& GetFgCol() const { return m_fgCol; } - const wxColour& GetBgCol() const { return m_bgCol; } + const wxPGCellData* GetData() const + { + return (const wxPGCellData*) m_refData; + } + + bool HasText() const + { + return (m_refData && GetData()->m_hasValidText); + } + + /** + Merges valid data from srcCell into this. + */ + void MergeFrom( const wxPGCell& srcCell ); + + void SetText( const wxString& text ); + void SetBitmap( const wxBitmap& bitmap ); + void SetFgCol( const wxColour& col ); + void SetBgCol( const wxColour& col ); + + const wxString& GetText() const { return GetData()->m_text; } + const wxBitmap& GetBitmap() const { return GetData()->m_bitmap; } + const wxColour& GetFgCol() const { return GetData()->m_fgCol; } + const wxColour& GetBgCol() const { return GetData()->m_bgCol; } + + wxPGCell& operator=( const wxPGCell& other ) + { + if ( this != &other ) + { + Ref(other); + } + return *this; + } protected: - wxString m_text; - wxBitmap m_bitmap; - wxColour m_fgCol; - wxColour m_bgCol; + virtual wxObjectRefData *CreateRefData() const + { return new wxPGCellData(); } + + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; }; @@ -215,7 +295,7 @@ public: ~wxPGAttributeStorage(); void Set( const wxString& name, const wxVariant& value ); - size_t GetCount() const { return m_map.size(); } + unsigned int GetCount() const { return (unsigned int) m_map.size(); } wxVariant FindValue( const wxString& name ) const { wxPGHashMapS2P::const_iterator it = m_map.find(name); @@ -242,7 +322,7 @@ public: data->IncRef(); variant.SetData(data); variant.SetName(it->first); - it++; + ++it; return true; } @@ -389,9 +469,6 @@ wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000 /** @} */ -// Amalgam of flags that should be inherited by sub-properties -#define wxPG_INHERITED_PROPFLAGS (wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR) - // Combination of flags that can be stored by GetFlagsAsString #define wxPG_STRING_STORED_FLAGS \ (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED) @@ -438,13 +515,28 @@ wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000 */ #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp") -/** wxBoolProperty specific, int, default 0. When 1 sets bool property to - use checkbox instead of choice. +/** Universal, wxArrayString. Set to enable auto-completion in any + wxTextCtrl-based property editor. +*/ +#define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete") + +/** wxBoolProperty and wxFlagsProperty specific. Value type is bool. + Default value is False. + + When set to True, bool property will use check box instead of a + combo box as its editor control. If you set this attribute + for a wxFlagsProperty, it is automatically applied to child + bool properties. */ #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox") -/** wxBoolProperty specific, int, default 0. When 1 sets bool property value - to cycle on double click (instead of showing the popup listbox). +/** wxBoolProperty and wxFlagsProperty specific. Value type is bool. + Default value is False. + + Set to True for the bool property to cycle value on double click + (instead of showing the popup listbox). If you set this attribute + for a wxFlagsProperty, it is automatically applied to child + bool properties. */ #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling") @@ -569,32 +661,32 @@ class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell { public: wxPGChoiceEntry(); - wxPGChoiceEntry( const wxPGChoiceEntry& entry ); - wxPGChoiceEntry( const wxString& label, - int value = wxPG_INVALID_VALUE ) - : wxPGCell(), m_value(value) + wxPGChoiceEntry(const wxPGChoiceEntry& other) + : wxPGCell(other) { - m_text = label; + m_value = other.m_value; } - wxPGChoiceEntry( const wxString& label, - int value, - const wxBitmap& bitmap, - const wxColour& fgCol = wxNullColour, - const wxColour& bgCol = wxNullColour ) - : wxPGCell(label, bitmap, fgCol, bgCol), m_value(value) + int value = wxPG_INVALID_VALUE ) + : wxPGCell(), m_value(value) { + SetText(label); } - virtual ~wxPGChoiceEntry() - { - } + virtual ~wxPGChoiceEntry() { } void SetValue( int value ) { m_value = value; } - int GetValue() const { return m_value; } - bool HasValue() const { return (m_value != wxPG_INVALID_VALUE); } + wxPGChoiceEntry& operator=( const wxPGChoiceEntry& other ) + { + if ( this != &other ) + { + Ref(other); + } + m_value = other.m_value; + return *this; + } protected: int m_value; @@ -612,37 +704,26 @@ public: void CopyDataFrom( wxPGChoicesData* data ); - // Takes ownership of 'item' - void Insert( int index, wxPGChoiceEntry* item ) - { - wxArrayPtrVoid::iterator it; - if ( index == -1 ) - { - it = m_items.end(); - index = m_items.size(); - } - else - { - it = m_items.begin() + index; - } - - // Need to fix value? - if ( item->GetValue() == wxPG_INVALID_VALUE ) - item->SetValue(index); - - m_items.insert(it, item); - } + wxPGChoiceEntry& Insert( int index, const wxPGChoiceEntry& item ); // Delete all entries void Clear(); - size_t GetCount() const { return m_items.size(); } + unsigned int GetCount() const + { + return (unsigned int) m_items.size(); + } - wxPGChoiceEntry* Item( unsigned int i ) const + const wxPGChoiceEntry& Item( unsigned int i ) const { - wxCHECK_MSG( i < GetCount(), NULL, "invalid index" ); + wxASSERT_MSG( i < GetCount(), "invalid index" ); + return m_items[i]; + } - return (wxPGChoiceEntry*) m_items[i]; + wxPGChoiceEntry& Item( unsigned int i ) + { + wxASSERT_MSG( i < GetCount(), "invalid index" ); + return m_items[i]; } void DecRef() @@ -654,7 +735,7 @@ public: } private: - wxArrayPtrVoid m_items; + wxVector m_items; // So that multiple properties can use the same set int m_refCount; @@ -671,6 +752,13 @@ private: Helper class for managing choices of wxPropertyGrid properties. Each entry can have label, value, bitmap, text colour, and background colour. + + wxPGChoices uses reference counting, similar to other wxWidgets classes. + This means that assignment operator and copy constructor only copy the + reference and not the actual data. Use Copy() member function to create a + real copy. + + @remarks If you do not specify value for entry, index is used. @library{wxpropgrid} @category{propgrid} @@ -686,7 +774,10 @@ public: Init(); } - /** Copy constructor. */ + /** + Copy constructor, uses reference counting. To create a real copy, + use Copy() member function instead. + */ wxPGChoices( const wxPGChoices& a ) { if ( a.m_data != wxPGChoicesEmptyData ) @@ -696,14 +787,30 @@ public: } } - /** Constructor. */ + /** + Constructor. + + @param labels + Labels for choices + + @param values + Values for choices. If NULL, indexes are used. + */ wxPGChoices( const wxChar** labels, const long* values = NULL ) { Init(); Set(labels,values); } - /** Constructor. */ + /** + Constructor. + + @param labels + Labels for choices + + @param values + Values for choices. If empty, indexes are used. + */ wxPGChoices( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() ) { @@ -730,16 +837,27 @@ public: If did not have own copies, creates them now. If was empty, identical to set except that creates copies. + + @param labels + Labels for added choices. + + @param values + Values for added choices. If empty, relevant entry indexes are used. */ void Add( const wxChar** labels, const ValArrItem* values = NULL ); - /** Version that works with wxArrayString. */ - void Add( const wxArrayString& arr, const ValArrItem* values = NULL ); - /** Version that works with wxArrayString and wxArrayInt. */ - void Add( const wxArrayString& arr, const wxArrayInt& arrint ); + void Add( const wxArrayString& arr, const wxArrayInt& arrint = wxArrayInt() ); - /** Adds single item. */ + /** + Adds a single choice. + + @param label + Label for added choice. + + @param value + Value for added choice. If unspecified, index is used. + */ wxPGChoiceEntry& Add( const wxString& label, int value = wxPG_INVALID_VALUE ); @@ -758,6 +876,10 @@ public: wxPGChoiceEntry& AddAsSorted( const wxString& label, int value = wxPG_INVALID_VALUE ); + /** + Assigns choices data, using reference counting. To create a real copy, + use Copy() member function instead. + */ void Assign( const wxPGChoices& a ) { AssignData(a.m_data); @@ -766,10 +888,17 @@ public: void AssignData( wxPGChoicesData* data ); /** Delete all choices. */ - void Clear() + void Clear(); + + /** + Returns a real copy of the choices. + */ + wxPGChoices Copy() const { - if ( m_data != wxPGChoicesEmptyData ) - m_data->Clear(); + wxPGChoices dst; + dst.EnsureData(); + dst.m_data->CopyDataFrom(m_data); + return dst; } void EnsureData() @@ -781,12 +910,12 @@ public: /** Gets a unsigned number identifying this list. */ wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; }; - const wxString& GetLabel( size_t ind ) const + const wxString& GetLabel( unsigned int ind ) const { return Item(ind).GetText(); } - size_t GetCount () const + unsigned int GetCount () const { if ( !m_data ) return 0; @@ -794,7 +923,7 @@ public: return m_data->GetCount(); } - int GetValue( size_t ind ) const { return Item(ind).GetValue(); } + int GetValue( unsigned int ind ) const { return Item(ind).GetValue(); } /** Returns array of values matching the given strings. Unmatching strings result in wxPG_INVALID_VALUE entry in array. @@ -807,14 +936,6 @@ public: wxArrayInt GetIndicesForStrings( const wxArrayString& strings, wxArrayString* unmatched = NULL ) const; - /** Returns true if choices in general are likely to have values - (depens on that all entries have values or none has) - */ - bool HasValues() const; - - bool HasValue( unsigned int i ) const - { return (i < m_data->GetCount()) && m_data->Item(i)->HasValue(); } - int Index( const wxString& str ) const; int Index( int val ) const; @@ -837,13 +958,13 @@ public: const wxPGChoiceEntry& Item( unsigned int i ) const { wxASSERT( IsOk() ); - return *m_data->Item(i); + return m_data->Item(i); } wxPGChoiceEntry& Item( unsigned int i ) { wxASSERT( IsOk() ); - return *m_data->Item(i); + return m_data->Item(i); } /** Removes count items starting at position nIndex. */ @@ -856,15 +977,6 @@ public: Free(); Add(labels,values); } - - /** Version that works with wxArrayString. - TODO: Deprecate this. - */ - void Set( wxArrayString& arr, const long* values = (const long*) NULL ) - { - Free(); - Add(arr,values); - } #endif // SWIG /** Version that works with wxArrayString and wxArrayInt. */ @@ -879,16 +991,7 @@ public: } // Creates exclusive copy of current choices - void SetExclusive() - { - if ( m_data->m_refCount != 1 ) - { - wxPGChoicesData* data = new wxPGChoicesData(); - data->CopyDataFrom(m_data); - Free(); - m_data = data; - } - } + void AllocExclusive(); // Returns data, increases refcount. wxPGChoicesData* GetData() @@ -914,7 +1017,8 @@ public: #ifndef SWIG void operator= (const wxPGChoices& a) { - AssignData(a.m_data); + if (this != &a) + AssignData(a.m_data); } wxPGChoiceEntry& operator[](unsigned int i) @@ -980,10 +1084,12 @@ public: variant << value; SetValue(variant); - // If has private child properties then create them here, e.g.: - // AddChild( new wxStringProperty( "Subprop 1", - // wxPG_LABEL, - // value.GetSubProp1() ) ); + // If has private child properties then create them here. Also + // set flag that indicates presence of private children. E.g.: + // + // AddPrivateChild( new wxStringProperty("Subprop 1", + // wxPG_LABEL, + // value.GetSubProp1() ) ); } @endcode @@ -1025,35 +1131,52 @@ public: wxPGValidationInfo& validationInfo ) const; /** - Converts 'text' into proper value 'variant'. - Returns true if new (different than m_value) value could be interpreted - from the text. + Converts text into wxVariant value appropriate for this property. + + @param variant + On function entry this is the old value (should not be wxNullVariant + in normal cases). Translated value must be assigned back to it. + + @param text + Text to be translated into variant. + @param argFlags If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one (they may be different). If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of - composite property string value (as generated by GetValueAsString() + composite property string value (as generated by ValueToString() called with this same flag). - @remarks - Default implementation converts semicolon delimited tokens into child - values. Only works for properties with children. + @return Returns @true if resulting wxVariant value was different. + + @remarks Default implementation converts semicolon delimited tokens into + child values. Only works for properties with children. + + You might want to take into account that m_value is Null variant + if property value is unspecified (which is usually only case if + you explicitly enabled that sort behavior). */ virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const; /** - Converts 'number' (including choice selection) into proper value - 'variant'. + Converts integer (possibly a choice selection) into wxVariant value + appropriate for this property. + + @param variant + On function entry this is the old value (should not be wxNullVariant + in normal cases). Translated value must be assigned back to it. - Returns true if new (different than m_value) value could be interpreted - from the integer. + @param number + Integer to be translated into variant. @param argFlags If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one. + @return Returns @true if resulting wxVariant value was different. + @remarks - If property is not supposed to use choice or spinctrl or other editor with int-based value, it is not necessary to implement this method. @@ -1061,27 +1184,32 @@ public: - If property uses choice control, and displays a dialog on some choice items, then it is preferred to display that dialog in IntToValue instead of OnEvent. + - You might want to take into account that m_value is Null variant if + property value is unspecified (which is usually only case if you + explicitly enabled that sort behavior). */ virtual bool IntToValue( wxVariant& value, int number, int argFlags = 0 ) const; #endif // !defined(SWIG) || defined(CREATE_VCW) + /** + Converts property value into a text representation. -public: - /** Returns text representation of property's value. + @param value + Value to be converted. @param argFlags + If 0 (default value), then displayed string is returned. If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable. If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl. If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to - display as a part of composite property string value. + display as a part of string property's composite text + representation. - @remarks - Default implementation returns string composed from text - representations of child properties. + @remarks Default implementation calls GenerateComposedValue(). */ - virtual wxString GetValueAsString( int argFlags = 0 ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; /** Converts string to a value, and if successful, calls SetValue() on it. Default behavior is to do nothing. @@ -1090,7 +1218,7 @@ public: @return true if value was changed. */ - bool SetValueFromString( const wxString& text, int flags = 0 ); + bool SetValueFromString( const wxString& text, int flags = wxPG_PROGRAMMATIC_VALUE ); /** Converts integer to a value, and if succesful, calls SetValue() on it. Default behavior is to do nothing. @@ -1264,7 +1392,7 @@ public: colour) pen for drawing framing rectangle. It can be changed as well. - @see GetValueAsString() + @see ValueToString() */ virtual void OnCustomPaint( wxDC& dc, const wxRect& rect, @@ -1318,18 +1446,14 @@ public: */ virtual wxPGEditorDialogAdapter* GetEditorDialog() const; - /** Returns wxPGCell of given column, NULL if none. If valid - object is returned, caller will gain its ownership. - */ - wxPGCell* AcquireCell( unsigned int column ) - { - if ( column >= m_cells.size() ) - return NULL; + /** + Called whenever validation has failed with given pending value. - wxPGCell* cell = (wxPGCell*) m_cells[column]; - m_cells[column] = NULL; - return cell; - } + @remarks If you implement this in your custom property class, please + remember to call the baser implementation as well, since they + may use it to revert property into pre-change state. + */ + virtual void OnValidationFailure( wxVariant& pendingValue ); /** Append a new choice to property's list of choices. */ @@ -1351,6 +1475,11 @@ public: return false; } + /** + Deletes children of the property. + */ + void DeleteChildren(); + /** Removes entry from property's wxPGChoices and editor control (if it is active). @@ -1372,8 +1501,15 @@ public: else ClearFlag( wxPG_PROP_USES_COMMON_VALUE ); } - /** Composes text from values of child properties. */ - void GenerateComposedValue( wxString& text, int argFlags = 0 ) const; + /** + Composes text from values of child properties. + */ + wxString GenerateComposedValue() const + { + wxString s; + DoGenerateComposedValue(s); + return s; + } /** Returns property's label. */ const wxString& GetLabel() const { return m_label; } @@ -1420,24 +1556,38 @@ public: } #endif - /** To acquire property's value as string, you should use this - function (instead of GetValueAsString()), as it may produce - more accurate value in future versions. + /** Returns text representation of property's value. + + @param argFlags + If 0 (default value), then displayed string is returned. + If wxPG_FULL_VALUE is set, returns complete, storable string value + instead of displayable. If wxPG_EDITABLE_VALUE is set, returns + string value that must be editable in textctrl. If + wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to + display as a part of string property's composite text + representation. + + @remarks In older versions, this function used to be overridden to convert + property's value into a string representation. This function is + now handled by ValueToString(), and overriding this function now + will result in run-time assertion failure. */ - wxString GetValueString( int argFlags = 0 ) const; + virtual wxString GetValueAsString( int argFlags = 0 ) const; + + /** Synonymous to GetValueAsString(). - void UpdateControl( wxWindow* primary ); + @deprecated Use GetValueAsString() instead. - /** Returns wxPGCell of given column, NULL if none. wxPGProperty - will retain ownership of the cell object. + @see GetValueAsString() */ - wxPGCell* GetCell( unsigned int column ) const - { - if ( column >= m_cells.size() ) - return NULL; + wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const ); - return (wxPGCell*) m_cells[column]; - } + /** + Returns wxPGCell of given column. + */ + const wxPGCell& GetCell( unsigned int column ) const; + + wxPGCell& GetCell( unsigned int column ); /** Return number of displayed common values for this property. */ @@ -1445,7 +1595,7 @@ public: wxString GetDisplayedString() const { - return GetValueString(0); + return GetValueAsString(0); } /** Returns property grid where property lies. */ @@ -1529,6 +1679,19 @@ public: */ bool HasVisibleChildren() const; + /** + Use this member function to add independent (ie. regular) children to + a property. + + @return Inserted childProperty. + + @remarks wxPropertyGrid is not automatically refreshed by this + function. + + @see AddPrivateChild() + */ + wxPGProperty* InsertChild( int index, wxPGProperty* childProperty ); + /** Inserts a new choice to property's list of choices. */ int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE ); @@ -1565,7 +1728,9 @@ public: /** Determines, recursively, if all children are not unspecified. - Takes values in given list into account. + @param pendingList + Assumes members in this wxVariant list as pending + replacement values. */ bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const; @@ -1579,9 +1744,9 @@ public: /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES. */ - FlagType UsesAutoUnspecified() const + bool UsesAutoUnspecified() const { - return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED); + return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false; } wxBitmap* GetValueImage() const @@ -1612,8 +1777,6 @@ public: */ double GetAttributeAsDouble( const wxString& name, double defVal ) const; - unsigned int GetArrIndex() const { return m_arrIndex; } - unsigned int GetDepth() const { return (unsigned int)m_depth; } /** Gets flags as a'|' delimited string. Note that flag names are not @@ -1666,6 +1829,32 @@ public: void SetAttributes( const wxPGAttributeStorage& attributes ); + /** + Sets property's background colour. + + @param colour + Background colour to use. + + @param recursively + If @true, children are affected recursively, and any categories + are not. + */ + void SetBackgroundColour( const wxColour& colour, + bool recursively = false ); + + /** + Sets property's text colour. + + @param colour + Text colour to use. + + @param recursively + If @true, children are affected recursively, and any categories + are not. + */ + void SetTextColour( const wxColour& colour, + bool recursively = false ); + #ifndef SWIG /** Sets editor for a property. @@ -1687,11 +1876,10 @@ public: */ inline void SetEditor( const wxString& editorName ); - /** Sets cell information for given column. - - Note that the property takes ownership of given wxPGCell instance. + /** + Sets cell information for given column. */ - void SetCell( int column, wxPGCell* cellObj ); + void SetCell( int column, const wxPGCell& cell ); /** Sets common value selected for this property. -1 for none. */ @@ -1735,26 +1923,21 @@ public: SetValueInEvent() instead. @param pList - Pointer to list variant that contains child values. Used to indicate - which children should be marked as modified. + Pointer to list variant that contains child values. Used to + indicate which children should be marked as modified. + @param flags - Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR). + Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is + enabled by default). */ - void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 ); + void SetValue( wxVariant value, wxVariant* pList = NULL, + int flags = wxPG_SETVAL_REFRESH_EDITOR ); /** Set wxBitmap in front of the value. This bitmap may be ignored by custom cell renderers. */ void SetValueImage( wxBitmap& bmp ); - /** If property has choices and they are not yet exclusive, new such copy - of them will be created. - */ - void SetChoicesExclusive() - { - m_choices.SetExclusive(); - } - /** Sets selected choice and changes property value. Tries to retain value type, although currently if it is not string, @@ -1768,8 +1951,22 @@ public: else m_flags &= ~wxPG_PROP_COLLAPSED; } + /** + Sets given property flag(s). + */ void SetFlag( FlagType flag ) { m_flags |= flag; } + /** + Sets or clears given property flag(s). + */ + void ChangeFlag( FlagType flag, bool set ) + { + if ( set ) + m_flags |= flag; + else + m_flags &= ~flag; + } + void SetFlagRecursively( FlagType flag, bool set ); void SetHelpString( const wxString& helpString ) @@ -1781,6 +1978,23 @@ public: inline void SetName( const wxString& newName ); + /** + Changes what sort of parent this property is for its children. + + @param flag + Use one of the following values: wxPG_PROP_MISC_PARENT (for + generic parents), wxPG_PROP_CATEGORY (for categories), or + wxPG_PROP_AGGREGATE (for derived property classes with private + children). + + @remarks You generally do not need to call this function. + */ + void SetParentalType( int flag ) + { + m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS); + m_flags |= flag; + } + void SetValueToUnspecified() { wxVariant val; // Create NULL variant @@ -1803,23 +2017,6 @@ public: } #endif // #if wxUSE_VALIDATORS - /** Updates property value in case there were last minute - changes. If value was unspecified, it will be set to default. - Use only for properties that have TextCtrl-based editor. - @remarks - If you have code similar to - @code - // Update the value in case of last minute changes - if ( primary && propgrid->IsEditorsValueModified() ) - GetEditorClass()->CopyValueFromControl( this, primary ); - @endcode - in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler, - then replace it with call to this method. - @return - True if value changed. - */ - bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid ); - #ifndef SWIG /** Returns client data (void*) of a property. */ @@ -1857,15 +2054,6 @@ public: */ bool SetChoices( wxPGChoices& choices ); - /** Sets new set of choices for property. - */ - bool SetChoices( const wxArrayString& labels, - const wxArrayInt& values = wxArrayInt() ) - { - wxPGChoices chs(labels, values); - return SetChoices(chs); - } - /** Set max length of text in text editor. */ inline bool SetMaxLength( int maxLen ); @@ -1895,8 +2083,33 @@ public: */ void AdaptListToValue( wxVariant& list, wxVariant* value ) const; - /** This is used by properties that have fixed sub-properties. */ - void AddChild( wxPGProperty* prop ); +#if wxPG_COMPATIBILITY_1_4 + /** + Adds a private child property. + + @deprecated Use AddPrivateChild() instead. + + @see AddPrivateChild() + */ + wxDEPRECATED( void AddChild( wxPGProperty* prop ) ); +#endif + + /** + Adds a private child property. If you use this instead of + wxPropertyGridInterface::Insert() or + wxPropertyGridInterface::AppendIn(), then property's parental + type will automatically be set up to wxPG_PROP_AGGREGATE. In other + words, all properties of this property will become private. + */ + void AddPrivateChild( wxPGProperty* prop ); + + /** + Appends a new child property. + */ + wxPGProperty* AppendChild( wxPGProperty* prop ) + { + return InsertChild(-1, prop); + } /** Returns height of children, recursively, and by taking expanded/collapsed status into account. @@ -1906,25 +2119,29 @@ public: int GetChildrenHeight( int lh, int iMax = -1 ) const; /** Returns number of child properties */ - unsigned int GetChildCount() const { return m_children.GetCount(); } + unsigned int GetChildCount() const + { + return (unsigned int) m_children.size(); + } /** Returns sub-property at index i. */ - wxPGProperty* Item( size_t i ) const - { return (wxPGProperty*)m_children.Item(i); } + wxPGProperty* Item( unsigned int i ) const + { return m_children[i]; } /** Returns last sub-property. */ - wxPGProperty* Last() const { return (wxPGProperty*)m_children.Last(); } + wxPGProperty* Last() const { return m_children.back(); } - /** Returns index of given sub-property. */ - int Index( const wxPGProperty* p ) const - { return m_children.Index((wxPGProperty*)p); } - - /** Deletes all sub-properties. */ - void Empty(); + /** Returns index of given child property. */ + int Index( const wxPGProperty* p ) const; // Puts correct indexes to children - void FixIndexesOfChildren( size_t starthere = 0 ); + void FixIndicesOfChildren( unsigned int starthere = 0 ); + + /** + Converts image width into full image offset, with margins. + */ + int GetImageOffset( int imageWidth ) const; #ifndef SWIG // Returns wxPropertyGridPageState in which this property resides. @@ -1969,6 +2186,13 @@ public: #ifndef SWIG + // Returns various display-related information for given column + void GetDisplayInfo( unsigned int column, + int choiceIndex, + int flags, + wxString* pString, + const wxPGCell** pCell ); + static wxString* sm_wxPG_LABEL; /** This member is public so scripting language bindings @@ -1977,9 +2201,49 @@ public: void* m_clientData; protected: - /** Returns text for given column. + + /** + Sets property cell in fashion that reduces number of exclusive + copies of cell data. Used when setting, for instance, same + background colour for a number of properties. + + @param firstCol + First column to affect. + + @param lastCol + Last column to affect. + + @param preparedCell + Pre-prepared cell that is used for those which cell data + before this matched unmodCellData. + + @param srcData + If unmodCellData did not match, valid cell data from this + is merged into cell (usually generating new exclusive copy + of cell's data). + + @param unmodCellData + If cell's cell data matches this, its cell is now set to + preparedCell. + + @param ignoreWithFlags + Properties with any one of these flags are skipped. + + @param recursively + If @true, apply this operation recursively in child properties. */ - wxString GetColumnText( unsigned int col ) const; + void AdaptiveSetCell( unsigned int firstCol, + unsigned int lastCol, + const wxPGCell& preparedCell, + const wxPGCell& srcData, + wxPGCellData* unmodCellData, + FlagType ignoreWithFlags, + bool recursively ); + + /** + Makes sure m_cells has size of column+1 (or more). + */ + void EnsureCells( unsigned int column ); /** Returns (direct) child property with given name (or NULL if not found), with hint index. @@ -1994,20 +2258,27 @@ protected: unsigned int hintIndex ) const; /** This is used by Insert etc. */ - void AddChild2( wxPGProperty* prop, - int index = -1, - bool correct_mode = true ); + void DoAddChild( wxPGProperty* prop, + int index = -1, + bool correct_mode = true ); + + void DoGenerateComposedValue( wxString& text, + int argFlags = wxPG_VALUE_IS_CURRENT, + const wxVariantList* valueOverrides = NULL, + wxPGHashMapS2S* childResults = NULL ) const; void DoSetName(const wxString& str) { m_name = str; } - // Call for after sub-properties added with AddChild - void PrepareSubProperties(); + /** Deletes all sub-properties. */ + void Empty(); - void SetParentalType( int flag ) - { - m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS); - m_flags |= flag; - } + void InitAfterAdded( wxPropertyGridPageState* pageState, + wxPropertyGrid* propgrid ); + + // Removes child property with given pointer. Does not delete it. + void RemoveChild( wxPGProperty* p ); + + void DoPreAddChild( int index, wxPGProperty* prop ); void SetParentState( wxPropertyGridPageState* pstate ) { m_parentState = pstate; } @@ -2022,7 +2293,7 @@ protected: wxString m_label; wxString m_name; wxPGProperty* m_parent; - wxPropertyGridPageState* m_parentState; + wxPropertyGridPageState* m_parentState; wxClientData* m_clientObject; @@ -2039,10 +2310,10 @@ protected: wxVariant m_value; wxPGAttributeStorage m_attributes; - wxArrayPtrVoid m_children; + wxArrayPGProperty m_children; // Extended cell information - wxArrayPtrVoid m_cells; + wxVector m_cells; // Choices shown in drop-down list of editor control. wxPGChoices m_choices; @@ -2071,9 +2342,6 @@ protected: // (essentially this is category's depth, if none then equals m_depth). unsigned char m_depthBgCol; - unsigned char m_bgColIndex; // Background brush index. - unsigned char m_fgColIndex; // Foreground colour index. - private: // Called in constructors. void Init(); @@ -2124,7 +2392,7 @@ public: public: /** Constructor. */ - wxPGRootProperty(); + wxPGRootProperty( const wxString& name = wxS("") ); virtual ~wxPGRootProperty(); virtual bool StringToValue( wxVariant&, const wxString&, int ) const @@ -2157,9 +2425,9 @@ public: int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const; -protected: - virtual wxString GetValueAsString( int argFlags ) const; + virtual wxString ValueToString( wxVariant& value, int argFlags ) const; +protected: void SetTextColIndex( unsigned int colInd ) { m_capFgColIndex = (wxByte) colInd; } unsigned int GetTextColIndex() const