LCOV - code coverage report
Current view: top level - framework/source/services - backingcomp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 127 189 67.2 %
Date: 2012-08-25 Functions: 16 29 55.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 150 412 36.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "services/backingcomp.hxx"
      31                 :            : 
      32                 :            : #include "backingwindow.hxx"
      33                 :            : 
      34                 :            : #include <threadhelp/readguard.hxx>
      35                 :            : #include <threadhelp/writeguard.hxx>
      36                 :            : #include <classes/droptargetlistener.hxx>
      37                 :            : #include <targets.h>
      38                 :            : #include <properties.h>
      39                 :            : #include <services.h>
      40                 :            : 
      41                 :            : #include <helpid.hrc>
      42                 :            : 
      43                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      44                 :            : #include <com/sun/star/util/XURLTransformer.hpp>
      45                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      46                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      47                 :            : #include <com/sun/star/awt/XDataTransferProviderAccess.hpp>
      48                 :            : #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
      49                 :            : #include <com/sun/star/awt/KeyEvent.hpp>
      50                 :            : #include <com/sun/star/awt/KeyModifier.hpp>
      51                 :            : #include <com/sun/star/frame/XLayoutManager.hpp>
      52                 :            : #include <com/sun/star/util/URLTransformer.hpp>
      53                 :            : 
      54                 :            : #include <comphelper/componentcontext.hxx>
      55                 :            : #include <cppuhelper/typeprovider.hxx>
      56                 :            : #include <cppuhelper/factory.hxx>
      57                 :            : #include <toolkit/helper/vclunohelper.hxx>
      58                 :            : #include <vcl/keycod.hxx>
      59                 :            : #include <vcl/wrkwin.hxx>
      60                 :            : #include <vcl/svapp.hxx>
      61                 :            : #include <rtl/ustrbuf.hxx>
      62                 :            : 
      63                 :            : #include <svl/solar.hrc>
      64                 :            : #include <svl/urihelper.hxx>
      65                 :            : #include <osl/file.hxx>
      66                 :            : #include <unotools/configmgr.hxx>
      67                 :            : 
      68                 :            : #include <unotools/bootstrap.hxx>
      69                 :            : 
      70                 :            : namespace framework
      71                 :            : {
      72                 :            : 
      73                 :            : //_______________________________________________
      74                 :            : 
      75                 :            : //_______________________________________________
      76                 :            : 
      77                 :          2 : BackingComp::BackingComp( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR )
      78         [ +  - ]:          2 :     : ThreadHelpBase    (&Application::GetSolarMutex()                  )
      79         [ +  - ]:          4 :     , m_xSMGR           (xSMGR                                          )
      80                 :            : {
      81                 :          2 : }
      82                 :            : 
      83                 :            : //_______________________________________________
      84                 :            : 
      85 [ +  - ][ +  - ]:          2 : BackingComp::~BackingComp()
      86                 :            : {
      87         [ -  + ]:          4 : }
      88                 :            : 
      89                 :            : //_______________________________________________
      90                 :            : 
      91                 :            : /** return information about supported interfaces.
      92                 :            : 
      93                 :            :     Some interfaces are supported by his class directly, but some other ones are
      94                 :            :     used by aggregation. An instance of this class must provide some window interfaces.
      95                 :            :     But it must represent a VCL window behind such interfaces too! So we use an internal
      96                 :            :     saved window member to ask it for it's interfaces and return it. But we must be aware then,
      97                 :            :     that it can be destroyed from outside too ...
      98                 :            : 
      99                 :            :     @param  aType
     100                 :            :                 describe the required interface type
     101                 :            : 
     102                 :            :     @return An Any holding the instance, which provides the queried interface.
     103                 :            :             Note: There exist two possible results ... this instance itself and her window member!
     104                 :            :  */
     105                 :            : 
     106                 :        142 : css::uno::Any SAL_CALL BackingComp::queryInterface( /*IN*/ const css::uno::Type& aType )
     107                 :            :     throw(css::uno::RuntimeException)
     108                 :            : {
     109                 :        142 :     css::uno::Any aResult;
     110                 :            : 
     111                 :            :     // first look for own supported interfaces
     112                 :            :     aResult = ::cppu::queryInterface(
     113                 :            :                 aType,
     114                 :            :                 static_cast< css::lang::XTypeProvider* >(this),
     115                 :            :                 static_cast< css::lang::XServiceInfo* >(this),
     116                 :            :                 static_cast< css::lang::XInitialization* >(this),
     117                 :            :                 static_cast< css::frame::XController* >(this),
     118                 :            :                 static_cast< css::lang::XComponent* >(this),
     119                 :            :                 static_cast< css::lang::XEventListener* >(this),
     120         [ +  - ]:        142 :                 static_cast< css::awt::XKeyListener* >(static_cast< css::lang::XEventListener* >(this)));
     121                 :            : 
     122                 :            :     // then look for supported window interfaces
     123                 :            :     // Note: They exist only, if this instance was initialized
     124                 :            :     // with a valid window reference. It's aggregation on demand ...
     125         [ +  + ]:        142 :     if (!aResult.hasValue())
     126                 :            :     {
     127                 :            :         /* SAFE { */
     128         [ +  - ]:         72 :         ReadGuard aReadLock(m_aLock);
     129         [ +  + ]:         72 :         if (m_xWindow.is())
     130 [ +  - ][ +  - ]:         70 :             aResult = m_xWindow->queryInterface(aType);
     131 [ +  - ][ +  - ]:         72 :         aReadLock.unlock();
     132                 :            :         /* } SAFE */
     133                 :            :     }
     134                 :            : 
     135                 :            :     // look for XWeak and XInterface
     136         [ +  + ]:        142 :     if (!aResult.hasValue())
     137         [ +  - ]:         66 :         aResult = OWeakObject::queryInterface(aType);
     138                 :            : 
     139                 :        142 :     return aResult;
     140                 :            : }
     141                 :            : 
     142                 :            : //_______________________________________________
     143                 :            : 
     144                 :            : /** increase ref count of this instance.
     145                 :            :  */
     146                 :            : 
     147                 :        300 : void SAL_CALL BackingComp::acquire()
     148                 :            :     throw()
     149                 :            : {
     150                 :        300 :     OWeakObject::acquire();
     151                 :        300 : }
     152                 :            : 
     153                 :            : //_______________________________________________
     154                 :            : 
     155                 :            : /** decrease ref count of this instance.
     156                 :            :  */
     157                 :            : 
     158                 :        300 : void SAL_CALL BackingComp::release()
     159                 :            :     throw()
     160                 :            : {
     161                 :        300 :     OWeakObject::release();
     162                 :        300 : }
     163                 :            : 
     164                 :            : //_______________________________________________
     165                 :            : 
     166                 :            : /** return collection about all supported interfaces.
     167                 :            : 
     168                 :            :     Optimize this method !
     169                 :            :     We initialize a static variable only one time.
     170                 :            :     And we don't must use a mutex at every call!
     171                 :            :     For the first call; pTypeCollection is NULL -
     172                 :            :     for the second call pTypeCollection is different from NULL!
     173                 :            : 
     174                 :            :     @return A list of all supported interface types.
     175                 :            : */
     176                 :            : 
     177                 :          0 : css::uno::Sequence< css::uno::Type > SAL_CALL BackingComp::getTypes()
     178                 :            :     throw(css::uno::RuntimeException)
     179                 :            : {
     180                 :            :     static ::cppu::OTypeCollection* pTypeCollection = NULL;
     181         [ #  # ]:          0 :     if (!pTypeCollection)
     182                 :            :     {
     183                 :            :         /* GLOBAL SAFE { */
     184 [ #  # ][ #  # ]:          0 :         ::osl::MutexGuard aGlobalLock(::osl::Mutex::getGlobalMutex());
     185                 :            :         // Control these pointer again ... it can be, that another instance will be faster then this one!
     186         [ #  # ]:          0 :         if (!pTypeCollection)
     187                 :            :         {
     188                 :            :             /* LOCAL SAFE { */
     189         [ #  # ]:          0 :             ReadGuard aReadLock(m_aLock);
     190         [ #  # ]:          0 :             css::uno::Reference< css::lang::XTypeProvider > xProvider(m_xWindow, css::uno::UNO_QUERY);
     191         [ #  # ]:          0 :             aReadLock.unlock();
     192                 :            :             /* } LOCAL SAFE */
     193                 :            : 
     194         [ #  # ]:          0 :             css::uno::Sequence< css::uno::Type > lWindowTypes;
     195         [ #  # ]:          0 :             if (xProvider.is())
     196 [ #  # ][ #  # ]:          0 :                 lWindowTypes = xProvider->getTypes();
         [ #  # ][ #  # ]
     197                 :            : 
     198                 :            :             static ::cppu::OTypeCollection aTypeCollection(
     199         [ #  # ]:          0 :                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XInitialization >*)NULL ),
     200         [ #  # ]:          0 :                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ),
     201         [ #  # ]:          0 :                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ),
     202         [ #  # ]:          0 :                     ::getCppuType((const ::com::sun::star::uno::Reference< css::frame::XController >*)NULL ),
     203         [ #  # ]:          0 :                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XComponent >*)NULL ),
     204 [ #  # ][ #  # ]:          0 :                     lWindowTypes);
         [ #  # ][ #  # ]
     205                 :            : 
     206 [ #  # ][ #  # ]:          0 :             pTypeCollection = &aTypeCollection;
     207         [ #  # ]:          0 :         }
     208                 :            :         /* } GLOBAL SAFE */
     209                 :            :     }
     210                 :          0 :     return pTypeCollection->getTypes();
     211                 :            : }
     212                 :            : 
     213                 :            : //_______________________________________________
     214                 :            : 
     215                 :            : /** create one unique Id for all instances of this class.
     216                 :            : 
     217                 :            :     Optimize this method
     218                 :            :     We initialize a static variable only one time. And we don't must use a mutex at every call!
     219                 :            :     For the first call; pID is NULL - for the second call pID is different from NULL!
     220                 :            : 
     221                 :            :     @return A byte array, which represent the unique id.
     222                 :            : */
     223                 :            : 
     224                 :          0 : css::uno::Sequence< sal_Int8 > SAL_CALL BackingComp::getImplementationId()
     225                 :            :     throw(css::uno::RuntimeException)
     226                 :            : {
     227                 :            :     static ::cppu::OImplementationId* pID = NULL;
     228         [ #  # ]:          0 :     if (!pID)
     229                 :            :     {
     230                 :            :         /* GLOBAL SAFE { */
     231 [ #  # ][ #  # ]:          0 :         ::osl::MutexGuard aLock(::osl::Mutex::getGlobalMutex());
     232                 :            :         // Control these pointer again ... it can be, that another instance will be faster then this one!
     233         [ #  # ]:          0 :         if (!pID)
     234                 :            :         {
     235 [ #  # ][ #  # ]:          0 :             static ::cppu::OImplementationId aID(sal_False);
     236                 :          0 :             pID = &aID;
     237         [ #  # ]:          0 :         }
     238                 :            :         /* } GLOBAL SAFE */
     239                 :            :     }
     240                 :          0 :     return pID->getImplementationId();
     241                 :            : }
     242                 :            : 
     243                 :            : //_______________________________________________
     244                 :            : 
     245                 :            : /** returns a static implementation name for this UNO service.
     246                 :            : 
     247                 :            :     Because this value is needed at different places and our class is used
     248                 :            :     by some generic macros too, we have to use a static impl method for that!
     249                 :            : 
     250                 :            :     @see impl_getStaticImplementationName()
     251                 :            :     @see IMPLEMENTATIONNAME
     252                 :            : 
     253                 :            :     @return The implementation name of this class.
     254                 :            : */
     255                 :            : 
     256                 :          0 : ::rtl::OUString SAL_CALL BackingComp::getImplementationName()
     257                 :            :     throw(css::uno::RuntimeException)
     258                 :            : {
     259                 :          0 :     return impl_getStaticImplementationName();
     260                 :            : }
     261                 :            : 
     262                 :            : //_______________________________________________
     263                 :            : 
     264                 :            : /** returns information about supported services.
     265                 :            : 
     266                 :            :     Because this value is needed at different places and our class is used
     267                 :            :     by some generic macros too, we have to use a static impl method for that!
     268                 :            : 
     269                 :            :     @see impl_getStaticSupportedServiceNames()
     270                 :            :     @see SERVICENAME
     271                 :            : 
     272                 :            :     @return <TRUE/> if the queried service is supported;
     273                 :            :             <br><FALSE/> otherwise.
     274                 :            : */
     275                 :            : 
     276                 :        240 : sal_Bool SAL_CALL BackingComp::supportsService( /*IN*/ const ::rtl::OUString& sServiceName )
     277                 :            :     throw(css::uno::RuntimeException)
     278                 :            : {
     279                 :            :     return (
     280 [ +  - ][ +  - ]:        480 :             sServiceName.equals(SERVICENAME_STARTMODULE    ) ||
                 [ #  # ]
     281 [ +  - ][ +  + ]:        432 :             sServiceName.equals(SERVICENAME_FRAMECONTROLLER)
                 [ #  # ]
     282   [ +  +  -  + ]:        672 :            );
     283                 :            : }
     284                 :            : 
     285                 :            : //_______________________________________________
     286                 :            : 
     287                 :            : /** returns collection of supported services.
     288                 :            : 
     289                 :            :     Because this value is needed at different places and our class is used
     290                 :            :     by some generic macros too, we have to use a static impl method for that!
     291                 :            : 
     292                 :            :     @see impl_getStaticSupportedServiceNames()
     293                 :            :     @see SERVICENAME
     294                 :            : 
     295                 :            :     @return A list of all supported uno service names.
     296                 :            : */
     297                 :            : 
     298                 :          0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL BackingComp::getSupportedServiceNames()
     299                 :            :     throw(css::uno::RuntimeException)
     300                 :            : {
     301                 :          0 :     return impl_getStaticSupportedServiceNames();
     302                 :            : }
     303                 :            : 
     304                 :            : //_______________________________________________
     305                 :            : 
     306                 :            : /** returns static implementation name.
     307                 :            : 
     308                 :            :     Because this value is needed at different places and our class is used
     309                 :            :     by some generic macros too, we have to use a static impl method for that!
     310                 :            : 
     311                 :            :     @see impl_getStaticSupportedServiceNames()
     312                 :            :     @see SERVICENAME
     313                 :            : 
     314                 :            :     @return The implementation name of this class.
     315                 :            : */
     316                 :            : 
     317                 :       2652 : ::rtl::OUString BackingComp::impl_getStaticImplementationName()
     318                 :            : {
     319                 :       2652 :     return IMPLEMENTATIONNAME_STARTMODULE;
     320                 :            : }
     321                 :            : 
     322                 :            : //_______________________________________________
     323                 :            : 
     324                 :            : /** returns static list of supported service names.
     325                 :            : 
     326                 :            :     Because this value is needed at different places and our class is used
     327                 :            :     by some generic macros too, we have to use a static impl method for that!
     328                 :            : 
     329                 :            :     @see impl_getStaticSupportedServiceNames()
     330                 :            :     @see SERVICENAME
     331                 :            : 
     332                 :            :     @return A list of all supported uno service names.
     333                 :            : */
     334                 :            : 
     335                 :          2 : css::uno::Sequence< ::rtl::OUString > BackingComp::impl_getStaticSupportedServiceNames()
     336                 :            : {
     337                 :          2 :     css::uno::Sequence< ::rtl::OUString > lNames(1);
     338 [ +  - ][ +  - ]:          2 :     lNames[0] = SERVICENAME_STARTMODULE;
     339                 :          2 :     return lNames;
     340                 :            : }
     341                 :            : 
     342                 :            : //_______________________________________________
     343                 :            : 
     344                 :            : /** returns a new instance of this class.
     345                 :            : 
     346                 :            :     This factory method is registered inside the UNO runtime
     347                 :            :     and will be called for every createInstance() request from outside,
     348                 :            :     which wish to use this service.
     349                 :            : 
     350                 :            :     @param  xSMGR
     351                 :            :                 reference to the uno service manager, which call us
     352                 :            :                 We use it too, to set it at the new created instance.
     353                 :            : 
     354                 :            :     @return A new instance as uno reference.
     355                 :            : */
     356                 :            : 
     357                 :          2 : css::uno::Reference< css::uno::XInterface > SAL_CALL BackingComp::impl_createInstance( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
     358                 :            :     throw(css::uno::Exception)
     359                 :            : {
     360         [ +  - ]:          2 :     BackingComp* pObject = new BackingComp(xSMGR);
     361         [ +  - ]:          2 :     return css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(pObject), css::uno::UNO_QUERY);
     362                 :            : }
     363                 :            : 
     364                 :            : //_______________________________________________
     365                 :            : 
     366                 :            : /** returns a new factory instance for instances of this class.
     367                 :            : 
     368                 :            :     It uses a helper class of the cppuhelper project as factory.
     369                 :            :     It will be initialized with all neccessary informations and
     370                 :            :     will be able afterwards to create instance of this class.
     371                 :            :     This factory call us back inside our method impl_createInstance().
     372                 :            :     So we can create and initialize ourself. Only filtering of creation
     373                 :            :     requests will be done by this factory.
     374                 :            : 
     375                 :            :     @param  xSMGR
     376                 :            :                 reference to the uno service manager, which call us
     377                 :            : 
     378                 :            :     @return A new instance of our factory.
     379                 :            : */
     380                 :            : 
     381                 :          2 : css::uno::Reference< css::lang::XSingleServiceFactory > BackingComp::impl_createFactory( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
     382                 :            : {
     383                 :            :     css::uno::Reference< css::lang::XSingleServiceFactory > xReturn(
     384                 :            :         cppu::createSingleFactory(
     385                 :            :             xSMGR,
     386                 :            :             BackingComp::impl_getStaticImplementationName(),
     387                 :            :             BackingComp::impl_createInstance,
     388 [ +  - ][ +  - ]:          2 :             BackingComp::impl_getStaticSupportedServiceNames()));
                 [ +  - ]
     389                 :          2 :     return xReturn;
     390                 :            : }
     391                 :            : 
     392                 :            : //_______________________________________________
     393                 :            : 
     394                 :            : /**
     395                 :            :     attach this component to a target frame.
     396                 :            : 
     397                 :            :     We has to use the container window of this frame as parent window of our own component window.
     398                 :            :     But it's not allowed to work with it realy. May another component used it too.
     399                 :            :     Currently we need it only to create our child component window and support it's
     400                 :            :     interfaces inside our queryInterface() method. The user of us must have e.g. the
     401                 :            :     XWindow interface of it to be able to call setComponent(xWindow,xController) at the
     402                 :            :     frame!
     403                 :            : 
     404                 :            :     May he will do the following things:
     405                 :            : 
     406                 :            :     <listing>
     407                 :            :         XController xBackingComp = (XController)UnoRuntime.queryInterface(
     408                 :            :             XController.class,
     409                 :            :             xSMGR.createInstance(SERVICENAME_STARTMODULE));
     410                 :            : 
     411                 :            :         // at this time XWindow isn't present at this instance!
     412                 :            :         XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
     413                 :            :             XWindow.class,
     414                 :            :             xBackingComp);
     415                 :            : 
     416                 :            :         // attach controller to the frame
     417                 :            :         // We will use it's container window, to create
     418                 :            :         // the component window. From now we offer the window interfaces!
     419                 :            :         xBackingComp.attachFrame(xFrame);
     420                 :            : 
     421                 :            :         XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
     422                 :            :             XWindow.class,
     423                 :            :             xBackingComp);
     424                 :            : 
     425                 :            :         // Our user can set us at the frame as new component
     426                 :            :         xFrame.setComponent(xBackingWin, xBackingComp);
     427                 :            : 
     428                 :            :         // But that had no effect to our view state.
     429                 :            :         // We must be started to create our UI elements like e.g. menu, title, background ...
     430                 :            :         XInitialization xBackingInit = (XInitialization)UnoRuntime.queryInterface(
     431                 :            :             XInitialization.class,
     432                 :            :             xBackingComp);
     433                 :            : 
     434                 :            :         xBackingInit.initialize(lArgs);
     435                 :            :     </listing>
     436                 :            : 
     437                 :            :     @param  xFrame
     438                 :            :                 reference to our new target frame
     439                 :            : 
     440                 :            :     @throw  com::sun::star::uno::RuntimeException
     441                 :            :                 if the given frame reference is wrong or component window couldn't be created
     442                 :            :                 successfully.
     443                 :            :                 We throw it too, if we already attached to a frame. Because we don't support
     444                 :            :                 reparenting of our component window on demand!
     445                 :            : */
     446                 :            : 
     447                 :          2 : void SAL_CALL BackingComp::attachFrame( /*IN*/ const css::uno::Reference< css::frame::XFrame >& xFrame )
     448                 :            :     throw (css::uno::RuntimeException)
     449                 :            : {
     450                 :            :     /* SAFE */
     451         [ +  - ]:          2 :     WriteGuard aWriteLock(m_aLock);
     452                 :            : 
     453                 :            :     // check some required states
     454         [ -  + ]:          2 :     if (m_xFrame.is())
     455                 :            :         throw css::uno::RuntimeException(
     456                 :            :                 ::rtl::OUString("already attached"),
     457 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     458                 :            : 
     459         [ -  + ]:          2 :     if (!xFrame.is())
     460                 :            :         throw css::uno::RuntimeException(
     461                 :            :                 ::rtl::OUString("invalid frame reference"),
     462 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     463                 :            : 
     464         [ -  + ]:          2 :     if (!m_xWindow.is())
     465                 :          2 :         return; // disposed
     466                 :            : 
     467                 :            :     // safe the frame reference
     468         [ +  - ]:          2 :     m_xFrame = xFrame;
     469                 :            : 
     470                 :            :     // establish drag&drop mode
     471         [ +  - ]:          2 :     ::framework::DropTargetListener* pDropListener = new ::framework::DropTargetListener(m_xSMGR, m_xFrame);
     472 [ +  - ][ +  - ]:          2 :     m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >(static_cast< ::cppu::OWeakObject* >(pDropListener), css::uno::UNO_QUERY);
     473                 :            : 
     474 [ +  - ][ +  - ]:          2 :     css::uno::Reference< css::awt::XDataTransferProviderAccess > xTransfer(m_xSMGR->createInstance(SERVICENAME_VCLTOOLKIT), css::uno::UNO_QUERY);
         [ +  - ][ +  - ]
     475         [ +  - ]:          2 :     if (xTransfer.is())
     476                 :            :     {
     477 [ +  - ][ +  - ]:          2 :         css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xTransfer->getDropTarget(m_xWindow);
     478         [ +  - ]:          2 :         if (xDropTarget.is())
     479                 :            :         {
     480 [ +  - ][ +  - ]:          2 :             xDropTarget->addDropTargetListener(m_xDropTargetListener);
     481 [ +  - ][ +  - ]:          2 :             xDropTarget->setActive(sal_True);
     482                 :          2 :         }
     483                 :            :     }
     484                 :            : 
     485                 :            :     // initialize the component and it's parent window
     486 [ +  - ][ +  - ]:          2 :     css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow();
     487         [ +  - ]:          2 :     WorkWindow* pParent = (WorkWindow*)VCLUnoHelper::GetWindow(xParentWindow);
     488         [ +  - ]:          2 :     Window*     pWindow = VCLUnoHelper::GetWindow(m_xWindow);
     489                 :            : 
     490                 :            :     // disable full screen mode of the frame!
     491 [ +  - ][ -  + ]:          2 :     if (pParent && pParent->IsFullScreenMode())
                 [ -  + ]
     492                 :            :     {
     493         [ #  # ]:          0 :         pParent->ShowFullScreenMode(sal_False);
     494         [ #  # ]:          0 :         pParent->SetMenuBarMode(MENUBAR_MODE_NORMAL);
     495                 :            :     }
     496                 :            : 
     497                 :            :     // create the menu bar for the backing component
     498         [ +  - ]:          2 :     css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY_THROW);
     499                 :          2 :     css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     500 [ +  - ][ +  - ]:          2 :     xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
         [ +  - ][ +  - ]
     501         [ +  - ]:          2 :     if (xLayoutManager.is())
     502                 :            :     {
     503 [ +  - ][ +  - ]:          2 :         xLayoutManager->lock();
     504 [ +  - ][ +  - ]:          2 :         xLayoutManager->createElement( DECLARE_ASCII( "private:resource/menubar/menubar"     ));
                 [ +  - ]
     505 [ +  - ][ +  - ]:          2 :         xLayoutManager->unlock();
     506                 :            :     }
     507                 :            : 
     508         [ +  - ]:          2 :     if (pWindow)
     509                 :            :     {
     510                 :            :         // set help ID for our canvas
     511         [ +  - ]:          2 :         pWindow->SetHelpId(HID_BACKINGWINDOW);
     512                 :            :     }
     513                 :            : 
     514                 :            :     // inform BackingWindow about frame
     515         [ -  + ]:          2 :     BackingWindow* pBack = dynamic_cast<BackingWindow*>(pWindow );
     516         [ +  - ]:          2 :     if( pBack )
     517         [ +  - ]:          2 :         pBack->setOwningFrame( m_xFrame );
     518                 :            : 
     519 [ +  - ][ +  - ]:          2 :     aWriteLock.unlock();
                 [ +  - ]
     520                 :            :     /* } SAFE */
     521                 :            : }
     522                 :            : 
     523                 :            : //_______________________________________________
     524                 :            : 
     525                 :            : /** not supported.
     526                 :            : 
     527                 :            :     This component does not know any model. It will be represented by a window and
     528                 :            :     it's controller only.
     529                 :            : 
     530                 :            :     return  <FALSE/> everytime.
     531                 :            :  */
     532                 :            : 
     533                 :          0 : sal_Bool SAL_CALL BackingComp::attachModel( /*IN*/ const css::uno::Reference< css::frame::XModel >& )
     534                 :            :     throw (css::uno::RuntimeException)
     535                 :            : {
     536                 :          0 :     return sal_False;
     537                 :            : }
     538                 :            : 
     539                 :            : //_______________________________________________
     540                 :            : 
     541                 :            : /** not supported.
     542                 :            : 
     543                 :            :     This component does not know any model. It will be represented by a window and
     544                 :            :     it's controller only.
     545                 :            : 
     546                 :            :     return  An empty reference every time.
     547                 :            :  */
     548                 :            : 
     549                 :         86 : css::uno::Reference< css::frame::XModel > SAL_CALL BackingComp::getModel()
     550                 :            :     throw (css::uno::RuntimeException)
     551                 :            : {
     552                 :         86 :     return css::uno::Reference< css::frame::XModel >();
     553                 :            : }
     554                 :            : 
     555                 :            : //_______________________________________________
     556                 :            : 
     557                 :            : /** not supported.
     558                 :            : 
     559                 :            :     return  An empty value.
     560                 :            :  */
     561                 :            : 
     562                 :          0 : css::uno::Any SAL_CALL BackingComp::getViewData()
     563                 :            :     throw (css::uno::RuntimeException)
     564                 :            : {
     565                 :          0 :     return css::uno::Any();
     566                 :            : }
     567                 :            : 
     568                 :            : //_______________________________________________
     569                 :            : 
     570                 :            : /** not supported.
     571                 :            : 
     572                 :            :     @param  aData
     573                 :            :                 not used.
     574                 :            :  */
     575                 :            : 
     576                 :          0 : void SAL_CALL BackingComp::restoreViewData( /*IN*/ const css::uno::Any& )
     577                 :            :     throw (css::uno::RuntimeException)
     578                 :            : {
     579                 :          0 : }
     580                 :            : 
     581                 :            : //_______________________________________________
     582                 :            : 
     583                 :            : /** returns the attached frame for this component.
     584                 :            : 
     585                 :            :     @see    attachFrame()
     586                 :            : 
     587                 :            :     @return The internaly saved frame reference.
     588                 :            :             Can be null, if attachFrame() was not called before.
     589                 :            :  */
     590                 :            : 
     591                 :          0 : css::uno::Reference< css::frame::XFrame > SAL_CALL BackingComp::getFrame()
     592                 :            :     throw (css::uno::RuntimeException)
     593                 :            : {
     594                 :            :     /* SAFE { */
     595         [ #  # ]:          0 :     ReadGuard aReadLock(m_aLock);
     596         [ #  # ]:          0 :     return m_xFrame;
     597                 :            :     /* } SAFE */
     598                 :            : }
     599                 :            : 
     600                 :            : //_______________________________________________
     601                 :            : 
     602                 :            : /** ask controller for it's current working state.
     603                 :            : 
     604                 :            :     If somehwere whish to close this component, it must suspend the controller before.
     605                 :            :     That will be a chance for it to disagree with that AND show any UI for a possible
     606                 :            :     UI user.
     607                 :            : 
     608                 :            :     @param  bSuspend
     609                 :            :                 If its set to sal_True this controller should be suspended.
     610                 :            :                 sal_False will resuspend it.
     611                 :            : 
     612                 :            :     @return sal_True if the request could be finished successfully; sal_False otherwise.
     613                 :            :  */
     614                 :            : 
     615                 :          2 : sal_Bool SAL_CALL BackingComp::suspend( /*IN*/ sal_Bool )
     616                 :            :     throw (css::uno::RuntimeException)
     617                 :            : {
     618                 :            :     /* FIXME ... implemented by using default :-( */
     619                 :          2 :     return sal_True;
     620                 :            : }
     621                 :            : 
     622                 :            : //_______________________________________________
     623                 :            : 
     624                 :            : /** callback from our window member.
     625                 :            : 
     626                 :            :     Our internal saved window wish to die. It will be disposed from outside (may be the frame)
     627                 :            :     and inform us. We must release its reference only here. Of course we check the given reference
     628                 :            :     here and reject callback from unknown sources.
     629                 :            : 
     630                 :            :     Note: deregistration as listener isnt neccessary here. The broadcaster do it automaticly.
     631                 :            : 
     632                 :            :     @param  aEvent
     633                 :            :                 describe the broadcaster of this callback
     634                 :            : 
     635                 :            :     @throw ::com::sun::star::uno::RuntimeException
     636                 :            :                 if the broadcaster doesn't represent the expected window reference.
     637                 :            : */
     638                 :            : 
     639                 :          0 : void SAL_CALL BackingComp::disposing( /*IN*/ const css::lang::EventObject& aEvent )
     640                 :            :     throw(css::uno::RuntimeException)
     641                 :            : {
     642                 :            :     // Attention: dont free m_pAccExec here! see comments inside dtor and
     643                 :            :     // keyPressed() for further details.
     644                 :            : 
     645                 :            :     /* SAFE { */
     646         [ #  # ]:          0 :     WriteGuard aWriteLock(m_aLock);
     647                 :            : 
     648 [ #  # ][ #  # ]:          0 :     if (!aEvent.Source.is() || aEvent.Source!=m_xWindow || !m_xWindow.is())
         [ #  # ][ #  # ]
                 [ #  # ]
     649                 :            :         throw css::uno::RuntimeException(
     650                 :            :                 ::rtl::OUString("unexpected source or called twice"),
     651 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     652                 :            : 
     653         [ #  # ]:          0 :     m_xWindow = css::uno::Reference< css::awt::XWindow >();
     654                 :            : 
     655 [ #  # ][ #  # ]:          0 :     aWriteLock.unlock();
     656                 :            :     /* } SAFE */
     657                 :          0 : }
     658                 :            : 
     659                 :            : //_______________________________________________
     660                 :            : 
     661                 :            : /** kill this instance.
     662                 :            : 
     663                 :            :     It can be called from our owner frame only. But there is no possibility to check the calli.
     664                 :            :     We have to release all our internal used resources and die. From this point we can throw
     665                 :            :     DisposedExceptions for every further interface request ... but current implementation doesn`t do so ...
     666                 :            : 
     667                 :            : */
     668                 :            : 
     669                 :          2 : void SAL_CALL BackingComp::dispose()
     670                 :            :     throw(css::uno::RuntimeException)
     671                 :            : {
     672                 :            :     /* SAFE { */
     673         [ +  - ]:          2 :     WriteGuard aWriteLock(m_aLock);
     674                 :            : 
     675                 :            :     // kill the menu
     676                 :          2 :     css::util::URL aURL;
     677         [ +  - ]:          2 :     aURL.Complete = DECLARE_ASCII(".uno:close");
     678 [ +  - ][ +  - ]:          2 :     css::uno::Reference< css::util::XURLTransformer > xParser(css::util::URLTransformer::create(::comphelper::ComponentContext(m_xSMGR).getUNOContext()));
         [ +  - ][ +  - ]
     679         [ +  - ]:          2 :     if (xParser.is())
     680 [ +  - ][ +  - ]:          2 :         xParser->parseStrict(aURL);
     681                 :            : 
     682         [ +  - ]:          2 :     css::uno::Reference< css::frame::XDispatchProvider > xProvider(m_xFrame, css::uno::UNO_QUERY);
     683         [ +  - ]:          2 :     if (xProvider.is())
     684                 :            :     {
     685 [ +  - ][ +  - ]:          2 :         css::uno::Reference< css::frame::XDispatch > xDispatch = xProvider->queryDispatch(aURL, SPECIALTARGET_MENUBAR, 0);
                 [ +  - ]
     686         [ +  - ]:          2 :         if (xDispatch.is())
     687 [ +  - ][ +  - ]:          2 :             xDispatch->dispatch(aURL, css::uno::Sequence< css::beans::PropertyValue>());
         [ +  - ][ +  - ]
     688                 :            :     }
     689                 :            : 
     690                 :            :     // deregister drag&drop helper
     691         [ +  - ]:          2 :     if (m_xDropTargetListener.is())
     692                 :            :     {
     693 [ +  - ][ +  - ]:          2 :         css::uno::Reference< css::awt::XDataTransferProviderAccess > xTransfer(m_xSMGR->createInstance(SERVICENAME_VCLTOOLKIT), css::uno::UNO_QUERY);
         [ +  - ][ +  - ]
     694         [ +  - ]:          2 :         if (xTransfer.is())
     695                 :            :         {
     696 [ +  - ][ +  - ]:          2 :             css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xTransfer->getDropTarget(m_xWindow);
     697         [ +  - ]:          2 :             if (xDropTarget.is())
     698                 :            :             {
     699 [ +  - ][ +  - ]:          2 :                 xDropTarget->removeDropTargetListener(m_xDropTargetListener);
     700 [ +  - ][ +  - ]:          2 :                 xDropTarget->setActive(sal_False);
     701                 :          2 :             }
     702                 :            :         }
     703         [ +  - ]:          2 :         m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >();
     704                 :            :     }
     705                 :            : 
     706                 :            :     // stop listening at the window
     707         [ +  - ]:          2 :     if (m_xWindow.is())
     708                 :            :     {
     709         [ +  - ]:          2 :         css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
     710         [ +  - ]:          2 :         if (xBroadcaster.is())
     711                 :            :         {
     712         [ +  - ]:          2 :             css::uno::Reference< css::lang::XEventListener > xEventThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
     713 [ +  - ][ +  - ]:          2 :             xBroadcaster->removeEventListener(xEventThis);
     714                 :            :         }
     715         [ +  - ]:          2 :         css::uno::Reference< css::awt::XKeyListener > xKeyThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
     716 [ +  - ][ +  - ]:          2 :         m_xWindow->removeKeyListener(xKeyThis);
     717         [ +  - ]:          2 :         m_xWindow = css::uno::Reference< css::awt::XWindow >();
     718                 :            :     }
     719                 :            : 
     720                 :            :     // forget all other used references
     721         [ +  - ]:          2 :     m_xFrame  = css::uno::Reference< css::frame::XFrame >();
     722         [ +  - ]:          2 :     m_xSMGR   = css::uno::Reference< css::lang::XMultiServiceFactory >();
     723                 :            : 
     724 [ +  - ][ +  - ]:          2 :     aWriteLock.unlock();
     725                 :            :     /* } SAFE */
     726                 :          2 : }
     727                 :            : 
     728                 :            : //_______________________________________________
     729                 :            : 
     730                 :            : /** not supported.
     731                 :            : 
     732                 :            :     @param  xListener
     733                 :            :                 not used.
     734                 :            : 
     735                 :            :     @throw  ::com::sun::star::uno::RuntimeException
     736                 :            :                 because the listener expect to be holded alive by this container.
     737                 :            :                 We must inform it about this unsupported feature.
     738                 :            :  */
     739                 :            : 
     740                 :          0 : void SAL_CALL BackingComp::addEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
     741                 :            :     throw(css::uno::RuntimeException)
     742                 :            : {
     743                 :            :     throw css::uno::RuntimeException(
     744                 :            :             ::rtl::OUString("not supported"),
     745 [ #  # ][ #  # ]:          0 :             static_cast< ::cppu::OWeakObject* >(this));
     746                 :            : }
     747                 :            : 
     748                 :            : //_______________________________________________
     749                 :            : 
     750                 :            : /** not supported.
     751                 :            : 
     752                 :            :     Because registration is not supported too, we must do nothing here. Nobody can call this method realy.
     753                 :            : 
     754                 :            :     @param  xListener
     755                 :            :                 not used.
     756                 :            :  */
     757                 :            : 
     758                 :          0 : void SAL_CALL BackingComp::removeEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
     759                 :            :     throw(css::uno::RuntimeException)
     760                 :            : {
     761                 :          0 : }
     762                 :            : 
     763                 :            : //_______________________________________________
     764                 :            : 
     765                 :            : /**
     766                 :            :     force initialiation for this component.
     767                 :            : 
     768                 :            :     Inside attachFrame() we created our component window. But it was not allowed there, to
     769                 :            :     initialitze it. E.g. the menu must be set at the container window of the frame, which
     770                 :            :     is our parent window. But may at that time another component used it.
     771                 :            :     That's why our creator has to inform us, when it's time to initialize us realy.
     772                 :            :     Currently only calling of this method must be done. But further implementatoins
     773                 :            :     can use special in parameter to configure this initialization ...
     774                 :            : 
     775                 :            :     @param  lArgs
     776                 :            :                 currently not used
     777                 :            : 
     778                 :            :     @throw  com::sun::star::uno::RuntimeException
     779                 :            :                 if some resources are missing
     780                 :            :                 Means if may be attachedFrame() wasn't called before.
     781                 :            :  */
     782                 :            : 
     783                 :          2 : void SAL_CALL BackingComp::initialize( /*IN*/ const css::uno::Sequence< css::uno::Any >& lArgs )
     784                 :            :     throw(css::uno::Exception, css::uno::RuntimeException)
     785                 :            : {
     786                 :            :     /* SAFE { */
     787         [ +  - ]:          2 :     WriteGuard aWriteLock(m_aLock);
     788                 :            : 
     789         [ -  + ]:          2 :     if (m_xWindow.is())
     790                 :            :         throw css::uno::Exception(
     791                 :            :                 ::rtl::OUString("already initialized"),
     792 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     793                 :            : 
     794                 :          2 :     css::uno::Reference< css::awt::XWindow > xParentWindow;
     795   [ +  -  -  + ]:          6 :     if (
         [ -  + ][ +  - ]
     796                 :          2 :         (lArgs.getLength()!=1         ) ||
     797         [ +  - ]:          2 :         (!(lArgs[0] >>= xParentWindow)) ||
     798                 :          2 :         (!xParentWindow.is()          )
     799                 :            :        )
     800                 :            :     {
     801                 :            :         throw css::uno::Exception(
     802                 :            :                 ::rtl::OUString("wrong or corrupt argument list"),
     803 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     804                 :            :     }
     805                 :            : 
     806                 :            :     // create the component window
     807         [ +  - ]:          2 :     Window* pParent   = VCLUnoHelper::GetWindow(xParentWindow);
     808 [ +  - ][ +  - ]:          2 :     Window* pWindow   = new BackingWindow(pParent);
     809 [ +  - ][ +  - ]:          2 :             m_xWindow = VCLUnoHelper::GetInterface(pWindow);
     810                 :            : 
     811         [ -  + ]:          2 :     if (!m_xWindow.is())
     812                 :            :         throw css::uno::RuntimeException(
     813                 :            :                 ::rtl::OUString("couldn't create component window"),
     814 [ #  # ][ #  # ]:          0 :                 static_cast< ::cppu::OWeakObject* >(this));
     815                 :            : 
     816                 :            :     // start listening for window disposing
     817                 :            :     // It's set at our owner frame as component window later too. So it will may be disposed there ...
     818         [ +  - ]:          2 :     css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
     819         [ +  - ]:          2 :     if (xBroadcaster.is())
     820 [ +  - ][ +  - ]:          2 :         xBroadcaster->addEventListener(static_cast< css::lang::XEventListener* >(this));
                 [ +  - ]
     821                 :            : 
     822 [ +  - ][ +  - ]:          2 :     m_xWindow->setVisible(sal_True);
     823                 :            : 
     824 [ +  - ][ +  - ]:          2 :     aWriteLock.unlock();
     825                 :            :     /* } SAFE */
     826                 :          2 : }
     827                 :            : 
     828                 :            : //_______________________________________________
     829                 :            : 
     830                 :            : /**
     831                 :            :  */
     832                 :            : 
     833                 :          0 : void SAL_CALL BackingComp::keyPressed( /*IN*/ const css::awt::KeyEvent&  )
     834                 :            :     throw(css::uno::RuntimeException)
     835                 :            : {
     836                 :          0 : }
     837                 :            : 
     838                 :            : //_______________________________________________
     839                 :            : 
     840                 :            : /**
     841                 :            :  */
     842                 :            : 
     843                 :          0 : void SAL_CALL BackingComp::keyReleased( /*IN*/ const css::awt::KeyEvent& )
     844                 :            :     throw(css::uno::RuntimeException)
     845                 :            : {
     846                 :            :     /* Attention
     847                 :            :         Please use keyPressed() instead of this method. Otherwhise it would be possible, that
     848                 :            :         - a key input may be first switch to the backing mode
     849                 :            :         - and this component register itself as key listener too
     850                 :            :         - and it's first event will be a keyRealeased() for the already well known event, which switched to the backing mode!
     851                 :            :         So it will be handled twice! document => backing mode => exit app ...
     852                 :            :      */
     853                 :          0 : }
     854                 :            : 
     855                 :            : } // namespace framework
     856                 :            : 
     857                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10