⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hzinput.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 3 页
字号:
//// hzinput.c: The GB2312 IME window.//// Orignally by KANG Xiaoning, some code from cce by He Rui.//// Copyright (C) 1998-1999 Rui He (herui@cs.duke.edu)// Copyright (C) 1999, Kang Xiaoning.// Copyright (C) 2000, Zheng Xiang.//// Modified by WEI Yongming and GONG Xiaorui.// Copyright (C) 1999, Wei Yongming.// Copyright (C) 1999, Gong Xiaorui.//// Current maintainer: Wei Yongming//// Create date: 1999.04/***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*///// Used abbreviations://  ime: input method//  punc: punctuate mark//// Modify records:////  Who             When        Where           For What//-----------------------------------------------------------------------------//  WEI Yongming    1999/06/14  Tsinghua        Message dispatching//  GONG Xiaorui    1999/07/01  HongShiFang     Soft keyboard//  WEI Yongming    1999/07/17  Tsinghua        Add some local functions//  WEI Yongming    1999/08/24  Tsinghua        Remove soft keyboard.//  WEI Yongming    1999/08/29  Tsinghua        Handle some special keys.//  Wei Yongming    1999/09/01  Tsinghua        Translat punc marks.//  Wei Yongming    1999/09/01  Tsinghua        Translat punc marks.//  Wei Yongming    2000/11/06  BluePoint       Merge pinyin module by Zheng Xiang.//// TODO://#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <pthread.h>#include <semaphore.h> #include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "hzinput.h"#include "pinyin.h"#ifndef lintstatic char fileid[] = "$Id: hzinput.c,v 1.23 2000/11/23 06:26:38 ymwei Exp $";#endif/************ private functions *******************/static BOOL hz_input_init(void);static void hz_input_done(void);static void unload_input_table(int i);static BOOL hz_filter(unsigned char key, LPARAM lParam);static int toggle_input_method(void);static void toggle_half_full(void);static void set_active_input_method(int);static void refresh_input_method_area(HDC hDC);static void DispSelection(HDC hDC);static void FindMatchKey(void);static void FillMatchChars(int j);static void FillAssociateChars(int index);static void FindAssociateKey(int index);static hz_input_table* IntCode_Init(void);static void IntCode_FindMatchKey(void);static void IntCode_FillMatchChars(int index);static void intcode_hz_filter(unsigned char key,LPARAM lParam);/*************************************************************************** *                           variable defines                              * ***************************************************************************/#define VERSION_STRING    "Chinese Input"static char ime_tab_path [MAX_PATH + 1];static unsigned char	fullchar[]	 =	" !”#$%&’()*+,-./0123456789:;<=>?"	"@ABCDEFGHIJKLMNOPQRSTUVWXYZ〔\〕^□"	"‘abcdefghijklmnopqrstuvwxyz{|}~  ";#define CPUNCTYPE_1TO1      0#define CPUNCTYPE_1TO2      1#define CPUNCTYPE_CYCLE     2#define CTRLBTN_WIDTH       16#define CTRLBTN_HEIGHT      16typedef struct PuncMark{    unsigned char   epunc;    int             type;    int             currone;          // only for cycle    unsigned char*  cpunc;}PUNCMARK;static PUNCMARK puncmark[] = {    {'`', 0, 0, "·"},    {'~', 0, 0, "~"},    {'!', 0, 0, "!"},    {'@', 0, 0, "℃"},    {'#', 0, 0, "#"},    {'$', 0, 0, "¥"},    {'%', 0, 0, "%"},    {'^', CPUNCTYPE_1TO2, 0, "……"},    {'&', 0, 0, "§"},    {'*', 0, 0, "×"},    {'_', CPUNCTYPE_1TO2, 0, "——"},    {'(', CPUNCTYPE_CYCLE, 0, "()"},    {')', CPUNCTYPE_CYCLE, 0, "〔〕"},    {'{', CPUNCTYPE_CYCLE, 0, "《》"},    {'}', CPUNCTYPE_CYCLE, 0, "〈〉"},    {'[', CPUNCTYPE_CYCLE, 0, "〖〗"},    {']', CPUNCTYPE_CYCLE, 0, "【】"},    {'\\', 0, 0, "÷"},    {'|', 0, 0, "※"},    {';', 0, 0, ";"},    {':', 0, 0, ":"},    {'\'', CPUNCTYPE_CYCLE, 0, "‘’"},    {'\"', CPUNCTYPE_CYCLE, 0, "“”"},    {',', 0, 0, ","},    {'.', 0, 0, "。"},    {'<', CPUNCTYPE_CYCLE, 0, "「」"},    {'>', CPUNCTYPE_CYCLE, 0, "『』"},    {'?', 0, 0, "?"},    {'/', 0, 0, "、"}};static int IsOpened;        /* 1 for opened, 0 for closed */static int IsEnabled;       /* 1 for enabled, 0 for disabled */static int IsHanziInput;    /* 0 for ascii, 1 for hanzi input */static int IsFullChar;      /* 0 for half char, 1 for full char */static int IsFullPunc;      /* 0 for half punctuate marks, 1 for full marks */ static int CurIME;static int nIMENr;          /* effetive IME method number */static HWND sg_hTargetWnd = HWND_DESKTOP; // target window of ime.static hz_input_table *input_table[NR_INPUTMETHOD],*cur_table = NULL;static char seltab[16][MAX_PHRASE_LENGTH];static int CurSelNum=0;   /* Current Total Selection Number */static unsigned long InpKey[MAX_INPUT_LENGTH],save_InpKey[MAX_INPUT_LENGTH];   /* Input key buffer */static int InputCount,InputMatch, StartKey,EndKey;static int save_StartKey,save_EndKey, save_MultiPageMode,            save_NextPageIndex, save_CurrentPageIndex;static int NextPageIndex,CurrentPageIndex,MultiPageMode;/* When enter MultiPageMode:   StartKey .... CurrentPageIndex .... NextPageIndex .... EndKey */static unsigned long val1, val2,key1,key2;static int IsAssociateMode;static int CharIndex[15];   // starting index of matched char/phrasesstatic BITMAP sg_bmpIME;	// the bmp of the IME control buttonstatic int UseAssociateMode = 0;/* 6 bit a key mask */static unsigned long mask[]={  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,   0x3F000000, 0x3FFC0000, 0x3FFFF000, 0x3FFFFFC0, 0x3FFFFFFF, 0x3FFFFFFF,  0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF};/*************************************************************************** *                          some local functions                           * ***************************************************************************/static hz_input_table* load_input_method(char *filename){  int  nread;  FILE *fd;  char phrase_filename[100],assoc_filename[100];  hz_input_table *table;    table = malloc(sizeof(hz_input_table));  if (table == NULL) return NULL;  fd = fopen(filename, "r");  if (fd == NULL) {    free(table);    return NULL;  }  nread = fread(table, sizeof(hz_input_table),1,fd);  if (nread != 1) {        return NULL;  }  if( strcmp(MAGIC_NUMBER, table->magic_number) ) {        return NULL;  }  table->item = (ITEM *)malloc(sizeof(ITEM ) * table->TotalChar);   if ( table->item == NULL ) {        return NULL;  }   fread (table->item, sizeof(ITEM), table->TotalChar, fd);  fclose (fd);   if (table->PhraseNum > 0) {     strcpy( phrase_filename, filename );     strcat( phrase_filename, ".phr" );     strcpy( assoc_filename, filename );     strcat( assoc_filename, ".lx");          table->PhraseFile = fopen( phrase_filename, "r" );     table->AssocFile = fopen( assoc_filename, "r");     if (table->PhraseFile == NULL || table->AssocFile == NULL) {          printf("Load Phrase/Assoc File error!\n");          free(table);          return NULL;     }  }  else {       table->PhraseFile = table->AssocFile = NULL;  }  return table;}static void free_input_method(hz_input_table *table){    free(table->item);    free(table);}static void ClrIn(void){  bzero( InpKey,   sizeof( InpKey   ) );  bzero( seltab, sizeof( seltab ) );  MultiPageMode = NextPageIndex = CurrentPageIndex = 0;  CurSelNum = InputCount = InputMatch = 0;  IsAssociateMode = 0;   /* lian xiang */}static void FindAssociateKey(int index){    FILE *fp = cur_table->AssocFile;    int ofs[2],offset;       if (index < 0xB0A1)     {       StartKey = EndKey = 0;       return;  /* no match */    }         offset = (index / 256 - 0xB0) * 94 + index % 256 - 0xA1;     fseek(fp, offset * sizeof(int), SEEK_SET);    fread(ofs,sizeof(int),2,fp);    StartKey = 72 * 94 + 1 + ofs[0];    EndKey = 72 * 94 + 1 + ofs[1];}static void load_phrase( int phrno, char *tt ){  FILE *fp = cur_table->PhraseFile;  int ofs[2], len;  fseek( fp, ( phrno + 1 ) << 2, SEEK_SET );  fread( ofs, 4, 2, fp );  len = ofs[1] - ofs[0];  if ( len > 128 || len <= 0 ) {     strcpy( tt, "error" );     return;  }  ofs[0] += ( cur_table->PhraseNum + 1 ) << 2;   /* Add the index area length */  fseek( fp, ofs[0], SEEK_SET );  fread( tt, 1, len, fp );  tt[len] = 0;}static void putstr (unsigned char *p ,LPARAM lParam){    int index,len = strlen(p);    writemsg(p, len, lParam, TRUE);    if (InputCount <= InputMatch)  /* All Match */    {        index = (int)p[len-2] * 256 + p[len-1];         ClrIn();        if (UseAssociateMode)        {             FindAssociateKey(index);              CurrentPageIndex = StartKey;             MultiPageMode = 0;             FillAssociateChars(StartKey);               if (CurSelNum > 0)             {                IsAssociateMode = 1;             }        }    }    else    {      int nCount = InputCount - InputMatch,nMatch = InputMatch,i;      MultiPageMode = NextPageIndex = CurrentPageIndex = 0;      InputCount = InputMatch = 0;      for(i = 0; i < nCount; i++)        save_InpKey[i] = InpKey[nMatch+i];      bzero(InpKey, sizeof(InpKey));      for(i = 1; i <= nCount; i++)  /* feed the additional keys */      {         InpKey[InputCount] = save_InpKey[InputCount++];         if (InputCount <= InputMatch+1)         {             FindMatchKey();             MultiPageMode = 0;             CurrentPageIndex = StartKey;             FillMatchChars(StartKey);         }       }      if (InputMatch == 0)    /* left key has no match, delete */      {         ClrIn();          return;      }    }}static int epunc2cpunc (unsigned char epunc, unsigned char* cpunc){    int i;        for (i = 0; i < 29; i++) {        if (puncmark [i].epunc == epunc) {            switch (puncmark [i].type)            {                case CPUNCTYPE_1TO1:                    memcpy (cpunc, puncmark [i].cpunc, 2);                    return 2;                case CPUNCTYPE_1TO2:                    memcpy (cpunc, puncmark [i].cpunc, 4);                    return 4;                case CPUNCTYPE_CYCLE:                    memcpy (cpunc, puncmark[i].cpunc + puncmark[i].currone, 2);                    if (puncmark[i].currone == 0)                        puncmark[i].currone = 2;                    else                        puncmark[i].currone = 0;                    return 2;                default:                    return 0;            }        }    }    return 0;}/* After add/delete a char, search the matched char/phrase, update the   StartKey/EndKey key,  save the related keys at first, if no match   is found, we may restore its original value*/static void FindMatchKey(void){  save_StartKey = StartKey;  save_EndKey = EndKey;  save_MultiPageMode = MultiPageMode;  save_NextPageIndex = NextPageIndex;  save_CurrentPageIndex = CurrentPageIndex;  val1 = InpKey[4] | (InpKey[3]<<6) | (InpKey[2]<<12) | (InpKey[1]<<18) |         (InpKey[0]<<24);  val2 = InpKey[9] | (InpKey[8]<<6) | (InpKey[7]<<12) | (InpKey[6]<<18) |         (InpKey[5]<<24);  if (InputCount == 1)     StartKey = cur_table->KeyIndex[InpKey[0]];  else     StartKey = CharIndex[InputCount-1];  EndKey = cur_table->KeyIndex[InpKey[0]+1];  for (; StartKey < EndKey; StartKey++)  {      key1 = (cur_table->item[StartKey].key1 & mask[InputCount+5]);      key2 = (cur_table->item[StartKey].key2 & mask[InputCount]);      if (key1 > val1) break;      if (key1 < val1) continue;      if (key2 < val2) continue;      break;  }  CharIndex[InputCount] = StartKey;}/*  Find the matched chars/phrases and fill it into SelTab    The starting checked index is j      The Selection Line 1xxx 2xxx,  80-20=60 60/2=30 chinese chars only    0-9 Selection can contain only 30 chinese chars*/static void FillAssociateChars(int index){    unsigned char str[25];    int PhraseNo, CurLen = 0;       CurSelNum = 0;     while( CurSelNum < cur_table->MaxDupSel && index < EndKey &&              CurLen < MAX_SEL_LENGTH)    {         fseek( cur_table->AssocFile, index << 2, SEEK_SET );         fread( &PhraseNo, sizeof(int), 1, cur_table->AssocFile );         load_phrase( PhraseNo, str );         strcpy(seltab[CurSelNum],str+2);         CurLen += strlen(seltab[CurSelNum++]);         index++;    }    /* check if more than one page */    if ( index < EndKey && CurSelNum == cur_table->MaxDupSel )    {      /* has another matched key, so enter MultiPageMode, has more pages */        NextPageIndex = index;        MultiPageMode = 1;    }    else if (MultiPageMode)    {        NextPageIndex = StartKey; /* rotate selection */    }    else MultiPageMode = 0;}static void FillMatchChars(int j){    int SelNum = 0, CurLen = 0;    //bzero( seltab, sizeof( seltab ) );    while( ( cur_table->item[j].key1 & mask[InputCount+5] ) == val1 &&            ( cur_table->item[j].key2 & mask[InputCount] ) == val2 &&              SelNum < cur_table->MaxDupSel && j < EndKey &&               CurLen < MAX_SEL_LENGTH)    {          if ( cur_table->item[j].ch < 0xA1A1 )              load_phrase( cur_table->item[j].ch, seltab[SelNum] );          else          {              memcpy( &seltab[SelNum], &(cur_table->item[j].ch),2);              seltab[SelNum][2] = '\0';          }          CurLen += strlen(seltab[SelNum++]);          j++;    }        if (SelNum == 0)  /* some match found */    {        StartKey = save_StartKey;        EndKey = save_EndKey;        MultiPageMode = save_MultiPageMode;        NextPageIndex = save_NextPageIndex;        CurrentPageIndex = save_CurrentPageIndex;        return;    /* keep the original selection */    }    CurSelNum = SelNum;    for(SelNum = CurSelNum; SelNum < 16; SelNum++)       seltab[SelNum][0] = '\0';  /* zero out the unused area */    InputMatch = InputCount; /* until now we have some matches */    /* check if more than one page */    if ( j < EndKey && (cur_table->item[j].key1 & mask[InputCount+5]) == val1 &&         ( cur_table->item[j].key2 & mask[InputCount] ) == val2 &&          CurSelNum == cur_table->MaxDupSel )    {      /* has another matched key, so enter MultiPageMode, has more pages */        NextPageIndex = j;        MultiPageMode = 1;    }      else if (MultiPageMode)    {        NextPageIndex = StartKey; /* rotate selection */    }    else MultiPageMode = 0;}/* return value: Has output? */static BOOL hz_filter(unsigned char key, LPARAM lParam){    int inkey = 0,vv;    char *is_sel_key = (char*)0;    if (IsEnabled) {        unsigned char cc [2];        if (IsFullPunc) {            unsigned char cpunc[4];            int len;        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -