Back to index

im-sdk  12.3.91
unicode_block.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003 Sun Microsystems Inc.
00003  *
00004  * This is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  *
00019  * Authors: Karl Park <karl.park@sun.com>
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <gtk/gtk.h>
00027 #include "unicode_block.h"
00028 
00029 enum {
00030   COLUMN_BLOCK_NAME,
00031   COLUMN_BLOCK_BEGIN,
00032   COLUMN_BLOCK_END,
00033   COLUMN_COUNT};
00034 
00035 static void unicodelookup_init (UnicodeLookup *obj);
00036 static GtkWidget *make_unicode_block_selector ();
00037 static GtkWidget *make_unicode_chartable ();
00038 static void unicode_block_changed (GtkTreeSelection *, gpointer );
00039 static void set_active_char_event_handler (GtkWidget *, gunichar, UnicodeLookup *);
00040 
00041 GType
00042 unicodelookup_get_type (void)
00043 {
00044   static GType unicodelookup_type = 0;
00045   if (!unicodelookup_type){
00046     static const GTypeInfo unicodelookup_info = {
00047       sizeof (UnicodeLookupClass),
00048       NULL, /* base init */
00049       NULL, /* base finalize */
00050       (GClassInitFunc) NULL, /* class init */
00051       NULL, /* class finalize */
00052       NULL, /* class data */
00053       sizeof (UnicodeLookup),
00054       0,
00055       (GInstanceInitFunc) unicodelookup_init, /* obj init */
00056       NULL /* value table */
00057     };
00058     unicodelookup_type =
00059       g_type_register_static (GTK_TYPE_HPANED, "unicodelookup",
00060                            &unicodelookup_info, 0);
00061   }
00062   return unicodelookup_type;
00063 }
00064 
00065 static void
00066 unicodelookup_init (UnicodeLookup *obj)
00067 {
00068   obj->block_selector = make_unicode_block_selector (obj);
00069   obj->char_table =  make_unicode_chartable ();
00070 
00071   g_signal_connect (G_OBJECT (obj->char_table),
00072                   "set_active_char",
00073                   G_CALLBACK (set_active_char_event_handler), obj);
00074 
00075   gtk_paned_pack1 (GTK_PANED (obj), obj->block_selector, FALSE, TRUE);
00076   gtk_paned_pack2 (GTK_PANED (obj), obj->char_table, TRUE, TRUE);
00077   
00078   gtk_widget_show (obj->block_selector);
00079   gtk_widget_show (obj->char_table);
00080 }
00081 
00082 
00083 static GtkWidget *
00084 make_unicode_block_selector (UnicodeLookup *obj)
00085 {
00086   GtkWidget *tv;
00087   GtkTreeStore *tv_model;
00088   GtkTreeIter iter;
00089   GtkCellRenderer *cell;
00090   GtkTreeViewColumn *column;
00091   
00092   tv_model = gtk_tree_store_new (
00093                              COLUMN_COUNT, G_TYPE_STRING,
00094                              G_TYPE_UINT, G_TYPE_UINT);
00095   gtk_tree_store_append (tv_model, &iter, NULL);
00096   gtk_tree_store_set (tv_model, &iter,
00097                     COLUMN_BLOCK_NAME, "--ga--",
00098                     COLUMN_BLOCK_BEGIN, 0xac00,
00099                     COLUMN_BLOCK_END, 0xb097, -1);
00100   gtk_tree_store_append (tv_model, &iter, NULL);
00101   gtk_tree_store_set (tv_model, &iter,
00102                       COLUMN_BLOCK_NAME, "--na--",
00103                       COLUMN_BLOCK_BEGIN, 0xb098,
00104                       COLUMN_BLOCK_END, 0xb2e3, -1);
00105   tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tv_model));
00106   obj->tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
00107   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tv), FALSE);
00108   cell = gtk_cell_renderer_text_new ();
00109   column =
00110     gtk_tree_view_column_new_with_attributes (NULL, cell,
00111                                          "text", COLUMN_BLOCK_NAME, NULL);
00112   gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
00113   gtk_widget_show_all (tv);
00114 
00115   obj->block_selection_changed_handler_id =
00116     g_signal_connect (
00117              G_OBJECT (obj->tree_selection), "changed",
00118                     G_CALLBACK (unicode_block_changed), obj);
00119 
00120        
00121   return tv;
00122 }
00123 static void
00124 set_active_char_event_handler (GtkWidget *widget,
00125                             gunichar uc,
00126                             UnicodeLookup *obj)
00127 {
00128   g_print ("set_active_char_event_handler called\n");
00129 }
00130 
00131 
00132 static GtkWidget *
00133 make_unicode_chartable ()
00134 {
00135   GtkWidget *char_table;
00136   
00137   char_table = unicharinfo_new ();
00138   gtk_widget_show (char_table);
00139 
00140   return char_table;
00141 }
00142 
00143 GtkWidget *
00144 unicodelookup_new (void)
00145 {
00146   return GTK_WIDGET (g_object_new (unicodelookup_get_type (), NULL));
00147 }
00148 
00149 static void
00150 unicode_block_changed (GtkTreeSelection *selection, gpointer data)
00151 {
00152   GtkTreeModel *model;
00153   GtkTreeIter iter;
00154   gchar *buffer;
00155   gint i_page;
00156   GtkWidget *page;
00157   UnicodeLookup *obj = UNICODELOOKUP(data);
00158   
00159   if (gtk_tree_selection_get_selected (selection, &model, &iter)){
00160     gtk_tree_model_get (model, &iter, COLUMN_BLOCK_NAME, &buffer, -1);
00161 
00162     g_printf (buffer);
00163   }
00164 }
00165 
00166 #ifdef TEST_RUN
00167 int
00168 main (int argc, char *argv[])
00169 {
00170   GtkWidget *main_window;
00171   GtkWidget *paned_widget;
00172   GtkWidget *hangul_block_selector;
00173   GtkWidget *text_entry2;
00174 
00175   gtk_init (&argc, &argv);
00176 
00177   main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00178   paned_widget = gtk_hpaned_new ();
00179   gtk_container_add (GTK_CONTAINER (main_window), paned_widget);
00180   gtk_widget_show (paned_widget);
00181   
00182   hangul_block_selector = make_unicode_block_selector ();
00183   gtk_paned_add1 (GTK_PANED (paned_widget), hangul_block_selector);
00184   gtk_widget_show (hangul_block_selector);
00185   
00186   text_entry2 = gtk_entry_new ();
00187   gtk_paned_add2 (GTK_PANED (paned_widget), text_entry2);
00188   gtk_widget_show (text_entry2);
00189 
00190   gtk_widget_show (main_window);
00191   gtk_main ();
00192   return 0;
00193   
00194   
00195 }
00196 
00197 #endif