Hi Frédéric,

> I need to create a checkbox in oowriter document with an external script in

here is a starbasic example how to add a command button into a writer document.

HTH

Oliver

------------------------
Option Explicit

Sub CreateControl

        Dim oDocument as Object
        Dim oView as Object
        Dim oDrawPage as Object
        Dim oController as Object
        Dim oForm as Object
        Dim oEvents(0) as New com.sun.star.script.ScriptEventDescriptor

        Dim oControlShape as Object
        Dim oControlModel as Object
        Dim oSize as New com.sun.star.awt.Size
        Dim oPosition as New com.sun.star.awt.Point

        oDocument = StarDesktop.getCurrentComponent
        oView = oDocument.CurrentController
        
        ' calc document's
        ' oDrawPage = oView.getActiveSheet.DrawPage
        oDrawPage = oDocument.getDrawPage()     
                
        oControlShape = 
oDocument.createInstance("com.sun.star.drawing.ControlShape")

        oSize.Height = 1000
        oSize.Width = 3000
        oPosition.X     = 2000
        oPosition.Y = 3000

        oControlShape.setSize(oSize)
        oControlShape.SizeProtect = True
        oControlShape.setPosition(oPosition)    
        oControlShape.MoveProtect = True
        oControlShape.setPropertyValue("AnchorType", 
com.sun.star.text.TextContentAnchorType.AT_PAGE)
        oControlShape.Name("My Shape")                  ' optional name for 
identification ...

        oControlModel = 
createUNOService("com.sun.star.form.component.CommandButton")
        oControlModel.Name = "My Control"
        oControlModel.Label = "Test"
        oControlModel.FontName = "Arial"
        oControlModel.FontHeight = 10
        oControlModel.Tag = "Hello World !"
        oControlModel.Enabled = True

        oControlShape.setControl(oControlModel)
        oDrawPage.add(oControlShape)

        oController = oView.getControl(oControlModel)
        oController.SetFocus()

        oForm = oDrawPage.getForms.getByIndex(0)

        oEvents(0).ListenerType = "XActionListener"
        oEvents(0).EventMethod  = "actionPerformed"
        oEvents(0).AddListenerParam = ""
        oEvents(0).ScriptType = "StarBasic"
        oEvents(0).ScriptCode = "application:Standard.Module1.Test"
        
        oForm.registerScriptEvent(0, oEvents(0))

        Call XToggleDesignMode(oDocument)

End Sub


Sub Test(oEvt)

        Dim oControlModel as Object

        oControlModel = oEvt.Source.Model
        MsgBox oControlModel.Tag

End Sub

Sub XToggleDesignMode(oDocument as Object)              ' from the Tools 
Library ...

        Dim aTransformer as Object
        Dim oDispatch as Object
        Dim oFrame as Object

        Dim aSwitchMode as New com.sun.star.util.URL
    Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue

        aSwitchMode.Complete = ".uno:SwitchControlDesignMode"

        aTransformer = createUnoService("com.sun.star.util.URLTransformer")
        aTransformer.parseStrict(aSwitchMode)

'       Print aTransformer.getPresentation(aSwitchmode, True)
        oFrame = oDocument.currentController.Frame

        oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name, 63)
        oDispatch.dispatch(aSwitchMode, aEmptyArgs())
End Sub

-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to