OK, I've now down some tests using
Novel OOo 2.0.2 and vanilla OOo2.0.4
both on Suse linux 10.1

method 1: works only before I reopen the document.
          The control editor show no events attached
method 2: does not work at all
          The control editor show the document:.. stuff but there is an
          error executing the macro due to wrong format
          After I reopen the macro the control editor is "empty"
method 3: works only before I reopen the document.
          The control editor show the vnd.sun... stuff
          After I reopen the macro the control editor is "empty"

what I find strange is that on windoes OOo2.0.4 the vnd.sun.star is not
working, but this is working on linux OOo2.0.4
anopther strnage part is why is not the document:.. macro definition
working?

Christian Andersson wrote:
> Hi there, I have a problem with creating a commandbutton using macro and
> then attaching an event to this button. (OOo 2.0.4, windows 2000)
> 
> I have tried several methods but they all end up not working as I want
> them to.
> 
> the basic function I'm using looks like the following.
> it is only the part [ATTACH_MACRO HERE] that changes for each attempt to
> get it working. (Obs there might be typing errors in the below code,
> just ignore those I'm manuyally copying this)
> 
> 
> Sub createButton(sText, sName, sTag, oCursor, optional macro, optional
> oDocument)
>   if isMissing(oDocument) Then
>     oDocument = ThisComponent
>   end if
>   Dim button, shape, drawpage
>   Dim oSize as new com.sun.star.awt.size
>   Dim oPosition as new com.sun.star.point
> 
>   button = createUnoService("com.sun.star.form.component.CommandButton")
>   button.Label     = sText
>   button.Enabled   = True
>   button.Printable = False
>   button.Name      = sName
>   button.Tag       = sTag
> 
>   shape = oDocument.createInstance("com.sun.star.drawing.ControlShape")
>   oSize.Height = 1000
>   oSize.Width  = 3000
>   oPosition.X  = 0
>   oPosition.Y  = 0
>   shape.setSize(oSize)
>   shape.setPosition(oPosition)
>   shape.LayerName = "Controls"
>   shape.setAnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
>   shape.setControl(button)
>   shape.attach(oCursor)
> 
>   if (!isEmpty(macro)
>     [ATTACH MACRO_HERE]
>   end if
> End Sub
> 
> My first attempt was attaching an actionListener by using the following code
> ----------------------------------
>     Dim oListener
>     oListener = CreateUnoListener( macro,
> "com.sun.star.awt.XActionListener")
>     oDocument.CurrentController().getControl(button).addActionListener(
> oListener )
> ----------------------------------
> ( macro = "doStuff_" and there exist a function called
> "doStuff_actionPerformed")
> 
> and this works, as long as I do not save the document, close it and
> reopen the document, then the button will not work anymore.
> that is it only works as long as I have the document opened.
> When looking at the formcontrol editor I cannot see any events attached
> to the control at any time (before I close and after I open)
> 
> 
> my next attempt was to use the registerScriptEvent
> ----------------------------------
>     Dim id,form
>     Dim oEvent as new com.sun.star.script.ScriptEventDescriptor
>     oEvent.ListenerType = "com.sun.star.awt.XActionListener"
>     oEvent.EventMethod  = "actionPerformed"
>     oEvent.ScriptType   = "Basic"
>     oEvent.ScriptCode   = "document:"+macro
>     form = oDocument.DrawPage.getForms().getByIndex(0)
>     id = form.getCount() -1
>     form.registerScriptEvent(id,oEvent)
> ----------------------------------
> (macro = "Standard.Module1.doStuff" and there exist a function called
> doStuff)
> and this also works, but only as long as _I have the document opened, if
> I save/close/reopen, this does not work anymore.
> When looking at the formcontrol editor I now cann see the event attached
> to the control both before the save and after the save, but looking at
> the "text" that is written in that event, it states the exact same
> string as I wrote in, but this type of string does not match hte type of
> string that gets written if I attach the event manually.
> "document:Standard.Module1.doStuff" compared to
> "vnd.sun.star.script:Standard.Module1.doStuff?language=Basic&location=document"
> 
> my 3rd and last attempt to attachthe macro was the same as the
> registerScriptEvent, but instead of using
>     oEvent.ScriptCode   = "document:"+macro
> 
> I used
> 
>     oEvent.ScriptCode   =
> "vnd.sun.star.script:"+macro+"?Language=Basic&Location=document"
> 
> ie the same code that the form editor puts in there.
> 
> but to my surprise, this did not work at all, not before the save/close
> and not after the reopen..
> 
> I'm going to test more about this, but please if anyone could help me
> getting this working I'd appreciate it..
> 

-- 
Christian Andersson - [EMAIL PROTECTED]

Configuration and Collaboration for OpenOffice.org
Open Framework Systems AS http://www.ofs.no

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to