Mercurial > hg > xemacs-beta
view src/gtk-glue.c @ 5366:f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
2011-03-08 Aidan Kehoe <kehoea@parhasard.net>
* buff-menu.el (list-buffers-noselect):
* byte-optimize.el (byte-optimize-identity):
* byte-optimize.el (byte-optimize-if):
* byte-optimize.el (byte-optimize-nth):
* byte-optimize.el (byte-optimize-nthcdr):
* bytecomp.el (byte-compile-warn-wrong-args):
* bytecomp.el (byte-compile-two-args-19->20):
* bytecomp.el (byte-compile-list):
* bytecomp.el (byte-compile-beginning-of-line):
* bytecomp.el (byte-compile-set):
* bytecomp.el (byte-compile-set-default):
* bytecomp.el (byte-compile-values):
* bytecomp.el (byte-compile-values-list):
* bytecomp.el (byte-compile-integerp):
* bytecomp.el (byte-compile-multiple-value-list-internal):
* bytecomp.el (byte-compile-throw):
* cl-macs.el (cl-do-arglist):
* cl-macs.el (cl-parse-loop-clause):
* cl-macs.el (multiple-value-bind):
* cl-macs.el (multiple-value-setq):
* cl-macs.el (get-setf-method):
* cmdloop.el (command-error):
* cmdloop.el (y-or-n-p-minibuf):
* cmdloop.el (yes-or-no-p-minibuf):
* coding.el (unencodable-char-position):
* cus-edit.el (custom-face-prompt):
* cus-edit.el (custom-buffer-create-internal):
* cus-edit.el (widget-face-action):
* cus-edit.el (custom-group-value-create):
* descr-text.el (describe-char-unicode-data):
* dialog-gtk.el (popup-builtin-question-dialog):
* dragdrop.el (experimental-dragdrop-drop-log-function):
* dragdrop.el (experimental-dragdrop-drop-mime-default):
* easymenu.el (easy-menu-add):
* easymenu.el (easy-menu-remove):
* faces.el (read-face-name):
* faces.el (set-face-stipple):
* files.el (file-name-non-special):
* font.el (font-combine-fonts):
* font.el (font-set-face-font):
* font.el (font-parse-rgb-components):
* font.el (font-rgb-color-p):
* font.el (font-color-rgb-components):
* gnuserv.el (gnuserv-edit-files):
* help.el (key-or-menu-binding):
* help.el (function-documentation-1):
* help.el (function-documentation):
* info.el (info):
* isearch-mode.el (isearch-exit):
* isearch-mode.el (isearch-edit-string):
* isearch-mode.el (isearch-*-char):
* isearch-mode.el (isearch-complete1):
* ldap.el (ldap-encode-country-string):
* ldap.el (ldap-decode-string):
* minibuf.el (read-file-name-internal-1):
* minibuf.el (read-non-nil-coding-system):
* minibuf.el (get-user-response):
* mouse.el (drag-window-divider):
* mule/ccl.el:
* mule/ccl.el (ccl-compile-if):
* mule/ccl.el (ccl-compile-break):
* mule/ccl.el (ccl-compile-repeat):
* mule/ccl.el (ccl-compile-write-repeat):
* mule/ccl.el (ccl-compile-call):
* mule/ccl.el (ccl-compile-end):
* mule/ccl.el (ccl-compile-read-multibyte-character):
* mule/ccl.el (ccl-compile-write-multibyte-character):
* mule/ccl.el (ccl-compile-translate-character):
* mule/ccl.el (ccl-compile-mule-to-unicode):
* mule/ccl.el (ccl-compile-unicode-to-mule):
* mule/ccl.el (ccl-compile-lookup-integer):
* mule/ccl.el (ccl-compile-lookup-character):
* mule/ccl.el (ccl-compile-map-multiple):
* mule/ccl.el (ccl-compile-map-single):
* mule/devan-util.el (devanagari-compose-to-one-glyph):
* mule/devan-util.el (devanagari-composition-component):
* mule/mule-cmds.el (finish-set-language-environment):
* mule/viet-util.el:
* mule/viet-util.el (viet-encode-viscii-char):
* multicast.el (open-multicast-group):
* newcomment.el (comment-quote-nested):
* newcomment.el (comment-region):
* newcomment.el (comment-dwim):
* regexp-opt.el (regexp-opt-group):
* replace.el (map-query-replace-regexp):
* specifier.el (derive-device-type-from-tag-set):
* subr.el (skip-chars-quote):
* test-harness.el (test-harness-from-buffer):
* test-harness.el (batch-test-emacs):
* wid-edit.el (widget-choice-action):
* wid-edit.el (widget-symbol-prompt-internal):
* wid-edit.el (widget-color-action):
* window-xemacs.el (push-window-configuration):
* window-xemacs.el (pop-window-configuration):
* window.el (quit-window):
* x-compose.el (electric-diacritic):
It's better style, and cheaper (often one assembler instruction
vs. a C funcall in the byte code), to use `eql' instead of `='
when it's clear what numerical type a given result will be. Change
much of our code to do this, with the help of a byte-compiler
change (not comitted) that looked for calls to #'length (which
always returns an integer) in its args.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 08 Mar 2011 23:41:52 +0000 |
parents | cd167465bf69 |
children | b9167d522a9a |
line wrap: on
line source
/* gtk-glue.c --- GTK interfaces with XEmacs Copyright (C) 2000, 2001 William M. Perry This file is part of XEmacs. XEmacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. XEmacs 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 General Public License for more details. You should have received a copy of the GNU General Public License along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ GtkType GTK_TYPE_ARRAY = 0; GtkType GTK_TYPE_STRING_ARRAY = 0; GtkType GTK_TYPE_FLOAT_ARRAY = 0; GtkType GTK_TYPE_INT_ARRAY = 0; GtkType GTK_TYPE_LISTOF = 0; GtkType GTK_TYPE_STRING_LIST = 0; GtkType GTK_TYPE_OBJECT_LIST = 0; GtkType GTK_TYPE_GDK_GC = 0; #include "console-gtk.h" #include "fontcolor-gtk-impl.h" static GtkType xemacs_type_register (gchar *name, GtkType parent) { GtkType type_id; GtkTypeInfo info; info.type_name = name; info.object_size = 0; info.class_size = 0; info.class_init_func = NULL; info.object_init_func = NULL; info.reserved_1 = NULL; info.reserved_2 = NULL; type_id = gtk_type_unique (parent, &info); return (type_id); } static void xemacs_init_gtk_classes (void) { if (!GTK_TYPE_ARRAY) { GTK_TYPE_ARRAY = xemacs_type_register ("GtkArrayOf", 0); GTK_TYPE_STRING_ARRAY = xemacs_type_register ("GtkArrayOfString", GTK_TYPE_ARRAY); GTK_TYPE_FLOAT_ARRAY = xemacs_type_register ("GtkArrayOfFloat", GTK_TYPE_ARRAY); GTK_TYPE_INT_ARRAY = xemacs_type_register ("GtkArrayOfInteger", GTK_TYPE_ARRAY); GTK_TYPE_LISTOF = xemacs_type_register ("GtkListOf", 0); GTK_TYPE_STRING_LIST = xemacs_type_register ("GtkListOfString", GTK_TYPE_LISTOF); GTK_TYPE_OBJECT_LIST = xemacs_type_register ("GtkListOfObject", GTK_TYPE_LISTOF); GTK_TYPE_GDK_GC = xemacs_type_register ("GdkGC", GTK_TYPE_BOXED); } } static void xemacs_list_to_gtklist (Lisp_Object obj, GtkArg *arg) { CHECK_LIST (obj); if (arg->type == GTK_TYPE_STRING_LIST) { Lisp_Object temp = obj; GList *strings = NULL; while (!NILP (temp)) { CHECK_STRING (XCAR (temp)); temp = XCDR (temp); } temp = obj; while (!NILP (temp)) { strings = g_list_append (strings, XSTRING_DATA (XCAR (temp))); temp = XCDR (temp); } GTK_VALUE_POINTER (*arg) = strings; } else if (arg->type == GTK_TYPE_OBJECT_LIST) { Lisp_Object temp = obj; GList *objects = NULL; while (!NILP (temp)) { CHECK_GTK_OBJECT (XCAR (temp)); temp = XCDR (temp); } temp = obj; while (!NILP (temp)) { objects = g_list_append (objects, XGTK_OBJECT (XCAR (temp))->object); temp = XCDR (temp); } GTK_VALUE_POINTER (*arg) = objects; } else { ABORT (); } } static void __make_gtk_object_mapper (gpointer data, gpointer user_data) { Lisp_Object *rv = (Lisp_Object *) user_data; *rv = Fcons (build_gtk_object (GTK_OBJECT (data)), *rv); } static void __make_string_mapper (gpointer data, gpointer user_data) { Lisp_Object *rv = (Lisp_Object *) user_data; *rv = Fcons (build_cistring ((char *)data), *rv); } static Lisp_Object xemacs_gtklist_to_list (GtkArg *arg) { Lisp_Object rval = Qnil; if (GTK_VALUE_POINTER (*arg)) { if (arg->type == GTK_TYPE_STRING_LIST) { g_list_foreach ((GList*) GTK_VALUE_POINTER (*arg), __make_string_mapper, &rval); } else if (arg->type == GTK_TYPE_OBJECT_LIST) { g_list_foreach ((GList*) GTK_VALUE_POINTER (*arg), __make_gtk_object_mapper, &rval); } else { ABORT (); } } return (rval); } static void xemacs_list_to_array (Lisp_Object obj, GtkArg *arg) { CHECK_LIST (obj); #define FROB(ret_type,check_fn,extract_fn) \ do { \ Lisp_Object temp = obj; \ int length = 0; \ ret_type *array = NULL; \ \ while (!NILP (temp)) \ { \ check_fn (XCAR (temp)); \ length++; \ temp = XCDR (temp); \ } \ \ array = xnew_array_and_zero (ret_type, length + 2); \ temp = obj; \ length = 0; \ \ while (!NILP (temp)) \ { \ array[length++] = extract_fn (XCAR (temp)); \ temp = XCDR (temp); \ } \ \ GTK_VALUE_POINTER (*arg) = array; \ } while (0); if (arg->type == GTK_TYPE_STRING_ARRAY) { FROB (gchar *, CHECK_STRING, (gchar*) XSTRING_DATA); } else if (arg->type == GTK_TYPE_FLOAT_ARRAY) { FROB (gfloat, CHECK_FLOAT, extract_float); } else if (arg->type == GTK_TYPE_INT_ARRAY) { FROB (gint, CHECK_INT, XINT); } else { ABORT (); } #undef FROB } static GdkGC * face_to_gc (Lisp_Object face) { Lisp_Object frame = Fselected_frame (Qnil); return (gtk_get_gc (XFRAME (frame), Fspecifier_instance (Fget (face, Qfont, Qnil), frame, Qnil, Qnil), Fspecifier_instance (Fget (face, Qforeground, Qnil), frame, Qnil, Qnil), Fspecifier_instance (Fget (face, Qbackground, Qnil), frame, Qnil, Qnil), Fspecifier_instance (Fget (face, Qbackground_pixmap, Qnil), frame, Qnil, Qnil), Fspecifier_instance (Fget (face, Qbackground_placement, Qnil), frame, Qnil, Qnil), Qnil)); } static GtkStyle * face_to_style (Lisp_Object face) { Lisp_Object device = Fselected_device (Qnil); GtkStyle *style = gtk_style_new (); int i; Lisp_Object font = Fspecifier_instance (Fget (face, Qfont, Qnil), device, Qnil, Qnil); Lisp_Object fg = Fspecifier_instance (Fget (face, Qforeground, Qnil), device, Qnil, Qnil); Lisp_Object bg = Fspecifier_instance (Fget (face, Qbackground, Qnil), device, Qnil, Qnil); Lisp_Object pm = Fspecifier_instance (Fget (face, Qbackground_pixmap, Qnil), device, Qnil, Qnil); for (i = 0; i < 5; i++) style->fg[i] = *COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (fg)); for (i = 0; i < 5; i++) style->bg[i] = *COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (bg)); if (IMAGE_INSTANCEP (pm)) { for (i = 0; i < 5; i++) style->bg_pixmap[i] = XIMAGE_INSTANCE_GTK_PIXMAP (pm); } style->font = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (font)); return (style); } static Lisp_Object gdk_event_to_emacs_event (GdkEvent *ev) { Lisp_Object event = Qnil; if (ev) { Lisp_Event *emacs_event; event = Fmake_event (Qnil, Qnil); emacs_event = XEVENT (event); if (!gtk_event_to_emacs_event (NULL, ev, emacs_event)) { /* We need to handle a few more cases than the normal event ** loop does. Mainly the double/triple click events. */ if ((ev->type == GDK_2BUTTON_PRESS) || (ev->type == GDK_3BUTTON_PRESS)) { set_event_type (emacs_event, misc_user_event); SET_EVENT_MISC_USER_BUTTON (emacs_event, ev->button.button); SET_EVENT_MISC_USER_MODIFIERS (emacs_event, 0); SET_EVENT_MISC_USER_X (emacs_event, (int) ev->button.x); SET_EVENT_MISC_USER_Y (emacs_event, (int) ev->button.y); if (ev->type == GDK_2BUTTON_PRESS) SET_EVENT_MISC_USER_FUNCTION (emacs_event, intern ("double-click")); else SET_EVENT_MISC_USER_FUNCTION (emacs_event, intern ("triple-click")); } else { Fdeallocate_event (event); event = Qnil; } } } return (event); }