imap_command.h 3.12 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 6 7
 *
 * Generates clickable image maps.
 *
 * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
 *
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 <https://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
20 21 22 23 24 25 26 27
 *
 */

#ifndef _IMAP_COMMAND_H
#define _IMAP_COMMAND_H

#include "imap_object.h"

28 29
#define DEFAULT_UNDO_LEVELS 10

Sven Neumann's avatar
Sven Neumann committed
30 31 32 33
typedef struct CommandClass_t CommandClass_t;
typedef struct Command_t Command_t;
typedef struct CommandList_t CommandList_t;

34 35
typedef enum {CMD_APPEND, CMD_DESTRUCT, CMD_IGNORE} CmdExecuteValue_t;

Sven Neumann's avatar
Sven Neumann committed
36 37
struct CommandClass_t {
   void (*destruct)(Command_t*);
38
   CmdExecuteValue_t (*execute)(Command_t*);
Sven Neumann's avatar
Sven Neumann committed
39 40 41 42 43 44 45
   void (*undo)(Command_t*);
   void (*redo)(Command_t*);
};

struct Command_t {
   CommandClass_t      *class;
   CommandList_t       *sub_commands;
46 47
   const gchar         *name;
   gboolean             locked;
Sven Neumann's avatar
Sven Neumann committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
};


typedef Command_t* (*CommandFactory_t)(void);

typedef void (*CommandListCallbackFunc_t)(Command_t*, gpointer);

typedef struct {
   CommandListCallbackFunc_t func;
   gpointer data;
} CommandListCB_t;

typedef struct {
   GList *list;
} CommandListCallback_t;

struct CommandList_t {
   CommandList_t *parent;
   gint undo_levels;
   GList *list;
68 69
   GList *undo;                 /* Pointer to current undo command */
   GList *redo;                 /* Pointer to current redo command */
Sven Neumann's avatar
Sven Neumann committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
   CommandListCallback_t update_cb;
};

CommandList_t *command_list_new(gint undo_levels);
void command_list_destruct(CommandList_t *list);
void command_list_set_undo_level(gint level);
void command_list_add(Command_t *command);
void command_list_remove_all(void);
void command_list_undo(CommandList_t *list);
void command_list_undo_all(CommandList_t *list);
void command_list_redo(CommandList_t *list);
void command_list_redo_all(CommandList_t *list);
void command_list_add_update_cb(CommandListCallbackFunc_t func, gpointer data);
Command_t *command_list_get_redo_command(void);

Command_t *command_new(void (*func)(void));
86
Command_t *command_init(Command_t *command, const gchar *name,
87
                        CommandClass_t *class);
Sven Neumann's avatar
Sven Neumann committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
void command_execute(Command_t *command);
void command_undo(Command_t *command);
void command_redo(Command_t *command);
void command_set_name(Command_t *command, const gchar *name);
void command_add_subcommand(Command_t *command, Command_t *sub_command);

void last_command_undo(void);
void last_command_redo(void);

void subcommand_list_add(CommandList_t *list, Command_t *command);
Command_t *subcommand_start(const gchar *name);
void subcommand_end(void);

#define command_lock(command) ((command)->locked = TRUE)

#endif /* _IMAP_COMMAND_H */