/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GTK_UNDO_H__
#define __GTK_UNDO_H__

#include <glib-object.h>

G_BEGIN_DECLS


#define GTK_TYPE_UNDO_STACK              (_gtk_undo_stack_get_type ())
#define GTK_UNDO_STACK(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_UNDO_STACK, GtkUndoStack))
#define GTK_UNDO_STACK_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_UNDO_STACK, GtkUndoStackClass))
#define GTK_IS_UNDO_STACK(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_UNDO_STACK))
#define GTK_IS_UNDO_STACK_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_UNDO_STACK))
#define GTK_UNDO_STACK_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_UNDO_STACK, GtkUndoStackClass))


typedef struct _GtkUndoStack          GtkUndoStack;
typedef struct _GtkUndoStackPrivate   GtkUndoStackPrivate;
typedef struct _GtkUndoStackClass     GtkUndoStackClass;
typedef struct _GtkUndoAction         GtkUndoAction;
typedef struct _GtkUndoActionClass    GtkUndoActionClass;

typedef void     (*GtkUndoActionUndo)   (GtkUndoAction  *action,
                                         gpointer        document);
typedef void     (*GtkUndoActionRedo)   (GtkUndoAction  *action,
                                         gpointer        document);
typedef gboolean (*GtkUndoActionMerge)  (GtkUndoAction  *action,
                                         GtkUndoAction  *what,
                                         gpointer        document);
typedef void     (*GtkUndoActionDestroy)(GtkUndoAction  *action,
                                         gpointer        document);

struct _GtkUndoActionClass
{
    GtkUndoActionUndo undo;
    GtkUndoActionRedo redo;
    GtkUndoActionMerge merge;
    GtkUndoActionDestroy destroy;
};

struct _GtkUndoStack
{
    GObject base;

    gpointer document;
    GSList *undo_stack; /* ActionGroup* */
    GSList *redo_stack; /* ActionGroup* */

    guint frozen;
    guint continue_group;
    gboolean do_continue;
    gboolean new_group;
};

struct _GtkUndoStackClass
{
    GObjectClass base_class;

    void (*undo) (GtkUndoStack    *mgr);
    void (*redo) (GtkUndoStack    *mgr);
};


GType           _gtk_undo_stack_get_type        (void) G_GNUC_CONST;

GtkUndoStack   *_gtk_undo_stack_new             (gpointer                document);

guint           _gtk_undo_action_register       (GtkUndoActionClass     *klass);

void            _gtk_undo_stack_add_action      (GtkUndoStack           *mgr,
                                                 guint                   type,
                                                 GtkUndoAction          *action);

void            _gtk_undo_stack_clear           (GtkUndoStack           *mgr);
void            _gtk_undo_stack_freeze          (GtkUndoStack           *mgr);
void            _gtk_undo_stack_thaw            (GtkUndoStack           *mgr);
gboolean        _gtk_undo_stack_frozen          (GtkUndoStack           *mgr);

void            _gtk_undo_stack_new_group       (GtkUndoStack           *mgr);
void            _gtk_undo_stack_start_group     (GtkUndoStack           *mgr);
void            _gtk_undo_stack_end_group       (GtkUndoStack           *mgr);

void            _gtk_undo_stack_undo            (GtkUndoStack           *mgr);
void            _gtk_undo_stack_redo            (GtkUndoStack           *mgr);
gboolean        _gtk_undo_stack_can_undo        (GtkUndoStack           *mgr);
gboolean        _gtk_undo_stack_can_redo        (GtkUndoStack           *mgr);


G_END_DECLS

#endif /* __GTK_UNDO_H__ */
