LibORef no4

LibreOffice RefCard

LibreOfice Basic

EventsInter.

v. 1.10 – 12/02/2018
Writen using LibreOffice v. 5.3.3 – Platform: All

Constants in com.sun.star.awt.KeyFunc.XXX
DONTKNOW
CUT
None
Cut
NEW
COPY
New
Copy
OPEN
PASTE
Open
Paste
SAVE
UNDO
Save
Undo
SAVEAS
REDO
Save as
Redo

CLOSE
Close
QUIT
Quit
PROPERTIES Properties
FIND
Find
FINDBACKWAR Find
D
backwards
PRINT
REPEAT
FRONT
Print
Repeat
To front
Constants in com.sun.star.awt.KeyModifier.XXX (additive with +/And)
MOD1
MOD2
SHIFT
Ctrl
Alt
MajFocus Events

EventsLibreOffice objects know of various event types that can be fired in various situations. You
may intercept these events and process accordingly.

Objets That Provide Events• The application• Documents• Forms and controls• Basic dialogues and controls• Document objects:• OLE objects• Images• Frames• AutoTexts• ImageMaps• Hyperlinks

Associating An Event To A Macro
Principe
1. Create the macro to be executed.
Follow this template:
Sub MacroName()
End Sub

 Name the macro according to the object, action and event type.
example : Sub OnButtonOKClick()
The Sub may bear a parameter. See below.
2. Select the object that carries the event to intercept (list above).
3. Go to the object settings (method varies depending on the object).
4. Select the event to intercept (see the lists in this refcard).
5. point to the macro to be executed when the event fires.

Getting Information About The Event Fired
The Sub may read the input parameter in order to get more information about the event :Sub EventResponse(ByRef Event As Object)
End Sub
The Event object structure and properties depend upon the type of event that fires theSub (see below).
Frequent situations for Basic dialogues controls:
To get toReadEvent.Source
Calling control object
Event.Source.ModelControl model object
Event.Source.Context
Dialogue object, control owner

Event Categories And Properties
Dialogues provide four event categories (col. Cat in the last table):Mouse
M Events fired by actions using the mouse (ex: movements or clicks).
Keyboard
K Events fired par keypresses.
Focus
F Events fired when focus changes.
Specific
S Events linked to some controls.
 The constants listed below are case-sensitive.

Mouse Events
Coordinates are in pixels, measured from the top-left control angle.
See the com.sun.star.awt.MouseEvent structure
Buttons (short)
The pressed button (const. com.sun.star.awt.MouseButton).
X (long) and Y (long) X (resp. Y) coordinate of the mouse pointer.
ClickCount (long) Number of clicks associated with the mouse event.
When LibreOffice can respond fast enough, ClickCount is 1 for a
double-click, because one single event is fired.
PopupTrigger
True if contextual menu.
(boolean)Constants defined in com.sun.star.awt.MouseButton
LEFTRIGHTMIDDLE
Left button.
Right button
Middle button.
 The VBA Click and Doubleclick events are not supported by LibO Basic. You may use
the LibO Basic event Mouse buton released as a replacement for a Click event andmimic the Doubleclick event by modifying the application logic.

Keyboard Events
Keyboard events are associated with logical key actions rather than to physical actions.
☞ Key combination = one single event.
☞ A unique action on a modification key (dead key, ex SHIFT or ALT) doesn’t create an
independent event.
The keyboard Event object holds the propertiesKeyCode (short)
The keypressed code (com.sun.star.awt.Key.XXX).
Modification keys ( Shift , Ctrl and Alt ) do not change that code.
KeyChar (String)
The entered character (takes modification keys into account).
KeyFunc (Integer)
The key functionality, as the constant incom.sun.star.awt.KeyFunction.XXXX

Modifiers (Integer)

