0% found this document useful (0 votes)
38 views

Events: Libreofice Basic

This document provides information about events and event handling in LibreOffice Basic, including: 1. LibreOffice objects can fire various event types that can be intercepted and processed. Objects that can fire events include documents, forms, dialogs, frames and hyperlinks. 2. To associate an event with a macro, create the macro sub procedure, name it according to the object and event, and select the event to intercept from the object's settings. 3. Event sub procedures can read the event object parameter to get information like the event name, source object, and supplemental data, which varies by event type.

Uploaded by

Marlon Carvalho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Events: Libreofice Basic

This document provides information about events and event handling in LibreOffice Basic, including: 1. LibreOffice objects can fire various event types that can be intercepted and processed. Objects that can fire events include documents, forms, dialogs, frames and hyperlinks. 2. To associate an event with a macro, create the macro sub procedure, name it according to the object and event, and select the event to intercept from the object's settings. 3. Event sub procedures can read the event object parameter to get information like the event name, source object, and supplemental data, which varies by event type.

Uploaded by

Marlon Carvalho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LibORef no4

LibreOffice RefCard
Constants in com.sun.star.awt.KeyFunc.XXX
LibreOfice Basic DONTKNOW
NEW
None
New
CUT
COPY
Cut
Copy
CLOSE
QUIT
Close
Quit

Events OPEN
SAVE
Open
Save
PASTE
UNDO
Paste
Undo
PROPERTIES Properties
FIND Find
SAVEAS Save as REDO Redo FINDBACKWAR Find
Inter. D backwards
v. 1.10 – 12/02/2018 PRINT Print REPEAT Repeat FRONT To front
Writen using LibreOffice v. 5.3.3 – Platform: All Constants in com.sun.star.awt.KeyModifier.XXX (additive with +/And)
MOD1 Ctrl MOD2 Alt SHIFT Maj
Focus Events
Events
The focus Event objects provide the following properties
LibreOffice objects know of various event types that can be fired in various situations. You FocusFlags (short) The focus change reason.
may intercept these events and process accordingly. See the com.sun.star.awt.FocusChangeReason constants.
Objets That Provide Events NextFocus (Object) The object that gets the focus (only for the On focus lost) event.
• The application • Document objects: Temporary (Boolean) True if the focus is temporarily lost.
• Documents • OLE objects • AutoTexts Constants as defined in com.sun.star.awt.FocusChangeReason
• Forms and controls • Images • ImageMaps TAB Tab has been pressed. BACKWARD Former control.
• Basic dialogues and controls • Frames • Hyperlinks CURSOR A direction key was AROUND From last to first control
pressed. (forward) or from the first
Associating An Event To A Macro to the last (backward).
Principe MNEMONIC A shortcut key was UNIQUEMNEMONIC A shortcut key to a unique
1. Create the macro to be executed. pressed. control was pressed.
FORWARD Next control.
Follow this template:
Sub MacroName() Specific Events
End Sub Some events (ex : When initiating) can be fired by actions on some controls (ex : radio
 Name the macro according to the object, action and event type. buttons). No action is executed to know whether the control status has actually changed.
example : Sub OnButtonOKClick()
Avoid such “blind events” by recording the control former value in a global variable, then
The Sub may bear a parameter. See below.
check whether the value was changed when the event is fired.
2. Select the object that carries the event to intercept (list above).
Properties for the Item Status Changed event:
3. Go to the object settings (method varies depending on the object).
Selected (long) The currently selected entry.
4. Select the event to intercept (see the lists in this refcard).
Highlighted (long) The currently highlighted entry.
5. point to the macro to be executed when the event fires.
ItemId (long) The entry ID.
Getting Information About The Event Fired Document Events
The Sub may read the input parameter in order to get more information about the event :
Sub EventResponse(ByRef Event As Object) Propriétés de l’événement entrant (voir chapitre suivant) :
End Sub EventName (string) Le nom de l’événement.
The Event object structure and properties depend upon the type of event that fires the Source (object) Le document à l’origine de l’événement.
Sub (see below). ViewController (object) Le contrôleur d’affichage concerné, sinon Null.
Frequent situations for Basic dialogues controls: Supplement (variant) Des infos complémentaires, sinon Empty.
To get to Read Document Or Application Events
Calling control object Event.Source
Control model object Event.Source.Model Tools > Customize, Events tab.
Dialogue object, control owner Event.Source.Context Available events:
Event The assigned macro is executed…
Event Categories And Properties Start application After the application start.
Dialogues provide four event categories (col. Cat in the last table): Close application Before the application closes.
Mouse M Events fired by actions using the mouse (ex: movements or clicks). Document created After File > New.
Keyboard K Events fired par keypresses. New document After creating the document from a template.
Focus F Events fired when focus changes. Document loading finished After the document was reloaded.
Specific S Events linked to some controls. Open document After File > Open.
 The constants listed below are case-sensitive. Document is going to be closed Before the document is closed.
