comparison src/glyphs-gtk.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents ef70ee47d287
children b3ce27ca7647 19a72041c5ed
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
160 /* image instance methods */ 160 /* image instance methods */
161 /************************************************************************/ 161 /************************************************************************/
162 162
163 /************************************************************************/ 163 /************************************************************************/
164 /* convert from a series of RGB triples to an XImage formated for the */ 164 /* convert from a series of RGB triples to an XImage formated for the */
165 /* proper display */ 165 /* proper display */
166 /************************************************************************/ 166 /************************************************************************/
167 static GdkImage * 167 static GdkImage *
168 convert_EImage_to_GDKImage (Lisp_Object device, int width, int height, 168 convert_EImage_to_GDKImage (Lisp_Object device, int width, int height,
169 unsigned char *pic, unsigned long **pixtbl, 169 unsigned char *pic, unsigned long **pixtbl,
170 int *npixels) 170 int *npixels)
213 if (!data) 213 if (!data)
214 { 214 {
215 gdk_image_destroy (outimg); 215 gdk_image_destroy (outimg);
216 return NULL; 216 return NULL;
217 } 217 }
218 218
219 if (vis->type == GDK_VISUAL_PSEUDO_COLOR) 219 if (vis->type == GDK_VISUAL_PSEUDO_COLOR)
220 { 220 {
221 unsigned long pixarray[256]; 221 unsigned long pixarray[256];
222 int pixcount, n; 222 int pixcount, n;
223 /* use our quantize table to allocate the colors */ 223 /* use our quantize table to allocate the colors */
229 n = *npixels; 229 n = *npixels;
230 for (i = 0; i < qtable->num_active_colors; i++) 230 for (i = 0; i < qtable->num_active_colors; i++)
231 { 231 {
232 GdkColor color; 232 GdkColor color;
233 int res; 233 int res;
234 234
235 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0; 235 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0;
236 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0; 236 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0;
237 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0; 237 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0;
238 res = allocate_nearest_color (cmap, vis, &color); 238 res = allocate_nearest_color (cmap, vis, &color);
239 if (res > 0 && res < 3) 239 if (res > 0 && res < 3)
341 else 341 else
342 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q]; 342 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
343 #endif 343 #endif
344 } 344 }
345 } 345 }
346 } 346 }
347 return outimg; 347 return outimg;
348 } 348 }
349 349
350 static void 350 static void
351 gtk_print_image_instance (struct Lisp_Image_Instance *p, 351 gtk_print_image_instance (struct Lisp_Image_Instance *p,
684 Lisp_Object instantiator, 684 Lisp_Object instantiator,
685 Lisp_Object pointer_fg, 685 Lisp_Object pointer_fg,
686 Lisp_Object pointer_bg) 686 Lisp_Object pointer_bg)
687 { 687 {
688 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 688 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
689 GdkPixmap *pixmap = IMAGE_INSTANCE_X_PIXMAP (ii); 689 GdkPixmap *pixmap = IMAGE_INSTANCE_GTK_PIXMAP (ii);
690 GdkPixmap *mask = (GdkPixmap *) IMAGE_INSTANCE_PIXMAP_MASK (ii); 690 GdkPixmap *mask = (GdkPixmap *) IMAGE_INSTANCE_GTK_MASK (ii);
691 GdkColor fg, bg; 691 GdkColor fg, bg;
692 int xhot = 0, yhot = 0; 692 int xhot = 0, yhot = 0;
693 int w, h; 693 int w, h;
694 694
695 if (INTP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii))) 695 if (INTP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
794 794
795 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = 795 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
796 find_keyword_in_vector (instantiator, Q_file); 796 find_keyword_in_vector (instantiator, Q_file);
797 797
798 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap; 798 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap;
799 IMAGE_INSTANCE_GTK_MASK (ii) = 0; 799 IMAGE_INSTANCE_PIXMAP_MASK (ii) = 0;
800 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = gdk_image->width; 800 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = gdk_image->width;
801 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = gdk_image->height; 801 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = gdk_image->height;
802 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = gdk_image->depth; 802 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = gdk_image->depth;
803 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap; 803 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap;
804 IMAGE_INSTANCE_GTK_PIXELS (ii) = pixels; 804 IMAGE_INSTANCE_GTK_PIXELS (ii) = pixels;
835 835
836 gdk_window_get_geometry (gdk_pixmap, NULL, NULL, &width, &height, &depth); 836 gdk_window_get_geometry (gdk_pixmap, NULL, NULL, &width, &height, &depth);
837 837
838 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil; 838 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
839 IMAGE_INSTANCE_GTK_PIXMAP (ii) = gdk_pixmap; 839 IMAGE_INSTANCE_GTK_PIXMAP (ii) = gdk_pixmap;
840 IMAGE_INSTANCE_GTK_MASK (ii) = 0; 840 IMAGE_INSTANCE_PIXMAP_MASK (ii) = 0;
841 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width; 841 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
842 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height; 842 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
843 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth; 843 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
844 IMAGE_INSTANCE_GTK_COLORMAP (ii) = gdk_window_get_colormap (gdk_pixmap); 844 IMAGE_INSTANCE_GTK_COLORMAP (ii) = gdk_window_get_colormap (gdk_pixmap);
845 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0; 845 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0;
883 883
884 static void 884 static void
885 gtk_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii, 885 gtk_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
886 int width, int height, 886 int width, int height,
887 int slices, 887 int slices,
888 unsigned char *eimage, 888 unsigned char *eimage,
889 int dest_mask, 889 int dest_mask,
890 Lisp_Object instantiator, 890 Lisp_Object instantiator,
891 Lisp_Object pointer_fg, 891 Lisp_Object pointer_fg,
892 Lisp_Object pointer_bg, 892 Lisp_Object pointer_bg,
893 Lisp_Object UNUSED (domain)) 893 Lisp_Object UNUSED (domain))
1166 if (STRINGP (value)) 1166 if (STRINGP (value))
1167 value = 1167 value =
1168 Fmake_color_instance 1168 Fmake_color_instance
1169 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN)); 1169 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN));
1170 else 1170 else
1171 { 1171 {
1172 assert (COLOR_SPECIFIERP (value)); 1172 assert (COLOR_SPECIFIERP (value));
1173 value = Fspecifier_instance (value, domain, Qnil, Qnil); 1173 value = Fspecifier_instance (value, domain, Qnil, Qnil);
1174 } 1174 }
1175 1175
1176 if (NILP (value)) 1176 if (NILP (value))
1177 continue; 1177 continue;
1178 results = noseeum_cons (noseeum_cons (name, value), results); 1178 results = noseeum_cons (noseeum_cons (name, value), results);
1179 i++; 1179 i++;
1180 } 1180 }
1181 UNGCPRO; /* no more evaluation */ 1181 UNGCPRO; /* no more evaluation */
1182 1182
1186 colortbl = xnew_array_and_zero (struct color_symbol, i); 1186 colortbl = xnew_array_and_zero (struct color_symbol, i);
1187 1187
1188 for (j=0; j<i; j++) 1188 for (j=0; j<i; j++)
1189 { 1189 {
1190 Lisp_Object cons = XCAR (results); 1190 Lisp_Object cons = XCAR (results);
1191 colortbl[j].color = 1191 colortbl[j].color =
1192 * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons))); 1192 * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
1193 1193
1194 colortbl[j].name = XSTRING_DATA (XCAR (cons)); 1194 colortbl[j].name = XSTRING_DATA (XCAR (cons));
1195 free_cons (cons); 1195 free_cons (cons);
1196 cons = results; 1196 cons = results;
1308 signal_image_error ("Error reading pixmap", data); 1308 signal_image_error ("Error reading pixmap", data);
1309 1309
1310 gdk_window_get_geometry (pixmap, NULL, NULL, &w, &h, &depth); 1310 gdk_window_get_geometry (pixmap, NULL, NULL, &w, &h, &depth);
1311 1311
1312 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap; 1312 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap;
1313 IMAGE_INSTANCE_PIXMAP_MASK (ii) = (void*)mask; 1313 IMAGE_INSTANCE_PIXMAP_MASK (ii) = mask;
1314 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap; 1314 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap;
1315 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0; 1315 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0;
1316 IMAGE_INSTANCE_GTK_NPIXELS (ii) = 0; 1316 IMAGE_INSTANCE_GTK_NPIXELS (ii) = 0;
1317 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w; 1317 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
1318 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h; 1318 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
1327 case IMAGE_COLOR_PIXMAP: 1327 case IMAGE_COLOR_PIXMAP:
1328 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth; 1328 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
1329 break; 1329 break;
1330 1330
1331 case IMAGE_POINTER: 1331 case IMAGE_POINTER:
1332 if (xpmattrs.valuemask & XpmHotspot) 1332 /* #### Gtk does not give us access to the hotspots of a pixmap */
1333 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xpmattrs.x_hotspot); 1333
1334 if (xpmattrs.valuemask & XpmHotspot) 1334 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int(1);
1335 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (xpmattrs.y_hotspot); 1335 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int(1);
1336 1336
1337
1337 image_instance_convert_to_pointer (ii, instantiator, pointer_fg, 1338 image_instance_convert_to_pointer (ii, instantiator, pointer_fg,
1338 pointer_bg); 1339 pointer_bg);
1339 break; 1340 break;
1340 1341
1341 default: 1342 default:
1438 **********************************************************************/ 1439 **********************************************************************/
1439 1440
1440 static void 1441 static void
1441 gtk_resource_validate (Lisp_Object instantiator) 1442 gtk_resource_validate (Lisp_Object instantiator)
1442 { 1443 {
1443 if ((NILP (find_keyword_in_vector (instantiator, Q_file)) 1444 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
1444 && 1445 &&
1445 NILP (find_keyword_in_vector (instantiator, Q_resource_id))) 1446 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
1446 || 1447 ||
1447 NILP (find_keyword_in_vector (instantiator, Q_resource_type))) 1448 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
1448 sferror ("Must supply :file, :resource-id and :resource-type", 1449 sferror ("Must supply :file, :resource-id and :resource-type",
1449 instantiator); 1450 instantiator);
1450 } 1451 }
1510 #if 0 1511 #if 0
1511 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK) 1512 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK)
1512 iitype = IMAGE_POINTER; 1513 iitype = IMAGE_POINTER;
1513 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) 1514 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1514 iitype = IMAGE_COLOR_PIXMAP; 1515 iitype = IMAGE_COLOR_PIXMAP;
1515 else 1516 else
1516 incompatible_image_types (instantiator, dest_mask, 1517 incompatible_image_types (instantiator, dest_mask,
1517 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK); 1518 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1518 #endif 1519 #endif
1519 1520
1520 /* mess with the keyword info we were provided with */ 1521 /* mess with the keyword info we were provided with */
1521 gtk_initialize_pixmap_image_instance (ii, 1, type); 1522 gtk_initialize_pixmap_image_instance (ii, 1, type);
1522 c = gdk_cursor_new ((GdkCursorType) resource_name_to_resource (resource_id, type)); 1523 c = gdk_cursor_new ((GdkCursorType) resource_name_to_resource (resource_id, type));
1523 IMAGE_INSTANCE_GTK_CURSOR (ii) = c; 1524 IMAGE_INSTANCE_GTK_CURSOR (ii) = c;
1524 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id; 1525 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id;
1611 alist); 1612 alist);
1612 if (yhot != -1) 1613 if (yhot != -1)
1613 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)), 1614 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
1614 alist); 1615 alist);
1615 1616
1616 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type); 1617 alist = xbm_mask_file_munging (alist, filename, Qt, console_type);
1617 1618
1618 { 1619 {
1619 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist); 1620 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
1620 free_alist (alist); 1621 free_alist (alist);
1621 RETURN_UNGCPRO (result); 1622 RETURN_UNGCPRO (result);
1686 TO_EXTERNAL_FORMAT (LISP_STRING, data, 1687 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1687 C_STRING_ALLOCA, name_ext, 1688 C_STRING_ALLOCA, name_ext,
1688 Qfile_name); 1689 Qfile_name);
1689 1690
1690 if (cursor_name_to_index (name_ext) != -1) 1691 if (cursor_name_to_index (name_ext) != -1)
1691 { 1692 {
1692 result = alist_to_tagged_vector (Qcursor_font, alist); 1693 result = alist_to_tagged_vector (Qcursor_font, alist);
1693 is_cursor_font = 1; 1694 is_cursor_font = 1;
1694 } 1695 }
1695 } 1696 }
1696 1697
1697 if (!is_cursor_font) 1698 if (!is_cursor_font)
1698 result = alist_to_tagged_vector (Qstring, alist); 1699 result = alist_to_tagged_vector (Qstring, alist);
1699 free_alist (alist); 1700 free_alist (alist);
1848 1849
1849 if (!the_gdk_cursors[GDK_BASED_ARROW_UP]) 1850 if (!the_gdk_cursors[GDK_BASED_ARROW_UP])
1850 { 1851 {
1851 /* Need to initialize the array */ 1852 /* Need to initialize the array */
1852 /* Supposedly since this array is static it should be 1853 /* Supposedly since this array is static it should be
1853 initialized to NULLs for us, but I'm very paranoid. */ 1854 initialized to NULLs for us, but I'm very paranoid. */
1854 for (i = 0; i < GDK_NUM_GLYPHS; i++) 1855 for (i = 0; i < GDK_NUM_GLYPHS; i++)
1855 { 1856 {
1856 the_gdk_cursors[i] = NULL; 1857 the_gdk_cursors[i] = NULL;
1857 } 1858 }
1858 1859
2207 GtkStyle *style = gtk_widget_get_style (w); 2208 GtkStyle *style = gtk_widget_get_style (w);
2208 Lisp_Object pixel = Qnil; 2209 Lisp_Object pixel = Qnil;
2209 GdkColor *fcolor, *bcolor; 2210 GdkColor *fcolor, *bcolor;
2210 2211
2211 style = gtk_style_copy (style); 2212 style = gtk_style_copy (style);
2212 2213
2213 /* Update the foreground. */ 2214 /* Update the foreground. */
2214 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain); 2215 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
2215 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel)); 2216 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
2216 2217
2217 /* Update the background. */ 2218 /* Update the background. */
2589 /* It is possible for a widget action to cause it to get out of 2590 /* It is possible for a widget action to cause it to get out of
2590 sync with its instantiator. Thus it is necessary to signal 2591 sync with its instantiator. Thus it is necessary to signal
2591 this possibility. */ 2592 this possibility. */
2592 if (IMAGE_INSTANCEP (image_instance)) 2593 if (IMAGE_INSTANCEP (image_instance))
2593 XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1; 2594 XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1;
2594 2595
2595 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex)) 2596 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex))
2596 { 2597 {
2597 event = Fmake_event (Qnil, Qnil); 2598 event = Fmake_event (Qnil, Qnil);
2598 2599
2599 XSET_EVENT_TYPE (event, misc_user_event); 2600 XSET_EVENT_TYPE (event, misc_user_event);
2969 { 2970 {
2970 case IMAGE_MONO_PIXMAP: 2971 case IMAGE_MONO_PIXMAP:
2971 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP; 2972 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
2972 /* Make sure there aren't two pointers to the same mask, causing 2973 /* Make sure there aren't two pointers to the same mask, causing
2973 it to get freed twice. */ 2974 it to get freed twice. */
2974 IMAGE_INSTANCE_GTK_MASK (p) = 0; 2975 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
2975 break; 2976 break;
2976 2977
2977 default: 2978 default:
2978 return 0; 2979 return 0;
2979 } 2980 }
3006 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground; 3007 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
3007 IMAGE_INSTANCE_PIXMAP_BG (p) = background; 3008 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
3008 return 1; 3009 return 1;
3009 } 3010 }
3010 } 3011 }
3011