1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tagwindowasmodified.cxx,v $
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 //_________________________________________________________________________________________________________________
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>
44 //_________________________________________________________________________________________________________________
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>
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 //_________________________________________________________________________________________________________________
58 //_________________________________________________________________________________________________________________
60 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
61 #include <toolkit/unohlp.hxx>
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 //_________________________________________________________________________________________________________________
74 //_________________________________________________________________________________________________________________
77 //*****************************************************************************************************************
78 // XInterface, XTypeProvider
80 DEFINE_XINTERFACE_4(TagWindowAsModified
,
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())
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
;
118 // SAFE -> ----------------------------------
119 WriteGuard
aWriteLock(m_aLock
);
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
);
138 ( ! xModel
.is () ) ||
139 ( ! xWindow
.is () ) ||
140 (aEvent
.Source
!= xModel
)
145 // <- SAFE ----------------------------------
147 ::sal_Bool bModified
= xModel
->isModified ();
150 ::vos::OClearableGuard
aSolarGuard(Application::GetSolarMutex());
152 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
156 sal_Bool bSystemWindow
= pWindow
->IsSystemWindow();
157 sal_Bool bWorkWindow
= (pWindow
->GetType() == WINDOW_WORKWINDOW
);
158 if (!bSystemWindow
&& !bWorkWindow
)
162 pWindow
->SetExtendedStyle(WB_EXT_DOCMODIFIED
);
164 pWindow
->SetExtendedStyle( ! WB_EXT_DOCMODIFIED
);
170 //*****************************************************************************************************************
171 void SAL_CALL
TagWindowAsModified::frameAction(const css::frame::FrameActionEvent
& aEvent
)
172 throw(css::uno::RuntimeException
)
175 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_REATTACHED
) &&
176 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_ATTACHED
)
180 // SAFE -> ----------------------------------
181 WriteGuard
aWriteLock(m_aLock
);
183 css::uno::Reference
< css::frame::XFrame
> xFrame(m_xFrame
.get(), css::uno::UNO_QUERY
);
185 ( ! xFrame
.is () ) ||
186 (aEvent
.Source
!= xFrame
)
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
);
206 (aEvent
.Source
== xFrame
)
209 m_xFrame
= css::uno::Reference
< css::frame::XFrame
>();
213 css::uno::Reference
< css::frame::XModel
> xModel(m_xModel
.get(), css::uno::UNO_QUERY
);
216 (aEvent
.Source
== xModel
)
219 m_xModel
= css::uno::Reference
< css::frame::XModel
>();
224 // <- SAFE ----------------------------------
227 //*****************************************************************************************************************
228 void TagWindowAsModified::impl_update (const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
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 ();
240 ( ! xWindow
.is ()) ||
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.
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