chart2/source/controller/inc/ChartController.hxx   |   10 +++-
 chart2/source/controller/main/ChartController.cxx  |   18 +++++++
 chart2/source/controller/main/ChartFrameloader.cxx |   15 +-----
 dbaccess/source/filter/xml/dbloader2.cxx           |    8 +--
 dbaccess/source/ui/browser/dbloader.cxx            |    5 --
 framework/source/services/autorecovery.cxx         |    7 --
 include/unotools/mvc.hxx                           |   52 +++++++++++++++++++++
 sd/qa/unit/misc-tests.cxx                          |    7 --
 sfx2/source/view/frmload.cxx                       |    7 --
 9 files changed, 92 insertions(+), 37 deletions(-)

New commits:
commit 876d9d6d333cafc0649abebc757f397faf86fc4d
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Oct 27 22:36:46 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Oct 28 06:31:54 2022 +0200

    Implement css::frame::XController2 in ChartController
    
    ... and use utl::ConnectModelViewController in ChartFrameLoader::load
    
    Change-Id: I9f0dae1b530c05aefdbeeb6a3b3f28d85b0eb14c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141947
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/chart2/source/controller/inc/ChartController.hxx 
b/chart2/source/controller/inc/ChartController.hxx
index ef229ad9abc8..f948e3bc6303 100644
--- a/chart2/source/controller/inc/ChartController.hxx
+++ b/chart2/source/controller/inc/ChartController.hxx
@@ -34,7 +34,7 @@
 #include <com/sun/star/util/XModeChangeListener.hpp>
 #include <com/sun/star/util/XCloseListener.hpp>
 #include <com/sun/star/util/XModifyListener.hpp>
-#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XController2.hpp>
 #include <com/sun/star/frame/XLayoutManagerListener.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -94,7 +94,7 @@ enum ChartDrawMode { CHARTDRAW_INSERT, CHARTDRAW_SELECT };
 
 
 class ChartController final : public ::cppu::WeakImplHelper <
-         css::frame::XController   //comprehends XComponent (required 
interface)
+         css::frame::XController2   //comprehends XComponent 
(css::frame::XController is required interface)
         ,css::frame::XDispatchProvider     //(required interface)
         ,css::view::XSelectionSupplier     //(optional interface)
         ,css::ui::XContextMenuInterception //(optional interface)
@@ -142,6 +142,12 @@ public:
     virtual sal_Bool SAL_CALL
         suspend( sal_Bool bSuspend ) override;
 
+    // css::frame::XController2
+    virtual css::uno::Reference<css::awt::XWindow> SAL_CALL 
getComponentWindow() override;
+    virtual OUString SAL_CALL getViewControllerName() override;
+    virtual css::uno::Sequence<css::beans::PropertyValue> SAL_CALL 
getCreationArguments() override;
+    virtual css::uno::Reference<css::ui::XSidebarProvider> SAL_CALL 
getSidebar() override;
+
     // css::lang::XComponent (base of XController)
     virtual void SAL_CALL
         dispose() override;
diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index bac40f686d51..1a59bb161ec3 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -694,6 +694,24 @@ sal_Bool SAL_CALL ChartController::suspend( sal_Bool 
bSuspend )
     return true;
 }
 
+// css::frame::XController2
+
+css::uno::Reference<css::awt::XWindow> SAL_CALL 
ChartController::getComponentWindow()
+{
+    // it is a special characteristic of ChartController
+    // that it simultaneously provides the XWindow functionality
+    return this;
+}
+
+OUString SAL_CALL ChartController::getViewControllerName() { return {}; }
+
+css::uno::Sequence<css::beans::PropertyValue> SAL_CALL 
ChartController::getCreationArguments()
+{
+    return {};
+}
+
+css::uno::Reference<css::ui::XSidebarProvider> SAL_CALL 
ChartController::getSidebar() { return {}; }
+
 void ChartController::impl_createDrawViewController()
 {
     SolarMutexGuard aGuard;
diff --git a/chart2/source/controller/main/ChartFrameloader.cxx 
b/chart2/source/controller/main/ChartFrameloader.cxx
index 4be01623f8a5..1a3fa8641a6c 100644
--- a/chart2/source/controller/main/ChartFrameloader.cxx
+++ b/chart2/source/controller/main/ChartFrameloader.cxx
@@ -23,6 +23,7 @@
 #include <ChartController.hxx>
 #include <ChartModel.hxx>
 #include <unotools/mediadescriptor.hxx>
+#include <unotools/mvc.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <com/sun/star/frame/XLoadable.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
@@ -104,24 +105,13 @@ sal_Bool SAL_CALL ChartFrameLoader::load( const 
uno::Sequence< beans::PropertyVa
     //create the controller(+XWindow)
     rtl::Reference< ChartController > xController = new ChartController(m_xCC);
 
-    //!!!it is a special characteristic of the example application
-    //that the controller simultaneously provides the XWindow controller 
functionality
-    uno::Reference< awt::XWindow > xComponentWindow = xController;
-
     if( impl_checkCancel() )
         return false;
 
     //connect frame, controller and model one to each other:
     if(xModel.is())
     {
-        xModel->connectController(xController);
-        xModel->setCurrentController(xController);
-        xController->attachModel(xModel);
-        if(xFrame.is())
-            xFrame->setComponent(xComponentWindow,xController);
-        //creates the view and menu
-        //for correct menu creation the initialized component must be already 
set into the frame
-        xController->attachFrame(xFrame);
+        utl::ConnectModelViewController(xModel, xFrame, xController);
     }
 
     // call initNew() or load() at XLoadable
@@ -160,6 +150,7 @@ sal_Bool SAL_CALL ChartFrameLoader::load( const 
uno::Sequence< beans::PropertyVa
                 //resize standalone files to get correct size:
                 if( aMDHelper.ISSET_FilterName && aMDHelper.FilterName == 
"StarChart 5.0" )
                 {
+                    uno::Reference<awt::XWindow> xComponentWindow = 
xController->getComponentWindow();
                     awt::Rectangle aRect( xComponentWindow->getPosSize() );
                     xComponentWindow->setPosSize( aRect.X, aRect.Y, 
aRect.Width, aRect.Height, 0 );
                 }
diff --git a/include/unotools/mvc.hxx b/include/unotools/mvc.hxx
index 36224b882ecf..6c9d65a778d3 100644
--- a/include/unotools/mvc.hxx
+++ b/include/unotools/mvc.hxx
@@ -41,7 +41,8 @@ ConnectModelViewController(const 
css::uno::Reference<css::frame::XModel>& xModel
                            const 
css::uno::Reference<css::frame::XController2>& xController)
 {
     ConnectModelController(xModel, xController);
-    xFrame->setComponent(xController->getComponentWindow(), xController);
+    if (xFrame)
+        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);
commit 16e98d669f2d1dd36c39007daab05a8696b08ebb
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Oct 27 22:17:55 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Oct 28 06:31:41 2022 +0200

    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.kagan...@collabora.com>

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;
 }

Reply via email to