/blt/test/main.ml

http://github.com/OCamlPro/ocamltk · OCaml · 43 lines · 36 code · 4 blank · 3 comment · 0 complexity · 5b0ac1f22936c0a15e6165a6cb493545 MD5 · raw file

  1. open Protocol
  2. open Tk
  3. open Blt
  4. let source top =
  5. let t = Toplevel.create top [] in
  6. Wm.title_set t "Source window";
  7. (* We are preparing an entry widget from which you can copy data *)
  8. let e = Entry.create t [] in
  9. DragDrop.create_source e [
  10. Button 3; (* 1 and 2 are already used *)
  11. PackageCmd (function token ->
  12. let pick = Entry.get e in
  13. (match Winfo.children token with
  14. [] -> pack [Label.create token [Text pick]][]
  15. | [x] -> Label.configure x [Text pick]);
  16. tkreturn pick); (* this is passed to the handler defined below*)
  17. Send ["text"]
  18. ];
  19. DragDrop.source_handler e "text" (BuiltinHandler "dd_send_text");
  20. pack [e][]
  21. let target top =
  22. let t = Toplevel.create top [] in
  23. Wm.title_set t "Target window";
  24. (* We are preparing a label widget into which you can copy data *)
  25. let l = Label.create t [Text "Initial Text"] in
  26. DragDrop.target_handler l "text"
  27. (function () ->
  28. (* this is a bit magic because you need to know the protocol ! *)
  29. let txt = Textvariable.get (Textvariable.coerce "DragDrop(text)") in
  30. Label.configure l [Text txt]);
  31. pack [l][]
  32. let main () =
  33. let top = openTk() in
  34. Blt.init();
  35. source top;
  36. source top;
  37. target top;
  38. mainLoop()
  39. let _ = Printexc.print main ()