LibreOffice Module framework (master) 1
tagwindowasmodified.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <com/sun/star/awt/XWindow.hpp>
23
24#include <com/sun/star/frame/FrameAction.hpp>
25
27#include <vcl/window.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/wintypes.hxx>
30
31namespace framework{
32
34{
35}
36
38{
39}
40
41void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
42{
43 css::uno::Reference< css::frame::XFrame > xFrame;
44
45 if (lArguments.hasElements())
46 lArguments[0] >>= xFrame;
47
48 if (!xFrame)
49 return;
50
52 xFrame->addFrameActionListener(this);
54}
55
56void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
57{
58 if (!m_xModel || !m_xWindow || aEvent.Source != m_xModel)
59 return;
60
61 bool bModified = m_xModel->isModified ();
62
63 // SYNCHRONIZED ->
64 SolarMutexGuard aSolarGuard;
65
66 if (m_xWindow->isDisposed())
67 return;
68
69 if (bModified)
70 m_xWindow->SetExtendedStyle(WindowExtendedStyle::DocModified);
71 else
72 m_xWindow->SetExtendedStyle(WindowExtendedStyle::NONE);
73 // <- SYNCHRONIZED
74}
75
76void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEvent& aEvent)
77{
78 if (
79 (aEvent.Action != css::frame::FrameAction_COMPONENT_REATTACHED) &&
80 (aEvent.Action != css::frame::FrameAction_COMPONENT_ATTACHED )
81 )
82 return;
83
84 if ( aEvent.Source != m_xFrame )
85 return;
86
88}
89
90void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
91{
93
94 if (m_xFrame && aEvent.Source == m_xFrame)
95 {
96 m_xFrame->removeFrameActionListener(this);
97 m_xFrame.clear();
98 return;
99 }
100
101 if (m_xModel && aEvent.Source == m_xModel)
102 {
103 m_xModel->removeModifyListener(this);
104 m_xModel.clear();
105 return;
106 }
107}
108
109void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
110{
111 if (!xFrame)
112 return;
113
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);
119
120 if (!xWindow || !xModel)
121 return;
122
123 {
125
127 bool bSystemWindow = pWindow->IsSystemWindow();
128 bool bWorkWindow = (pWindow->GetType() == WindowType::WORKWINDOW);
129 if (!bSystemWindow && !bWorkWindow)
130 return;
131
132 if (m_xModel)
133 m_xModel->removeModifyListener (this);
134
135 // Note: frame was set as member outside ! we have to refresh connections
136 // regarding window and model only here.
137 m_xWindow = pWindow;
139 }
140
141 m_xModel->addModifyListener (this);
142}
143
144} // namespace framework
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &aEvent) override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::util::XModifiable > m_xModel
we list on the model for modify events
void impl_update(const css::uno::Reference< css::frame::XFrame > &xFrame)
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &lArguments) override
css::uno::Reference< css::frame::XFrame > m_xFrame
reference to the frame, where we listen for new loaded documents for updating our own xModel referenc...
VclPtr< vcl::Window > m_xWindow
reference to the frame container window, where we must set the tag
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel