imap_default_dialog.c 5.84 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1 2 3 4 5
/*
 * This is a plug-in for the GIMP.
 *
 * Generates clickable image maps.
 *
6
 * Copyright (C) 1998-2002 Maurits Rijk  lpeek.mrijk@consunet.nl
Sven Neumann's avatar
Sven Neumann committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

24
#include "config.h"
25

26 27
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
28

Sven Neumann's avatar
Sven Neumann committed
29 30
#include "imap_default_dialog.h"

31 32 33
#include "libgimp/stdplugins-intl.h"


Sven Neumann's avatar
Sven Neumann committed
34 35 36 37 38 39 40 41 42
static void
dialog_cancel(GtkWidget *widget, gpointer data)
{
   DefaultDialog_t *dialog = (DefaultDialog_t*) data;
   gtk_widget_hide(dialog->dialog);
   if (dialog->cancel_cb)
      dialog->cancel_cb(dialog->cancel_cb_data);
}

43
static gboolean
Sven Neumann's avatar
Sven Neumann committed
44 45 46
dialog_destroy(GtkWidget *widget, GdkEvent *event, gpointer data)
{
   dialog_cancel(widget, data);
47
   return TRUE;
Sven Neumann's avatar
Sven Neumann committed
48 49 50 51 52 53
}

static void
dialog_apply(GtkWidget *widget, gpointer data)
{
   DefaultDialog_t *dialog = (DefaultDialog_t*) data;
54 55 56
   if (dialog->apply_cb)
      dialog->apply_cb(dialog->apply_cb_data);
   else if (dialog->ok_cb)
Sven Neumann's avatar
Sven Neumann committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
      dialog->ok_cb(dialog->ok_cb_data);
}

static void
dialog_ok(GtkWidget *widget, gpointer data)
{
   DefaultDialog_t *dialog = (DefaultDialog_t*) data;
   gtk_widget_hide(dialog->dialog);
   if (dialog->ok_cb)
      dialog->ok_cb(dialog->ok_cb_data);
}

void 
default_dialog_set_ok_cb(DefaultDialog_t *dialog, void (*ok_cb)(gpointer), 
			 gpointer ok_cb_data)
{
   dialog->ok_cb = ok_cb;
   dialog->ok_cb_data = ok_cb_data;
}

77 78 79 80 81 82 83 84 85
void 
default_dialog_set_apply_cb(DefaultDialog_t *dialog, 
			    void (*apply_cb)(gpointer), 
			    gpointer apply_cb_data)
{
   dialog->apply_cb = apply_cb;
   dialog->apply_cb_data = apply_cb_data;
}

Sven Neumann's avatar
Sven Neumann committed
86 87 88 89 90 91 92 93 94 95 96 97 98
void 
default_dialog_set_cancel_cb(DefaultDialog_t *dialog, 
			     void (*cancel_cb)(gpointer), 
			     gpointer cancel_cb_data)
{
   dialog->cancel_cb = cancel_cb;
   dialog->cancel_cb_data = cancel_cb_data;
}

DefaultDialog_t*
make_default_dialog(const gchar *title)
{
   DefaultDialog_t *data = (DefaultDialog_t*) g_new(DefaultDialog_t, 1);
99
   GtkWidget *dialog, *hbbox;
Sven Neumann's avatar
Sven Neumann committed
100 101

   data->ok_cb = NULL;
102
   data->apply_cb = NULL;
Sven Neumann's avatar
Sven Neumann committed
103 104
   data->cancel_cb = NULL;
   data->dialog = dialog = gtk_dialog_new();
105 106 107

   if (title)
      gtk_window_set_title(GTK_WINDOW(dialog), title);
Sven Neumann's avatar
Sven Neumann committed
108

109 110
   g_signal_connect(G_OBJECT(dialog), "delete_event",
                    G_CALLBACK(dialog_destroy), (gpointer) data);
Sven Neumann's avatar
Sven Neumann committed
111

112 113
   /*  Action area  */
   gtk_container_set_border_width(GTK_CONTAINER(
114
      GTK_DIALOG(dialog)->action_area), 12);
115 116
   gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(dialog)->action_area), FALSE);
   hbbox = gtk_hbutton_box_new();
117
   gtk_box_set_spacing(GTK_BOX(hbbox), 6);
