[UP]
Events
|
|
|
The representation of events in O'Caml
In the module Wd_types, the event type is
defined as follows:
type event =
Button of string
| Image_button of (string * int * int)
| Indexed_button of (string * string)
| Indexed_image_button of (string * string * int * int)
| No_event
| Popup_request of string
The variants of the type correspond to the event types:
Button event: A button event for the button n is
represented as
Button n Indexed button event: A button event for the button n
with index i is represented as
Indexed_button(n,i) Imagebutton event: An imagebutton event for the button n is
represented as
Image_button(n,x,y)
The coordinate (x,y) is the position of the click relative to the image.
Indexed imagebutton event: An imagebutton event
for the button n with index i is
represented as
Indexed_image_button(n,i,x,y)
The coordinate (x,y) is the position of the click relative to the image.
Hyperlink event: A hyperlink event for the anchor n is
represented as
Button n
The representations for hyperlinks and for buttons are intentionally the same.
Indexed hyperlink event: A hyperlink event for the anchor n
with index i is represented as
Indexed_button(n,i)
The representations for hyperlinks and for buttons are intentionally the same.
Popup request: A popup request is represented as
Popup_request s
Note that the current page is changed to the page popping up while
the popup request is processed.The parameter s of the popup request is the second argument of
the generated open Javascript function (to simplify parameterized
popup windows). For example, a popup window declared with
<ui:server-popup page="x"/>
can be opened by the Javascript statement
open_x(window_specification, s);
The parameter s is passed back to the application once the window
pops up and the contents of the window are requested. You can use
this parameter arbitrarily.
Popups are explained in conjunction with ui:server-popup.
Null event: The null event is represented as
No_event
Handling events
The handle method of the current dialog is called when the event has
been triggered. The method event can be used to find out the last
event, e.g.
method handle =
let e = self # event in
match e with
Button("this_button") ->
...
| Button("that_button") ->
...
| Indexed_image_button("clicked_icon", x, y) ->
...
| _ ->
(* It is recommended to do nothing as default *)
()
When the handle method returns normally, the current page of the
current dialog is generated again. Alternatively, another page can
be set by raising the exception Change_page; or it can be changed to
another dialog instance by raising the exception Change_dialog.
Example:
method handle =
let e = self # event in
match e with
Button("this_button") ->
self # set_variable "xy" (String_value "wow");
(* ... and continue with the same page *)
| Button("that_button") ->
self # set_variable "xy" (String_value "boo");
raise(Change_page "another_page")
| Indexed_image_button("clicked_icon", x, y) ->
let next_dlg =
self # universe # create (self#environment) "other_dialog" in
raise(Change_dialog next_dlg)
|