1 /*
2 * This is a plug-in for GIMP.
3 *
4 * Generates clickable image maps.
5 *
6 * Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.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 3 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, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "config.h"
24
25 #include <gtk/gtk.h>
26
27 #include "imap_commands.h"
28
29 #include "libgimp/stdplugins-intl.h"
30
31 static void unselect_all_command_destruct(Command_t *command);
32 static CmdExecuteValue_t unselect_all_command_execute(Command_t *command);
33
34 /* COMMAND_PROTO(unselect_all_command); */
35
36 static CommandClass_t unselect_all_command_class = {
37 unselect_all_command_destruct,
38 unselect_all_command_execute,
39 NULL, /* unselect_all_command_undo */
40 NULL /* unselect_all_command_redo */
41 };
42
43 typedef struct {
44 Command_t parent;
45 ObjectList_t *list;
46 Object_t *exception;
47 } UnselectAllCommand_t;
48
49 Command_t*
unselect_all_command_new(ObjectList_t * list,Object_t * exception)50 unselect_all_command_new(ObjectList_t *list, Object_t *exception)
51 {
52 UnselectAllCommand_t *command = g_new(UnselectAllCommand_t, 1);
53 command->list = list;
54 command->exception = (exception) ? object_ref(exception) : exception;
55 return command_init(&command->parent, _("Unselect All"),
56 &unselect_all_command_class);
57 }
58
59 static void
unselect_all_command_destruct(Command_t * parent)60 unselect_all_command_destruct(Command_t *parent)
61 {
62 UnselectAllCommand_t *command = (UnselectAllCommand_t*) parent;
63 if (command->exception)
64 object_unref(command->exception);
65 }
66
67 static void
select_one_object(Object_t * obj,gpointer data)68 select_one_object(Object_t *obj, gpointer data)
69 {
70 UnselectAllCommand_t *command = (UnselectAllCommand_t*) data;
71 command_add_subcommand(&command->parent, unselect_command_new(obj));
72 }
73
74 static CmdExecuteValue_t
unselect_all_command_execute(Command_t * parent)75 unselect_all_command_execute(Command_t *parent)
76 {
77 UnselectAllCommand_t *command = (UnselectAllCommand_t*) parent;
78 gpointer id;
79 CmdExecuteValue_t rvalue;
80
81 id = object_list_add_select_cb(command->list, select_one_object,
82 command);
83 if (object_list_deselect_all(command->list, command->exception)) {
84 rvalue = CMD_APPEND;
85 } else {
86 rvalue = CMD_DESTRUCT;
87 }
88 object_list_remove_select_cb(command->list, id);
89 return rvalue;
90 }
91