LCOV - code coverage report
Current view: top level - framework/source/helper - tagwindowasmodified.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 80 83 96.4 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.0 %
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 <macros/generic.hxx>
      23             : #include <services.h>
      24             : 
      25             : #include <com/sun/star/awt/XWindow.hpp>
      26             : 
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      29             : #include <com/sun/star/util/XModifiable.hpp>
      30             : #include <com/sun/star/frame/FrameAction.hpp>
      31             : 
      32             : #include <toolkit/helper/vclunohelper.hxx>
      33             : #include <vcl/window.hxx>
      34             : #include <vcl/syswin.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : #include <vcl/wrkwin.hxx>
      37             : #include <tools/wintypes.hxx>
      38             : 
      39             : namespace framework{
      40             : 
      41        3274 : TagWindowAsModified::TagWindowAsModified()
      42             : {
      43        3274 : }
      44             : 
      45        6528 : TagWindowAsModified::~TagWindowAsModified()
      46             : {
      47        6528 : }
      48             : 
      49        3274 : void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
      50             :     throw(css::uno::Exception       ,
      51             :           css::uno::RuntimeException, std::exception)
      52             : {
      53        3274 :     css::uno::Reference< css::frame::XFrame > xFrame;
      54             : 
      55        3274 :     if (lArguments.getLength() > 0)
      56        3274 :         lArguments[0] >>= xFrame;
      57             : 
      58        3274 :     if ( ! xFrame.is ())
      59        3274 :         return;
      60             : 
      61             :     {
      62        3274 :         SolarMutexGuard g;
      63        3274 :         m_xFrame = xFrame;
      64             :     }
      65             : 
      66        3274 :     xFrame->addFrameActionListener(this);
      67        3274 :     impl_update (xFrame);
      68             : }
      69             : 
      70       83501 : void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
      71             :     throw(css::uno::RuntimeException, std::exception)
      72             : {
      73       83501 :     css::uno::Reference< css::util::XModifiable > xModel;
      74      167001 :     css::uno::Reference< css::awt::XWindow >      xWindow;
      75             :     {
      76       83501 :         SolarMutexGuard g;
      77       83501 :         xModel.set(m_xModel.get (), css::uno::UNO_QUERY);
      78       83501 :         xWindow.set(m_xWindow.get(), css::uno::UNO_QUERY);
      79       83501 :         if (
      80      167002 :             ( ! xModel.is  ()       ) ||
      81      167001 :             ( ! xWindow.is ()       ) ||
      82       83500 :             (aEvent.Source != xModel)
      83             :         )
      84           1 :             return;
      85             :     }
      86             : 
      87       83500 :     bool bModified = xModel->isModified ();
      88             : 
      89             :     // SYNCHRONIZED ->
      90      167000 :     SolarMutexGuard aSolarGuard;
      91             : 
      92       83500 :     vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
      93       83500 :     if ( ! pWindow)
      94           0 :         return;
      95             : 
      96       83500 :     bool bSystemWindow = pWindow->IsSystemWindow();
      97       83500 :     bool bWorkWindow   = (pWindow->GetType() == WINDOW_WORKWINDOW);
      98       83500 :     if (!bSystemWindow && !bWorkWindow)
      99           0 :         return;
     100             : 
     101       83500 :     if (bModified)
     102       82269 :         pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
     103             :     else
     104       84731 :         pWindow->SetExtendedStyle(0);
     105             :     // <- SYNCHRONIZED
     106             : }
     107             : 
     108       18245 : void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
     109             :     throw(css::uno::RuntimeException, std::exception)
     110             : {
     111       18245 :     if (
     112       36474 :         (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
     113       18229 :         (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED  )
     114             :        )
     115       29912 :         return;
     116             : 
     117        3289 :     css::uno::Reference< css::frame::XFrame > xFrame;
     118             :     {
     119        3289 :         SolarMutexGuard g;
     120        3289 :         xFrame.set(m_xFrame.get(), css::uno::UNO_QUERY);
     121        3289 :         if (
     122        6578 :             ( ! xFrame.is ()        ) ||
     123        3289 :             (aEvent.Source != xFrame)
     124             :         )
     125           0 :             return;
     126             :     }
     127             : 
     128        3289 :     impl_update (xFrame);
     129             : }
     130             : 
     131        6545 : void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
     132             :     throw(css::uno::RuntimeException, std::exception)
     133             : {
     134        6545 :     SolarMutexGuard g;
     135             : 
     136        6560 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     137        6545 :     if (
     138        9940 :         (xFrame.is ()           ) &&
     139        3395 :         (aEvent.Source == xFrame)
     140             :        )
     141             :     {
     142        3265 :         m_xFrame = css::uno::Reference< css::frame::XFrame >();
     143        3265 :         return;
     144             :     }
     145             : 
     146        3295 :     css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
     147        3280 :     if (
     148        6545 :         (xModel.is ()           ) &&
     149        3265 :         (aEvent.Source == xModel)
     150             :        )
     151             :     {
     152        3265 :         m_xModel = css::uno::Reference< css::frame::XModel >();
     153        3265 :         return;
     154          15 :     }
     155             : }
     156             : 
     157        6563 : void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
     158             : {
     159        6563 :     if ( ! xFrame.is ())
     160        3275 :         return;
     161             : 
     162        6563 :     css::uno::Reference< css::awt::XWindow >       xWindow     = xFrame->getContainerWindow ();
     163        9851 :     css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
     164        9851 :     css::uno::Reference< css::frame::XModel >      xModel;
     165        6563 :     if (xController.is ())
     166        3289 :         xModel = xController->getModel ();
     167             : 
     168        6563 :     if (
     169       13126 :         ( ! xWindow.is ()) ||
     170        6563 :         ( ! xModel.is  ())
     171             :        )
     172        3275 :         return;
     173             : 
     174             :     {
     175        3288 :         SolarMutexGuard g;
     176             :         // Note: frame was set as member outside ! we have to refresh connections
     177             :         // regarding window and model only here.
     178        3288 :         m_xWindow = xWindow;
     179        3288 :         m_xModel  = xModel;
     180             :     }
     181             : 
     182        6576 :     css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
     183        3288 :     if (xModifiable.is ())
     184        6576 :         xModifiable->addModifyListener (this);
     185             : }
     186             : 
     187             : } // namespace framework
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11