Back to index

im-sdk  12.3.91
le_session.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "le_info.h"
00004 #include "le_session.h"
00005 #include "le_desktop.h"
00006 #include "wtt_isc.h"
00007 #include "encode.h"
00008 
00009 LeDesktopContextRec *le_session_get_desktop_context(iml_session_t * s);
00010 LeSessionContextRec *le_session_get_session_context(iml_session_t * s);
00011 
00012 LeResult le_session_set_focus_out(iml_session_t * s);
00013 LeResult le_session_set_focus_in(iml_session_t * s);
00014 
00015 extern LeInfoRec *le_info;
00016 
00017 /*****************************************
00018       LeSessionContextRec
00019 *****************************************/
00020 LeSessionContextRec *le_session_context_new()
00021 {
00022     LeSessionContextRec *le_session_context = NULL;
00023 
00024     le_session_context =
00025        (LeSessionContextRec *) calloc(1, sizeof(LeSessionContextRec));
00026     if (le_session_context == NULL)
00027        return (NULL);
00028 
00029     le_session_context->current_conversion_status = CONVERSION_OFF;
00030     le_session_context->current_input_mode_id = WTT_ISC0;
00031     le_session_context->current_keyboard_id = 0;
00032 
00033     return (le_session_context);
00034 }
00035 
00036 LeResult le_session_context_destroy(LeSessionContextRec *
00037                                 le_session_context)
00038 {
00039     if (le_session_context == NULL)
00040        return (LE_FAIL);
00041 
00042     free((char *) le_session_context);
00043 
00044     return (LE_OK);
00045 }
00046 
00047 LeResult le_session_context_print(LeSessionContextRec * le_session_context)
00048 {
00049     if (le_session_context == NULL)
00050        return (LE_FAIL);
00051 
00052     return (LE_OK);
00053 }
00054 
00055 /*****************************************
00056       LE Session for iml_session_t
00057 *****************************************/
00058 LeSessionContextRec *le_session_create(iml_session_t * s)
00059 {
00060     LeDesktopContextRec *le_desktop_context = NULL;
00061     LeSessionContextRec *le_session_context = NULL;
00062     int default_input_mode_id;
00063     int default_keyboard_id;
00064     int default_conversion_status;
00065 
00066     le_session_context = (LeSessionContextRec *) le_session_context_new();
00067     if (le_session_context == NULL)
00068        return (NULL);
00069 
00070     le_desktop_context =
00071        (LeDesktopContextRec *) le_session_get_desktop_context(s);
00072     default_input_mode_id =
00073        le_desktop_context_get_default_input_mode_id(le_desktop_context);
00074     default_keyboard_id =
00075        le_desktop_context_get_default_keyboard_id(le_desktop_context);
00076     default_conversion_status =
00077        le_desktop_context_get_default_conversion_status
00078        (le_desktop_context);
00079 
00080     le_session_context->current_input_mode_id = default_input_mode_id;
00081     le_session_context->current_keyboard_id = default_keyboard_id;
00082     le_session_context->current_conversion_status =
00083        default_conversion_status;
00084 
00085     le_session_context->s = s;
00086 
00087     s->specific_data = (void *) le_session_context;
00088 
00089     return (le_session_context);
00090 }
00091 
00092 LeResult le_session_destroy(iml_session_t * s)
00093 {
00094     DEBUG_printf("le_session_destroy: s: 0x%x\n", s);
00095 
00096     LeSessionContextRec *le_session_context =
00097        le_session_get_session_context(s);
00098 
00099     if (le_session_context != NULL) {
00100        le_session_context_destroy(le_session_context);
00101     }
00102 
00103     return (LE_OK);
00104 }
00105 
00106 LeResult le_session_set_focus_out(iml_session_t * s)
00107 {
00108 }
00109 
00110 LeResult le_session_set_focus_in(iml_session_t * s)
00111 {
00112     LeSessionContextRec *le_session_context = NULL;
00113     ConversionStatus conversion_status;
00114 
00115     le_session_context = le_session_get_session_context(s);
00116     if (le_session_context == NULL)
00117        return (LE_FAIL);
00118 
00119     conversion_status = le_session_context->current_conversion_status;
00120     DEBUG_printf("le_session_set_focus_in: %d\n", conversion_status);
00121     if (conversion_status == CONVERSION_OFF) {
00122        le_status_draw(s, CONVERSION_OFF);
00123     } else {
00124        le_status_draw(s, CONVERSION_ON);
00125     }
00126 
00127     return (LE_OK);
00128 }
00129 
00130 IMText *le_session_reset(iml_session_t * s)
00131 {
00132     return ((IMText *) NULL);
00133 }
00134 
00135 /*****************************************
00136       LE Session Functions for iml_session_t
00137 *****************************************/
00138 LeDesktopContextRec *le_session_get_desktop_context(iml_session_t * s)
00139 {
00140     return ((LeDesktopContextRec *) s->desktop->specific_data);
00141 }
00142 
00143 LeSessionContextRec *le_session_get_session_context(iml_session_t * s)
00144 {
00145     return (LeSessionContextRec *) s->specific_data;
00146 }
00147 
00148 ConversionStatus le_session_get_conversion_status(iml_session_t * s)
00149 {
00150     LeSessionContextRec *le_session_context = NULL;
00151 
00152     le_session_context = le_session_get_session_context(s);
00153     if (le_session_context == NULL)
00154        return (CONVERSION_OFF);
00155 
00156     return (le_session_context->current_conversion_status);
00157 }
00158 
00159 LeResult le_session_set_conversion_status(iml_session_t * s,
00160                                      ConversionStatus
00161                                      conversion_status)
00162 {
00163     LeSessionContextRec *le_session_context = NULL;
00164 
00165     le_session_context = le_session_get_session_context(s);
00166     if (le_session_context == NULL)
00167        return (LE_FAIL);
00168 
00169     if (conversion_status == CONVERSION_OFF) {
00170        le_status_draw(s, CONVERSION_OFF);
00171        le_iml_conversion_off(s);
00172     } else {
00173        le_iml_conversion_on(s);
00174        le_status_draw(s, CONVERSION_ON);
00175     }
00176 
00177     le_session_context->current_conversion_status = conversion_status;
00178 
00179     return (LE_OK);
00180 }
00181 
00182 LeResult le_session_toggle_conversion_status(iml_session_t * s)
00183 {
00184     LeSessionContextRec *le_session_context = NULL;
00185     ConversionStatus conversion_status;
00186     LeResult le_result;
00187 
00188     le_session_context = le_session_get_session_context(s);
00189     if (le_session_context == NULL)
00190        return (LE_FAIL);
00191 
00192     conversion_status = le_session_context->current_conversion_status;
00193     DEBUG_printf("le_session_toggle_conversion_status: %d\n",
00194                ~conversion_status);
00195     if (conversion_status == CONVERSION_OFF) {
00196        le_result = le_session_set_conversion_status(s, CONVERSION_ON);
00197     } else {
00198        le_result = le_session_set_conversion_status(s, CONVERSION_OFF);
00199     }
00200 
00201     return (le_result);
00202 }
00203 
00204 LeResult le_session_set_as_desktop_current_session(iml_session_t * s)
00205 {
00206     LeDesktopContextRec *le_desktop_context = NULL;
00207 
00208     le_desktop_context =
00209        (LeDesktopContextRec *) le_session_get_desktop_context(s);
00210     le_desktop_context_set_current_session(le_desktop_context, s);
00211 
00212     return (LE_OK);
00213 }
00214 
00215 int le_session_get_isc_mode(iml_session_t * s)
00216 {
00217     LeDesktopContextRec *le_desktop_context =
00218        (LeDesktopContextRec *) le_session_get_desktop_context(s);
00219     LeSessionContextRec *le_session_context =
00220        le_session_get_session_context(s);
00221     int current_input_mode_id;
00222 
00223     current_input_mode_id = le_session_context->current_input_mode_id;
00224 
00225     if (current_input_mode_id < 0
00226        || current_input_mode_id >= WTT_ISC_MODES_NUM)
00227        current_input_mode_id = le_desktop_context->default_input_mode_id;
00228 
00229     return (current_input_mode_id);
00230 }
00231 
00232 int le_session_save_isc_mode(iml_session_t * s, int current_input_mode_id)
00233 {
00234     LeSessionContextRec *le_session_context =
00235        le_session_get_session_context(s);
00236 
00237     if (current_input_mode_id < 0
00238        || current_input_mode_id >= WTT_ISC_MODES_NUM)
00239        current_input_mode_id = WTT_ISC0;
00240 
00241     le_session_context->current_input_mode_id = current_input_mode_id;
00242 }
00243 
00244 int le_session_get_keyboard_mode(iml_session_t * s)
00245 {
00246     LeDesktopContextRec *le_desktop_context =
00247        (LeDesktopContextRec *) le_session_get_desktop_context(s);
00248     LeSessionContextRec *le_session_context =
00249        le_session_get_session_context(s);
00250     int current_keyboard_id;
00251 
00252     current_keyboard_id = le_session_context->current_keyboard_id;
00253 
00254     if (current_keyboard_id < 0
00255        || current_keyboard_id >= le_info->keymap_list->nNum_Keymaps)
00256        current_keyboard_id = le_desktop_context->default_keyboard_id;
00257 
00258     return (current_keyboard_id);
00259 }
00260 
00261 int le_session_save_keyboard_mode(iml_session_t * s,
00262                               int current_keyboard_id)
00263 {
00264     LeDesktopContextRec *le_desktop_context =
00265        (LeDesktopContextRec *) le_session_get_desktop_context(s);
00266     LeSessionContextRec *le_session_context =
00267        le_session_get_session_context(s);
00268 
00269     if (current_keyboard_id < 0
00270        || current_keyboard_id >= le_info->keymap_list->nNum_Keymaps)
00271        current_keyboard_id = le_desktop_context->default_keyboard_id;
00272 
00273     le_session_context->current_keyboard_id = current_keyboard_id;
00274 }
00275 
00276 int le_session_get_previous_char(iml_session_t * s)
00277 {
00278     LeSessionContextRec *le_session_context =
00279        le_session_get_session_context(s);
00280     return (le_session_context->char_previous);
00281 }
00282 
00283 int le_session_save_previous_char(iml_session_t * s, char ch)
00284 {
00285     LeSessionContextRec *le_session_context =
00286        le_session_get_session_context(s);
00287     le_session_context->char_previous = ch;
00288 }