Re: Portable version (Re: OLE: VBS "Automation_Bridge" to ooRexx

2022-08-22 Thread Rony G. Flatscher

Hi Matthias,

On 21.08.2022 16:22, Matthias Seidel wrote:

I almost forgot to answer...

:)

This is great work (although I only understand a bit of it).

Could this also work with Object REXX from OS/2 [1]?


If there was an OS/2 version of ooRexx and someone compiled BSF4ooRexx.cc for 
OS/2, then yes.

Background: ooRexx ("open object Rexx") is based on IBM's source code for Object REXX and got 
released by the non-profit "Rexx Language Association"( cf. ) under the name 
"open object Rexx (ooRexx)". For more than 15 years ooRexx got developed further, the kernel got 
rewritten and made portable, 32- and 64-bit versions for Windows, Apple and Linux have been made 
available.


"BSF4ooRexx" is a library that I have been developing for more than 20 years which establishes the 
ooRexx-Java bridge and available for all the aforementioned platforms. The major motivation was to 
not only teach BA students from zero to oo-programming within a single semester (four months, four 
hour weekly lecture) but to allow them to use all of Java (class libraries) as if they were ooRexx 
(class libraries). Among other things it takes advantage of the message paradigm (decoupling the 
concepts from the implementations).


As AOO/OOo has a Java interface and a Java based scripting framework it was possible to make ooRexx 
for the BA students available such that they not only learn how to program MS Office, but in the 
same semester how to do all of that in a portable, open-source manner using AOO/OOo.


If the OS/2 community would port ooRexx 5.0 and BSF4ooRexx.cc to OS/2 it could immediately take 
advantage of the infrastructure and run those ooRexx samples that I posted unchanged.


HTH,

---rony

P.S.: The idea of BSF4ooRexx and the first implementations came out of OS/2. But that is another 
story ... ;)






[1] http://www.edm2.com/index.php/IBM_Object_REXX_for_OS/2

Am 04.08.22 um 14:07 schrieb Rony G. Flatscher:

This is the first 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":
.

Here the portable, OLE-less solution as a follow-up to the matching
posting (see underneath):

   
/**

  swriter_table.rxo: using UNO.CLS (i.e. Java UNO under the hood)
with ooRexx

  Links:
 


  
 



  This is the ooRexx version (which includes corrections) of the
VBScript
  "A Quick Tour" example from the AOO (Apache OpenOffice) DevGuide,
chapter
  "Automation_Bridge" documentation.

  Using UNO.CLS create a new swriter document, a TextTable, a
TextFrame, paragraphs
  and apply various formattings.
   
***/


   -- Create the Desktop
   xDesktop=uno.createDesktop()    -- bootstrap & get access to
XDesktop
   xcl=xDesktop~XComponentLoader   -- get XComponentLoader
