[Libreoffice-commits] core.git: forms/source

Stephan Bergmann sbergman at redhat.com
Fri Feb 27 04:27:55 PST 2015


 forms/source/component/FormattedFieldWrapper.cxx |   44 +++++++++++++++++++++--
 forms/source/component/FormattedFieldWrapper.hxx |   12 ++++--
 2 files changed, 51 insertions(+), 5 deletions(-)

New commits:
commit fa6c09877ed6502593de2f73541d91f31c8feea1
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Feb 27 13:25:42 2015 +0100

    Fix OFormattedFieldWrapper[_ForcedFormatted] instance creation
    
    broken with 5d05f7ed8582193c39e29b7dc16767fb850e9f28 "forms: use constructor
    feature for form modules" and follow-up misguided clean up
    
    Change-Id: If9447740e6408472722b81d112cd85349020eabe

diff --git a/forms/source/component/FormattedFieldWrapper.cxx b/forms/source/component/FormattedFieldWrapper.cxx
index 43d81f6..f278132 100644
--- a/forms/source/component/FormattedFieldWrapper.cxx
+++ b/forms/source/component/FormattedFieldWrapper.cxx
@@ -48,6 +48,40 @@ OFormattedFieldWrapper::OFormattedFieldWrapper(const Reference<XComponentContext
 {
 }
 
+InterfaceRef OFormattedFieldWrapper::createFormattedFieldWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory, bool bActAsFormatted)
+{
+    OFormattedFieldWrapper *pRef = new OFormattedFieldWrapper(_rxFactory);
+
+    if (bActAsFormatted)
+    {
+        // instantiate an FormattedModel
+        InterfaceRef  xFormattedModel;
+        // (instantiate it directly ..., as the OFormattedModel isn't
+        // registered for any service names anymore)
+        OFormattedModel* pModel = new OFormattedModel(pRef->m_xContext);
+        query_interface(static_cast<XWeak*>(pModel), xFormattedModel);
+
+        pRef->m_xAggregate = Reference<XAggregation> (xFormattedModel, UNO_QUERY);
+        OSL_ENSURE(pRef->m_xAggregate.is(), "the OFormattedModel didn't have an XAggregation interface !");
+
+        // _before_ setting the delegator, give it to the member references
+        query_interface(xFormattedModel, pRef->m_xFormattedPart);
+        pRef->m_pEditPart = rtl::Reference< OEditModel >(new OEditModel(pRef->m_xContext));
+    }
+
+    increment(pRef->m_refCount);
+
+    if (pRef->m_xAggregate.is())
+    {   // has to be in it's own block because of the temporary variable created by *this
+        pRef->m_xAggregate->setDelegator(static_cast<XWeak*>(pRef));
+    }
+
+    InterfaceRef xRef(*pRef);
+    decrement(pRef->m_refCount);
+
+    return xRef;
+}
+
 Reference< XCloneable > SAL_CALL OFormattedFieldWrapper::createClone() throw (RuntimeException, std::exception)
 {
     ensureAggregate();
@@ -311,14 +345,20 @@ extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
 com_sun_star_form_OFormattedFieldWrapper_get_implementation(::com::sun::star::uno::XComponentContext* component,
         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
 {
-    return cppu::acquire(new frm::OFormattedFieldWrapper(component));
+    css::uno::Reference<css::uno::XInterface> inst(
+        OFormattedFieldWrapper::createFormattedFieldWrapper(component, false));
+    inst->acquire();
+    return inst.get();
 }
 
 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
 com_sun_star_comp_forms_OFormattedFieldWrapper_ForcedFormatted_get_implementation(::com::sun::star::uno::XComponentContext* component,
         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
 {
-    return cppu::acquire(new frm::OFormattedFieldWrapper(component));
+    css::uno::Reference<css::uno::XInterface> inst(
+        OFormattedFieldWrapper::createFormattedFieldWrapper(component, true));
+    inst->acquire();
+    return inst.get();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/forms/source/component/FormattedFieldWrapper.hxx b/forms/source/component/FormattedFieldWrapper.hxx
index b510957..36a8c47 100644
--- a/forms/source/component/FormattedFieldWrapper.hxx
+++ b/forms/source/component/FormattedFieldWrapper.hxx
@@ -41,9 +41,6 @@ class OFormattedFieldWrapper : public OFormattedFieldWrapper_Base
 {
     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
 
-public:
-    OFormattedFieldWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory);
-
 protected:
     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation>      m_xAggregate;
 
@@ -51,10 +48,19 @@ protected:
     // if we act as formatted this is used to write the EditModel part
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject>     m_xFormattedPart;
 
+private:
+    OFormattedFieldWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory);
+
 protected:
     virtual ~OFormattedFieldWrapper();
 
 public:
+    // if we act as formatted, this is the PersistObject interface of our aggregate, used
+    // to read and write the FormattedModel part
+    // if bActAsFormatted is false, the state is undetermined until somebody calls
+    // ::read or does anything which requires a living aggregate
+    static InterfaceRef createFormattedFieldWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory, bool bActAsFormatted);
+
     // UNO
     DECLARE_UNO3_AGG_DEFAULTS(OFormattedFieldWrapper, OWeakAggObject)
     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;


More information about the Libreoffice-commits mailing list