Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

drag.c

Go to the documentation of this file.
00001 
00008 /* GtkSQL -- an interactive graphical query tool for PostgreSQL
00009  * Copyright (C) 2002  Darryl Luff
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024  * --------------------------------------------------------------------------
00025  * drag.c
00026  *
00027  * Handles dragging and dropping of text between the table list and the query window.
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 }

Generated on Sun May 9 19:19:16 2004 for GtkSQL by doxygen1.2.18