interface

   -- Open a new empty writer document
   uri="private:factory/swriter"   -- new swriter document
   objDocument=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)

   -- Create a text object
   objText= objDocument~XTextDocument~getText

   -- Create a cursor object
   objCursor= objText~createTextCursor

   -- Inserting some Text
   vbLf = "0a"x    -- line-feed character
   objText~insertString( objCursor, "The first line in the newly
created text document."vbLf, .false)

   -- Inserting a second line
   objText~insertString( objCursor, "Now we-- re in the second
line", .false)

   -- query interface XMultiServiceFactory
   objDocument = objDocument~XMultiServiceFactory

   -- Create instance of a text table with 4 columns and 4 rows
   objTable= objDocument~createInstance(
"com.sun.star.text.TextTable")~XTextTable
 

Re: Portable version (Re: OLE: VBS "Automation_Bridge" to ooRexx

2022-08-21 Thread Matthias Seidel
Hello Rony,

I almost forgot to answer...

This is great work (although I only understand a bit of it).

Could this also work with Object REXX from OS/2 [1]?

Regards,

   Matthias

[1] http://www.edm2.com/index.php/IBM_Object_REXX_for_OS/2

Am 04.08.22 um 14:07 schrieb Rony G. Flatscher:
> This is the first 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":
> .
>
> Here the portable, OLE-less solution as a follow-up to the matching
> posting (see underneath):
>
>   
> /**
>  swriter_table.rxo: using UNO.CLS (i.e. Java UNO under the hood)
> with ooRexx
>
>  Links:
> 
> 
>  
> 
> 
>
>  This is the ooRexx version (which includes corrections) of the
> VBScript
>  "A Quick Tour" example from the AOO (Apache OpenOffice) DevGuide,
> chapter
>  "Automation_Bridge" documentation.
>
>  Using UNO.CLS create a new swriter document, a TextTable, a
> TextFrame, paragraphs
>  and apply various formattings.
>   
> ***/
>
>   -- Create the Desktop
>   xDesktop=uno.createDesktop()    -- bootstrap & get access to
> XDesktop
>   xcl=xDesktop~XComponentLoader   -- get XComponentLoader
> interface
>
>   -- Open a new empty writer document
>   uri="private:factory/swriter"   -- new swriter document
>   objDocument=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)
>
>   -- Create a text object
>   objText= objDocument~XTextDocument~getText
>
>   -- Create a cursor object
>   objCursor= objText~createTextCursor
>
>   -- Inserting some Text
>   vbLf = "0a"x    -- line-feed character
>   objText~insertString( objCursor, "The first line in the newly
> created text document."vbLf, .false)
>
>   -- Inserting a second line
>   objText~insertString( objCursor, "Now we-- re in the second
> line", .false)
>
>   -- query interface XMultiServiceFactory
>   objDocument = objDocument~XMultiServiceFactory
>
>   -- Create instance of a text table with 4 columns and 4 rows
>   objTable= objDocument~createInstance(
> "com.sun.star.text.TextTable")~XTextTable
>   objTable~initialize( 4, 4 )
>
>   -- Insert the table
>   objText~insertTextContent( objCursor, objTable, .false)
>
>   -- Get first row
>   objRows= objTable~getRows
>   objRow= objRows~getByIndex( 0)
>
>   -- Set the table background color
>   objTable~XPropertySet~setPropertyValue( "BackTransparent", .false)
>   objTable~XPropertySet~setPropertyValue( "BackColor", 13421823)
>
>   -- Set a different background color for the first row
>   objRow~XPropertySet~setPropertyValue( "BackTransparent", .false)
>   objRow~XPropertySet~setPropertyValue( "BackColor", 6710932)
>
>   -- Fill the first table row
>   call insertIntoCell "A1","FirstColumn", objTable --
> insertIntoCell is a helper function, see below
>   call insertIntoCell "B1","SecondColumn", objTable
>   call insertIntoCell "C1","ThirdColumn", objTable
>   call insertIntoCell "D1","SUM", objTable
>
>   objTable~getCellByName("A2")~setValue( 22.5 )
>   objTable~getCellByName("B2")~setValue( 5615.3   )
>   objTable~getCellByName("C2")~setValue( -2315.7  )
>   objTable~getCellByName("D2")~setFormula( "=sum ++"  )
>
>   objTable~getCellByName("A3")~setValue( 21.5 )
>   objTable~getCellByName("B3")~setValue( 615.3    )
>   objTable~getCellByName("C3")~setValue( -315.7   )
>   objTable~getCellByName("D3")~setFormula( "sum ++" )
>
>   objTable~getCellByName("A4")~setValue( 121.5    )
>   objTable~getCellByName("B4")~setValue( -615.3   )
>   

Portable version (Re: OLE: VBS "Automation_Bridge" to ooRexx

2022-08-04 Thread Rony G. Flatscher
This is the first 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": 
.


Here the portable, OLE-less solution as a follow-up to the matching posting 
(see underneath):

   /**
 swriter_table.rxo: using UNO.CLS (i.e. Java UNO under the hood) with ooRexx

 Links:
 

 
 

 This is the ooRexx version (which includes corrections) of the VBScript
 "A Quick Tour" example from the AOO (Apache OpenOffice) DevGuide, chapter
 "Automation_Bridge" documentation.

 Using UNO.CLS create a new swriter document, a TextTable, a TextFrame, 
paragraphs
 and apply various formattings.
   ***/

  -- Create the Desktop
  xDesktop=uno.createDesktop()-- bootstrap & get access to XDesktop
  xcl=xDesktop~XComponentLoader   -- get XComponentLoader interface

  -- Open a new empty writer document
  uri="private:factory/swriter"   -- new swriter document
  objDocument=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)

  -- Create a text object
  objText= objDocument~XTextDocument~getText

  -- Create a cursor object
  objCursor= objText~createTextCursor

  -- Inserting some Text
  vbLf = "0a"x-- line-feed character
  objText~insertString( objCursor, "The first line in the newly created text 
document."vbLf, .false)

  -- Inserting a second line
  objText~insertString( objCursor, "Now we-- re in the second line", .false)

  -- query interface XMultiServiceFactory
  objDocument = objDocument~XMultiServiceFactory

  -- Create instance of a text table with 4 columns and 4 rows
  objTable= objDocument~createInstance( 
"com.sun.star.text.TextTable")~XTextTable
  objTable~initialize( 4, 4 )

  -- Insert the table
  objText~insertTextContent( objCursor, objTable, .false)

  -- Get first row
  objRows= objTable~getRows
  objRow= objRows~getByIndex( 0)

  -- Set the table background color
  objTable~XPropertySet~setPropertyValue( "BackTransparent", .false)
  objTable~XPropertySet~setPropertyValue( "BackColor", 13421823)

  -- Set a different background color for the first row
  objRow~XPropertySet~setPropertyValue( "BackTransparent", .false)
  objRow~XPropertySet~setPropertyValue( "BackColor", 6710932)

  -- Fill the first table row
  call insertIntoCell "A1","FirstColumn", objTable -- insertIntoCell is a 
helper function, see below
  call insertIntoCell "B1","SecondColumn", objTable
  call insertIntoCell "C1","ThirdColumn", objTable
  call insertIntoCell "D1","SUM", objTable

  objTable~getCellByName("A2")~setValue( 22.5 )
  objTable~getCellByName("B2")~setValue( 5615.3   )
  objTable~getCellByName("C2")~setValue( -2315.7  )
  objTable~getCellByName("D2")~setFormula( "=sum ++"  )

  objTable~getCellByName("A3")~setValue( 21.5 )
  objTable~getCellByName("B3")~setValue( 615.3)
  objTable~getCellByName("C3")~setValue( -315.7   )
  objTable~getCellByName("D3")~setFormula( "sum ++" )

  objTable~getCellByName("A4")~setValue( 121.5)
  objTable~getCellByName("B4")~setValue( -615.3   )
  objTable~getCellByName("C4")~setValue( 415.7)
  objTable~getCellByName("D4")~setFormula( "sum ++" )

  range=objTable~XCellRange~getCellRangeByName("A2:D4")
  range~XPropertySet~setPropertyValue("NumberFormat", box("short",4))   -- 
set number format
  -- use ParaAdjust: com.sun.star.style.ParagraphAdjust.RIGHT
  right=.uno_enum~new("com.sun.star.style.ParagraphAdjust")~right
  range~XPropertySet~setPropertyValue("ParaAdjust", right)  -- align right

  -- Change the CharColor 

OLE: VBS "Automation_Bridge" to ooRexx

2022-06-24 Thread Rony G. Flatscher
Having looked around some nutshell OLE samples to port to ooRexx I stumbled over 
 which 
depicts a VBScript example.


There are the following changes in the ooRexx code:

 * the "=sum" formula now has the cells and the + operator to add them up,
 * the TextTable numbers are formatted to #,###.00 and right adjusted.

Ad ooRexx: I use it to teach BA students programming from zero to Windows to Java in a four hour 
lecture in a semester (four months). The Java part includes the knowledge to apply ooRexx via the 
UNO Java bindings (one can use ooRexx to interact with Java objects, such that the students do not 
need to know Java, they just need to be able to read Java documentation).


ooRexx implements the message paradigm: a value (an object, an instance) is conceptually like a 
living thing that understands messages one sends to it, which causes the value to look for a method 
by the same name (supplying arguments, if any) which it invokes and returns any return value if any. 
The message operator is the tilde (~), the receiver is on the left hand side, the message name on 
the right hand side. (The short paper at  introduces ooRexx briefly in 
ten pages.)


Usually one can turn VB code into ooRexx by replacing dots with a tilde, however it also works the 
other way round by replacing tildes with dots . :)


Here the transcription:

   /**
 AOO_swriter_table.rex using OLE (object linking and embedding) with ooRexx

 Links: 
   

   
   

 This is the ooRexx version (which includes corrections) of the VBScript
 "A Quick Tour" example from the AOO (Apache OpenOffice) DevGuide, chapter
 "Automation_Bridge" documentation.

 Using OLE create a new swriter document, a TextTable, a TextFrame, 
paragraphs
 and apply various formatings.
   ***/

  -- The service manager is always the starting point
  -- If there is no office running then an office is started up
  objServiceManager= .OleObject~new("com.sun.star.ServiceManager")

  -- Create the Desktop
  objDesktop= objServiceManager~createInstance("com.sun.star.frame.Desktop")

  -- Open a new empty writer document
  args=.array~new
  objDocument= objDesktop~loadComponentFromURL("private:factory/swriter", 
"_blank", 0, args)

  -- Create a text object
  objText= objDocument~getText

  -- Create a cursor object
  objCursor= objText~createTextCursor

  -- Inserting some Text
  vbLf = "0a"x    -- line-feed character
  objText~insertString( objCursor, "The first line in the newly created text 
document."vbLf,
   .false)

  -- Inserting a second line
  objText~insertString( objCursor, "Now we-- re in the second line", .false)

  -- Create instance of a text table with 4 columns and 4 rows
  objTable= objDocument~createInstance( "com.sun.star.text.TextTable")
  objTable~initialize( 4, 4 )

  -- Insert the table
  objText~insertTextContent( objCursor, objTable, .false)

  -- Get first row
  objRows= objTable~getRows
  objRow= objRows~getByIndex( 0)

  -- Set the table background color
  objTable~setPropertyValue( "BackTransparent", .false)
  objTable~setPropertyValue( "BackColor", 13421823)

  -- Set a different background color for the first row
  objRow~setPropertyValue( "BackTransparent", .false)
  objRow~setPropertyValue( "BackColor", 6710932)

  -- Fill the first table row
  call insertIntoCell "A1","FirstColumn", objTable -- insertIntoCell is a 
helper function, see
   below
  call insertIntoCell "B1","SecondColumn", objTable
  call insertIntoCell "C1","ThirdColumn", objTable
  call insertIntoCell "D1","SUM", objTable

  objTable~getCellByName("A2")~setValue( 22.5 )
  objTable~getCellByName("B2")~setValue( 5615.3   )
  objTable~getCellByName("C2")~setValue( -2315.7  )
  objTable~getCellByName("D2")~setFormula( "=sum ++"  )

  objTable~getCellByName("A3")~setValue( 21.5 )
  objTable~getCellByName("B3")~setValue( 615.3    )
  objTable~getCellByName("C3")~setValue( -315.7   )
  objTable~getCellByName("D3")~setFormula( "sum ++" )

  objTable~getCellByName("A4")~setValue( 121.5    )
  objTable~getCellByName("B4")~setValue( -615.3   )
  objTable~getCellByName("C4")~setValue( 415.7    )
  objTable~getCellByName("D4")~setFormula( "sum ++" )

  range=objTable~getCellRangeByName("A2:D4")
  range~setPropertyValue("NumberFormat", 4)  -- set number format
  -- use ParaAdjust: