xim.c
来自「具有IDE功能的编辑器」· C语言 代码 · 共 609 行 · 第 1/2 页
C
609 行
/* xim.c - XIM handlers, for multiple locale input methods. Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. *//* #define DEBUG *//* #define DEBUG_ENTRY */#include <config.h>#include <stdio.h>#include <my_string.h>#include <stdlib.h>#include <stdarg.h>#include <X11/Intrinsic.h>#include "lkeysym.h"#include "stringtools.h"#include "app_glob.c"#include "coolwidget.h"#include "coollocal.h"#include "font.h"#include "mad.h"/* A lot of this stuff is hatched from rxvt-2.6.1: *//*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* * $Id: command.c,v 1.85.2.23 1999/08/12 16:32:39 mason Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (C) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> * - original version * Copyright (C) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> * - extensive modifications * Copyright (C) 1995 Garrett D'Amore <garrett@netcom.com> * - vt100 printing * Copyright (C) 1995 Steven Hirsch <hirsch@emba.uvm.edu> * - X11 mouse report mode and support for * DEC "private mode" save/restore functions. * Copyright (C) 1995 Jakub Jelinek <jj@gnu.ai.mit.edu> * - key-related changes to handle Shift+function * keys properly. * Copyright (C) 1997 MJ Olesen <olesen@me.queensu.ca> * - extensive modifications * Copyright (C) 1997 Raul Garcia Garcia <rgg@tid.es> * - modification and cleanups for Solaris 2.x * and Linux 1.2.x * Copyright (C) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> * Copyright (C) 1998 Geoff Wing <gcw@pobox.com> * Copyright (C) 1998 Alfredo K. Kojima <kojima@windowmaker.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *----------------------------------------------------------------------*/#ifndef HAVE_XPOINTERtypedef char *XPointer;#endif#ifdef USE_XIMstatic void xim_print_error (char *s,...){ char k[1024]; va_list ap; va_start (ap, s); vsprintf (k, s, ap); fprintf (stderr, "%s: %s\n", CAppName, k); va_end (ap);}int option_use_xim = 1;static void IMInstantiateCallback (Display * display, XPointer client_data, XPointer call_data);void init_xlocale (void){ char *xim_locale = NULL; xim_locale = setlocale (LC_CTYPE, 0); CPushFont ("editor", 0); if (!xim_locale) { xim_print_error ("Setting locale failed."); } else if (!current_font->font_set) { xim_print_error ("Font set not loaded - cannot create input method."); } else {#ifdef GREEK_SUPPORT greek_init ();#endif if (option_use_xim) XRegisterIMInstantiateCallback (CDisplay, NULL, NULL, NULL, IMInstantiateCallback, NULL); } CPopFont ();}void setPosition (CWidget * child, CWidget * w, XPoint * pos){#ifdef dont_forget_this /* FIXME */ XWindowAttributes xwa; XGetWindowAttributes (CDisplay, TermWin.vt, &xwa); pos->x = Col2Pixel (screen.cur.col) + xwa.x; pos->y = Height2Pixel ((screen.cur.row + 1)) + xwa.y;#else pos->x = w->width / 2; pos->y = w->height / 2;#endif}static void IMSendSpot (Window window){ XPoint spot; XVaNestedList preedit_attr; XIMStyle input_style; CWidget *child, *w; if (!window) return; if (!(child = CWidgetOfWindow (window))) return; if (child->mainid) { w = CWidgetOfWindow (child->mainid); } else { w = child; } if (!w->input_context) return; XGetICValues (w->input_context, XNInputStyle, &input_style, NULL); if (!(input_style & XIMPreeditPosition)) return; setPosition (child, w, &spot); preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); XSetICValues (w->input_context, XNPreeditAttributes, preedit_attr, NULL); XFree (preedit_attr);}KeySym key_sym_xlat (XEvent * ev, char *x_lat){ static int len = 0; static KeySym keysym = 0; static XComposeStatus compose = {NULL, 0}; static unsigned char kbuf[512] = ""; static Time time = 0; static int valid_keysym = 1; Status status_return = 0;#ifdef GREEK_SUPPORT static short greek_mode = 0;#endif if (x_lat) *x_lat = '\0'; if (ev->type != KeyPress && ev->type != KeyRelease) return 0;/* we mustn't call this twice with the same event */ if (time == ev->xkey.time) goto no_repeat_call; time = ev->xkey.time; keysym = 0; len = 0; if (ev->type == KeyRelease) { len = XLookupString (&ev->xkey, (char *) kbuf, sizeof (kbuf), &keysym, 0); if (!len && (keysym >= 0x0100) && (keysym < 0x0800)) { len = 1; kbuf[0] = (keysym & 0xFF); } } else if (CIC) { CWidget *w; IMSendSpot (ev->xkey.window); w = CWidgetOfWindow (ev->xkey.window); if (!w) return 0; if (w->mainid) w = CWidgetOfWindow (w->mainid); if (w->input_context != CIC) { printf ("w->input_context != CIC --> Huh?\n"); /* FIXME:this seems to actually happen */ return 0; } len = XmbLookupString (CIC, &ev->xkey, (char *) kbuf, sizeof (kbuf), &keysym, &status_return); valid_keysym = ((status_return == XLookupKeySym) || (status_return == XLookupBoth)); if (valid_keysym) {#ifdef GREEK_SUPPORT if (keysym == XK_Mode_switch) { greek_mode = !greek_mode; if (greek_mode) { xterm_seq (XTerm_title, (greek_getmode () == GREEK_ELOT928 ? "[Greek: iso]" : "[Greek: ibm]")); greek_reset (); } else xterm_seq (XTerm_title, APL_NAME "-" VERSION); return; }#endif } } else {#if 0 lookup_string:#endif keysym = 0; len = XLookupString (&ev->xkey, (char *) kbuf, sizeof (kbuf), &keysym, &compose); if (!len && (keysym >= 0x0100) && (keysym < 0x0800)) { len = 1; kbuf[0] = (keysym & 0xFF); } } no_repeat_call: if (x_lat) { if (len > 0) { if (len > 7) len = 7; memcpy (x_lat, kbuf, len); x_lat[len] = '\0'; } }/* return valid_keysym ? keysym : 0; */ return ((keysym >= 0x0100) && (keysym < 0x0800)) ? (valid_keysym ? kbuf[0] : 0) : (valid_keysym ? keysym : 0);}void setSize (CWidget * w, XRectangle * size){#ifdef RXVT_SOURCE /* FIXME */ size->x = TermWin_internalBorder; size->y = TermWin_internalBorder; size->width = Width2Pixel (TermWin.ncol); size->height = Height2Pixel (TermWin.nrow);#else size->x = 0; size->y = 0; size->width = w->width; size->height = w->height;#endif}void setColor (CWidget * w, unsigned long *fg, unsigned long *bg){#ifdef dont_forget_this /* FIXME */ *fg = PixColors[Color_fg]; *bg = PixColors[Color_bg];#else *fg = COLOR_BLACK; *bg = COLOR_WHITE;#endif}void setPreeditArea (CWidget * w, XRectangle * preedit_rect, XRectangle * status_rect, XRectangle * needed_rect){#ifdef RXVT_SOURCE /* FIXME */ preedit_rect->x = needed_rect->width + (scrollbar_visible () && !(Options & Opt_scrollBar_right) ? (SB_WIDTH + sb_shadow * 2) : 0); preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + ((menuBar.state == 1) ? menuBar_TotalHeight () : 0); preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + (!(Options & Opt_scrollBar_right) ? (SB_WIDTH + sb_shadow * 2) : 0); preedit_rect->height = Height2Pixel (1); status_rect->x = (scrollbar_visible () && !(Options & Opt_scrollBar_right)) ? (SB_WIDTH + sb_shadow * 2) : 0; status_rect->y = Height2Pixel (TermWin.nrow - 1) + ((menuBar.state == 1) ? menuBar_TotalHeight () : 0); status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); status_rect->height = Height2Pixel (1);#else preedit_rect->x = 0; preedit_rect->y = 0; preedit_rect->width = w->width; preedit_rect->height = w->height - 20; status_rect->x = 0; status_rect->y = w->height - 20; status_rect->width = w->width; status_rect->height = 20;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?