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