1 /* I really wish this entire file could go away, but there is
2 currently no way to do the following in the Foreign Function
5 1) Deal with return values in the parameter list (ie: int *foo)
7 So we have to code a few functions by hand. Ick.
9 William M. Perry 5/8/00
14 DEFUN("gtk-box-query-child-packing", Fgtk_box_query_child_packing, 2, 2, 0, /*
15 Returns information about how CHILD is packed into BOX.
16 Return value is a list of (EXPAND FILL PADDING PACK_TYPE).
20 gboolean expand, fill;
22 GtkPackType pack_type;
23 Lisp_Object result = Qnil;
25 CHECK_GTK_OBJECT(box);
26 CHECK_GTK_OBJECT(child);
28 if (!GTK_IS_BOX(XGTK_OBJECT(box)->object)) {
29 signal_simple_error("Object is not a GtkBox", box);
32 if (!GTK_IS_WIDGET(XGTK_OBJECT(child)->object)) {
33 signal_simple_error("Child is not a GtkWidget", child);
36 gtk_box_query_child_packing(GTK_BOX(XGTK_OBJECT(box)->object),
37 GTK_WIDGET(XGTK_OBJECT(child)->object),
38 &expand, &fill, &padding, &pack_type);
40 result = Fcons(make_int(pack_type), result);
41 result = Fcons(make_int(padding), result);
42 result = Fcons(fill ? Qt : Qnil, result);
43 result = Fcons(expand ? Qt : Qnil, result);
48 /* void gtk_button_box_get_child_size_default (gint *min_width, gint *min_height); */
49 DEFUN("gtk-button-box-get-child-size-default", Fgtk_button_box_get_child_size_default, 0, 0, 0, /*
50 Return a cons cell (WIDTH . HEIGHT) of the default button box child size.
56 gtk_button_box_get_child_size_default(&width, &height);
58 return (Fcons(make_int(width), make_int(height)));
61 /* void gtk_button_box_get_child_ipadding_default (gint *ipad_x, gint *ipad_y); */
62 DEFUN("gtk-button-box-get-child-ipadding-default", Fgtk_button_box_get_child_ipadding_default, 0, 0, 0, /*
63 Return a cons cell (X . Y) of the default button box ipadding.
69 gtk_button_box_get_child_ipadding_default(&x, &y);
71 return (Fcons(make_int(x), make_int(y)));
74 /* void gtk_button_box_get_child_size (GtkButtonBox *widget,
75 gint *min_width, gint *min_height); */
76 DEFUN("gtk-button-box-get-child-size", Fgtk_button_box_get_child_size, 1, 1, 0, /*
77 Get the current size of a child in the buttonbox BOX.
83 CHECK_GTK_OBJECT(box);
85 if (!GTK_IS_BUTTON_BOX(XGTK_OBJECT(box)->object)) {
86 signal_simple_error("Not a GtkBox object", box);
89 gtk_button_box_get_child_size(GTK_BUTTON_BOX(XGTK_OBJECT(box)->object),
92 return (Fcons(make_int(width), make_int(height)));
95 /* void gtk_button_box_get_child_ipadding (GtkButtonBox *widget, gint *ipad_x, gint *ipad_y); */
96 DEFUN("gtk-button-box-get-child-ipadding", Fgtk_button_box_get_child_ipadding, 1, 1, 0, /*
97 Return a cons cell (X . Y) of the current buttonbox BOX ipadding.
103 CHECK_GTK_OBJECT(box);
105 if (!GTK_IS_BUTTON_BOX(XGTK_OBJECT(box)->object)) {
106 signal_simple_error("Not a GtkBox object", box);
109 gtk_button_box_get_child_ipadding(GTK_BUTTON_BOX
110 (XGTK_OBJECT(box)->object), &x, &y);
112 return (Fcons(make_int(x), make_int(y)));
115 /*void gtk_calendar_get_date (GtkCalendar *calendar,
120 DEFUN("gtk-calendar-get-date", Fgtk_calendar_get_date, 1, 1, 0, /*
121 Return a list of (YEAR MONTH DAY) from the CALENDAR object.
125 guint year, month, day;
127 CHECK_GTK_OBJECT(calendar);
129 if (!GTK_IS_CALENDAR(XGTK_OBJECT(calendar)->object)) {
130 signal_simple_error("Not a GtkCalendar object", calendar);
133 gtk_calendar_get_date(GTK_CALENDAR(XGTK_OBJECT(calendar)->object),
134 &year, &month, &day);
136 return (list3(make_int(year), make_int(month), make_int(day)));
139 /* gint gtk_clist_get_text (GtkCList *clist,
144 DEFUN("gtk-clist-get-text", Fgtk_clist_get_text, 3, 3, 0, /*
145 Returns the text from GtkCList OBJ cell at coordinates ROW, COLUMN.
150 Lisp_Object rval = Qnil;
152 CHECK_GTK_OBJECT(obj);
156 if (!GTK_IS_CLIST(XGTK_OBJECT(obj)->object)) {
157 signal_simple_error("Object is not a GtkCList", obj);
160 gtk_clist_get_text(GTK_CLIST(XGTK_OBJECT(obj)->object), XINT(row),
161 XINT(column), &text);
164 rval = build_string(text);
165 /* NOTE: This is NOT a memory leak. GtkCList returns a pointer
166 to internally used memory, not a copy of it.
174 /* gint gtk_clist_get_selection_info (GtkCList *clist,
179 DEFUN("gtk-clist-get-selection-info", Fgtk_clist_get_selection, 3, 3, 0, /*
180 Returns a cons cell of (ROW . COLUMN) of the GtkCList OBJ at coordinates X, Y.
186 CHECK_GTK_OBJECT(obj);
190 if (!GTK_IS_CLIST(XGTK_OBJECT(obj)->object)) {
191 signal_simple_error("Object is not a GtkCList", obj);
194 gtk_clist_get_selection_info(GTK_CLIST(XGTK_OBJECT(obj)->object),
195 XINT(x), XINT(y), &row, &column);
197 return (Fcons(make_int(row), make_int(column)));
200 DEFUN("gtk-clist-get-pixmap", Fgtk_clist_get_pixmap, 3, 3, 0, /*
201 Return a cons of (pixmap . mask) at ROW,COLUMN in CLIST.
203 (clist, row, column))
205 GdkPixmap *pixmap = NULL;
206 GdkBitmap *mask = NULL;
208 CHECK_GTK_OBJECT(clist);
212 if (!GTK_IS_CLIST(XGTK_OBJECT(clist)->object)) {
213 signal_simple_error("Object is not a GtkCList", clist);
216 gtk_clist_get_pixmap(GTK_CLIST(XGTK_OBJECT(clist)->object),
217 XINT(row), XINT(column), &pixmap, &mask);
220 (pixmap ? build_gtk_boxed(pixmap, GTK_TYPE_GDK_WINDOW) : Qnil,
221 mask ? build_gtk_boxed(mask, GTK_TYPE_GDK_WINDOW) : Qnil));
224 DEFUN("gtk-clist-get-pixtext", Fgtk_clist_get_pixtext, 3, 3, 0, /*
225 Return a list of (pixmap mask text) at ROW,COLUMN in CLIST.
227 (clist, row, column))
229 GdkPixmap *pixmap = NULL;
230 GdkBitmap *mask = NULL;
234 CHECK_GTK_OBJECT(clist);
238 if (!GTK_IS_CLIST(XGTK_OBJECT(clist)->object)) {
239 signal_simple_error("Object is not a GtkCList", clist);
242 gtk_clist_get_pixtext(GTK_CLIST(XGTK_OBJECT(clist)->object),
243 XINT(row), XINT(column), &text, &spacing,
247 (pixmap ? build_gtk_boxed(pixmap, GTK_TYPE_GDK_WINDOW) : Qnil,
248 mask ? build_gtk_boxed(mask, GTK_TYPE_GDK_WINDOW) : Qnil, (text
252 ? build_string(text) : Qnil));
255 /* void gtk_color_selection_get_color(GtkColorSelection *colorsel, gdouble *color); */
256 DEFUN("gtk-color-selection-get-color", Fgtk_color_selection_get_color, 1, 1, 0, /*
257 Return a list of (RED GREEN BLUE ALPHA) from the GtkColorSelection OBJECT.
263 CHECK_GTK_OBJECT(object);
265 if (!GTK_IS_COLOR_SELECTION(XGTK_OBJECT(object)->object)) {
266 signal_simple_error("Object is not a GtkColorSelection",
270 gtk_color_selection_get_color(GTK_COLOR_SELECTION(XGTK_OBJECT(object)),
273 return (list4(make_float(rgba[0]),
275 make_float(rgba[2]), make_float(rgba[3])));
278 /* (gtk-import-function nil "gtk_editable_insert_text" 'GtkEditable 'GtkString 'gint 'pointer-to-gint) */
279 DEFUN("gtk-editable-insert-text", Fgtk_editable_insert_text, 3, 3, 0, /*
280 Insert text STRINT at POS in GtkEditable widget OBJ.
281 Returns the new position of the cursor in the widget.
287 CHECK_GTK_OBJECT(obj);
288 CHECK_STRING(string);
293 if (!GTK_IS_EDITABLE(XGTK_OBJECT(obj)->object)) {
294 signal_simple_error("Object is not a GtkEditable", obj);
297 gtk_editable_insert_text(GTK_EDITABLE(XGTK_OBJECT(obj)->object),
298 (char *)XSTRING_DATA(string),
299 XSTRING_LENGTH(string), &the_pos);
301 return (make_int(the_pos));
304 DEFUN("gtk-pixmap-get", Fgtk_pixmap_get, 1, 1, 0, /*
305 Return a cons cell of (PIXMAP . MASK) from GtkPixmap OBJECT.
309 GdkPixmap *pixmap, *mask;
311 CHECK_GTK_OBJECT(object);
313 if (!GTK_IS_PIXMAP(XGTK_OBJECT(object)->object)) {
314 signal_simple_error("Object is not a GtkPixmap", object);
317 gtk_pixmap_get(GTK_PIXMAP(XGTK_OBJECT(object)->object), &pixmap, &mask);
319 return (Fcons(pixmap ? build_gtk_object(GTK_OBJECT(pixmap)) : Qnil,
320 mask ? build_gtk_object(GTK_OBJECT(mask)) : Qnil));
323 DEFUN("gtk-curve-get-vector", Fgtk_curve_get_vector, 2, 2, 0, /*
324 Returns a vector of LENGTH points representing the curve of CURVE.
328 gfloat *vector = NULL;
329 Lisp_Object lisp_vector = Qnil;
332 CHECK_GTK_OBJECT(curve);
335 if (!GTK_IS_CURVE(XGTK_OBJECT(curve)->object)) {
336 signal_simple_error("Object is not a GtkCurve", curve);
339 vector = (gfloat *) alloca(sizeof(gfloat) * XINT(length));
341 gtk_curve_get_vector(GTK_CURVE(XGTK_OBJECT(curve)->object),
342 XINT(length), vector);
343 lisp_vector = make_vector(XINT(length), Qnil);
345 for (i = 0; i < XINT(length); i++) {
346 XVECTOR_DATA(lisp_vector)[i] = make_float(vector[i]);
349 return (lisp_vector);
352 DEFUN("gtk-curve-set-vector", Fgtk_curve_set_vector, 2, 2, 0, /*
353 Set the vector of points on CURVE to VECTOR.
357 gfloat *c_vector = NULL;
361 CHECK_GTK_OBJECT(curve);
362 CHECK_VECTOR(vector);
364 vec_length = XVECTOR_LENGTH(vector);
366 if (!GTK_IS_CURVE(XGTK_OBJECT(curve)->object)) {
367 signal_simple_error("Object is not a GtkCurve", curve);
370 c_vector = (gfloat *) alloca(sizeof(gfloat) * vec_length);
372 for (i = 0; i < vec_length; i++) {
373 CHECK_FLOAT(XVECTOR_DATA(vector)[i]);
374 c_vector[i] = extract_float(XVECTOR_DATA(vector)[i]);
377 gtk_curve_set_vector(GTK_CURVE(XGTK_OBJECT(curve)->object), vec_length,
382 DEFUN("gtk-label-get", Fgtk_label_get, 1, 1, 0, /*
383 Return the text of LABEL.
389 CHECK_GTK_OBJECT(label);
391 if (!GTK_IS_LABEL(XGTK_OBJECT(label)->object)) {
392 signal_simple_error("Object is not a GtkLabel", label);
395 gtk_label_get(GTK_LABEL(XGTK_OBJECT(label)->object), &string);
397 return (build_string(string));
400 DEFUN("gtk-notebook-query-tab-label-packing", Fgtk_notebook_query_tab_label_packing, 2, 2, 0, /*
401 Return a list of packing information (EXPAND FILL PACK_TYPE) for CHILD in NOTEBOOK.
405 gboolean expand, fill;
406 GtkPackType pack_type;
408 CHECK_GTK_OBJECT(notebook);
409 CHECK_GTK_OBJECT(child);
411 if (!GTK_IS_NOTEBOOK(XGTK_OBJECT(notebook)->object)) {
412 signal_simple_error("Object is not a GtkLabel", notebook);
415 if (!GTK_IS_WIDGET(XGTK_OBJECT(child)->object)) {
416 signal_simple_error("Object is not a GtkWidget", child);
419 gtk_notebook_query_tab_label_packing(GTK_NOTEBOOK
420 (XGTK_OBJECT(notebook)->object),
421 GTK_WIDGET(XGTK_OBJECT(child)->
422 object), &expand, &fill,
426 (expand ? Qt : Qnil, fill ? Qt : Qnil, make_int(pack_type)));
429 DEFUN("gtk-widget-get-pointer", Fgtk_widget_get_pointer, 1, 1, 0, /*
430 Return the pointer position relative to WIDGET as a cons of (X . Y).
435 CHECK_GTK_OBJECT(widget);
437 if (!GTK_IS_WIDGET(XGTK_OBJECT(widget)->object)) {
438 signal_simple_error("Object is not a GtkWidget", widget);
441 gtk_widget_get_pointer(GTK_WIDGET(XGTK_OBJECT(widget)->object), &x, &y);
443 return (Fcons(make_int(x), make_int(y)));
446 /* This is called whenever an item with a GUI_ID associated with it is
447 destroyed. This allows us to remove the references in gui-gtk.c
448 that made sure callbacks and such were GCPRO-ed
450 static void __remove_gcpro_by_id(gpointer user_data)
452 ungcpro_popup_callbacks((GUI_ID) user_data);
455 static void __generic_toolbar_callback(GtkWidget * item, gpointer user_data)
457 Lisp_Object callback;
458 Lisp_Object lisp_user_data;
460 VOID_TO_LISP(callback, user_data);
462 lisp_user_data = XCAR(callback);
463 callback = XCDR(callback);
465 signal_special_gtk_user_event(Qnil, callback, lisp_user_data);
469 generic_toolbar_insert_item(Lisp_Object toolbar,
471 Lisp_Object tooltip_text,
472 Lisp_Object tooltip_private_text,
474 Lisp_Object callback,
476 Lisp_Object prepend_p, Lisp_Object position)
481 CHECK_GTK_OBJECT(toolbar);
482 CHECK_GTK_OBJECT(icon);
484 CHECK_STRING(tooltip_text);
485 CHECK_STRING(tooltip_private_text);
487 if (!SYMBOLP(callback) && !LISTP(callback)) {
488 signal_simple_error("Callback must be symbol or eval-able form",
492 if (!GTK_IS_TOOLBAR(XGTK_OBJECT(toolbar)->object)) {
493 signal_simple_error("Object is not a GtkToolbar", toolbar);
496 if (!GTK_IS_WIDGET(XGTK_OBJECT(icon)->object)) {
497 signal_simple_error("Object is not a GtkWidget", icon);
500 callback = Fcons(data, callback);
503 gcpro_popup_callbacks(id, callback);
504 gtk_object_weakref(XGTK_OBJECT(toolbar)->object, __remove_gcpro_by_id,
507 if (NILP(position)) {
508 w = (NILP(prepend_p) ? gtk_toolbar_append_item :
509 gtk_toolbar_prepend_item)
510 (GTK_TOOLBAR(XGTK_OBJECT(toolbar)->object),
511 XSTRING_DATA(text), XSTRING_DATA(tooltip_text),
512 XSTRING_DATA(tooltip_private_text),
513 GTK_WIDGET(XGTK_OBJECT(icon)->object),
514 GTK_SIGNAL_FUNC(__generic_toolbar_callback),
515 LISP_TO_VOID(callback));
517 w = gtk_toolbar_insert_item(GTK_TOOLBAR
518 (XGTK_OBJECT(toolbar)->object),
520 XSTRING_DATA(tooltip_text),
521 XSTRING_DATA(tooltip_private_text),
522 GTK_WIDGET(XGTK_OBJECT(icon)->
525 (__generic_toolbar_callback),
526 LISP_TO_VOID(callback),
530 return (w ? build_gtk_object(GTK_OBJECT(w)) : Qnil);
533 DEFUN("gtk-toolbar-append-item", Fgtk_toolbar_append_item, 6, 7, 0, /*
534 Appends a new button to the given toolbar.
536 (toolbar, text, tooltip_text, tooltip_private_text, icon, callback, data))
538 return (generic_toolbar_insert_item
539 (toolbar, text, tooltip_text, tooltip_private_text, icon,
540 callback, data, Qnil, Qnil));
543 DEFUN("gtk-toolbar-prepend-item", Fgtk_toolbar_prepend_item, 6, 7, 0, /*
544 Adds a new button to the beginning (left or top edges) of the given toolbar.
546 (toolbar, text, tooltip_text, tooltip_private_text, icon, callback, data))
548 return (generic_toolbar_insert_item
549 (toolbar, text, tooltip_text, tooltip_private_text, icon,
550 callback, data, Qt, Qnil));
553 DEFUN("gtk-toolbar-insert-item", Fgtk_toolbar_insert_item, 7, 8, 0, /*
554 Adds a new button to the beginning (left or top edges) of the given toolbar.
556 (toolbar, text, tooltip_text, tooltip_private_text, icon, callback,
561 return (generic_toolbar_insert_item
562 (toolbar, text, tooltip_text, tooltip_private_text, icon,
563 callback, data, Qnil, position));
566 /* GtkCTree is an abomination in the eyes of the object system. */
568 __emacs_gtk_ctree_recurse_internal(GtkCTree * ctree, GtkCTreeNode * node,
573 VOID_TO_LISP(closure, user_data);
576 build_gtk_object(GTK_OBJECT(ctree)),
577 build_gtk_boxed(node, GTK_TYPE_CTREE_NODE), XCDR(closure));
580 DEFUN("gtk-ctree-recurse", Fgtk_ctree_recurse, 3, 6, 0, /*
581 Recursively apply FUNC to all nodes of CTREE at or below NODE.
582 FUNC is called with three arguments: CTREE, a GtkCTreeNode, and DATA.
583 The return value of FUNC is ignored.
585 If optional 5th argument CHILDFIRSTP is non-nil, then
586 the function is called for each node after it has been
587 called for that node's children.
589 Optional 6th argument DEPTH limits how deeply to recurse.
591 This function encompasses all the following Gtk functions:
593 void gtk_ctree_post_recursive (GtkCTree *ctree,
597 void gtk_ctree_post_recursive_to_depth (GtkCTree *ctree,
602 void gtk_ctree_pre_recursive (GtkCTree *ctree,
606 void gtk_ctree_pre_recursive_to_depth (GtkCTree *ctree,
612 (ctree, node, func, data, childfirstp, depth))
614 struct gcpro gcpro1, gcpro2, gcpro3;
615 Lisp_Object closure = Qnil;
617 CHECK_GTK_OBJECT(ctree);
620 CHECK_GTK_BOXED(node);
627 closure = Fcons(func, data);
629 GCPRO3(ctree, node, closure);
632 (NILP(childfirstp) ? gtk_ctree_post_recursive :
633 gtk_ctree_pre_recursive)
634 (GTK_CTREE(XGTK_OBJECT(ctree)->object),
635 NILP(node) ? NULL : (GtkCTreeNode *) XGTK_BOXED(node)->
636 object, __emacs_gtk_ctree_recurse_internal,
637 LISP_TO_VOID(closure));
639 (NILP(childfirstp) ? gtk_ctree_post_recursive_to_depth :
640 gtk_ctree_pre_recursive_to_depth)
641 (GTK_CTREE(XGTK_OBJECT(ctree)->object),
642 NILP(node) ? NULL : (GtkCTreeNode *) XGTK_BOXED(node)->
643 object, XINT(depth), __emacs_gtk_ctree_recurse_internal,
644 LISP_TO_VOID(closure));
651 void syms_of_ui_byhand(void)
653 DEFSUBR(Fgtk_toolbar_append_item);
654 DEFSUBR(Fgtk_toolbar_insert_item);
655 DEFSUBR(Fgtk_toolbar_prepend_item);
656 DEFSUBR(Fgtk_box_query_child_packing);
657 DEFSUBR(Fgtk_button_box_get_child_size_default);
658 DEFSUBR(Fgtk_button_box_get_child_ipadding_default);
659 DEFSUBR(Fgtk_button_box_get_child_size);
660 DEFSUBR(Fgtk_button_box_get_child_ipadding);
661 DEFSUBR(Fgtk_calendar_get_date);
662 DEFSUBR(Fgtk_clist_get_text);
663 DEFSUBR(Fgtk_clist_get_selection);
664 DEFSUBR(Fgtk_clist_get_pixmap);
665 DEFSUBR(Fgtk_clist_get_pixtext);
666 DEFSUBR(Fgtk_color_selection_get_color);
667 DEFSUBR(Fgtk_editable_insert_text);
668 DEFSUBR(Fgtk_pixmap_get);
669 DEFSUBR(Fgtk_curve_get_vector);
670 DEFSUBR(Fgtk_curve_set_vector);
671 DEFSUBR(Fgtk_label_get);
672 DEFSUBR(Fgtk_notebook_query_tab_label_packing);
673 DEFSUBR(Fgtk_widget_get_pointer);
674 DEFSUBR(Fgtk_ctree_recurse);