/* GTK - The GIMP Toolkit
 * Copyright (C) 2000 Red Hat Software
 * Copyright (C) 2000 SuSE Linux Ltd
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 *
 * Original author: Owen Taylor <otaylor@redhat.com>
 * 
 * Modified for Thai (Broken) - Robert Brady <robert@suse.co.uk>
 *
 * Modified for Thai (TIS820-2538) - Cholwich Nattee <cholwich@nm.cs.titech.ac.jp>
 *
 */

#include <string.h>

#include <gdk/gdkkeysyms.h>

#include "gtk/gtkintl.h"
#include "gtk/gtkimcontextsimple.h"
#include "gtk/gtkimmodule.h"

GType type_thai_tis820 = 0;

static void thai_tis820_class_init (GtkIMContextSimpleClass *class);
static void thai_tis820_init (GtkIMContextSimple *im_context);

static void
thai_tis820_register_type (GTypeModule *module)
{
  static const GTypeInfo object_info =
  {
    sizeof (GtkIMContextSimpleClass),
    (GBaseInitFunc) NULL,
    (GBaseFinalizeFunc) NULL,
    (GClassInitFunc) thai_tis820_class_init,
    NULL,           /* class_finalize */
    NULL,           /* class_data */
    sizeof (GtkIMContextSimple),
    0,
    (GtkObjectInitFunc) thai_tis820_init,
  };

  type_thai_tis820 = 
    g_type_module_register_type (module,
				 GTK_TYPE_IM_CONTEXT_SIMPLE,
				 "GtkIMContextThaiTIS820",
				 &object_info, 0);
}

static guint16 thai_tis820_compose_seqs[] = {

	0x21, 0, 0, 0, 0, 0x0e45,
	0x22, 0, 0, 0, 0, 0x002e,
	0x23, 0, 0, 0, 0, 0x0e52,
	0x24, 0, 0, 0, 0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, 0x0e30,
	0x75, 0, 0, 0, 0, 0x0e35,
	0x76, 0, 0, 0, 0, 0x0e2d,
	0x77, 0, 0, 0, 0, 0x0e44,
	0x78, 0, 0, 0, 0, 0x0e1b,
	0x79, 0, 0, 0, 0, 0x0e31,
	0x7a, 0, 0, 0, 0, 0x0e1c,
	0x7b, 0, 0, 0, 0, 0x0e10,
	0x7c, 0, 0, 0, 0, 0x0e03,
	0x7d, 0, 0, 0, 0, 0x002c,
	0x7e, 0, 0, 0, 0, 0x0e5b,
};

static void
thai_tis820_class_init (GtkIMContextSimpleClass *class)
{
}

static void
thai_tis820_init (GtkIMContextSimple *im_context)
{
  gtk_im_context_simple_add_table (im_context,
				   thai_tis820_compose_seqs,
				   4,
				   G_N_ELEMENTS (thai_tis820_compose_seqs) / (4 + 2));
}

static const GtkIMContextInfo thai_tis820_info = { 
  "thai_tis820",	   /* ID */
  N_("Thai (TIS820-2538)"),     /* Human readable name */
  "gtk+",		   /* Translation domain */
   GTK_LOCALEDIR,	   /* Dir for bindtextdomain (not strictly needed for "gtk+") */
  ""			   /* Languages for which this module is the default */
};

static const GtkIMContextInfo *info_list[] = {
  &thai_tis820_info
};

void
im_module_init (GTypeModule *module)
{
  thai_tis820_register_type (module);
}

void 
im_module_exit (void)
{
}

void 
im_module_list (const GtkIMContextInfo ***contexts,
		int                      *n_contexts)
{
  *contexts = info_list;
  *n_contexts = G_N_ELEMENTS (info_list);
}

GtkIMContext *
im_module_create (const gchar *context_id)
{
  if (strcmp (context_id, "thai_tis820") == 0)
    return GTK_IM_CONTEXT (g_object_new (type_thai_tis820, NULL));
  else
    return NULL;
}
