Branch data 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 [ + + ][ + - ]: 339077 : 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 : 1743 : TagWindowAsModified::TagWindowAsModified(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
63 [ + - ]: 1743 : : ThreadHelpBase (&Application::GetSolarMutex())
64 [ + - ][ + - ]: 3486 : , m_xSMGR (xSMGR )
[ + - ][ + - ]
65 : : {
66 : 1743 : }
67 : :
68 : : //*****************************************************************************************************************
69 [ + - ][ + - ]: 1650 : TagWindowAsModified::~TagWindowAsModified()
[ + - ][ + - ]
[ + - ]
70 : : {
71 [ - + ]: 3300 : }
72 : :
73 : : //*****************************************************************************************************************
74 : 1743 : void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
75 : : throw(css::uno::Exception ,
76 : : css::uno::RuntimeException)
77 : : {
78 : 1743 : css::uno::Reference< css::frame::XFrame > xFrame;
79 : :
80 [ + - ]: 1743 : if (lArguments.getLength() > 0)
81 [ + - ]: 1743 : lArguments[0] >>= xFrame;
82 : :
83 [ - + ]: 1743 : if ( ! xFrame.is ())
84 : 1743 : return;
85 : :
86 : : // SAFE -> ----------------------------------
87 [ + - ]: 1743 : WriteGuard aWriteLock(m_aLock);
88 [ + - ]: 1743 : m_xFrame = xFrame ;
89 [ + - ]: 1743 : aWriteLock.unlock();
90 : : // <- SAFE ----------------------------------
91 : :
92 [ + - ][ + - ]: 1743 : xFrame->addFrameActionListener(this);
[ + - ]
93 [ + - ][ + - ]: 1743 : impl_update (xFrame);
[ + - ]
94 : : }
95 : :
96 : : //*****************************************************************************************************************
97 : 39130 : void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
98 : : throw(css::uno::RuntimeException)
99 : : {
100 : : // SAFE -> ----------------------------------
101 [ + - ]: 39130 : ReadGuard aReadLock(m_aLock);
102 : :
103 [ + - ][ + - ]: 39130 : css::uno::Reference< css::util::XModifiable > xModel (m_xModel.get (), css::uno::UNO_QUERY);
104 [ + - ][ + - ]: 39130 : css::uno::Reference< css::awt::XWindow > xWindow(m_xWindow.get(), css::uno::UNO_QUERY);
105 [ - + ][ - + ]: 117390 : if (
[ + - + - ]
106 : 39130 : ( ! xModel.is () ) ||
107 : 39130 : ( ! xWindow.is () ) ||
108 [ + - ]: 39130 : (aEvent.Source != xModel)
109 : : )
110 : : return;
111 : :
112 [ + - ]: 39130 : aReadLock.unlock();
113 : : // <- SAFE ----------------------------------
114 : :
115 [ + - ][ + - ]: 39130 : ::sal_Bool bModified = xModel->isModified ();
116 : :
117 : : // SYNCHRONIZED ->
118 [ + - ]: 39130 : SolarMutexGuard aSolarGuard;
119 : :
120 [ + - ]: 39130 : Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
121 [ - + ]: 39130 : if ( ! pWindow)
122 : : return;
123 : :
124 [ + - ]: 39130 : sal_Bool bSystemWindow = pWindow->IsSystemWindow();
125 [ + - ]: 39130 : sal_Bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW);
126 [ - + ][ # # ]: 39130 : if (!bSystemWindow && !bWorkWindow)
127 : : return;
128 : :
129 [ + + ]: 39130 : if (bModified)
130 [ + - ]: 38221 : pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
131 : : else
132 [ + - ][ + - ]: 39130 : pWindow->SetExtendedStyle( ! WB_EXT_DOCMODIFIED);
[ - + ][ - + ]
[ - + ][ + - ]
[ + - ]
133 : : // <- SYNCHRONIZED
134 : : }
135 : :
136 : : //*****************************************************************************************************************
137 : 9575 : void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
138 : : throw(css::uno::RuntimeException)
139 : : {
140 [ + + ][ + + ]: 9575 : if (
141 : : (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
142 : : (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
143 : : )
144 : : return;
145 : :
146 : : // SAFE -> ----------------------------------
147 [ + - ]: 1761 : WriteGuard aWriteLock(m_aLock);
148 : :
149 [ + - ][ + - ]: 1761 : css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
150 [ - + ][ - + ]: 3522 : if (
[ + - ]
151 : 1761 : ( ! xFrame.is () ) ||
152 [ + - ]: 1761 : (aEvent.Source != xFrame)
153 : : )
154 : : return;
155 : :
156 [ + - ]: 1761 : aWriteLock.unlock();
157 : : // <- SAFE ----------------------------------
158 : :
159 [ + - ][ - + ]: 9575 : impl_update (xFrame);
[ + - ][ + - ]
160 : : }
161 : :
162 : : //*****************************************************************************************************************
163 : 3318 : void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
164 : : throw(css::uno::RuntimeException)
165 : : {
166 : : // SAFE -> ----------------------------------
167 [ + - ]: 3318 : WriteGuard aWriteLock(m_aLock);
168 : :
169 [ + - ][ + - ]: 3318 : css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
170 [ + + ][ + + ]: 4978 : if (
[ + + ]
171 : 3318 : (xFrame.is () ) &&
172 [ + - ]: 1660 : (aEvent.Source == xFrame)
173 : : )
174 : : {
175 [ + - ]: 1652 : m_xFrame = css::uno::Reference< css::frame::XFrame >();
176 : : return;
177 : : }
178 : :
179 [ + - ][ + - ]: 1666 : css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
180 [ + - ][ + + ]: 3316 : if (
[ + + ]
181 : 1666 : (xModel.is () ) &&
182 [ + - ]: 1650 : (aEvent.Source == xModel)
183 : : )
184 : : {
185 [ + - ]: 1650 : m_xModel = css::uno::Reference< css::frame::XModel >();
186 : : return;
187 : : }
188 : :
189 [ + - ][ + + ]: 3318 : aWriteLock.unlock();
[ + + ][ + - ]
[ + + ]
190 : : // <- SAFE ----------------------------------
191 : : }
192 : :
193 : : //*****************************************************************************************************************
194 : 3504 : void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
195 : : {
196 [ + - ]: 3504 : if ( ! xFrame.is ())
197 : : return;
198 : :
199 [ + - ][ + - ]: 3504 : css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow ();
200 [ + - ][ + - ]: 3504 : css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
201 : 3504 : css::uno::Reference< css::frame::XModel > xModel ;
202 [ + + ]: 3504 : if (xController.is ())
203 [ + - ][ + - ]: 1761 : xModel = xController->getModel ();
[ + - ]
204 : :
205 [ + + ]: 7008 : if (
[ + - + + ]
206 : 3504 : ( ! xWindow.is ()) ||
207 : 3504 : ( ! xModel.is ())
208 : : )
209 : : return;
210 : :
211 : : // SAFE -> ----------------------------------
212 [ + - ]: 1759 : 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 [ + - ]: 1759 : m_xWindow = xWindow;
216 [ + - ]: 1759 : m_xModel = xModel ;
217 [ + - ]: 1759 : aWriteLock.unlock();
218 : : // <- SAFE ----------------------------------
219 : :
220 [ + - ]: 1759 : css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
221 [ + - ]: 1759 : if (xModifiable.is ())
222 [ + - ][ + - ]: 3504 : xModifiable->addModifyListener (this);
[ + - ][ + - ]
[ + + ][ + + ]
[ + + ]
223 : : }
224 : :
225 : : } // namespace framework
226 : :
227 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|