| 93 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); |
94 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); |
| 94 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
95 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
| 95 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
96 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
| 96 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); |
97 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); |
| 97 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data); |
98 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data); |
| |
99 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext); |
| 98 |
100 |
| 99 /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */ |
101 /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */ |
| 100 #define MAX_FONT_SIZE 7 |
102 #define MAX_FONT_SIZE 7 |
| 101 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
103 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
| 102 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736}; |
104 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736}; |
| 218 #if 0 /* Debugging for Windows clipboard */ |
220 #if 0 /* Debugging for Windows clipboard */ |
| 219 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret); |
221 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret); |
| 220 #endif |
222 #endif |
| 221 |
223 |
| 222 return ret; |
224 return ret; |
| |
225 } |
| |
226 |
| |
227 static void clipboard_copy_html_win32(GtkIMHtml *imhtml) { |
| |
228 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); |
| |
229 if (clipboard != NULL) { |
| |
230 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
| |
231 if (OpenClipboard(hwnd)) { |
| |
232 if (EmptyClipboard()) { |
| |
233 gint length = strlen(clipboard); |
| |
234 HGLOBAL hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
| |
235 if (hdata != NULL) { |
| |
236 gchar *buffer = GlobalLock(hdata); |
| |
237 memcpy(buffer, clipboard, length); |
| |
238 GlobalUnlock(hdata); |
| |
239 |
| |
240 if (SetClipboardData(win_html_fmt, hdata) == NULL) { |
| |
241 gchar *err_msg = |
| |
242 g_win32_error_message(GetLastError()); |
| |
243 gaim_debug_info("html clipboard", |
| |
244 "Unable to set clipboard data: %s\n", |
| |
245 err_msg ? err_msg : "Unknown Error"); |
| |
246 g_free(err_msg); |
| |
247 } |
| |
248 } |
| |
249 } |
| |
250 CloseClipboard(); |
| |
251 } |
| |
252 g_free(clipboard); |
| |
253 } |
| |
254 } |
| |
255 |
| |
256 static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) { |
| |
257 gboolean pasted = FALSE; |
| |
258 |
| |
259 if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)) |
| |
260 && IsClipboardFormatAvailable(win_html_fmt)) { |
| |
261 gboolean error_reading_clipboard = FALSE; |
| |
262 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
| |
263 |
| |
264 if (OpenClipboard(hwnd)) { |
| |
265 HGLOBAL hdata = GetClipboardData(win_html_fmt); |
| |
266 if (hdata == NULL) { |
| |
267 error_reading_clipboard = TRUE; |
| |
268 } else { |
| |
269 char *buffer = GlobalLock(hdata); |
| |
270 if (buffer == NULL) { |
| |
271 error_reading_clipboard = TRUE; |
| |
272 } else { |
| |
273 char *text = clipboard_win32_to_html( |
| |
274 buffer); |
| |
275 imhtml_paste_insert(imhtml, text, |
| |
276 FALSE); |
| |
277 g_free(text); |
| |
278 pasted = TRUE; |
| |
279 } |
| |
280 GlobalUnlock(hdata); |
| |
281 } |
| |
282 |
| |
283 CloseClipboard(); |
| |
284 |
| |
285 } else { |
| |
286 error_reading_clipboard = TRUE; |
| |
287 } |
| |
288 |
| |
289 if (error_reading_clipboard) { |
| |
290 gchar *err_msg = g_win32_error_message(GetLastError()); |
| |
291 gaim_debug_info("html clipboard", |
| |
292 "Unable to read clipboard data: %s\n", |
| |
293 err_msg ? err_msg : "Unknown Error"); |
| |
294 g_free(err_msg); |
| |
295 } |
| |
296 } |
| |
297 |
| |
298 return pasted; |
| 223 } |
299 } |
| 224 #endif |
300 #endif |
| 225 |
301 |
| 226 static GtkSmileyTree* |
302 static GtkSmileyTree* |
| 227 gtk_smiley_tree_new () |
303 gtk_smiley_tree_new () |
| 789 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); |
865 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); |
| 790 |
866 |
| 791 #ifdef _WIN32 |
867 #ifdef _WIN32 |
| 792 /* We're going to still copy plain text, but let's toss the "HTML Format" |
868 /* We're going to still copy plain text, but let's toss the "HTML Format" |
| 793 we need into the windows clipboard now as well. */ |
869 we need into the windows clipboard now as well. */ |
| 794 HGLOBAL hdata; |
870 clipboard_copy_html_win32(imhtml); |
| 795 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); |
|
| 796 gchar *buffer; |
|
| 797 gint length = strlen(clipboard); |
|
| 798 if(clipboard != NULL) { |
|
| 799 OpenClipboard(NULL); |
|
| 800 hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
|
| 801 buffer = GlobalLock(hdata); |
|
| 802 memcpy(buffer, clipboard, length); |
|
| 803 GlobalUnlock(hdata); |
|
| 804 SetClipboardData(win_html_fmt, hdata); |
|
| 805 CloseClipboard(); |
|
| 806 g_free(clipboard); |
|
| 807 } |
|
| 808 #endif |
871 #endif |
| 809 |
872 |
| 810 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
873 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 811 } |
874 } |
| 812 |
875 |
| 833 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); |
896 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); |
| 834 |
897 |
| 835 #ifdef _WIN32 |
898 #ifdef _WIN32 |
| 836 /* We're going to still copy plain text, but let's toss the "HTML Format" |
899 /* We're going to still copy plain text, but let's toss the "HTML Format" |
| 837 we need into the windows clipboard now as well. */ |
900 we need into the windows clipboard now as well. */ |
| 838 HGLOBAL hdata; |
901 clipboard_copy_html_win32(imhtml); |
| 839 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); |
|
| 840 gchar *buffer; |
|
| 841 gint length = strlen(clipboard); |
|
| 842 if(clipboard != NULL) { |
|
| 843 OpenClipboard(NULL); |
|
| 844 hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
|
| 845 buffer = GlobalLock(hdata); |
|
| 846 memcpy(buffer, clipboard, length); |
|
| 847 GlobalUnlock(hdata); |
|
| 848 SetClipboardData(win_html_fmt, hdata); |
|
| 849 CloseClipboard(); |
|
| 850 g_free(clipboard); |
|
| 851 } |
|
| 852 #endif |
902 #endif |
| 853 |
903 |
| 854 if (imhtml->editable) |
904 if (imhtml->editable) |
| 855 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); |
905 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); |
| 856 g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); |
906 g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); |
| 950 |
1000 |
| 951 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) |
1001 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) |
| 952 { |
1002 { |
| 953 #ifdef _WIN32 |
1003 #ifdef _WIN32 |
| 954 /* If we're on windows, let's see if we can get data from the HTML Format |
1004 /* If we're on windows, let's see if we can get data from the HTML Format |
| 955 clipboard before we try to paste from the GTK+ buffer */ |
1005 clipboard before we try to paste from the GTK buffer */ |
| 956 HGLOBAL hdata; |
1006 if (!clipboard_paste_html_win32(imhtml)) { |
| 957 DWORD err; |
|
| 958 char *buffer; |
|
| 959 char *text; |
|
| 960 |
|
| 961 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
|
| 962 return; |
|
| 963 |
|
| 964 if (IsClipboardFormatAvailable(win_html_fmt)) { |
|
| 965 OpenClipboard(NULL); |
|
| 966 hdata = GetClipboardData(win_html_fmt); |
|
| 967 if (hdata == NULL) { |
|
| 968 err = GetLastError(); |
|
| 969 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); |
|
| 970 CloseClipboard(); |
|
| 971 return; |
|
| 972 } |
|
| 973 buffer = GlobalLock(hdata); |
|
| 974 if (buffer == NULL) { |
|
| 975 err = GetLastError(); |
|
| 976 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); |
|
| 977 CloseClipboard(); |
|
| 978 return; |
|
| 979 } |
|
| 980 text = clipboard_win32_to_html(buffer); |
|
| 981 GlobalUnlock(hdata); |
|
| 982 CloseClipboard(); |
|
| 983 |
|
| 984 imhtml_paste_insert(imhtml, text, FALSE); |
|
| 985 g_free(text); |
|
| 986 } else { |
|
| 987 #endif |
1007 #endif |
| 988 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
1008 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
| 989 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), |
1009 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), |
| 990 paste_received_cb, imhtml); |
1010 paste_received_cb, imhtml); |
| 991 #ifdef _WIN32 |
1011 #ifdef _WIN32 |