Page 1 of 1

[Solved] Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Mon Jul 02, 2012 4:59 pm
by saleem145
Hello,

I am trying to compile my first add in for Open Office Calc written in C++. Once I have this working I hope to modify it to suit my needs.

The add-in in question is

http://wiki.services.openoffice.org/wik ... alc_Add-In

The good news is I have it compiling after making quite a few changes to the Makefile. The problem is I do not know how to use it -- the instructions don't seem to work.

In

/Applications/OpenOffice.org.app/Contents/program

I have placed two files

libRNG.dylib
RNG.rdb

Next I have edited the fundamentalrc file. The last two lines in the file are

Code: Select all

URE_MORE_SERVICES=${${OOO_BASE_DIR}/program/fundamentalbasisrc:URE_MORE_SERVICES} $ORIGIN/services.rdb $ORIGIN/RNG.rdb
URE_MORE_TYPES=${${OOO_BASE_DIR}/program/fundamentalbasisrc:URE_MORE_TYPES} $ORIGIN/RNG.rdb
I have edited the Main Macro to be

Code: Select all

Sub Main

	mgr = getProcessServiceManager()
	o = mgr.createInstance("org.openoffice.sheet.addin.RNG")
	MsgBox o.expo(10)

End Sub
When I run it I get the following error

Code: Select all

Basic RunTime Error
Object Variable Not Set
When I look at the value of the variable o it is set to NULL. Which means it was unable to create an instance of RNG.

So probably some installation issue.

Saleem

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Tue Jul 03, 2012 3:29 am
by Charlie Young
I tried the simple add-in a while back, and it didn't work for me either. I never worried about it too much, I already had the so-called Complete AddIn working, and that is much more useful since it provides a shell for writing extension functions. Even that is badly outdated though, but it is worth pursuing if you want to learn how to do it. I and probably others here can help with that if you have problems. It is not necessary to implement XAddin, but if you do it that way we can show you how to bring it up to snuff.

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Tue Jul 03, 2012 4:40 pm
by saleem145
Per your advice I was able to compile "Complete Addin" and have a call to it from OO Basic working.

Code: Select all

Sub demonstrateSimpleComponent

	Dim oSimpleComponent
	oSimpleComponent = CreateUnoService( "my_module.MyService1" )
	msgbox oSimpleComponent.methodOne( "Component succesfully instantiated and running!" )

End Sub
This works correctly. I would now like to be able to call MethodOne and MethodTwo from a cell command. That is in a cell enter a formula like =methodOne("This is a test") or =methodTwo() and have them work.

I tried to add in a description.xml, an xcu and edit the manifest.xml to make this happen.

My manifest.xml is below (I have added in an entry for the xcu file)

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"
                       manifest:full-path="CppComponent.uno.rdb"/>
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" 
		       manifest:full-path="CalcAddIn.xcu"/> 
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-components;platform=MacOSX_x86"
                       manifest:full-path="CppComponent.components"/>
</manifest:manifest>
Next I created the CalcAddIn.xcu file

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcAddIns" oor:package="org.openoffice.Office">
<node oor:name="AddInInfo">
<node oor:name="my_module.MacOSX_x86.MyService2Impl" oor:op="replace">
<node oor:name="AddInFunctions">
  <node oor:name="methodOne" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">methodOne</value></prop>
    <prop oor:name="Description"><value xml:lang="en">Test Method One.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <prop oor:name="CompatibilityName"><value xml:lang="en">AutoAddIn.my_module.methodOne</value></prop>
    <node oor:name="Parameters">
      <node oor:name="val" oor:op="replace">
        <prop oor:name="DisplayName"><value xml:lang="en">val</value></prop>
        <prop oor:name="Description"><value xml:lang="en">The string.</value></prop>
      </node>
    </node>
  </node>
  <node oor:name="methodTwo" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">methodTwo</value></prop>
    <prop oor:name="Description"><value xml:lang="en">Test Method Two.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <prop oor:name="CompatibilityName"><value xml:lang="en">AutoAddIn.my_module.methodTwo</value></prop>
    <node oor:name="Parameters">
    </node>
  </node>
</node>
</node>
</node>
</oor:component-data>
Finally I edited the description file

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006" 
xmlns:d="http://openoffice.org/extensions/description/2006" 
xmlns:xlink="http://www.w3.org/1999/xlink"> 

<dependencies> 
	<OpenOffice.org-minimal-version value="2.4" d:name="OpenOffice.org 2.4"/> 
</dependencies> 

<identifier value="my_module" /> 
<version value="0.25" />
<display-name><name lang="en">Complete cpp component.</name></display-name>
<publisher><name xlink:href="http://www.doobiecompany.com" lang="en">Doobie Company</name></publisher>

</description> 
Finally I recreated the oxt file. In the function wizard it thinks methodOne does not take in any parameters. So my guess is there is some problem with the XCU.

Also =methodOne("Test") returns Err:504
=methodTwo() returns #NULL!

Any suggestions?? Thanks for your help in advance.

Saleem

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Tue Jul 03, 2012 8:01 pm
by Charlie Young
I don't see anything wrong with the methodOne stuff in your CalcAddin.xcu, though it is easy to go awry somewhere and not see it right away.

First thing though, did you restart Office after installing the extension?

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Tue Jul 03, 2012 8:12 pm
by saleem145
Hi Charlie,

Would it be possible for you to try to generate an XCU at your end and see if it works. I am just using the stock Complete Add-in example with no changes....I would really appreciate your help on this!!

Saleem

