This is the second of a total of four postings with the intention to demonstrate how to realize the
same functionality of the posted OLE samples without OLE and in a portable way (running unchanged on
Windows, Linux and Apple).
These are samples in the ooRexx scripting language, which usually can be easily adapted to other
languages by replacing the tilde (~), the ooRexx message operator, with a dot (.).
Also, these solutions will use queryInterface() such that one can see for other programming
languages that need to employ queryInterface() what the interface names are. The ooRexx solution
(actually the ooRexx-Java bridge BSF4ooRexx) takes advantage of the available message paradigm and
allows one to merely send the (unqualified) interface name to an UNO object (instead of coding the
entire queryInterface() statement). The fully qualified interface name can always be looked up
quickly from the AOO index for the letter "X":
<https://www.openoffice.org/api/docs/common/ref/index-files/index-24.html>.
Here the portable, OLE-less solution as a follow-up to the matching posting
(see underneath):
/**********************************************************************
simpress_present.rxo: using UNO.CLS (i.e. Java UNO under the hood) with
ooRexx
Links:<https://OpenOffice.org>
<https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Bridge/Automation_Bridge>
<https://www.pitonyak.org/oo.php>
<https://www.openoffice.org/udk/common/man/spec/ole_bridge.html>
Using UNO.CLS create a new simpress presentation about REXX and ooRexx and
then
display it as a presentation. Demonstrates how to use enumeration to
enumerate paragraphs of a text and query their 'NumberingLevel' property.
***********************************************************************/
/* create a presentation, then start it */
xDesktop=uno.createDesktop() -- bootstrap & get access to XDesktop
xcl=xDesktop~XComponentLoader -- get XComponentLoader interface
uri="private:factory/simpress" -- new simpress document
document=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)
xDrawPages = document~XDrawPagesSupplier~getDrawPages -- get DrawPages
-- first page
drawPage=xDrawPages~getByIndex(0) -- get first (empty) page
drawPage~XPropertySet~setPropertyValue("Layout", box("short",0)) -- "Title
Slide"
xShapes=drawPage~XShapes -- get access to its shapes
---
title = "ooRexx"
xShapes~getByIndex(0)~XText~setString(title)
shape = xShapes~getByIndex(1)~XText
cursor = shape~createTextCursor~XTextCursor -- create cursor, get
XTextCursor
cr="0d"x
shape~insertString(cursor,"Open Object Rexx (ooRexx)"cr, .false)
textRange=shape~getEnd -- get a XTextRange
textRange~XPropertySet~setPropertyValue("CharHeight", box('short',15)) --
use 15 pixel height
info="(Presentation created:" .dateTime~new")"
textRange~setString(info) -- set it to this string
-- add a second page
drawPage=xDrawPages~~insertNewByIndex(1)~getByIndex(1) -- insert at end, get
access
-- drawPage=drawPages~~insertNewByIndex(1)~getByIndex(1) -- insert at end,
get access
drawPage~XPropertySet~setPropertyValue("Layout", box('short',1)) -- "Title
Content"
xShapes = drawPage~XShapes
xshapes~getByIndex(0)~XText~setString("Open Object Rexx (ooRexx)") -- first
shape
text=xShapes~getByIndex(1)~XText -- get second shape (listing)
-- add string, supply level
call addItem text, "REXX (IBM)", 0
call addItem text, "First released in 1979 for IBM mainframes", 1
call addItem text, "Object REXX (IBM)", 0
call addItem text, "Object-oriented successor to REXX", 1
call addItem text, "First released in 1994 with IBM's OS/2 Warp", 1
call addItem text, "Negotiations about open-sourcing with RexxLA", 1
call addItem text, "Rexx Language Association (www.RexxLA.org)", 2
call addItem text, "Source code handed over to RexxLA in 2003", 2
call addItem text, "Open Object Rexx (ooRexx by RexxLA)", 0
call addItem text, "First released in 2004 by RexxLA", 1, .false
document~XModifiable~setModified(.false) -- inhibit save-as popup
/* "start" would be found in the ooRexx root class .Object, hence forcing
the message to be dispatched to the Java object */
document~XPresentationSupplier~getPresentation~~bsf.dispatch("start") --
start presentation
say "double-check: dump NumberingLevel of each text paragraph:"
call dumpItems text -- demonstrates enumerating listing
text
::requires UNO.CLS -- get UNO support, will require BSF.CLS
(ooRexx-Java bridge)
::routine addItem -- adds string at the given (0-based
outline) level
use arg xText, string, level, bNewParagraph=.true
xTR=xText~getEnd -- get 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 -- we need XTextRange's string & properties
nl=xtr~XPropertySet~getPropertyValue("NumberingLevel")
say " item #" i": NumberingLevel="pp(nl)
pp(xtr~XTextRange~getString)
end
return
pp: -- "pretty print", internal routine: return argument enclosed in square
brackets
return "["arg(1)"]"
If there are any questions, please ask them.
---rony
On 24.06.2022 13:07, Rony G. Flatscher wrote:
This ooRexx program creates a simpress presentation and then runs/starts it.
/**********************************************************************
AOO_simpress_present.rex using OLE (object linking and embedding) with
ooRexx
Links: <https://OpenOffice.org>
<https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Bridge/Automation_Bridge>
<https://www.pitonyak.org/oo.php>
<https://www.openoffice.org/udk/common/man/spec/ole_bridge.html>
Using OLE create a new simpress presentation about REXX and ooRexx and then
display it as a presentation. Demonstrates how to use enumeration to
enumerate paragraphs of a text and query their 'NumberingLevel' property.
***********************************************************************/
/* create a presentation, then start it */
serviceManager = .OLEObject~new('com.sun.star.ServiceManager')
desktop = serviceManager~createInstance('com.sun.star.frame.Desktop')
noProps = .array~new /* empty array (no properties) */
document = desktop~loadComponentFromURL('private:factory/simpress',
'_blank', 0, noProps)
drawPages = document~getDrawPages -- get DrawPages
-- first page
drawPage=drawPages~getByIndex(0) -- get first (empty) page
drawPage~setPropertyValue("Layout", 0) -- "Title Slide"
title = "ooRexx"
shape = drawPage~getByIndex(0) -- get first shape (title)
shape~setString(title)
shape = drawPage~getByIndex(1) -- get second shape (subtitle)
cursor = shape~createTextCursor -- get XTextCursor
cr="0d"x
shape~insertString(cursor,"Open Object Rexx (ooRexx)"cr, .false)
textRange=shape~getEnd -- get a XTextRange
textRange~setPropertyValue("CharHeight", 15) -- use 15 pixel height
info="(Presentation created:" .dateTime~new")"
textRange~setString(info) -- set it to this string
-- add a second page
drawPage=drawPages~~insertNewByIndex(1)~getByIndex(1) -- insert at end, get
access
drawPage~setPropertyValue("Layout", 1) -- "Title Content"
drawPage~getByIndex(0)~setString("Open Object Rexx (ooRexx)") -- first shape
text=drawPage~getByIndex(1) -- get second shape (listing)
-- add string, supply level
call addItem text, "REXX (IBM)", 0
call addItem text, "First released in 1979 for IBM mainframes", 1
call addItem text, "Object REXX (IBM)", 0
call addItem text, "Object-oriented successor to REXX", 1
call addItem text, "First released in 1994 with IBM's OS/2 Warp", 1
call addItem text, "Negotiations about open-sourcing with RexxLA", 1
call addItem text, "Rexx Language Association (www.RexxLA.org)", 2
call addItem text, "Source code handed over to RexxLA in 2003", 2
call addItem text, "Open Object Rexx (ooRexx by RexxLA)", 0
call addItem text, "First released in 2004 by RexxLA", 1, .false
document~setModified(.false) -- inhibit save-as popup
/* OOo OLE interface does not answer hasOleMethod('start') with .true
therefore forcing "start" to be dispatched to Windows */
document~getPresentation~dispatch("start") -- start presentation
say "double-check: dump NumberingLevel of each text paragraph:"
call dumpItems text -- demonstrates enumerating listing
text
::routine addItem -- adds string at the given (0-based
outline) level
use arg xText, string, level, bNewParagraph=.true
xTR=xText~getEnd -- get XTextRange
xTR~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~createEnumeration -- enumerate paragraphs
do i=1 while enum~hasMoreElements
xtr=enum~nextElement -- we need XTextRange's string & properties
nl=xtr~getPropertyValue("NumberingLevel")
say " item #" i": NumberingLevel="pp(nl) pp(xtr~getString)
end
return
pp: -- "pretty print", internal routine: return argument enclosed in square
brackets
return "["arg(1)"]"
HTH
---rony
P.S.: The short paper at <https://epub.wu.ac.at/8118/> introduces ooRexx briefly in ten pages,
home of Rexx based technologies is the non-profit SIG "Rexx Language Association" at
<https://www.RexxLA.org>.