tile.h 4.16 KB
Newer Older
Jim Krehl's avatar
Jim Krehl committed
1
/*
2
 * This file is part of libtile.
Jim Krehl's avatar
Jim Krehl committed
3 4 5
 *
 * Copyright (c) 2006 Novell, Inc.
 *
6
 * Libtile is free software; you can redistribute it and/or modify it under the
Jim Krehl's avatar
Jim Krehl committed
7 8 9 10
 * 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.
 *
11
 * Libtile is distributed in the hope that it will be useful, but WITHOUT ANY
Jim Krehl's avatar
Jim Krehl committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * 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 libslab; if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef __TILE_H__
#define __TILE_H__

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

G_BEGIN_DECLS
28

Jim Krehl's avatar
Jim Krehl committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#define TILE_TYPE         (tile_get_type ())
#define TILE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TILE_TYPE, Tile))
#define TILE_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TILE_TYPE, TileClass))
#define IS_TILE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TILE_TYPE))
#define IS_TILE_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c), TILE_TYPE))
#define TILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TILE_TYPE, TileClass))
#define TILE_ACTION_TYPE         (tile_action_get_type ())
#define TILE_ACTION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TILE_ACTION_TYPE, TileAction))
#define TILE_ACTION_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TILE_ACTION_TYPE, TileActionClass))
#define IS_TILE_ACTION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TILE_ACTION_TYPE))
#define IS_TILE_ACTION_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c), TILE_ACTION_TYPE))
#define TILE_ACTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TILE_ACTION_TYPE, TileActionClass))
#define TILE_ACTION_CHECK_FLAG(action,flag) ((TILE_ACTION (action)->flags & (flag)) != 0)
#define TILE_STATE_ENTERED GTK_STATE_PRELIGHT
#define TILE_STATE_FOCUSED GTK_STATE_PRELIGHT
44

Jim Krehl's avatar
Jim Krehl committed
45 46 47 48 49 50 51 52
typedef struct _Tile Tile;
typedef struct _TileClass TileClass;
typedef struct _TileAction TileAction;
typedef struct _TileActionClass TileActionClass;
typedef struct _TileEvent TileEvent;

typedef void (*TileActionFunc) (Tile *, TileEvent *, TileAction *);

53 54
typedef enum
{
Jim Krehl's avatar
Jim Krehl committed
55 56 57 58 59 60 61 62
	TILE_EVENT_ACTIVATED_SINGLE_CLICK,
	TILE_EVENT_ACTIVATED_DOUBLE_CLICK,
	TILE_EVENT_ACTIVATED_KEYBOARD,
	TILE_EVENT_IMPLICIT_DISABLE,
	TILE_EVENT_IMPLICIT_ENABLE,
	TILE_EVENT_ACTION_TRIGGERED
} TileEventType;

63 64
typedef enum
{
Jim Krehl's avatar
Jim Krehl committed
65 66 67 68
	TILE_ACTION_OPENS_NEW_WINDOW = 1 << 0,
	TILE_ACTION_OPENS_HELP = 1 << 1
} TileActionFlags;

69 70
struct _Tile
{
Jim Krehl's avatar
Jim Krehl committed
71 72 73 74 75 76 77 78 79 80 81 82 83
	GtkButton gtk_button;

	gchar *uri;
	GtkMenu *context_menu;
	gboolean entered;
	gboolean enabled;

	TileAction **actions;
	gint n_actions;

	TileAction *default_action;
};

84 85
struct _TileClass
{
Jim Krehl's avatar
Jim Krehl committed
86 87 88 89 90 91 92 93 94 95 96
	GtkButtonClass gtk_button_class;

	void (*tile_explicit_enable) (Tile *);
	void (*tile_explicit_disable) (Tile *);

	void (*tile_activated) (Tile *, TileEvent *);
	void (*tile_implicit_enable) (Tile *, TileEvent *);
	void (*tile_implicit_disable) (Tile *, TileEvent *);
	void (*tile_action_triggered) (Tile *, TileEvent *, TileAction *);
};

97 98
struct _TileAction
{
Jim Krehl's avatar
Jim Krehl committed
99 100 101 102 103 104 105 106 107 108
	GObject parent;

	Tile *tile;

	TileActionFunc func;
	GtkMenuItem *menu_item;

	guint32 flags;
};

109 110
struct _TileActionClass
{
Jim Krehl's avatar
Jim Krehl committed
111 112 113
	GObjectClass parent_class;
};

114 115
struct _TileEvent
{
Jim Krehl's avatar
Jim Krehl committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	TileEventType type;
	guint32 time;
};

GType tile_get_type (void);
GType tile_action_get_type (void);

gint tile_compare (gconstpointer a, gconstpointer b);

void tile_explicit_enable (Tile * tile);
void tile_explicit_disable (Tile * tile);

void tile_implicit_enable (Tile * tile);
void tile_implicit_disable (Tile * tile);
void tile_implicit_enable_with_time (Tile * tile, guint32 time);
void tile_implicit_disable_with_time (Tile * tile, guint32 time);

void tile_trigger_action (Tile * tile, TileAction * action);
134
void tile_trigger_action_with_time (Tile * tile, TileAction * action, guint32 time);
Jim Krehl's avatar
Jim Krehl committed
135

136 137
TileAction *tile_action_new (Tile * tile, TileActionFunc func, const gchar * menu_item_markup,
	guint32 flags);
Jim Krehl's avatar
Jim Krehl committed
138

139
void tile_action_set_menu_item_label (TileAction * action, const gchar * markup);
Jim Krehl's avatar
Jim Krehl committed
140 141 142 143
GtkMenuItem *tile_action_get_menu_item (TileAction * action);

G_END_DECLS
#endif