1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/*
* This is a plug-in for GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include "libgimp/gimp.h"
#include "libgimp/gimpui.h"
#include "imap_browse.h"
#include "libgimp/stdplugins-intl.h"
static const GtkTargetEntry target_table[] =
{
{"STRING", 0, 1 },
{"text/plain", 0, 2 }
};
static void
select_cb (GtkWidget *dialog,
gint response_id,
BrowseWidget_t *browse)
{
if (response_id == GTK_RESPONSE_OK)
{
gchar *p;
gchar *file;
file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
p = (browse->filter ?
browse->filter (file, browse->filter_data) : file);
gtk_entry_set_text (GTK_ENTRY (browse->file), p);
if (browse->filter)
g_free (p);
g_free (file);
}
gtk_widget_hide (dialog);
gtk_widget_grab_focus (browse->file);
}
static void
browse_cb (GtkWidget *widget,
BrowseWidget_t *browse)
{
if (!browse->file_chooser)
{
GtkWidget *dialog;
dialog = browse->file_chooser =
gtk_file_chooser_dialog_new (browse->name,
GTK_WINDOW (gtk_widget_get_toplevel (widget)),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (select_cb),
browse);
}
gtk_window_present (GTK_WINDOW (browse->file_chooser));
}
static void
handle_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y,
GtkSelectionData *data, guint info, guint time)
{
gboolean success = FALSE;
if (gtk_selection_data_get_length (data) >= 0 &&
gtk_selection_data_get_format (data) == 8)
{
const gchar *text = (const gchar *) gtk_selection_data_get_data (data);
if (g_utf8_validate (text, -1, NULL))
{
gtk_entry_set_text (GTK_ENTRY (widget), text);
success = TRUE;
}
}
gtk_drag_finish(context, success, FALSE, time);
}
BrowseWidget_t*
browse_widget_new (const gchar *name)
{
BrowseWidget_t *browse = g_new(BrowseWidget_t, 1);
GtkWidget *button;
GtkWidget *icon;
browse->file_chooser = NULL;
browse->name = name;
browse->filter = NULL;
browse->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
gtk_widget_show (browse->hbox);
browse->file = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX(browse->hbox), browse->file, TRUE, TRUE, 0);
gtk_drag_dest_set (browse->file, GTK_DEST_DEFAULT_ALL, target_table,
2, GDK_ACTION_COPY);
g_signal_connect (browse->file, "drag-data-received",
G_CALLBACK(handle_drop), NULL);
gtk_widget_show (browse->file);
browse->button = button = gtk_button_new ();
icon = gtk_image_new_from_icon_name (GIMP_ICON_DOCUMENT_OPEN,
GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), icon);
gtk_widget_show (icon);
gtk_box_pack_end(GTK_BOX (browse->hbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK(browse_cb), (gpointer) browse);
gtk_widget_show (button);
return browse;
}
void
browse_widget_set_filename(BrowseWidget_t *browse, const gchar *filename)
{
gtk_entry_set_text (GTK_ENTRY (browse->file), filename);
}
void
browse_widget_set_filter(BrowseWidget_t *browse, BrowseFilter_t filter,
gpointer data)
{
browse->filter = filter;
browse->filter_data = data;
}
|