Document closed After the document has been closed.
Mouse Events ☞ Note that the Document closed event may also
Coordinates are in pixels, measured from the top-left control angle. be fired on document saving, just before the doc-
See the com.sun.star.awt.MouseEvent structure ument is closed.
Buttons (short) The pressed button (const. com.sun.star.awt.MouseButton). View created After the document view has been created.
X (long) and Y (long) X (resp. Y) coordinate of the mouse pointer. View is going to be closed Before the document view is closed.
ClickCount (long) Number of clicks associated with the mouse event. View closed After the document view has been closed.
When LibreOffice can respond fast enough, ClickCount is 1 for a Activate document After display of the document in the foreground.
double-click, because one single event is fired. Deactivate document After display of another document in the foreground.
PopupTrigger True if contextual menu. Save document Before File > Save, if the document name is specified.
(boolean) ☞ See Document closed.
Constants defined in com.sun.star.awt.MouseButton Document has been saved After File > Save, if the document name is specified.
LEFT Left button. RIGHT Right button MIDDLE Middle button. Saving of document failed After the document saving has failed.
 The VBA Click and Doubleclick events are not supported by LibO Basic. You may use Save document as Before File > Save as (or File > Save if the document
the LibO Basic event Mouse buton released as a replacement for a Click event and name is not specified).
mimic the Doubleclick event by modifying the application logic. Document has been saved as After File > Save as (or File > Save if the document
Keyboard Events name is not specified).
‘Save as’ has failed After a Save as error.
Keyboard events are associated with logical key actions rather than to physical actions.
Storing or exporting copy of
☞ Key combination = one single event.
document
☞ A unique action on a modification key (dead key, ex SHIFT or ALT) doesn’t create an Document copy has been created After the creation of the copy.
independent event.
Creating of document copy failed After error on copy creation.
The keyboard Event object holds the properties Print document After the Print dialog closes, but before actual
KeyCode (short) The keypressed code (com.sun.star.awt.Key.XXX).
printing.
Modification keys ( Shift , Ctrl and Alt ) do not change that code. ‘Modified’ status changed After the modification status has changed.
KeyChar (String) The entered character (takes modification keys into account). Document title changed After the document title has changed.
KeyFunc (Integer) The key functionality, as the constant in Printing of form leters started After the Print dialog closes, but before actual
com.sun.star.awt.KeyFunction.XXXX printing.
Modifiers (Integer) Specifiies whether a modification was pressed, see constants Printing of form leters finished After mail merge printing.
com.sun.star.awt.KeyModifier.XXX. Merging of form fields started
Constants defined in com.sun.star.awt.Key.XXX (excerpts) Merging of form fields finished
NUM0 à NUM9 Numbers RETURN Enter POINT . Changing the page count When the page number changes.
AàZ Letters ESCAPE Esc COMMA , ☞ View events are fired when the document display changes: Preview mode or New
F1 à F26 Function keys TAB Tab LESS < Window mode.
UP Up BACKSPACE GREATER > Document Events Sequences
DOWN Down SPACE Space EQUAL =
LEFT Left INSERT Ins CUT Ctrl + X Opening An Existing Document (All Methods)
RIGHT Right DELETE Del COPY Ctrl + C Open document > View created
HOME Home ADD + PASTE Ctrl + V Closing The Active Document (All Methods)
END End SUBTRACT − HELP F1 View is going to be closed > Document is going to be closed > View closed >
PAGEUP Page up MULTIPLY * MENU Document closed
PAGEDOWN Page down DIVIDE / CONTEXTMENU Creating A Document From A Template
☞ These codes identify physical keys. New document > View created

LibOBasic_04_Events_Flat_A4_EN_v110.odt
Interacting With Document Objects Event The assigned macro is executed…
Prior to reset Before a form is reset. The linked macro can, for example, pre-
Object properties, then misc.: Macro tab, Macro button, Events button, etc. vent this action by returning FALSE.

OLE object
A form is reset if one of the following conditions is met:

