Back to index

im-sdk  12.3.91
status.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 "guiIM.h"
00044 #include "composeIM.h"
00045 #include "status.h"
00046 #include "iiimpIM.h"
00047 
00048 static Bool
00049 setup_local_status_ext(XicCommon ic)
00050 {
00051   LocalStatusExt *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00052 
00053   if (hook) return (True);
00054 
00055   hook = (LocalStatusExt *)Xmalloc(sizeof(LocalStatusExt));
00056   if(!hook)
00057     return (False);
00058   memset(hook, 0, sizeof(LocalStatusExt));
00059 
00060   ic->local_icpart->status_ext = hook;
00061   return(True);
00062 }
00063 
00064 /* public */
00065 void
00066 Ximp_Local_Status_Create(XicCommon ic) {
00067   setup_local_status_ext(ic);
00068   return;
00069 }
00070 
00071 void
00072 Ximp_Local_Status_Start(XicCommon ic) {
00073   LocalStatusExt *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00074 
00075   if (!hook) {
00076     if (!setup_local_status_ext(ic))
00077       return;
00078     hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00079   }
00080   XIC_GUI(ic, change_status)((XIC)ic, STATUS_START, NULL);
00081 }
00082 
00083 void
00084 Ximp_Local_Status_Draw(XicCommon ic) {
00085   LocalStatusExt *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00086   XIMDrawTextStruct status_draw;
00087 
00088   if (!(ic->ximp_icpart->value_mask & XIMP_CLIENT_WIN) ||
00089       !ic->core.client_window)
00090     return;
00091 
00092   if (!hook) {
00093     Ximp_Local_Status_Start(ic);
00094     hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00095     if (!hook) return;
00096   }
00097   if (hook->text.length == 0) return;
00098 
00099   if (XIM_USE_UNICODE(ic->core.im)) {
00100     XIMText status_text;
00101     size_t native_len = 64; /* enough */
00102     char buffer[64], *pbuffer;
00103     memset(&buffer, 0, 64);
00104     pbuffer = buffer;
00105 
00106     memset(&status_text, 0, sizeof(XIMText)) ;
00107     if (IMConvertFromUTF8(hook->text.string.multi_byte,
00108                        strlen(hook->text.string.multi_byte),
00109                        (char**)&pbuffer, &native_len) != -1) {
00110       status_text.string.multi_byte = buffer;
00111       status_text.length = 64 - native_len;
00112     } else {
00113       status_text.string.multi_byte = hook->text.string.multi_byte;
00114       status_text.length = strlen(hook->text.string.multi_byte);
00115     }
00116     status_draw.call_data = (XPointer)&status_text;
00117     status_draw.feedback_list = 0;
00118     XIC_GUI(ic, change_status)((XIC)ic, STATUS_DRAW, (XPointer)&status_draw);
00119   } else {
00120     status_draw.call_data = (XPointer)&hook->text;
00121     status_draw.feedback_list = 0;
00122     XIC_GUI(ic, change_status)((XIC)ic, STATUS_DRAW, (XPointer)&status_draw);
00123   }
00124   return;
00125 }
00126 
00127 void
00128 Ximp_Local_Status_Window(XicCommon ic) {
00129   XIC_GUI(ic, change_status)((XIC)ic, STATUS_WIN, (XPointer)NULL);
00130   return;
00131 }
00132 
00133 void
00134 Ximp_Local_Status_Done(XicCommon ic) {
00135   /* do nothing */
00136   return;
00137 }
00138 
00139 void
00140 Ximp_Local_Status_Destroy(XicCommon ic) {
00141   LocalStatusExt *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00142 
00143   if (!hook) return;
00144 
00145   Xfree(hook);
00146   ic->local_icpart->status_ext = 0;
00147   return;
00148 }
00149 
00150 void
00151 Ximp_Local_Status_Set(XicCommon ic) {
00152   LocalIMState *imstate = ic->local_icpart->imstate;
00153   LocalStatusExt *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00154   char *state_name;
00155 
00156   if (!hook) {
00157     if (!setup_local_status_ext(ic))
00158       return;
00159     hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00160   }
00161 
00162   state_name = imstate->name;
00163   hook->text.string.multi_byte = state_name;
00164   hook->text.length = strlen(state_name);
00165   hook->text.feedback = 0;
00166   hook->text.encoding_is_wchar = False;
00167   return;
00168 }
00169 
00170 #if 0
00171 static Bool
00172 _Ximp_local_repaint_status(d, w, ev, client_data)
00173     Display *d;
00174     Window w;
00175     XEvent *ev;
00176     XPointer client_data;
00177 {
00178   XicCommon ic = (XicCommon)client_data;
00179   LocalStatusExt  *hook = (LocalStatusExt *)(ic->local_icpart->status_ext);
00180 
00181   if(!hook)
00182     return (True);
00183 
00184   Ximp_Local_Status_Draw(ic);
00185 
00186   return(True);
00187 }
00188 #endif
00189 
00190 void
00191 Ximp_Local_Status_Reset(XicCommon ic) {
00192   Ximp_Local_Status_Set(ic);
00193   Ximp_Local_Status_Draw(ic);
00194   return;
00195 }