1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoevent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 // HINTIDs must be on top; it is required for the macitem.hxx header
36 #include "hintids.hxx"
37 #include "unoevent.hxx"
38 #include "unoframe.hxx"
39 #include "unostyle.hxx"
40 #include "swevent.hxx"
41 #include "docstyle.hxx"
42 #ifndef _SVX_SVXIDS_HRC
43 #include <svx/svxids.hrc>
45 #include "fmtinfmt.hxx"
46 #include <svtools/macitem.hxx>
47 #include <rtl/ustrbuf.hxx>
48 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP
49 #include <com/sun/star/beans/PropertyValue.hpp>
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::uno
;
55 using ::com::sun::star::container::NoSuchElementException
;
56 using ::com::sun::star::container::XNameReplace
;
57 using ::com::sun::star::lang::IllegalArgumentException
;
58 using ::com::sun::star::lang::WrappedTargetException
;
59 using ::com::sun::star::lang::XServiceInfo
;
60 using ::com::sun::star::beans::PropertyValue
;
61 using ::cppu::WeakImplHelper2
;
62 using ::rtl::OUString
;
63 using ::rtl::OUStringBuffer
;
66 const sal_Char sAPI_ServiceName
[] = "com.sun.star.container.XNameReplace";
67 const sal_Char sAPI_SwFrameEventDescriptor
[] = "SwFrameEventDescriptor";
68 const sal_Char sAPI_SwFrameStyleEventDescriptor
[] =
69 "SwFrameStyleEventDescriptor";
70 const sal_Char sAPI_SwDetachedEventDescriptor
[] = "SwDetachedEventDescriptor";
71 const sal_Char sAPI_SwHyperlinkEventDescriptor
[] =
72 "SwHyperlinkEventDescriptor";
73 const sal_Char sAPI_SwAutoTextEventDescriptor
[] =
74 "SwAutoTextEventDescriptor";
77 // tables of allowed events for specific objects
80 const struct SvEventDescription aGraphicEvents
[] =
82 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
83 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
84 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
85 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
86 { SVX_EVENT_IMAGE_LOAD
, "OnLoadDone" },
87 { SVX_EVENT_IMAGE_ABORT
, "OnLoadCancel" },
88 { SVX_EVENT_IMAGE_ERROR
, "OnLoadError" },
92 const struct SvEventDescription aFrameEvents
[] =
94 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
95 { SW_EVENT_FRM_KEYINPUT_ALPHA
, "OnAlphaCharInput" },
96 { SW_EVENT_FRM_KEYINPUT_NOALPHA
, "OnNonAlphaCharInput" },
97 { SW_EVENT_FRM_RESIZE
, "OnResize" },
98 { SW_EVENT_FRM_MOVE
, "OnMove" },
99 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
100 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
101 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
105 const struct SvEventDescription aOLEEvents
[] =
107 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
108 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
109 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
110 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
114 const struct SvEventDescription aHyperlinkEvents
[] =
116 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
117 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
118 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
122 const struct SvEventDescription aAutotextEvents
[] =
124 { SW_EVENT_START_INS_GLOSSARY
, "OnInsertStart" },
125 { SW_EVENT_END_INS_GLOSSARY
, "OnInsertDone" },
129 const struct SvEventDescription aFrameStyleEvents
[] =
131 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
132 { SW_EVENT_FRM_KEYINPUT_ALPHA
, "OnAlphaCharInput" },
133 { SW_EVENT_FRM_KEYINPUT_NOALPHA
, "OnNonAlphaCharInput" },
134 { SW_EVENT_FRM_RESIZE
, "OnResize" },
135 { SW_EVENT_FRM_MOVE
, "OnMove" },
136 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
137 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
138 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
139 { SVX_EVENT_IMAGE_LOAD
, "OnLoadDone" },
140 { SVX_EVENT_IMAGE_ABORT
, "OnLoadCancel" },
141 { SVX_EVENT_IMAGE_ERROR
, "OnLoadError" },
146 // SwHyperlinkEventDescriptor
149 SwHyperlinkEventDescriptor::SwHyperlinkEventDescriptor() :
150 SvDetachedEventDescriptor(aHyperlinkEvents
),
151 sImplName(RTL_CONSTASCII_USTRINGPARAM(sAPI_SwHyperlinkEventDescriptor
))
155 SwHyperlinkEventDescriptor::~SwHyperlinkEventDescriptor()
159 OUString
SwHyperlinkEventDescriptor::getImplementationName(void)
160 throw( RuntimeException
)
165 void SwHyperlinkEventDescriptor::copyMacrosFromINetFmt(
166 const SwFmtINetFmt
& aFmt
)
168 for(sal_Int16 i
= 0; mpSupportedMacroItems
[i
].mnEvent
!= 0; i
++)
170 USHORT nEvent
= mpSupportedMacroItems
[i
].mnEvent
;
171 const SvxMacro
* aMacro
= aFmt
.GetMacro(nEvent
);
173 replaceByName(nEvent
, *aMacro
);
177 void SwHyperlinkEventDescriptor::copyMacrosIntoINetFmt(
180 for(sal_Int16 i
= 0; mpSupportedMacroItems
[i
].mnEvent
!= 0; i
++)
182 USHORT nEvent
= mpSupportedMacroItems
[i
].mnEvent
;
183 if (hasByName(nEvent
))
185 SvxMacro
aMacro(sEmpty
, sEmpty
);
186 getByName(aMacro
, nEvent
);
187 aFmt
.SetMacro(nEvent
, aMacro
);
193 void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
195 container::XNameReplace
> & xReplace
)
197 // iterate over all names (all names that *we* support)
198 Sequence
<OUString
> aNames
= getElementNames();
199 sal_Int32 nCount
= aNames
.getLength();
200 for(sal_Int32 i
= 0; i
< nCount
; i
++)
202 // copy element for that name
203 const OUString
& rName
= aNames
[i
];
204 if (xReplace
->hasByName(rName
))
206 SvBaseEventDescriptor::replaceByName(rName
,
207 xReplace
->getByName(rName
));
214 // SwFrameEventDescriptor
217 // use double cast in superclass constructor to avoid ambigous cast
218 SwFrameEventDescriptor::SwFrameEventDescriptor(
219 SwXTextFrame
& rFrameRef
) :
220 SvEventDescriptor((text::XTextFrame
&)rFrameRef
, aFrameEvents
),
221 sSwFrameEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
222 sAPI_SwFrameEventDescriptor
)),
227 SwFrameEventDescriptor::SwFrameEventDescriptor(
228 SwXTextGraphicObject
& rGraphicRef
) :
229 SvEventDescriptor((text::XTextContent
&)rGraphicRef
, aGraphicEvents
),
230 rFrame((SwXFrame
&)rGraphicRef
)
234 SwFrameEventDescriptor::SwFrameEventDescriptor(
235 SwXTextEmbeddedObject
& rObjectRef
) :
236 SvEventDescriptor((text::XTextContent
&)rObjectRef
, aOLEEvents
),
237 rFrame((SwXFrame
&)rObjectRef
)
241 SwFrameEventDescriptor::~SwFrameEventDescriptor()
245 void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem
& rItem
)
247 rFrame
.GetFrmFmt()->SetFmtAttr(rItem
);
250 const SvxMacroItem
& SwFrameEventDescriptor::getMacroItem()
252 return (const SvxMacroItem
&)rFrame
.GetFrmFmt()->GetFmtAttr(RES_FRMMACRO
);
255 sal_uInt16
SwFrameEventDescriptor::getMacroItemWhich() const
260 OUString
SwFrameEventDescriptor::getImplementationName()
261 throw( RuntimeException
)
263 return sSwFrameEventDescriptor
;
268 // SwFrameStyleEventDescriptor
271 SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
272 SwXFrameStyle
& rStyleRef
) :
273 SvEventDescriptor((document::XEventsSupplier
&)rStyleRef
,
275 sSwFrameStyleEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
276 sAPI_SwFrameStyleEventDescriptor
)),
281 SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
285 void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem
& rItem
)
287 // As I was told, for some entirely unobvious reason getting an
288 // item from a style has to look as follows:
289 SfxStyleSheetBasePool
* pBasePool
= rStyle
.GetBasePool();
292 SfxStyleSheetBase
* pBase
= pBasePool
->Find(rStyle
.GetStyleName());
295 rtl::Reference
< SwDocStyleSheet
> xStyle( new SwDocStyleSheet( *(SwDocStyleSheet
*)pBase
) );
296 SfxItemSet
& rStyleSet
= xStyle
->GetItemSet();
297 SfxItemSet
aSet(*rStyleSet
.GetPool(), RES_FRMMACRO
, RES_FRMMACRO
);
299 xStyle
->SetItemSet(aSet
);
304 static const SvxMacroItem
aEmptyMacroItem(RES_FRMMACRO
);
306 const SvxMacroItem
& SwFrameStyleEventDescriptor::getMacroItem()
308 // As I was told, for some entirely unobvious reason getting an
309 // item from a style has to look as follows:
310 SfxStyleSheetBasePool
* pBasePool
= rStyle
.GetBasePool();
313 SfxStyleSheetBase
* pBase
= pBasePool
->Find(rStyle
.GetStyleName());
316 rtl::Reference
< SwDocStyleSheet
> xStyle( new SwDocStyleSheet( *(SwDocStyleSheet
*)pBase
) );
317 return (const SvxMacroItem
&)xStyle
->GetItemSet().Get(RES_FRMMACRO
);
320 return aEmptyMacroItem
;
323 return aEmptyMacroItem
;
326 OUString
SwFrameStyleEventDescriptor::getImplementationName()
327 throw( RuntimeException
)
329 return sSwFrameStyleEventDescriptor
;
332 sal_uInt16
SwFrameStyleEventDescriptor::getMacroItemWhich() const