1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 // HINTIDs must be on top; it is required for the macitem.hxx header
29 #include "hintids.hxx"
30 #include "unoevent.hxx"
31 #include "unoframe.hxx"
32 #include "unostyle.hxx"
33 #include "swevent.hxx"
34 #include "docstyle.hxx"
35 #ifndef _SVX_SVXIDS_HRC
36 #include <svx/svxids.hrc>
37 #endif
38 #include "fmtinfmt.hxx"
39 #include <svl/macitem.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #endif
44
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47
48 using ::com::sun::star::container::NoSuchElementException;
49 using ::com::sun::star::container::XNameReplace;
50 using ::com::sun::star::lang::IllegalArgumentException;
51 using ::com::sun::star::lang::WrappedTargetException;
52 using ::com::sun::star::lang::XServiceInfo;
53 using ::com::sun::star::beans::PropertyValue;
54 using ::cppu::WeakImplHelper2;
55 using ::rtl::OUString;
56 using ::rtl::OUStringBuffer;
57
58
59 const sal_Char sAPI_ServiceName[] = "com.sun.star.container.XNameReplace";
60 const sal_Char sAPI_SwFrameEventDescriptor[] = "SwFrameEventDescriptor";
61 const sal_Char sAPI_SwFrameStyleEventDescriptor[] =
62 "SwFrameStyleEventDescriptor";
63 const sal_Char sAPI_SwDetachedEventDescriptor[] = "SwDetachedEventDescriptor";
64 const sal_Char sAPI_SwHyperlinkEventDescriptor[] =
65 "SwHyperlinkEventDescriptor";
66 const sal_Char sAPI_SwAutoTextEventDescriptor[] =
67 "SwAutoTextEventDescriptor";
68
69 //
70 // tables of allowed events for specific objects
71 //
72
73 const struct SvEventDescription aGraphicEvents[] =
74 {
75 { SW_EVENT_OBJECT_SELECT, "OnSelect" },
76 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
77 { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
78 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
79 { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
80 { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
81 { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
82 { 0, NULL }
83 };
84
85 const struct SvEventDescription aFrameEvents[] =
86 {
87 { SW_EVENT_OBJECT_SELECT, "OnSelect" },
88 { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
89 { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
90 { SW_EVENT_FRM_RESIZE, "OnResize" },
91 { SW_EVENT_FRM_MOVE, "OnMove" },
92 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
93 { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
94 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
95 { 0, NULL }
96 };
97
98 const struct SvEventDescription aOLEEvents[] =
99 {
100 { SW_EVENT_OBJECT_SELECT, "OnSelect" },
101 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
102 { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
103 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
104 { 0, NULL }
105 };
106
107 const struct SvEventDescription aHyperlinkEvents[] =
108 {
109 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
110 { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
111 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
112 { 0, NULL }
113 };
114
115 const struct SvEventDescription aAutotextEvents[] =
116 {
117 { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" },
118 { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" },
119 { 0, NULL }
120 };
121
122 const struct SvEventDescription aFrameStyleEvents[] =
123 {
124 { SW_EVENT_OBJECT_SELECT, "OnSelect" },
125 { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
126 { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
127 { SW_EVENT_FRM_RESIZE, "OnResize" },
128 { SW_EVENT_FRM_MOVE, "OnMove" },
129 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
130 { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
131 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
132 { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
133 { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
134 { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
135 { 0, NULL }
136 };
137
138 //
139 // SwHyperlinkEventDescriptor
140 //
141
SwHyperlinkEventDescriptor()142 SwHyperlinkEventDescriptor::SwHyperlinkEventDescriptor() :
143 SvDetachedEventDescriptor(aHyperlinkEvents),
144 sImplName(RTL_CONSTASCII_USTRINGPARAM(sAPI_SwHyperlinkEventDescriptor))
145 {
146 }
147
~SwHyperlinkEventDescriptor()148 SwHyperlinkEventDescriptor::~SwHyperlinkEventDescriptor()
149 {
150 }
151
getImplementationName(void)152 OUString SwHyperlinkEventDescriptor::getImplementationName(void)
153 {
154 return sImplName;
155 }
156
copyMacrosFromINetFmt(const SwFmtINetFmt & aFmt)157 void SwHyperlinkEventDescriptor::copyMacrosFromINetFmt(
158 const SwFmtINetFmt& aFmt)
159 {
160 for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
161 {
162 sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
163 const SvxMacro* aMacro = aFmt.GetMacro(nEvent);
164 if (NULL != aMacro)
165 replaceByName(nEvent, *aMacro);
166 }
167 }
168
copyMacrosIntoINetFmt(SwFmtINetFmt & aFmt)169 void SwHyperlinkEventDescriptor::copyMacrosIntoINetFmt(
170 SwFmtINetFmt& aFmt)
171 {
172 for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
173 {
174 sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
175 if (hasByName(nEvent))
176 {
177 SvxMacro aMacro(sEmpty, sEmpty);
178 getByName(aMacro, nEvent);
179 aFmt.SetMacro(nEvent, aMacro);
180 }
181 }
182 }
183
184
copyMacrosFromNameReplace(uno::Reference<container::XNameReplace> & xReplace)185 void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
186 uno::Reference<
187 container::XNameReplace> & xReplace)
188 {
189 // iterate over all names (all names that *we* support)
190 Sequence<OUString> aNames = getElementNames();
191 sal_Int32 nCount = aNames.getLength();
192 for(sal_Int32 i = 0; i < nCount; i++)
193 {
194 // copy element for that name
195 const OUString& rName = aNames[i];
196 if (xReplace->hasByName(rName))
197 {
198 SvBaseEventDescriptor::replaceByName(rName,
199 xReplace->getByName(rName));
200 }
201 }
202 }
203
204
205 //
206 // SwFrameEventDescriptor
207 //
208
209 // use double cast in superclass constructor to avoid ambigous cast
SwFrameEventDescriptor(SwXTextFrame & rFrameRef)210 SwFrameEventDescriptor::SwFrameEventDescriptor(
211 SwXTextFrame& rFrameRef ) :
212 SvEventDescriptor((text::XTextFrame&)rFrameRef, aFrameEvents),
213 sSwFrameEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
214 sAPI_SwFrameEventDescriptor)),
215 rFrame(rFrameRef)
216 {
217 }
218
SwFrameEventDescriptor(SwXTextGraphicObject & rGraphicRef)219 SwFrameEventDescriptor::SwFrameEventDescriptor(
220 SwXTextGraphicObject& rGraphicRef ) :
221 SvEventDescriptor((text::XTextContent&)rGraphicRef, aGraphicEvents),
222 rFrame((SwXFrame&)rGraphicRef)
223 {
224 }
225
SwFrameEventDescriptor(SwXTextEmbeddedObject & rObjectRef)226 SwFrameEventDescriptor::SwFrameEventDescriptor(
227 SwXTextEmbeddedObject& rObjectRef ) :
228 SvEventDescriptor((text::XTextContent&)rObjectRef, aOLEEvents),
229 rFrame((SwXFrame&)rObjectRef)
230 {
231 }
232
~SwFrameEventDescriptor()233 SwFrameEventDescriptor::~SwFrameEventDescriptor()
234 {
235 }
236
setMacroItem(const SvxMacroItem & rItem)237 void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
238 {
239 rFrame.GetFrmFmt()->SetFmtAttr(rItem);
240 }
241
getMacroItem()242 const SvxMacroItem& SwFrameEventDescriptor::getMacroItem()
243 {
244 return (const SvxMacroItem&)rFrame.GetFrmFmt()->GetFmtAttr(RES_FRMMACRO);
245 }
246
getMacroItemWhich() const247 sal_uInt16 SwFrameEventDescriptor::getMacroItemWhich() const
248 {
249 return RES_FRMMACRO;
250 }
251
getImplementationName()252 OUString SwFrameEventDescriptor::getImplementationName()
253 {
254 return sSwFrameEventDescriptor;
255 }
256
257
258 //
259 // SwFrameStyleEventDescriptor
260 //
261
SwFrameStyleEventDescriptor(SwXFrameStyle & rStyleRef)262 SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
263 SwXFrameStyle& rStyleRef ) :
264 SvEventDescriptor((document::XEventsSupplier&)rStyleRef,
265 aFrameStyleEvents),
266 sSwFrameStyleEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
267 sAPI_SwFrameStyleEventDescriptor)),
268 rStyle(rStyleRef)
269 {
270 }
271
~SwFrameStyleEventDescriptor()272 SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
273 {
274 }
275
setMacroItem(const SvxMacroItem & rItem)276 void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
277 {
278 // As I was told, for some entirely unobvious reason getting an
279 // item from a style has to look as follows:
280 SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
281 if (pBasePool)
282 {
283 SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
284 if (pBase)
285 {
286 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase ) );
287 SfxItemSet& rStyleSet = xStyle->GetItemSet();
288 SfxItemSet aSet(*rStyleSet.GetPool(), RES_FRMMACRO, RES_FRMMACRO);
289 aSet.Put(rItem);
290 xStyle->SetItemSet(aSet);
291 }
292 }
293 }
294
295 static const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO);
296
getMacroItem()297 const SvxMacroItem& SwFrameStyleEventDescriptor::getMacroItem()
298 {
299 // As I was told, for some entirely unobvious reason getting an
300 // item from a style has to look as follows:
301 SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
302 if (pBasePool)
303 {
304 SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
305 if (pBase)
306 {
307 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase) );
308 return (const SvxMacroItem&)xStyle->GetItemSet().Get(RES_FRMMACRO);
309 }
310 else
311 return aEmptyMacroItem;
312 }
313 else
314 return aEmptyMacroItem;
315 }
316
getImplementationName()317 OUString SwFrameStyleEventDescriptor::getImplementationName()
318 {
319 return sSwFrameStyleEventDescriptor;
320 }
321
getMacroItemWhich() const322 sal_uInt16 SwFrameStyleEventDescriptor::getMacroItemWhich() const
323 {
324 return RES_FRMMACRO;
325 }
326