LCOV - code coverage report
Current view: top level - libreoffice/framework/source/helper - tagwindowasmodified.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 77 97.4 %
Date: 2012-12-27 Functions: 11 13 84.6 %
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/unohlp.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        4480 : 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         240 : TagWindowAsModified::TagWindowAsModified(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      63         240 :     : ThreadHelpBase          (&Application::GetSolarMutex())
      64         480 :     , m_xSMGR                 (xSMGR                        )
      65             : {
      66         240 : }
      67             : 
      68             : //*****************************************************************************************************************
      69         126 : TagWindowAsModified::~TagWindowAsModified()
      70             : {
      71         126 : }
      72             : 
      73             : //*****************************************************************************************************************
      74         240 : void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
      75             :     throw(css::uno::Exception       ,
      76             :           css::uno::RuntimeException)
      77             : {
      78         240 :     css::uno::Reference< css::frame::XFrame > xFrame;
      79             : 
      80         240 :     if (lArguments.getLength() > 0)
      81         240 :         lArguments[0] >>= xFrame;
      82             : 
      83         240 :     if ( ! xFrame.is ())
      84         240 :         return;
      85             : 
      86             :     // SAFE -> ----------------------------------
      87         240 :     WriteGuard aWriteLock(m_aLock);
      88         240 :     m_xFrame = xFrame ;
      89         240 :     aWriteLock.unlock();
      90             :     // <- SAFE ----------------------------------
      91             : 
      92         240 :     xFrame->addFrameActionListener(this);
      93         240 :     impl_update (xFrame);
      94             : }
      95             : 
      96             : //*****************************************************************************************************************
      97          42 : void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
      98             :     throw(css::uno::RuntimeException)
      99             : {
     100             :     // SAFE -> ----------------------------------
     101          42 :     ReadGuard aReadLock(m_aLock);
     102             : 
     103          42 :     css::uno::Reference< css::util::XModifiable > xModel (m_xModel.get (), css::uno::UNO_QUERY);
     104          42 :     css::uno::Reference< css::awt::XWindow >      xWindow(m_xWindow.get(), css::uno::UNO_QUERY);
     105         126 :     if (
     106          42 :         ( ! xModel.is  ()       ) ||
     107          42 :         ( ! xWindow.is ()       ) ||
     108          42 :         (aEvent.Source != xModel)
     109             :        )
     110             :         return;
     111             : 
     112          42 :     aReadLock.unlock();
     113             :     // <- SAFE ----------------------------------
     114             : 
     115          42 :     ::sal_Bool bModified = xModel->isModified ();
     116             : 
     117             :     // SYNCHRONIZED ->
     118          42 :     SolarMutexGuard aSolarGuard;
     119             : 
     120          42 :     Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
     121          42 :     if ( ! pWindow)
     122             :         return;
     123             : 
     124          42 :     sal_Bool bSystemWindow = pWindow->IsSystemWindow();
     125          42 :     sal_Bool bWorkWindow   = (pWindow->GetType() == WINDOW_WORKWINDOW);
     126          42 :     if (!bSystemWindow && !bWorkWindow)
     127             :         return;
     128             : 
     129          42 :     if (bModified)
     130          21 :         pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
     131             :     else
     132          21 :         pWindow->SetExtendedStyle( ! WB_EXT_DOCMODIFIED);
     133             :     // <- SYNCHRONIZED
     134             : }
     135             : 
     136             : //*****************************************************************************************************************
     137        1090 : void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
     138             :     throw(css::uno::RuntimeException)
     139             : {
     140        1090 :     if (
     141             :         (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
     142             :         (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED  )
     143             :        )
     144             :         return;
     145             : 
     146             :     // SAFE -> ----------------------------------
     147         240 :     WriteGuard aWriteLock(m_aLock);
     148             : 
     149         240 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     150         480 :     if (
     151         240 :         ( ! xFrame.is ()        ) ||
     152         240 :         (aEvent.Source != xFrame)
     153             :        )
     154             :         return;
     155             : 
     156         240 :     aWriteLock.unlock();
     157             :     // <- SAFE ----------------------------------
     158             : 
     159         240 :     impl_update (xFrame);
     160             : }
     161             : 
     162             : //*****************************************************************************************************************
     163         126 : void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
     164             :     throw(css::uno::RuntimeException)
     165             : {
     166             :     // SAFE -> ----------------------------------
     167         126 :     WriteGuard aWriteLock(m_aLock);
     168             : 
     169         126 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     170         189 :     if (
     171         126 :         (xFrame.is ()           ) &&
     172          63 :         (aEvent.Source == xFrame)
     173             :        )
     174             :     {
     175          63 :         m_xFrame = css::uno::Reference< css::frame::XFrame >();
     176             :         return;
     177             :     }
     178             : 
     179          63 :     css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
     180         126 :     if (
     181          63 :         (xModel.is ()           ) &&
     182          63 :         (aEvent.Source == xModel)
     183             :        )
     184             :     {
     185          63 :         m_xModel = css::uno::Reference< css::frame::XModel >();
     186             :         return;
     187             :     }
     188             : 
     189           0 :     aWriteLock.unlock();
     190             :     // <- SAFE ----------------------------------
     191             : }
     192             : 
     193             : //*****************************************************************************************************************
     194         480 : void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
     195             : {
     196         480 :     if ( ! xFrame.is ())
     197             :         return;
     198             : 
     199         480 :     css::uno::Reference< css::awt::XWindow >       xWindow     = xFrame->getContainerWindow ();
     200         480 :     css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
     201         480 :     css::uno::Reference< css::frame::XModel >      xModel ;
     202         480 :     if (xController.is ())
     203         240 :         xModel = xController->getModel ();
     204             : 
     205         960 :     if (
     206         480 :         ( ! xWindow.is ()) ||
     207         480 :         ( ! xModel.is  ())
     208             :        )
     209             :         return;
     210             : 
     211             :     // SAFE -> ----------------------------------
     212         240 :     WriteGuard aWriteLock(m_aLock);
     213             :     // Note: frame was set as member outside ! we have to refresh connections
     214             :     // regarding window and model only here.
     215         240 :     m_xWindow = xWindow;
     216         240 :     m_xModel  = xModel ;
     217         240 :     aWriteLock.unlock();
     218             :     // <- SAFE ----------------------------------
     219             : 
     220         240 :     css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
     221         240 :     if (xModifiable.is ())
     222         240 :         xModifiable->addModifyListener (this);
     223             : }
     224             : 
     225             : } // namespace framework
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10