/usr/lib/ruby/vendor_ruby/gdk3/loader.rb is in ruby-gdk3 2.2.5-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | # Copyright (C) 2013-2014 Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
module Gdk
class Loader < GObjectIntrospection::Loader
private
def window_class
@window_class ||= @base_module.const_get(:Window)
end
def event_class
@event_class ||= @base_module.const_get(:Event)
end
def event_motion_class
@event_motion_class ||= @base_module.const_get(:EventMotion)
end
def rectangle_class
@rectangle_class ||= @base_module.const_get(:Rectangle)
end
def pre_load(repository, namespace)
setup_pending_constants
define_keyval_module
define_selection_module
load_cairo_rectangle_int
end
def define_keyval_module
@keyval_module = Module.new
@base_module.const_set("Keyval", @keyval_module)
end
def define_selection_module
@selection_module = Module.new
@base_module.const_set("Selection", @selection_module)
end
def load_cairo_rectangle_int
info = find_cairo_rectangle_int_info
klass = self.class.define_class(info.gtype,
"Rectangle",
@base_module,
:size => info.size)
load_fields(info, klass)
load_methods(info, klass)
end
def find_cairo_rectangle_int_info
repository = GObjectIntrospection::Repository.default
repository.each("cairo") do |info|
if info.name == "RectangleInt"
return info
end
end
nil
end
def post_load(repository, namespace)
apply_pending_constants
require_libraries
convert_event_classes
define_selection_constants
end
def setup_pending_constants
@pending_constants = []
end
def apply_pending_constants
@pending_constants.each do |info|
case info.name
when /\AEVENT_/
event_class.const_set($POSTMATCH, info.value)
end
end
end
def require_libraries
require "gdk3/atom"
require "gdk3/color"
require "gdk3/event"
require "gdk3/rectangle"
require "gdk3/rgba"
require "gdk3/window"
require "gdk3/window-attr"
require "gdk3/cairo"
require "gdk3/deprecated"
end
def convert_event_classes
event_map = {
EventType::EXPOSE => EventExpose,
EventType::MOTION_NOTIFY => EventMotion,
EventType::BUTTON_PRESS => EventButton,
EventType::BUTTON2_PRESS => EventButton,
EventType::BUTTON3_PRESS => EventButton,
EventType::BUTTON_RELEASE => EventButton,
EventType::KEY_PRESS => EventKey,
EventType::KEY_RELEASE => EventKey,
EventType::ENTER_NOTIFY => EventCrossing,
EventType::LEAVE_NOTIFY => EventCrossing,
EventType::FOCUS_CHANGE => EventFocus,
EventType::CONFIGURE => EventConfigure,
EventType::PROPERTY_NOTIFY => EventProperty,
EventType::SELECTION_CLEAR => EventSelection,
EventType::SELECTION_REQUEST => EventSelection,
EventType::SELECTION_NOTIFY => EventSelection,
EventType::PROXIMITY_IN => EventProximity,
EventType::PROXIMITY_OUT => EventProximity,
EventType::DRAG_ENTER => EventDND,
EventType::DRAG_LEAVE => EventDND,
EventType::DRAG_MOTION => EventDND,
EventType::DRAG_STATUS => EventDND,
EventType::DROP_START => EventDND,
EventType::DROP_FINISHED => EventDND,
EventType::VISIBILITY_NOTIFY => EventVisibility,
EventType::SCROLL => EventScroll,
EventType::WINDOW_STATE => EventWindowState,
EventType::SETTING => EventSetting,
EventType::OWNER_CHANGE => EventOwnerChange,
EventType::GRAB_BROKEN => EventGrabBroken,
EventType::DAMAGE => EventExpose,
EventType::TOUCH_BEGIN => EventTouch,
EventType::TOUCH_UPDATE => EventTouch,
EventType::TOUCH_END => EventTouch,
EventType::TOUCH_CANCEL => EventTouch,
}
self.class.register_boxed_class_converter(Event.gtype) do |event|
event_map[event.type] || Event
end
end
def define_selection_constants
selections = {
"PRIMARY" => "PRIMARY",
"SECONDARY" => "SECONDARY",
"CLIPBOARD" => "CLIPBOARD",
"TARGET_BITMAP" => "BITMAP",
"TARGET_COLORMAP" => "COLORMAP",
"TARGET_DRAWABLE" => "DRAWABLE",
"TARGET_PIXMAP" => "PIXMAP",
"TARGET_STRING" => "STRING",
"TYPE_ATOM" => "ATOM",
"TYPE_BITMAP" => "BITMAP",
"TYPE_COLORMAP" => "COLORMAP",
"TYPE_DRAWABLE" => "DRAWABLE",
"TYPE_INTEGER" => "INTEGER",
"TYPE_PIXMAP" => "PIXMAP",
"TYPE_WINDOW" => "WINDOW",
"TYPE_STRING" => "STRING",
}
selections.each do |key, value|
# TODO: Gdk::Atom.intern is not working yet.
#@selection_module.const_set(key, Gdk::Atom.intern(value))
end
end
def load_function_info(info)
name = info.name
case name
when "init", /_get_type\z/
# ignore
when /\Arectangle_/
define_method(info, rectangle_class, $POSTMATCH)
when /\Apixbuf_/
target_class = nil
case $POSTMATCH
when "get_from_window"
target_class = window_class
when "get_from_surface"
target_class = Cairo::Surface
end
if target_class
define_method(info, target_class, "to_pixbuf")
else
super
end
when /\Aevent_/
name = $POSTMATCH
case name
when "request_motions"
define_method(info, event_motion_class, "request")
else
super # TODO
end
when /\Acairo_/
name = $POSTMATCH
case name
when "create"
define_method(info, window_class, "create_cairo_context")
when "set_source_color"
define_method(info, Cairo::Context, "set_source_gdk_color")
when "set_source_rgba"
define_method(info, Cairo::Context, "set_source_gdk_rgba")
when "rectangle"
define_method(info, Cairo::Context, "gdk_rectangle")
when "region_create_from_surface"
# TODO
when "surface_create_from_pixbuf"
# TODO
else
define_method(info, Cairo::Context, name)
end
when /\Akeyval_/
name = rubyish_method_name(info, :prefix => "keyval_")
define_module_function(@keyval_module, name, info)
else
super
end
end
def load_struct_info(info)
return if info.gtype_struct?
options = {}
case info.name
when /\AEvent/
options[:parent] = event_class
end
define_struct(info, options)
end
def define_enum(info)
case info.name
when "EventType"
self.class.register_constant_rename_map("2BUTTON_PRESS",
"BUTTON2_PRESS")
self.class.register_constant_rename_map("3BUTTON_PRESS",
"BUTTON3_PRESS")
super
else
super
end
end
def load_constant_info(info)
case info.name
when /\AEVENT_/
@pending_constants << info
when /\AKEY_/
@keyval_module.const_set(info.name, info.value)
else
super
end
end
end
end
|