Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 7766:9d6ba1c44cb7
[gaim-migrate @ 8411]
This is cool. WYSIWYGing your default formatting.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 05 Dec 2003 17:09:18 +0000 |
parents | f75991b27e94 |
children | 3db18c16f573 |
comparison
equal
deleted
inserted
replaced
7765:9b3c8ef31105 | 7766:9d6ba1c44cb7 |
---|---|
370 GString *str = g_string_new(NULL); | 370 GString *str = g_string_new(NULL); |
371 | 371 |
372 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | 372 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ |
373 str = g_string_append_unichar(str, 0xfeff); | 373 str = g_string_append_unichar(str, 0xfeff); |
374 str = g_string_append(str, text); | 374 str = g_string_append(str, text); |
375 str = g_string_append_unichar(str, 0x0000); | |
375 char *selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); | 376 char *selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
376 gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); | 377 gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); |
377 g_string_free(str, TRUE); | 378 g_string_free(str, TRUE); |
378 g_free(text); | 379 g_free(text); |
379 g_free(selection); | 380 g_free(selection); |
404 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | 405 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), |
405 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | 406 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, |
406 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | 407 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); |
407 | 408 |
408 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); | 409 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
410 } | |
411 | |
412 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, GtkIMHtml *imhtml) | |
413 { | |
414 char *text; | |
415 guint16 c; | |
416 if (selection_data->length < 0) { | |
417 text = gtk_clipboard_wait_for_text(clipboard); | |
418 printf("%s\n", text); | |
419 } else { | |
420 text = g_malloc((selection_data->format / 8) * selection_data->length); | |
421 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); | |
422 printf("%s\n", text); | |
423 } | |
424 | |
425 memcpy (&c, text, 2); | |
426 if (c == 0xfeff) { | |
427 /* This is UCS2 */ | |
428 char *utf8 = g_convert(text, selection_data->length * (selection_data->format / 8), "UTF-8", "UCS-2", NULL, NULL, NULL); | |
429 g_free(text); | |
430 text = utf8; | |
431 } | |
432 gtk_imhtml_append_text_with_images(imhtml, text, 0, NULL); | |
433 } | |
434 | |
435 | |
436 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
437 { | |
438 | |
439 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
440 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
441 paste_received_cb, imhtml); | |
442 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); | |
409 } | 443 } |
410 | 444 |
411 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) | 445 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) |
412 { | 446 { |
413 GtkClipboard *clipboard; | 447 GtkClipboard *clipboard; |
517 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); | 551 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
518 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); | 552 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
519 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); | 553 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
520 #if GTK_CHECK_VERSION(2,2,0) | 554 #if GTK_CHECK_VERSION(2,2,0) |
521 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); | 555 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
556 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); | |
522 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); | 557 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
523 #endif | 558 #endif |
524 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); | 559 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
525 | 560 |
526 imhtml->tip = NULL; | 561 imhtml->tip = NULL; |