home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_browse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  4.1 KB  |  138 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "imap_browse.h"
  25.  
  26. #include "open.xpm"
  27.  
  28. static GtkTargetEntry target_table[] = {
  29.    {"STRING", 0, 1 },
  30.    {"text/plain", 0, 2 }
  31. };
  32.  
  33. static void
  34. select_cb(GtkWidget *widget, gpointer data)
  35. {
  36.    BrowseWidget_t *browse = (BrowseWidget_t*) data;
  37.    const gchar *p;
  38.    gchar *file;
  39.  
  40.    file = gtk_file_selection_get_filename(
  41.       GTK_FILE_SELECTION(browse->file_selection));
  42.  
  43.    p = (browse->filter) ? browse->filter(file, browse->filter_data) : file;
  44.  
  45.    gtk_entry_set_text(GTK_ENTRY(browse->file), p);
  46.    gtk_widget_hide(browse->file_selection);
  47.    gtk_widget_grab_focus(browse->file);
  48. }
  49.  
  50. static void
  51. browse_cb(GtkWidget *widget, gpointer data)
  52. {
  53.    BrowseWidget_t *browse = (BrowseWidget_t*) data;
  54.  
  55.    if (!browse->file_selection) {
  56.       GtkWidget *dialog;
  57.       dialog = browse->file_selection = gtk_file_selection_new(browse->name);
  58.       gtk_signal_connect_object(
  59.      GTK_OBJECT(GTK_FILE_SELECTION(dialog)->cancel_button),
  60.      "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(dialog));
  61.       gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
  62.              "clicked", GTK_SIGNAL_FUNC(select_cb), data);
  63.    }
  64.    gtk_widget_show(browse->file_selection);
  65. }
  66.  
  67. static void 
  68. handle_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, 
  69.         GtkSelectionData *data, guint info, guint time)
  70. {
  71.    gboolean success;
  72.    if (data->length >= 0 && data->format == 8) {
  73.       gtk_entry_set_text(GTK_ENTRY(widget), data->data);
  74.       success = TRUE;
  75.    } else {
  76.       success = FALSE;
  77.    }
  78.    gtk_drag_finish(context, success, FALSE, time);
  79. }
  80.  
  81. BrowseWidget_t*
  82. browse_widget_new(const gchar *name)
  83. {
  84.    BrowseWidget_t *browse = g_new(BrowseWidget_t, 1);
  85.    GtkWidget *button;
  86.    GtkWidget *iconw;
  87.    GdkPixmap *icon;
  88.    GdkBitmap *mask;
  89.    GtkStyle  *style;
  90.  
  91.    browse->file_selection = NULL;
  92.    browse->name = name;
  93.    browse->filter = NULL;
  94.  
  95.    browse->hbox = gtk_hbox_new(FALSE, 1);
  96.    gtk_widget_show(browse->hbox);
  97.  
  98.    browse->file = gtk_entry_new();
  99.    gtk_box_pack_start(GTK_BOX(browse->hbox), browse->file, TRUE, TRUE, 0);
  100.    gtk_drag_dest_set(browse->file, GTK_DEST_DEFAULT_ALL, target_table,
  101.              2, GDK_ACTION_COPY);
  102.    gtk_signal_connect(GTK_OBJECT(browse->file), "drag_data_received",
  103.               GTK_SIGNAL_FUNC(handle_drop), NULL);
  104.  
  105.    gtk_widget_show(browse->file);
  106.  
  107.    browse->button = button = gtk_button_new();
  108.    style = gtk_widget_get_style(button);
  109.    icon = gdk_pixmap_colormap_create_from_xpm_d(
  110.       button->window, gtk_widget_get_colormap(button), &mask, 
  111.       &style->bg[GTK_STATE_NORMAL], open_xpm);
  112.  
  113.    iconw = gtk_pixmap_new(icon, mask);
  114.    gtk_widget_show(iconw);
  115.    gtk_container_add(GTK_CONTAINER(button), iconw);
  116.  
  117.    gtk_box_pack_end(GTK_BOX(browse->hbox), button, FALSE, FALSE, 0);
  118.    gtk_signal_connect(GTK_OBJECT(button), "clicked", 
  119.               GTK_SIGNAL_FUNC(browse_cb), (gpointer) browse);
  120.    gtk_widget_show(button);
  121.  
  122.    return browse;
  123. }
  124.  
  125. void 
  126. browse_widget_set_filename(BrowseWidget_t *browse, const gchar *filename)
  127. {
  128.    gtk_entry_set_text(GTK_ENTRY(browse->file), filename);
  129. }
  130.  
  131. void 
  132. browse_widget_set_filter(BrowseWidget_t *browse, BrowseFilter_t filter, 
  133.              gpointer data)
  134. {
  135.    browse->filter = filter;
  136.    browse->filter_data = data;
  137. }
  138.