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