I got it working, at the bottom of this text there is mny "test script"
to create a button and attach a script to it (that will continue to work
after a reload.

Method 1: NOT WORKING AT ALL, "Incorrect format for script uri"
          the "script" is forgotten after a reload so nothing happens
          when pressing the button
Method 2: WORKING
Method 3: NOT WORKING AT ALL, "Incorrect format for script uri"
          the "script" is remembered after a reload so I get the same
          error message.
Method 4: WORKING
so method2 and 4 was working when I entered the correct values in the
script event. basicly this was just the "scriptType" that needed to be
changed.

method 2:
          scriptType = "StarBasic"   ' not "Basic" or "Script"
          ScriptCode = "document:Standard.Module1.test"
method 4:
          scriptType = "Script"   ' not "StarBasic" or "Basic"
          ScriptCode =
"vnd.sun.star.script:Standard.Module1.test?language=Basic&location=document"

for long term I believe that method 4 is best because that one allows
other languages I think document: only allows starbasic...



Sub createButton(sText, sName, sTag, oCursor, way, 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.awt.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.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
  shape.setControl(button)
  shape.attach(oCursor)

  if not isMissing(macro) then
    Dim oListener
    Dim id,form, oEvent as new com.sun.star.script.ScriptEventDescriptor
        if way=1 then
            ' METHOD 1
            oEvent.ListenerType = "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)
        elseif way=2 then
            ' METHOD 2
            oEvent.ListenerType = "XActionListener"
            oEvent.EventMethod  = "actionPerformed"
            oEvent.ScriptType   = "StarBasic"
            oEvent.ScriptCode   = "document:"+macro
            form = oDocument.DrawPage.getForms().getByIndex(0)
            id = form.getCount() -1
            form.registerScriptEvent(id,oEvent)
        elseif way=3 then
            ' METHOD 3
            oEvent.ListenerType = "XActionListener"
            oEvent.EventMethod  = "actionPerformed"
            oEvent.ScriptType   = "Script"
            oEvent.ScriptCode   = "document:"+macro
            form = oDocument.DrawPage.getForms().getByIndex(0)
            id = form.getCount() -1
            form.registerScriptEvent(id,oEvent)
        elseif way=4 then
            ' METHOD 4
            oEvent.ListenerType = "XActionListener"
            oEvent.EventMethod  = "actionPerformed"
            oEvent.ScriptType   = "Script"
            oEvent.ScriptCode   =
"vnd.sun.star.script:"+macro+"?language=Basic&location=document"
            form = oDocument.DrawPage.getForms().getByIndex(0)
            id = form.getCount() -1
            form.registerScriptEvent(id,oEvent)
        end if
  end if
End Sub


Frank Schönheit - Sun Microsystems Germany wrote:
> Hi Christian,
> 
>> I still cannot see why #2 and #3 is not working though.
> 
> /me too
> 
>> I've now tested this with OOo 2.1 on Suse 10.1 and I get the same rsult
> 
> Did you try a) examining what getScriptEvents tells you when you
> registered an event via UI and b) what is written into the content.xml
> when you write your programmatically-created document?
> 
>> (I' ve created a test document for this if you want to take a look at it
>> yourself..)
> 
> That'd be one of the later resorts :)
> 
> Ciao
> Frank
> 

-- 
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