Question ad Impress: inserting text using the content's layout formatting, howto

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher
When working interactively (via the GUI) with Impress it is fairly easy and straightforward to enter
text like this in the (usually) bulleted placeholder area of the content part:

  * first praragraph
      o indented under first para
      o indented after second para
  * second paragraph
      o indented under second para
          + indented one level more
  * third paragrpah

Trying to do the same programmatically (e.g. via Java, C++) has not been possible for me so far. The
best I could arrive at was fetching the correct XShape with a ShapeType of
"com.sun.star.presentation.OutlinerShape" and using the XText setString() method to set text.
However, the result is not formatted according to the content's outline layout! :(

So far, I have not been successful in finding the corners (interfaces, properties, or whatever is
needed) where one becomes able to insert text and determine what outline level it should be placed
at within the OutlinerShape.

Even tried to get via the StyleFamily the "Default" one which contains XStyles "outline1" through
"outline9" and assign e.g. the XStyle "outline1" to the OutlinerShape (property "Style") without any
effects.

Also googling for Java, C++ or AOO/OOO Basic examples yielded no results so far.

Also trying to get at the functionality by recording macros to get at the dispatches does not work
as simpress does not allow for recording macros. :(

---

So does anyone know or have samples that would demonstrate how to create two or three simple slides
with bulleted text with different outlines?
(Preferably also showing how to add custom animation to each outline text paragraph in these slides?)

TIA for any hints/insights/samples,

---rony

Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher (Apache)
Hi there,

here at ApacheCon Europe 2012 (Sinsheim) Christoph Lipp from Munich solved the mystery today!

In Impress you need to use a XTextRange and set one of its properties named "NumberLevel" to a value
between 0 and 8.

After learning the result of his research and experiments I have added a nutshell example
demonstrating this (also reading and determining the defined NumberLevel using an XEnumerationAccess
as no XParagraphCursor is available) to my presentation tomorrow ("Scripting Apache OpenOffice")
you can fetch that presentation's PDF to see a working example, once it becomes available.

If there is interest, I could also post that nutshell example here.

---rony

P.S.: It has been a great and interesting conference!


On 02.11.2012 17:03, Rony G. Flatscher wrote:

> When working interactively (via the GUI) with Impress it is fairly easy and straightforward to enter
> text like this in the (usually) bulleted placeholder area of the content part:
>
>   * first praragraph
>       o indented under first para
>       o indented after second para
>   * second paragraph
>       o indented under second para
>           + indented one level more
>   * third paragrpah
>
> Trying to do the same programmatically (e.g. via Java, C++) has not been possible for me so far. The
> best I could arrive at was fetching the correct XShape with a ShapeType of
> "com.sun.star.presentation.OutlinerShape" and using the XText setString() method to set text.
> However, the result is not formatted according to the content's outline layout! :(
>
> So far, I have not been successful in finding the corners (interfaces, properties, or whatever is
> needed) where one becomes able to insert text and determine what outline level it should be placed
> at within the OutlinerShape.
>
> Even tried to get via the StyleFamily the "Default" one which contains XStyles "outline1" through
> "outline9" and assign e.g. the XStyle "outline1" to the OutlinerShape (property "Style") without any
> effects.
>
> Also googling for Java, C++ or AOO/OOO Basic examples yielded no results so far.
>
> Also trying to get at the functionality by recording macros to get at the dispatches does not work
> as simpress does not allow for recording macros. :(
>
> ---
>
> So does anyone know or have samples that would demonstrate how to create two or three simple slides
> with bulleted text with different outlines?
> (Preferably also showing how to add custom animation to each outline text paragraph in these slides?)
>
> TIA for any hints/insights/samples,
>
> ---rony
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Andrew Pitonyak

On 11/07/2012 05:40 PM, Rony G. Flatscher (Apache) wrote:
> If there is interest, I could also post that nutshell example here.
Please post the example :-)

Wish I was there!

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php

Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher

On 08.11.2012 03:26, Andrew Douglas Pitonyak wrote:
>
> On 11/07/2012 05:40 PM, Rony G. Flatscher (Apache) wrote:
>> If there is interest, I could also post that nutshell example here.
> Please post the example :-)
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!

---rony

Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Ariel Constenla-Haile-2
Hi Rony,

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?

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.

Another issue: how to set an animation for each paragraph?

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.

Impress API seems broken at several levels.


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher
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 | Threaded
Open this post in threaded view
|

