merge the formfield patch from ooo-build
[ooovba.git] / framework / source / helper / tagwindowasmodified.cxx
blobea6f7ca1484387651ecf40b0a1ce36020d6e28b4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tagwindowasmodified.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include <helper/tagwindowasmodified.hxx>
38 #include <pattern/window.hxx>
39 #include <threadhelp/writeguard.hxx>
40 #include <threadhelp/readguard.hxx>
41 #include <macros/generic.hxx>
42 #include <services.h>
44 //_________________________________________________________________________________________________________________
45 // interface includes
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/awt/XWindow.hpp>
49 #ifndef _COM_SUN_STAR_LANG_XSERVICXEINFO_HPP_
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 #endif
52 #include <com/sun/star/util/XModifyBroadcaster.hpp>
53 #include <com/sun/star/util/XModifiable.hpp>
54 #include <com/sun/star/frame/FrameAction.hpp>
56 //_________________________________________________________________________________________________________________
57 // other includes
58 //_________________________________________________________________________________________________________________
60 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
61 #include <toolkit/unohlp.hxx>
62 #endif
63 #include <vcl/window.hxx>
64 #include <vcl/syswin.hxx>
65 #include <vcl/svapp.hxx>
66 #include <vcl/wrkwin.hxx>
67 #include <vcl/wintypes.hxx>
69 //_________________________________________________________________________________________________________________
70 // namespace
72 namespace framework{
74 //_________________________________________________________________________________________________________________
75 // definitions
77 //*****************************************************************************************************************
78 // XInterface, XTypeProvider
80 DEFINE_XINTERFACE_4(TagWindowAsModified ,
81 OWeakObject ,
82 DIRECT_INTERFACE (css::lang::XTypeProvider ),
83 DIRECT_INTERFACE (css::lang::XInitialization ),
84 DIRECT_INTERFACE (css::util::XModifyListener ),
85 DERIVED_INTERFACE(css::lang::XEventListener, css::util::XModifyListener))
87 DEFINE_XTYPEPROVIDER_4(TagWindowAsModified ,
88 css::lang::XTypeProvider ,
89 css::lang::XInitialization ,
90 css::util::XModifyListener ,
91 css::lang::XEventListener )
93 //*****************************************************************************************************************
94 TagWindowAsModified::TagWindowAsModified(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
95 : ThreadHelpBase (&Application::GetSolarMutex())
96 , m_xSMGR (xSMGR )
100 //*****************************************************************************************************************
101 TagWindowAsModified::~TagWindowAsModified()
105 //*****************************************************************************************************************
106 void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
107 throw(css::uno::Exception ,
108 css::uno::RuntimeException)
110 css::uno::Reference< css::frame::XFrame > xFrame;
112 if (lArguments.getLength() > 0)
113 lArguments[0] >>= xFrame;
115 if ( ! xFrame.is ())
116 return;
118 // SAFE -> ----------------------------------
119 WriteGuard aWriteLock(m_aLock);
120 m_xFrame = xFrame ;
121 aWriteLock.unlock();
122 // <- SAFE ----------------------------------
124 xFrame->addFrameActionListener(this);
125 impl_update (xFrame);
128 //*****************************************************************************************************************
129 void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
130 throw(css::uno::RuntimeException)
132 // SAFE -> ----------------------------------
133 ReadGuard aReadLock(m_aLock);
135 css::uno::Reference< css::util::XModifiable > xModel (m_xModel.get (), css::uno::UNO_QUERY);
136 css::uno::Reference< css::awt::XWindow > xWindow(m_xWindow.get(), css::uno::UNO_QUERY);
137 if (
138 ( ! xModel.is () ) ||
139 ( ! xWindow.is () ) ||
140 (aEvent.Source != xModel)
142 return;
144 aReadLock.unlock();
145 // <- SAFE ----------------------------------
147 ::sal_Bool bModified = xModel->isModified ();
149 // SYNCHRONIZED ->
150 ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
152 Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
153 if ( ! pWindow)
154 return;
156 sal_Bool bSystemWindow = pWindow->IsSystemWindow();
157 sal_Bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW);
158 if (!bSystemWindow && !bWorkWindow)
159 return;
161 if (bModified)
162 pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
163 else
164 pWindow->SetExtendedStyle( ! WB_EXT_DOCMODIFIED);
166 aSolarGuard.clear();
167 // <- SYNCHRONIZED
170 //*****************************************************************************************************************
171 void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
172 throw(css::uno::RuntimeException)
174 if (
175 (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
176 (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
178 return;
180 // SAFE -> ----------------------------------
181 WriteGuard aWriteLock(m_aLock);
183 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
184 if (
185 ( ! xFrame.is () ) ||
186 (aEvent.Source != xFrame)
188 return;
190 aWriteLock.unlock();
191 // <- SAFE ----------------------------------
193 impl_update (xFrame);
196 //*****************************************************************************************************************
197 void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
198 throw(css::uno::RuntimeException)
200 // SAFE -> ----------------------------------
201 WriteGuard aWriteLock(m_aLock);
203 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
204 if (
205 (xFrame.is () ) &&
206 (aEvent.Source == xFrame)
209 m_xFrame = css::uno::Reference< css::frame::XFrame >();
210 return;
213 css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
214 if (
215 (xModel.is () ) &&
216 (aEvent.Source == xModel)
219 m_xModel = css::uno::Reference< css::frame::XModel >();
220 return;
223 aWriteLock.unlock();
224 // <- SAFE ----------------------------------
227 //*****************************************************************************************************************
228 void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
230 if ( ! xFrame.is ())
231 return;
233 css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow ();
234 css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
235 css::uno::Reference< css::frame::XModel > xModel ;
236 if (xController.is ())
237 xModel = xController->getModel ();
239 if (
240 ( ! xWindow.is ()) ||
241 ( ! xModel.is ())
243 return;
245 // SAFE -> ----------------------------------
246 WriteGuard aWriteLock(m_aLock);
247 // Note: frame was set as member outside ! we have to refresh connections
248 // regarding window and model only here.
249 m_xWindow = xWindow;
250 m_xModel = xModel ;
251 aWriteLock.unlock();
252 // <- SAFE ----------------------------------
254 css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
255 if (xModifiable.is ())
256 xModifiable->addModifyListener (this);
259 } // namespace framework