Specifiies whether a modification was pressed, see constantscom.sun.star.awt.KeyModifier.XXX.
Constants defined in com.sun.star.awt.Key.XXX (excerpts)
RETURNPOINT
NUM0 à NUM9 Numbers
Enter.
ESCAPE
COMMA
AàZ
Letters
Esc,LESSF1 à F26
Function keys TAB
Tab<UPBACKSPACE
GREATER
Up>
DOWN
SPACE
EQUAL
Down
Space=LEFT
INSERT
CUTLeft
Ins
Ctrl + X
RIGHT
DELETE
COPY
Right
Del
Ctrl + C
HOME
ADD
PASTE
Home+Ctrl + V
END
SUBTRACT−HELP
End
F1PAGEUP
MULTIPLY*MENU
Page up
PAGEDOWNDIVIDECONTEXTMENU
Page down/☞ These codes identify physical keys.

LibOBasic_04_Events_Flat_A4_EN_v110.odt

The focus Event objects provide the following properties
FocusFlags (short)
The focus change reason.
See the com.sun.star.awt.FocusChangeReason constants.
NextFocus (Object) The object that gets the focus (only for the On focus lost) event.
Temporary (Boolean) True if the focus is temporarily lost.
Constants as defined in com.sun.star.awt.FocusChangeReason
TAB
BACKWARD
Tab has been pressed.
Former control.
CURSORAROUND
A direction key was
From last to first control
pressed.
(forward) or from the firstto the last (backward).
MNEMONICUNIQUEMNEMONIC A shortcut key to a unique
A shortcut key waspressed.
control was pressed.
FORWARD
Next control.

Specific EventsSome events (ex : When initiating) can be fired by actions on some controls (ex : radiobuttons). No action is executed to know whether the control status has actually changed.
Avoid such “blind events” by recording the control former value in a global variable, thencheck whether the value was changed when the event is fired.
Properties for the Item Status Changed event:Selected (long)
The currently selected entry.
Highlighted (long)
The currently highlighted entry.
ItemId (long)
The entry ID.

Document Events
Propriétés de l’événement entrant (voir chapitre suivant) :EventName (string)
Le nom de l’événement.
Source (object)
Le document à l’origine de l’événement.
ViewController (object)
Le contrôleur d’affichage concerné, sinon Null.
Supplement (variant)
Des infos complémentaires, sinon Empty.

Document Or Application Events
Tools > Customize, Events tab.

Available events:
EventStart application
Close application
Document created
New document
Document loading finishedOpen document
Document is going to be closed
Document closed

View createdView is going to be closed
View closed
Activate documentDeactivate document
Save document
Document has been saved
Saving of document failed
Save document asDocument has been saved as‘Save as’ has failed
Storing or exporting copy ofdocument
Document copy has been createdCreating of document copy failed
Print document‘Modified’ status changed
Document title changed
Printing of form leters started

The assigned macro is executed…
After the application start.
Before the application closes.
After File > New.
After creating the document from a template.
After the document was reloaded.
After File > Open.
Before the document is closed.
After the document has been closed.
☞ Note that the Document closed event may also
be fired on document saving, just before the document is closed.
After the document view has been created.
Before the document view is closed.
After the document view has been closed.
After display of the document in the foreground.
After display of another document in the foreground.
Before File > Save, if the document name is specified.
☞ See Document closed.
After File > Save, if the document name is specified.
After the document saving has failed.
Before File > Save as (or File > Save if the documentname is not specified).
After File > Save as (or File > Save if the documentname is not specified).
After a Save as error.
After the creation of the copy.
After error on copy creation.
After the Print dialog closes, but before actual
printing.
After the modification status has changed.
After the document title has changed.
After the Print dialog closes, but before actual
printing.
After mail merge printing.

Printing of form leters finishedMerging of form fields started
Merging of form fields finished
Changing the page countWhen the page number changes.
☞ View events are fired when the document display changes: Preview mode or New
Window mode.

Document Events Sequences
Opening An Existing Document (All Methods)
Open document > View createdClosing The Active Document (All Methods)
View is going to be closed > Document is going to be closed > View closed >Document closed

Creating A Document From A Template
New document > View createdEventPrior to reset

Interacting With Document Objects

Image loading ended
Image loaded stopped
Image loading error
Alphanumericalcharacters enteredNon-alphanumericalcharacters entered
Frame sized changed

Frame moved
Before autotext
insertion
Afer autotext insertion After the text block insertion.

Hyperlink

●
●
●

●
●
●

●
●
●

●

●
●

●

●

●

●

●

AutoText

