https://bugs.documentfoundation.org/show_bug.cgi?id=166496

--- Comment #7 from Mubeen <mubee...@yahoo.com> ---
We have essentially wrapped LibreOffice's executeDispatch function, which we
call UNO_ExecuteDispatch, so it resembles the VBA-like macro LibreOffice
creates when using the Macro Recorder.


For example to create a table in Writer, the VBA would look like this: 

rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "TableName"
args1(0).Value = ""
args1(1).Name = "Columns"
args1(1).Value = 40
args1(2).Name = "Rows"
args1(2).Value = 4
args1(3).Name = "Flags"
args1(3).Value = 9

dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, args1())



Our with our C++ wrappers it looks like this:

void InsertTable(int iRows, int iCols)
{
        Sequence<PropertyValue> args1(4);
        UNO_SeqArgMaker(args1[0], "TableName", "");
        UNO_SeqArgMaker(args1[1], "Columns", ( sal_Int32 ) iCols);
        UNO_SeqArgMaker(args1[2], "Rows", ( sal_Int32 ) iRows);
        UNO_SeqArgMaker(args1[3], "Flags", ( sal_Int8 ) 9);

        UNO_ExecuteDispatch(".uno:InsertTable", "", 0, &args1);
}

-----------------------------------------------------------------------

bool UNO_ExecuteDispatch(
std::string strUNOCommandURL, 
std::string TargetFrameName, 
::sal_Int32 SearchFlags, 
const::css::uno::Sequence<::css::beans::PropertyValue>* arguments)
{
        try
        {
                const::css::uno::Sequence<::css::beans::PropertyValue>
array(0);
                if ( arguments == nullptr )
                        arguments = &array;
                m_rDispatchService->executeDispatch(m_rDispatchReceivingWindow,
                                                  
StringToOUString(strUNOCommandURL),
                                                  
StringToOUString(TargetFrameName),
                                                   SearchFlags,
                                                   *arguments);
                return true;
        }
        catch ( ... )
        {
                return false;
        }
}



// SEQUENCE ARRAY HELPER FUNCTIONS
void UNO_SeqArgMaker(com::sun::star::beans::PropertyValue &argIndexValue,
std::string name, sal_Int32 value)
{
        argIndexValue.Name = StringToOUString(name);
        argIndexValue.Value <<= value;
}

void UNO_SeqArgMaker(com::sun::star::beans::PropertyValue &argIndexValue,
std::string name, sal_Int16 value)
{
        argIndexValue.Name = StringToOUString(name);
        argIndexValue.Value <<= value;
}

void UNO_SeqArgMaker(com::sun::star::beans::PropertyValue &argIndexValue,
std::string name, sal_Int8 value)
{
        argIndexValue.Name = StringToOUString(name);
        argIndexValue.Value <<= value;
}


void UNO_SeqArgMaker(com::sun::star::beans::PropertyValue &argIndexValue,
std::string name, sal_Bool value)
{
        argIndexValue.Name = StringToOUString(name);
        argIndexValue.Value <<= value;
}

void UNO_SeqArgMaker(com::sun::star::beans::PropertyValue &argIndexValue,
std::string name, std::string value)
{
        argIndexValue.Name = StringToOUString(name);
        argIndexValue.Value <<= StringToOUString(value);
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to