include/unihan_im.h

Go to the documentation of this file.
00001 //
00002 // Unihan Input Method
00003 //
00004 // Copyright © 2002-2007 Sun Wah Linux Ltd.
00005 //
00006 //
00007 // This library is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; either version 2.1 of the
00010 // License, or (at your option) any later version.
00011 //
00012 // This library is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // Lesser General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020 // USA
00021 //
00022 // $Id: unihan_im.h 815 2007-08-22 03:16:28Z roger $
00023 //
00024 
00025 #ifndef __UNIHAN_IM_H
00026 #define __UNIHAN_IM_H
00027 
00028 #include <stdlib.h>
00029 #if NEW_PROPERTY
00030 #include "unihan_property.h"
00031 #endif
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 typedef struct _UnihanIM UnihanIM;            
00038 typedef struct _UnihanMethods UnihanMethods;  
00039 typedef struct _UnihanStyleList UnihanStyleList;
00040 typedef struct _UnihanStyle UnihanStyle;
00041 typedef struct _UnihanLookupDraw UnihanLookupDraw;
00042 typedef struct _UnihanLookupStart UnihanLookupStart;
00043 
00044 typedef enum {
00045     UNIHAN_TCSC_NO_CONV = 0,
00046     UNIHAN_TCSC_TO_SIMPLIFIED = 1,
00047     UNIHAN_TCSC_TO_TRADITIONAL = 2,
00048     UNIHAN_TCSC_AUTO_TO_SIMPLIFIED = 3,     
00049     UNIHAN_TCSC_AUTO_TO_TRADITIONAL = 4     
00050 } UnihanTCSCMode;
00051 
00052 typedef enum {
00053     UserName = 1,
00054     HostName = 2,
00055     ProtocolType = 3,
00056     ClientType = 4,
00057     DisplayID = 5,
00058     OSName = 6,
00059     OSVersion = 7,
00060     OSArch = 8
00061 } UnihanClientInfoType;
00062 
00063 typedef enum {
00064     UNIHAN_LOG_LEVEL_ERROR      = 1 << 2,
00065     UNIHAN_LOG_LEVEL_CRITICAL   = 1 << 3,
00066     UNIHAN_LOG_LEVEL_WARNING    = 1 << 4,
00067     UNIHAN_LOG_LEVEL_MESSAGE    = 1 << 5,
00068     UNIHAN_LOG_LEVEL_INFO       = 1 << 6,
00069     UNIHAN_LOG_LEVEL_DEBUG      = 1 << 7
00070 } UnihanLogLevelFlags;
00071 
00075 struct _UnihanMethods {
00076     int (*send_buffer)          (UnihanIM *uim,
00077                                  void *buf,
00078                                  size_t buf_size);
00079 
00089     int (*config_get)           (UnihanIM *uim,
00090                                  char *key,
00091                                  char **value,
00092                                  long *len);
00093 
00102     int (*config_set)           (UnihanIM *uim,
00103                                  char *key,
00104                                  char *value,
00105                                  long len);
00106 
00116     int (*preedit_draw)         (UnihanIM *uim, 
00117                                  char *s, 
00118                                  UnihanStyleList *styles);
00119 
00127     int (*preedit_caret_pos)    (UnihanIM *uim, 
00128                                  int caretPos);
00129 
00142     int (*preedit_change)       (UnihanIM *uim, 
00143                                  char *s, 
00144                                  UnihanStyleList *styles,
00145                                  int pos, 
00146                                  int len, 
00147                                  int caretPos);
00148 
00154     int (*preedit_erase)        (UnihanIM *uim);
00155 
00163     int (*lookup_start)         (UnihanIM *uim,
00164                                  UnihanLookupStart *lustart);
00165 
00173     int (*lookup_draw)          (UnihanIM *uim,
00174                                  UnihanLookupDraw *ludraw);
00175 
00181     int (*lookup_done)          (UnihanIM *uim);
00182 
00190     int (*status_draw)          (UnihanIM *uim, 
00191                                  char *s, 
00192                                  UnihanStyleList *styles);
00193 
00200     int (*commit_string)        (UnihanIM *uim, 
00201                                  char *s);
00202 
00210     int (*locale_get)           (UnihanIM *uim,
00211                                  char **locale);
00212 
00219     int (*tcsc_mode_get)        (UnihanIM *uim,
00220                                  UnihanTCSCMode *tcscMode);
00221 
00230     int (*tcsc_do_conv)         (UnihanIM *uim,
00231                                  UnihanTCSCMode tcscMode,
00232                                  char *orig,
00233                                  char **converted);
00234 
00244     int (*mem_alloc)            (UnihanIM *uim,
00245                                  size_t len,
00246                                  void **mem);
00247 
00252     int (*client_info_get)      (UnihanIM *uim,
00253                                  UnihanClientInfoType type,
00254                                  char **info);
00255 
00261     int (*is_fullwidth)         (UnihanIM *uim);
00262 
00268     int (*is_chinesepunc)       (UnihanIM *uim);
00269 
00275     int (*is_shuangpin)         (UnihanIM *uim);
00276 
00282     int (*beep)                 (UnihanIM *uim);
00283 
00290     int (*match_phrase)         (UnihanIM *uim,
00291                                  char *s);
00292 
00297     void (*log)                 (UnihanIM *uim,
00298                                  UnihanLogLevelFlags log_level,
00299                                  const char *format,
00300                                  ...);
00301 
00302 #if NEW_PROPERTY
00303     int (*properties_register)  (UnihanIM *uim,
00304                                  const UnihanPropertyList *property_list, 
00305                                  char* imid);
00306     int (*properties_update)    (UnihanIM *uim,
00307                                  const UnihanPropertyList *property_list);
00308 #endif
00309 };
00310 
00311 struct _UnihanIM {
00312     void *privateData;  // privateData is just the im-sdk session struct
00313     char *id;           
00314     char *module_id;    
00315     char *host_name;
00316     char *user_name;
00317 
00329     void *imUserData;
00330 
00343     void *desktopUserData;
00344 
00356     void *sessionUserData;
00357 
00358     UnihanMethods *m;   
00359 };
00360 
00361 typedef enum {
00362     SHIFT_MODIFIER = 1,
00363     CTRL_MODIFIER = 2,
00364     META_MODIFIER = 4,
00365     ALT_MODIFIER = 8,
00366     ALT_GRAPH_MODIFIER = 32
00367 } IMKeyModifier;
00368 
00369 typedef enum {
00370     IM_NOTHING = -1,
00371     IM_FOCUS = 1,
00372     IM_KEY = 2,
00373     IM_CONFIG_CHANGE = 3,
00374     IM_SWITCH = 4,
00375     IM_PROPERTY_TOGGLED = 5,
00376     IM_PROPERTY_REGISTER = 6,
00377     IM_USER_TABLE = 7,
00378     IM_LOOKUP_PAGE_TURN = 8,
00379     IM_LOOKUP_SELECT = 9
00380 } IMEventType;
00381 
00382 typedef struct _IMKeyEvent {
00383     IMEventType type;
00384     int keyCode;
00385     int keyChar;
00386     int modifier;
00387 } IMKeyEvent;
00388 
00389 typedef struct _IMFocusEvent {
00390     IMEventType type;
00391     int focused;
00392 } IMFocusEvent;
00393 
00394 typedef struct _IMConfigChangeEvent {
00395     IMEventType type;
00396     char *key;
00397     int value;
00398 } IMConfigChangeEvent;
00399 
00400 typedef struct _IMSwitchEvent {
00401     IMEventType type;
00402     int on;
00403 } IMSwitchEvent;
00404 
00405 typedef struct _IMPropertyToggledEvent {
00406     IMEventType type;
00407     char *key;
00408 } IMPropertyToggledEvent;
00409 
00410 typedef struct _IMPropertyRegisterEvent {
00411     IMEventType type;
00412     char *imid;
00413 } IMPropertyRegisterEvent;
00414 
00415 typedef struct _IMUserTableEvent {
00416     IMEventType type;
00417     void *table;
00418     int numItem;
00419 } IMUserTableEvent;
00420 
00421 typedef struct _IMLookupPageTurn {
00422     IMEventType type;
00423     int direction;
00424 } IMLookupPageTurnEvent;
00425 
00426 typedef struct _IMLookupSelect {
00427     IMEventType type;
00428     int num;
00429 } IMLookupSelectEvent;
00430 
00431 typedef union _IMEvent {
00432     IMEventType type;
00433     IMKeyEvent key;
00434     IMFocusEvent focus;
00435     IMConfigChangeEvent configChange;
00436     IMSwitchEvent switched;
00437     IMPropertyToggledEvent propertyToggled;
00438     IMPropertyRegisterEvent propertyRegister;
00439     IMUserTableEvent table;
00440     IMLookupPageTurnEvent lookupPageTurn;
00441     IMLookupSelectEvent lookupSelect;
00442 } IMEvent;
00443 
00444 typedef struct _IMMethods {
00445     int (*init)(UnihanIM *);
00446     int (*done)(UnihanIM *);
00447     int (*create_session)(UnihanIM *);
00448     int (*destroy_session)(UnihanIM *);
00449     int (*handle_event)(UnihanIM *, IMEvent *);
00450 } IMMethods;
00451 
00452 typedef struct _IMInfo IMInfo;
00453 struct _IMInfo {
00454     char *id;
00455     char *name;
00456     char *version;
00457     void *imUserData;
00458     IMMethods *methodTable;
00459     IMInfo *next;
00460 #if NEW_PROPERTY
00461     UnihanPropertyArgList proplist;
00462     IMConfig *config;
00463 #endif
00464 };
00465 
00466 typedef enum {
00467     UNIHAN_IM_API_VERSION = 1,
00468     UNIHAN_IM_MODULE_ID = 2,
00469     UNIHAN_IM_MODULE_NAME = 3,
00470     UNIHAN_IM_MODULE_VERSION = 4,
00471     UNIHAN_IM_MODULE_IM_LIST = 5
00472 } UnihanIMModuleArgID;
00473 
00474 typedef struct {
00475     UnihanIMModuleArgID id;
00476     void *value;
00477 } UnihanIMModuleArgList;
00478 
00479 struct _UnihanStyleList {
00480     unsigned int numStyles;
00481     UnihanStyle *style;
00482 };
00483 
00484 typedef enum {
00485     UNIHAN_STYLE_DECORATION = 0,
00486     UNIHAN_STYLE_FOREGROUND_RGB = 1,
00487     UNIHAN_STYLE_BACKGROUND_RGB = 2
00488 } UnihanStyleType;
00489 
00490 #define UNIHAN_RGB_COLOR(red,green,blue)  (int)((red<<16) + (green<<8) + blue)
00491 
00492 struct _UnihanStyle {
00493     UnihanStyleType type;
00494     int value;
00495 };
00496 
00497 typedef enum {
00498     UNIHAN_LOOKUP_DIRECTION_RIGHT = 0,
00499     UNIHAN_LOOKUP_DIRECTION_DOWN = 1
00500 } UnihanLookupDirection;
00501 
00502 struct _UnihanLookupStart {
00503     int choicePerWindow;
00504     int numColumns;
00505     int numRows;
00506     UnihanLookupDirection direction;
00507 };
00508 
00509 typedef enum {
00510     UNIHAN_LOOKUP_MODE_NORMAL = 0,
00511     UNIHAN_LOOKUP_MODE_PHRASE = 1
00512 } UnihanLookupMode;
00513 
00514 struct _UnihanLookupDraw {
00515     UnihanLookupMode mode;
00516     int numChoices;
00517     int selected;
00518     int currentChoice;
00519     int totalChoices;
00520     char *title;
00521     char **label;
00522     UnihanStyleList *labelStyles;
00523     char **value;
00524     UnihanStyleList *valueStyles;
00525 };
00526 
00527 typedef struct _SymbolUserTable {
00528     int modifier;
00529     int keyCode;
00530     char *symbol;
00531 } SymbolUserTable;
00532 
00533 typedef struct _WordUserTable {
00534     char *key;
00535     char *word;
00536 } WordUserTable;
00537 
00538 #ifndef TRUE
00539 # define TRUE 1
00540 #endif
00541 
00542 #ifndef FALSE
00543 # define FALSE 0
00544 #endif
00545 
00546 #ifdef __cplusplus
00547 }
00548 #endif
00549 
00550 #endif /* __UNIHAN_IM_H */
00551 
00552 // vi:ts=4:sw=4:nowrap:cin:expandtab

Generated on Fri Sep 7 15:51:41 2007 for unihan-core-le by  doxygen 1.5.2