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 
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 
32 using ::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 
95  SvDetachedEventDescriptor(aHyperlinkEvents)
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  rFrame(rFrameRef)
157 {
158 }
159 
161  SwXTextGraphicObject& rGraphicRef ) :
162  SvEventDescriptor(static_cast<text::XTextContent&>(rGraphicRef), aGraphicEvents),
163  rFrame(static_cast<SwXFrame&>(rGraphicRef))
164 {
165 }
166 
168  SwXTextEmbeddedObject& rObjectRef ) :
169  SvEventDescriptor(static_cast<text::XTextContent&>(rObjectRef), aOLEEvents),
170  rFrame(static_cast<SwXFrame&>(rObjectRef))
171 {
172 }
173 
175 {
176 }
177 
179 {
181 }
182 
184 {
186 }
187 
189 {
190  return RES_FRMMACRO;
191 }
192 
194 {
195  return "SwFrameEventDescriptor";
196 }
197 
199  sw::ICoreFrameStyle& rStyle ) :
200  SvEventDescriptor(rStyle.GetEventsSupplier(),
201  aFrameStyleEvents),
202  m_rStyle(rStyle)
203 {
204 }
205 
207 {
208 }
209 
211 {
212  m_rStyle.SetItem(RES_FRMMACRO, rItem);
213 }
214 
216 
218 {
219  const SfxPoolItem* pItem(m_rStyle.GetItem(RES_FRMMACRO));
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: */
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
void copyMacrosIntoINetFormat(SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:120
const SwFrameFormat * GetFrameFormat() const
Definition: unoframe.hxx:152
const SvEventDescription * mpSupportedMacroItems
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:103
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:188
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:251
virtual const SfxPoolItem * GetItem(sal_uInt16 eAtr)=0
void copyMacrosFromNameReplace(css::uno::Reference< css::container::XNameReplace > const &xReplace)
Definition: unoevent.cxx:135
SwFrameEventDescriptor(SwXTextFrame &rFrameRef)
Definition: unoevent.cxx:153
SwFrameStyleEventDescriptor(sw::ICoreFrameStyle &rStyle)
Definition: unoevent.cxx:198
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:228
static const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO)
const struct SvEventDescription aFrameStyleEvents[]
Definition: unoevent.cxx:78
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:70
int i
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:183
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:178
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:217
const struct SvEventDescription aGraphicEvents[]
Definition: unoevent.cxx:36
SvMacroItemId const mnEvent
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:223
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
void copyMacrosFromINetFormat(const SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:108
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
void SetMacro(SvMacroItemId nEvent, const SvxMacro &rMacro)
Macro getter and setter.
Definition: fmtatr2.cxx:243
virtual ~SwHyperlinkEventDescriptor() override
Definition: unoevent.cxx:99
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:193
const struct SvEventDescription aFrameEvents[]
Definition: unoevent.cxx:48
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:174
def text(shape, st)
virtual ~SwFrameStyleEventDescriptor() override
Definition: unoevent.cxx:206
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:210
bool hasById(const SvMacroItemId nEvent) const
#define RES_FRMMACRO
Definition: hintids.hxx:308
const struct SvEventDescription aOLEEvents[]
Definition: unoevent.cxx:61