The Java transcription ... (Re: Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher
In reply to this post by Ariel Constenla-Haile-2
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?
>
> 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.
>
> Another issue: how to set an animation for each paragraph?
>
> 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.
>
> Impress API seems broken at several levels.
in the case that you need a pure Java version of the above ooRexx code, here is a transcription.

In order to run the following program you need to compile them having access to the AOO jar-files
juh.jar and jurt.jar (both in URE/java) and ridl.jar and unoil.jar (both in Basis/program/classes).

    import com.sun.star.uno.UnoRuntime;

    import com.sun.star.beans.PropertyValue;
    import com.sun.star.beans.XPropertySet;

    import com.sun.star.comp.helper.Bootstrap;

    import com.sun.star.frame.XDesktop;

    import com.sun.star.text.XText;
    // import com.sun.star.text.XTextCursor;
    import com.sun.star.text.XTextRange;

    import com.sun.star.container.XEnumerationAccess;
    import com.sun.star.container.XEnumeration;
    import com.sun.star.frame.XComponentLoader;

    import com.sun.star.drawing.XDrawPage;
    import com.sun.star.drawing.XDrawPages;
    import com.sun.star.drawing.XDrawPagesSupplier;

    import com.sun.star.uno.XComponentContext;
    import com.sun.star.lang.XComponent;

    import com.sun.star.drawing.XShape;
    import com.sun.star.drawing.XShapes;

    import com.sun.star.util.XModifiable;
    import com.sun.star.presentation.XPresentationSupplier;

    import com.sun.star.comp.helper.BootstrapException;
    import com.sun.star.uno.Exception;
    import com.sun.star.beans.UnknownPropertyException;
    import com.sun.star.beans.PropertyVetoException;
    import com.sun.star.lang.IllegalArgumentException;
    import com.sun.star.lang.WrappedTargetException;
    import com.sun.star.container.NoSuchElementException;

    class Simpress3
    {
        public static void main (String args[]) throws BootstrapException, Exception
        {
            XComponentContext xContext=Bootstrap.bootstrap();   // create a fully initialized local
XComponentContext
            String service   ="com.sun.star.frame.Desktop";     // OOo Desktop UNO component service
            Object  desktop  =xContext.getServiceManager().createInstanceWithContext(service,xContext);
            XDesktop xDesktop=(XDesktop) UnoRuntime.queryInterface(XDesktop.class,desktop);

            XComponentLoader xcl=(XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class,xDesktop);
            String uri="private:factory/simpress";              // new simpress document
            XComponent doc=xcl.loadComponentFromURL(uri,"_blank",0, new PropertyValue[0]);

                // get XDrawPages
            XDrawPages xDrawPages=((XDrawPagesSupplier)
UnoRuntime.queryInterface(XDrawPagesSupplier.class,doc)).getDrawPages();

                // work on first XDrawPage (first slide)
            XDrawPage xDrawPage=(XDrawPage)
UnoRuntime.queryInterface(XDrawPage.class,xDrawPages.getByIndex(0));   // get first (empty) page

            ((XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,xDrawPage)).setPropertyValue("Layout",0); // "Title Slide"
            XShapes xShapes=(XShapes) UnoRuntime.queryInterface(XShapes.class,xDrawPage);

            XShape xs=(XShape) UnoRuntime.queryInterface(XShape.class,xShapes.getByIndex(0));
            ((XText) UnoRuntime.queryInterface(XText.class,xs)).setString("ApacheCon Europe 2012");
            xs=(XShape) UnoRuntime.queryInterface(XShape.class,xShapes.getByIndex(1));
            ((XText) UnoRuntime.queryInterface(XText.class,xs)).setString("Scripting Apache
OpenOffice");

                // create and work on a second XDrawPage (second slide)
            xDrawPages.insertNewByIndex(1);
            xDrawPage=(XDrawPage)
UnoRuntime.queryInterface(XDrawPage.class,xDrawPages.getByIndex(1)); // insert at end, get access
            ((XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,xDrawPage)).setPropertyValue("Layout",1); // "Title
Content"

            xShapes=(XShapes) UnoRuntime.queryInterface(XShapes.class,xDrawPage);
            xs=(XShape) UnoRuntime.queryInterface(XShape.class,xShapes.getByIndex(0));
            ((XText) UnoRuntime.queryInterface(XText.class,xs)).setString("Scripting Apache
OpenOffice");

            XText xText=(XText) UnoRuntime.queryInterface(XText.class,xShapes.getByIndex(1));   //
content's XText

            addItem(xText, "First",            0, true);
            addItem(xText, "Explored by many", 0, true);
            addItem(xText, "Kudos! go to",     1, true);
            addItem(xText, "Christoph Jopp!",  1, true);
            addItem(xText, "On 2012-11-07",    0, false);

            ((XModifiable) UnoRuntime.queryInterface(XModifiable.class,doc)).setModified(false);
                // start presentation
            ((XPresentationSupplier)
UnoRuntime.queryInterface(XPresentationSupplier.class,doc)).getPresentation().start();

            System.out.println("now dumping infos about second page's content XText:");
            dumpItems(xText);

            System.exit(0);
        }

        static void addItem(XText xText, String string, int level, boolean bNewParagraph) throws
UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException
        {
            XTextRange xTR=((XTextRange)
UnoRuntime.queryInterface(XTextRange.class,xText)).getEnd(); // get end, a XTextRange
                // set TextRange level
            ((XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,xTR)).setPropertyValue("NumberingLevel",new
Short((short)level));

            xTR.setString(string);                  // set string

            if (bNewParagraph==true)                // add new paragraph
            {
                xTR.getEnd().setString("\n");       // add linefeed character -> new paragraph
            }
        }

        static void dumpItems(XText xText) throws NoSuchElementException, UnknownPropertyException,
WrappedTargetException
        {
                // enumerate paragraphs
            XEnumeration enuMM=(XEnumeration) ((XEnumerationAccess)
UnoRuntime.queryInterface(XEnumerationAccess.class,xText)).createEnumeration();
            int i=0;
            while (enuMM.hasMoreElements())
            {
                    // we need XTextRange's string & properties
                XTextRange
xtr=(XTextRange)UnoRuntime.queryInterface(XTextRange.class,enuMM.nextElement());
                Object nl=((XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,xtr)).getPropertyValue("NumberingLevel");
                System.out.println("     item # "+(++i)+": NumberingLevel=["+nl+"]
["+xtr.getString()+"]");
            }
        }
    }

HTH,

---rony







Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Ariel Constenla-Haile-2
In reply to this post by Rony G. Flatscher
Hi Rony,

On Fri, Nov 09, 2012 at 04:33:31PM +0100, Rony G. Flatscher wrote:
> > 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.

I've found my old animation example
http://openoffice.2283327.n4.nabble.com/UNO-Java-adding-a-motion-path-Animation-to-an-XShape-in-Impress-td2772586.html
with a motion path.

Setting an animation effect to each numbering level in a shape's text is
posible with a com.sun.star.presentation.ParagraphTarget see
http://people.apache.org/~arielch/api/AnimationDemo.zip

My original example (AnimationDemo.java in that zip) was SMIL-correct,
but the effect wasn't displayed on the UI; in order to display it I had
to add some extra parallel time containers; it looks like Impress UI
understands only

<anim:par presentation:node-type="timing-root">
    <anim:seq presentation:node-type="main-sequence">
        <anim:par smil:begin="next">
            <anim:par smil:begin="0s">
                <anim:par                  <--- the actual effect
                </anim:par>
            </anim:par>
        </anim:par>
   </anim:seq>
</anim:par>

I was simply adding a parallel time container to the main sequence. This
works and is SMIL-correct, but isn't displayed in the task panel.

And if you look at the numbering level example, I use a simple text
shape and set the levels; this way, the levels are not displayed on the
Outline view (even if I set the text shape style to outline). I'll have
to investigate what is expecting Impress (it looks as if it wants us to
use predefined layouts).

Another interesting thing: I was trying to create a custom style for the
text shape, it turns out that the document factory can't instantiate new
styles, like in Writer (and Calc?); you have to instantiate the style at
the document's style container, what contradict the current
documentation:
http://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Overall_Document_Features

New styles can be created, as well. For this purpose, use
createInstance() at the document factory of a drawing document and ask
for a "com.sun.star.style.Style" service. Set the properties of the new
style, as required. Append the new style to the style family "graphics"
using insertByName() at its XNameContainer interface.

Does anyone recall if this ever worked?


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Question ad Impress: inserting text using the content's layout formatting, howto

Rony G. Flatscher
Hi Ariel,

On 11.11.2012 13:05, Ariel Constenla-Haile wrote:

> On Fri, Nov 09, 2012 at 04:33:31PM +0100, Rony G. Flatscher wrote:
>>> 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.
>
> I've found my old animation example
>
http://openoffice.2283327.n4.nabble.com/UNO-Java-adding-a-motion-path-Animation-to-an-XShape-in-Impress-td2772586.html

> with a motion path.
>
> Setting an animation effect to each numbering level in a shape's text is
> posible with a com.sun.star.presentation.ParagraphTarget see
> http://people.apache.org/~arielch/api/AnimationDemo.zip
>
> My original example (AnimationDemo.java in that zip) was SMIL-correct,
> but the effect wasn't displayed on the UI; in order to display it I had
> to add some extra parallel time containers; it looks like Impress UI
> understands only
>
> <anim:par presentation:node-type="timing-root">
> <anim:seq presentation:node-type="main-sequence">
> <anim:par smil:begin="next">
> <anim:par smil:begin="0s">
> <anim:par <--- the actual effect
> </anim:par>
> </anim:par>
> </anim:par>
> </anim:seq>
> </anim:par>
>
> I was simply adding a parallel time container to the main sequence. This
> works and is SMIL-correct, but isn't displayed in the task panel.
>
> And if you look at the numbering level example, I use a simple text
> shape and set the levels; this way, the levels are not displayed on the
> Outline view (even if I set the text shape style to outline). I'll have
> to investigate what is expecting Impress (it looks as if it wants us to
> use predefined layouts).
>
> Another interesting thing: I was trying to create a custom style for the
> text shape, it turns out that the document factory can't instantiate new
> styles, like in Writer (and Calc?); you have to instantiate the style at
> the document's style container, what contradict the current
> documentation:
> http://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Overall_Document_Features
>
> New styles can be created, as well. For this purpose, use
> createInstance() at the document factory of a drawing document and ask
> for a "com.sun.star.style.Style" service. Set the properties of the new
> style, as required. Append the new style to the style family "graphics"
> using insertByName() at its XNameContainer interface.
>
> Does anyone recall if this ever worked?
Thank you very much for your *very useful* information, links and programs!

Ad your questions: sorry, cannot answer you, because I never was (yet) in those "dark" corners of
Impress ...

---rony