/src/wrappers/gtk/library/key_event_callback.e

http://github.com/tybor/Liberty · Specman e · 71 lines · 54 code · 13 blank · 4 comment · 3 complexity · 78a28c485ada2757643521bd98cae493 MD5 · raw file

  1. indexing
  2. description: "Generic callback for the key-release-event and key-pressed-event signals"
  3. copyright: "[
  4. Copyright (C) 2006 Paolo redaelli, eiffel-libraries team, GTK+ team and others
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. license: "LGPL v2 or later"
  19. date: "$Date:$"
  20. revision "$Revision:$"
  21. deferred class KEY_EVENT_CALLBACK
  22. -- You want to use one of KEY_EVENT_RELEASE_CALLBACK or KEY_EVENT_PRESS_CALLBACK
  23. inherit CALLBACK redefine object end
  24. insert G_OBJECT_FACTORY [GTK_WIDGET]
  25. feature
  26. object: GTK_WIDGET
  27. feature
  28. callback (event_key_ptr: POINTER; instance: POINTER): INTEGER is
  29. local
  30. key_event: GDK_EVENT_KEY
  31. specific_event: GDK_EVENT_ANY
  32. do
  33. debug print ("Callback: instance=") print (instance.to_string) print ("%N") end
  34. -- The following is written with the implicit requirement
  35. -- that object actually has an Eiffel wrapper
  36. object := wrapper(instance)
  37. create key_event.from_external_pointer (event_key_ptr)
  38. Result := function.item ([key_event, object]).to_integer
  39. -- GTK is about to release this event, detach it from Eiffel
  40. key_event.dispose
  41. end
  42. callback_pointer: POINTER is
  43. do
  44. Result := get_callback_pointer ($callback)
  45. ensure
  46. Result.is_not_null
  47. end
  48. connect (an_object: GTK_WIDGET; a_function: FUNCTION [ANY, TUPLE [GDK_EVENT_KEY, GTK_WIDGET], BOOLEAN]) is
  49. do
  50. handler_id := g_signal_connect_closure (an_object.handle,
  51. signal_name.to_external,
  52. handle,
  53. 0 -- i.e. call it before default handler
  54. )
  55. function := a_function
  56. end
  57. function: FUNCTION [ANY, TUPLE [GDK_EVENT_KEY, GTK_WIDGET], BOOLEAN]
  58. end -- class KEY_EVENT_CALLBACK