comparison src/glyphs-gtk.c @ 4252:8475ff9c49ea

[xemacs-hg @ 2007-11-05 14:59:20 by didierv] Fix recent image related crashes
author didierv
date Mon, 05 Nov 2007 14:59:24 +0000
parents dbd2a866e38a
children 1bf48c59700e
comparison
equal deleted inserted replaced
4251:b45f331a659d 4252:8475ff9c49ea
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,
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;
1332 /* #### Gtk does not give us access to the hotspots of a pixmap */ 1332 /* #### Gtk does not give us access to the hotspots of a pixmap */
1333 1333
1334 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = 1; 1334 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = 1;
1335 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = 1; 1335 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = 1;
1336 1336
1337 1337
1338 image_instance_convert_to_pointer (ii, instantiator, pointer_fg, 1338 image_instance_convert_to_pointer (ii, instantiator, pointer_fg,
1339 pointer_bg); 1339 pointer_bg);
1340 break; 1340 break;
1341 1341
1342 default: 1342 default:
1439 **********************************************************************/ 1439 **********************************************************************/
1440 1440
1441 static void 1441 static void
1442 gtk_resource_validate (Lisp_Object instantiator) 1442 gtk_resource_validate (Lisp_Object instantiator)
1443 { 1443 {
1444 if ((NILP (find_keyword_in_vector (instantiator, Q_file)) 1444 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
1445 && 1445 &&
1446 NILP (find_keyword_in_vector (instantiator, Q_resource_id))) 1446 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
1447 || 1447 ||
1448 NILP (find_keyword_in_vector (instantiator, Q_resource_type))) 1448 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
1449 sferror ("Must supply :file, :resource-id and :resource-type", 1449 sferror ("Must supply :file, :resource-id and :resource-type",
1450 instantiator); 1450 instantiator);
1451 } 1451 }
1511 #if 0 1511 #if 0
1512 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK) 1512 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK)
1513 iitype = IMAGE_POINTER; 1513 iitype = IMAGE_POINTER;
1514 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) 1514 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1515 iitype = IMAGE_COLOR_PIXMAP; 1515 iitype = IMAGE_COLOR_PIXMAP;
1516 else 1516 else
1517 incompatible_image_types (instantiator, dest_mask, 1517 incompatible_image_types (instantiator, dest_mask,
1518 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK); 1518 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1519 #endif 1519 #endif
1520 1520
1521 /* mess with the keyword info we were provided with */ 1521 /* mess with the keyword info we were provided with */
1522 gtk_initialize_pixmap_image_instance (ii, 1, type); 1522 gtk_initialize_pixmap_image_instance (ii, 1, type);
1523 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));
1524 IMAGE_INSTANCE_GTK_CURSOR (ii) = c; 1524 IMAGE_INSTANCE_GTK_CURSOR (ii) = c;
1525 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id; 1525 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id;
1612 alist); 1612 alist);
1613 if (yhot != -1) 1613 if (yhot != -1)
1614 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)), 1614 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
1615 alist); 1615 alist);
1616 1616
1617 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type); 1617 alist = xbm_mask_file_munging (alist, filename, Qt, console_type);
1618 1618
1619 { 1619 {
1620 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist); 1620 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
1621 free_alist (alist); 1621 free_alist (alist);
1622 RETURN_UNGCPRO (result); 1622 RETURN_UNGCPRO (result);
1687 TO_EXTERNAL_FORMAT (LISP_STRING, data, 1687 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1688 C_STRING_ALLOCA, name_ext, 1688 C_STRING_ALLOCA, name_ext,
1689 Qfile_name); 1689 Qfile_name);
1690 1690
1691 if (cursor_name_to_index (name_ext) != -1) 1691 if (cursor_name_to_index (name_ext) != -1)
1692 { 1692 {
1693 result = alist_to_tagged_vector (Qcursor_font, alist); 1693 result = alist_to_tagged_vector (Qcursor_font, alist);
1694 is_cursor_font = 1; 1694 is_cursor_font = 1;
1695 } 1695 }
1696 } 1696 }
1697 1697
1698 if (!is_cursor_font) 1698 if (!is_cursor_font)
1699 result = alist_to_tagged_vector (Qstring, alist); 1699 result = alist_to_tagged_vector (Qstring, alist);
1700 free_alist (alist); 1700 free_alist (alist);
1849 1849
1850 if (!the_gdk_cursors[GDK_BASED_ARROW_UP]) 1850 if (!the_gdk_cursors[GDK_BASED_ARROW_UP])
1851 { 1851 {
1852 /* Need to initialize the array */ 1852 /* Need to initialize the array */
1853 /* Supposedly since this array is static it should be 1853 /* Supposedly since this array is static it should be
1854 initialized to NULLs for us, but I'm very paranoid. */ 1854 initialized to NULLs for us, but I'm very paranoid. */
1855 for (i = 0; i < GDK_NUM_GLYPHS; i++) 1855 for (i = 0; i < GDK_NUM_GLYPHS; i++)
1856 { 1856 {
1857 the_gdk_cursors[i] = NULL; 1857 the_gdk_cursors[i] = NULL;
1858 } 1858 }
1859 1859
2208 GtkStyle *style = gtk_widget_get_style (w); 2208 GtkStyle *style = gtk_widget_get_style (w);
2209 Lisp_Object pixel = Qnil; 2209 Lisp_Object pixel = Qnil;
2210 GdkColor *fcolor, *bcolor; 2210 GdkColor *fcolor, *bcolor;
2211 2211
2212 style = gtk_style_copy (style); 2212 style = gtk_style_copy (style);
2213 2213
2214 /* Update the foreground. */ 2214 /* Update the foreground. */
2215 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain); 2215 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
2216 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel)); 2216 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
2217 2217
2218 /* Update the background. */ 2218 /* Update the background. */
2590 /* 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
2591 sync with its instantiator. Thus it is necessary to signal 2591 sync with its instantiator. Thus it is necessary to signal
2592 this possibility. */ 2592 this possibility. */
2593 if (IMAGE_INSTANCEP (image_instance)) 2593 if (IMAGE_INSTANCEP (image_instance))
2594 XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1; 2594 XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1;
2595 2595
2596 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex)) 2596 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex))
2597 { 2597 {
2598 event = Fmake_event (Qnil, Qnil); 2598 event = Fmake_event (Qnil, Qnil);
2599 2599
2600 XSET_EVENT_TYPE (event, misc_user_event); 2600 XSET_EVENT_TYPE (event, misc_user_event);
3007 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground; 3007 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
3008 IMAGE_INSTANCE_PIXMAP_BG (p) = background; 3008 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
3009 return 1; 3009 return 1;
3010 } 3010 }
3011 } 3011 }
3012