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

/*
 *  Copyright (C) 2003 Hiroyuki Ikezoe
 *
 *  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 __GTKUTILS_H__
#define __GTKUTILS_H__

#include <gtk/gtk.h>

G_BEGIN_DECLS

#if (GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION < 1)
#  define gtkutil_notebook_get_n_pages(notebook) \
   (GTK_IS_NOTEBOOK (notebook) ? g_list_length(GTK_NOTEBOOK(notebook)->children) : 0)
#else /* (GTK_MAJOR_VERSION == 2) && (GTK_MAJOR_VERSION < 1) */
#  define gtkutil_notebook_get_n_pages gtk_notebook_get_n_pages
#endif /* (GTK_MAJOR_VERSION == 2) && (GTK_MAJOR_VERSION < 1) */

void   gtkutil_menu_position_under_widget	(GtkMenu *menu,
						 gint *x, gint *y,
						 gboolean *push_in,
						 gpointer user_data);

GList *gtkutil_tree_selection_get_selected_rows	(GtkTreeSelection *selection,
						 GtkTreeModel **model);
GList *gtkutil_tree_selection_get_selected_references
						(GtkTreeSelection *selection,
						 GtkTreeModel **tree_model);
void   gtkutil_list_store_swap			(GtkListStore *store,
						 GtkTreeIter  *a,
						 GtkTreeIter  *b);
void   gtkutil_copy_text                        (const gchar *text);
void   gtkutil_append_im_menuitem               (GtkMenuShell *shell);

void   gtkutil_superpose_pixbuf                 (GtkWidget *widget,
						 GdkPixbuf *pixbuf, 
						 const gchar *stock_id,
						 GtkIconSize size);

#define GTKUTIL_CREATE_MENU(menu, array, n_array, field)		\
{									\
	gint i;								\
									\
	menu = gtk_menu_new ();						\
									\
	for (i = 0; i < n_array; i++)					\
	{								\
		GtkWidget *item;					\
									\
		item = gtk_menu_item_new_with_label (_(array[i].field));\
		gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); 	\
		gtk_widget_show (item);					\
	}								\
}


#define GTKUTIL_SET_DEFAULT_HISTORY(menu, str, array, n_array, field)	       \
{									       \
	gint i;								       \
									       \
	for (i = 0; str && i < n_array; i++)				       \
	{								       \
		if (!strcmp(str, array[i].field))			       \
		{							       \
			gtk_option_menu_set_history(GTK_OPTION_MENU(menu), i); \
			break;						       \
		}							       \
	}								       \
}

G_END_DECLS

#endif /* __GTKUTILS_H__ */
