21#include <com/sun/star/frame/DispatchStatement.hpp>
22#include <com/sun/star/lang/IllegalArgumentException.hpp>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <com/sun/star/script/CannotConvertException.hpp>
25#include <com/sun/star/script/Converter.hpp>
27#include <osl/diagnose.h>
29#include <typelib/typedescription.h>
43 return "com.sun.star.comp.framework.DispatchRecorder";
53 return {
"com.sun.star.frame.DispatchRecorder" };
59 ::std::vector< Any > * vec,
void const * data,
60 typelib_CompoundTypeDescription * pTD )
62 if (pTD->pBaseTypeDescription)
69 Any(
static_cast<char const *
>(data) + pTD->pMemberOffsets[
nPos ], pTD->ppTypeRefs[
nPos ] ) );
76 Type const &
type = val.getValueType();
77 TypeClass eTypeClass =
type.getTypeClass();
78 if (TypeClass_STRUCT != eTypeClass && TypeClass_EXCEPTION != eTypeClass)
81 type.getTypeName() +
"is no struct or exception!" );
84 TYPELIB_DANGER_GET( &pTD,
type.getTypeLibType() );
89 "cannot get type descr of type " +
type.getTypeName() );
92 ::std::vector< Any > vec;
93 vec.reserve(
reinterpret_cast<typelib_CompoundTypeDescription *
>(pTD)->nMembers );
95 TYPELIB_DANGER_RELEASE( pTD );
96 return Sequence< Any >( vec.data(), vec.size() );
117 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
119 css::frame::DispatchStatement aStatement(
aURL.Complete, OUString(), lArguments, 0,
false );
124 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
127 css::frame::DispatchStatement aStatement(
aURL.Complete, OUString(), lArguments, 0,
true );
144 OUStringBuffer aScriptBuffer;
145 aScriptBuffer.ensureCapacity(10000);
148 aScriptBuffer.append(
149 "rem ----------------------------------------------------------------------\n"
150 "rem define variables\n"
151 "dim document as object\n"
152 "dim dispatcher as object\n"
153 "rem ----------------------------------------------------------------------\n"
154 "rem get access to the document\n"
155 "document = ThisComponent.CurrentController.Frame\n"
156 "dispatcher = createUnoService(\"com.sun.star.frame.DispatchHelper\")\n\n");
159 implts_recordMacro( statement.aCommand, statement.aArgs, statement.bIsComment, aScriptBuffer );
160 OUString
sScript = aScriptBuffer.makeStringAndClear();
167 if (aValue.getValueTypeClass() == css::uno::TypeClass_STRUCT )
171 aArgumentBuffer.append(
"Array(");
172 for ( sal_Int32 nAny=0; nAny<
aSeq.getLength(); nAny++ )
175 if ( nAny+1 <
aSeq.getLength() )
177 aArgumentBuffer.append(
",");
180 aArgumentBuffer.append(
")");
182 else if (aValue.getValueTypeClass() == css::uno::TypeClass_SEQUENCE )
185 css::uno::Sequence < css::uno::Any >
aSeq;
188 catch (
const css::uno::Exception&) {}
191 aArgumentBuffer.append(
"Array(");
192 for ( sal_Int32 nAny=0; nAny<
aSeq.getLength(); nAny++ )
195 if ( nAny+1 <
aSeq.getLength() )
197 aArgumentBuffer.append(
",");
200 aArgumentBuffer.append(
")");
202 else if (aValue.getValueTypeClass() == css::uno::TypeClass_STRING )
209 if ( !sVal.isEmpty() )
212 bool bInString =
false;
213 for ( sal_Int32 nChar=0; nChar<sVal.getLength(); nChar ++ )
215 if ( pChars[nChar] < 32 || pChars[nChar] ==
'"' )
221 aArgumentBuffer.append(
"\"");
227 aArgumentBuffer.append(
"+");
230 aArgumentBuffer.append(
"CHR$(");
231 aArgumentBuffer.append(
static_cast<sal_Int32
>(pChars[nChar]) );
232 aArgumentBuffer.append(
")");
240 aArgumentBuffer.append(
"+");
243 aArgumentBuffer.append(
"\"");
247 aArgumentBuffer.append( pChars[nChar] );
253 aArgumentBuffer.append(
"\"");
256 aArgumentBuffer.append(
"\"\"");
258 else if (
auto nVal = o3tl::tryAccess<sal_Unicode>(aValue))
261 aArgumentBuffer.append(
"\"");
264 aArgumentBuffer.append(*nVal);
265 aArgumentBuffer.append(*nVal);
266 aArgumentBuffer.append(
"\"");
273 aNew =
m_xConverter->convertToSimpleType( aValue, css::uno::TypeClass_STRING );
275 catch (
const css::script::CannotConvertException&) {}
276 catch (
const css::uno::Exception&) {}
280 if (aValue.getValueTypeClass() == css::uno::TypeClass_ENUM )
282 OUString
aName = aValue.getValueType().getTypeName();
283 aArgumentBuffer.append(
aName );
284 aArgumentBuffer.append(
".");
287 aArgumentBuffer.append(sVal);
292 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
293 bool bAsComment, OUStringBuffer& aScriptBuffer )
295 OUStringBuffer aArgumentBuffer(1000);
299 aScriptBuffer.append(
"rem ----------------------------------------------------------------------\n");
301 sal_Int32
nLength = lArguments.getLength();
302 sal_Int32 nValidArgs = 0;
305 if(!lArguments[
i].
Value.hasValue())
308 OUStringBuffer sValBuffer(100);
313 catch(
const css::uno::Exception&)
315 sValBuffer.setLength(0);
317 if (sValBuffer.isEmpty())
324 aArgumentBuffer.append(sArrayName
325 +
"(" + OUString::number(nValidArgs)
326 +
").Name = \"" + lArguments[
i].
Name
332 aArgumentBuffer.append(sArrayName
333 +
"(" + OUString::number(nValidArgs)
334 +
").Value = " + sValBuffer +
"\n");
345 aScriptBuffer.append(
"dim ");
346 aScriptBuffer.append (sArrayName);
347 aScriptBuffer.append(
"(");
348 aScriptBuffer.append (
static_cast<sal_Int32
>(nValidArgs-1));
349 aScriptBuffer.append(
") as new com.sun.star.beans.PropertyValue\n");
350 aScriptBuffer.append (aArgumentBuffer);
351 aScriptBuffer.append(
"\n");
357 aScriptBuffer.append(
"dispatcher.executeDispatch(document, \"");
358 aScriptBuffer.append(
aURL);
359 aScriptBuffer.append(
"\", \"\", 0, ");
361 aScriptBuffer.append(
"Array()");
364 aScriptBuffer.append( sArrayName );
365 aScriptBuffer.append(
"()");
367 aScriptBuffer.append(
")\n\n");
392 throw css::lang::IndexOutOfBoundsException(
"Dispatch recorder out of bounds" );
402 if (element.getValueType() !=
404 throw css::lang::IllegalArgumentException(
405 "Illegal argument in dispatch recorder",
406 Reference< XInterface >(), 2 );
410 throw css::lang::IndexOutOfBoundsException(
411 "Dispatch recorder out of bounds" );
413 auto pStatement = o3tl::doAccess<css::frame::DispatchStatement>(element);
415 css::frame::DispatchStatement aStatement(
416 pStatement->aCommand,
420 pStatement->bIsComment);
428extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
430 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& )
constexpr OUStringLiteral sServiceName
css::uno::Type const & get()
virtual void SAL_CALL replaceByIndex(sal_Int32, const css::uno::Any &) override
virtual OUString SAL_CALL getRecordedMacro() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL startRecording(const css::uno::Reference< css::frame::XFrame > &xFrame) override
virtual void SAL_CALL recordDispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32) override
DispatchRecorder(const css::uno::Reference< css::uno::XComponentContext > &xSMGR)
virtual sal_Int32 SAL_CALL getCount() override
::std::vector< css::frame::DispatchStatement > m_aStatements
css::uno::Reference< css::script::XTypeConverter > m_xConverter
virtual sal_Bool SAL_CALL hasElements() override
void implts_recordMacro(std::u16string_view aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, bool bAsComment, OUStringBuffer &)
virtual ~DispatchRecorder() override
virtual void SAL_CALL recordDispatchAsComment(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
virtual void SAL_CALL endRecording() override
void AppendToBuffer(const css::uno::Any &aValue, OUStringBuffer &aArgumentBuffer)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_DispatchRecorder_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XTypeConverter > m_xConverter
Sequence< sal_Int8 > aSeq
struct _typelib_TypeDescription typelib_TypeDescription
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
constexpr OUStringLiteral REM_AS_COMMENT
static Sequence< Any > make_seq_out_of_struct(Any const &val)
static void flatten_struct_members(::std::vector< Any > *vec, void const *data, typelib_CompoundTypeDescription *pTD)
constexpr OUStringLiteral sScript