ImageMap

Mouse quit

The object is selected.
The mouse is moving above the object.
The hyperlink assigned to the object isactivated.
The mouse pointer is moved outside ofthe object.
The image loading is finished.
The images loading was interrupted bythe user (ex: on page download).
The image load failed (ex. image notfound).
Some text was entered using thekeyboard.
Non-printable chars were entered (tab,enter, etc.).
The frame size was changed using themouse.
The frame was moved using the mouse.
Before the text block insertion.

Image

Object clicked
Mouse hover
Hyperlink fired

Fired when

Frame

Event

OLE object

Object properties, then misc.: Macro tab, Macro button, Events button, etc.

●●

Afer reseting
Before record change
Before unloading
Before reloading
Confirm deletion●●

When loading
When unloading●When reloading●Fill parameters●SELECT * FROM address WHERE name=:namewhere :name is a parameter that must be filled out when●
●Calc Sheets Events
Sheet > Sheet Events (or right-click the sheet tab then Sheet events)

Event
Activate document
Deactivate document
Selection changed
Double click
Right click
Formulas calculated
Content changed

The assigned macro is executed…
Before a form is reset. The linked macro can, for example, prevent this action by returning FALSE.
A form is reset if one of the following conditions is met:
1. The user presses an (HTML) button that is defined as a resetbutton.
2. A new and empty record is created in a form that is linked toa data source. For example, in the last record, the Next
Record button may be pressed.
After a form has been reset.
Before the current record pointer is changed. Ex. To stop thisaction by returning FALSE.
Before the form is unloaded (separated from the database).
Before the form is reloaded. The data contents has not been
updated yet.
As soon as the data have been suppressed from the form. Ex.
Ask for a confirmation.
After the form was loaded.
Just after the form was unloaded (separated from thedatabase).
Just after the form has been reloaded. The data have been
already updated.
When the to be loaded form needs parameters (SQL).
This event is fired whenever a parameter can’t be provided.
For example, the form data source might be the SQL command:

An error happened

The assigned macro is executed…
After the document was displayed in the foreground.
After another document was displayed in the foreground.
After the selection was changed.
After double-clicking a cell.
After right-clicking a range.
After formulae recalculation.
After a cell contents has been changed.

loading. The parameter is automatically filled out from theparent form if possible. If the parameter cannot be filled out, thisevent is called and a linked macro can fill out the parameter.
Whenever an error occurs when accessing the database.
☞ Applies to forms, listboxes and comboboxes.

Form Events
Control properties, Events tab.

Common Non-Database EventsCat

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:

pressedM Mouse moved
M Mouse buton pressed

M Mouse buton released
M Mouse outsidepressing a key during a drag and drop sets the drag/drop
mode (move or copy).
While the mouse pointer moves over the control.
When a mouse button is pressed while the pointer is overthe control.
☞ The Mouse buton pressed event is also used to notifyof context menu calls.
Then, the event PopupTrigger property is TRUE.
On a right-click call, the event is fired twice: (1) on thecontext menu call and (2) for the click itself. If you’reonly interested in the click event, ignore calls wherePopupTrigger is TRUE.
When a mouse button is released while the pointer is overthe control.
While the mouse pointer is outside control boundaries.

Dialog Boxes Events
Some dialog boxes controls provide the supplemental events:
CatEventThe 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
Afer record action
Afer record change
Before record action
Before submiting
Before update
Afer update

The assigned macro is executed…
After the current record was modified.
Just after the current record pointer was changed.
Before the current record is modified. Allows to ask for aconfirmation.
Before the form data is sent.
Before the modified control contents is written to the database.
Ex. Stop this action by returning FALSE.
After the modified control contents has been written to thedatabase.

Credits
Author : Jean-François Nifenecker – jean-francois.nifenecker@laposte.net
We are like dwarves perched on the shoulders of giants, and thus we are able to see more and farther than thelatter. And this is not at all because of the acuteness of our sight or the stature of our body, but because we arecarried aloft and elevated by the magnitude of the giants (Bernard de Chartres [attr.])HistoryVersion

Date

1.01

11/09/2018

Minor updates

Comments

1.10

02/12/2018

Rework and complements

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