From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/text/sbasic/guide/access2base.xhp | 98 ++++++++ .../source/text/sbasic/guide/basic_2_python.xhp | 181 +++++++++++++++ .../source/text/sbasic/guide/basic_examples.xhp | 36 +++ .../source/text/sbasic/guide/calc_borders.xhp | 248 +++++++++++++++++++++ .../text/sbasic/guide/control_properties.xhp | 49 ++++ .../source/text/sbasic/guide/create_dialog.xhp | 60 +++++ .../source/text/sbasic/guide/insert_control.xhp | 57 +++++ .../source/text/sbasic/guide/read_write_values.xhp | 196 ++++++++++++++++ .../source/text/sbasic/guide/sample_code.xhp | 139 ++++++++++++ .../source/text/sbasic/guide/show_dialog.xhp | 63 ++++++ .../source/text/sbasic/guide/translation.xhp | 108 +++++++++ 11 files changed, 1235 insertions(+) create mode 100644 helpcontent2/source/text/sbasic/guide/access2base.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/basic_2_python.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/basic_examples.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/calc_borders.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/control_properties.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/create_dialog.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/insert_control.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/read_write_values.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/sample_code.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/show_dialog.xhp create mode 100644 helpcontent2/source/text/sbasic/guide/translation.xhp (limited to 'helpcontent2/source/text/sbasic/guide') diff --git a/helpcontent2/source/text/sbasic/guide/access2base.xhp b/helpcontent2/source/text/sbasic/guide/access2base.xhp new file mode 100644 index 000000000..507a63c9d --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/access2base.xhp @@ -0,0 +1,98 @@ + + + + + + + + + + + Access2Base + /text/sbasic/guide/access2base.xhp + + + Access2Base topic first insertion, by Jean-Pierre Ledure + + + + +Access2Base +Microsoft Access; Access2Base +Access databases; run in Base + + Access2Base + What is Access2Base? + Access2Base is a %PRODUCTNAME BASIC library of macros for (business or personal) application developers and advanced users. It is one of the libraries stored in "Application macros and dialogs". + The functionalities provided by the implemented macros are all directly inspired by Microsoft Access. The macros are callable mainly from a %PRODUCTNAME Base application, but also from any %PRODUCTNAME document (Writer, Calc, ...) where access to data stored in a database makes sense. + The API provided by Access2Base is intended to be more concise, intuitive and easy to learn than the standard UNO API (API = Application Programming Interface). + The library is documented online on http://www.access2base.com. + The implemented macros include: + + + a simplified and extensible API for forms, dialogs and controls manipulations similar with the Microsoft Access object model, + + + an API for database access with the table, query, recordset and field objects, + + + a number of actions with a syntax identical to their corresponding Microsoft Access macros/actions, + + + the DLookup, DSum, ... database functions, + + + the support of the shortcut notations like Forms!myForm!myControl + + + in addition + + + a consistent errors and exceptions handler, + + + facilities for programming form, dialog and control events and + + + the support of both embedded forms and standalone (Writer) forms. + + + Compare Access2Base with Microsoft Access VBA + + REM Open a form ... + OpenForm("myForm") + REM Move a form to new left-top coordinates ... + Dim ofForm As Object ' In VBA => Dim ofForm As Form + Set ofForm = Forms("myForm") + ofForm.Move(100, 200) + REM Get the value of a control ... + Dim ocControl As Object + ocControl = ofForm.Controls("myControl") + MsgBox ocControl.Value + REM Hide a control ... + ocControl.Visible = False + REM ... or alternatively ... + setValue("Forms!myForm!myControl.Visible", False) ' Shortcut notation + ' In VBA => Forms!myForm!myControl.Visible = False + + + diff --git a/helpcontent2/source/text/sbasic/guide/basic_2_python.xhp b/helpcontent2/source/text/sbasic/guide/basic_2_python.xhp new file mode 100644 index 000000000..4ea2d89f4 --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/basic_2_python.xhp @@ -0,0 +1,181 @@ + + + + + + Basic to Python + /text/sbasic/guide/basic_2_python.xhp + + + + + Basic;Calling Python + API;SimpleFileAccess + API;PathSettings + API;XScript + +

