1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
##ifdef CAMLTK
let cCAMLtoTKxEvent = function
| Activate -> "Activate"
| ButtonPress -> "ButtonPress"
| ButtonPressDetail n -> "ButtonPress-"^string_of_int n
| ButtonRelease -> "ButtonRelease"
| ButtonReleaseDetail n -> "ButtonRelease-"^string_of_int n
| Circulate -> "Circulate"
| ColorMap -> "Colormap"
| Configure -> "Configure"
| Deactivate -> "Deactivate"
| Destroy -> "Destroy"
| Enter -> "Enter"
| Expose -> "Expose"
| FocusIn -> "FocusIn"
| FocusOut -> "FocusOut"
| Gravity -> "Gravity"
| KeyPress -> "KeyPress"
| KeyPressDetail s -> "KeyPress-"^s
| KeyRelease -> "KeyRelease"
| KeyReleaseDetail s -> "KeyRelease-"^s
| Leave -> "Leave"
| Map -> "Map"
| Motion -> "Motion"
| Property -> "Property"
| Reparent -> "Reparent"
| Unmap -> "Unmap"
| Visibility -> "Visibility"
| Virtual s -> "<"^s^">"
;;
let cCAMLtoTKmodifier = function
| Control -> "Control-"
| Shift -> "Shift-"
| Lock -> "Lock-"
| Button1 -> "Button1-"
| Button2 -> "Button2-"
| Button3 -> "Button3-"
| Button4 -> "Button4-"
| Button5 -> "Button5-"
| Double -> "Double-"
| Triple -> "Triple-"
| Mod1 -> "Mod1-"
| Mod2 -> "Mod2-"
| Mod3 -> "Mod3-"
| Mod4 -> "Mod4-"
| Mod5 -> "Mod5-"
| Meta -> "Meta-"
| Alt -> "Alt-"
;;
exception IllegalVirtualEvent
(* type event = modifier list * xEvent *)
let cCAMLtoTKevent (ml, xe) =
match xe with
| Virtual s ->
if ml = [] then "<<"^s^">>"
else raise IllegalVirtualEvent
| _ ->
"<" ^ (String.concat " " (List.map cCAMLtoTKmodifier ml))
^ (cCAMLtoTKxEvent xe) ^ ">"
;;
(* type eventSequence == (modifier list * xEvent) list *)
let cCAMLtoTKeventSequence l =
TkToken(List.fold_left (^) "" (List.map cCAMLtoTKevent l))
##else
let cCAMLtoTKmodifier : modifier -> string = function
| `Control -> "Control-"
| `Shift -> "Shift-"
| `Lock -> "Lock-"
| `Button1 -> "Button1-"
| `Button2 -> "Button2-"
| `Button3 -> "Button3-"
| `Button4 -> "Button4-"
| `Button5 -> "Button5-"
| `Double -> "Double-"
| `Triple -> "Triple-"
| `Mod1 -> "Mod1-"
| `Mod2 -> "Mod2-"
| `Mod3 -> "Mod3-"
| `Mod4 -> "Mod4-"
| `Mod5 -> "Mod5-"
| `Meta -> "Meta-"
| `Alt -> "Alt-"
;;
exception IllegalVirtualEvent
let cCAMLtoTKevent (ev : event) =
let modified = ref false in
let rec convert = function
| `Activate -> "Activate"
| `ButtonPress -> "ButtonPress"
| `ButtonPressDetail n -> "ButtonPress-"^string_of_int n
| `ButtonRelease -> "ButtonRelease"
| `ButtonReleaseDetail n -> "ButtonRelease-"^string_of_int n
| `Circulate -> "Circulate"
| `Colormap -> "Colormap"
| `Configure -> "Configure"
| `Deactivate -> "Deactivate"
| `Destroy -> "Destroy"
| `Enter -> "Enter"
| `Expose -> "Expose"
| `FocusIn -> "FocusIn"
| `FocusOut -> "FocusOut"
| `Gravity -> "Gravity"
| `KeyPress -> "KeyPress"
| `KeyPressDetail s -> "KeyPress-"^s
| `KeyRelease -> "KeyRelease"
| `KeyReleaseDetail s -> "KeyRelease-"^s
| `Leave -> "Leave"
| `Map -> "Map"
| `Motion -> "Motion"
| `Property -> "Property"
| `Reparent -> "Reparent"
| `Unmap -> "Unmap"
| `Visibility -> "Visibility"
| `Virtual s ->
if !modified then raise IllegalVirtualEvent else "<"^s^">"
| `Modified(ml, ev) ->
modified := true;
String.concat ~sep:"" (List.map ~f:cCAMLtoTKmodifier ml)
^ convert ev
in "<" ^ convert ev ^ ">"
;;
let cCAMLtoTKeventSequence (l : event list) =
TkToken(String.concat ~sep:"" (List.map ~f:cCAMLtoTKevent l))
;;
##endif
|