xref: /aoo42x/main/sw/source/core/unocore/unoevent.cxx (revision efeef26f)
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 	throw( RuntimeException )
154 {
155 	return sImplName;
156 }
157 
copyMacrosFromINetFmt(const SwFmtINetFmt & aFmt)158 void SwHyperlinkEventDescriptor::copyMacrosFromINetFmt(
159 	const SwFmtINetFmt& aFmt)
160 {
161 	for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
162 	{
163 		sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
164 		const SvxMacro* aMacro = aFmt.GetMacro(nEvent);
165 		if (NULL != aMacro)
166 			replaceByName(nEvent, *aMacro);
167 	}
168 }
169 
copyMacrosIntoINetFmt(SwFmtINetFmt & aFmt)170 void SwHyperlinkEventDescriptor::copyMacrosIntoINetFmt(
171 	SwFmtINetFmt& aFmt)
172 {
173 	for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
174 	{
175 		sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
176 		if (hasByName(nEvent))
177 		{
178 			SvxMacro aMacro(sEmpty, sEmpty);
179 			getByName(aMacro, nEvent);
180 			aFmt.SetMacro(nEvent, aMacro);
181 		}
182 	}
183 }
184 
185 
copyMacrosFromNameReplace(uno::Reference<container::XNameReplace> & xReplace)186 void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
187     uno::Reference<
188         container::XNameReplace> & xReplace)
189 {
190 	// iterate over all names (all names that *we* support)
191 	Sequence<OUString> aNames = getElementNames();
192 	sal_Int32 nCount = aNames.getLength();
193 	for(sal_Int32 i = 0; i < nCount; i++)
194 	{
195 		// copy element for that name
196 		const OUString& rName = aNames[i];
197 		if (xReplace->hasByName(rName))
198 		{
199 			SvBaseEventDescriptor::replaceByName(rName,
200 												 xReplace->getByName(rName));
201 		}
202 	}
203 }
204 
205 
206 //
207 // SwFrameEventDescriptor
208 //
209 
210 // use double cast in superclass constructor to avoid ambigous cast
SwFrameEventDescriptor(SwXTextFrame & rFrameRef)211 SwFrameEventDescriptor::SwFrameEventDescriptor(
212 	SwXTextFrame& rFrameRef ) :
213 		SvEventDescriptor((text::XTextFrame&)rFrameRef, aFrameEvents),
214 		sSwFrameEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
215 			sAPI_SwFrameEventDescriptor)),
216 		rFrame(rFrameRef)
217 {
218 }
219 
SwFrameEventDescriptor(SwXTextGraphicObject & rGraphicRef)220 SwFrameEventDescriptor::SwFrameEventDescriptor(
221 	SwXTextGraphicObject& rGraphicRef ) :
222 		SvEventDescriptor((text::XTextContent&)rGraphicRef, aGraphicEvents),
223 		rFrame((SwXFrame&)rGraphicRef)
224 {
225 }
226 
SwFrameEventDescriptor(SwXTextEmbeddedObject & rObjectRef)227 SwFrameEventDescriptor::SwFrameEventDescriptor(
228 	SwXTextEmbeddedObject& rObjectRef ) :
229 		SvEventDescriptor((text::XTextContent&)rObjectRef, aOLEEvents),
230 		rFrame((SwXFrame&)rObjectRef)
231 {
232 }
233 
~SwFrameEventDescriptor()234 SwFrameEventDescriptor::~SwFrameEventDescriptor()
235 {
236 }
237 
setMacroItem(const SvxMacroItem & rItem)238 void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
239 {
240     rFrame.GetFrmFmt()->SetFmtAttr(rItem);
241 }
242 
getMacroItem()243 const SvxMacroItem& SwFrameEventDescriptor::getMacroItem()
244 {
245     return (const SvxMacroItem&)rFrame.GetFrmFmt()->GetFmtAttr(RES_FRMMACRO);
246 }
247 
getMacroItemWhich() const248 sal_uInt16 SwFrameEventDescriptor::getMacroItemWhich() const
249 {
250 	return RES_FRMMACRO;
251 }
252 
getImplementationName()253 OUString SwFrameEventDescriptor::getImplementationName()
254 	throw( RuntimeException )
255 {
256 	return sSwFrameEventDescriptor;
257 }
258 
259 
260 //
261 // SwFrameStyleEventDescriptor
262 //
263 
SwFrameStyleEventDescriptor(SwXFrameStyle & rStyleRef)264 SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
265 	SwXFrameStyle& rStyleRef ) :
266 		SvEventDescriptor((document::XEventsSupplier&)rStyleRef,
267 						  aFrameStyleEvents),
268 		sSwFrameStyleEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
269 			sAPI_SwFrameStyleEventDescriptor)),
270 		rStyle(rStyleRef)
271 {
272 }
273 
~SwFrameStyleEventDescriptor()274 SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
275 {
276 }
277 
setMacroItem(const SvxMacroItem & rItem)278 void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
279 {
280 	// As I was told, for some entirely unobvious reason getting an
281 	// item from a style has to look as follows:
282 	SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
283 	if (pBasePool)
284 	{
285 		SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
286 		if (pBase)
287 		{
288 			rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase ) );
289 			SfxItemSet& rStyleSet = xStyle->GetItemSet();
290 			SfxItemSet aSet(*rStyleSet.GetPool(), RES_FRMMACRO, RES_FRMMACRO);
291 			aSet.Put(rItem);
292 			xStyle->SetItemSet(aSet);
293 		}
294 	}
295 }
296 
297 static const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO);
298 
getMacroItem()299 const SvxMacroItem& SwFrameStyleEventDescriptor::getMacroItem()
300 {
301 	// As I was told, for some entirely unobvious reason getting an
302 	// item from a style has to look as follows:
303 	SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
304 	if (pBasePool)
305 	{
306 		SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
307 		if (pBase)
308 		{
309 			rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase) );
310 			return (const SvxMacroItem&)xStyle->GetItemSet().Get(RES_FRMMACRO);
311 		}
312 		else
313 			return aEmptyMacroItem;
314 	}
315 	else
316 		return aEmptyMacroItem;
317 }
318 
getImplementationName()319 OUString SwFrameStyleEventDescriptor::getImplementationName()
320 	throw( RuntimeException )
321 {
322 	return sSwFrameStyleEventDescriptor;
323 }
324 
getMacroItemWhich() const325 sal_uInt16 SwFrameStyleEventDescriptor::getMacroItemWhich() const
326 {
327 	return RES_FRMMACRO;
328 }
329 
330