Calling Python Scripts from Basic

+ Calling Python scripts from %PRODUCTNAME Basic macros is possible, and valuable features can be obtained such as: + + ComputerName identification or OSName detection are possible, + Basic FileLen() function and com.sun.star.ucb.SimpleFileAccess.getSize() API function exhibit a 2 Gigabytes file size upper limit that Python helps to overcome, + com.sun.star.util.PathSettings can be normalized, + and many more. + + A reasonable exposure to %PRODUCTNAME Basic and to Application Programming Interface (API) features is recommended prior to perform inter-language calls from Basic to Python, to JavaScript or any other script engine. +

Retrieving Python Scripts

+ Python scripts can be personal, shared, or embedded in documents. In order to execute them, %PRODUCTNAME Basic needs to be provided with Python script locations. Locating com.sun.star.script.provider.XScript interface compliant UNO objects allows the execution of Python scripts: + + Option Explicit + + Public Function GetPythonScript(macro As String, _ + Optional location As String) As com.sun.star.script.provider.Xscript + ''' Grab Python script object before execution + ' Arguments: + ' macro : as "library/module.py$macro" or "module.py$macro" + ' location: as "document", "share", "user" or ENUM(eration) + ' Result: + ' located com.sun.star.script.provider.XScript UNO service''' + If IsMissing(location) Then location = "user" + Dim mspf As Object ' com.sun.star.script.provider.MasterScriptProviderFactory + Dim sp As Object ' com.sun.star.script.provider.XScriptProvider compatible + Dim uri As String + If location="document" Then + sp = ThisComponent.getScriptProvider() + Else + mspf = CreateUNOService("com.sun.star.script.provider.MasterScriptProviderFactory") + sp = mspf.createScriptProvider("") + End If + uri = "vnd.sun.star.script:"& macro &"?language=Python&location="& location + GetPythonScript = sp.getScript(uri) + End Function ' GetPythonScript + +

Executing Python Scripts

+ +

Syntax

+ workstation_name = script.invoke(Array(), Array(), Array()) + opSysName = script.invoke(Array(), in_outs, Array()) ' in_out is an Array + file_len = script.invoke(Array(systemFilePath), Array(), Array()) + normalizedPath = script.invoke(Array(systemFilePath), Array(), Array()) +

Embedded Scripts Examples

