Hi Ariel,

On 08.11.2012 20:37, Ariel Constenla-Haile wrote:
> On Thu, Nov 08, 2012 at 02:02:08PM +0100, Rony G. Flatscher wrote:
>> O.K., it is at the end of this e-mail. Correction: the kudos for
>> finding it goes to Christoph *Jopp* still from Munich and a great AOO
>> hacker! :)
>>>
>>> Wish I was there!
>> Yes, that would have been nice to meet in person!
>>
>> ---
>>
>> The following was created yesterday and added to todays presentation
>> "Scripting Apache OpenOffice", which should be uploaded by ASF (no URL
>> yet).
>>
>> The programming language is ooRexx (http://www.ooRexx.org) which is
>> powerful yet its syntax is very easy and looks like pseudo code. It
>> has a proper message operator (tilde: ~), left of it is the receiving
>> object right of it is the message name (sometimes with arguments in
>> round parenthesis).
>>
>> The logic needed can be found in the routine addItem(), dumpItem()
>> demonstrates how to iterate over an impress XText and learn the
>> outline level in addition:
>>
>> xDesktop=uno.createDesktop() -- bootstrap & get access to
>> XDesktop xcl=xDesktop~XComponentLoader -- get
>> XComponentLoader interface
>>
>> uri="private:factory/simpress" -- new simpress document
>> doc=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)
>>
>> xDrawPages = doc~XDrawPagesSupplier~getDrawPages -- get
>> DrawPages
>>
>> xDrawPage=xDrawPages~getByIndex(0) -- get first (empty) page
>> xDrawPage~XPropertySet~setPropertyValue("Layout", box("short",0))
>> -- "Title Slide" xShapes=xDrawPage~XShapes -- get access
>> to its shapes xShapes~getByIndex(0)~XText~setString("ApacheCon
>> Europe 2012") xShapes~getByIndex(1)~XText~setString("Scripting
>> Apache OpenOffice")
>>
>> xDrawPage=xDrawPages~~insertNewByIndex(1)~getByIndex(1) -- insert
>> at end, get access
>> xDrawPage~XPropertySet~setPropertyValue("Layout", box("short",1))
>> -- "Title Content" xShapes=xDrawPage~XShapes -- get
>> access to its shapes
>> xShapes~getByIndex(0)~XText~setString("Scripting Apache
>> OpenOffice")
>>
>> xText=xShapes~getByIndex(1)~XText -- content's XText call
>> addItem xText, "First", 0 -- add string, determine
>> level call addItem xText, "Explored by many", 0 call addItem
>> xText, "Kudos! go to", 1 call addItem xText, "Christoph
>> Jopp!", 1 call addItem xText, "On 2012-11-07", 0, .false
>>
>> doc~XModifiable~setModified(.false)
>> doc~XPresentationSupplier~getPresentation~~bsf.dispatch("start")
>> -- start presentation
>>
>> say "now dumping infos about second page's content XText:" call
>> dumpItems xText
>>
>> ::requires UNO.CLS -- get UNO support
>>
>> ::routine addItem -- adds string at the given
>> (0-based outline) level use arg xText, string, level,
>> bNewParagraph=.true
>>
>> xTR=xText~XTextRange~getEnd -- get end, a XTextRange
>> xTR~XPropertySet~setPropertyValue("NumberingLevel",level) -- set
>> XTextRange level
>>
>> xTR~setString(string) -- set string
>>
>> if bNewParagraph=.true then -- add new paragraph
>> xTR~getEnd~setString("0a"x) -- add linefeed character -> new
>> paragraph
>>
>>
>> ::routine dumpItems -- show level and string from
>> XText use arg xText
>>
>> enum=xText~XEnumerationAccess~createEnumeration -- enumerate
>> paragraphs do i=1 while enum~hasMoreElements
>> xtr=enum~nextElement~XTextRange -- we need XTextRange's string
>> & properties
>> nl=xtr~XPropertySet~getPropertyValue("NumberingLevel") say
>> " item #" i": NumberingLevel="pp(nl) pp(xtr~getString) end
>>
>> Should anyone have questions, please come forward!
>
> I was digging into this the other days, to give a sample, but I've found
> it somehow broken. Could you insert more than one paragraph in the same
> shape, and set each paragraph to a different numbering level?
Yes, that is what the above code does. Maybe you look at the presentation 
slides at
<http://wi.wu.ac.at/rgf/rexx/misc/ApacheConEurope12/>, where the code is syntax 
highlighted (using
vim's rexx syntax) and therefore easier to read.

In the presentation <FlatscherScriptingAOO-ACE12-20121108.pdf> go to page # 81 
("Presentation
Example 2"), where two slides are created and the indenting is done with a tab 
character, no bullets
whatsoever. Just page down to see the code and the Impress slides.

Then scroll forward to page # 85 ("Presentation Example 3") which is the code I 
posted, but is
followed with a screenshot of the second page, showing that one can insert more 
than one paragraph
and control the outline level individually using the "NumberLevel" property on 
the XRangeText
(important!).

Also, you cona use insertString() and insertControlCharacter() instead of the 
setString()-methods
used above. Here is the code of the addItem-routine which uses the 
insertString() methods instead:

    ::routine addItem                   -- adds string at the given (0-based 
outline) level
      use arg xText, string, level, bNewParagraph=.true

      xTR=xText~XTextRange~getEnd       -- get end, a XTextRange
      xTR~XPropertySet~setPropertyValue("NumberingLevel",level) -- set 
XTextRange level

      xTextCursor=xText~createTextCursor~XTextCursor
      xText~insertString(xTextCursor,string,.false)

      if bNewParagraph=.true then       -- add new paragraph
         xText~insertControlCharacter(xTextCursor,0,.false)     -- 
paragraph_break is the value 0,
could also look it up

Bothe versions were working.

If you need a Java version, then please let me know and I will create one 
tomorrow and post it.
(The ooRexx version is actually using the Java bridget. So whenever you see the 
name of an interface
being sent as a message you would need to do a queryInterface() in Java 
instead.)


> In my test, only the first paragraph gets the numbering level, it does
> not work for subsequent paragraphs (added by inserting a para. break
> control character). And, the numbering level inserted via API is not
> reflected on the Outline view.
With the above code the Outline view would show levels correctly. However the 
little preview slides
on the left-hand side when the "Normal" tab is selected would not be updated to 
reflect the last
inserted slide. Clicking on the other tabs ("Outline", "Notes", "Handout", 
"Slide Sorter") will
eventually cause the "Slides" pane in "Normal" view to be updated.

> Another issue: how to set an animation for each paragraph?
Hmm, good question! The xTextRange seems to only implement the services
com.sun.star.style.CharacterProperties+com.sun.star.style.CharacterPropertiesComplex+com.s
un.star.style.CharacterPropertiesAsian (in SvxUnoTextRange).

Will have to start another research round, once I have settled and again a 
little bit of time on my
hands.

> Yet another one, setting the draw page Layout has effect, but is not
> reflected in the UI: when you select a page with a specific layout, the
> "Layout" taks pane should reflect this by selecting the respective
> level; that's not the case.
Hmm, it was possible to set the layouts and the UI would select them in the 
Layout pane on the right
hand side, except for the last layout in the layout pane (# 33, "Title, 6 
Content").

The layout numbers I could research are:

  * 0: "Title Slide"
  * 1: "Title Content"
  * 3: "Tilte, 2 content"
  * 19: "Title Only"
  * 32: "Centered Text"
  * 15: "Title, 2 content and Content"
  * 12: "Title, Content and 2 Content"
  * 16: "Title, 2 Content over Content"
  * 14: "Title, Content over Content"
  * 18: "Title, 4 Content"
  * 33, "Title, 6 Content"
  * 20: "Blank slide"

HTH,

---rony


Reply via email to