ergtk-im-context-erkeyb.c

Go to the documentation of this file.
00001 /*
00002  * File Name: ergtk-im-context-erkeyb.c
00003  */
00004 
00005 /*
00006  * This file is part of erkeyb.
00007  *
00008  * erkeyb is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * erkeyb is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2009 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 // system includes
00032 #include <stdio.h>
00033 #include <string.h>
00034 // gtk
00035 #include <gtk/gtk.h>
00036 #include <gtk/gtkimmodule.h>
00037 #include <gtk/gtkimcontextsimple.h>
00038 
00039 // local include files, between " "
00040 #include "config.h"
00041 #include "ergtk-im-context-erkeyb.h"
00042 #include "erkeyb-client.h"
00043 
00044 // logging
00045 #include "logging.h"
00046 
00047 //----------------------------------------------------------------------------
00048 // MACROS and definitions
00049 //----------------------------------------------------------------------------
00050 
00051 //----------------------------------------------------------------------------
00052 // Type Declarations
00053 //----------------------------------------------------------------------------
00054 
00055 //----------------------------------------------------------------------------
00056 // Static Variables
00057 //----------------------------------------------------------------------------
00058 
00059 static GObjectClass *parent_class;
00060 GType ergtk_type_im_context_erkeyb = 0;
00061 
00062 //----------------------------------------------------------------------------
00063 // Functions Prototypes  (im-context)
00064 //----------------------------------------------------------------------------
00065 
00066 static void ergtk_im_context_erkeyb_class_init (ErGtkIMContextErkeybClass *klass);
00067 static void ergtk_im_context_erkeyb_init (ErGtkIMContextErkeyb *self);
00068 
00069 static void ergtk_im_context_erkeyb_set_client_window(GtkIMContext* context, GdkWindow* window );
00070 static void ergtk_im_context_erkeyb_focus_in (GtkIMContext *context);
00071 static void ergtk_im_context_erkeyb_focus_out (GtkIMContext *context);
00072 static void ergtk_im_context_erkeyb_finalize( GObject* obj) ;
00073 
00074 //============================================================================
00075 // Functions Implementation
00076 //============================================================================
00077 
00078 void ergtk_im_context_erkeyb_register_type (GTypeModule *type_module)
00079 { 
00080     DBG_ENTRY;
00081 
00082     if (! ergtk_type_im_context_erkeyb )
00083     {
00084         static const GTypeInfo im_context_erkeyb_info =
00085         { 
00086             sizeof (ErGtkIMContextErkeybClass),
00087             (GBaseInitFunc) NULL,
00088             (GBaseFinalizeFunc) NULL,
00089             (GClassInitFunc) ergtk_im_context_erkeyb_class_init,
00090             NULL,           /* class_finalize */
00091             NULL,           /* class_data */
00092             sizeof (ErGtkIMContextErkeyb),
00093             0,
00094             (GInstanceInitFunc) ergtk_im_context_erkeyb_init,
00095             NULL
00096         };
00097 
00098         ergtk_type_im_context_erkeyb =
00099             g_type_module_register_type (type_module,
00100                     GTK_TYPE_IM_CONTEXT_SIMPLE,
00101                     "ErGtkIMContextErkeyb",
00102                     &im_context_erkeyb_info, 0);
00103     }
00104     else {
00105         DBG("ErGtkIMContextErkeyb was already registered. This is not an error.\n");
00106     }
00107     DBG_EXIT;
00108 }
00109 
00110 static void  ergtk_im_context_erkeyb_class_init (ErGtkIMContextErkeybClass *klass)
00111 {
00112     DBG_ENTRY;
00113     GtkIMContextClass*  context_class = GTK_IM_CONTEXT_CLASS (klass);
00114     GObjectClass*       object_class = G_OBJECT_CLASS(klass);
00115 
00116     parent_class = g_type_class_peek_parent (klass);
00117 
00118     context_class->set_client_window = ergtk_im_context_erkeyb_set_client_window;
00119     context_class->focus_in = ergtk_im_context_erkeyb_focus_in;
00120     context_class->focus_out = ergtk_im_context_erkeyb_focus_out;
00121     object_class->finalize = ergtk_im_context_erkeyb_finalize;
00122     DBG_EXIT;
00123 }
00124 
00125 static void ergtk_im_context_erkeyb_init (ErGtkIMContextErkeyb *self)
00126 {
00127     DBG_ENTRY;
00128 
00129     self->finalizing = FALSE ;  
00130    
00131     if ( 0 != erkeyb_client_init() )
00132     {
00133         ERR("Could not initialize keyboard!\n");
00134     }
00135 
00136     DBG_EXIT;
00137 }
00138 
00139 static void ergtk_im_context_erkeyb_finalize( GObject* obj) 
00140 {
00141     DBG_ENTRY;
00142 
00143     ErGtkIMContextErkeyb* context_erkeyb = ERGTK_IM_CONTEXT_ERKEYB(obj);
00144     context_erkeyb->finalizing = TRUE;
00145 
00146     erkeyb_client_term();
00147 
00148     G_OBJECT_CLASS(parent_class)->finalize(obj);
00149 
00150     DBG_EXIT;
00151 }
00152 
00153 GtkIMContext* ergtk_im_context_erkeyb_new (void)
00154 {
00155     DBG_ENTRY;
00156 
00157     ErGtkIMContextErkeyb* result = NULL ;
00158     result = ERGTK_IM_CONTEXT_ERKEYB( g_object_new(ERGTK_TYPE_IM_CONTEXT_ERKEYB, NULL ));
00159 
00160     DBG_EXIT;
00161     return GTK_IM_CONTEXT( result) ; 
00162 }
00163 
00164 static void ergtk_im_context_erkeyb_focus_in (GtkIMContext *context)
00165 {
00166     DBG_ENTRY;
00167 
00168     erkeyb_client_show();
00169 
00170     if (GTK_IM_CONTEXT_CLASS (parent_class)->focus_in)
00171         GTK_IM_CONTEXT_CLASS (parent_class)->focus_in (context);
00172     DBG_EXIT;
00173 }
00174 
00175 static void ergtk_im_context_erkeyb_focus_out (GtkIMContext *context)
00176 {   DBG_ENTRY;
00177 
00178     erkeyb_client_hide();
00179 
00180     if (GTK_IM_CONTEXT_CLASS (parent_class)->focus_out)
00181         GTK_IM_CONTEXT_CLASS (parent_class)->focus_out (context);
00182     DBG_EXIT;
00183 }
00184 
00185 static void ergtk_im_context_erkeyb_set_client_window(GtkIMContext* context, GdkWindow* window )
00186 {
00187     DBG_ENTRY;
00188 
00189     if ( window == NULL )
00190     {
00191         erkeyb_client_hide();
00192     }
00193 
00194     if (GTK_IM_CONTEXT_CLASS (parent_class)->set_client_window)
00195         GTK_IM_CONTEXT_CLASS (parent_class)->set_client_window (context, window);
00196 
00197     DBG_EXIT;
00198 }
Generated by  doxygen 1.6.2-20100208