/src/wrappers/gdk/library/gdk_event.e

http://github.com/tybor/Liberty · Specman e · 194 lines · 114 code · 29 blank · 51 comment · 5 complexity · 047ad249201076d4794e42f140d4f282 MD5 · raw file

  1. indexing
  2. description: "union GdkEvent"
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  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. class GDK_EVENT
  22. inherit
  23. C_STRUCT
  24. redefine from_external_pointer end
  25. insert
  26. GDK_EVENT_EXTERNALS
  27. GDK_EVENT_ANY_EXTERNALS
  28. -- The GdkEvent struct contains a union of all of the event
  29. -- structs, and allows access to the data fields in a number of
  30. -- ways.
  31. -- The event type is always the first field in all of the event
  32. -- structs, and can always be accessed with the following code, no
  33. -- matter what type of event it is:
  34. -- GdkEvent *event;
  35. -- GdkEventType type;
  36. -- type = event->type;
  37. -- To access other fields of the event structs, the pointer to
  38. -- the event can be cast to the appropriate event struct pointer,
  39. -- or the union member name can be used. For example if the event
  40. -- type is GDK_BUTTON_PRESS then the x coordinate of the button
  41. -- press can be accessed with:
  42. -- GdkEvent *event;
  43. -- gdouble x;
  44. -- x = ((GdkEventButton*)event)->x;
  45. --or:
  46. -- GdkEvent *event;
  47. -- gdouble x;
  48. -- x = event->button.x;
  49. --union GdkEvent
  50. --{
  51. -- GdkEventType type;
  52. -- GdkEventAny any;
  53. -- GdkEventExpose expose;
  54. -- GdkEventNoExpose no_expose;
  55. -- GdkEventVisibility visibility;
  56. -- GdkEventMotion motion;
  57. -- GdkEventButton button;
  58. -- GdkEventScroll scroll;
  59. -- GdkEventKey key;
  60. -- GdkEventCrossing crossing;
  61. -- GdkEventFocus focus_change;
  62. -- GdkEventConfigure configure;
  63. -- GdkEventProperty property;
  64. -- GdkEventSelection selection;
  65. -- GdkEventOwnerChange owner_change;
  66. -- GdkEventProximity proximity;
  67. -- GdkEventClient client;
  68. -- GdkEventDND dnd;
  69. -- GdkEventWindowState window_state;
  70. -- GdkEventSetting setting;
  71. -- GdkEventGrabBroken grab_broken;
  72. --};
  73. creation {WRAPPER_HANDLER} from_external_pointer
  74. feature
  75. from_external_pointer (a_pointer: POINTER) is
  76. do
  77. Precursor(a_pointer)
  78. debug
  79. std_error.put_string("GDK_EVENT.from_external_pointer: creating a generic GDK_EVENT of type "+type.out)
  80. if is_event_motion then std_error.put_string(" motion ")
  81. elseif is_event_button then std_error.put_string(" button ")
  82. elseif is_event_scroll then std_error.put_string(" scroll ")
  83. elseif is_event_key then std_error.put_string(" key ")
  84. elseif is_event_focus then std_error.put_string(" focus ")
  85. elseif is_event_crossing then std_error.put_string(" crossing ")
  86. elseif is_event_expose then std_error.put_string(" expose ")
  87. end
  88. std_error.put_line("from pointer "+a_pointer.out)
  89. end
  90. end
  91. feature
  92. type, event_type: INTEGER is
  93. do
  94. Result := gdk_event_type (handle)
  95. ensure
  96. is_valid_gdk_event_type (Result)
  97. end
  98. is_event_motion: BOOLEAN is
  99. do
  100. Result := event_type = gdk_event_motion_notify
  101. end
  102. is_event_button: BOOLEAN is
  103. do
  104. Result := (event_type = gdk_event_button_press) or else
  105. (event_type = gdk_event_2button_press) or else
  106. (event_type = gdk_event_3button_press) or else
  107. (event_type = gdk_event_button_release)
  108. end
  109. is_event_scroll: BOOLEAN is
  110. do
  111. Result := event_type = gdk_event_scroll
  112. end
  113. is_event_key: BOOLEAN is
  114. do
  115. Result := (event_type = gdk_event_key_press) or else
  116. (event_type = gdk_event_key_release)
  117. end
  118. is_event_focus: BOOLEAN is
  119. do
  120. Result := (event_type = gdk_event_focus_change)
  121. end
  122. is_event_crossing: BOOLEAN is
  123. do
  124. Result := (event_type = gdk_event_enter_notify) or else
  125. (event_type = gdk_event_leave_notify)
  126. end
  127. is_event_expose: BOOLEAN is
  128. do
  129. Result := (event_type = gdk_event_expose)
  130. end
  131. feature -- Common fields
  132. window: GDK_WINDOW is
  133. -- the window which received the event.
  134. local
  135. factory: G_OBJECT_EXPANDED_FACTORY[GDK_WINDOW]
  136. do
  137. if internal_window=Void then
  138. internal_window := factory.existant_wrapper (gdk_event_any_get_window (handle))
  139. end
  140. Result:=internal_window
  141. end
  142. send_event: BOOLEAN is
  143. -- TRUE if the event was sent explicitly (e.g. using XSendEvent).
  144. do
  145. Result := gdk_event_any_get_send_event (handle).to_boolean
  146. end
  147. feature -- Memory handling
  148. dispose is
  149. do
  150. -- TODO: See if this class could be an EIFFEL_OWNED heir.
  151. -- Note that dispose is public for this class. This is
  152. -- because it can be called when knowing that the event will
  153. -- no longer be valid (i.e, deallocated by C)
  154. if handle.is_not_null then
  155. gdk_event_free (handle)
  156. handle:= default_pointer
  157. end
  158. end
  159. struct_size: INTEGER is
  160. external "C inline use <gdk/gdk.h>"
  161. alias "sizeof(GdkEvent)"
  162. end
  163. internal_window: GDK_WINDOW
  164. invariant handle_is_not_null: is_not_null
  165. end -- class GDK_EVENT