+ Below ComputerName, and GetFilelen routines are calling their Python counterparts, using aforementioned GetPythonScript function. Exception handling is not detailed. + + Option Explicit + Option Compatible ' Properties are supported + + Private scr As Object ' com.sun.star.script.provider.XScript + + Private Property Get ComputerName As String + '''Workstation name''' + scr = GetPythonScript("Platform.py$computer_name", "document") + ComputerName = scr.invoke(Array(), Array(), Array()) + End Property ' ComputerName + + Private Function GetFilelen(systemFilePath As String) As Currency + '''File size in bytes''' + scr = GetPythonScript("Os/Path.py$get_size", Script.ISEMBEDDED) + GetFilelen = scr.invoke(Array(systemFilePath), Array(), Array(),) + End Function ' GetFilelen + + Private Type _SCRIPT_LOCATION + ISEMBEDDED As String ' document script + ISPERSONAL As String ' user script + ISSHARED As String ' %PRODUCTNAME macro + End Type ' _SCRIPT_LOCATION + + Public Function Script() As Object ' Text enumeration + Static enums As _SCRIPT_LOCATION : With enums + If .ISEMBEDDED = "" Then + .ISEMBEDDED = "document" ' document script + .ISPERSONAL = "user" ' user scripts + .ISSHARED = "share" ' %PRODUCTNAME macro + End If : End With ' enums + Script = enums + End Function ' Script + + Two different Python modules are called. They can either be embedded in the current document, either be stored on the file system. Argument type checking is skipped for clarity: + + Platform.py + + + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + + import platform + + def computer_name() -> str: + return platform.node() + + def OSname() -> str: + return platform.system() + + + Os/Path.py + + + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + + import os.path + + def get_size(systemFilePath: str) -> str: + return str(os.path.getsize(systemFilePath)) + + def normalyze(systemPath: str) -> str: + return os.path.normpath(systemPath) + +

Personal or Shared Scripts Examples

+ The calling mechanism for personal or shared Python scripts is identical to that of embedded scripts. Library names are mapped to folders. Computing %PRODUCTNAME user profile and shared modules system file paths can be performed as detailed in Getting session information. Below OSName, HelloWorld and NormalizePath routines are calling their Python counterparts, using aforementioned GetPythonScript function. Exception handling is not detailed. + + Option Explicit + Option Compatible ' Properties are supported + + Private scr As Object ' com.sun.star.script.provider.XScript + + Private Property Get OSName As String + '''Platform name as "Linux", "Darwin" or "Windows"''' + scr = GetPythonScript("Platform.py$OSname", Script.ISPERSONAL) + OSName = scr.invoke(Array(), Array(), Array()) + End Property ' OSName + + Private Sub HelloWorld() + '''%PRODUCTNAME Python shared sample''' + scr = GetPythonScript("HelloWorld.py$HelloWorldPython", Script.ISSHARED) + scr.invoke(Array(), Array(), Array(),) + End Sub ' HelloWorld + + Public Function NormalizePath(systemFilePath As String) As String + '''Strip superfluous '\..' in path''' + scr = GetPythonScript("Os/Path.py$normalyze", "user") + NormalizePath = scr.invoke(Array(systemFilePath), Array(), Array()) + End Function ' NormalizePath + +

Python standard modules

+ %PRODUCTNAME embedded Python contains many standard libraries to benefit from. They bear a rich feature set, such as but not limited to: + + argparse Parser for command-line options, arguments and sub-commands + cmath Mathematical functions for complex numbers + csv CSV files reading and writing + datetime Genuine date and time types + json JSON encoder and decoder + math Mathematical functions + re Regular expression operations + socket Low-level networking interface + sys System-specific parameters and functions + unittest and trace Unit testing framework and Track Python execution + xml.etree.ElementTree ElementTree XML API + +
+ + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/basic_examples.xhp b/helpcontent2/source/text/sbasic/guide/basic_examples.xhp new file mode 100644 index 000000000..97b11c065 --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/basic_examples.xhp @@ -0,0 +1,36 @@ + + + + + + Basic Programming Examples + /text/sbasic/guide/basic_examples.xhp + + + + + Basic;programming examples + +
+

Basic Programming Examples

+
+ + + + + + + + +
+ +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/calc_borders.xhp b/helpcontent2/source/text/sbasic/guide/calc_borders.xhp new file mode 100644 index 000000000..23fa7b885 --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/calc_borders.xhp @@ -0,0 +1,248 @@ + + + + + + + Formatting Borders in Calc with Macros + /text/sbasic/guide/calc_borders.xhp + + + + + + macros;format borders + +

Formatting Borders in Calc with Macros

+ By using Basic or Python programming languages it is possible to write macros that apply formats to ranges of cells in Calc. + +

Formatting Borders in Ranges of Cells

+ The code snippet below creates a Sub called FormatCellBorder that applies new border formats to a given range address in the current Calc sheet. + + Sub FormatCellBorder(cellAddress as String, newStyle as Byte, newWidth as Long, Optional newColor as Long) + ' Creates the UNO struct that will store the new line format + Dim lineFormat as New com.sun.star.table.BorderLine2 + lineFormat.LineStyle = newStyle + lineFormat.LineWidth = newWidth + If Not IsMissing(newColor) Then lineFormat.Color = newColor + ' Gets the target cell + Dim oCell as Object + Set oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName(cellAddress) + ' Applies the new format to all borders + oCell.TopBorder = lineFormat + oCell.RightBorder = lineFormat + oCell.LeftBorder = lineFormat + oCell.BottomBorder = lineFormat + End Sub + + The Sub described above takes in four arguments: + + + cellAddress is a string denoting the range to be formatted in the format "A1". + + + newStyle is an integer value that corresponds to the border line style (see Line Styles below). + + + newWidth is an integer value that defines the line width. + + + newColor is an integer value corresponding to a color defined using the RGB function. + + + To call FormatCellBorder create a new macro and pass the desired arguments, as shown below: + + Sub MyMacro + ' Gives access to the line style constants + Dim cStyle as Object + Set cStyle = com.sun.star.table.BorderLineStyle + ' Formats "B5" with solid blue borders + FormatCellBorder("B5", cStyle.SOLID, 20, RGB(0, 0, 255)) + ' Formats all borders in the range "D2:F6" with red dotted borders + FormatCellBorder("D2:F6", cStyle.DOTTED, 20, RGB(255, 0, 0)) + End Sub + + It is possible to implement the same functionality in Python: + + from uno import createUnoStruct + from scriptforge import CreateScriptService + + def formatCellBorder(cellAddress, newStyle, newWidth, newColor=0): + # Defines the new line format + line_format = createUnoStruct("com.sun.star.table.BorderLine2") + line_format.LineStyle = newStyle + line_format.LineWidth = newWidth + line_format.Color = newColor + # Scriptforge service to access cell ranges + doc = CreateScriptService("Calc") + cell = doc.XCellRange(cellAddress) + cell.TopBorder = line_format + cell.RightBorder = line_format + cell.LeftBorder = line_format + cell.BottomBorder = line_format + + The code snippet below implements a macro named myMacro that calls formatCellBorder: + + from com.sun.star.table import BorderLineStyle as cStyle + + def myMacro(): + bas = CreateScriptService("Basic") + formatCellBorder("B5", cStyle.SOLID, 20, bas.RGB(0, 0, 255)) + formatCellBorder("D2:F6", cStyle.DOTTED, 20, bas.RGB(255, 0, 0)) + + The Python code presented above uses the ScriptForge library that is available since %PRODUCTNAME 7.2. + +
+

Line Styles

+
+ Line styles are defined as integer constants. The table below lists the constants for the line styles available in Format - Cells - Borders: + + + + Constant name + + + Integer value + + + Line style name + + + + + SOLID + + + 0 + + + Solid + + + + + DOTTED + + + 1 + + + Dotted + + + + + DASHED + + + 2 + + + Dashed + + + + + FINE_DASHED + + + 14 + + + Fine dashed + + + + + DOUBLE_THIN + + + 15 + + + Double thin + + + + + DASH_DOT + + + 16 + + + Dash dot + + + + + DASH_DOT_DOT + + + 17 + + + Dash dot dot + + +
+ Refer to the BorderLineStyle Constant Reference in the LibreOffice API documentation to learn more about line style constants. + +

Formatting Borders Using TableBorder2

+ Range objects have a property named TableBorder2 that can be used to format range borders as it is done in the Format - Cells - Borders dialog in the Line Arrangement section. + In addition to top, bottom, left and right borders, TableBorder2 also defines vertical and horizontal borders. The macro below applies only the top and bottom borders to the range "B2:E5". + + Sub TableBorder2Example + Dim cStyle as Object + Set cStyle = com.sun.star.table.BorderLineStyle + ' Defines the new line format + Dim lineFormat as New com.sun.star.table.BorderLine2 + lineFormat.LineStyle = cStyle.SOLID + lineFormat.LineWidth = 15 + lineFormat.Color = RGB(0, 0, 0) + ' Struct that stores the new TableBorder2 definition + Dim tableFormat as New com.sun.star.table.TableBorder2 + tableFormat.TopLine = lineFormat + tableFormat.BottomLine = lineFormat + tableFormat.IsTopLineValid = True + tableFormat.IsBottomLineValid = True + ' Applies the table format to the range "B2:E5" + Dim oCell as Object + oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("B2:E5") + oCell.TableBorder2 = tableFormat + End Sub + + The macro can be implemented in Python as follows: + + from com.sun.star.table import BorderLineStyle as cStyle + from scriptforge import CreateScriptService + + def tableBorder2Example(): + bas = CreateScriptService("Basic") + line_format = createUnoStruct("com.sun.star.table.BorderLine2") + line_format.LineStyle = cStyle.SOLID + line_format.LineWidth = 18 + line_format.Color = bas.RGB(0, 0, 0) + table_format = createUnoStruct("com.sun.star.table.TableBorder2") + table_format.TopLine = line_format + table_format.BottomLine = line_format + table_format.IsTopLineValid = True + table_format.IsBottomLineValid = True + doc = CreateScriptService("Calc") + cell = doc.XCellRange("B2:E5") + cell.TableBorder2 = table_format + + Refer to the TableBorder2 Struct Reference in the LibreOffice API documentation to learn more about its attributes. + +
+ +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/control_properties.xhp b/helpcontent2/source/text/sbasic/guide/control_properties.xhp new file mode 100644 index 000000000..7d8ff2c3e --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/control_properties.xhp @@ -0,0 +1,49 @@ + + + + + + + + +Changing the Properties of Controls in the Dialog Editor +/text/sbasic/guide/control_properties.xhp + + +Sun Microsystems, Inc. + + + +properties; controls in dialog editor +changing;control properties +controls;changing properties +dialog editor;changing control properties + +Changing the Properties of Controls in the Dialog Editor + +You can set the properties of control that you add to a dialog. For example, you can change the color, name, and size of a button that you added. You can change most control properties when you create or edit a dialog. However, you can only change some properties at runtime. +To change the properties of a control in design mode, right-click the control, and then choose Properties. +
+ + + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/create_dialog.xhp b/helpcontent2/source/text/sbasic/guide/create_dialog.xhp new file mode 100644 index 000000000..e948d4467 --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/create_dialog.xhp @@ -0,0 +1,60 @@ + + + + + + + + + + +Creating a Basic Dialog +/text/sbasic/guide/create_dialog.xhp + + + +dialogs;creating Basic dialogs +Creating a Basic Dialog + + + +Choose Tools - Macros - Organize Dialogs, and then click New. + + +Enter a name for the dialog and click OK. To rename the dialog later, right-click the name on the tab and choose Rename.UFI: issue #i51589# + + +Click Edit. The Basic dialog editor opens and contains a blank dialog. + + +If you do not see the Toolbox bar, click the arrow next to the Insert Controls icon to open the Toolbox bar. + + +Click a tool and then drag in the dialog to create the control. + + +
+ + + + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/insert_control.xhp b/helpcontent2/source/text/sbasic/guide/insert_control.xhp new file mode 100644 index 000000000..cbc6fdbdb --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/insert_control.xhp @@ -0,0 +1,57 @@ + + + + + + + + +Creating Controls in the Dialog Editor +/text/sbasic/guide/insert_control.xhp + + +Sun Microsystems, Inc. + + + +controls; creating in the dialog editor +dialog editor;creating controls + +Creating Controls in the Dialog Editor + +Use the tools on the Toolbox of the BASIC dialog editor to add controls to your dialog. + + +To open the Toolbox, click the arrow next to the Insert Controls icon on the Macro toolbar. + + +Click a tool on the toolbar, for example, Button. + + +On the dialog, drag the button to the size you want. + + +
+ + + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/read_write_values.xhp b/helpcontent2/source/text/sbasic/guide/read_write_values.xhp new file mode 100644 index 000000000..b8dab321c --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/read_write_values.xhp @@ -0,0 +1,196 @@ + + + + + + + Reading and Writing values to Ranges + /text/sbasic/guide/read_write_values.xhp + + + + + + macros;read values from cells + macros;write values to cells + +

Reading and Writing values to Ranges

+ Macros in %PRODUCTNAME Calc often need to read and write values from/to sheets. This help page describes the various approaches to accessing sheets and ranges to read or write their values. + All examples presented in this page can be implemented both in Basic and Python. + +

Accessing a Single Cell

+ The example below enters the numeric value 123 into cell "A1" of the current sheet. + + Dim oSheet as Object + Dim oCell as Object + oSheet = ThisComponent.CurrentController.getActiveSheet() + oCell = oSheet.getCellRangeByName("A1") + oCell.setValue(123) + + The same can be accomplished with Python: + + doc = XSCRIPTCONTEXT.getDocument() + sheet = doc.getCurrentController().getActiveSheet() + cell = sheet.getCellRangeByName("A1") + cell.setValue(123) + + Note that in the previous examples the cell is accessed using its range name "A1". It is also possible to access cells using indices as though the sheet were a matrix where columns and rows are indexed starting from zero. + This can be done using the getCellByPosition(colIndex, rowIndex) method, that takes in a column and a row index. The example below in Basic changes the text value in cell "C1" (column 2, row 0). + + oSheet = ThisComponent.CurrentController.getActiveSheet() + oCell = oSheet.getCellByPosition(2, 0) + oCell.setString("Hello") + + This example can also be implemented in Python as follows: + + doc = XSCRIPTCONTEXT.getDocument() + sheet = doc.getCurrentController().getActiveSheet() + cell = sheet.getCellByPosition(2, 0) + cell.setString("Hello") + + The main difference between Python and Basic scripts lies on how to get access to the sheet object by using the XSCRIPTCONTEXT context variable. After that, all methods and properties are identical in Basic and Python. +

Values, Strings and Formulas

+ Calc cells can have three types of values: numeric, strings and formulas. Each type has its own set and get methods: + + + + Type + + + Get Method + + + Set Method + + + + + Numeric + + + getValue() + + + setValue(newValue) + + + + + Text + + + getString() + + + setString(newString) + + + + + Formula + + + getFormula() + + + setFormula(newFormula) + + +
+ Dates and currency values are considered as numeric values in Calc. + The following example enters numeric values into cells "A1" and "A2" and inserts a formula in cell "A3" that returns the multiplication of these values. + + oSheet = ThisComponent.CurrentController.getActiveSheet() + oCell = oSheet.getCellRangeByName("A1") + oCell.setValue(10) + oCell = oSheet.getCellRangeByName("A2") + oCell.setValue(20) + oCell = oSheet.getCellRangeByName("A3") + oCell.setFormula("=A1*A2") + +

Accessing Ranges in Different Sheets

+ The previous examples used only the active sheet to perform operations. It is possible to access cell ranges in different sheets by their indices or names. + The example below enters a numeric value into cell "A1" of the sheet named "Sheet2". + + oSheet = ThisComponent.Sheets.getByName("Sheet2") + oCell = oSheet.getCellRangeByName("A1") + oCell.setValue(123) + + This example can also be implemented in Python as follows: + + doc = XSCRIPTCONTEXT.getDocument() + sheet = doc.Sheets["Sheet2"] + cell = sheet.getCellRangeByName("A1") + cell.setValue(123) + + Sheets can also be accessed using zero-based indices indicating which sheet considering the order they appear in the Calc file. + In Basic, instead of using the getByName method, use Sheets(sheetIndex) as shown next: + + oSheet = ThisComponent.Sheets(0) + + This can be done in a similar fashion in Python: + + sheet = doc.Sheets[0] + +

Using the ScriptForge Library

+ The Calc service of the ScriptForge library can be used to get and set cell values as follows: + + ' Loads the ScriptForge library + GlobalScope.BasicLibraries.LoadLibrary("ScriptForge") + ' Gets access to the current Calc document + oDoc = CreateScriptService("Calc") + ' Sets the value of cells A1 and A2 + oDoc.setValue("A1", "Hello") + oDoc.setValue("A2", 123) + + The setValue method can be used to set both numeric and text values. To set a cell formula, use the setFormula method. + With the Calc service, getting and setting cell values can be done with a single line of code. The example below gets the value from cell "A1" and shows it on a message box. + + Dim val as Variant, oDoc as Object + oDoc = CreateScriptService("Calc") + val = oDoc.getValue("A1") + MsgBox val + + The ScriptForge library also makes it simpler to access ranges in different sheets, as demonstrated in the example below: + + Dim val1, val2 + ' Gets cell "A1" from the sheet named "Sheet1" + val1 = oDoc.getValue("Sheet1.A1") + ' Gets cell "B3" from the sheet named "Sheet2" + val2 = oDoc.getValue("Sheet2.B3") + ' Places the result into cell "A1" of sheet "Report" + Dim result : result = val1 * val2 + oDoc.setValue("Report.A1", result) + + The examples above can also be implemented in Python as follows: + + from scriptforge import CreateScriptService + doc = CreateScriptService("Calc") + doc.setValue("A1", "Hello") + + + doc = CreateScriptService("Calc") + bas = CreateScriptService("Basic") + val = doc.getValue("A1") + bas.MsgBox(val) + + + first_val = doc.getValue("Sheet1.A1") + second_val = doc.getValue("Sheet2.B3") + result = first_val * second_val + doc.setValue("Report.A1", result) + +
+ + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/sample_code.xhp b/helpcontent2/source/text/sbasic/guide/sample_code.xhp new file mode 100644 index 000000000..cdb79e383 --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/sample_code.xhp @@ -0,0 +1,139 @@ + + + + + + Programming Examples for Controls in the Dialog Editor + /text/sbasic/guide/sample_code.xhp + + + Sun Microsystems, Inc. + + + + programming examples for controls + dialogs;loading (example) + dialogs;displaying (example) + controls;reading or editing properties (example) + list boxes;removing entries from (example) + list boxes;adding entries to (example) + examples; programming controls + dialog editor;programming examples for controls + Tools;LoadDialog + +
+ Programming Examples for Controls in the Dialog Editor + +
+The following examples are for a new dialog called "Dialog1". Use the tools on the Toolbox bar in the dialog editor to create the dialog and add the following controls: a Check Box called "CheckBox1", a Label Field called "Label1", a Button called "CommandButton1", and a List Box called "ListBox1". +Be consistent with uppercase and lowercase letter when you attach a control to an object variable. +Global Function for Loading Dialogs + +Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer) +Dim oLib as Object ' com.sun.star.script.XLibraryContainer +Dim oLibDialog as Object +Dim oRuntimeDialog as Object + If IsMissing(oLibContainer) Then + oLibContainer = DialogLibraries + End If + oLibContainer.LoadLibrary(LibName) + oLib = oLibContainer.GetByName(Libname) + oLibDialog = oLib.GetByName(DialogName) + oRuntimeDialog = CreateUnoDialog(oLibDialog) + LoadDialog() = oRuntimeDialog +End Function + +LoadDialog function is stored in Tools.ModuleControls available from Application Macros and Dialogs. +Displaying a Dialog + +REM global definition of variables +Dim oDialog1 AS Object +Sub StartDialog1 + With GlobalScope.BasicLibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + oDialog1 = Tools.ModuleControls.LoadDialog("Standard", "Dialog1") + oDialog1.Execute() +End Sub + +Read or Edit Properties of Controls in the Program + +Sub Sample1 + With GlobalScope.Basiclibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + oDialog1 = Tools.LoadDialog("Standard", "Dialog1") + REM get dialog model + oDialog1Model = oDialog1.Model + REM display text of Label1 + oLabel1 = oDialog1.GetControl("Label1") + MsgBox oLabel1.Text + REM set new text for control Label1 + oLabel1.Text = "New Files" + REM display model properties for the control CheckBox1 + oCheckBox1Model = oDialog1Model.CheckBox1 + MsgBox oCheckBox1Model.Dbg_Properties + REM set new state for CheckBox1 for model of control + oCheckBox1Model.State = 1 + REM display model properties for control CommandButton1 + oCMD1Model = oDialog1Model.CommandButton1 + MsgBox oCMD1Model.Dbg_Properties + REM display properties of control CommandButton1 + oCMD1 = oDialog1.GetControl("CommandButton1") + MsgBox oCMD1.Dbg_Properties + REM execute dialog + oDialog1.Execute() +End Sub + +Add an Entry to a ListBox + +Sub AddEntry + With GlobalScope.Basiclibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1") + REM adds a new entry to the ListBox + oDialog1Model = oDialog1.Model + oListBox = oDialog1.GetControl("ListBox1") + Dim iCount as integer + iCount = oListbox.ItemCount + oListbox.additem("New Item" & iCount,0) +End Sub + +Remove an Entry from a ListBox + +Sub RemoveEntry + With GlobalScope.Basiclibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + oDialog1 = Tools.ModuleControls.LoadDialogLoadDialog("Standard", "Dialog1") + REM remove the first entry from the ListBox + oDialog1Model = oDialog1.Model + oListBox = oDialog1.GetControl("ListBox1") + oListbox.removeitems(0,1) +End Sub + +
+ + + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/show_dialog.xhp b/helpcontent2/source/text/sbasic/guide/show_dialog.xhp new file mode 100644 index 000000000..117ff796c --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/show_dialog.xhp @@ -0,0 +1,63 @@ + + + + + +Opening a Dialog With Basic +/text/sbasic/guide/show_dialog.xhp + + + + + module/dialog toggle + dialogs;using Basic to show (example) + examples; showing a dialog with Basic + Tools;LoadDialog + +Opening a Dialog With Basic + +In the %PRODUCTNAME BASIC window for a dialog that you created, leave the dialog editor by clicking the name tab of the Module that the dialog is assigned to. The name tab is at the bottom of the window. +Enter the following code for a subroutine called Dialog1Show. In this example, the name of the dialog that you created is "Dialog1": + +Sub Dialog1Show + With GlobalScope.BasicLibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + oDialog1 = Tools.ModuleControls.LoadDialog("Standard", "Dialog1") + oDialog1.Execute() +End Sub + +Without using "LoadDialog" you can call the code as follows: + +Sub Dialog1Show + DialogLibraries.LoadLibrary("Standard") + oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Dialog1 ) + oDialog1.Execute() +End Sub + +When you execute this code, "Dialog1" opens. To close the dialog, click the close button (x) on its title bar. +
+ + + + + +
+ +
diff --git a/helpcontent2/source/text/sbasic/guide/translation.xhp b/helpcontent2/source/text/sbasic/guide/translation.xhp new file mode 100644 index 000000000..38608ddea --- /dev/null +++ b/helpcontent2/source/text/sbasic/guide/translation.xhp @@ -0,0 +1,108 @@ + + + + + + + + + + +Translation of Controls in the Dialog Editor +/text/sbasic/guide/translation.xhp + + + +dialogs;translating +localizing dialogs +translating dialogs + +Translation of Controls in the Dialog Editor + +The Language toolbar in the Basic IDE dialog editor shows controls to enable and manage localizable dialogs. +By default, any dialog that you create only contains string resources for one language. You may want to create dialogs that automatically show localized strings according to the user's language settings. +Select the language for the strings that you want to edit. Click the Manage Languages icon to add languages.Manage Language icon is in sbasic/shared/02/20000000.xhp + + +Click a language, then click Default to set the language as default, or click Delete to remove the language from the list. +Opens a dialog where you can add a language to the list. +Select a language in the list and click Delete to remove that language. When you remove all languages, the string resources for localizable dialogs are removed from all dialogs in the current library. +Select a language in the list and click Default to set the language as default language. + + +The default language will be used as a source for all other language strings. +Add UI languages for your dialog strings. +To enable localizable dialogs + + +In the Basic IDE dialog editor, open the Language toolbar choosing View - Toolbars - Language. +If the current library already contains a localizable dialog, the Language toolbar is shown automatically. + + +Click the Manage Languages icon +Manage Language icon + on the Language toolbar or on the Toolbox bar. +You see the Manage User Interface Language dialog. The dialog manages languages for the current library. The name of the current library is shown on the title bar. + + +Click Add in the dialog to add a language entry. +This step enables all new dialogs to contain localizable string resources. + + +The first time you click Add, you see the Set Default User Interface Language dialog. The following times you click Add, this dialog has the name Add User Interface Language. +You can also change the default language in the Manage User Interface Language dialog. + + +Select a language. +This adds string resources to contain the translated versions of all strings to the dialog properties. The set of dialog strings of the default language is copied to the new set of strings. Later, you can switch to the new language and then translate the strings. + + +Close the dialog or add additional languages. + + +To edit localizable controls in your dialog +Once you have added the resources for localizable strings in your dialogs, you can select the current language from the Current Language listbox on the Language toolbar. + + +Switch the Current Language listbox to display the default language. + + +Insert any number of controls to your dialog and enter all strings you want. + + +Select another language in the Current Language listbox. + + +Using the control's property dialogs, edit all strings to the other language. + + +Repeat for all languages that you added. + + +The user of your dialog will see the strings of the user interface language of the user's version of %PRODUCTNAME, if you did provide strings in that language. +If no language matches the user's version, the user will see the default language strings. +If the user has an older version of %PRODUCTNAME that does not know localizable string resources for Basic dialogs, the user will see the default language strings. +
+ + + + +
+ +
-- cgit v1.2.3