3 (defconst GTK_TYPE_INVALID 0)
4 (defconst GTK_TYPE_NONE 1)
5 (defconst GTK_TYPE_CHAR 2)
6 (defconst GTK_TYPE_UCHAR 3)
7 (defconst GTK_TYPE_BOOL 4)
8 (defconst GTK_TYPE_INT 5)
9 (defconst GTK_TYPE_UINT 6)
10 (defconst GTK_TYPE_LONG 7)
11 (defconst GTK_TYPE_ULONG 8)
12 (defconst GTK_TYPE_FLOAT 9)
13 (defconst GTK_TYPE_DOUBLE 10)
14 (defconst GTK_TYPE_STRING 11)
15 (defconst GTK_TYPE_ENUM 12)
16 (defconst GTK_TYPE_FLAGS 13)
17 (defconst GTK_TYPE_BOXED 14)
18 (defconst GTK_TYPE_POINTER 15)
19 (defconst GTK_TYPE_SIGNAL 16)
20 (defconst GTK_TYPE_ARGS 17)
21 (defconst GTK_TYPE_CALLBACK 18)
22 (defconst GTK_TYPE_C_CALLBACK 19)
23 (defconst GTK_TYPE_FOREIGN 20)
24 (defconst GTK_TYPE_OBJECT 21)
26 (defconst gtk-value-accessor-names
27 '("INVALID" "NONE" "CHAR" "UCHAR" "BOOL" "INT" "UINT" "LONG" "ULONG" "FLOAT" "DOUBLE"
28 "STRING" "ENUM" "FLAGS" "BOXED" "POINTER" "SIGNAL" "ARGS" "CALLBACK" "C_CALLBACK"
31 (defun define-widget-accessors (gtk-class
34 "Output stub C code to access parts of a widget from lisp.
35 GTK-CLASS is the GTK class to grant access to.
36 WRAPPER is a fragment to construct GTK C macros for typechecking/etc. (ie: WIDGET)
37 ARGS is a list of (type . name) cons cells.
38 Defines a whole slew of functions to access & set the slots in the
40 (set-buffer (get-buffer-create "emacs-widget-accessors.c"))
41 (goto-char (point-max))
47 (setq gtk-class (symbol-name gtk-class)
48 wrapper (upcase wrapper))
49 (while (setq arg (pop args))
50 (setq lisp-func-name (format "gtk-%s-%s" prefix (cdr arg))
51 lisp-func-name (replace-in-string lisp-func-name "_" "-")
52 c-func-name (concat "F" (replace-in-string lisp-func-name "-" "_")))
54 "DEFUN (\"" lisp-func-name "\", " c-func-name ", 1, 1, 0, /*\n"
55 "Access the `" (symbol-name (cdr arg)) "' slot of OBJ, a " gtk-class " object.\n"
59 (format "\t%s *the_obj = NULL;\n" gtk-class)
62 "\tCHECK_GTK_OBJECT (obj);\n"
64 (format "\tif (!GTK_IS_%s (XGTK_OBJECT (obj)->object))\n" wrapper)
66 (format "\t\tsignal_simple_error (\"Object is not a %s\", obj);\n" gtk-class)
69 (format "\tthe_obj = GTK_%s (XGTK_OBJECT (obj)->object);\n" wrapper)
71 (format "\targ.type = gtk_type_from_name (\"%s\");\n" (symbol-name (car arg))))
72 ; (format "\targ.type = GTK_TYPE_%s;\n" (or
73 ; (nth (gtk-fundamental-type (car arg))
74 ; gtk-value-accessor-names)
76 ; (GtkListOfString "STRING_LIST")
77 ; (GtkListOfObject "OBJECT_LIST")
81 (setq base-arg-type (gtk-fundamental-type (car arg)))
83 ((= base-arg-type GTK_TYPE_OBJECT)
85 (format "\tGTK_VALUE_OBJECT (arg) = GTK_OBJECT (the_obj->%s);"
87 ((or (= base-arg-type GTK_TYPE_POINTER)
88 (= base-arg-type GTK_TYPE_BOXED))
90 (format "\tGTK_VALUE_%s (arg) = (void *)the_obj->%s;"
91 (nth (gtk-fundamental-type (car arg)) gtk-value-accessor-names)
95 (format "\tGTK_VALUE_%s (arg) = the_obj->%s;"
96 (or (nth (gtk-fundamental-type (car arg)) gtk-value-accessor-names) "POINTER")
100 "\treturn (gtk_type_to_lisp (&arg));\n"
102 (push c-func-name func-names))
105 (defun import-widget-accessors (file syms-function-name &rest description)
106 "Import multiple widgets, and emit a suitable vars_of_foo() function for them.\n"
107 (let ((c-mode-common-hook nil)
113 (setq c-funcs (nconc (define-widget-accessors
114 (pop description) (pop description)
115 (pop description) (pop description)) c-funcs)))
116 (goto-char (point-max))
117 (insert "void " syms-function-name " (void)\n"
119 (mapconcat (lambda (x)
120 (concat "DEFSUBR (" x ");")) c-funcs "\n\t")
124 ;; Because the new FFI layer imports GTK types lazily, we need to load
125 ;; up all of the gtk types we know about, or we get errors about
126 ;; unknown GTK types later on.
127 (mapatoms (lambda (sym)
128 (if (string-match "gtk-[^-]+-get-type" (symbol-name sym))
131 (import-widget-accessors
132 "../../src/emacs-widget-accessors.c"
133 "syms_of_widget_accessors "
135 'GtkAdjustment "ADJUSTMENT" "adjustment"
139 (gfloat . step_increment)
140 (gfloat . page_increment)
141 (gfloat . page_size))
143 'GtkWidget "WIDGET" "widget"
146 (GtkStateType . state)
148 (GtkWidget . parent))
150 'GtkButton "BUTTON" "button"
151 '((GtkWidget . child)
152 (gboolean . in_button)
153 (gboolean . button_down))
155 'GtkCombo "COMBO" "combo"
156 '((GtkWidget . entry)
162 'GtkGammaCurve "GAMMA_CURVE" "gamma-curve"
163 '((GtkWidget . table)
166 (GtkWidget . gamma_dialog)
167 (GtkWidget . gamma_text))
169 'GtkCheckMenuItem "CHECK_MENU_ITEM" "check-menu-item"
170 '((gboolean . active))
172 'GtkNotebook "NOTEBOOK" "notebook"
173 '((GtkPositionType . tab_pos))
175 'GtkText "TEXT" "text"
176 '((GtkAdjustment . hadj)
177 (GtkAdjustment . vadj))
179 'GtkFileSelection "FILE_SELECTION" "file-selection"
180 '((GtkWidget . dir_list)
181 (GtkWidget . file_list)
182 (GtkWidget . selection_entry)
183 (GtkWidget . selection_text)
184 (GtkWidget . main_vbox)
185 (GtkWidget . ok_button)
186 (GtkWidget . cancel_button)
187 (GtkWidget . help_button)
188 (GtkWidget . action_area))
190 'GtkFontSelectionDialog "FONT_SELECTION_DIALOG" "font-selection-dialog"
191 '((GtkWidget . fontsel)
192 (GtkWidget . main_vbox)
193 (GtkWidget . action_area)
194 (GtkWidget . ok_button)
195 (GtkWidget . apply_button)
196 (GtkWidget . cancel_button))
198 'GtkColorSelectionDialog "COLOR_SELECTION_DIALOG" "color-selection-dialog"
199 '((GtkWidget . colorsel)
200 (GtkWidget . main_vbox)
201 (GtkWidget . ok_button)
202 (GtkWidget . reset_button)
203 (GtkWidget . cancel_button)
204 (GtkWidget . help_button))
206 'GtkDialog "DIALOG" "dialog"
208 (GtkWidget . action_area))
210 'GtkInputDialog "INPUT_DIALOG" "input-dialog"
211 '((GtkWidget . close_button)
212 (GtkWidget . save_button))
214 'GtkPlug "PLUG" "plug"
215 '((GdkWindow . socket_window)
218 'GtkObject "OBJECT" "object"
222 'GtkPaned "PANED" "paned"
223 '((GtkWidget . child1)
225 (gboolean . child1_resize)
226 (gboolean . child2_resize)
227 (gboolean . child1_shrink)
228 (gboolean . child2_shrink))
230 'GtkCList "CLIST" "clist"
233 (GtkAdjustment . hadjustment)
234 (GtkAdjustment . vadjustment)
235 (GtkSortType . sort_type)
237 (gint . sort_column))
239 'GtkList "LIST" "list"
240 '((GtkListOfObject . children)
241 (GtkListOfObject . selection))
243 'GtkTree "TREE" "tree"
244 '((GtkListOfObject . children)
245 (GtkTree . root_tree)
246 (GtkWidget . tree_owner)
247 (GtkListOfObject . selection))
249 'GtkTreeItem "TREE_ITEM" "tree-item"
250 '((GtkWidget . subtree))
252 'GtkScrolledWindow "SCROLLED_WINDOW" "scrolled-window"
253 '((GtkWidget . hscrollbar)
254 (GtkWidget . vscrollbar)
255 (gboolean . hscrollbar_visible)
256 (gboolean . vscrollbar_visible))