From 16e98d669f2d1dd36c39007daab05a8696b08ebb Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 27 Oct 2022 22:17:55 +0300 Subject: 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 --- dbaccess/source/filter/xml/dbloader2.cxx | 8 ++--- dbaccess/source/ui/browser/dbloader.cxx | 5 ++- framework/source/services/autorecovery.cxx | 7 ++-- include/unotools/mvc.hxx | 51 ++++++++++++++++++++++++++++++ sd/qa/unit/misc-tests.cxx | 7 ++-- sfx2/source/view/frmload.cxx | 7 ++-- 6 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 include/unotools/mvc.hxx 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 #include #include +#include #include #include @@ -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 #include #include +#include #include 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 #include #include +#include #include #include #include @@ -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 +#include +#include +#include + +namespace utl +{ +inline void ConnectModelController(const css::uno::Reference& xModel, + const css::uno::Reference& xController) +{ + xController->attachModel(xModel); + xModel->connectController(xController); + xModel->setCurrentController(xController); +} + +// Introduce model/view/controller to each other +inline void +ConnectModelViewController(const css::uno::Reference& xModel, + const css::uno::Reference& xFrame, + const css::uno::Reference& 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 #include #include +#include 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 #include #include +#include #include #include #include @@ -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; } -- cgit