Back to index

gcompris  8.2.2
gcompris_im.c
Go to the documentation of this file.
00001 /* gcompris - gcompris_im.c
00002  *
00003  * Time-stamp: <2006/08/21 23:26:19 bruno>
00004  *
00005  * Copyright (C) 2000,2003 Bruno Coudoin
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  */
00021 
00022 #include "gcompris.h"
00023 
00024 static gint im_context_commit_callback (GtkIMContext *imcontext,
00025                                    gchar *arg1,
00026                                    gpointer user_data);
00027 
00028 static gint im_context_preedit_callback (GtkIMContext *imcontext,
00029                                     gpointer user_data);
00030 
00031 static gint window_focus_callback (GtkWidget *widget,
00032                                GdkEventFocus *event,
00033                                gpointer user_data);
00034 
00035 
00036 void
00037 gc_im_init(GtkWidget *window)
00038 {
00039   GcomprisProperties *properties = gc_prop_get ();
00040 
00041 
00042   /* set IMContext */
00043   properties->context = gtk_im_multicontext_new ();
00044 
00045   if(gc_profile_get_current())
00046     {
00047       GHashTable *init_im =  g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
00048       init_im = gc_db_conf_with_table_get (gc_profile_get_current()->profile_id, 
00049                                          -1, 
00050                                          init_im );
00051 
00052       properties->default_context = g_hash_table_lookup ( init_im, "default_im");
00053 
00054       if (properties->default_context)
00055        g_setenv ("GTK_IM_MODULE",
00056                 properties->default_context,
00057                 TRUE);
00058     }
00059 
00060   gtk_im_context_set_client_window (properties->context,
00061                                     window->window);
00062 
00063   g_signal_connect (G_OBJECT (properties->context), "commit",
00064                   G_CALLBACK(im_context_commit_callback), NULL);
00065 
00066   g_signal_connect (G_OBJECT (properties->context), "preedit-changed",
00067                   G_CALLBACK(im_context_preedit_callback), NULL);
00068 
00069   g_signal_connect (GTK_WIDGET (window), "focus-in-event",
00070                   G_CALLBACK(window_focus_callback), NULL);
00071 
00072   g_signal_connect (GTK_WIDGET (window), "focus-out-event",
00073                   G_CALLBACK(window_focus_callback), NULL);
00074  
00075 }
00076 
00077 void
00078 gc_im_reset()
00079 {
00080   GcomprisProperties *properties = gc_prop_get ();
00081   gtk_im_context_reset (properties->context);
00082 }
00083 
00084     
00085 static gint
00086 im_context_commit_callback (GtkIMContext *imcontext,
00087                          gchar *arg1,
00088                          gpointer user_data)
00089 {
00090   if (gc_board_get_current_board_plugin()!=NULL && gc_board_get_current_board_plugin()->key_press)
00091     {
00092       int result = gc_board_get_current_board_plugin()->key_press (0, arg1, NULL);
00093       //      g_free(arg1);
00094       return(result);
00095     }
00096   return FALSE;
00097 }
00098     
00099 static gint
00100 im_context_preedit_callback (GtkIMContext *imcontext,
00101                           gpointer user_data)
00102 {
00103   gchar *preedit_string;
00104   PangoAttrList *attrs;
00105   gint cursor_pos;
00106 
00107   gtk_im_context_get_preedit_string (imcontext,
00108                                  &preedit_string,
00109                                  &attrs,
00110                                  &cursor_pos);
00111 
00112   if (gc_board_get_current_board_plugin()!=NULL && gc_board_get_current_board_plugin()->key_press)
00113     {
00114       int result = gc_board_get_current_board_plugin()->key_press (0, NULL, preedit_string);
00115       g_free(preedit_string);
00116       pango_attr_list_unref (attrs);
00117       return(result);
00118     }
00119   return FALSE;
00120 }
00121 
00122 static gint
00123 window_focus_callback (GtkWidget *widget,
00124                      GdkEventFocus *event,
00125                      gpointer user_data)
00126 {
00127   GcomprisProperties *properties = gc_prop_get ();
00128   if (event->in)
00129     gtk_im_context_focus_in (properties->context);
00130   else
00131     gtk_im_context_focus_out (properties->context);
00132   
00133   return FALSE;
00134 }