Back to index

im-sdk  12.3.91
SunIMConf2.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <sys/types.h>
00045 
00046 #include "SunIM.h"
00047 
00048 static Bool if_sunimdefault_OpenIF(iml_if_t *);
00049 static Bool if_sunimdefault_CloseIF(iml_if_t *);
00050 static Bool if_sunimdefault_GetIFValues(iml_if_t *, IMArgList, int);
00051 static Bool if_sunimdefault_SetIFValues(iml_if_t *, IMArgList, int);
00052 static Bool if_sunimdefault_OpenDesktop(iml_desktop_t *, IMArgList, int);
00053 static Bool if_sunimdefault_CloseDesktop(iml_desktop_t *);
00054 static Bool if_sunimdefault_CreateSC(iml_session_t *, IMArgList, int);
00055 static Bool if_sunimdefault_DestroySC(iml_session_t *);
00056 static Bool if_sunimdefault_GetSCValues(iml_session_t *, IMArgList, int);
00057 static Bool if_sunimdefault_SetSCValues(iml_session_t *, IMArgList, int);
00058 static IMText *if_sunimdefault_ResetSC(iml_session_t *);
00059 static void if_sunimdefault_SetSCFocus(iml_session_t *);
00060 static void if_sunimdefault_UnsetSCFocus(iml_session_t *);
00061 static void if_sunimdefault_SendEvent(iml_session_t *, IMInputEvent * ev);
00062 
00063 if_methods_t sunim_default_methods = {
00064     if_sunimdefault_OpenIF,
00065     if_sunimdefault_CloseIF,
00066     if_sunimdefault_GetIFValues,
00067     if_sunimdefault_SetIFValues,
00068     if_sunimdefault_OpenDesktop,
00069     if_sunimdefault_CloseDesktop,
00070     if_sunimdefault_CreateSC,
00071     if_sunimdefault_DestroySC,
00072     if_sunimdefault_GetSCValues,
00073     if_sunimdefault_SetSCValues,
00074     if_sunimdefault_ResetSC,
00075     if_sunimdefault_SetSCFocus,
00076     if_sunimdefault_UnsetSCFocus,
00077     if_sunimdefault_SendEvent
00078 };
00079 
00080 typedef struct {
00081     int status_start;
00082 }   PerSessionStruct;
00083 
00084 static UTFCHAR status_string[] =
00085 {'[', 'N', 'o', ' ', 'I', 'M', ' ', 'c', 'o', 'n', 'n', 'e', 'c', 't', 'e', 'd', ']'};
00086 
00087 #define       STATUS_LEN    17
00088 
00089 static IMText *status_text = 0;
00090 
00091 static void
00092 turnoff_forwarding_event(
00093     iml_session_t * s
00094 )
00095 {
00096     iml_inst *lp;
00097     lp = s->If->m->iml_make_end_conversion_inst(s);
00098     s->If->m->iml_execute(s, &lp);
00099 }
00100 
00101 static void
00102 turnon_forwarding_event(
00103     iml_session_t * s
00104 )
00105 {
00106     iml_inst *lp;
00107     lp = s->If->m->iml_make_start_conversion_inst(s);
00108     s->If->m->iml_execute(s, &lp);
00109 }
00110 
00111 static void
00112 error_status_draw(
00113     iml_session_t * s
00114 )
00115 {
00116     PerSessionStruct *p = (PerSessionStruct *) s->specific_data;
00117     iml_inst *lp;
00118     if (!p) {
00119         return;
00120     }
00121     if (p->status_start == 0) {
00122         lp = s->If->m->iml_make_status_start_inst(s);
00123         s->If->m->iml_execute(s, &lp);
00124     }
00125     if (status_text) {
00126         lp = s->If->m->iml_make_status_draw_inst(s, status_text);
00127         s->If->m->iml_execute(s, &lp);
00128     }
00129 }
00130 
00131 static Bool
00132 if_sunimdefault_OpenIF(
00133     iml_if_t * If
00134 )
00135 {
00136     int i;
00137     status_text = (IMText *) calloc(1, sizeof(IMText));
00138     status_text->text.utf_chars = (UTFCHAR *) & status_string;
00139     status_text->char_length = STATUS_LEN;
00140     status_text->feedback = (IMFeedbackList *) calloc(1, sizeof(IMFeedback) * STATUS_LEN);
00141     for (i=0;i<STATUS_LEN;i++) {
00142         IMFeedbackList *list=&status_text->feedback[i];
00143         IMFeedback *feedback;
00144         list->count_feedbacks=1;
00145         list->feedbacks = (IMFeedback *) calloc(1, sizeof(IMFeedback) * status_text->feedback->count_feedbacks);
00146         feedback=&list->feedbacks[0];
00147         feedback->type=IM_DECORATION_FEEDBACK;
00148         feedback->value=0;
00149     }
00150     return True;
00151 }
00152 
00153 static Bool
00154 if_sunimdefault_CloseIF(
00155     iml_if_t * If
00156 )
00157 {
00158     free(status_text);
00159     return True;
00160 }
00161 
00162 static Bool
00163 if_sunimdefault_GetIFValues(
00164     iml_if_t * If,
00165     IMArgList args,
00166     int num_args
00167 )
00168 {
00169     return True;
00170 }
00171 
00172 static Bool
00173 if_sunimdefault_SetIFValues(
00174     iml_if_t * If,
00175     IMArgList args,
00176     int num_args
00177 )
00178 {
00179     return True;
00180 }
00181 
00182 static Bool
00183 if_sunimdefault_OpenDesktop(
00184     iml_desktop_t * desktop,
00185     IMArgList args,
00186     int num_args
00187 )
00188 {
00189     return True;
00190 }
00191 
00192 static Bool
00193 if_sunimdefault_CloseDesktop(
00194     iml_desktop_t * desktop
00195 )
00196 {
00197     return True;
00198 }
00199 
00200 static Bool
00201 if_sunimdefault_CreateSC(
00202     iml_session_t *s,
00203     IMArgList args,
00204     int num_args
00205 )
00206 {
00207     PerSessionStruct *p = (PerSessionStruct*)calloc(1, sizeof(PerSessionStruct));
00208     p->status_start = 0;
00209     s->specific_data = (void*) p;
00210     return True;
00211 }
00212 
00213 static Bool
00214 if_sunimdefault_DestroySC(
00215     iml_session_t * s
00216 )
00217 {
00218     PerSessionStruct *p = (PerSessionStruct *) s->specific_data;
00219     if (p) {
00220         free(p);
00221     }
00222     return True;
00223 }
00224 
00225 static Bool
00226 if_sunimdefault_GetSCValues(
00227     iml_session_t * s,
00228     IMArgList args,
00229     int num_args
00230 )
00231 {
00232     return True;
00233 }
00234 
00235 static Bool
00236 if_sunimdefault_SetSCValues(
00237     iml_session_t * s,
00238     IMArgList args,
00239     int num_args
00240 )
00241 {
00242     int i;
00243     IMArg *p=args;
00244     for (i = 0; i < num_args; i++, p++) {
00245         switch (p->id) {
00246             case SC_TRIGGER_ON_NOTIFY:
00247                 turnon_forwarding_event(s);
00248             }
00249     }
00250     return True;
00251 }
00252 
00253 static IMText *
00254 if_sunimdefault_ResetSC(
00255     iml_session_t * s
00256 )
00257 {
00258     turnoff_forwarding_event(s);
00259     return (IMText *) NULL;
00260 }
00261 
00262 static void
00263 if_sunimdefault_SetSCFocus(
00264     iml_session_t * s
00265 )
00266 {
00267     error_status_draw(s);
00268     turnoff_forwarding_event(s);
00269 }
00270 
00271 static void
00272 if_sunimdefault_UnsetSCFocus(
00273     iml_session_t * s
00274 )
00275 {
00276     error_status_draw(s);
00277     turnoff_forwarding_event(s);
00278 }
00279 
00280 static void
00281 if_sunimdefault_SendEvent(
00282     iml_session_t * s,
00283     IMInputEvent * ev
00284 )
00285 {
00286     iml_inst *lp;
00287     IMKeyListEvent *keylist;
00288     
00289     if (ev->type == IM_EventKeyList) {
00290         keylist = (IMKeyListEvent *) ev;
00291         lp = s->If->m->iml_make_keypress_inst(s, (IMKeyEventStruct *) keylist->keylist);
00292         s->If->m->iml_execute(s, &lp);
00293     }
00294     
00295     turnoff_forwarding_event(s);
00296 }