ImageMap
Hyperlink
AutoText
Frame
Image
1. The user presses an (HTML) button that is defined as a reset
Event Fired when button.
2. A new and empty record is created in a form that is linked to
Object clicked a data source. For example, in the last record, the Next
The object is selected. ● ● ●
Record button may be pressed.
Mouse hover The mouse is moving above the object. ● ● ● ● ●
Hyperlink fired The hyperlink assigned to the object is ● ● ● ● Afer reseting After a form has been reset.
activated. Before record change Before the current record pointer is changed. Ex. To stop this
Mouse quit The mouse pointer is moved outside of ● ● ● ● ● action by returning FALSE.
the object. Before unloading Before the form is unloaded (separated from the database).
Image loading ended The image loading is finished. ● Before reloading Before the form is reloaded. The data contents has not been
Image loaded stopped The images loading was interrupted by ● updated yet.
the user (ex: on page download). Confirm deletion As soon as the data have been suppressed from the form. Ex.
Image loading error The image load failed (ex. image not ● Ask for a confirmation.
found). When loading After the form was loaded.
Alphanumerical Some text was entered using the ● When unloading Just after the form was unloaded (separated from the
characters entered keyboard. database).
Non-alphanumerical Non-printable chars were entered (tab, ● When reloading Just after the form has been reloaded. The data have been
characters entered enter, etc.). already updated.
Frame sized changed The frame size was changed using the ● Fill parameters When the to be loaded form needs parameters (SQL).
mouse. This event is fired whenever a parameter can’t be provided.
Frame moved The frame was moved using the mouse. ● For example, the form data source might be the SQL command:
SELECT * FROM address WHERE name=:name
Before autotext Before the text block insertion. ●
where :name is a parameter that must be filled out when
insertion
Afer autotext insertion After the text block insertion. loading. The parameter is automatically filled out from the

parent form if possible. If the parameter cannot be filled out, this
Calc Sheets Events event is called and a linked macro can fill out the parameter.
Sheet > Sheet Events (or right-click the sheet tab then Sheet events) An error happened Whenever an error occurs when accessing the database.
Event The assigned macro is executed… ☞ Applies to forms, listboxes and comboboxes.
Activate document After the document was displayed in the foreground.
Deactivate document After another document was displayed in the foreground.
Selection changed After the selection was changed.
Double click After double-clicking a cell.
Right click After right-clicking a range.
Formulas calculated After formulae recalculation.
Content changed After a cell contents has been changed.
Form Events
Control properties, Events tab.
Common Non-Database Events
Cat Event The assigned macro is executed…
F When receiving focus When the control receives the focus.
F When losing focus When a control loses the focus.
K Key pressed When a key is pressed on the focused control.
K Key released When a key is released on the focused control.
M Mouse inside When the mouse pointer is inside control boundaries.
M Mouse moved while key When the mouse is moved while a key is pressed. Ex:
pressed pressing a key during a drag and drop sets the drag/drop
mode (move or copy).
M Mouse moved While the mouse pointer moves over the control.
M Mouse buton pressed When a mouse button is pressed while the pointer is over
the control.
☞ The Mouse buton pressed event is also used to notify
of context menu calls.
Then, the event PopupTrigger property is TRUE.
On a right-click call, the event is fired twice: (1) on the
context menu call and (2) for the click itself. If you’re
only interested in the click event, ignore calls where
PopupTrigger is TRUE.
M Mouse buton released When a mouse button is released while the pointer is over
the control.
M Mouse outside While the mouse pointer is outside control boundaries.
Dialog Boxes Events
Some dialog boxes controls provide the supplemental events:
Cat Event The assigned macro is executed…
Execute action When the action starts. Ex: if the form has a Send
button, the sending process is the action to take.
☞ Use for button click responses.
KM Item status changed When the control state has changed.
M While adjusting When moving a scroll bar or a spinbutton.
Database Events Only
Event The assigned macro is executed…
Afer record action Credits
After the current record was modified.
Afer record change Just after the current record pointer was changed. Author : Jean-François Nifenecker – [email protected]
We are like dwarves perched on the shoulders of giants, and thus we are able to see more and farther than the
Before record action Before the current record is modified. Allows to ask for a latter. And this is not at all because of the acuteness of our sight or the stature of our body, but because we are
confirmation. carried aloft and elevated by the magnitude of the giants (Bernard de Chartres [attr.])
Before submiting Before the form data is sent. History
Before update Before the modified control contents is written to the database.
Ex. Stop this action by returning FALSE. Version Date Comments
Afer update After the modified control contents has been written to the 1.01 11/09/2018 Minor updates
database. 1.10 02/12/2018 Rework and complements

License
This refcard is placed under the
CreativeCommons BY-SA v4 (intl) license.
More information:
https://creativecommons.org/licenses/by-sa/4.0/

You might also like