Back to index

im-sdk  12.3.91
Defines | Functions | Variables
lookup.c File Reference
#include <stdio.h>
#include <X11/keysym.h>
#include "xiiimp.h"
#include "iiimpIM.h"
#include "guiIM.h"
#include "composeIM.h"
#include "codeinput.h"
#include "lookup.h"

Go to the source code of this file.

Defines

#define MAX_LABEL_SIZE   0x5e
#define LABEL_OFF   0x21
#define XIMIsMaster   1

Functions

static Bool DefillLookup (LocalLookupExt *luext, int start_index, int n_choices)
static Bool FillLookup (XicCommon ic, LocalLookupExt *luext, int start_index, int n_choices)
static Bool setup_local_lookup_ext (XicCommon ic)
void Ximp_Local_Lookup_Create (XicCommon ic)
void Ximp_Local_Lookup_Start (XicCommon ic)
void Ximp_Local_Lookup_Draw (XicCommon ic)
void Ximp_Local_Lookup_Done (XicCommon ic)
static void lookup_commit (XicCommon ic, char *mb, XEvent *ev)
Bool Ximp_Local_Lookup_Button_Filter (XicCommon ic, int index, XEvent *ev)
Bool Ximp_Local_Lookup_Input_Filter (XicCommon ic, char *input, XEvent *ev)
Bool Ximp_Local_Lookup_Action_Filter (XicCommon ic, ActionType action, XEvent *ev)
void Ximp_Local_Lookup_Destroy (XicCommon ic)

Variables

static XIMFeedback no_feedback []

Define Documentation

#define LABEL_OFF   0x21

Definition at line 52 of file lookup.c.

#define MAX_LABEL_SIZE   0x5e

Definition at line 51 of file lookup.c.

#define XIMIsMaster   1

Definition at line 188 of file lookup.c.


Function Documentation

static Bool DefillLookup ( LocalLookupExt luext,
int  start_index,
int  n_choices 
) [static]

Definition at line 59 of file lookup.c.

                                                                    {
  XIMText *p;
  XIMChoiceObject2 *LUTable = (XIMChoiceObject2*)luext->LUTable;
  int i;
  if (!LUTable) return True;

  p = LUTable->label;
  if (!p) return True;
  for (i = 0; p < &LUTable->label[n_choices]; p++, i++) {
    if (p->string.multi_byte) {
      Xfree(p->string.multi_byte);
      p->string.multi_byte = NULL;
    } else
      break;
  }
  if (LUTable->label) {
    Xfree(LUTable->label);
    LUTable->label = 0;
  }
  p = LUTable->value;
  if (!p) return True;
  for (i = 0; p < &LUTable->value[n_choices]; p++, i++) {
    if (p->string.multi_byte) {
      Xfree(p->string.multi_byte);
      p->string.multi_byte = NULL;
    } else
      break;
  }
  if (LUTable->value) {
    Xfree(LUTable->value);
    LUTable->value = 0;
  }
  return True;
}

Here is the caller graph for this function:

static Bool FillLookup ( XicCommon  ic,
LocalLookupExt luext,
int  start_index,
int  n_choices 
) [static]

