![]() [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:
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)
|