118 119 120 121
   gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area), hbbox, FALSE, 
		    FALSE, 0);
   gtk_widget_show (hbbox);

122
   data->ok = gtk_button_new_from_stock(GTK_STOCK_OK);
Sven Neumann's avatar
Sven Neumann committed
123
   GTK_WIDGET_SET_FLAGS(data->ok, GTK_CAN_DEFAULT);
124 125
   g_signal_connect(G_OBJECT(data->ok), "clicked",
                    G_CALLBACK(dialog_ok), (gpointer) data);
126
   gtk_box_pack_start(GTK_BOX(hbbox), data->ok, FALSE, FALSE, 0);
Sven Neumann's avatar
Sven Neumann committed
127 128 129
   gtk_widget_grab_default(data->ok);
   gtk_widget_show(data->ok);

130
   data->apply = gtk_button_new_from_stock(GTK_STOCK_APPLY);
131
   GTK_WIDGET_SET_FLAGS(data->apply, GTK_CAN_DEFAULT);
132 133
   g_signal_connect(G_OBJECT(data->apply), "clicked",
                    G_CALLBACK(dialog_apply), (gpointer) data);
134
   gtk_box_pack_start(GTK_BOX(hbbox), data->apply, FALSE, FALSE, 0);
Sven Neumann's avatar
Sven Neumann committed
135 136
   gtk_widget_show(data->apply);

137
   data->cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
138
   GTK_WIDGET_SET_FLAGS(data->cancel, GTK_CAN_DEFAULT);
139 140
   g_signal_connect(G_OBJECT(data->cancel), "clicked",
                    G_CALLBACK(dialog_cancel), (gpointer) data);
141
   gtk_box_pack_start(GTK_BOX(hbbox), data->cancel, FALSE, FALSE, 0);
Sven Neumann's avatar
Sven Neumann committed
142 143
   gtk_widget_show(data->cancel);

144
   data->help = gtk_button_new_with_label(_("Help..."));
Sven Neumann's avatar
Sven Neumann committed
145 146 147 148 149
  /* Fix me: no action yet
     GTK_WIDGET_SET_FLAGS(data->help, GTK_CAN_DEFAULT);
     gtk_box_pack_start(GTK_BOX(hbbox), data->help, FALSE, FALSE, 0);
     gtk_widget_show(data->help);
   */
150
 
Sven Neumann's avatar
Sven Neumann committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
   return data;
}

void 
default_dialog_show(DefaultDialog_t *dialog)
{
   gtk_widget_show(dialog->dialog);
}

void 
default_dialog_hide_cancel_button(DefaultDialog_t *dialog)
{
   gtk_widget_hide(dialog->cancel);
}

void 
default_dialog_hide_apply_button(DefaultDialog_t *dialog)
{
   gtk_widget_hide(dialog->apply);
}

172 173 174 175 176 177
void 
default_dialog_hide_help_button(DefaultDialog_t *dialog)
{
   gtk_widget_hide(dialog->help);
}

Sven Neumann's avatar
Sven Neumann committed
178 179 180 181 182 183 184
void
default_dialog_set_title(DefaultDialog_t *dialog, const gchar *title)
{
   gtk_window_set_title(GTK_WINDOW(dialog->dialog), title);
}

void 
185
default_dialog_set_ok_sensitivity(DefaultDialog_t *dialog, gboolean sensitive)
Sven Neumann's avatar
Sven Neumann committed
186 187 188 189 190 191 192 193 194
{
   gtk_widget_set_sensitive(dialog->ok, sensitive);
}

void
default_dialog_set_label(DefaultDialog_t *dialog, gchar *text)
{
   GtkWidget *label = gtk_label_new(text);
   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->dialog)->vbox), label, 
195
		      TRUE, TRUE, 5);
Sven Neumann's avatar
Sven Neumann committed
196 197
   gtk_widget_show(label);
}
198 199 200 201 202 203 204 205 206 207 208 209

GtkWidget*
default_dialog_add_table(DefaultDialog_t *dialog, gint rows, gint cols)
{
   GtkWidget *table = gtk_table_new(rows, cols, FALSE);
   gtk_container_set_border_width(GTK_CONTAINER(table), 10);
   gtk_table_set_row_spacings(GTK_TABLE(table), 10);
   gtk_table_set_col_spacings(GTK_TABLE(table), 10);
   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox), table);
   gtk_widget_show(table);
   return table;
}