summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-10-27 22:17:55 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-10-28 06:31:41 +0200
commit16e98d669f2d1dd36c39007daab05a8696b08ebb (patch)
tree345c4331a554db1c32061a4dadbf0a5a3c1764b9
parent5f72a041c0160e4067ca931a9cec711b84b558f4 (diff)
Introduce utl::ConnectModelViewController
And use it to avoid code duplication Change-Id: I18447bc1a0388d57a273b310977a0f0fb54152b1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141946 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--dbaccess/source/filter/xml/dbloader2.cxx8
-rw-r--r--dbaccess/source/ui/browser/dbloader.cxx5
-rw-r--r--framework/source/services/autorecovery.cxx7
-rw-r--r--include/unotools/mvc.hxx51
-rw-r--r--sd/qa/unit/misc-tests.cxx7
-rw-r--r--sfx2/source/view/frmload.cxx7
6 files changed, 62 insertions, 23 deletions
diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx
index d00dba43445d..bfcdfc074026 100644
--- a/dbaccess/source/filter/xml/dbloader2.cxx
+++ b/dbaccess/source/filter/xml/dbloader2.cxx
@@ -53,6 +53,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <sfx2/docfile.hxx>
#include <unotools/moduleoptions.hxx>
+#include <unotools/mvc.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <vcl/svapp.hxx>
@@ -447,11 +448,8 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU
Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW );
Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_SET_THROW );
- xController->attachModel( xModel );
- xModel->connectController( xController );
- rFrame->setComponent( xController->getComponentWindow(), xController );
- xController->attachFrame( rFrame );
- xModel->setCurrentController( xController );
+ // introduce model/view/controller to each other
+ utl::ConnectModelViewController(xModel, rFrame, xController);
bSuccess = true;
}
diff --git a/dbaccess/source/ui/browser/dbloader.cxx b/dbaccess/source/ui/browser/dbloader.cxx
index cb1371c80c57..d5c4395efe3a 100644
--- a/dbaccess/source/ui/browser/dbloader.cxx
+++ b/dbaccess/source/ui/browser/dbloader.cxx
@@ -38,6 +38,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <tools/urlobj.hxx>
+#include <unotools/mvc.hxx>
#include <vcl/svapp.hxx>
using namespace ::com::sun::star;
@@ -177,9 +178,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU
if ( xReportModel.is() )
{
xController.set( ReportDesign::create( m_xContext ) );
- xController->attachModel( xReportModel );
- xReportModel->connectController( xController );
- xReportModel->setCurrentController( xController );
+ utl::ConnectModelController(xReportModel, xController);
}
}
diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx
index 30894359e38b..d59a36b5bb09 100644
--- a/framework/source/services/autorecovery.cxx
+++ b/framework/source/services/autorecovery.cxx
@@ -77,6 +77,7 @@
#include <o3tl/typed_flags_set.hxx>
#include <o3tl/string_view.hxx>
#include <unotools/mediadescriptor.hxx>
+#include <unotools/mvc.hxx>
#include <comphelper/multiinterfacecontainer3.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/sequence.hxx>
@@ -3422,11 +3423,7 @@ void AutoRecovery::implts_openOneDoc(const OUString& sURL ,
}
// introduce model/view/controller to each other
- xController->attachModel( xModel );
- xModel->connectController( xController );
- xTargetFrame->setComponent( xController->getComponentWindow(), xController );
- xController->attachFrame( xTargetFrame );
- xModel->setCurrentController( xController );
+ utl::ConnectModelViewController(xModel, xTargetFrame, xController);
}
rInfo.Document = xModel.get();
diff --git a/include/unotools/mvc.hxx b/include/unotools/mvc.hxx
new file mode 100644
index 000000000000..36224b882ecf
--- /dev/null
+++ b/include/unotools/mvc.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <com/sun/star/frame/XController2.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace utl
+{
+inline void ConnectModelController(const css::uno::Reference<css::frame::XModel>& xModel,
+ const css::uno::Reference<css::frame::XController>& xController)
+{
+ xController->attachModel(xModel);
+ xModel->connectController(xController);
+ xModel->setCurrentController(xController);
+}
+
+// Introduce model/view/controller to each other
+inline void
+ConnectModelViewController(const css::uno::Reference<css::frame::XModel>& xModel,
+ const css::uno::Reference<css::frame::XFrame>& xFrame,
+ const css::uno::Reference<css::frame::XController2>& xController)
+{
+ ConnectModelController(xModel, xController);
+ xFrame->setComponent(xController->getComponentWindow(), xController);
+ // creates the view and menu
+ // for correct menu creation the initialized component must be already set into the frame
+ xController->attachFrame(xFrame);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index 41d406e2a1e5..eb33a7e1e5a1 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -58,6 +58,7 @@
#include <svx/view3d.hxx>
#include <svx/scene3d.hxx>
#include <svx/sdmetitm.hxx>
+#include <unotools/mvc.hxx>
using namespace ::com::sun::star;
@@ -149,11 +150,7 @@ sd::DrawDocShellRef SdMiscTest::Load(const OUString& rURL, sal_Int32 nFormat)
CPPUNIT_ASSERT(xController.is());
// introduce model/view/controller to each other
- xController->attachModel(xModel2);
- xModel2->connectController(xController);
- xTargetFrame->setComponent(xController->getComponentWindow(), xController);
- xController->attachFrame(xTargetFrame);
- xModel2->setCurrentController(xController);
+ utl::ConnectModelViewController(xModel2, xTargetFrame, xController);
sd::ViewShell *pViewShell = xDocSh->GetViewShell();
CPPUNIT_ASSERT(pViewShell);
diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx
index 8f369c299bc0..bf9a7b247fbe 100644
--- a/sfx2/source/view/frmload.cxx
+++ b/sfx2/source/view/frmload.cxx
@@ -58,6 +58,7 @@
#include <svl/eitem.hxx>
#include <svl/stritem.hxx>
#include <unotools/moduleoptions.hxx>
+#include <unotools/mvc.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <tools/stream.hxx>
#include <tools/urlobj.hxx>
@@ -580,11 +581,7 @@ Reference< XController2 > SfxFrameLoader_Impl::impl_createDocumentView( const Re
), UNO_SET_THROW );
// introduce model/view/controller to each other
- xController->attachModel( i_rModel );
- i_rModel->connectController( xController );
- i_rFrame->setComponent( xController->getComponentWindow(), xController );
- xController->attachFrame( i_rFrame );
- i_rModel->setCurrentController( xController );
+ utl::ConnectModelViewController(i_rModel, i_rFrame, xController);
return xController;
}