comparison src/glyphs-gtk.c @ 739:2e5e2ccbeed2

[xemacs-hg @ 2002-02-02 13:42:53 by wmperry] Fix XPM transparency in GTK, mostly.
author wmperry
date Sat, 02 Feb 2002 13:42:54 +0000
parents 02339d4ebed4
children 943eaba38521
comparison
equal deleted inserted replaced
738:5039859429c5 739:2e5e2ccbeed2
1081 1081
1082 #ifdef HAVE_XPM 1082 #ifdef HAVE_XPM
1083 /********************************************************************** 1083 /**********************************************************************
1084 * XPM * 1084 * XPM *
1085 **********************************************************************/ 1085 **********************************************************************/
1086
1087 static void 1086 static void
1088 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out) 1087 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out)
1089 { 1088 {
1090 Lisp_Object instream, outstream; 1089 Lisp_Object instream, outstream;
1091 Lstream *istr, *ostr; 1090 Lstream *istr, *ostr;
1181 1180
1182 if (fubar) 1181 if (fubar)
1183 report_file_error ("Writing temp file", build_string (filename_out)); 1182 report_file_error ("Writing temp file", build_string (filename_out));
1184 } 1183 }
1185 1184
1186 static void 1185 struct color_symbol
1187 gtk_xpm_instantiate (Lisp_Object image_instance, 1186 {
1188 Lisp_Object instantiator, 1187 char* name;
1188 GdkColor color;
1189 };
1190
1191 static struct color_symbol*
1192 extract_xpm_color_names (Lisp_Object device,
1193 Lisp_Object domain,
1194 Lisp_Object color_symbol_alist,
1195 int* nsymbols)
1196 {
1197 /* This function can GC */
1198 Lisp_Object rest;
1199 Lisp_Object results = Qnil;
1200 int i, j;
1201 struct color_symbol *colortbl;
1202 struct gcpro gcpro1, gcpro2;
1203
1204 GCPRO2 (results, device);
1205
1206 /* We built up results to be (("name" . #<color>) ...) so that if an
1207 error happens we don't lose any malloc()ed data, or more importantly,
1208 leave any pixels allocated in the server. */
1209 i = 0;
1210 LIST_LOOP (rest, color_symbol_alist)
1211 {
1212 Lisp_Object cons = XCAR (rest);
1213 Lisp_Object name = XCAR (cons);
1214 Lisp_Object value = XCDR (cons);
1215 if (NILP (value))
1216 continue;
1217 if (STRINGP (value))
1218 value =
1219 Fmake_color_instance
1220 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
1221 else
1222 {
1223 assert (COLOR_SPECIFIERP (value));
1224 value = Fspecifier_instance (value, domain, Qnil, Qnil);
1225 }
1226
1227 if (NILP (value))
1228 continue;
1229 results = noseeum_cons (noseeum_cons (name, value), results);
1230 i++;
1231 }
1232 UNGCPRO; /* no more evaluation */
1233
1234 *nsymbols=i;
1235 if (i == 0) return 0;
1236
1237 colortbl = xnew_array_and_zero (struct color_symbol, i);
1238
1239 for (j=0; j<i; j++)
1240 {
1241 Lisp_Object cons = XCAR (results);
1242 colortbl[j].color =
1243 * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
1244
1245 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
1246 free_cons (XCONS (cons));
1247 cons = results;
1248 results = XCDR (results);
1249 free_cons (XCONS (cons));
1250 }
1251 return colortbl;
1252 }
1253
1254 static void
1255 gtk_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1189 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1256 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1190 int dest_mask, Lisp_Object domain) 1257 int dest_mask, Lisp_Object domain)
1191 { 1258 {
1192 /* This function can GC */ 1259 /* This function can GC */
1193 char temp_file_name[1024]; 1260 char temp_file_name[1024];
1198 int depth; 1265 int depth;
1199 GdkVisual *visual; 1266 GdkVisual *visual;
1200 GdkPixmap *pixmap; 1267 GdkPixmap *pixmap;
1201 GdkPixmap *mask = 0; 1268 GdkPixmap *mask = 0;
1202 GdkWindow *window = 0; 1269 GdkWindow *window = 0;
1203 int i = 0; 1270 int nsymbols = 0, i = 0;
1271 struct color_symbol *color_symbols = NULL;
1272 GdkColor *transparent_color = NULL;
1204 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator, 1273 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
1205 Q_color_symbols); 1274 Q_color_symbols);
1206 enum image_instance_type type; 1275 enum image_instance_type type;
1207 int force_mono; 1276 int force_mono;
1208 unsigned int w, h; 1277 unsigned int w, h;
1229 1298
1230 gtk_initialize_pixmap_image_instance (ii, 1, type); 1299 gtk_initialize_pixmap_image_instance (ii, 1, type);
1231 1300
1232 assert (!NILP (data)); 1301 assert (!NILP (data));
1233 1302
1303 /* Need to get the transparent color here */
1304 color_symbols = extract_xpm_color_names (device, domain, color_symbol_alist, &nsymbols);
1305 for (i = 0; i < nsymbols; i++)
1306 {
1307 if (!strcasecmp ("BgColor", color_symbols[i].name) ||
1308 !strcasecmp ("None", color_symbols[i].name))
1309 {
1310 transparent_color = &color_symbols[i].color;
1311 }
1312 }
1313
1234 write_lisp_string_to_temp_file (data, temp_file_name); 1314 write_lisp_string_to_temp_file (data, temp_file_name);
1235 pixmap = gdk_pixmap_create_from_xpm (window, &mask, NULL, temp_file_name); 1315 pixmap = gdk_pixmap_create_from_xpm (window, &mask, transparent_color, temp_file_name);
1236 unlink (temp_file_name); 1316 unlink (temp_file_name);
1317
1318 if (color_symbols) xfree (color_symbols);
1237 1319
1238 if (!pixmap) 1320 if (!pixmap)
1239 { 1321 {
1240 signal_image_error ("Error reading pixmap", data); 1322 signal_image_error ("Error reading pixmap", data);
1241 } 1323 }
1299 1381
1300 default: 1382 default:
1301 abort (); 1383 abort ();
1302 } 1384 }
1303 } 1385 }
1304
1305 #endif /* HAVE_XPM */ 1386 #endif /* HAVE_XPM */
1306 1387
1307 1388
1308 #ifdef HAVE_XFACE 1389 #ifdef HAVE_XFACE
1309 1390