merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / helper / tagwindowasmodified.cxx
bloba71c5263455b387f51cded49ba7c6b7a23ec4b42
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
32 // my own includes
33 //_________________________________________________________________________________________________________________
34 #include <helper/tagwindowasmodified.hxx>
35 #include <pattern/window.hxx>
36 #include <threadhelp/writeguard.hxx>
37 #include <threadhelp/readguard.hxx>
38 #include <macros/generic.hxx>
39 #include <services.h>
41 //_________________________________________________________________________________________________________________
42 // interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/awt/XWindow.hpp>
46 #ifndef _COM_SUN_STAR_LANG_XSERVICXEINFO_HPP_
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 #endif
49 #include <com/sun/star/util/XModifyBroadcaster.hpp>
50 #include <com/sun/star/util/XModifiable.hpp>
51 #include <com/sun/star/frame/FrameAction.hpp>
53 //_________________________________________________________________________________________________________________
54 // other includes
55 //_________________________________________________________________________________________________________________
57 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
58 #include <toolkit/unohlp.hxx>
59 #endif
60 #include <vcl/window.hxx>
61 #include <vcl/syswin.hxx>
62 #include <vcl/svapp.hxx>
63 #include <vcl/wrkwin.hxx>
64 #include <vcl/wintypes.hxx>
66 //_________________________________________________________________________________________________________________
67 // namespace
69 namespace framework{
71 //_________________________________________________________________________________________________________________
72 // definitions
74 //*****************************************************************************************************************
75 // XInterface, XTypeProvider
77 DEFINE_XINTERFACE_4(TagWindowAsModified ,
78 OWeakObject ,
79 DIRECT_INTERFACE (css::lang::XTypeProvider ),
80 DIRECT_INTERFACE (css::lang::XInitialization ),
81 DIRECT_INTERFACE (css::util::XModifyListener ),
82 DERIVED_INTERFACE(css::lang::XEventListener, css::util::XModifyListener))
84 DEFINE_XTYPEPROVIDER_4(TagWindowAsModified ,
85 css::lang::XTypeProvider ,
86 css::lang::XInitialization ,
87 css::util::XModifyListener ,
88 css::lang::XEventListener )
90 //*****************************************************************************************************************
91 TagWindowAsModified::TagWindowAsModified(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
92 : ThreadHelpBase (&Application::GetSolarMutex())
93 , m_xSMGR (xSMGR )
97 //*****************************************************************************************************************
98 TagWindowAsModified::~TagWindowAsModified()
102 //*****************************************************************************************************************
103 void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
104 throw(css::uno::Exception ,
105 css::uno::RuntimeException)
107 css::uno::Reference< css::frame::XFrame > xFrame;
109 if (lArguments.getLength() > 0)
110 lArguments[0] >>= xFrame;
112 if ( ! xFrame.is ())
113 return;
115 // SAFE -> ----------------------------------
116 WriteGuard aWriteLock(m_aLock);
117 m_xFrame = xFrame ;
118 aWriteLock.unlock();
119 // <- SAFE ----------------------------------
121 xFrame->addFrameActionListener(this);
122 impl_update (xFrame);
125 //*****************************************************************************************************************
126 void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
127 throw(css::uno::RuntimeException)
129 // SAFE -> ----------------------------------
130 ReadGuard aReadLock(m_aLock);
132 css::uno::Reference< css::util::XModifiable > xModel (m_xModel.get (), css::uno::UNO_QUERY);
133 css::uno::Reference< css::awt::XWindow > xWindow(m_xWindow.get(), css::uno::UNO_QUERY);
134 if (
135 ( ! xModel.is () ) ||
136 ( ! xWindow.is () ) ||
137 (aEvent.Source != xModel)
139 return;
141 aReadLock.unlock();
142 // <- SAFE ----------------------------------
144 ::sal_Bool bModified = xModel->isModified ();
146 // SYNCHRONIZED ->
147 ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
149 Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
150 if ( ! pWindow)
151 return;
153 sal_Bool bSystemWindow = pWindow->IsSystemWindow();
154 sal_Bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW);
155 if (!bSystemWindow && !bWorkWindow)
156 return;
158 if (bModified)
159 pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
160 else
161 pWindow->SetExtendedStyle( ! WB_EXT_DOCMODIFIED);
163 aSolarGuard.clear();
164 // <- SYNCHRONIZED
167 //*****************************************************************************************************************
168 void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
169 throw(css::uno::RuntimeException)
171 if (
172 (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
173 (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
175 return;
177 // SAFE -> ----------------------------------
178 WriteGuard aWriteLock(m_aLock);
180 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
181 if (
182 ( ! xFrame.is () ) ||
183 (aEvent.Source != xFrame)
185 return;
187 aWriteLock.unlock();
188 // <- SAFE ----------------------------------
190 impl_update (xFrame);
193 //*****************************************************************************************************************
194 void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
195 throw(css::uno::RuntimeException)
197 // SAFE -> ----------------------------------
198 WriteGuard aWriteLock(m_aLock);
200 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
201 if (
202 (xFrame.is () ) &&
203 (aEvent.Source == xFrame)
206 m_xFrame = css::uno::Reference< css::frame::XFrame >();
207 return;
210 css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
211 if (
212 (xModel.is () ) &&
213 (aEvent.Source == xModel)
216 m_xModel = css::uno::Reference< css::frame::XModel >();
217 return;
220 aWriteLock.unlock();
221 // <- SAFE ----------------------------------
224 //*****************************************************************************************************************
225 void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
227 if ( ! xFrame.is ())
228 return;
230 css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow ();
231 css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
232 css::uno::Reference< css::frame::XModel > xModel ;
233 if (xController.is ())
234 xModel = xController->getModel ();
236 if (
237 ( ! xWindow.is ()) ||
238 ( ! xModel.is ())
240 return;
242 // SAFE -> ----------------------------------
243 WriteGuard aWriteLock(m_aLock);
244 // Note: frame was set as member outside ! we have to refresh connections
245 // regarding window and model only here.
246 m_xWindow = xWindow;
247 m_xModel = xModel ;
248 aWriteLock.unlock();
249 // <- SAFE ----------------------------------
251 css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
252 if (xModifiable.is ())
253 xModifiable->addModifyListener (this);
256 } // namespace framework