Definition at line 95 of file lookup.c.

                                          {
  XIMChoiceObject2 *LUTable;
  XIMText *p;
  int i;
  wchar_t wstr[2];
  XimCommon im = (XimCommon)ic->core.im;
  size_t mb_len;

  if (!luext->LUTable) {
    LUTable = Xmalloc(sizeof(XIMChoiceObject2));
    memset(LUTable, 0, sizeof(XIMChoiceObject2));
  } else {
    LUTable = (XIMChoiceObject2*)luext->LUTable;
  }
  if (!LUTable) return False;

  LUTable->label_decoration = BRACKET_DECORATION;

  LUTable->label = Xmalloc(sizeof(XIMText) * n_choices);
  LUTable->value = Xmalloc(sizeof(XIMText) * n_choices);

  if (!LUTable->label || !LUTable->value) {
    /* something is wrong */
    return False;
  }
  memset(LUTable->label, 0, sizeof(XIMText) * n_choices);
  memset(LUTable->value, 0, sizeof(XIMText) * n_choices);

  p = LUTable->label;
  for (i = 0; p < &LUTable->label[n_choices]; p++, i++) {
    p->length = 1;
    p->feedback = no_feedback;
    p->encoding_is_wchar = False;

    wstr[0] = (wchar_t)(i + LABEL_OFF);
    wstr[1] = (wchar_t)0;

    mb_len = XLC_PUBLIC(im->core.lcd, mb_cur_max);
    p->string.multi_byte = Xmalloc(mb_len + 1);
    if (p->string.multi_byte) {
      if ((mb_len = IIimpWcstoMbs(im, wstr, 1,
                              p->string.multi_byte, mb_len, NULL)) < 0) {
       return False;
      }
      p->string.multi_byte[mb_len] = 0;
    } else {
      goto error;
    }
  }
  p = LUTable->value;
  for (i = 0; p < &LUTable->value[n_choices]; p++, i++) {
    p->length = 1;
    p->feedback = no_feedback;
    p->encoding_is_wchar = False;

    wstr[0] = (wchar_t)(start_index + i);
    wstr[1] = (wchar_t)0;

    mb_len = XLC_PUBLIC(im->core.lcd, mb_cur_max);
    p->string.multi_byte = Xmalloc(mb_len + 1);
    if (p->string.multi_byte) {
      if ((mb_len = IIimpWcstoMbs(im, wstr, 1,
                              p->string.multi_byte, mb_len, NULL)) < 0) {
       return False;
      }
      p->string.multi_byte[mb_len] = 0;
    } else {
      goto error;
    }
  }
  luext->LUTable = (XPointer)LUTable;
  return True;
 error:
  /* memory clean up */
  DefillLookup(luext, start_index, n_choices);
  return False;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void lookup_commit ( XicCommon  ic,
char *  mb,
XEvent *  ev 
) [static]

Definition at line 316 of file lookup.c.

                                                  {
  Display *display = ic->core.im->core.display;
  size_t len = strlen(mb);
  XimCommon im = (XimCommon)ic->core.im;
  Bool useUnicode;

  if (!display) {
    return;
  }

  useUnicode = (XIM_USE_UNICODE(im) &&
              NULL != ic->commit_string_callback.callback);
  /* private XIC extension */
  if (useUnicode) {
    XIMCallback *cb = &ic->commit_string_callback;
    XIMUnicodeText cbtext;
    size_t len_utf16 = 256; /* enough */
    char buffer[256];
    memset(&cbtext, 0, sizeof(XIMUnicodeText));
    cbtext.string.multi_byte = buffer;
    cbtext.length = len_utf16;
    IMConvertFromUTF8ToUTF16(mb, len,
                          (char**)&cbtext.string.utf16_char,
                          &len_utf16);
    cbtext.length -= len_utf16;
    cbtext.length /= sizeof(unsigned short);
    (*cb->callback)((XIM)ic, cb->client_data, (XPointer)&cbtext);
  } else {
    if (ic->local_icpart->composed != (DefTree *)NULL ) {
      if (ic->local_icpart->composed->mb != NULL )
       Xfree(ic->local_icpart->composed->mb);
      ic->local_icpart->composed->mb = (char *)NULL;
      Xfree(ic->local_icpart->composed);
      ic->local_icpart->composed = (DefTree *)NULL;
    }
    if ((ic->local_icpart->composed =
        (DefTree *)Xmalloc(sizeof(DefTree))) == NULL)
      return;
    memset(ic->local_icpart->composed, 0, sizeof(DefTree));

    if ((ic->local_icpart->composed->mb = (char *)
        Xmalloc((len + 1) * sizeof(char))) == (char *)NULL) {
      return;
    }
    strncpy(ic->local_icpart->composed->mb, mb, len);
    ic->local_icpart->composed->mb[len] = 0;
    ic->local_icpart->composed->keysym_return = NoSymbol;
    /* return back to client KeyPressEvent keycode == 0 */
    ev->type = KeyPress;
    ev->xkey.keycode = XIM_COMPOSE_KEYCODE;
    ev->xkey.window = ic->core.focus_window;
    XPutBackEvent(display, ev);
  }

  Ximp_Local_Preedit_Done(ic);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Bool setup_local_lookup_ext ( XicCommon  ic) [static]

Definition at line 175 of file lookup.c.

                                     {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);

  if (hook) return False;

  hook = (LocalLookupExt *)Xmalloc(sizeof(LocalLookupExt));
  if (!hook) return False;

  memset(hook, 0, sizeof(LocalLookupExt));
  ic->local_icpart->lookup_ext = hook;
  return True;
}

Here is the caller graph for this function:

Bool Ximp_Local_Lookup_Action_Filter ( XicCommon  ic,
ActionType  action,
XEvent *  ev 
)

Definition at line 410 of file lookup.c.

                                        {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
  int startindex, endindex;

  if (!hook) return False;
  switch (action) {
  case TopPage:
    /* top page */
    startindex = hook->begin_range;
    if (hook->startindex == startindex) {
      /* already at top */
      return False;
    }
    hook->startindex = startindex;
    Ximp_Local_Lookup_Draw(ic);
    break;
  case LastPage:
    /* last page */
    endindex = hook->end_range == -1 ? 0xffff : hook->end_range;
    if (hook->startindex + hook->choice_per_window - 1 == endindex) {
      /* already at last */
      return False;
    }
    startindex = endindex - hook->choice_per_window + 1;
    hook->startindex = startindex;
    Ximp_Local_Lookup_Draw(ic);
    break;
  case NextPage:
    /* next page */
    endindex = hook->end_range == -1 ? 0xffff : hook->end_range;
    if (hook->startindex + hook->choice_per_window - 1 == endindex) {
      /* already at last */
      return False;
    }
    startindex = hook->startindex + hook->choice_per_window;
    if (startindex + hook->choice_per_window > endindex) {
      startindex = endindex - hook->choice_per_window + 1;
    }
    hook->startindex = startindex;
    Ximp_Local_Lookup_Draw(ic);
    break;
  case PrevPage:
    /* prev page */
    startindex = hook->begin_range;
    if (hook->startindex == startindex) {
      /* already at top */
      return False;
    }
    startindex = hook->startindex - hook->choice_per_window;
    if (startindex < hook->begin_range) {
      startindex = hook->begin_range;
    }
    hook->startindex = startindex;
    Ximp_Local_Lookup_Draw(ic);
    break;
  case NextCand:
    /* move focus to next cand */
    if (hook->currentindex == hook->choice_per_window - 1) {
      /* move to top */
      hook->currentindex = 0;
    } else {
      hook->currentindex++;
    }
    Ximp_Local_Lookup_Draw(ic);
    break;
  case PrevCand:
    /* move focus to prev cand */
    if (hook->currentindex == 0) {
      /* move to last */
      hook->currentindex = hook->choice_per_window - 1;
    } else {
      hook->currentindex--;
    }
    Ximp_Local_Lookup_Draw(ic);
    break;
  case UpCand:
    /* move focus to up cand */
    hook->currentindex -= hook->ncolumns;
    if (hook->currentindex < 0) {
      hook->currentindex += hook->choice_per_window;
    }
    Ximp_Local_Lookup_Draw(ic);
    break;
  case DownCand:
    /* move focus to down cand */
    hook->currentindex += hook->ncolumns;
    if (hook->currentindex >= hook->choice_per_window) {
      hook->currentindex -= hook->choice_per_window;
    }
    Ximp_Local_Lookup_Draw(ic);
    break;
  case SelectCand:
    {
      /* select cand at currentindex */
      XIMText *p;
      XIMChoiceObject2 *LUTable;
      LUTable = (XIMChoiceObject2*)hook->LUTable;
      p = &LUTable->value[hook->currentindex];
      lookup_commit(ic, p->string.multi_byte, ev);
    }
    break;
  default:
    break;
  }
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool Ximp_Local_Lookup_Button_Filter ( XicCommon  ic,
int  index,
XEvent *  ev 
)

Definition at line 376 of file lookup.c.

                                                   {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
  XIMChoiceObject2 *LUTable;
  XIMText *p;

  if (!hook) return False;
  LUTable = (XIMChoiceObject2*)hook->LUTable;
  p = &LUTable->value[index];
  lookup_commit(ic, p->string.multi_byte, ev);
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 192 of file lookup.c.

                                       {
  setup_local_lookup_ext(ic);
  return;
}

Here is the call graph for this function:

Definition at line 519 of file lookup.c.

                                        {
  LocalLookupExt *hook = (LocalLookupExt *)(ic->local_icpart->lookup_ext);

  if (!hook) return;

  if (hook->LUTable) {
    DefillLookup(hook, hook->startindex, hook->n_choices);
    Xfree(hook->LUTable);
  }
  Xfree(hook);
  ic->local_icpart->lookup_ext = 0;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 307 of file lookup.c.

                                     {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
  if (!hook) return;
  DefillLookup(hook, hook->startindex, hook->n_choices);
  XIC_GUI(ic, change_lookup)((XIC)ic, LOOKUP_DONE, NULL);
  hook->mapped = LOOKUP_UNMAPPED;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 232 of file lookup.c.

                                     {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
  XIMLookupDrawCallbackStruct2 cbdata;
  XIMText title_text;
  char stitle[80];
  size_t tlen;
  int startindex, endindex;

  if (!hook) {
    Ximp_Local_Lookup_Start(ic);
    hook = (LocalLookupExt *)(ic->local_icpart->lookup_ext);
    if (!hook) return;
  }
  DefillLookup(hook, hook->startindex, hook->n_choices);

  startindex = hook->startindex;

  endindex = startindex + ((hook->end_range == -1) ? 
                        hook->choice_per_window : hook->end_range);

  if (endindex < startindex) return;

  if (0xffff0000 & endindex) {
    endindex = 0x0000ffff;
  }

  memset(&cbdata, 0, sizeof(XIMLookupDrawCallbackStruct2));
  cbdata.n_choices =
    ((endindex - startindex) + 1 > hook->choice_per_window) ?
    hook->choice_per_window : (endindex - startindex) + 1;
  hook->n_choices = cbdata.n_choices;
  cbdata.first_index = 0;
  cbdata.current_index = hook->currentindex;
  cbdata.last_index = cbdata.n_choices - 1;

  if (!FillLookup(ic, hook, startindex, cbdata.n_choices)) return;

  cbdata.choices = (XIMChoiceObject2*)hook->LUTable;

  if (hook->crange != -1) {
    sprintf(stitle, "%s:  0x%04x to 0x%04x",
           hook->range[hook->crange].RangeName+3, startindex, 
           (startindex + (cbdata.n_choices - 1)));
  } else {
    sprintf(stitle, "UNICODE Lookup:  0x%04x to 0x%04x",
           startindex, (startindex +(cbdata.n_choices - 1)));
  }
  tlen = strlen(stitle);

  cbdata.title = &title_text;
  memset((char *)cbdata.title, 0, sizeof(XIMText));
  cbdata.title->length = tlen;
  cbdata.title->feedback = (XIMFeedback*)Xmalloc(sizeof(XIMFeedback) * tlen);
  if (cbdata.title->feedback) {
    XIMFeedback *p;
    for (p = cbdata.title->feedback; p < &cbdata.title->feedback[tlen]; p++) {
      *p = 0;
    }
  } else {
    return;
  }

  cbdata.title->encoding_is_wchar = False;
  cbdata.title->string.multi_byte = stitle;

  XIC_GUI(ic, change_lookup)((XIC)ic, LOOKUP_DRAW, (XPointer)&cbdata);
  hook->mapped = LOOKUP_MAPPED;

  if (cbdata.title->feedback) {
    Xfree(cbdata.title->feedback);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool Ximp_Local_Lookup_Input_Filter ( XicCommon  ic,
char *  input,
XEvent *  ev 
)

Definition at line 390 of file lookup.c.

                                                                      {
  LocalLookupExt *hook = (LocalLookupExt *)(ic->local_icpart->lookup_ext);
  int i;
  XIMChoiceObject2 *LUTable;
  XIMText *p;
  LUTable = (XIMChoiceObject2*)hook->LUTable;
  if (!LUTable) return False;
  p = LUTable->label;
  if (!p) return False;
  /* if given input matches to a label, commit it */
  for (i = 0; p < &LUTable->label[hook->n_choices]; p++, i++) {
    if (!strcmp(p->string.multi_byte, input)) {
      Ximp_Local_Lookup_Button_Filter(ic, i, ev);
      return True;          /* filtered */
    }
  }
  return False;                    /* not filtered */
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 198 of file lookup.c.

                                      {
  LocalLookupExt *hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
  LocalIMState *state = (LocalIMState *)(ic->local_icpart->imstate);
  XIMLookupStartCallbackStruct2 cbdata;

  if (!hook) {
    if (!setup_local_lookup_ext(ic))
      return;
    hook = (LocalLookupExt*)(ic->local_icpart->lookup_ext);
    if (!hook) return;
  }

  memset(&cbdata, 0, sizeof(XIMLookupStartCallbackStruct2));
  cbdata.which_is_master = XIMIsMaster;
  if (state->attr && state->type == LookupState) {
    cbdata.nrows = state->attr->_attr_u.LUstruct.num_of_rows;
    cbdata.ncolumns = state->attr->_attr_u.LUstruct.num_of_cols;
    cbdata.choice_per_window = state->attr->_attr_u.LUstruct.num_of_cands;
  } else {
    cbdata.nrows = 6;
    cbdata.ncolumns = 16;
    cbdata.choice_per_window = 80;
  }
  hook->choice_per_window = cbdata.choice_per_window; /* for drawing */
  hook->nrows = cbdata.nrows; /* for drawing */
  hook->ncolumns = cbdata.ncolumns; /* for drawing */
  cbdata.who_owns_label = XIMOwnsLabel;

  XIC_GUI(ic, change_lookup)((XIC)ic, LOOKUP_START,
                          (XPointer)&cbdata);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

XIMFeedback no_feedback[] [static]
Initial value:
 {
  0, 0
}

Definition at line 54 of file lookup.c.