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 OUString("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)
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  sSwFrameEventDescriptor("SwFrameEventDescriptor"),
161  rFrame(rFrameRef)
162 {
163 }
164 
166  SwXTextGraphicObject& rGraphicRef ) :
167  SvEventDescriptor(static_cast<text::XTextContent&>(rGraphicRef), aGraphicEvents),
168  rFrame(static_cast<SwXFrame&>(rGraphicRef))
169 {
170 }
171 
173  SwXTextEmbeddedObject& rObjectRef ) :
174  SvEventDescriptor(static_cast<text::XTextContent&>(rObjectRef), aOLEEvents),
175  rFrame(static_cast<SwXFrame&>(rObjectRef))
176 {
177 }
178 
180 {
181 }
182 
184 {
186 }
187 
189 {
191 }
192 
194 {
195  return RES_FRMMACRO;
196 }
197 
199 {
201 }
202 
204  sw::ICoreFrameStyle& rStyle ) :
205  SvEventDescriptor(rStyle.GetEventsSupplier(),
206  aFrameStyleEvents),
207  m_rStyle(rStyle)
208 {
209 }
210 
212 {
213 }
214 
216 {
217  m_rStyle.SetItem(RES_FRMMACRO, rItem);
218 }
219 
221 
223 {
224  const SfxPoolItem* pItem(m_rStyle.GetItem(RES_FRMMACRO));
225  return pItem ? static_cast<const SvxMacroItem&>(*pItem) : aEmptyMacroItem;
226 }
227 
229 {
230  return OUString("SwFrameStyleEventDescriptor");
231 }
232 
234 {
235  return RES_FRMMACRO;
236 }
237 
238 /* 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:151
const SvEventDescription * mpSupportedMacroItems
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:107
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:193
virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem &rItem)=0
SvMacroItemId
sw::ICoreFrameStyle & m_rStyle
Definition: unoevent.hxx:77
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:203
virtual sal_uInt16 getMacroItemWhich() const override
Definition: unoevent.cxx:233
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
OUString const sSwFrameEventDescriptor
Definition: unoevent.hxx:56
int i
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:188
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:183
virtual const SvxMacroItem & getMacroItem() override
Definition: unoevent.cxx:222
const struct SvEventDescription aGraphicEvents[]
Definition: unoevent.cxx:40
SvMacroItemId const mnEvent
virtual OUString SAL_CALL getImplementationName() override
Definition: unoevent.cxx:228
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:460
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:198
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:379
virtual ~SwFrameEventDescriptor() override
Definition: unoevent.cxx:179
def text(shape, st)
virtual ~SwFrameStyleEventDescriptor() override
Definition: unoevent.cxx:211
virtual void setMacroItem(const SvxMacroItem &rItem) override
Definition: unoevent.cxx:215
bool hasById(const SvMacroItemId nEvent) const
#define RES_FRMMACRO
Definition: hintids.hxx:213
const struct SvEventDescription aOLEEvents[]
Definition: unoevent.cxx:65