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