File: | home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx |
Warning: | line 129, column 1 Potential leak of memory pointed to by 'aRef.pObj' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | #include <hintids.hxx> | |||
21 | ||||
22 | #include <rtl/ustring.hxx> | |||
23 | #include <sal/log.hxx> | |||
24 | #include <vcl/imap.hxx> | |||
25 | #include <vcl/imapobj.hxx> | |||
26 | #include <basic/sbx.hxx> | |||
27 | #include <frmfmt.hxx> | |||
28 | #include <fmtinfmt.hxx> | |||
29 | #include <fmturl.hxx> | |||
30 | #include <frmatr.hxx> | |||
31 | #include <docary.hxx> | |||
32 | #include <doc.hxx> | |||
33 | #include <docsh.hxx> | |||
34 | #include <swevent.hxx> | |||
35 | #include <frameformats.hxx> | |||
36 | #include <memory> | |||
37 | ||||
38 | using namespace ::com::sun::star::uno; | |||
39 | ||||
40 | static Sequence<Any> *lcl_docbasic_convertArgs( SbxArray& rArgs ) | |||
41 | { | |||
42 | Sequence<Any> *pRet = nullptr; | |||
43 | ||||
44 | sal_uInt32 nCount = rArgs.Count32(); | |||
45 | if( nCount > 1 ) | |||
46 | { | |||
47 | nCount--; | |||
48 | pRet = new Sequence<Any>( nCount ); | |||
49 | Any *pUnoArgs = pRet->getArray(); | |||
50 | for( sal_uInt32 i=0; i<nCount; i++ ) | |||
51 | { | |||
52 | SbxVariable *pVar = rArgs.Get32( i+1 ); | |||
53 | switch( pVar->GetType() ) | |||
54 | { | |||
55 | case SbxSTRING: | |||
56 | pUnoArgs[i] <<= pVar->GetOUString(); | |||
57 | break; | |||
58 | case SbxCHAR: | |||
59 | pUnoArgs[i] <<= static_cast<sal_Int16>(pVar->GetChar()) ; | |||
60 | break; | |||
61 | case SbxUSHORT: | |||
62 | pUnoArgs[i] <<= static_cast<sal_Int16>(pVar->GetUShort()); | |||
63 | break; | |||
64 | case SbxLONG: | |||
65 | pUnoArgs[i] <<= pVar->GetLong(); | |||
66 | break; | |||
67 | default: | |||
68 | pUnoArgs[i].clear(); | |||
69 | break; | |||
70 | } | |||
71 | } | |||
72 | } | |||
73 | ||||
74 | return pRet; | |||
75 | } | |||
76 | ||||
77 | void SwDoc::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs ) | |||
78 | { | |||
79 | switch( rMacro.GetScriptType() ) | |||
| ||||
80 | { | |||
81 | case STARBASIC: | |||
82 | { | |||
83 | SbxBaseRef aRef; | |||
84 | SbxValue* pRetValue = new SbxValue; | |||
85 | aRef = pRetValue; | |||
86 | mpDocShell->CallBasic( rMacro.GetMacName(), | |||
87 | rMacro.GetLibName(), | |||
88 | pArgs, pRet ? pRetValue : nullptr ); | |||
89 | ||||
90 | if( pRet
| |||
91 | SbxVOID != pRetValue->GetType() ) | |||
92 | { | |||
93 | // valid value, so set it | |||
94 | *pRet = pRetValue->GetOUString(); | |||
95 | } | |||
96 | } | |||
97 | break; | |||
98 | case JAVASCRIPT: | |||
99 | // ignore JavaScript calls | |||
100 | break; | |||
101 | case EXTENDED_STYPE: | |||
102 | { | |||
103 | std::unique_ptr<Sequence<Any> > pUnoArgs; | |||
104 | if( pArgs ) | |||
105 | { | |||
106 | // better to rename the local function to lcl_translateBasic2Uno and | |||
107 | // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx | |||
108 | pUnoArgs.reset(lcl_docbasic_convertArgs( *pArgs )); | |||
109 | } | |||
110 | ||||
111 | if (!pUnoArgs) | |||
112 | { | |||
113 | pUnoArgs.reset(new Sequence< Any > (0)); | |||
114 | } | |||
115 | ||||
116 | // TODO - return value is not handled | |||
117 | Any aRet; | |||
118 | Sequence< sal_Int16 > aOutArgsIndex; | |||
119 | Sequence< Any > aOutArgs; | |||
120 | ||||
121 | SAL_INFO("sw", "SwDoc::ExecMacro URL is " << rMacro.GetMacName() )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SwDoc::ExecMacro URL is " << rMacro.GetMacName ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "121" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SwDoc::ExecMacro URL is " << rMacro .GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "SwDoc::ExecMacro URL is " << rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "121" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SwDoc::ExecMacro URL is " << rMacro.GetMacName ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "121" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SwDoc::ExecMacro URL is " << rMacro .GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "SwDoc::ExecMacro URL is " << rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "121" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
122 | ||||
123 | mpDocShell->CallXScript( | |||
124 | rMacro.GetMacName(), *pUnoArgs, aRet, aOutArgsIndex, aOutArgs); | |||
125 | ||||
126 | break; | |||
127 | } | |||
128 | } | |||
129 | } | |||
| ||||
130 | ||||
131 | sal_uInt16 SwDoc::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent, | |||
132 | bool bCheckPtr ) | |||
133 | { | |||
134 | if( !mpDocShell ) // we can't do that without a DocShell! | |||
135 | return 0; | |||
136 | ||||
137 | sal_uInt16 nRet = 0; | |||
138 | const SvxMacroTableDtor* pTable = nullptr; | |||
139 | switch( rCallEvent.eType ) | |||
140 | { | |||
141 | case EVENT_OBJECT_INETATTR: | |||
142 | if( bCheckPtr ) | |||
143 | { | |||
144 | for (const SfxPoolItem* pItem : GetAttrPool().GetItemSurrogates(RES_TXTATR_INETFMT)) | |||
145 | { | |||
146 | auto pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem); | |||
147 | if( pFormatItem && rCallEvent.PTR.pINetAttr == pFormatItem ) | |||
148 | { | |||
149 | bCheckPtr = false; // misuse as a flag | |||
150 | break; | |||
151 | } | |||
152 | } | |||
153 | } | |||
154 | if( !bCheckPtr ) | |||
155 | pTable = rCallEvent.PTR.pINetAttr->GetMacroTable(); | |||
156 | break; | |||
157 | ||||
158 | case EVENT_OBJECT_URLITEM: | |||
159 | case EVENT_OBJECT_IMAGE: | |||
160 | { | |||
161 | const SwFrameFormat* pFormat = rCallEvent.PTR.pFormat; | |||
162 | if( bCheckPtr ) | |||
163 | { | |||
164 | if (GetSpzFrameFormats()->IsAlive(pFormat)) | |||
165 | bCheckPtr = false; // misuse as a flag | |||
166 | else | |||
167 | // this shouldn't be possible now that SwCallMouseEvent | |||
168 | // listens for dying format? | |||
169 | assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail ( "false", "/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" , 169, __extension__ __PRETTY_FUNCTION__)); | |||
170 | } | |||
171 | if( !bCheckPtr ) | |||
172 | pTable = &pFormat->GetMacro().GetMacroTable(); | |||
173 | } | |||
174 | break; | |||
175 | ||||
176 | case EVENT_OBJECT_IMAGEMAP: | |||
177 | { | |||
178 | const IMapObject* pIMapObj = rCallEvent.PTR.IMAP.pIMapObj; | |||
179 | if( bCheckPtr ) | |||
180 | { | |||
181 | const SwFrameFormat* pFormat = rCallEvent.PTR.IMAP.pFormat; | |||
182 | if (GetSpzFrameFormats()->IsAlive(pFormat)) | |||
183 | { | |||
184 | const ImageMap* pIMap = pFormat->GetURL().GetMap(); | |||
185 | if (pIMap) | |||
186 | { | |||
187 | for( size_t nPos = pIMap->GetIMapObjectCount(); nPos; ) | |||
188 | if( pIMapObj == pIMap->GetIMapObject( --nPos )) | |||
189 | { | |||
190 | bCheckPtr = false; // misuse as a flag | |||
191 | break; | |||
192 | } | |||
193 | } | |||
194 | } | |||
195 | } | |||
196 | if( !bCheckPtr ) | |||
197 | pTable = &pIMapObj->GetMacroTable(); | |||
198 | } | |||
199 | break; | |||
200 | default: | |||
201 | break; | |||
202 | } | |||
203 | ||||
204 | if( pTable ) | |||
205 | { | |||
206 | nRet = 0x1; | |||
207 | if( pTable->IsKeyValid( nEvent ) ) | |||
208 | { | |||
209 | const SvxMacro& rMacro = *pTable->Get( nEvent ); | |||
210 | if( STARBASIC == rMacro.GetScriptType() ) | |||
211 | { | |||
212 | nRet += ERRCODE_NONEErrCode(0) == mpDocShell->CallBasic( rMacro.GetMacName(), | |||
213 | rMacro.GetLibName(), nullptr ) ? 1 : 0; | |||
214 | } | |||
215 | else if( EXTENDED_STYPE == rMacro.GetScriptType() ) | |||
216 | { | |||
217 | std::unique_ptr<Sequence<Any> > pUnoArgs(new Sequence<Any>()); | |||
218 | ||||
219 | Any aRet; | |||
220 | Sequence< sal_Int16 > aOutArgsIndex; | |||
221 | Sequence< Any > aOutArgs; | |||
222 | ||||
223 | SAL_INFO("sw", "SwDoc::CallEvent URL is " << rMacro.GetMacName() )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SwDoc::CallEvent URL is " << rMacro.GetMacName ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "223" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SwDoc::CallEvent URL is " << rMacro .GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "SwDoc::CallEvent URL is " << rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "223" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SwDoc::CallEvent URL is " << rMacro.GetMacName ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "223" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SwDoc::CallEvent URL is " << rMacro .GetMacName()), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "SwDoc::CallEvent URL is " << rMacro.GetMacName(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/core/doc/docbasic.cxx" ":" "223" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
224 | ||||
225 | nRet += ERRCODE_NONEErrCode(0) == mpDocShell->CallXScript( | |||
226 | rMacro.GetMacName(), *pUnoArgs,aRet, aOutArgsIndex, aOutArgs) ? 1 : 0; | |||
227 | } | |||
228 | // JavaScript calls are ignored | |||
229 | } | |||
230 | } | |||
231 | return nRet; | |||
232 | } | |||
233 | ||||
234 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |