Back to index

im-sdk  12.3.91
guiIMClbk.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 "xiiimp.h"
00043 #include "iiimpIM.h"
00044 #include "guiIM.h"
00045 #include "status.h"
00046 #include "XimpIm.h"
00047 #include <langinfo.h>
00048 
00049 int
00050 CallPreeditStartCallback(XicCommon ic, XPointer p) {
00051   XIMCallback *cb;
00052   int max_len = -1;
00053 
00054   cb = &ic->core.preedit_attr.start_callback;
00055   if (cb->callback &&
00056       ic->core.input_style & XIMPreeditCallbacks) {
00057     max_len = (*(int(*)())cb->callback)(ic, cb->client_data, NULL);
00058     ic->ximp_icpart->cbstatus |= XIMPCBPREEDITACTIVE ;
00059   } else {
00060     XIC_GUI(ic, change_preedit)((XIC)ic, PREEDIT_START, NULL);
00061   }
00062   return max_len;
00063 }
00064 
00065 Bool
00066 CallPreeditDrawCallback(XicCommon ic, XIMPreeditDrawCallbackStruct *p,
00067                      IMFeedbackList *feedback_list) {
00068   XIMCallback *cb;
00069   cb = &ic->core.preedit_attr.draw_callback;
00070   if (cb->callback &&
00071       ic->core.input_style & XIMPreeditCallbacks) {
00072     (*cb->callback)((XIC)ic, cb->client_data, (XPointer)p);
00073   } else {
00074     XIMDrawTextStruct preedit_draw;
00075     preedit_draw.call_data = (XPointer)p;
00076     preedit_draw.feedback_list = feedback_list;
00077     XIC_GUI(ic, change_preedit)((XIC)ic, PREEDIT_DRAW,
00078                             (XPointer)&preedit_draw);
00079   }
00080   return True;
00081 }
00082 
00083 Bool
00084 CallPreeditCaretCallback(XicCommon ic, XPointer p) {
00085   XIMCallback *cb;
00086   XIMPreeditCaretCallbackStruct *call_data = (XIMPreeditCaretCallbackStruct*)p;
00087   cb = &ic->core.preedit_attr.caret_callback;
00088   if (cb->callback &&
00089       ic->core.input_style & XIMPreeditCallbacks) {
00090     (*cb->callback)((XIC)ic, cb->client_data, (XPointer)call_data);
00091   } else {
00092     XIC_GUI(ic, change_preedit)((XIC)ic, PREEDIT_CARET, (XPointer)p);
00093   }
00094   return True;
00095 }
00096 
00097 Bool
00098 CallPreeditDoneCallback(XicCommon ic, XPointer p) {
00099   XIMCallback *cb;
00100   cb = &ic->core.preedit_attr.done_callback;
00101   if (cb->callback &&
00102       ic->core.input_style & XIMPreeditCallbacks) {
00103     (*cb->callback)((XIC)ic, cb->client_data, NULL);
00104     ic->ximp_icpart->cbstatus &= ~XIMPCBPREEDITACTIVE ;
00105   } else {
00106     XIC_GUI(ic, change_preedit)((XIC)ic, PREEDIT_DONE, NULL);
00107   }
00108   return True;
00109 }
00110 
00111 Bool
00112 CallStatusStartCallback(XicCommon ic, XPointer p) {
00113   XIMCallback *cb;
00114   cb = &ic->core.status_attr.start_callback;
00115   if (cb->callback && ic->core.input_style & XIMStatusCallbacks &&
00116       IsIMStatusAttached()) {
00117     (*cb->callback)((XIC)ic, cb->client_data, NULL);
00118     ic->ximp_icpart->cbstatus |= XIMPCBSTATUSACTIVE ;
00119   } else {
00120     XIC_GUI(ic, change_status)((XIC)ic, STATUS_START, (XPointer)p);
00121   }
00122   return True;
00123 }
00124 
00125 static char*
00126 locale_to_utf8 (char *loc)
00127 {
00128   char *encoding = nl_langinfo(CODESET);
00129 
00130   if (loc == NULL)
00131     return strdup (" ");
00132 
00133   if (!strcmp(encoding, "UTF-8"))
00134     return strdup(loc);
00135   else {
00136     size_t utf8_len = 64;   /* enough */
00137     char buffer[64], *pbuffer;
00138     memset(&buffer, 0, 64);
00139     pbuffer = buffer;
00140     if (IMConvertToUTF8(loc, strlen(loc),
00141                      (char**)&pbuffer, &utf8_len) != -1)
00142       buffer[64 - utf8_len] = 0;
00143     else
00144       strcpy (buffer, " ");
00145     return strdup(buffer);
00146   }
00147 }
00148 
00149 Bool
00150 CallStatusDrawCallback(XicCommon ic, XIMStatusDrawCallbackStruct *call_data,
00151                      IMFeedbackList *feedback_list) {
00152   XIMCallback *cb;
00153   cb = &ic->core.status_attr.draw_callback;
00154 
00155   if (!IsIMStatusAttached()) {
00156     if (call_data->type == XIMTextType &&
00157        !call_data->data.text->encoding_is_wchar) {
00158       char *utf8 = locale_to_utf8 (call_data->data.text->string.multi_byte);
00159       ic_switcher_set_status_text (ic, utf8);
00160       free (utf8);
00161     } else {
00162       ic_switcher_set_status_text (ic, " ");
00163     }
00164   }
00165   if (cb->callback && ic->core.input_style & XIMStatusCallbacks) {
00166     if (!IsIMStatusAttached())
00167          call_data->data.text = NULL;
00168     (*cb->callback)((XIC)ic, cb->client_data, (XPointer)call_data);
00169   } else {
00170     XIMDrawTextStruct status_draw;
00171 
00172     if (XIM_IS_SWITCH(ic->core.im)) {
00173       /*
00174        fix for 4276042:
00175        status strings is not [English/European] when iiim IM is off
00176       */
00177       if (!IsConversionMode(ic)) {
00178        Ximp_Local_Status_Reset(ic);
00179        return True;
00180       }
00181     }
00182     status_draw.call_data = (XPointer)call_data->data.text;
00183     status_draw.feedback_list = feedback_list;
00184     XIC_GUI(ic, change_status)((XIC)ic, STATUS_DRAW,
00185                             (XPointer)&status_draw);
00186   }
00187 
00188   /* move preedit window */
00189   if (ic->core.input_style & XIMPreeditNothing) {
00190     XIC_GUI(ic, change_preedit)((XIC)ic, PREEDIT_WIN, NULL);
00191   }
00192   return True;
00193 }
00194 
00195 Bool
00196 CallStatusDoneCallback(XicCommon ic, XPointer p) {
00197   XIMCallback *cb;
00198   cb = &ic->core.status_attr.done_callback;
00199   if (cb->callback && ic->core.input_style & XIMStatusCallbacks &&
00200       IsIMStatusAttached()) {
00201     (*cb->callback)((XIC)ic, cb->client_data, NULL);
00202     ic->ximp_icpart->cbstatus &= ~XIMPCBSTATUSACTIVE ;
00203   } else {
00204     XIC_GUI(ic, change_status)((XIC)ic, STATUS_DONE, NULL);
00205   }
00206   return True;
00207 }