The WR ON EVENT command installs method as the method to be called whenever the event described by event occurs in area. Events are passed directly to method before being handled by 4D Write.
If area equals 0, method becomes the default event method for all 4D Write areas until the database is closed. If an area has a specific event method installed, that method is called instead of the default.
In the event parameter, pass a value indicating the event to intercept. You can use one of the following predefined constants, located in the WR Events theme:
Constant |
Type |
Value |
Comment |
wr on key |
Longint |
0 |
Key down (including arrow keys, returns, tabs…) |
wr on double click |
Longint |
1 |
A double click |
wr on single click |
Longint |
2 |
A single click |
wr on triple click |
Longint |
3 |
Three clicks |
wr on right click |
Longint |
4 |
A click with the right mouse button |
wr on activate |
Longint |
5 |
4D Write area activated or deactivated |
wr on printing |
Longint |
7 |
Printing document |
wr on ruler |
Longint |
8 |
Ruler modification |
wr on compute references |
Longint |
9 |
Dynamic references modified |
wr on close |
Longint |
10 |
4D Write area or window closed |
wr on drag |
Longint |
11 |
An object is dragged |
wr on drop |
Longint |
12 |
An object is dropped |
wr on timer |
Longint |
13 |
End of a timer cycle |
To activate method for all events, pass -1 in event.
When called, method receives seven parameters that describe the state of area at the time of the event. You must explicitly type these parameters using compiler directives. The following table describes the parameters received by method:
Parameter | Type | Description |
$1 | Long integer | 4D Write area |
$2 | Integer | Shift key |
$3 | Integer | Alt (Windows), Option (Mac OS) |
$4 | Integer | Ctrl (Windows), Command (Mac OS) |
$5 | Integer | Event type |
$6 | Integer | Changes depending on event type |
$0 | Long integer | If method returns a value |
$1 returns the long integer that is the area ID where the event took place. $2, $3, and $4 describe whether a specific modifier key was depressed at the time of the event. If the value equals 0, the key was not pressed. If the value equals 1, the key was pressed. $5 returns the event type. $6 varies depending on the type of event.
Method Variables and the Event Parameter ($6)
- If event equals 0, $6 returns the code of the key calling the event.
- If event equals 1 or 2, $6 indicates whether you single- or double-clicked a reference. If $6 equals 0, no reference was selected. If $6 equals 1, a reference was selected.
Note: method can be called before managing a click if you perform one of the following actions:
- Single- or double-click a reference (hypertext link, 4D or HTML expression)
- Right-click (on Windows) or Control-click (on Mac OS). On Mac OS, pressing the Control key while clicking typically displays a pop-up menu.
On Windows, right-clicking typically displays a drop-down menu. Both these menus display the list of the database fields. For better compatibility, it is recommended to use event 4 (wr on right click).
- If event equals 3, $6 concerns the paragraph selection. A triple click can be made on a reference unless a called event method has been installed for the double click and this has been intercepted by $0:=1. In this case, $6 is not significant.
- If event equals 4, $6 indicates the type of context menu about to be displayed (according to the location of the click):
- If $6 equals 1, a type 1 context menu (click in header/footer) is displayed.
- If $6 equals 2, a type 2 context menu (click in the text of the body area) is displayed.
- If $6 equals 3, a type 3 context menu (click on a picture of the body area) is displayed.
- If event equals 5, $6 describes whether or not the area is activated. If $6 equals 0, the 4D Write area is deactivated. If $6 equals 1, the 4D Write area is activated.
- If event equals 7 and the print job is a mail merge, $6 indicates the table number for the table used. If the print job is not a mail merge, $6 equals 0.
- If event equals 8 (an action occurs in the ruler), $6 does not return a significant value. Initialize $0 to 1 if you want to prevent any action in the ruler.
- If event equals 9, $6 indicates where margins have been reset in the document. If $6 equals 0, the margins have been reset in the body. If $6 equals 1, the margins have been reset in the header. If $6 equals 2, the margins have been reset in the footer.
- If event equals 13, the method will be called automatically every X ticks (a tick = 1/60th of a second), regardless of user actions. The timer can be used more particularly to implement an automatic back-up security mechanism for documents being edited. By default, the timer generates an event every 3600 ticks (60 seconds). You can modify this frequency using the WR SET AREA PROPERTY command. Be careful, the method must not carry out too large an amount of processing since its repeated execution can significantly slow down the application.
To filter events, you must use
method as a function that returns 0 or 1. This enables you to specify characters in the document that 4D Write will ignore.
Initialize $0 to 1 to make the method trap a particular event. Initialize $0 to 0 if you do not want to trap a particular event. For example, if you do not want the character “@” to appear in your document, filter all characters appearing in the document. If the $6 variable is equal to the character code of the “@” character, you initialize $0 to 1 and ignore it.
Note: If you filter all characters, operations may slow down considerably since the method will be called for each keystroke.
In the following examples, some actions are executed depending on the type of event: