/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Copyright (C) 2003 Takuro Ashie
 *
 *  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 2, 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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __KZ_GESTURE_H__
#define __KZ_GESTURE_H__

#include <gtk/gtk.h>
#include <gtk24backports.h>

G_BEGIN_DECLS

#define KZ_TYPE_GESTURE			(kz_gesture_get_type ())
#define KZ_GESTURE(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_GESTURE, KzGesture))
#define KZ_GESTURE_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_GESTURE, KzGestureClass))
#define KZ_IS_GESTURE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_GESTURE))
#define KZ_IS_GESTURE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_GESTURE))
#define KZ_GESTURE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_GESTURE, KzGestureClass))

typedef struct _KzGesture	KzGesture;
typedef struct _KzGestureClass	KzGestureClass;
typedef struct _KzGestureItem	KzGestureItem;
typedef struct _KzGestureItems	KzGestureItems;

#define	KZ_GESTURE_MOTION_TERMINATOR	'\0'
#define	KZ_GESTURE_MOTION_UP		'U'
#define	KZ_GESTURE_MOTION_DOWN		'D'
#define	KZ_GESTURE_MOTION_LEFT		'L'
#define	KZ_GESTURE_MOTION_RIGHT		'R'

typedef gchar KzGestureMotion;

struct _KzGesture
{
	GObject parent;

	KzGestureMotion  sequence[32];
	gint             sequence_len;
	gint             max_sequence_len;
	gint             current_mode;
	gint             prev_x, prev_y;
	gint             x, y;
	gboolean         started;
	gint             threshold;

	KzGestureItems  *items;
};

struct _KzGestureClass
{
	GObjectClass parent_class;

	/* -- signals -- */
	void (*start)        (KzGesture *gesture);
	void (*cancel)       (KzGesture *gesture);
	void (*stack_motion) (KzGesture *gesture,
			      KzGestureMotion motion);
	void (*perform)      (KzGesture *gesture);
};

struct _KzGestureItem
{
	GtkAction       *action;
	gint             mode;
	KzGestureMotion *sequence;
};

struct _KzGestureItems
{
	GSList *list;
	gint ref_count;
};

GType        kz_gesture_get_type               (void);
KzGesture   *kz_gesture_new                    (void);

void         kz_gesture_set_items              (KzGesture *gesture,
						KzGestureItems *items);

void         kz_gesture_start                  (KzGesture *gesture,
						gint mode,
						gint x, gint y);
void         kz_gesture_perform                (KzGesture *gesture);
void         kz_gesture_cancel                 (KzGesture *gesture);
gboolean     kz_gesture_is_started             (KzGesture *gesture);
void         kz_gesture_update_position        (KzGesture *gesture,
						gint x, gint y);
void         kz_gesture_create_gesture_string  (KzGesture *gesture,
						gchar buf[], gint len);
gboolean     kz_gesture_is_matched             (KzGesture *gesture);
const gchar *kz_gesture_get_matched_label      (KzGesture *gesture);
void         kz_gesture_get_current_position   (KzGesture *gesture,
					        gint *x, gint *y);
const KzGestureMotion *
             kz_gesture_get_current_sequence   (KzGesture *gesture);
gint         kz_gesture_get_mode               (KzGesture *gesture);
void         kz_gesture_set_mode               (KzGesture *gesture,
						gint mode);
gint         kz_gesture_get_threshold          (KzGesture *gesture);
void         kz_gesture_set_threshold          (KzGesture *gesture,
						gint threshold);


KzGestureItems *kz_gesture_items_new           (void);
KzGestureItems *kz_gesture_items_ref           (KzGestureItems *items);
void            kz_gesture_items_unref         (KzGestureItems *items);
void            kz_gesture_items_set_action    (KzGestureItems *items,
						GtkAction *action,
						gint mode,
						const KzGestureMotion *sequence);
void            kz_gesture_items_unset_action  (KzGestureItems *items,
						GtkAction *action);

G_END_DECLS

#endif /* __KZ_GESTURE_H__ */
