Mercurial > pidgin
comparison src/gtkimhtml.c @ 8091:56b74730715f
[gaim-migrate @ 8790]
A drag-and-drop URL patch. It seems to get the drop signal twice, but I'm
going to commit this now and fix it later so that Dan can claim the bounty
and hopefully have it accepted.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 13 Jan 2004 03:02:59 +0000 |
parents | ea073d234191 |
children | 42c7227d6e4d |
comparison
equal
deleted
inserted
replaced
8090:fb0eab758560 | 8091:56b74730715f |
---|---|
22 */ | 22 */ |
23 | 23 |
24 #ifdef HAVE_CONFIG_H | 24 #ifdef HAVE_CONFIG_H |
25 #include <config.h> | 25 #include <config.h> |
26 #endif | 26 #endif |
27 #include "util.h" | |
27 #include "gtkimhtml.h" | 28 #include "gtkimhtml.h" |
28 #include "gtksourceiter.h" | 29 #include "gtksourceiter.h" |
29 #include <gtk/gtk.h> | 30 #include <gtk/gtk.h> |
30 #include <glib/gerror.h> | 31 #include <glib/gerror.h> |
31 #include <gdk/gdkkeysyms.h> | 32 #include <gdk/gdkkeysyms.h> |
61 | 62 |
62 #define TOOLTIP_TIMEOUT 500 | 63 #define TOOLTIP_TIMEOUT 500 |
63 | 64 |
64 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); | 65 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
65 void gtk_imhtml_close_tags(GtkIMHtml *imhtml); | 66 void gtk_imhtml_close_tags(GtkIMHtml *imhtml); |
67 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); | |
66 | 68 |
67 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a | 69 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
68 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | 70 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ |
69 #define MAX_FONT_SIZE 7 | 71 #define MAX_FONT_SIZE 7 |
70 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) | 72 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
76 TARGET_COMPOUND_TEXT, | 78 TARGET_COMPOUND_TEXT, |
77 TARGET_STRING, | 79 TARGET_STRING, |
78 TARGET_TEXT | 80 TARGET_TEXT |
79 }; | 81 }; |
80 | 82 |
83 enum { | |
84 DRAG_URL | |
85 }; | |
86 | |
81 GtkTargetEntry selection_targets[] = { | 87 GtkTargetEntry selection_targets[] = { |
82 { "text/html", 0, TARGET_HTML }, | 88 { "text/html", 0, TARGET_HTML }, |
83 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, | 89 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
84 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | 90 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, |
85 { "STRING", 0, TARGET_STRING }, | 91 { "STRING", 0, TARGET_STRING }, |
86 { "TEXT", 0, TARGET_TEXT}}; | 92 { "TEXT", 0, TARGET_TEXT}}; |
93 | |
94 GtkTargetEntry link_drag_drop_targets[] = { | |
95 {"x-url/ftp", 0, DRAG_URL}, | |
96 {"x-url/http", 0, DRAG_URL}, | |
97 {"text/uri-list", 0, DRAG_URL}, | |
98 {"_NETSCAPE_URL", 0, DRAG_URL}}; | |
87 | 99 |
88 static GtkSmileyTree* | 100 static GtkSmileyTree* |
89 gtk_smiley_tree_new () | 101 gtk_smiley_tree_new () |
90 { | 102 { |
91 return g_new0 (GtkSmileyTree, 1); | 103 return g_new0 (GtkSmileyTree, 1); |
559 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); | 571 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
560 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); | 572 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
561 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); | 573 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
562 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); | 574 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
563 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); | 575 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
576 | |
577 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, | |
578 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
579 GDK_ACTION_COPY); | |
580 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
581 | |
564 #if GTK_CHECK_VERSION(2,2,0) | 582 #if GTK_CHECK_VERSION(2,2,0) |
565 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); | 583 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
566 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); | 584 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
567 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); | 585 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
568 #endif | 586 #endif |
730 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | 748 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
731 return TRUE; /* Clicking the right mouse button on a link shouldn't | 749 return TRUE; /* Clicking the right mouse button on a link shouldn't |
732 be caught by the regular GtkTextView menu */ | 750 be caught by the regular GtkTextView menu */ |
733 else | 751 else |
734 return FALSE; /* Let clicks go through if we didn't catch anything */ | 752 return FALSE; /* Let clicks go through if we didn't catch anything */ |
753 } | |
754 | |
755 static void | |
756 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
757 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) | |
758 { | |
759 if(gtk_imhtml_get_editable(imhtml) && sd->data){ | |
760 gchar **links; | |
761 gchar *link; | |
762 | |
763 gaim_str_strip_cr(sd->data); | |
764 | |
765 links = g_strsplit(sd->data, "\n", 0); | |
766 while((link = *links++) != NULL){ | |
767 if(gaim_str_has_prefix(link, "http://") || | |
768 gaim_str_has_prefix(link, "https://") || | |
769 gaim_str_has_prefix(link, "ftp://")){ | |
770 gtk_imhtml_insert_link(imhtml, link, link); | |
771 } else if (link=='\0') { | |
772 //Ignore blank lines | |
773 } else { | |
774 //Special reasons, aka images being put in via other tag, etc. | |
775 } | |
776 } | |
777 | |
778 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
779 } else { | |
780 gtk_drag_finish(dc, FALSE, FALSE, t); | |
781 } | |
735 } | 782 } |
736 | 783 |
737 /* this isn't used yet | 784 /* this isn't used yet |
738 static void | 785 static void |
739 gtk_smiley_tree_remove (GtkSmileyTree *tree, | 786 gtk_smiley_tree_remove (GtkSmileyTree *tree, |