00001 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include <string.h>
00032 #include "buf.h"
00033 #include "drag.h"
00034 
00036 void receive_callback(GtkWidget * widget, GdkDragContext * context, gint x,
00037                      gint y, GtkSelectionData * selection, guint info,
00038                      guint time)
00039 {
00040     if (selection->length < 0) {
00041         g_warning("Selection retrieval failed\n");
00042         return;
00043     }
00044 
00045     if (selection->type != selection->target) {
00046         g_warning("Selection type is wrong\n");
00047         return;
00048     }
00049     gtk_text_insert(GTK_TEXT(widget), NULL, NULL, NULL, selection->data,
00050                     strlen(selection->data));
00051     return;
00052 }
00053 
00055 void send_callback(GtkWidget * widget, GdkDragContext * context,
00056                   GtkSelectionData * selection, guint info, guint time)
00057 {
00058     GtkCList *clist;
00059     GList *list;
00060     int row = 0;
00061     char *field;
00062     ABuf *fields = buf_new(1024);
00063     int focus = -1;
00064 
00065     if (! fields) {
00066         g_error("sendCallback() could not allocate memory for a buffer\n");
00067         return;
00068     }
00069     clist = GTK_CLIST(widget);
00070     gtk_clist_get_text(clist, row, 0, &field);
00071 
00072     focus = clist->focus_row;
00073     gtk_clist_get_text(clist, focus, 0, &field);
00074     strncpy(fields->b_dat, field, fields->b_len);
00075 
00076     list = clist->selection;
00077     while (list) {
00078         row = (int) list->data;
00079         if (row != focus) {
00080             gtk_clist_get_text(clist, row, 0, &field);
00081             fields = buf_check(fields, strlen(fields->b_dat) + strlen(field) + 3);
00082             fields = buf_strcat(fields, ", ");
00083             fields = buf_strcat(fields, field);
00084         }
00085         list = list->next;
00086     }
00087 
00088     gtk_selection_data_set(selection, selection->target, 8,
00089                            (const guchar *) fields->b_dat, strlen(fields->b_dat) + 1);
00090     buf_free(fields);
00091 }