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";
78 // // tables of all known events handled by this class
81 // // careful: keep aKnownEventIDs and aKnownEventNames in sync!
83 // const USHORT aKnownEventIDs[] =
85 // SW_EVENT_OBJECT_SELECT,
86 // SW_EVENT_START_INS_GLOSSARY,
87 // SW_EVENT_END_INS_GLOSSARY,
88 // SW_EVENT_MAIL_MERGE,
89 // SW_EVENT_FRM_KEYINPUT_ALPHA,
90 // SW_EVENT_FRM_KEYINPUT_NOALPHA,
91 // SW_EVENT_FRM_RESIZE,
93 // SW_EVENT_PAGE_COUNT,
94 // SFX_EVENT_MOUSEOVER_OBJECT,
95 // SFX_EVENT_MOUSECLICK_OBJECT,
96 // SFX_EVENT_MOUSEOUT_OBJECT,
98 // SFX_EVENT_CLOSEDOC,
99 // SFX_EVENT_STARTAPP,
100 // SFX_EVENT_CLOSEAPP,
101 // SFX_EVENT_CREATEDOC,
102 // SFX_EVENT_SAVEDOC,
103 // SFX_EVENT_SAVEASDOC,
104 // SFX_EVENT_ACTIVATEDOC,
105 // SFX_EVENT_DEACTIVATEDOC,
106 // SFX_EVENT_PRINTDOC,
107 // SFX_EVENT_ONERROR,
108 // SFX_EVENT_LOADFINISHED,
109 // SFX_EVENT_SAVEFINISHED,
110 // SFX_EVENT_MODIFYCHANGED,
111 // SFX_EVENT_PREPARECLOSEDOC,
112 // SFX_EVENT_NEWMESSAGE,
113 // SFX_EVENT_TOGGLEFULLSCREENMODE,
114 // SFX_EVENT_SAVEDOCDONE,
115 // SFX_EVENT_SAVEASDOCDONE,
116 // SVX_EVENT_IMAGE_LOAD,
117 // SVX_EVENT_IMAGE_ABORT,
118 // SVX_EVENT_IMAGE_ERROR,
122 // const sal_Char* aKnownEventNames[] =
124 // "OnSelect", // SW_EVENT_OBJECT_SELECT
125 // "OnInsertStart", // SW_EVENT_START_INS_GLOSSARY
126 // "OnInsertDone", // SW_EVENT_END_INS_GLOSSARY
127 // "OnMailMerge", // SW_EVENT_MAIL_MERGE
128 // "OnAlphaCharInput", // SW_EVENT_FRM_KEYINPUT_ALPHA
129 // "OnNonAlphaCharInput", // SW_EVENT_FRM_KEYINPUT_NOALPHA
130 // "OnResize", // SW_EVENT_FRM_RESIZE
131 // "OnMove", // SW_EVENT_FRM_MOVE
132 // "PageCountChange", // SW_EVENT_PAGE_COUNT
133 // "OnMouseOver", // SFX_EVENT_MOUSEOVER_OBJECT
134 // "OnClick", // SFX_EVENT_MOUSECLICK_OBJECT
135 // "OnMouseOut", // SFX_EVENT_MOUSEOUT_OBJECT
136 // "OnLoad", // SFX_EVENT_OPENDOC,
137 // "OnUnload", // SFX_EVENT_CLOSEDOC,
138 // "OnStartApp", // SFX_EVENT_STARTAPP,
139 // "OnCloseApp", // SFX_EVENT_CLOSEAPP,
140 // "OnNew", // SFX_EVENT_CREATEDOC,
141 // "OnSave", // SFX_EVENT_SAVEDOC,
142 // "OnSaveAs", // SFX_EVENT_SAVEASDOC,
143 // "OnFocus", // SFX_EVENT_ACTIVATEDOC,
144 // "OnUnfocus", // SFX_EVENT_DEACTIVATEDOC,
145 // "OnPrint", // SFX_EVENT_PRINTDOC,
146 // "OnError", // SFX_EVENT_ONERROR,
147 // "OnLoadFinished", // SFX_EVENT_LOADFINISHED,
148 // "OnSaveFinished", // SFX_EVENT_SAVEFINISHED,
149 // "OnModifyChanged", // SFX_EVENT_MODIFYCHANGED,
150 // "OnPrepareUnload", // SFX_EVENT_PREPARECLOSEDOC,
151 // "OnNewMail", // SFX_EVENT_NEWMESSAGE,
152 // "OnToggleFullscreen", // SFX_EVENT_TOGGLEFULLSCREENMODE,
153 // "OnSaveDone", // SFX_EVENT_SAVEDOCDONE,
154 // "OnSaveAsDone", // SFX_EVENT_SAVEASDOCDONE,
155 // "OnLoadError", // SVX_EVENT_IMAGE_LOAD,
156 // "OnLoadCancel", // SVX_EVENT_IMAGE_ABORT,
157 // "OnLoadDone", // SVX_EVENT_IMAGE_ERROR,
164 // tables of allowed events for specific objects
167 const struct SvEventDescription aGraphicEvents
[] =
169 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
170 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
171 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
172 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
173 { SVX_EVENT_IMAGE_LOAD
, "OnLoadDone" },
174 { SVX_EVENT_IMAGE_ABORT
, "OnLoadCancel" },
175 { SVX_EVENT_IMAGE_ERROR
, "OnLoadError" },
179 const struct SvEventDescription aFrameEvents
[] =
181 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
182 { SW_EVENT_FRM_KEYINPUT_ALPHA
, "OnAlphaCharInput" },
183 { SW_EVENT_FRM_KEYINPUT_NOALPHA
, "OnNonAlphaCharInput" },
184 { SW_EVENT_FRM_RESIZE
, "OnResize" },
185 { SW_EVENT_FRM_MOVE
, "OnMove" },
186 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
187 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
188 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
192 const struct SvEventDescription aOLEEvents
[] =
194 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
195 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
196 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
197 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
201 const struct SvEventDescription aHyperlinkEvents
[] =
203 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
204 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
205 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
209 const struct SvEventDescription aAutotextEvents
[] =
211 { SW_EVENT_START_INS_GLOSSARY
, "OnInsertStart" },
212 { SW_EVENT_END_INS_GLOSSARY
, "OnInsertDone" },
216 const struct SvEventDescription aFrameStyleEvents
[] =
218 { SW_EVENT_OBJECT_SELECT
, "OnSelect" },
219 { SW_EVENT_FRM_KEYINPUT_ALPHA
, "OnAlphaCharInput" },
220 { SW_EVENT_FRM_KEYINPUT_NOALPHA
, "OnNonAlphaCharInput" },
221 { SW_EVENT_FRM_RESIZE
, "OnResize" },
222 { SW_EVENT_FRM_MOVE
, "OnMove" },
223 { SFX_EVENT_MOUSEOVER_OBJECT
, "OnMouseOver" },
224 { SFX_EVENT_MOUSECLICK_OBJECT
, "OnClick" },
225 { SFX_EVENT_MOUSEOUT_OBJECT
, "OnMouseOut" },
226 { SVX_EVENT_IMAGE_LOAD
, "OnLoadDone" },
227 { SVX_EVENT_IMAGE_ABORT
, "OnLoadCancel" },
228 { SVX_EVENT_IMAGE_ERROR
, "OnLoadError" },
232 const struct SvEventDescription aDocumentEvents
[] =
234 { SFX_EVENT_STARTAPP
, "OnStartApp" },
235 { SFX_EVENT_CLOSEAPP
, "OnCloseApp" },
236 { SFX_EVENT_CREATEDOC
, "OnNew" },
237 { SFX_EVENT_OPENDOC
, "OnLoad" },
238 { SFX_EVENT_SAVEDOC
, "OnSave" },
239 { SFX_EVENT_SAVEASDOC
, "OnSaveAs" },
240 // ??? cf. SAVEDOCDONE, SAVEASDOCDONE
241 { SFX_EVENT_SAVEFINISHED
, "OnSaveFinished" },
242 { SFX_EVENT_CLOSEDOC
, "OnUnload" },
243 { SFX_EVENT_ACTIVATEDOC
, "OnFocus" },
244 { SFX_EVENT_DEACTIVATEDOC
, "OnUnfocus" },
245 { SFX_EVENT_ONERROR
, "OnError" },
246 { SFX_EVENT_NEWMESSAGE
, "OnNewMail" },
247 { SFX_EVENT_PRINTDOC
, "OnPrint" },
248 { SW_EVENT_MAIL_MERGE
, "OnMailMerge" },
249 { SW_EVENT_PAGE_COUNT
, "PageCountChange" },
250 { SW_EVENT_FIELD_MERGE
, "OnFieldMerge" },
251 { SW_EVENT_FIELD_MERGE_FINISHED
, "OnFieldMergeFinished" },
252 // SFX_EVENT_LOADFINISHED,
253 // SFX_EVENT_MODIFYCHANGED,
254 // SFX_EVENT_PREPARECLOSEDOC,
255 // SFX_EVENT_TOGGLEFULLSCREENMODE,
256 // SFX_EVENT_SAVEDOCDONE,
257 // SFX_EVENT_SAVEASDOCDONE,
267 // SwHyperlinkEventDescriptor
270 SwHyperlinkEventDescriptor::SwHyperlinkEventDescriptor() :
271 SvDetachedEventDescriptor(aHyperlinkEvents
),
272 sImplName(RTL_CONSTASCII_USTRINGPARAM(sAPI_SwHyperlinkEventDescriptor
))
276 SwHyperlinkEventDescriptor::~SwHyperlinkEventDescriptor()
280 OUString
SwHyperlinkEventDescriptor::getImplementationName(void)
281 throw( RuntimeException
)
286 void SwHyperlinkEventDescriptor::copyMacrosFromINetFmt(
287 const SwFmtINetFmt
& aFmt
)
289 for(sal_Int16 i
= 0; mpSupportedMacroItems
[i
].mnEvent
!= 0; i
++)
291 USHORT nEvent
= mpSupportedMacroItems
[i
].mnEvent
;
292 const SvxMacro
* aMacro
= aFmt
.GetMacro(nEvent
);
294 replaceByName(nEvent
, *aMacro
);
298 void SwHyperlinkEventDescriptor::copyMacrosIntoINetFmt(
301 for(sal_Int16 i
= 0; mpSupportedMacroItems
[i
].mnEvent
!= 0; i
++)
303 USHORT nEvent
= mpSupportedMacroItems
[i
].mnEvent
;
304 if (hasByName(nEvent
))
306 SvxMacro
aMacro(sEmpty
, sEmpty
);
307 getByName(aMacro
, nEvent
);
308 aFmt
.SetMacro(nEvent
, aMacro
);
314 void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
316 container::XNameReplace
> & xReplace
)
318 // iterate over all names (all names that *we* support)
319 Sequence
<OUString
> aNames
= getElementNames();
320 sal_Int32 nCount
= aNames
.getLength();
321 for(sal_Int32 i
= 0; i
< nCount
; i
++)
323 // copy element for that name
324 const OUString
& rName
= aNames
[i
];
325 if (xReplace
->hasByName(rName
))
327 SvBaseEventDescriptor::replaceByName(rName
,
328 xReplace
->getByName(rName
));
335 // SwFrameEventDescriptor
338 // use double cast in superclass constructor to avoid ambigous cast
339 SwFrameEventDescriptor::SwFrameEventDescriptor(
340 SwXTextFrame
& rFrameRef
) :
341 SvEventDescriptor((text::XTextFrame
&)rFrameRef
, aFrameEvents
),
342 sSwFrameEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
343 sAPI_SwFrameEventDescriptor
)),
348 SwFrameEventDescriptor::SwFrameEventDescriptor(
349 SwXTextGraphicObject
& rGraphicRef
) :
350 SvEventDescriptor((text::XTextContent
&)rGraphicRef
, aGraphicEvents
),
351 rFrame((SwXFrame
&)rGraphicRef
)
355 SwFrameEventDescriptor::SwFrameEventDescriptor(
356 SwXTextEmbeddedObject
& rObjectRef
) :
357 SvEventDescriptor((text::XTextContent
&)rObjectRef
, aOLEEvents
),
358 rFrame((SwXFrame
&)rObjectRef
)
362 SwFrameEventDescriptor::~SwFrameEventDescriptor()
366 void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem
& rItem
)
368 rFrame
.GetFrmFmt()->SetFmtAttr(rItem
);
371 const SvxMacroItem
& SwFrameEventDescriptor::getMacroItem()
373 return (const SvxMacroItem
&)rFrame
.GetFrmFmt()->GetFmtAttr(RES_FRMMACRO
);
376 sal_uInt16
SwFrameEventDescriptor::getMacroItemWhich() const
381 OUString
SwFrameEventDescriptor::getImplementationName()
382 throw( RuntimeException
)
384 return sSwFrameEventDescriptor
;
389 // SwFrameStyleEventDescriptor
392 SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
393 SwXFrameStyle
& rStyleRef
) :
394 SvEventDescriptor((document::XEventsSupplier
&)rStyleRef
,
396 sSwFrameStyleEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
397 sAPI_SwFrameStyleEventDescriptor
)),
402 SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
406 void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem
& rItem
)
408 // As I was told, for some entirely unobvious reason getting an
409 // item from a style has to look as follows:
410 SfxStyleSheetBasePool
* pBasePool
= rStyle
.GetBasePool();
413 SfxStyleSheetBase
* pBase
= pBasePool
->Find(rStyle
.GetStyleName());
416 rtl::Reference
< SwDocStyleSheet
> xStyle( new SwDocStyleSheet( *(SwDocStyleSheet
*)pBase
) );
417 SfxItemSet
& rStyleSet
= xStyle
->GetItemSet();
418 SfxItemSet
aSet(*rStyleSet
.GetPool(), RES_FRMMACRO
, RES_FRMMACRO
);
420 xStyle
->SetItemSet(aSet
);
425 static const SvxMacroItem
aEmptyMacroItem(RES_FRMMACRO
);
427 const SvxMacroItem
& SwFrameStyleEventDescriptor::getMacroItem()
429 // As I was told, for some entirely unobvious reason getting an
430 // item from a style has to look as follows:
431 SfxStyleSheetBasePool
* pBasePool
= rStyle
.GetBasePool();
434 SfxStyleSheetBase
* pBase
= pBasePool
->Find(rStyle
.GetStyleName());
437 rtl::Reference
< SwDocStyleSheet
> xStyle( new SwDocStyleSheet( *(SwDocStyleSheet
*)pBase
) );
438 return (const SvxMacroItem
&)xStyle
->GetItemSet().Get(RES_FRMMACRO
);
441 return aEmptyMacroItem
;
444 return aEmptyMacroItem
;
447 OUString
SwFrameStyleEventDescriptor::getImplementationName()
448 throw( RuntimeException
)
450 return sSwFrameStyleEventDescriptor
;
453 sal_uInt16
SwFrameStyleEventDescriptor::getMacroItemWhich() const