]> git.saurik.com Git - wxWidgets.git/commitdiff
Removed dysfunctional wxPGPropery::PrepareValueForDialogEditing(); Replaced its funct...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Wed, 8 Oct 2008 18:15:10 +0000 (18:15 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Wed, 8 Oct 2008 18:15:10 +0000 (18:15 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56169 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/property.h
include/wx/propgrid/propgrid.h
interface/wx/propgrid/property.h
interface/wx/propgrid/propgrid.h
samples/propgrid/sampleprops.cpp
src/propgrid/advprops.cpp
src/propgrid/property.cpp
src/propgrid/propgrid.cpp
src/propgrid/props.cpp

index ece85011db7cedabbb6560f2b91801153088a9ca..6825cda44580ad69274ce84f88741d0d50e5c8a1 100644 (file)
@@ -1814,23 +1814,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.
     */
index 8bad63c5d4cb742778d8b951ccaca048d24e3459..3796b332d3dd98f5c889eafea10d87b2186909f2 100644 (file)
@@ -832,6 +832,14 @@ public:
     /** Returns background colour of margin. */
     wxColour GetMarginColour() const { return m_colMargin; }
 
+    /**
+        Returns most up-to-date value of selected property. This will return
+        value different from GetSelectedProperty()->GetValue() only when text
+        editor is activate and string edited by user represents valid,
+        uncommitted property value.
+    */
+    wxVariant GetPendingEditedValue();
+
     /** Returns cell background colour of a property. */
     wxColour GetPropertyBackgroundColour( wxPGPropArg id ) const;
 
@@ -1257,12 +1265,6 @@ public:
     virtual bool DoPropertyChanged( wxPGProperty* p,
                                     unsigned int selFlags = 0 );
 
-    /**
-        Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
-        Returns true if all tests passed.
-    */
-    virtual bool PerformValidation( wxPGProperty* p, wxVariant& pendingValue );
-
     /** Called when validation for given property fails.
         @param invalidValue
             Value which failed in validation.
@@ -1340,6 +1342,21 @@ protected:
     */
     virtual wxPropertyGridPageState* CreateState() const;
 
+    enum PerformValidationFlags
+    {
+        SendEvtChanging         = 0x0001,
+        IsStandaloneValidation  = 0x0002   // Not called in response to event
+    };
+
+    /**
+        Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
+        Returns true if all tests passed. Implement in derived class to
+        add additional validation behavior.
+    */
+    virtual bool PerformValidation( wxPGProperty* p,
+                                    wxVariant& pendingValue,
+                                    int flags = SendEvtChanging );
+
 #ifndef DOXYGEN
 public:
 
index 229a8ede3ca506abb301c585a277da237c163790..5b5e500e924d8422df282be746c77351f83d98c4 100644 (file)
     @code
         virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
         {
-            // Update property value from editor, if necessary
-            PrepareValueForDialogEditing(propGrid);
-
             wxSize dialogSize(...size of your dialog...);
 
             wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
@@ -1199,24 +1196,6 @@ public:
     */
     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 );
-
     /**
         If property's editor is active, then update it's value.
     */
index 8e96de4352a2ae467be2347e2446e311f691d444..bcbf41ac7d5acaece611eb9165ae2376a7d31a4c 100644 (file)
@@ -586,6 +586,14 @@ public:
     */
     wxColour GetMarginColour() const;
 
+    /**
+        Returns most up-to-date value of selected property. This will return
+        value different from GetSelectedProperty()->GetValue() only when text
+        editor is activate and string edited by user represents valid,
+        uncommitted property value.
+    */
+    wxVariant GetPendingEditedValue();
+
     /**
         Returns cell background colour of a property.
     */
index 459de82c475908e813dd94aaeaaaf40221e1fe0d..21303e7af44252cd8c644b6eb4bc10d66476b054 100644 (file)
@@ -131,11 +131,10 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
 {
     if ( propgrid->IsMainButtonEvent(event) )
     {
-        // Update value from last minute changes
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetPendingEditedValue();
 
         wxFontData fontData;
-        fontData << m_value_wxFontData;
+        fontData << useValue;
 
         fontData.SetInitialFont(fontData.GetChosenFont());
 
@@ -554,10 +553,10 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
 {
     if ( propgrid->IsMainButtonEvent(event) )
     {
-        wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
-
         // Update the value in case of last minute changes
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetPendingEditedValue();
+
+        wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
 
         // Create editor dialog.
         wxArrayDoubleEditorDialog dlg;
index 1f556ddbcf29877ca3d0b89bfdd0cb45fb631b40..f50ce38f493226f73c85119be25987122c556d2f 100644 (file)
@@ -531,11 +531,11 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
     if ( propgrid->IsMainButtonEvent(event) )
     {
         // Update value from last minute changes
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetPendingEditedValue();
 
         wxFontData data;
         wxFont font;
-        font << m_value;
+        font << useValue;
         data.SetInitialFont( font );
         data.SetColour(*wxBLACK);
 
@@ -1803,7 +1803,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
     if ( propgrid->IsMainButtonEvent(event) )
     {
         // Update the value
-        PrepareValueForDialogEditing(propgrid);
+        wxVariant useValue = propgrid->GetPendingEditedValue();
 
         wxArrayString labels = m_choices.GetLabels();
         unsigned int choiceCount;
@@ -1823,7 +1823,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
 
         dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
 
-        wxArrayString strings = m_value.GetArrayString();
+        wxArrayString strings = useValue.GetArrayString();
         wxArrayString extraStrings;
 
         dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
index cc14b53a9f3b0ce4ea400f45a0842a51370652a3..e26512862e29c4eec95fa48833a081836fc44ca3 100644 (file)
@@ -1412,12 +1412,6 @@ bool wxPGProperty::HasVisibleChildren() const
     return false;
 }
 
-bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid )
-{
-    return propGrid->CommitChangesFromEditor();
-}
-
-
 bool wxPGProperty::RecreateEditor()
 {
     wxPropertyGrid* pg = GetGrid();
index 0b0f8a4bcf55de6d320331081b6033ea2d2c94c7..0ec16d26c292ff6e110f8d2fedf825d212df0355 100644 (file)
@@ -2731,7 +2731,8 @@ bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
 
 // -----------------------------------------------------------------------
 
-bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue )
+bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
+                                        int flags )
 {
     //
     // Runs all validation functionality.
@@ -2800,34 +2801,37 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
 
     wxVariant evtChangingValue = value;
 
-    // FIXME: After proper ValueToString()s added, remove
-    // this. It is just a temporary fix, as evt_changing
-    // will simply not work for wxPG_PROP_COMPOSED_VALUE
-    // (unless it is selected, and textctrl editor is open).
-    if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
+    if ( flags & SendEvtChanging )
     {
-        evtChangingProperty = baseChangedProperty;
-        if ( evtChangingProperty != p )
+        // FIXME: After proper ValueToString()s added, remove
+        // this. It is just a temporary fix, as evt_changing
+        // will simply not work for wxPG_PROP_COMPOSED_VALUE
+        // (unless it is selected, and textctrl editor is open).
+        if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
         {
-            evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
-        }
-        else
-        {
-            evtChangingValue = pendingValue;
+            evtChangingProperty = baseChangedProperty;
+            if ( evtChangingProperty != p )
+            {
+                evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
+            }
+            else
+            {
+                evtChangingValue = pendingValue;
+            }
         }
-    }
 
-    if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
-    {
-        if ( changedProperty == m_selected )
-        {
-            wxWindow* editor = GetEditorControl();
-            wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
-            evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
-        }
-        else
+        if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
         {
-            wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
+            if ( changedProperty == m_selected )
+            {
+                wxWindow* editor = GetEditorControl();
+                wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
+                evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
+            }
+            else
+            {
+                wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
+            }
         }
     }
 
@@ -2849,9 +2853,20 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
             return false;
     }
 
-    // SendEvent returns true if event was vetoed
-    if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
-        return false;
+    if ( flags & SendEvtChanging )
+    {
+        // SendEvent returns true if event was vetoed
+        if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
+            return false;
+    }
+
+    if ( flags & IsStandaloneValidation )
+    {
+        // If called in 'generic' context, we need to reset
+        // m_chgInfo_changedProperty and write back translated value.
+        m_chgInfo_changedProperty = NULL;
+        pendingValue = value;
+    }
 
     return true;
 }
@@ -3089,6 +3104,30 @@ bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue )
 
 // -----------------------------------------------------------------------
 
+wxVariant wxPropertyGrid::GetPendingEditedValue()
+{
+    wxPGProperty* prop = GetSelectedProperty();
+
+    if ( !prop )
+        return wxNullVariant;
+
+    wxTextCtrl* tc = GetEditorTextCtrl();
+    wxVariant value = prop->GetValue();
+
+    if ( !tc || !IsEditorsValueModified() )
+        return value;
+
+    if ( !prop->StringToValue(value, tc->GetValue()) )
+        return value;
+
+    if ( !PerformValidation(prop, value, IsStandaloneValidation) )
+        return prop->GetValue();
+
+    return value;
+}
+
+// -----------------------------------------------------------------------
+
 // Runs wxValidator for the selected property
 bool wxPropertyGrid::DoEditorValidate()
 {
index d4e078bd2d2250bbf0228fdbe1e5df78f04ed9be..a4119166876608456f2e95409892dfc777337453 100644 (file)
@@ -1558,8 +1558,6 @@ wxValidator* wxDirProperty::DoGetValidator() const
 bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
 {
     // Update property value from editor, if necessary
-    PrepareValueForDialogEditing(propGrid);
-
     wxSize dlg_sz(300,400);
 
     wxDirDialog dlg( propGrid,
@@ -1887,9 +1885,9 @@ bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED
     if ( propGrid->IsMainButtonEvent(event) )
     {
         // Update the value
-        PrepareValueForDialogEditing(propGrid);
+        wxVariant useValue = propGrid->GetPendingEditedValue();
 
-        wxString val1 = GetValueAsString(0);
+        wxString val1 = useValue.GetString();
         wxString val_orig = val1;
 
         wxString value;
@@ -2489,7 +2487,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
                                            const wxChar* cbt )
 {
     // Update the value
-    PrepareValueForDialogEditing(propGrid);
+    wxVariant useValue = propGrid->GetPendingEditedValue();
 
     if ( !propGrid->EditorValidate() )
         return false;
@@ -2506,7 +2504,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
     if ( strEdDlg )
         strEdDlg->SetCustomButton(cbt, this);
 
-    dlg->SetDialogValue( wxVariant(m_value) );
+    dlg->SetDialogValue( useValue );
     dlg->Create(propGrid, wxEmptyString, m_label);
 
 #if !wxPG_SMALL_SCREEN