imap_default_dialog.c 5.05 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1
/*
2
 * This is a plug-in for GIMP.
Sven Neumann's avatar
Sven Neumann committed
3 4 5
 *
 * Generates clickable image maps.
 *
6
 * Copyright (C) 1998-2002 Maurits Rijk  lpeek.mrijk@consunet.nl
Sven Neumann's avatar
Sven Neumann committed
7
 *
8
 * This program is free software: you can redistribute it and/or modify
Sven Neumann's avatar
Sven Neumann committed
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
Sven Neumann's avatar
Sven Neumann committed
11 12 13 14 15 16 17 18
 * (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
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
20 21 22
 *
 */

23
#include "config.h"
24

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

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

31

Sven Neumann's avatar
Sven Neumann committed
32
static void
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
dialog_response (GtkWidget       *widget,
                 gint             response_id,
                 DefaultDialog_t *dialog)
{
  switch (response_id)
    {
    case GTK_RESPONSE_APPLY:
      if (dialog->apply_cb)
        dialog->apply_cb (dialog->apply_cb_data);
      else if (dialog->ok_cb)
        dialog->ok_cb (dialog->ok_cb_data);
      break;

    case GTK_RESPONSE_OK:
      gtk_widget_hide (dialog->dialog);
      if (dialog->ok_cb)
        dialog->ok_cb (dialog->ok_cb_data);
      break;

    default:
      gtk_widget_hide (dialog->dialog);
      if (dialog->cancel_cb)
        dialog->cancel_cb (dialog->cancel_cb_data);
      break;
    }
Sven Neumann's avatar
Sven Neumann committed
58 59
}

60 61
void
default_dialog_set_ok_cb(DefaultDialog_t *dialog, void (*ok_cb)(gpointer),
62
                         gpointer ok_cb_data)
Sven Neumann's avatar
Sven Neumann committed
63 64 65 66 67
{
   dialog->ok_cb = ok_cb;
   dialog->ok_cb_data = ok_cb_data;
}

68 69
void
default_dialog_set_apply_cb(DefaultDialog_t *dialog,
70 71
                            void (*apply_cb)(gpointer),
                            gpointer apply_cb_data)
72 73 74 75 76
{
   dialog->apply_cb = apply_cb;
   dialog->apply_cb_data = apply_cb_data;
}

77 78
void
default_dialog_set_cancel_cb(DefaultDialog_t *dialog,
79 80
                             void (*cancel_cb)(gpointer),
                             gpointer cancel_cb_data)
Sven Neumann's avatar
Sven Neumann committed
81 82 83 84 85
{
   dialog->cancel_cb = cancel_cb;
   dialog->cancel_cb_data = cancel_cb_data;
}

86 87
DefaultDialog_t *
make_default_dialog (const gchar *title)
Sven Neumann's avatar
Sven Neumann committed
88
{
89
   DefaultDialog_t *data = g_new0 (DefaultDialog_t, 1);
Sven Neumann's avatar
Sven Neumann committed
90 91

   data->ok_cb = NULL;
92
   data->apply_cb = NULL;
Sven Neumann's avatar
Sven Neumann committed
93
   data->cancel_cb = NULL;
94

95
   data->dialog = gimp_dialog_new (title, PLUG_IN_ROLE,
Sven Neumann's avatar
Sven Neumann committed
96
                                   get_dialog(), 0,
97
                                   gimp_standard_help_func, PLUG_IN_PROC,
98
                                   NULL);
Sven Neumann's avatar
Sven Neumann committed
99

100 101
   data->apply = gtk_dialog_add_button (GTK_DIALOG (data->dialog),
                                        GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
102

103 104
   data->cancel = gtk_dialog_add_button (GTK_DIALOG (data->dialog),
                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
105

106 107 108
   data->ok = gtk_dialog_add_button (GTK_DIALOG (data->dialog),
                                     GTK_STOCK_OK, GTK_RESPONSE_OK);

109
   gtk_dialog_set_alternative_button_order (GTK_DIALOG (data->dialog),
110 111 112 113 114
                                            GTK_RESPONSE_OK,
                                            GTK_RESPONSE_APPLY,
                                            GTK_RESPONSE_CANCEL,
                                            -1);

115 116 117 118
   g_signal_connect (data->dialog, "response",
                     G_CALLBACK (dialog_response),
                     data);
   g_signal_connect (data->dialog, "destroy",
119
                     G_CALLBACK (gtk_widget_destroyed),
120
                     &data->dialog);
121

122
   data->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
123
   gtk_container_set_border_width (GTK_CONTAINER (data->vbox), 12);
124 125
   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
                       data->vbox, TRUE, TRUE, 0);
126 127
   gtk_widget_show (data->vbox);

Sven Neumann's avatar
Sven Neumann committed
128 129 130
   return data;
}

131
void
Sven Neumann's avatar
Sven Neumann committed
132 133 134 135 136
default_dialog_show(DefaultDialog_t *dialog)
{
   gtk_widget_show(dialog->dialog);
}

137
void
Sven Neumann's avatar
Sven Neumann committed
138 139
default_dialog_hide_cancel_button(DefaultDialog_t *dialog)
{
140
  gtk_widget_hide(dialog->cancel);
Sven Neumann's avatar
Sven Neumann committed
141 142
}

143
void
Sven Neumann's avatar
Sven Neumann committed
144 145
default_dialog_hide_apply_button(DefaultDialog_t *dialog)
{
146
  gtk_widget_hide(dialog->apply);
Sven Neumann's avatar
Sven Neumann committed
147 148
}

149
void
150 151
default_dialog_hide_help_button(DefaultDialog_t *dialog)
{
152
  /* gtk_widget_hide(dialog->help); */
153 154
}

Sven Neumann's avatar
Sven Neumann committed
155 156 157 158 159 160 161
void
default_dialog_set_title(DefaultDialog_t *dialog, const gchar *title)
{
   gtk_window_set_title(GTK_WINDOW(dialog->dialog), title);
}

void
162
default_dialog_set_label(DefaultDialog_t *dialog, const gchar *text)
Sven Neumann's avatar
Sven Neumann committed
163 164
{
   GtkWidget *label = gtk_label_new(text);
165 166

   gtk_box_pack_start (GTK_BOX (dialog->vbox), label, TRUE, TRUE, 0);
Sven Neumann's avatar
Sven Neumann committed
167 168
   gtk_widget_show(label);
}
169 170 171 172

GtkWidget*
default_dialog_add_table(DefaultDialog_t *dialog, gint rows, gint cols)
{
173
  GtkWidget *table = gtk_table_new (rows, cols, FALSE);
174

175 176
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
177

178 179
  gtk_box_pack_start (GTK_BOX (dialog->vbox), table, TRUE, TRUE, 0);
  gtk_widget_show (table);
180

181
  return table;
182
}