Branch data 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 : : using ::rtl::OUString;
46 : : using ::rtl::OUStringBuffer;
47 : :
48 : : //
49 : : // tables of allowed events for specific objects
50 : : //
51 : :
52 : : const struct SvEventDescription aGraphicEvents[] =
53 : : {
54 : : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
55 : : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
56 : : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
57 : : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
58 : : { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
59 : : { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
60 : : { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
61 : : { 0, NULL }
62 : : };
63 : :
64 : : const struct SvEventDescription aFrameEvents[] =
65 : : {
66 : : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
67 : : { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
68 : : { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
69 : : { SW_EVENT_FRM_RESIZE, "OnResize" },
70 : : { SW_EVENT_FRM_MOVE, "OnMove" },
71 : : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
72 : : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
73 : : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
74 : : { 0, NULL }
75 : : };
76 : :
77 : : const struct SvEventDescription aOLEEvents[] =
78 : : {
79 : : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
80 : : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
81 : : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
82 : : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
83 : : { 0, NULL }
84 : : };
85 : :
86 : : const struct SvEventDescription aHyperlinkEvents[] =
87 : : {
88 : : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
89 : : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
90 : : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
91 : : { 0, NULL }
92 : : };
93 : :
94 : : const struct SvEventDescription aAutotextEvents[] =
95 : : {
96 : : { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" },
97 : : { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" },
98 : : { 0, NULL }
99 : : };
100 : :
101 : : const struct SvEventDescription aFrameStyleEvents[] =
102 : : {
103 : : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
104 : : { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
105 : : { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
106 : : { SW_EVENT_FRM_RESIZE, "OnResize" },
107 : : { SW_EVENT_FRM_MOVE, "OnMove" },
108 : : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
109 : : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
110 : : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
111 : : { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
112 : : { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
113 : : { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
114 : : { 0, NULL }
115 : : };
116 : :
117 : : //
118 : : // SwHyperlinkEventDescriptor
119 : : //
120 : :
121 : 2 : SwHyperlinkEventDescriptor::SwHyperlinkEventDescriptor() :
122 : : SvDetachedEventDescriptor(aHyperlinkEvents),
123 : 2 : sImplName("SwHyperlinkEventDescriptor")
124 : : {
125 : 2 : }
126 : :
127 : 2 : SwHyperlinkEventDescriptor::~SwHyperlinkEventDescriptor()
128 : : {
129 [ - + ]: 4 : }
130 : :
131 : 0 : OUString SwHyperlinkEventDescriptor::getImplementationName(void)
132 : : throw( RuntimeException )
133 : : {
134 : 0 : return sImplName;
135 : : }
136 : :
137 : 2 : void SwHyperlinkEventDescriptor::copyMacrosFromINetFmt(
138 : : const SwFmtINetFmt& aFmt)
139 : : {
140 [ + + ]: 8 : for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
141 : : {
142 : 6 : sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
143 : 6 : const SvxMacro* aMacro = aFmt.GetMacro(nEvent);
144 [ - + ]: 6 : if (NULL != aMacro)
145 : 0 : replaceByName(nEvent, *aMacro);
146 : : }
147 : 2 : }
148 : :
149 : 0 : void SwHyperlinkEventDescriptor::copyMacrosIntoINetFmt(
150 : : SwFmtINetFmt& aFmt)
151 : : {
152 [ # # ]: 0 : for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
153 : : {
154 : 0 : sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
155 [ # # ]: 0 : if (hasByName(nEvent))
156 : : {
157 [ # # ]: 0 : SvxMacro aMacro(sEmpty, sEmpty);
158 [ # # ]: 0 : getByName(aMacro, nEvent);
159 [ # # ][ # # ]: 0 : aFmt.SetMacro(nEvent, aMacro);
160 : : }
161 : : }
162 : 0 : }
163 : :
164 : :
165 : 0 : void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
166 : : uno::Reference<
167 : : container::XNameReplace> & xReplace)
168 : : {
169 : : // iterate over all names (all names that *we* support)
170 [ # # ]: 0 : Sequence<OUString> aNames = getElementNames();
171 : 0 : sal_Int32 nCount = aNames.getLength();
172 [ # # ]: 0 : for(sal_Int32 i = 0; i < nCount; i++)
173 : : {
174 : : // copy element for that name
175 [ # # ]: 0 : const OUString& rName = aNames[i];
176 [ # # ][ # # ]: 0 : if (xReplace->hasByName(rName))
[ # # ]
177 : : {
178 : : SvBaseEventDescriptor::replaceByName(rName,
179 [ # # ][ # # ]: 0 : xReplace->getByName(rName));
[ # # ]
180 : : }
181 [ # # ]: 0 : }
182 : 0 : }
183 : :
184 : :
185 : : //
186 : : // SwFrameEventDescriptor
187 : : //
188 : :
189 : : // use double cast in superclass constructor to avoid ambigous cast
190 : 0 : SwFrameEventDescriptor::SwFrameEventDescriptor(
191 : : SwXTextFrame& rFrameRef ) :
192 : : SvEventDescriptor((text::XTextFrame&)rFrameRef, aFrameEvents),
193 : : sSwFrameEventDescriptor("SwFrameEventDescriptor"),
194 : 0 : rFrame(rFrameRef)
195 : : {
196 : 0 : }
197 : :
198 : 0 : SwFrameEventDescriptor::SwFrameEventDescriptor(
199 : : SwXTextGraphicObject& rGraphicRef ) :
200 : : SvEventDescriptor((text::XTextContent&)rGraphicRef, aGraphicEvents),
201 : 0 : rFrame((SwXFrame&)rGraphicRef)
202 : : {
203 : 0 : }
204 : :
205 : 0 : SwFrameEventDescriptor::SwFrameEventDescriptor(
206 : : SwXTextEmbeddedObject& rObjectRef ) :
207 : : SvEventDescriptor((text::XTextContent&)rObjectRef, aOLEEvents),
208 : 0 : rFrame((SwXFrame&)rObjectRef)
209 : : {
210 : 0 : }
211 : :
212 : 0 : SwFrameEventDescriptor::~SwFrameEventDescriptor()
213 : : {
214 [ # # ]: 0 : }
215 : :
216 : 0 : void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
217 : : {
218 : 0 : rFrame.GetFrmFmt()->SetFmtAttr(rItem);
219 : 0 : }
220 : :
221 : 0 : const SvxMacroItem& SwFrameEventDescriptor::getMacroItem()
222 : : {
223 : 0 : return (const SvxMacroItem&)rFrame.GetFrmFmt()->GetFmtAttr(RES_FRMMACRO);
224 : : }
225 : :
226 : 0 : sal_uInt16 SwFrameEventDescriptor::getMacroItemWhich() const
227 : : {
228 : 0 : return RES_FRMMACRO;
229 : : }
230 : :
231 : 0 : OUString SwFrameEventDescriptor::getImplementationName()
232 : : throw( RuntimeException )
233 : : {
234 : 0 : return sSwFrameEventDescriptor;
235 : : }
236 : :
237 : :
238 : : //
239 : : // SwFrameStyleEventDescriptor
240 : : //
241 : :
242 : 0 : SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
243 : : SwXFrameStyle& rStyleRef ) :
244 : : SvEventDescriptor((document::XEventsSupplier&)rStyleRef,
245 : : aFrameStyleEvents),
246 : : sSwFrameStyleEventDescriptor("SwFrameStyleEventDescriptor"),
247 : 0 : rStyle(rStyleRef)
248 : : {
249 : 0 : }
250 : :
251 : 0 : SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
252 : : {
253 [ # # ]: 0 : }
254 : :
255 : 0 : void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
256 : : {
257 : : // As I was told, for some entirely unobvious reason getting an
258 : : // item from a style has to look as follows:
259 : 0 : SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
260 [ # # ]: 0 : if (pBasePool)
261 : : {
262 : 0 : SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
263 [ # # ]: 0 : if (pBase)
264 : : {
265 [ # # ]: 0 : rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase ) );
266 [ # # ]: 0 : SfxItemSet& rStyleSet = xStyle->GetItemSet();
267 [ # # ]: 0 : SfxItemSet aSet(*rStyleSet.GetPool(), RES_FRMMACRO, RES_FRMMACRO);
268 [ # # ]: 0 : aSet.Put(rItem);
269 [ # # ][ # # ]: 0 : xStyle->SetItemSet(aSet);
270 : : }
271 : : }
272 : 0 : }
273 : :
274 : 73 : static const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO);
275 : :
276 : 0 : const SvxMacroItem& SwFrameStyleEventDescriptor::getMacroItem()
277 : : {
278 : : // As I was told, for some entirely unobvious reason getting an
279 : : // item from a style has to look as follows:
280 : 0 : SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
281 [ # # ]: 0 : if (pBasePool)
282 : : {
283 : 0 : SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
284 [ # # ]: 0 : if (pBase)
285 : : {
286 [ # # ]: 0 : rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pBase) );
287 [ # # ][ # # ]: 0 : return (const SvxMacroItem&)xStyle->GetItemSet().Get(RES_FRMMACRO);
288 : : }
289 : : else
290 : 0 : return aEmptyMacroItem;
291 : : }
292 : : else
293 : 0 : return aEmptyMacroItem;
294 : : }
295 : :
296 : 0 : OUString SwFrameStyleEventDescriptor::getImplementationName()
297 : : throw( RuntimeException )
298 : : {
299 : 0 : return sSwFrameStyleEventDescriptor;
300 : : }
301 : :
302 : 0 : sal_uInt16 SwFrameStyleEventDescriptor::getMacroItemWhich() const
303 : : {
304 : 0 : return RES_FRMMACRO;
305 [ + - ][ + - ]: 219 : }
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|