There are some things I do not understand about the XCU format -- I am still trying to find documentation on this so any insights would be appreciated.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcAddIns" oor:package="org.openoffice.Office">
<node oor:name="AddInInfo">
<node oor:name="my_module.MacOSX_x86.MyService2Impl" oor:op="replace">
<node oor:name="AddInFunctions">
Are the tag values CalcAddIns, AddInInfo, my_module.MacOSX_x86.MyService2Impl, AddInFunctions correct?? I am not sure where they come from and are just a guess.

Code: Select all

 <node oor:name="methodOne" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">methodOne</value></prop>
    <prop oor:name="Description"><value xml:lang="en">Test Method One.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <prop oor:name="CompatibilityName"><value xml:lang="en">AutoAddIn.my_module.methodOne</value></prop>
Is the tag value for "CompatibilityName" correct??

Code: Select all

    <node oor:name="Parameters">
      <node oor:name="val" oor:op="replace">
Is name="val" correct??

Code: Select all

       <prop oor:name="DisplayName"><value xml:lang="en">val</value></prop>
        <prop oor:name="Description"><value xml:lang="en">The string.</value></prop>
      </node>
    </node>
  </node>
  <node oor:name="methodTwo" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">methodTwo</value></prop>
    <prop oor:name="Description"><value xml:lang="en">Test Method Two.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <prop oor:name="CompatibilityName"><value xml:lang="en">AutoAddIn.my_module.methodTwo</value></prop>
    <node oor:name="Parameters">
    </node>
  </node>
</node>
</node>
</node>
</oor:component-data>
Wonder what the implications of method2 returning NULL are??

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Tue Jul 03, 2012 9:20 pm
by Charlie Young
My own implementation of the Complete Add-In is a bit disheveled, and I don't actually use it. Like I said, it's mostly useful for getting a shell set up. I have it with both XAddin and CalcAddin.xcu, which has the messy result that if I install it, the method names are all duplicated in the function wizard. They do work, however!

My CalcAddin.xcu looks like

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcAddIns" oor:package="org.openoffice.Office">
<node oor:name="AddInInfo">
<node oor:name="mymodule.my_sc_implementation.MyService2Impl" oor:op="replace">
<node oor:name="AddInFunctions">
  <node oor:name="methodOne" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">method1</value></prop>
    <prop oor:name="Description"><value xml:lang="en">add Message.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <node oor:name="Parameters">
      <node oor:name="val" oor:op="replace">
        <prop oor:name="DisplayName"><value xml:lang="en">val</value></prop>
        <prop oor:name="Description"><value xml:lang="en">String.</value></prop>
      </node>
    </node>
  </node>
  <node oor:name="methodTwo" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">method2</value></prop>
    <prop oor:name="Description"><value xml:lang="en">add Message.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <node oor:name="Parameters">
      <node oor:name="val" oor:op="replace">
        <prop oor:name="DisplayName"><value xml:lang="en">val</value></prop>
        <prop oor:name="Description"><value xml:lang="en">String</value></prop>
      </node>
    </node>
  </node>
  <node oor:name="methodThree" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">method3</value></prop>
    <prop oor:name="Description"><value xml:lang="en">sum cell range</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <node oor:name="Parameters">
      <node oor:name="aValList" oor:op="replace">
        <prop oor:name="DisplayName"><value xml:lang="en">aValList</value></prop>
        <prop oor:name="Description"><value xml:lang="en">Number Code.</value></prop>
      </node>
    </node>
	</node>
	<node oor:name="methodFour" oor:op="replace">
    <prop oor:name="DisplayName"><value xml:lang="en">method4</value></prop>
    <prop oor:name="Description"><value xml:lang="en">matrix tricks</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <node oor:name="Parameters">
      <node oor:name="aValList" oor:op="replace">
        <prop oor:name="DisplayName"><value xml:lang="en">aValList</value></prop>
        <prop oor:name="Description"><value xml:lang="en">Cell Range.</value></prop>
      </node>
    </node>
  </node>
</node>
</node>
</node>
</oor:component-data>

I'm not using the compatability names at all, I think that's just for getting the equivalent add-in for Excel -- which doesn't exist anyway, I don't think. I think the variable names need to agree with the .idl file, but I'm not sure whether the names in the c++ program need to agree, I always just use the same names as in the .idl anyway (the data types definitely have to match!).

A key thing is the "AddInInfo," and mine is probably different from yours.

Code: Select all

<node oor:name="AddInInfo">
<node oor:name="mymodule.my_sc_implementation.MyService2Impl" oor:op="replace">
That comes from this function in the c++:

Code: Select all

static OUString getImplementationName_MyService2Impl()
{
	static OUString *pImplName = 0;
	if( ! pImplName )
	{
//		MutexGuard guard( Mutex::getGlobalMutex() );
		if( ! pImplName )
		{
			static OUString implName( RTL_CONSTASCII_USTRINGPARAM("mymodule.my_sc_implementation.MyService2") );
			pImplName = &implName;
		}
	}
	return *pImplName;
}

That also shows up in the .rdb file.
 Edit: <node oor:name="mymodule.my_sc_implementation.MyService2Impl" oor:op="replace"> may or may not require the Impl on the end. Though my Complete Add-In example has Impl, later things I've done do without it. 

Re: Calc/Add-In/Simple Calc Add-In on Mac OS X

Posted: Wed Jul 04, 2012 1:42 am
by saleem145
I have it working. AddInInfo was not set correctly!! Thanks for your help. I really appreciate it!!

Saleem