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 //_________________________________________________________________________________________________________________
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>
41 //_________________________________________________________________________________________________________________
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>
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 //_________________________________________________________________________________________________________________
55 //_________________________________________________________________________________________________________________
57 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
58 #include <toolkit/unohlp.hxx>
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 //_________________________________________________________________________________________________________________
71 //_________________________________________________________________________________________________________________
74 //*****************************************************************************************************************
75 // XInterface, XTypeProvider
77 DEFINE_XINTERFACE_4(TagWindowAsModified
,
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())
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
;
115 // SAFE -> ----------------------------------
116 WriteGuard
aWriteLock(m_aLock
);
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
);
135 ( ! xModel
.is () ) ||
136 ( ! xWindow
.is () ) ||
137 (aEvent
.Source
!= xModel
)
142 // <- SAFE ----------------------------------
144 ::sal_Bool bModified
= xModel
->isModified ();
147 ::vos::OClearableGuard
aSolarGuard(Application::GetSolarMutex());
149 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
153 sal_Bool bSystemWindow
= pWindow
->IsSystemWindow();
154 sal_Bool bWorkWindow
= (pWindow
->GetType() == WINDOW_WORKWINDOW
);
155 if (!bSystemWindow
&& !bWorkWindow
)
159 pWindow
->SetExtendedStyle(WB_EXT_DOCMODIFIED
);
161 pWindow
->SetExtendedStyle( ! WB_EXT_DOCMODIFIED
);
167 //*****************************************************************************************************************
168 void SAL_CALL
TagWindowAsModified::frameAction(const css::frame::FrameActionEvent
& aEvent
)
169 throw(css::uno::RuntimeException
)
172 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_REATTACHED
) &&
173 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_ATTACHED
)
177 // SAFE -> ----------------------------------
178 WriteGuard
aWriteLock(m_aLock
);
180 css::uno::Reference
< css::frame::XFrame
> xFrame(m_xFrame
.get(), css::uno::UNO_QUERY
);
182 ( ! xFrame
.is () ) ||
183 (aEvent
.Source
!= xFrame
)
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
);
203 (aEvent
.Source
== xFrame
)
206 m_xFrame
= css::uno::Reference
< css::frame::XFrame
>();
210 css::uno::Reference
< css::frame::XModel
> xModel(m_xModel
.get(), css::uno::UNO_QUERY
);
213 (aEvent
.Source
== xModel
)
216 m_xModel
= css::uno::Reference
< css::frame::XModel
>();
221 // <- SAFE ----------------------------------
224 //*****************************************************************************************************************
225 void TagWindowAsModified::impl_update (const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
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 ();
237 ( ! xWindow
.is ()) ||
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.
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