Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / helper / tagwindowasmodified.cxx
blob3c40842dd6fa216efcc9fe710112bcb38ccdc4ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <pattern/window.hxx>
22 #include <services.h>
24 #include <com/sun/star/awt/XWindow.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/util/XModifyBroadcaster.hpp>
28 #include <com/sun/star/util/XModifiable.hpp>
29 #include <com/sun/star/frame/FrameAction.hpp>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/syswin.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/wrkwin.hxx>
36 #include <tools/wintypes.hxx>
38 namespace framework{
40 TagWindowAsModified::TagWindowAsModified()
44 TagWindowAsModified::~TagWindowAsModified()
48 void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
50 css::uno::Reference< css::frame::XFrame > xFrame;
52 if (lArguments.hasElements())
53 lArguments[0] >>= xFrame;
55 if ( ! xFrame.is ())
56 return;
59 SolarMutexGuard g;
60 m_xFrame = xFrame;
63 xFrame->addFrameActionListener(this);
64 impl_update (xFrame);
67 void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
69 css::uno::Reference< css::util::XModifiable > xModel;
70 css::uno::Reference< css::awt::XWindow > xWindow;
72 SolarMutexGuard g;
73 xModel.set(m_xModel.get (), css::uno::UNO_QUERY);
74 xWindow.set(m_xWindow.get(), css::uno::UNO_QUERY);
75 if (
76 ( ! xModel.is () ) ||
77 ( ! xWindow.is () ) ||
78 (aEvent.Source != xModel)
80 return;
83 bool bModified = xModel->isModified ();
85 // SYNCHRONIZED ->
86 SolarMutexGuard aSolarGuard;
88 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
89 if ( ! pWindow)
90 return;
92 bool bSystemWindow = pWindow->IsSystemWindow();
93 bool bWorkWindow = (pWindow->GetType() == WindowType::WORKWINDOW);
94 if (!bSystemWindow && !bWorkWindow)
95 return;
97 if (bModified)
98 pWindow->SetExtendedStyle(WindowExtendedStyle::DocModified);
99 else
100 pWindow->SetExtendedStyle(WindowExtendedStyle::NONE);
101 // <- SYNCHRONIZED
104 void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
106 if (
107 (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
108 (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
110 return;
112 css::uno::Reference< css::frame::XFrame > xFrame;
114 SolarMutexGuard g;
115 xFrame.set(m_xFrame.get(), css::uno::UNO_QUERY);
116 if (
117 ( ! xFrame.is () ) ||
118 (aEvent.Source != xFrame)
120 return;
123 impl_update (xFrame);
126 void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
128 SolarMutexGuard g;
130 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
131 if (
132 (xFrame.is () ) &&
133 (aEvent.Source == xFrame)
136 m_xFrame.clear();
137 return;
140 css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
141 if (
142 (xModel.is () ) &&
143 (aEvent.Source == xModel)
146 m_xModel.clear();
147 return;
151 void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
153 if ( ! xFrame.is ())
154 return;
156 css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow ();
157 css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
158 css::uno::Reference< css::frame::XModel > xModel;
159 if (xController.is ())
160 xModel = xController->getModel ();
162 if (
163 ( ! xWindow.is ()) ||
164 ( ! xModel.is ())
166 return;
169 SolarMutexGuard g;
170 // Note: frame was set as member outside ! we have to refresh connections
171 // regarding window and model only here.
172 m_xWindow = xWindow;
173 m_xModel = xModel;
176 css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
177 if (xModifiable.is ())
178 xModifiable->addModifyListener (this);
181 } // namespace framework
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */