LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/helper - tagwindowasmodified.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 83 88 94.3 %
Date: 2013-07-09 Functions: 13 15 86.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <helper/tagwindowasmodified.hxx>
      21             : #include <pattern/window.hxx>
      22             : #include <threadhelp/writeguard.hxx>
      23             : #include <threadhelp/readguard.hxx>
      24             : #include <macros/generic.hxx>
      25             : #include <services.h>
      26             : 
      27             : #include <com/sun/star/awt/XWindow.hpp>
      28             : 
      29             : #include <com/sun/star/lang/XServiceInfo.hpp>
      30             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      31             : #include <com/sun/star/util/XModifiable.hpp>
      32             : #include <com/sun/star/frame/FrameAction.hpp>
      33             : 
      34             : #include <toolkit/helper/vclunohelper.hxx>
      35             : #include <vcl/window.hxx>
      36             : #include <vcl/syswin.hxx>
      37             : #include <vcl/svapp.hxx>
      38             : #include <vcl/wrkwin.hxx>
      39             : #include <tools/wintypes.hxx>
      40             : 
      41             : 
      42             : namespace framework{
      43             : 
      44             : 
      45             : //*****************************************************************************************************************
      46             : //  XInterface, XTypeProvider
      47             : 
      48      216246 : DEFINE_XINTERFACE_4(TagWindowAsModified                                                     ,
      49             :                     OWeakObject                                                             ,
      50             :                     DIRECT_INTERFACE (css::lang::XTypeProvider                             ),
      51             :                     DIRECT_INTERFACE (css::lang::XInitialization                           ),
      52             :                     DIRECT_INTERFACE (css::util::XModifyListener                           ),
      53             :                     DERIVED_INTERFACE(css::lang::XEventListener, css::util::XModifyListener))
      54             : 
      55           0 : DEFINE_XTYPEPROVIDER_4(TagWindowAsModified        ,
      56             :                        css::lang::XTypeProvider   ,
      57             :                        css::lang::XInitialization ,
      58             :                        css::util::XModifyListener ,
      59             :                        css::lang::XEventListener  )
      60             : 
      61             : //*****************************************************************************************************************
      62        1098 : TagWindowAsModified::TagWindowAsModified()
      63        1098 :     : ThreadHelpBase          (&Application::GetSolarMutex())
      64             : {
      65        1098 : }
      66             : 
      67             : //*****************************************************************************************************************
      68        2182 : TagWindowAsModified::~TagWindowAsModified()
      69             : {
      70        2182 : }
      71             : 
      72             : //*****************************************************************************************************************
      73        1098 : void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
      74             :     throw(css::uno::Exception       ,
      75             :           css::uno::RuntimeException)
      76             : {
      77        1098 :     css::uno::Reference< css::frame::XFrame > xFrame;
      78             : 
      79        1098 :     if (lArguments.getLength() > 0)
      80        1098 :         lArguments[0] >>= xFrame;
      81             : 
      82        1098 :     if ( ! xFrame.is ())
      83        1098 :         return;
      84             : 
      85             :     // SAFE -> ----------------------------------
      86        2196 :     WriteGuard aWriteLock(m_aLock);
      87        1098 :     m_xFrame = xFrame ;
      88        1098 :     aWriteLock.unlock();
      89             :     // <- SAFE ----------------------------------
      90             : 
      91        1098 :     xFrame->addFrameActionListener(this);
      92        2196 :     impl_update (xFrame);
      93             : }
      94             : 
      95             : //*****************************************************************************************************************
      96       26389 : void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
      97             :     throw(css::uno::RuntimeException)
      98             : {
      99             :     // SAFE -> ----------------------------------
     100       26389 :     ReadGuard aReadLock(m_aLock);
     101             : 
     102       52778 :     css::uno::Reference< css::util::XModifiable > xModel (m_xModel.get (), css::uno::UNO_QUERY);
     103       52778 :     css::uno::Reference< css::awt::XWindow >      xWindow(m_xWindow.get(), css::uno::UNO_QUERY);
     104       26389 :     if (
     105       52778 :         ( ! xModel.is  ()       ) ||
     106       52778 :         ( ! xWindow.is ()       ) ||
     107       26389 :         (aEvent.Source != xModel)
     108             :        )
     109           0 :         return;
     110             : 
     111       26389 :     aReadLock.unlock();
     112             :     // <- SAFE ----------------------------------
     113             : 
     114       26389 :     ::sal_Bool bModified = xModel->isModified ();
     115             : 
     116             :     // SYNCHRONIZED ->
     117       52778 :     SolarMutexGuard aSolarGuard;
     118             : 
     119       26389 :     Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
     120       26389 :     if ( ! pWindow)
     121           0 :         return;
     122             : 
     123       26389 :     sal_Bool bSystemWindow = pWindow->IsSystemWindow();
     124       26389 :     sal_Bool bWorkWindow   = (pWindow->GetType() == WINDOW_WORKWINDOW);
     125       26389 :     if (!bSystemWindow && !bWorkWindow)
     126           0 :         return;
     127             : 
     128       26389 :     if (bModified)
     129       25852 :         pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
     130             :     else
     131       26926 :         pWindow->SetExtendedStyle( ! WB_EXT_DOCMODIFIED);
     132             :     // <- SYNCHRONIZED
     133             : }
     134             : 
     135             : //*****************************************************************************************************************
     136        5879 : void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
     137             :     throw(css::uno::RuntimeException)
     138             : {
     139        5879 :     if (
     140       11749 :         (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
     141        5870 :         (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED  )
     142             :        )
     143        9544 :         return;
     144             : 
     145             :     // SAFE -> ----------------------------------
     146        1107 :     WriteGuard aWriteLock(m_aLock);
     147             : 
     148        2214 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     149        1107 :     if (
     150        2214 :         ( ! xFrame.is ()        ) ||
     151        1107 :         (aEvent.Source != xFrame)
     152             :        )
     153           0 :         return;
     154             : 
     155        1107 :     aWriteLock.unlock();
     156             :     // <- SAFE ----------------------------------
     157             : 
     158        2214 :     impl_update (xFrame);
     159             : }
     160             : 
     161             : //*****************************************************************************************************************
     162        2190 : void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
     163             :     throw(css::uno::RuntimeException)
     164             : {
     165             :     // SAFE -> ----------------------------------
     166        2190 :     WriteGuard aWriteLock(m_aLock);
     167             : 
     168        2198 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     169        2190 :     if (
     170        3286 :         (xFrame.is ()           ) &&
     171        1096 :         (aEvent.Source == xFrame)
     172             :        )
     173             :     {
     174        1091 :         m_xFrame = css::uno::Reference< css::frame::XFrame >();
     175        1091 :         return;
     176             :     }
     177             : 
     178        1107 :     css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
     179        1099 :     if (
     180        2190 :         (xModel.is ()           ) &&
     181        1091 :         (aEvent.Source == xModel)
     182             :        )
     183             :     {
     184        1091 :         m_xModel = css::uno::Reference< css::frame::XModel >();
     185        1091 :         return;
     186             :     }
     187             : 
     188          16 :     aWriteLock.unlock();
     189             :     // <- SAFE ----------------------------------
     190             : }
     191             : 
     192             : //*****************************************************************************************************************
     193        2205 : void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
     194             : {
     195        2205 :     if ( ! xFrame.is ())
     196        1099 :         return;
     197             : 
     198        2205 :     css::uno::Reference< css::awt::XWindow >       xWindow     = xFrame->getContainerWindow ();
     199        3311 :     css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
     200        3311 :     css::uno::Reference< css::frame::XModel >      xModel ;
     201        2205 :     if (xController.is ())
     202        1107 :         xModel = xController->getModel ();
     203             : 
     204        2205 :     if (
     205        4410 :         ( ! xWindow.is ()) ||
     206        2205 :         ( ! xModel.is  ())
     207             :        )
     208        1099 :         return;
     209             : 
     210             :     // SAFE -> ----------------------------------
     211        2212 :     WriteGuard aWriteLock(m_aLock);
     212             :     // Note: frame was set as member outside ! we have to refresh connections
     213             :     // regarding window and model only here.
     214        1106 :     m_xWindow = xWindow;
     215        1106 :     m_xModel  = xModel ;
     216        1106 :     aWriteLock.unlock();
     217             :     // <- SAFE ----------------------------------
     218             : 
     219        2212 :     css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
     220        1106 :     if (xModifiable.is ())
     221        2212 :         xModifiable->addModifyListener (this);
     222             : }
     223             : 
     224         402 : } // namespace framework
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10