LibreOffice Module sw (master) 1
unoevent.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
20// HINTIDs must be on top; it is required for the macitem.hxx header
21#include <hintids.hxx>
22#include <unoevent.hxx>
23#include <unoframe.hxx>
24#include <unostyle.hxx>
25#include <fmtinfmt.hxx>
26#include <svl/macitem.hxx>
27#include <sfx2/event.hxx>
28
29using namespace ::com::sun::star;
30using namespace ::com::sun::star::uno;
31
32using ::com::sun::star::container::XNameReplace;
33
34// tables of allowed events for specific objects
35
37{
38 { SvMacroItemId::SwObjectSelect, "OnSelect" },
39 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
40 { SvMacroItemId::OnClick, "OnClick" },
41 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
42 { SvMacroItemId::OnImageLoadDone, "OnLoadDone" },
43 { SvMacroItemId::OnImageLoadCancel, "OnLoadCancel" },
44 { SvMacroItemId::OnImageLoadError, "OnLoadError" },
45 { SvMacroItemId::NONE, nullptr }
46};
47
49{
50 { SvMacroItemId::SwObjectSelect, "OnSelect" },
51 { SvMacroItemId::SwFrmKeyInputAlpha, "OnAlphaCharInput" },
52 { SvMacroItemId::SwFrmKeyInputNoAlpha, "OnNonAlphaCharInput" },
53 { SvMacroItemId::SwFrmResize, "OnResize" },
54 { SvMacroItemId::SwFrmMove, "OnMove" },
55 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
56 { SvMacroItemId::OnClick, "OnClick" },
57 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
58 { SvMacroItemId::NONE, nullptr }
59};
60
62{
63 { SvMacroItemId::SwObjectSelect, "OnSelect" },
64 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
65 { SvMacroItemId::OnClick, "OnClick" },
66 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
67 { SvMacroItemId::NONE, nullptr }
68};
69
71{
72 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
73 { SvMacroItemId::OnClick, "OnClick" },
74 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
75 { SvMacroItemId::NONE, nullptr }
76};
77
79{
80 { SvMacroItemId::SwObjectSelect, "OnSelect" },
81 { SvMacroItemId::SwFrmKeyInputAlpha, "OnAlphaCharInput" },
82 { SvMacroItemId::SwFrmKeyInputNoAlpha, "OnNonAlphaCharInput" },
83 { SvMacroItemId::SwFrmResize, "OnResize" },
84 { SvMacroItemId::SwFrmMove, "OnMove" },
85 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
86 { SvMacroItemId::OnClick, "OnClick" },
87 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
88 { SvMacroItemId::OnImageLoadDone, "OnLoadDone" },
89 { SvMacroItemId::OnImageLoadCancel, "OnLoadCancel" },
90 { SvMacroItemId::OnImageLoadError, "OnLoadError" },
91 { SvMacroItemId::NONE, nullptr }
92};
93
96{
97}
98
100{
101}
102
104{
105 return "SwHyperlinkEventDescriptor";
106}
107
109 const SwFormatINetFormat& aFormat)
110{
111 for(sal_uInt16 i = 0; mpSupportedMacroItems[i].mnEvent != SvMacroItemId::NONE; ++i)
112 {
114 const SvxMacro* aMacro = aFormat.GetMacro(nEvent);
115 if (nullptr != aMacro)
116 replaceByName(nEvent, *aMacro);
117 }
118}
119
121 SwFormatINetFormat& aFormat)
122{
123 for(sal_uInt16 i = 0; mpSupportedMacroItems[i].mnEvent != SvMacroItemId::NONE; ++i)
124 {
126 if (hasById(nEvent))
127 {
128 SvxMacro aMacro("", "");
129 getByName(aMacro, nEvent);
130 aFormat.SetMacro(nEvent, aMacro);
131 }
132 }
133}
134
136 uno::Reference<
137 container::XNameReplace> const & xReplace)
138{
139 // iterate over all names (all names that *we* support)
140 const Sequence<OUString> aNames = getElementNames();
141 for(const OUString& rName : aNames)
142 {
143 // copy element for that name
144 if (xReplace->hasByName(rName))
145 {
147 xReplace->getByName(rName));
148 }
149 }
150}
151
152// use double cast in superclass constructor to avoid ambiguous cast
154 SwXTextFrame& rFrameRef ) :
155 SvEventDescriptor(static_cast<text::XTextFrame&>(rFrameRef), aFrameEvents),
156 m_rFrame(rFrameRef)
157{
158}
159
161 SwXTextGraphicObject& rGraphicRef ) :
162 SvEventDescriptor(static_cast<text::XTextContent&>(rGraphicRef), aGraphicEvents),
163 m_rFrame(static_cast<SwXFrame&>(rGraphicRef))
164{
165}
166
168 SwXTextEmbeddedObject& rObjectRef ) :
169 SvEventDescriptor(static_cast<text::XTextContent&>(rObjectRef), aOLEEvents),
170 m_rFrame(static_cast<SwXFrame&>(rObjectRef))
171{
172}
173
175{
176}
177
179{
180 m_rFrame.GetFrameFormat()->SetFormatAttr(rItem);
181}
182
184{
185 return m_rFrame.GetFrameFormat()->GetFormatAttr(RES_FRMMACRO);
186}
187
189{
190 return RES_FRMMACRO;
191}
192
194{
195 return "SwFrameEventDescriptor";
196}
197
199 sw::ICoreFrameStyle& rStyle ) :
200 SvEventDescriptor(rStyle.GetEventsSupplier(),
202 m_rStyle(rStyle)
203{
204}
205
207{
208}
209
211{
213}
214
216
218{
220 return pItem ? static_cast<const SvxMacroItem&>(*pItem) : aEmptyMacroItem;
221}
222
224{
225 return "SwFrameStyleEventDescriptor";
226}
227
229{
230 return RES_FRMMACRO;
231}
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SvEventDescription * mpSupportedMacroItems
virtual void SAL_CALL replaceByName(const OUString &rName, const css::uno::Any &rElement) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
bool hasById(const SvMacroItemId nEvent) const
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
virtual void replaceByName(const SvMacroItemId nEvent, const SvxMacro &rMacro) override
const SvxMacro * GetMacro(SvMacroItemId nEvent) const
Definition: fmtatr2.cxx:269
void SetMacro(SvMacroItemId nEvent, const SvxMacro &rMacro)
Macro getter and setter.
Definition: fmtatr2.cxx:261
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:178
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:193
SwFrameEventDescriptor(SwXTextFrame &rFrameRef)
Definition: unoevent.cxx:153
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:183
virtual ~SwFrameEventDescriptor() override
Definition: unoevent.cxx:174
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:188
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:217
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:228
virtual ~SwFrameStyleEventDescriptor() override
Definition: unoevent.cxx:206
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:210
SwFrameStyleEventDescriptor(sw::ICoreFrameStyle &rStyle)
Definition: unoevent.cxx:198
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:223
sw::ICoreFrameStyle & m_rStyle
Definition: unoevent.hxx:78
virtual ~SwHyperlinkEventDescriptor() override
Definition: unoevent.cxx:99
void copyMacrosIntoINetFormat(SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:120
void copyMacrosFromINetFormat(const SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:108
void copyMacrosFromNameReplace(css::uno::Reference< css::container::XNameReplace > const &xReplace)
Definition: unoevent.cxx:135
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:103
virtual const SfxPoolItem * GetItem(sal_uInt16 eAtr)=0
virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem &rItem)=0
SvMacroItemId
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(114)
def text(shape, orig_st)
int i
SvMacroItemId mnEvent
const struct SvEventDescription aFrameStyleEvents[]
Definition: unoevent.cxx:78
const struct SvEventDescription aFrameEvents[]
Definition: unoevent.cxx:48
const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO)
const struct SvEventDescription aHyperlinkEvents[]
Definition: unoevent.cxx:70
const struct SvEventDescription aGraphicEvents[]
Definition: unoevent.cxx:36
const struct SvEventDescription aOLEEvents[]
Definition: unoevent.cxx:61