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 : // HINTIDs must be on top; it is required for the macitem.hxx header
21 : #include "hintids.hxx"
22 : #include "unoevent.hxx"
23 : #include "unoframe.hxx"
24 : #include "unostyle.hxx"
25 : #include "swevent.hxx"
26 : #include "docstyle.hxx"
27 : #include <svx/svxids.hrc>
28 : #include "fmtinfmt.hxx"
29 : #include <svl/macitem.hxx>
30 : #include <rtl/ustrbuf.hxx>
31 : #include <com/sun/star/beans/PropertyValue.hpp>
32 :
33 : using namespace ::com::sun::star;
34 : using namespace ::com::sun::star::uno;
35 :
36 : using ::com::sun::star::container::NoSuchElementException;
37 : using ::com::sun::star::container::XNameReplace;
38 : using ::com::sun::star::lang::IllegalArgumentException;
39 : using ::com::sun::star::lang::WrappedTargetException;
40 : using ::com::sun::star::lang::XServiceInfo;
41 : using ::com::sun::star::beans::PropertyValue;
42 :
43 : // tables of allowed events for specific objects
44 :
45 : const struct SvEventDescription aGraphicEvents[] =
46 : {
47 : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
48 : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
49 : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
50 : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
51 : { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
52 : { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
53 : { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
54 : { 0, NULL }
55 : };
56 :
57 : const struct SvEventDescription aFrameEvents[] =
58 : {
59 : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
60 : { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
61 : { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
62 : { SW_EVENT_FRM_RESIZE, "OnResize" },
63 : { SW_EVENT_FRM_MOVE, "OnMove" },
64 : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
65 : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
66 : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
67 : { 0, NULL }
68 : };
69 :
70 : const struct SvEventDescription aOLEEvents[] =
71 : {
72 : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
73 : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
74 : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
75 : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
76 : { 0, NULL }
77 : };
78 :
79 : const struct SvEventDescription aHyperlinkEvents[] =
80 : {
81 : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
82 : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
83 : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
84 : { 0, NULL }
85 : };
86 :
87 : const struct SvEventDescription aFrameStyleEvents[] =
88 : {
89 : { SW_EVENT_OBJECT_SELECT, "OnSelect" },
90 : { SW_EVENT_FRM_KEYINPUT_ALPHA, "OnAlphaCharInput" },
91 : { SW_EVENT_FRM_KEYINPUT_NOALPHA, "OnNonAlphaCharInput" },
92 : { SW_EVENT_FRM_RESIZE, "OnResize" },
93 : { SW_EVENT_FRM_MOVE, "OnMove" },
94 : { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
95 : { SFX_EVENT_MOUSECLICK_OBJECT, "OnClick" },
96 : { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
97 : { SVX_EVENT_IMAGE_LOAD, "OnLoadDone" },
98 : { SVX_EVENT_IMAGE_ABORT, "OnLoadCancel" },
99 : { SVX_EVENT_IMAGE_ERROR, "OnLoadError" },
100 : { 0, NULL }
101 : };
102 :
103 21 : SwHyperlinkEventDescriptor::SwHyperlinkEventDescriptor() :
104 : SvDetachedEventDescriptor(aHyperlinkEvents),
105 21 : sImplName("SwHyperlinkEventDescriptor")
106 : {
107 21 : }
108 :
109 42 : SwHyperlinkEventDescriptor::~SwHyperlinkEventDescriptor()
110 : {
111 42 : }
112 :
113 0 : OUString SwHyperlinkEventDescriptor::getImplementationName()
114 : throw( RuntimeException, std::exception )
115 : {
116 0 : return sImplName;
117 : }
118 :
119 21 : void SwHyperlinkEventDescriptor::copyMacrosFromINetFormat(
120 : const SwFormatINetFormat& aFormat)
121 : {
122 84 : for(sal_uInt16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; ++i)
123 : {
124 63 : const sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
125 63 : const SvxMacro* aMacro = aFormat.GetMacro(nEvent);
126 63 : if (NULL != aMacro)
127 0 : replaceByName(nEvent, *aMacro);
128 : }
129 21 : }
130 :
131 0 : void SwHyperlinkEventDescriptor::copyMacrosIntoINetFormat(
132 : SwFormatINetFormat& aFormat)
133 : {
134 0 : for(sal_uInt16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; ++i)
135 : {
136 0 : const sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
137 0 : if (hasByName(nEvent))
138 : {
139 0 : SvxMacro aMacro(sEmpty, sEmpty);
140 0 : getByName(aMacro, nEvent);
141 0 : aFormat.SetMacro(nEvent, aMacro);
142 : }
143 : }
144 0 : }
145 :
146 0 : void SwHyperlinkEventDescriptor::copyMacrosFromNameReplace(
147 : uno::Reference<
148 : container::XNameReplace> & xReplace)
149 : {
150 : // iterate over all names (all names that *we* support)
151 0 : Sequence<OUString> aNames = getElementNames();
152 0 : sal_Int32 nCount = aNames.getLength();
153 0 : for(sal_Int32 i = 0; i < nCount; i++)
154 : {
155 : // copy element for that name
156 0 : const OUString& rName = aNames[i];
157 0 : if (xReplace->hasByName(rName))
158 : {
159 : SvBaseEventDescriptor::replaceByName(rName,
160 0 : xReplace->getByName(rName));
161 : }
162 0 : }
163 0 : }
164 :
165 : // use double cast in superclass constructor to avoid ambigous cast
166 59 : SwFrameEventDescriptor::SwFrameEventDescriptor(
167 : SwXTextFrame& rFrameRef ) :
168 : SvEventDescriptor((text::XTextFrame&)rFrameRef, aFrameEvents),
169 : sSwFrameEventDescriptor("SwFrameEventDescriptor"),
170 59 : rFrame(rFrameRef)
171 : {
172 59 : }
173 :
174 6 : SwFrameEventDescriptor::SwFrameEventDescriptor(
175 : SwXTextGraphicObject& rGraphicRef ) :
176 : SvEventDescriptor((text::XTextContent&)rGraphicRef, aGraphicEvents),
177 6 : rFrame((SwXFrame&)rGraphicRef)
178 : {
179 6 : }
180 :
181 9 : SwFrameEventDescriptor::SwFrameEventDescriptor(
182 : SwXTextEmbeddedObject& rObjectRef ) :
183 : SvEventDescriptor((text::XTextContent&)rObjectRef, aOLEEvents),
184 9 : rFrame((SwXFrame&)rObjectRef)
185 : {
186 9 : }
187 :
188 148 : SwFrameEventDescriptor::~SwFrameEventDescriptor()
189 : {
190 148 : }
191 :
192 0 : void SwFrameEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
193 : {
194 0 : rFrame.GetFrameFormat()->SetFormatAttr(rItem);
195 0 : }
196 :
197 550 : const SvxMacroItem& SwFrameEventDescriptor::getMacroItem()
198 : {
199 550 : return static_cast<const SvxMacroItem&>(rFrame.GetFrameFormat()->GetFormatAttr(RES_FRMMACRO));
200 : }
201 :
202 0 : sal_uInt16 SwFrameEventDescriptor::getMacroItemWhich() const
203 : {
204 0 : return RES_FRMMACRO;
205 : }
206 :
207 0 : OUString SwFrameEventDescriptor::getImplementationName()
208 : throw( RuntimeException, std::exception )
209 : {
210 0 : return sSwFrameEventDescriptor;
211 : }
212 :
213 31 : SwFrameStyleEventDescriptor::SwFrameStyleEventDescriptor(
214 : SwXFrameStyle& rStyleRef ) :
215 : SvEventDescriptor((document::XEventsSupplier&)rStyleRef,
216 : aFrameStyleEvents),
217 : sSwFrameStyleEventDescriptor("SwFrameStyleEventDescriptor"),
218 31 : rStyle(rStyleRef)
219 : {
220 31 : }
221 :
222 62 : SwFrameStyleEventDescriptor::~SwFrameStyleEventDescriptor()
223 : {
224 62 : }
225 :
226 0 : void SwFrameStyleEventDescriptor::setMacroItem(const SvxMacroItem& rItem)
227 : {
228 : // As I was told, for some entirely unobvious reason getting an
229 : // item from a style has to look as follows:
230 0 : SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
231 0 : if (pBasePool)
232 : {
233 0 : SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
234 0 : if (pBase)
235 : {
236 0 : rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
237 0 : SfxItemSet& rStyleSet = xStyle->GetItemSet();
238 0 : SfxItemSet aSet(*rStyleSet.GetPool(), RES_FRMMACRO, RES_FRMMACRO);
239 0 : aSet.Put(rItem);
240 0 : xStyle->SetItemSet(aSet);
241 : }
242 : }
243 0 : }
244 :
245 59 : static const SvxMacroItem aEmptyMacroItem(RES_FRMMACRO);
246 :
247 341 : const SvxMacroItem& SwFrameStyleEventDescriptor::getMacroItem()
248 : {
249 : // As I was told, for some entirely unobvious reason getting an
250 : // item from a style has to look as follows:
251 341 : SfxStyleSheetBasePool* pBasePool = rStyle.GetBasePool();
252 341 : if (pBasePool)
253 : {
254 341 : SfxStyleSheetBase* pBase = pBasePool->Find(rStyle.GetStyleName());
255 341 : if (pBase)
256 : {
257 341 : rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase)) );
258 341 : return static_cast<const SvxMacroItem&>(xStyle->GetItemSet().Get(RES_FRMMACRO));
259 : }
260 : else
261 0 : return aEmptyMacroItem;
262 : }
263 : else
264 0 : return aEmptyMacroItem;
265 : }
266 :
267 0 : OUString SwFrameStyleEventDescriptor::getImplementationName()
268 : throw( RuntimeException, std::exception )
269 : {
270 0 : return sSwFrameStyleEventDescriptor;
271 : }
272 :
273 0 : sal_uInt16 SwFrameStyleEventDescriptor::getMacroItemWhich() const
274 : {
275 0 : return RES_FRMMACRO;
276 177 : }
277 :
278 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|