1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <helper/tagwindowasmodified.hxx>
22 #include <com/sun/star/awt/XWindow.hpp>
24 #include <com/sun/star/frame/FrameAction.hpp>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <vcl/window.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/wintypes.hxx>
33 TagWindowAsModified::TagWindowAsModified()
37 TagWindowAsModified::~TagWindowAsModified()
41 void SAL_CALL
TagWindowAsModified::initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
43 css::uno::Reference
< css::frame::XFrame
> xFrame
;
45 if (lArguments
.hasElements())
46 lArguments
[0] >>= xFrame
;
52 xFrame
->addFrameActionListener(this);
56 void SAL_CALL
TagWindowAsModified::modified(const css::lang::EventObject
& aEvent
)
58 if (!m_xModel
|| !m_xWindow
|| aEvent
.Source
!= m_xModel
)
61 bool bModified
= m_xModel
->isModified ();
64 SolarMutexGuard aSolarGuard
;
66 if (m_xWindow
->isDisposed())
70 m_xWindow
->SetExtendedStyle(WindowExtendedStyle::DocModified
);
72 m_xWindow
->SetExtendedStyle(WindowExtendedStyle::NONE
);
76 void SAL_CALL
TagWindowAsModified::frameAction(const css::frame::FrameActionEvent
& aEvent
)
79 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_REATTACHED
) &&
80 (aEvent
.Action
!= css::frame::FrameAction_COMPONENT_ATTACHED
)
84 if ( aEvent
.Source
!= m_xFrame
)
87 impl_update (m_xFrame
);
90 void SAL_CALL
TagWindowAsModified::disposing(const css::lang::EventObject
& aEvent
)
94 if (m_xFrame
&& aEvent
.Source
== m_xFrame
)
96 m_xFrame
->removeFrameActionListener(this);
101 if (m_xModel
&& aEvent
.Source
== m_xModel
)
103 m_xModel
->removeModifyListener(this);
109 void TagWindowAsModified::impl_update (const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
114 css::uno::Reference
< css::awt::XWindow
> xWindow
= xFrame
->getContainerWindow ();
115 css::uno::Reference
< css::frame::XController
> xController
= xFrame
->getController ();
116 css::uno::Reference
< css::util::XModifiable
> xModel
;
117 if (xController
.is ())
118 xModel
= css::uno::Reference
< css::util::XModifiable
>(xController
->getModel(), css::uno::UNO_QUERY
);
120 if (!xWindow
|| !xModel
)
126 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(xWindow
);
127 bool bSystemWindow
= pWindow
->IsSystemWindow();
128 bool bWorkWindow
= (pWindow
->GetType() == WindowType::WORKWINDOW
);
129 if (!bSystemWindow
&& !bWorkWindow
)
133 m_xModel
->removeModifyListener (this);
135 // Note: frame was set as member outside ! we have to refresh connections
136 // regarding window and model only here.
141 m_xModel
->addModifyListener (this);
144 } // namespace framework
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */