Simplified Libreoffice API

Mindaugas mindauga at freemail.lt
Mon Mar 11 10:23:05 PDT 2013


 I like and use hard Libreoffice scripting  possibilities being
non-programmer, but I think that Libreoffice API is too much complicated for
non-professional scripters. For example, I can't understand benefits of
visible paradigm model-controller-frame. I'll try explain. I have one text
field in spreadsheet and I want to write text to this field, change size of
this field and set focus to this field. Now my code must be similar to this:

Sub Main
        'write text - model
        Sheet = ThisComponent.Sheets.getByIndex(0)
        Control = Sheet.DrawPage.Forms.getByIndex(0).getByName("txtField")
        Control.Text = "Test"
        Sub Main
        'write text - model
        Sheet = ThisComponent.Sheets.getByIndex(0)
        Control = Sheet.DrawPage.Forms.getByIndex(0).getByName("txtField")
        Control.Text = "Test"
       
        'change size -frame
    for i=0 to Sheet.DrawPage.getCount()-1
    Shape = Sheet.DrawPage.getByIndex(i)
        sControl = Shape.getControl()
        if sControl.getName() = "txtField" then sShape = Shape
    next i
    Dim Size as new com.sun.star.awt.Size
        Size.Height = 1000
        Size.Width = 8000
    sShape.setSize(Size)
   
    'set focus - controller
    Controller = ThisComponent.getCurrentController()
    Model =
Controller.getActiveSheet().DrawPage.Forms.getByIndex(0).getByName("txtField")
   cControl = Controller.getControl(Model)
   cControl.setFocus()
   
End Sub

But I think, that next code would be more elegant, clear and simple:

Sub Main

        Sheet = ThisComponent.Sheets.getByIndex(0)
        Control = Sheet.Controls.getByName(“txtField”)
        Control.Text = “Test”
        Control.Height = 1000
        Control.Width = 8000
        Control.setFocus()

End Sub
       
I can't understand, for example, why we everywhere  use a form
Sheets.getByName (or getByIndex), Forms.getByName(or getByIndex) etc but we
can't use Cells.getByName (or getByPosition), we have function
getCellByPosition instead (and don't have getCellByName). On the other hand
we have function getCellByName and don't have getCellByPosition for cells in
text document tables.

I can't understand why for filling list in ListBox control in dialog we use 
model.stringitemlist property or additem() and additems() methods,  but for
the same control in form we must use stringitemlist and insertitem(). Why in
additem() we have the item in first argument  and the position in second and
vice versa in insertitem() - the position in first, item in second and some
unclear third argument.

I can't  understand what benefits we get when we use that complicated method
of creating new objects with createinstance(“com.sun.star......). For
example instead of

        new_sheet = doc.createinstance(“com.sun.star.sheet.Spreadsheet”)
        Doc.Sheets.insertByName(“MySheet”,new_sheet)

why it can't be simple:

        Doc.Sheets.insertNewSheet(“MySheet”)  

or similar.

Etc etc etc.

I understand that changing of API is very problematic for compatibility with
old scripts but may be we can have two API – old for geeks and new
simplified  for dummies like me.



Mindaugas





--
View this message in context: http://nabble.documentfoundation.org/Simplified-Libreoffice-API-tp4043112.html
Sent from the Dev mailing list archive at Nabble.com.


More information about the LibreOffice mailing list