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