X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40924780ea265ba9430b59348c563d78b8c40a71..c39058f631b3a53682f00807a60bfff6c5aa2b7c:/include/wx/propgrid/property.h?ds=sidebyside diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 682732813c..ff2d2d5377 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 ///////////////////////////////////////////////////////////////////////////// @@ -215,7 +215,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); @@ -615,11 +615,11 @@ public: // Takes ownership of 'item' void Insert( int index, wxPGChoiceEntry* item ) { - wxArrayPtrVoid::iterator it; + wxVector::iterator it; if ( index == -1 ) { it = m_items.end(); - index = m_items.size(); + index = (int) m_items.size(); } else { @@ -636,13 +636,16 @@ public: // 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 { wxCHECK_MSG( i < GetCount(), NULL, "invalid index" ); - return (wxPGChoiceEntry*) m_items[i]; + return m_items[i]; } void DecRef() @@ -654,7 +657,7 @@ public: } private: - wxArrayPtrVoid m_items; + wxVector m_items; // So that multiple properties can use the same set int m_refCount; @@ -781,12 +784,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 +797,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. @@ -856,15 +859,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. */ @@ -980,7 +974,11 @@ public: variant << value; SetValue(variant); - // If has private child properties then create them here, e.g.: + // If has private child properties then create them here. Also + // set flag that indicates presence of private children. E.g.: + // + // SetParentalType(wxPG_PROP_AGGREGATE); + // // AddChild( new wxStringProperty( "Subprop 1", // wxPG_LABEL, // value.GetSubProp1() ) ); @@ -1025,9 +1023,15 @@ 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). @@ -1035,25 +1039,36 @@ public: composite property string value (as generated by GetValueAsString() 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,6 +1076,9 @@ 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, @@ -1565,7 +1583,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 +1599,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 +1632,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 @@ -1781,6 +1799,27 @@ 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 only need to call this if you use AddChild() to add + child properties. Adding properties with + wxPropertyGridInterface::Insert() or + wxPropertyGridInterface::AppendIn() will automatically set + property to use wxPG_PROP_MISC_PARENT style. + */ + 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 +1842,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 +1879,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,7 +1908,23 @@ public: */ void AdaptListToValue( wxVariant& list, wxVariant* value ) const; - /** This is used by properties that have fixed sub-properties. */ + /** + Adds a child property. If you use this instead of + wxPropertyGridInterface::Insert() or + wxPropertyGridInterface::AppendIn(), then you must set up + property's parental type before making the call. To do this, + call property's SetParentalType() function with either + wxPG_PROP_MISC_PARENT (normal, public children) or with + wxPG_PROP_AGGREGATE (private children for subclassed property). + For instance: + + @code + wxPGProperty* prop = new wxStringProperty(wxS("Property")); + prop->SetParentalType(wxPG_PROP_MISC_PARENT); + wxPGProperty* prop2 = new wxStringProperty(wxS("Property2")); + prop->AddChild(prop2); + @endcode + */ void AddChild( wxPGProperty* prop ); /** Returns height of children, recursively, and @@ -1906,25 +1935,27 @@ 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); } + /** Returns index of given child property. */ + int Index( const wxPGProperty* p ) const; /** Deletes all sub-properties. */ void Empty(); // Puts correct indexes to children - void FixIndexesOfChildren( size_t starthere = 0 ); + void FixIndicesOfChildren( unsigned int starthere = 0 ); #ifndef SWIG // Returns wxPropertyGridPageState in which this property resides. @@ -2000,14 +2031,11 @@ protected: void DoSetName(const wxString& str) { m_name = str; } - // Call for after sub-properties added with AddChild - void PrepareSubProperties(); + void InitAfterAdded( wxPropertyGridPageState* pageState, + wxPropertyGrid* propgrid ); - void SetParentalType( int flag ) - { - m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS); - m_flags |= flag; - } + // Removes child property with given pointer. Does not delete it. + void RemoveChild( wxPGProperty* p ); void SetParentState( wxPropertyGridPageState* pstate ) { m_parentState = pstate; } @@ -2039,7 +2067,7 @@ protected: wxVariant m_value; wxPGAttributeStorage m_attributes; - wxArrayPtrVoid m_children; + wxArrayPGProperty m_children; // Extended cell information wxArrayPtrVoid m_cells;