]> git.saurik.com Git - wxWidgets.git/blobdiff - interface/wx/propgrid/property.h
interface revisions
[wxWidgets.git] / interface / wx / propgrid / property.h
index d02fe49fe7f4066412b5987888169b5f6fa7c417..4538172cc2f36ac7ce1e3125ee5d8fa13959fade 100644 (file)
@@ -2,7 +2,7 @@
 // Name:        property.h
 // Purpose:     interface of wxPGProperty
 // Author:      wxWidgets team
-// RCS-ID:      $Id:
+// RCS-ID:      $Id$
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
     dialog. Note that in long string values, tabs are represented by "\t" and
     line break by "\n".
 
+    To display custom dialog on button press, you can subclass
+    wxLongStringProperty and implement OnButtonClick, like this:
+
+    @code
+        virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
+        {
+            wxSize dialogSize(...size of your dialog...);
+
+            wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
+                                                                   dialogSize)
+
+            // Create dialog dlg at dlgPos. Use value as initial string
+            // value.
+            ...
+
+            if ( dlg.ShowModal() == wxID_OK )
+            {
+                value = dlg.GetStringValue);
+                return true;
+            }
+            return false;
+        }
+    @endcode
+
+    Also, if you wish not to have line breaks and tabs translated to
+    escape sequences, then do following in constructor of your subclass:
+
+    @code
+        m_flags |= wxPG_PROP_NO_ESCAPE;
+    @endcode
+
     @subsection wxDirProperty
 
     Like wxLongStringProperty, but the button triggers dir selector instead.
     <b>Useful alternate editor:</b> Choice.
 
     Represents wxColour. wxButton is used to trigger a colour picker dialog.
+    There are various sub-classing opportunities with this class. See
+    below in wxSystemColourProperty section for details.
 
     @subsection wxFontProperty
 
 
     Represents wxColour and a system colour index. wxChoice is used to edit
     the value. Drop-down list has color images. Note that value type
-    is wxColourPropertyValue instead of wxColour.
+    is wxColourPropertyValue instead of wxColour (which wxColourProperty
+    uses).
+
     @code
         class wxColourPropertyValue : public wxObject
         {
             wxColour    m_colour;
         };
     @endcode
+    
+    in wxSystemColourProperty, and its derived class wxColourProperty, there
+    are various sub-classing features. To set basic list list of colour
+    names, call wxPGProperty::SetChoices().
+
+    @code
+        // Override in derived class to customize how colours are translated
+        // to strings.
+        virtual wxString ColourToString( const wxColour& col, int index ) const;
+
+        // Returns index of entry that triggers colour picker dialog
+        // (default is last).
+        virtual int GetCustomColourIndex() const;
+
+        // Helper function to show the colour dialog
+        bool QueryColourFromUser( wxVariant& variant ) const;
+
+        // Returns colour for given choice.
+        // Default function returns wxSystemSettings::GetColour(index).
+        virtual wxColour GetColour( int index ) const;
+    @endcode
 
     @subsection wxCursorProperty
 
                 return wxPGEditor_TextCtrl;
             }
 
-            virtual wxString GetValueAsString( int argFlags ) const
+            virtual wxString ValueToString( wxVariant& value,
+                                            int argFlags ) const
             {
-                // TODO: Return property value in string format
+                // TODO: Convert given property value to a string
             }
 
             virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
@@ -486,7 +543,7 @@ public:
             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).
 
         @return Returns @true if resulting wxVariant value was different.
@@ -531,19 +588,23 @@ public:
     virtual bool IntToValue( wxVariant& value, int number, int argFlags = 0 ) const;
 
     /**
-        Returns text representation of property's value.
+        Converts property value into a text representation.
+
+        @param value
+            Value to be converted.
 
         @param argFlags
-        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.
+            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
-        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.
@@ -729,7 +790,7 @@ public:
             - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
               drawing framing rectangle. It can be changed as well.
 
-        @see GetValueAsString()
+        @see ValueToString()
     */
     virtual void OnCustomPaint( wxDC& dc, const wxRect& rect, wxPGPaintData& paintdata );
 
@@ -812,8 +873,21 @@ public:
     int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE );
 
     /**
-        Properties which have private child properties should add them
-        with this function, called in their constructor.
+        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* property );
 
@@ -854,8 +928,10 @@ public:
     /** Deletes all child properties. */
     void Empty();
 
-    /** 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;
 
     /**
         Returns property attribute value, null variant if not found.
@@ -1030,14 +1106,31 @@ public:
     */
     wxBitmap* GetValueImage() const;
 
-    /**
-        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.
+    */
+    virtual wxString GetValueAsString( int argFlags = 0 ) const;
+
+    /** Synonymous to GetValueAsString().
+
+        @deprecated Use GetValueAsString() instead.
 
         @see GetValueAsString()
     */
-    wxString GetValueString( int argFlags = 0 ) const;
+    wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
 
     /**
         Returns value type used by this property.
@@ -1138,25 +1231,7 @@ public:
     /**
         Returns child property at index i.
     */
-    wxPGProperty* Item( size_t i ) const;
-
-    /**
-        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 Returns @true if value changed.
-    */
-    bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
+    wxPGProperty* Item( unsigned int i ) const;
 
     /**
         If property's editor is active, then update it's value.
@@ -1261,6 +1336,23 @@ public:
     */
     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 );
+
     /** Sets wxValidator for a property */
     void SetValidator( const wxValidator& validator );
 
@@ -1410,17 +1502,17 @@ public:
     /**
         Returns labe of item.
     */
-    const wxString& GetLabel( size_t ind ) const;
+    const wxString& GetLabel( unsigned int ind ) const;
 
     /**
         Returns number of items.
     */
-    size_t GetCount () const;
+    unsigned int GetCount() const;
 
     /**
         Returns value of item;
     */
-    int GetValue( size_t ind ) const;
+    int GetValue( unsigned int ind ) const;
 
     /**
         Returns array of values matching the given strings. Unmatching strings