comparison src/gtkimhtml.c @ 10145:4d484e455839

[gaim-migrate @ 11218] This fixes the crash / hang / strangeness when dragging a buddy to a conversation entry thing. Also fixes a minor memory leak with old plugins. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 26 Oct 2004 01:00:35 +0000
parents 4b276d2e5589
children 5c3b27763126
comparison
equal deleted inserted replaced
10144:757a7c088801 10145:4d484e455839
104 TARGET_STRING, 104 TARGET_STRING,
105 TARGET_TEXT 105 TARGET_TEXT
106 }; 106 };
107 107
108 enum { 108 enum {
109 DRAG_URL,
110 DRAG_HTML,
111 DRAG_UTF8_STRING,
112 DRAG_COMPOUND_TEXT,
113 DRAG_STRING,
114 DRAG_TEXT,
115 };
116
117 enum {
118 URL_CLICKED, 109 URL_CLICKED,
119 BUTTONS_UPDATE, 110 BUTTONS_UPDATE,
120 TOGGLE_FORMAT, 111 TOGGLE_FORMAT,
121 CLEAR_FORMAT, 112 CLEAR_FORMAT,
122 UPDATE_FORMAT, 113 UPDATE_FORMAT,
131 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, 122 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
132 { "STRING", 0, TARGET_STRING }, 123 { "STRING", 0, TARGET_STRING },
133 { "TEXT", 0, TARGET_TEXT}}; 124 { "TEXT", 0, TARGET_TEXT}};
134 125
135 GtkTargetEntry link_drag_drop_targets[] = { 126 GtkTargetEntry link_drag_drop_targets[] = {
136 {"text/html", 0, DRAG_HTML }, 127 GTK_IMHTML_DND_TARGETS
137 {"x-url/ftp", 0, DRAG_URL}, 128 };
138 {"x-url/http", 0, DRAG_URL},
139 {"text/uri-list", 0, DRAG_URL},
140 {"_NETSCAPE_URL", 0, DRAG_URL},
141 { "UTF8_STRING", 0, DRAG_UTF8_STRING },
142 { "COMPOUND_TEXT", 0, DRAG_COMPOUND_TEXT },
143 { "STRING", 0, DRAG_STRING },
144 { "TEXT", 0, DRAG_TEXT}};
145
146 129
147 #ifdef _WIN32 130 #ifdef _WIN32
148 /* Win32 clipboard format value, and functions to convert back and 131 /* Win32 clipboard format value, and functions to convert back and
149 * forth between HTML and the clipboard format. 132 * forth between HTML and the clipboard format.
150 */ 133 */
1296 gint y, 1279 gint y,
1297 guint time) 1280 guint time)
1298 { 1281 {
1299 GdkDragAction suggested_action = 0; 1282 GdkDragAction suggested_action = 0;
1300 1283
1301 if (gtk_drag_dest_find_target (widget, context, 1284 if (gtk_drag_dest_find_target (widget, context, NULL) == GDK_NONE) {
1302 gtk_drag_dest_get_target_list (widget)) == GDK_NONE) {
1303 /* can't accept any of the offered targets */ 1285 /* can't accept any of the offered targets */
1304 } else { 1286 } else {
1305 GtkWidget *source_widget; 1287 GtkWidget *source_widget;
1306 suggested_action = context->suggested_action; 1288 suggested_action = context->suggested_action;
1307 source_widget = gtk_drag_get_source_widget (context); 1289 source_widget = gtk_drag_get_source_widget (context);
1312 if ((context->actions & GDK_ACTION_MOVE) != 0) 1294 if ((context->actions & GDK_ACTION_MOVE) != 0)
1313 suggested_action = GDK_ACTION_MOVE; 1295 suggested_action = GDK_ACTION_MOVE;
1314 } 1296 }
1315 } 1297 }
1316 1298
1317 if (suggested_action != 0) { 1299 gdk_drag_status (context, suggested_action, time);
1318 gdk_drag_status (context, suggested_action, time);
1319 } else {
1320 gdk_drag_status (context, 0, time);
1321 }
1322 1300
1323 /* TRUE return means don't propagate the drag motion to parent 1301 /* TRUE return means don't propagate the drag motion to parent
1324 * widgets that may also be drop sites. 1302 * widgets that may also be drop sites.
1325 */ 1303 */
1326 return TRUE; 1304 return TRUE;
1352 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); 1330 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
1353 1331
1354 1332
1355 if(gtk_imhtml_get_editable(imhtml) && sd->data){ 1333 if(gtk_imhtml_get_editable(imhtml) && sd->data){
1356 switch (info) { 1334 switch (info) {
1357 case DRAG_URL: 1335 case GTK_IMHTML_DRAG_URL:
1358 gaim_str_strip_cr(sd->data); 1336 gaim_str_strip_cr(sd->data);
1359 1337
1360 links = g_strsplit(sd->data, "\n", 0); 1338 links = g_strsplit(sd->data, "\n", 0);
1361 while((link = *links++) != NULL){ 1339 while((link = *links++) != NULL){
1362 if(gaim_str_has_prefix(link, "http://") || 1340 if(gaim_str_has_prefix(link, "http://") ||
1368 } else { 1346 } else {
1369 /* Special reasons, aka images being put in via other tag, etc. */ 1347 /* Special reasons, aka images being put in via other tag, etc. */
1370 } 1348 }
1371 } 1349 }
1372 break; 1350 break;
1373 case DRAG_HTML: 1351 case GTK_IMHTML_DRAG_HTML:
1374 if (sd->length >= 2 && 1352 if (sd->length >= 2 &&
1375 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { 1353 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
1376 /* This is UCS-2 */ 1354 /* This is UCS-2 */
1377 char *tmp; 1355 char *tmp;
1378 char *utf8 = g_convert(text, sd->length, "UTF-8", "UCS-2", NULL, NULL, NULL); 1356 char *utf8 = g_convert(text, sd->length, "UTF-8", "UCS-2", NULL, NULL, NULL);
1391 g_free(text); 1369 g_free(text);
1392 return; 1370 return;
1393 } 1371 }
1394 gtk_imhtml_insert_html_at_iter(imhtml, text, 0, &iter); 1372 gtk_imhtml_insert_html_at_iter(imhtml, text, 0, &iter);
1395 break; 1373 break;
1374 case GTK_IMHTML_DRAG_TEXT:
1375 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
1376 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
1377 g_free(text);
1378 return;
1379 } else {
1380 char *tmp = gaim_escape_html(text);
1381 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter);
1382 g_free(tmp);
1383 }
1384 break;
1396 default: 1385 default:
1397 break; 1386 gtk_drag_finish(dc, FALSE, FALSE, t);
1398 } 1387 return;
1399 1388 }
1400
1401 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); 1389 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
1402 } else { 1390 } else {
1403 gtk_drag_finish(dc, FALSE, FALSE, t); 1391 gtk_drag_finish(dc, FALSE, FALSE, t);
1404 } 1392 }
1405 } 1393 }