fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / helper / tagwindowasmodified.cxx
blob8048b084d27698513ba37c53aef2f3f07baab127
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 <macros/generic.hxx>
23 #include <services.h>
25 #include <com/sun/star/awt/XWindow.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/util/XModifyBroadcaster.hpp>
29 #include <com/sun/star/util/XModifiable.hpp>
30 #include <com/sun/star/frame/FrameAction.hpp>
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/syswin.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/wrkwin.hxx>
37 #include <tools/wintypes.hxx>
39 namespace framework{
41 TagWindowAsModified::TagWindowAsModified()
45 TagWindowAsModified::~TagWindowAsModified()
49 void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
50 throw(css::uno::Exception ,
51 css::uno::RuntimeException, std::exception)
53 css::uno::Reference< css::frame::XFrame > xFrame;
55 if (lArguments.getLength() > 0)
56 lArguments[0] >>= xFrame;
58 if ( ! xFrame.is ())
59 return;
62 SolarMutexGuard g;
63 m_xFrame = xFrame;
66 xFrame->addFrameActionListener(this);
67 impl_update (xFrame);
70 void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
71 throw(css::uno::RuntimeException, std::exception)
73 css::uno::Reference< css::util::XModifiable > xModel;
74 css::uno::Reference< css::awt::XWindow > xWindow;
76 SolarMutexGuard g;
77 xModel.set(m_xModel.get (), css::uno::UNO_QUERY);
78 xWindow.set(m_xWindow.get(), css::uno::UNO_QUERY);
79 if (
80 ( ! xModel.is () ) ||
81 ( ! xWindow.is () ) ||
82 (aEvent.Source != xModel)
84 return;
87 bool bModified = xModel->isModified ();
89 // SYNCHRONIZED ->
90 SolarMutexGuard aSolarGuard;
92 vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
93 if ( ! pWindow)
94 return;
96 bool bSystemWindow = pWindow->IsSystemWindow();
97 bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW);
98 if (!bSystemWindow && !bWorkWindow)
99 return;
101 if (bModified)
102 pWindow->SetExtendedStyle(WB_EXT_DOCMODIFIED);
103 else
104 pWindow->SetExtendedStyle(0);
105 // <- SYNCHRONIZED
108 void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
109 throw(css::uno::RuntimeException, std::exception)
111 if (
112 (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
113 (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
115 return;
117 css::uno::Reference< css::frame::XFrame > xFrame;
119 SolarMutexGuard g;
120 xFrame.set(m_xFrame.get(), css::uno::UNO_QUERY);
121 if (
122 ( ! xFrame.is () ) ||
123 (aEvent.Source != xFrame)
125 return;
128 impl_update (xFrame);
131 void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
132 throw(css::uno::RuntimeException, std::exception)
134 SolarMutexGuard g;
136 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
137 if (
138 (xFrame.is () ) &&
139 (aEvent.Source == xFrame)
142 m_xFrame = css::uno::Reference< css::frame::XFrame >();
143 return;
146 css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
147 if (
148 (xModel.is () ) &&
149 (aEvent.Source == xModel)
152 m_xModel = css::uno::Reference< css::frame::XModel >();
153 return;
157 void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
159 if ( ! xFrame.is ())
160 return;
162 css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow ();
163 css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
164 css::uno::Reference< css::frame::XModel > xModel;
165 if (xController.is ())
166 xModel = xController->getModel ();
168 if (
169 ( ! xWindow.is ()) ||
170 ( ! xModel.is ())
172 return;
175 SolarMutexGuard g;
176 // Note: frame was set as member outside ! we have to refresh connections
177 // regarding window and model only here.
178 m_xWindow = xWindow;
179 m_xModel = xModel;
182 css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
183 if (xModifiable.is ())
184 xModifiable->addModifyListener (this);
187 } // namespace framework
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */