/src/wrappers/gdk/library/gdk_event.e
Specman e | 194 lines | 114 code | 29 blank | 51 comment | 5 complexity | 047ad249201076d4794e42f140d4f282 MD5 | raw file
1indexing 2 description: "union GdkEvent" 3 copyright: "[ 4 Copyright (C) 2006 eiffel-libraries team, GTK+ team 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public License 8 as published by the Free Software Foundation; either version 2.1 of 9 the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA 20 ]" 21 license: "LGPL v2 or later" 22 date: "$Date:$" 23 revision: "$Revision:$" 24 25class GDK_EVENT 26 27inherit 28 C_STRUCT 29 redefine from_external_pointer end 30 31insert 32 GDK_EVENT_EXTERNALS 33 GDK_EVENT_ANY_EXTERNALS 34 -- The GdkEvent struct contains a union of all of the event 35 -- structs, and allows access to the data fields in a number of 36 -- ways. 37 38 -- The event type is always the first field in all of the event 39 -- structs, and can always be accessed with the following code, no 40 -- matter what type of event it is: 41 42 -- GdkEvent *event; 43 -- GdkEventType type; 44 -- type = event->type; 45 46 -- To access other fields of the event structs, the pointer to 47 -- the event can be cast to the appropriate event struct pointer, 48 -- or the union member name can be used. For example if the event 49 -- type is GDK_BUTTON_PRESS then the x coordinate of the button 50 -- press can be accessed with: 51 52 -- GdkEvent *event; 53 -- gdouble x; 54 -- x = ((GdkEventButton*)event)->x; 55 --or: 56 -- GdkEvent *event; 57 -- gdouble x; 58 -- x = event->button.x; 59 60 --union GdkEvent 61 --{ 62 -- GdkEventType type; 63 -- GdkEventAny any; 64 -- GdkEventExpose expose; 65 -- GdkEventNoExpose no_expose; 66 -- GdkEventVisibility visibility; 67 -- GdkEventMotion motion; 68 -- GdkEventButton button; 69 -- GdkEventScroll scroll; 70 -- GdkEventKey key; 71 -- GdkEventCrossing crossing; 72 -- GdkEventFocus focus_change; 73 -- GdkEventConfigure configure; 74 -- GdkEventProperty property; 75 -- GdkEventSelection selection; 76 -- GdkEventOwnerChange owner_change; 77 -- GdkEventProximity proximity; 78 -- GdkEventClient client; 79 -- GdkEventDND dnd; 80 -- GdkEventWindowState window_state; 81 -- GdkEventSetting setting; 82 -- GdkEventGrabBroken grab_broken; 83 --}; 84 85creation {WRAPPER_HANDLER} from_external_pointer 86 87feature 88 from_external_pointer (a_pointer: POINTER) is 89 do 90 Precursor(a_pointer) 91 debug 92 std_error.put_string("GDK_EVENT.from_external_pointer: creating a generic GDK_EVENT of type "+type.out) 93 if is_event_motion then std_error.put_string(" motion ") 94 elseif is_event_button then std_error.put_string(" button ") 95 elseif is_event_scroll then std_error.put_string(" scroll ") 96 elseif is_event_key then std_error.put_string(" key ") 97 elseif is_event_focus then std_error.put_string(" focus ") 98 elseif is_event_crossing then std_error.put_string(" crossing ") 99 elseif is_event_expose then std_error.put_string(" expose ") 100 end 101 std_error.put_line("from pointer "+a_pointer.out) 102 end 103 end 104feature 105 106 type, event_type: INTEGER is 107 do 108 Result := gdk_event_type (handle) 109 ensure 110 is_valid_gdk_event_type (Result) 111 end 112 113 is_event_motion: BOOLEAN is 114 do 115 Result := event_type = gdk_event_motion_notify 116 end 117 118 is_event_button: BOOLEAN is 119 do 120 Result := (event_type = gdk_event_button_press) or else 121 (event_type = gdk_event_2button_press) or else 122 (event_type = gdk_event_3button_press) or else 123 (event_type = gdk_event_button_release) 124 end 125 126 is_event_scroll: BOOLEAN is 127 do 128 Result := event_type = gdk_event_scroll 129 end 130 131 is_event_key: BOOLEAN is 132 do 133 Result := (event_type = gdk_event_key_press) or else 134 (event_type = gdk_event_key_release) 135 end 136 137 is_event_focus: BOOLEAN is 138 do 139 Result := (event_type = gdk_event_focus_change) 140 end 141 142 is_event_crossing: BOOLEAN is 143 do 144 Result := (event_type = gdk_event_enter_notify) or else 145 (event_type = gdk_event_leave_notify) 146 end 147 148 is_event_expose: BOOLEAN is 149 do 150 Result := (event_type = gdk_event_expose) 151 end 152 153feature -- Common fields 154 window: GDK_WINDOW is 155 -- the window which received the event. 156 local 157 factory: G_OBJECT_EXPANDED_FACTORY[GDK_WINDOW] 158 do 159 if internal_window=Void then 160 internal_window := factory.existant_wrapper (gdk_event_any_get_window (handle)) 161 end 162 Result:=internal_window 163 end 164 165 send_event: BOOLEAN is 166 -- TRUE if the event was sent explicitly (e.g. using XSendEvent). 167 do 168 Result := gdk_event_any_get_send_event (handle).to_boolean 169 end 170 171feature -- Memory handling 172 173 dispose is 174 do 175 -- TODO: See if this class could be an EIFFEL_OWNED heir. 176 177 -- Note that dispose is public for this class. This is 178 -- because it can be called when knowing that the event will 179 -- no longer be valid (i.e, deallocated by C) 180 if handle.is_not_null then 181 gdk_event_free (handle) 182 handle:= default_pointer 183 end 184 end 185 186 struct_size: INTEGER is 187 external "C inline use <gdk/gdk.h>" 188 alias "sizeof(GdkEvent)" 189 end 190 191 internal_window: GDK_WINDOW 192 193 invariant handle_is_not_null: is_not_null 194end -- class GDK_EVENT