Added timeouts
[cl-gtk2.git] / glib / gobject.type-designator.lisp
index 7cf8bf7..5468403 100644 (file)
@@ -3,15 +3,23 @@
 (defctype g-type gsize)
 
 (define-foreign-type g-type-designator ()
-  ()
+  ((mangled-p :initarg :mangled-p
+              :reader g-type-designator-mangled-p
+              :initform nil
+              :documentation "Whether the type designator is mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag"))
   (:documentation "Values of this CFFI foreign type identify the GType. GType is designated by a its name (a string) or a numeric identifier. Functions accept GType designators as a string or integer and return them as a string. Functions @fun{g-type-name} and @fun{g-type-from-name} are used to convert between name and numeric identifier.
 
 Numeric identifier of GType may be different between different program runs. But string identifier of GType does not change.")
   (:actual-type g-type)
   (:simple-parser g-type-designator))
 
+(defun unmangle-g-type (g-type)
+  (logxor g-type (ldb (byte 1 0) g-type)));;subtract the G_SIGNAL_TYPE_STATIC_SCOPE
+
 (defmethod translate-from-foreign (value (type g-type-designator))
-  (g-type-name value))
+  (g-type-name (if (g-type-designator-mangled-p type)
+                   (unmangle-g-type value)
+                   value)))
 
 (defmethod translate-to-foreign (value (type g-type-designator))
   (etypecase value
@@ -19,6 +27,18 @@ Numeric identifier of GType may be different between different program runs. But
     (integer value)
     (null 0)))
 
+(defun g-type-numeric (g-type-designator)
+  (etypecase g-type-designator
+    (string (g-type-from-name g-type-designator))
+    (integer g-type-designator)
+    (null 0)))
+
+(defun g-type-string (g-type-designator)
+  (etypecase g-type-designator
+    (string (g-type-name g-type-designator))
+    (integer (g-type-name g-type-designator))
+    (null nil)))
+
 (defcfun (g-type-name "g_type_name") :string
   "Returns the name of a GType.@see{g-type-from-name}
 
@@ -45,4 +65,12 @@ Example:
 }
 @arg[name]{a string - name of GType}
 @return{an integer}"
-  (name :string))
\ No newline at end of file
+  (name :string))
+
+(defun g-type= (type-1 type-2)
+  (= (g-type-numeric type-1)
+     (g-type-numeric type-2)))
+
+(defun g-type/= (type-1 type-2)
+  (/= (g-type-numeric type-1)
+      (g-type-numeric type-2)))