Esempio n. 1
0
static Bool
ResizeVendorShell_Core(VendorShellWidget vw, XawVendorShellExtPart *ve,
		       XawIcTableList p)
{
    XVaNestedList		pe_attr, st_attr;
    XRectangle			pe_area, st_area;
    XRectangle			*get_pe_area = NULL, *get_st_area = NULL;

    st_area.width = 0;
    if (p->input_style & XIMStatusArea) {
	st_attr = XVaCreateNestedList(0, XNArea, &get_st_area, NULL);
	XGetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
	XFree(st_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
	st_area.x = 0;
	st_area.y = vw->core.height - ve->im.area_height;
	st_area.width = get_st_area->width;
	st_area.height = get_st_area->height;
	XFree(get_st_area);
	st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
	XSetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
	XFree(st_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
    }
    if (p->input_style & XIMPreeditArea) {
	pe_attr = XVaCreateNestedList(0, XNArea, &get_pe_area, NULL);
	XGetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XFree(pe_attr);
	if (p->xic == NULL) {
	    return(FALSE);
	}
	pe_area.x = st_area.width;
	pe_area.y = vw->core.height - ve->im.area_height;
	pe_area.width = vw->core.width;
	pe_area.height = get_pe_area->height;
	if (p->input_style & XIMStatusArea) {
	    pe_area.width -= st_area.width;
	}
	XFree(get_pe_area);
	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XFree(pe_attr);
    }
    return(TRUE);
}
Esempio n. 2
0
static void
_ecore_imf_context_xim_cursor_location_set(Ecore_IMF_Context *ctx,
                                           int x, int y, int w, int h)
{
   Ecore_IMF_Context_Data *imf_context_data = ecore_imf_context_data_get(ctx);
   XIC ic;
   XVaNestedList preedit_attr;
   XPoint spot;

   DBG("ctx=%p, imf_context_data=%p, location=(%d, %d, %d, %d)",
       ctx, imf_context_data, x, y, w, h);

   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);
   ic = imf_context_data->ic;
   if (!ic)
     return;

   spot.x = x;
   spot.y = y + h;

   preedit_attr = XVaCreateNestedList(0,
                                      XNSpotLocation, &spot,
                                      NULL);
   XSetICValues(ic,
                XNPreeditAttributes, preedit_attr,
                NULL);

   XFree(preedit_attr);
}
Esempio n. 3
0
/*ARGSUSED*/
static void
ConfigureCB(Widget w, XtPointer closure, XEvent *event, Boolean *unused)
{
    XawIcTableList		p;
    XawVendorShellExtPart	*ve;
    VendorShellWidget		vw;
    XVaNestedList		pe_attr;
    XRectangle			pe_area;
    XawTextMargin		*margin;

    if (event->type != ConfigureNotify) return;

    if ((vw = SearchVendorShell(w)) == NULL) return;

    if ((ve = GetExtPart(vw)) != NULL) {
        if (IsSharedIC(ve)) return;
	if ((ve->im.xim == NULL) ||
	    ((p = GetIcTableShared(w, ve)) == NULL) ||
	    (p->xic == NULL) || !(p->input_style & XIMPreeditPosition)) return;
	pe_area.x = 0;
        pe_area.y = 0;
        pe_area.width = w->core.width;
        pe_area.height = w->core.height;
	margin = &(((TextWidget)w)->text.margin);
	pe_area.x += margin->left;
	pe_area.y += margin->top;
	pe_area.width -= (margin->left + margin->right - 1);
	pe_area.height -= (margin->top + margin->bottom - 1);

	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
	XtFree(pe_attr);
    }
}
Esempio n. 4
0
void
rxvt_term::IMSetPosition ()
{
  XRectangle preedit_rect, status_rect, *needed_rect;
  XVaNestedList preedit_attr, status_attr;

  if (!Input_Context
      || !focus
      || !(input_style & (XIMPreeditArea | XIMPreeditPosition))
      || !IMisRunning ())
    return;

  if (input_style & XIMPreeditPosition)
    {
      im_set_size (preedit_rect);
      preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);

      XSetICValues (Input_Context,
                    XNPreeditAttributes, preedit_attr, NULL);
    }
  else
    {
      /* Getting the necessary width of preedit area */
      status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
      XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
      XFree (status_attr);

      im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
      XFree (needed_rect);

      preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
      status_attr  = XVaCreateNestedList (0, XNArea, &status_rect,  NULL);

      XSetICValues (Input_Context,
                    XNPreeditAttributes, preedit_attr,
                    XNStatusAttributes,  status_attr,
                    NULL);

      XFree (status_attr);
    }

   XFree (preedit_attr);
}
void WindowContextBase::enableOrResetIME() {
    Display *display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(gdk_window));
    if (xim.im == NULL || xim.ic == NULL) {
        xim.im = XOpenIM(display, NULL, NULL, NULL);
        if (xim.im == NULL) {
            return;
        }

        XIMStyle styles = get_best_supported_style(xim.im);
        if (styles == 0) {
            return;
        }

        XIMCallback startCallback = {(XPointer) jview, (XIMProc) im_preedit_start};
        XIMCallback doneCallback = {(XPointer) jview, im_preedit_done};
        XIMCallback drawCallback = {(XPointer) jview, im_preedit_draw};
        XIMCallback caretCallback = {(XPointer) jview, im_preedit_caret};

        XVaNestedList list = XVaCreateNestedList(0,
                XNPreeditStartCallback, &startCallback,
                XNPreeditDoneCallback, &doneCallback,
                XNPreeditDrawCallback, &drawCallback,
                XNPreeditCaretCallback, &caretCallback,
                NULL);

        xim.ic = XCreateIC(xim.im,
                XNInputStyle, styles,
                XNClientWindow, GDK_WINDOW_XID(gdk_window),
                XNPreeditAttributes, list,
                NULL);

        XFree(list);

        if (xim.ic == NULL) {
            return;
        }
    }

    if (xim.enabled) { //called when changed focus to different input
        XmbResetIC(xim.ic);
    }


    XSetICFocus(xim.ic);

    xim.enabled = TRUE;
}
Esempio n. 6
0
void
Tk_SetCaretPos(
    Tk_Window tkwin,
    int x,
    int y,
    int height)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;

    if ((dispPtr->caret.winPtr == winPtr)
	    && (dispPtr->caret.x == x)
	    && (dispPtr->caret.y == y)
	    && (dispPtr->caret.height == height)) {
	return;
    }

    dispPtr->caret.winPtr = winPtr;
    dispPtr->caret.x = x;
    dispPtr->caret.y = y;
    dispPtr->caret.height = height;

    /*
     * Adjust the XIM caret position.
     */

#ifdef TK_USE_INPUT_METHODS
    if ((dispPtr->flags & TK_DISPLAY_USE_IM)
	    && (dispPtr->inputStyle & XIMPreeditPosition)
	    && (winPtr->inputContext != NULL)) {
	XVaNestedList preedit_attr;
	XPoint spot;

	spot.x = dispPtr->caret.x;
	spot.y = dispPtr->caret.y + dispPtr->caret.height;
	preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
	XSetICValues(winPtr->inputContext, XNPreeditAttributes, preedit_attr,
		NULL);
	XFree(preedit_attr);
    }
#endif
}
Esempio n. 7
0
File: xim.c Progetto: AndreRH/wine
void X11DRV_SetPreeditState(HWND hwnd, BOOL fOpen)
{
    XIC ic;
    XIMPreeditState state;
    XVaNestedList attr;

    ic = X11DRV_get_ic(hwnd);
    if (!ic)
        return;

    if (fOpen)
        state = XIMPreeditEnable;
    else
        state = XIMPreeditDisable;

    attr = XVaCreateNestedList(0, XNPreeditState, state, NULL);
    if (attr != NULL)
    {
        XSetICValues(ic, XNPreeditAttributes, attr, NULL);
        XFree(attr);
    }
}
Esempio n. 8
0
void
rxvt_term::IMSendSpot ()
{
  XPoint nspot;
  XVaNestedList preedit_attr;

  if (!Input_Context
      || !focus
      || !(input_style & (XIMPreeditPosition | XIMPreeditCallbacks)))
    return;

  im_set_position (nspot);

  if (nspot.x == spot.x && nspot.y == spot.y)
    return;

  spot = nspot;

  preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
  XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
  XFree (preedit_attr);
}
Esempio n. 9
0
static void
_ecore_imf_context_xim_cursor_location_set(Ecore_IMF_Context *ctx,
                                           int x, int y, int w, int h)
{
   EINA_LOG_DBG("%s in", __FUNCTION__);

#ifdef ENABLE_XIM
   Ecore_IMF_Context_Data *imf_context_data;
   XIC ic;
   XVaNestedList preedit_attr;
   XPoint spot;

   imf_context_data = ecore_imf_context_data_get(ctx);
   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);
   ic = imf_context_data->ic;
   if (!ic)
     return;

   spot.x = x;
   spot.y = y + h;

   preedit_attr = XVaCreateNestedList(0,
                                      XNSpotLocation, &spot,
                                      NULL);
   XSetICValues(ic,
                XNPreeditAttributes, preedit_attr,
                NULL);

   XFree(preedit_attr);
#else
   (void)ctx;
   (void)x;
   (void)y;
   (void)h;
#endif
   (void)(w); // yes w is unused, but only a bi-product of the algorithm
}
Esempio n. 10
0
static void
_ecore_imf_context_xim_reset(Ecore_IMF_Context *ctx)
{
   EINA_LOG_DBG("%s in", __FUNCTION__);
#ifdef ENABLE_XIM
   XIC ic;
   Ecore_IMF_Context_Data *imf_context_data;
   char *result;

   /* restore conversion state after resetting ic later */
   XIMPreeditState preedit_state = XIMPreeditUnKnown;
   XVaNestedList preedit_attr;
   Eina_Bool have_preedit_state = EINA_FALSE;

   imf_context_data = ecore_imf_context_data_get(ctx);
   EINA_SAFETY_ON_NULL_RETURN(imf_context_data);

   ic = imf_context_data->ic;
   if (!ic)
     return;

   if (imf_context_data->preedit_length == 0)
     return;

   preedit_attr = XVaCreateNestedList(0,
                                      XNPreeditState, &preedit_state,
                                      NULL);
   if (!XGetICValues(ic,
                     XNPreeditAttributes, preedit_attr,
                     NULL))
     have_preedit_state = EINA_TRUE;

   XFree(preedit_attr);

   result = XmbResetIC(ic);

   preedit_attr = XVaCreateNestedList(0,
                                      XNPreeditState, preedit_state,
                                      NULL);
   if (have_preedit_state)
     XSetICValues(ic,
                  XNPreeditAttributes, preedit_attr,
                  NULL);

   XFree(preedit_attr);

   if (imf_context_data->feedbacks)
     {
        free(imf_context_data->feedbacks);
        imf_context_data->feedbacks = NULL;
     }

   if (imf_context_data->preedit_length)
     {
        imf_context_data->preedit_length = 0;
        free(imf_context_data->preedit_chars);
        imf_context_data->preedit_chars = NULL;

        ecore_imf_context_preedit_changed_event_add(ctx);
        ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
     }

   if (result)
     {
        char *result_utf8 = strdup(result);
        if (result_utf8)
          {
             ecore_imf_context_commit_event_add(ctx, result_utf8);
             ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_COMMIT, result_utf8);
             free(result_utf8);
          }
     }

   XFree(result);
#else
   (void)ctx;
#endif
}
Esempio n. 11
0
XVaNestedList awt_util_getXICStatusAreaList(Widget w)
{
    XIC xic;
    XmImXICInfo icp;
    XmVendorShellExtObject ve;
    XmWidgetExtData extData;
    XmImShellInfo im_info;
    XmFontList fl=NULL;

    XRectangle  *ssgeometry = &geometryRect;
    XRectangle geomRect ;
    XRectangle *im_rect;
    XFontSet   *im_font;

    Pixel bg ;
    Pixel fg ;
    Dimension height, width ;
    Position x,y ;
    Pixmap bpm, *bpmout ;

    XVaNestedList list = NULL;

    char *ret;
    Widget p=w;

    while (!XtIsShell(p)) {
        p = XtParent(p);
    }

    XtVaGetValues(p,
        XmNx, &x,
        XmNy, &y,
        XmNwidth, &width,
        XmNheight, &height,
        XmNbackgroundPixmap, &bpm,
        NULL);

    extData = _XmGetWidgetExtData((Widget) p, XmSHELL_EXTENSION);
    if (extData == NULL) {
        return NULL;
    }
    ve = (XmVendorShellExtObject) extData->widget;
    im_info = get_im_info(w, False);

    if (im_info == NULL) {
        return NULL;
    } else {
        icp = im_info->iclist;
    }

    if (icp) {
        /*
         * We have at least a textfield/textarea in the frame, use the
         * first one.
         */
        ssgeometry->x = 0;
        ssgeometry->y = height - icp->sp_height;
        ssgeometry->width = icp->status_width;
        ssgeometry->height = icp->sp_height;
        XtVaGetValues(w, XmNbackground, &bg, NULL);
        XtVaGetValues(w, XmNforeground, &fg, NULL);
        XtVaGetValues(w, XmNfontList, &fl, NULL);
        /*
         * use motif TextComponent's resource
         */

        list = XVaCreateNestedList(0,
                        XNFontSet, extract_fontset(fl),
                        XNArea, ssgeometry,
                        XNBackground, bg,
                        XNForeground, fg,
                        NULL);
   }
   return list ;
}
Esempio n. 12
0
XVaNestedList awt_motif_getXICStatusAreaList(Widget w, jobject tc)
{
    Widget p;
    XmVendorShellExtObject ve;
    XmWidgetExtData extData;
    XmImInfo *im_info;
    XmICStruct *icp;

    XVaNestedList list = NULL;
    XRectangle  *ssgeometry = &geometryRect;
    Pixel  bg;
    Pixel  fg;
    Pixmap bpm;
    Dimension height,width;
    Position  x,y;

    p = w;
    while (!XtIsShell(p)){
	p = XtParent(p);
    }

    XtVaGetValues(p,
		  XmNx, &x,
		  XmNy, &y,
		  XmNwidth, &width,
		  XmNheight, &height,
		  NULL);

    extData = (XmWidgetExtData)_XmGetWidgetExtData((Widget) p, XmSHELL_EXTENSION);
    if (extData == NULL) {
	return NULL;
    }

    ve = (XmVendorShellExtObject) extData->widget;
    if ((im_info = (XmImInfo *) ve->vendor.im_info) == NULL) {
	return NULL;         
    } else
	icp = im_info->iclist;


    if (icp) {
	/*
	 * We hava at least a textfield/textarea in the frame, use the
	 * first one.
	 */
	ssgeometry->x = 0;
	ssgeometry->y = height - icp->status_height;
	ssgeometry->width = icp->status_width;
	ssgeometry->height = icp->status_height;

	/*
	 * use motif TextComponent's resource
	 */
	fg = icp->foreground;
	bg = icp->background;
	bpm = icp->background_pixmap;

	list = XVaCreateNestedList(0, 
			XNFontSet, extract_fontset((XmFontList)icp->font_list),
			XNArea, ssgeometry, 
			XNBackground, bg, 
			XNForeground, fg, 
			XNBackgroundPixmap, bpm, 
			NULL);
   }
    return list ;
}
Esempio n. 13
0
	int main(int argc, char **argv)
	{
		Display *display;
		int screen_num;
		Window win;			//窗口ID
		unsigned int width, height;	//窗口尺寸
		unsigned int border_width = 4;	//边界空白
		unsigned int display_width, display_height;//屏幕尺寸
		XEvent report;
		GC gc;
		unsigned long valuemask = 0;
		XGCValues values;
		char *display_name = NULL;
		Atom          protocols;

		//edit
		int           len = 127;
		unsigned char string[128], s_tab[ROW][127];
		KeySym        keysym;
		int           row = 0, col = 0;
		int           i, count = 0;
		Status        status;
		//字体集
		XFontSet fontset;
		char **missing_charsets;
		int num_missing_charsets;
		char *default_string;
		XFontSetExtents *fs_ext;
		int dec;    

		//XIM
		XIM im;
		XIC ic;
		//overspot
		XRectangle    spot, s_rect;
		XVaNestedList preedit_attr, status_attr;

		//设置locale	
		if((setlocale(LC_ALL, "")) == NULL){
			printf("cannot set locale\n");
			exit(1);
		}

		//判断X是否支持locale
		if(!XSupportsLocale()){
			printf("X does not support current locale\n");
			exit(1);
		}

		//设置locale修饰
		if(XSetLocaleModifiers(NULL)){
			printf("Cannot set locale modifiers\n");
			exit(1);
		}
	
		// 和X 服务器连接
		if ( (display=XOpenDisplay(display_name)) == NULL )
		{
			printf("Cannot connect to X server %s\n", 
					XDisplayName(display_name));
			exit(-1);
		}

		//获得缺省的 screen_num
		screen_num = DefaultScreen(display);

		//获得屏幕的宽度和高度
		display_width = DisplayWidth(display, screen_num);
		display_height = DisplayHeight(display, screen_num);
	
		//建立字体集
		fontset = XCreateFontSet(display, 
			"8x16,-*-song-medium-r-normal--16-*-*-*-*-*-gb2312.1980-0",
			&missing_charsets, &num_missing_charsets,
			&default_string);

		if(num_missing_charsets > 0){
			int i;
			printf("Following charsets are missing:\n");
			for(i=0; i<num_missing_charsets; i++){
				printf("Missing %d: %s\n", 
					i, missing_charsets[i]);
			}
			printf("\nDefault string:%s\n", default_string);
			XFreeStringList(missing_charsets);
		}
		//字体的Extents
		fs_ext = XExtentsOfFontSet(fontset);
		dec = fs_ext->max_logical_extent.height 
			+ fs_ext->max_logical_extent.y;

		width  = W_WIDTH;
		height = W_HEIGHT + dec;

	
		//建立窗口
		win = XCreateSimpleWindow(display, 	//display
			RootWindow(display,screen_num), //父窗口
			0, 0, width, height, 		//位置和大小
			border_width, 			//边界宽度
			BlackPixel(display,screen_num), //前景色
			WhitePixel(display,screen_num));//背景色
	
		//选择窗口感兴趣的事件掩码
		XSelectInput(display, win, 
			ExposureMask | KeyPressMask | 
			ButtonPressMask | StructureNotifyMask);

		//建立GC
		gc = XCreateGC(display, win, valuemask, &values);

		protocols = XInternAtom(display, "WM_DELETE_WINDOW", True);
		XSetWMProtocols(display, win, &protocols, 1);

		//显示窗口
		XMapWindow(display, win);

		//联接输入服务器
		if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){
			printf("Error : XOpenIM !\n");
			exit(1);
		}

		//设置输入服务器的位置
		spot.x = F_SIZE / 2 * col;
		spot.y = F_SIZE * (row + 1) - dec; 
		preedit_attr = XVaCreateNestedList(0,
			XNSpotLocation, &spot,
			XNFontSet, fontset, 
			NULL);
		s_rect.x = 0;
		s_rect.y = F_SIZE * ROW + dec + 2;
		s_rect.width = W_WIDTH;
		s_rect.height = F_SIZE;
		status_attr = XVaCreateNestedList(0,
			XNArea, &s_rect,
			XNFontSet, fontset,
			NULL);
		//建立IC
		if((ic = XCreateIC(im, 
			XNInputStyle, XIMPreeditPosition | XIMStatusNothing,
			XNClientWindow, win, 
			XNPreeditAttributes, preedit_attr,
			XNStatusAttributes, status_attr, NULL)) == NULL){
			printf("Error : XCreateIC() ! \n");
			XCloseIM(im);
			exit(0);
		}
		//释放内存
		XFree(preedit_attr);
		XFree(status_attr);


		//写屏缓冲区初始化
		for(i = 0; i < ROW; i++)s_tab[i][0] = 0;

		//进入事件循环
		while (1)  {

			//取得队列中的事件
			XNextEvent(display, &report);

			//过滤事件
			if(XFilterEvent(&report, None) == True) continue;
			switch  (report.type) {

			//聚焦发声变化
			case FocusIn:
				XSetICFocus(ic); 
				break;
			case FocusOut:
				XUnsetICFocus(ic);
				break;

			//曝光事件, 窗口应重绘
			case Expose:
				//取得最后一个曝光事件
				if (report.xexpose.count != 0) break;
				for ( i=0; i < ROW; i++)
					XmbDrawString(display, win, fontset,gc, 
					0, F_SIZE * (i +1), 
					s_tab[i], strlen(s_tab[i]));
				break;

			//窗口尺寸改变, 重新取得窗口的宽度和高度
			case ConfigureNotify:
				width = report.xconfigure.width;
				height = report.xconfigure.height;
				break;

			//鼠标点击或有按键, 释放资源则退出
			case KeyPress:
				count = XmbLookupString(ic, 
					(XKeyPressedEvent *) &report,
					string, len, &keysym, &status);
				string[count] = 0;
				if (status == XLookupBoth&&keysym == XK_Return){
					row = (++row) % ROW;
					col = 0;
					s_tab[row][0] = 0;
					XClearArea(display, win, 
						0, F_SIZE * row + dec,
						W_WIDTH, F_SIZE, False);
				} else if (status = XLookupChars 
					|| status == XLookupBoth){
					XmbDrawString(display, win, fontset, gc,
					F_SIZE / 2 * col, F_SIZE * (row + 1),
					string, count);
					for (i = 0; i < count && col < len && 
						string[i]; i++, col++)
						s_tab[row][col] = string[i];
						s_tab[row][col] = 0;
				}
				//更新输入服务器位置
				spot.x = F_SIZE / 2 * col;
				spot.y = F_SIZE * (row + 1);
				preedit_attr = XVaCreateNestedList(0,
					XNSpotLocation, &spot,
					NULL);
				XSetICValues(ic, 
					XNPreeditAttributes, preedit_attr, 
					NULL);
				XFree(preedit_attr);
				break;
			case ClientMessage:
				if (report.xclient.data.l[0] == protocols) {
					XDestroyIC(ic);
					XCloseIM(im);
					XDestroyWindow(display, win);
					XCloseDisplay(display);
					exit(0);
				}
				break;
			default:
				break;
			}
		}
	}
Esempio n. 14
0
XVaNestedList awt_motif_getXICStatusAreaList(Widget w, jobject tc)
{
    XIC xic;

    XRectangle *im_rect;
    XFontSet   *im_font;

    Pixel bg ;
    Pixel fg ;
    Dimension height, width ;
    Position x,y ;

    XVaNestedList list = NULL;

    char *ret;
    Widget p=w;

    while (!XtIsShell(p)) {
        p = XtParent(p);
    }

    XtVaGetValues(p,
        XmNx, &x,
        XmNy, &y,
        XmNwidth, &width,
        XmNheight, &height,
        XmNbackgroundPixmap, &bpm,
        NULL);



    xic = XmImGetXIC(getTextWidget(tc), XmPER_SHELL, NULL, 0);
    if(xic == NULL)
    {
#if defined DEBUG
        jio_fprintf(stderr,"Could not get XIC");
#endif
        return list ;
    }

   /* finally query the server for the required attributes area geometry */
    xic_vlist[0].name = XNFontSet ;
    xic_vlist[0].value =  (XtArgVal) &im_font ;
    xic_vlist[1].name = XNArea;
    xic_vlist[1].value = (XtArgVal) &im_rect;
    xic_vlist[2].name = XNBackground ;
    xic_vlist[2].value = (XtArgVal) &bg ;
    xic_vlist[3].name = XNForeground ;
    xic_vlist[3].value = (XtArgVal) &fg ;
    xic_vlist[4].name = NULL;


    if(ret=XGetICValues(xic, XNStatusAttributes, &xic_vlist[0], NULL))
    {
        return list ;
    } else {
        geomRect.x = 0 ;
        geomRect.y = height - im_rect->height ;
        geomRect.width = im_rect->width ;
        geomRect.height = im_rect->height ;
        XFree(im_rect) ;

        list = XVaCreateNestedList(0 ,
                        XNFontSet, im_font ,
                        XNArea, &geomRect ,
                        XNBackground, bg ,
                        XNForeground, fg ,
                        XNBackgroundPixmap, &bpm ,
                        NULL );
    }
#if defined(DEBUG)
    jio_fprintf(stderr,"awt_motif_getXICStatusAreaList:\n");
    jio_fprintf(stderr,"XNArea:x=%d,y=%d,width=%d,height=%d\n", \
         geomRect.x,geomRect.y,geomRect.width,geomRect.height);
    jio_fprintf(stderr,"XNBackground=0x%x\n",bg);
    jio_fprintf(stderr,"XNForeground=0x%x\n",fg);
    jio_fprintf(stderr,"XNBackgroundPixmap=0x%x\n",bpm);
#endif
    return list ;

}
Esempio n. 15
0
/*
 * Try to open a XIM with the current modifiers, then see if we can
 * open a suitable preedit type
 */
bool
rxvt_term::IM_get_IC (const char *modifiers)
{
  int i, j, found;
  XIM xim;
  XPoint spot;
  XRectangle rect, status_rect, needed_rect;
  unsigned long fg, bg;
  const char *p;
  char **s;
  XIMStyles *xim_styles;
#ifdef ENABLE_XIM_ONTHESPOT
  XIMCallback xcb[4];
#endif

  set_environ (envv);

  if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
    return false;

  input_method = display->get_xim (locale, modifiers);
  if (input_method == NULL)
    return false;

  xim = input_method->xim;
  spot.x = spot.y = -1;

  xim_styles = NULL;
  if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
      || !xim_styles || !xim_styles->count_styles)
    {
      im_destroy ();
      return false;
    }

  const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };

  for (int pi = 0; pi < 2; pi++)
    {
      p = pet[pi];

      if (!p)
        continue;

      s = rxvt_splitcommastring (p);

      for (i = found = 0; !found && s[i]; i++)
        {
          if (!strcmp (s[i], "OverTheSpot"))
            input_style = XIMPreeditPosition | XIMStatusNothing;
          else if (!strcmp (s[i], "OffTheSpot"))
            input_style = XIMPreeditArea | XIMStatusArea;
          else if (!strcmp (s[i], "Root"))
            input_style = XIMPreeditNothing | XIMStatusNothing;
          else if (!strcmp (s[i], "None"))
            input_style = XIMPreeditNone | XIMStatusNone;
#ifdef ENABLE_XIM_ONTHESPOT
          else if (SHOULD_INVOKE (HOOK_XIM_PREEDIT_START) && !strcmp (s[i], "OnTheSpot"))
            input_style = XIMPreeditCallbacks | XIMStatusNothing;
#endif
          else
            input_style = XIMPreeditNothing | XIMStatusNothing;

          for (j = 0; j < xim_styles->count_styles; j++)
            if (input_style == xim_styles->supported_styles[j])
              {
                rxvt_freecommastring (s);

                found = 1;
                goto foundpet;
              }

        }

      rxvt_freecommastring (s);
    }

foundpet:

  XFree (xim_styles);

  if (!found)
    {
      im_destroy ();
      return false;
    }

  XFontSet fs = 0;
  XVaNestedList preedit_attr = 0, status_attr = 0;

  if (input_style & (XIMPreeditPosition | XIMPreeditArea))
    {
      // fake us a font-set, please
      char **missing_charset_list;
      int missing_charset_count;
      char *def_string;
      char pat[512];

      sprintf (pat,
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
               "*",
               fheight,
               fheight + 1, fheight - 1,
               fheight - 2, fheight + 2);

      fs = XCreateFontSet (dpy, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
                           &missing_charset_list, &missing_charset_count, &def_string);

      if (missing_charset_list)
        XFreeStringList (missing_charset_list);

      if (!fs)
        {
          input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
          rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
        }
    }

  if (input_style & XIMPreeditPosition)
    {
      im_set_size (rect);
      im_set_position (spot);
      im_set_color (fg, bg);

      preedit_attr = XVaCreateNestedList (0,
                                          XNForeground, fg,
                                          XNBackground, bg,
                                          XNArea, &rect,
                                          XNSpotLocation, &spot,
                                          XNFontSet, fs,
                                          NULL);
    }
  else if (input_style & XIMPreeditArea)
    {
      im_set_color (fg, bg);

      /*
       * The necessary width of preedit area is unknown
       * until create input context.
       */
      needed_rect.width = 0;
      im_set_preedit_area (rect, status_rect, needed_rect);

      preedit_attr = XVaCreateNestedList (0,
                                          XNForeground, fg,
                                          XNBackground, bg,
                                          XNArea, &rect,
                                          XNFontSet, fs,
                                          NULL);
      status_attr = XVaCreateNestedList (0,
                                         XNForeground, fg,
                                         XNBackground, bg,
                                         XNArea, &status_rect,
                                         XNFontSet, fs,
                                         NULL);
    }
#if ENABLE_XIM_ONTHESPOT
  else if (input_style & XIMPreeditCallbacks)
    {
      im_set_position (spot);

      xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start;
      xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done;
      xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw;
# if 0
      xcb[3].client_data = (XPointer)this; xcb[3].callback = (XIMProc)xim_preedit_caret;
# endif

      preedit_attr = XVaCreateNestedList (0,
                                          XNSpotLocation, &spot,
                                          XNPreeditStartCallback, &xcb[0],
                                          XNPreeditDoneCallback , &xcb[1],
                                          XNPreeditDrawCallback , &xcb[2],
# if 0
                                          XNPreeditCaretCallback, &xcb[3],
# endif
                                          NULL);
    }
#endif

  Input_Context = XCreateIC (xim,
                             XNInputStyle, input_style,
                             XNClientWindow, vt,
                             XNFocusWindow, parent[0],
                             preedit_attr ? XNPreeditAttributes : NULL,
                             preedit_attr,
                             status_attr ? XNStatusAttributes : NULL,
                             status_attr, NULL);

  if (preedit_attr) XFree (preedit_attr);
  if (status_attr)  XFree (status_attr);
  if (fs)           XFreeFontSet (dpy, fs);

  if (Input_Context == NULL)
    {
      rxvt_warn ("failed to create input context, continuing without XIM.\n");
      im_destroy ();
      return false;
    }

#if 0
  // unfortunately, only the focus window is used by XIM, hard to fix
  if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL))
    vt_select_input ();
#endif

  IMSetPosition ();

  return true;
}
Esempio n. 16
0
  bool create(std::string display, int buffer, bool fullscreen, bool border,
              int&x, int&y, unsigned int&w, unsigned int&h, bool transparent)
  {
    int modeNum=4;
#ifdef HAVE_LIBXXF86VM
    XF86VidModeModeInfo **modes;
#endif

    XSetErrorHandler (ErrorHandler);

    if ( (dpy = XOpenDisplay(display.c_str())) == NULL) {
      ::error("Could not open display %s",display.c_str());
      return false;
    }
    screen  = DefaultScreen(dpy);

    if ( !glXQueryExtension(dpy, NULL, NULL) ) {
      throw(GemException("X server has no OpenGL GLX extension"));
      return false;
    }

    if (fullscreen) {
      if (!display.empty()) {
        fullscreen=false;
        throw(GemException("fullscreen not available on remote display"));
      } else {
#ifdef HAVE_LIBXXF86VM
        XF86VidModeGetAllModeLines(dpy, screen, &modeNum, &modes);
        deskMode = *modes[0];
#else
        throw(GemException("no xxf86vm-support: cannot switch to fullscreen"));
#endif
      }
    }

    XVisualInfo *vi=0;

#ifdef HAVE_LIBXRENDER
    if (transparent) {

      static GLXFBConfig *fbconfigs, fbconfig;
      static int numfbconfigs;

      // need to get some function pointer at runtime
      typedef GLXFBConfig*(*glXChooseFBConfigProc)(Display* dpy, int screen,
          const int* attribList, int* nitems);
      glXChooseFBConfigProc glXChooseFBConfigFn = (glXChooseFBConfigProc)
          glXGetProcAddress((const GLubyte*)"glXChooseFBConfig");

      typedef XVisualInfo*(*glXGetVisualFromFBConfigProc)(Display* dpy,
          GLXFBConfig fbconfig);
      glXGetVisualFromFBConfigProc glXGetVisualFromFBConfigFn =
        (glXGetVisualFromFBConfigProc)glXGetProcAddress((const GLubyte*)
            "glXGetVisualFromFBConfig");

      if (glXChooseFBConfigFn && glXGetVisualFromFBConfigFn) {
        static int**fbbuf=0;
        switch(buffer) {
        default: ::error("only single/double buffer supported; defaulting to double");
        case 2:
          fbbuf=dblBufFbCfg;
          break;
        case 1:
          fbbuf=snglBufFbCfg;
          break;
        }
        bool breakme=false;
        for(; *fbbuf; fbbuf++) {

          fbconfigs =  glXChooseFBConfigFn(dpy, screen, *fbbuf, &numfbconfigs);

          fbconfig = 0;
          for(int i = 0; i<numfbconfigs; i++) {
            vi = (XVisualInfo*) glXGetVisualFromFBConfigFn(dpy, fbconfigs[i]);
            if(!vi) {
              continue;
            }

            XRenderPictFormat *pict_format = XRenderFindVisualFormat(dpy, vi->visual);
            if(!pict_format) {
              continue;
            }

            fbconfig = fbconfigs[i];
            if(pict_format->direct.alphaMask > 0) {
              ::verbose(0,"choose fbconfig : %d", i);
              breakme = true;
              break;
            }
          }
          if ( breakme ) {
            break;
          }
        }

        if(!fbconfig) {
          ::error("Can't find valid framebuffer configuration, try again with legacy method.");
        } else {
          typedef void(*glXGetFBConfigAttribProc)(Display* dpy,GLXFBConfig fbconfig,
                                                  int attr, int* val);
          glXGetFBConfigAttribProc glXGetFBConfigAttribFn =
            (glXGetFBConfigAttribProc)glXGetProcAddress((const GLubyte*)
                "glXGetFBConfigAttrib");
          if ( glXGetFBConfigAttribFn ) {
            int doublebuffer;
            int red_bits, green_bits, blue_bits, alpha_bits, depth_bits;

            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_DOUBLEBUFFER, &doublebuffer);
            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_RED_SIZE, &red_bits);
            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_GREEN_SIZE, &green_bits);
            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_BLUE_SIZE, &blue_bits);
            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_ALPHA_SIZE, &alpha_bits);
            glXGetFBConfigAttribFn(dpy, fbconfig, GLX_DEPTH_SIZE, &depth_bits);

            ::verbose(0, "FBConfig selected:");
            ::verbose(0, " Doublebuffer: %s", doublebuffer == True ? "Yes" : "No");
            ::verbose(0,
                      " Red Bits: %d, Green Bits: %d, Blue Bits: %d, Alpha Bits: %d, Depth Bits: %d",
                      red_bits, green_bits, blue_bits, alpha_bits, depth_bits);
          } else {
            ::error("can't get glXGetFBConfigAttrib function pointer");
          }
        }
      }
    }

#endif // HAVE_LIBXRENDER

    if (vi == NULL) { // if Xrender method doesn't work try legacy
      static int**buf=0;
      switch(buffer) {
      default: ::error("only single/double buffer supported; defaulting to double");
      case 2:
        buf=dblBufs;
        break;
      case 1:
        buf=snglBufs;
        break;
      }
      // the user wants double buffer
      for(; *buf; buf++) {
        vi = glXChooseVisual(dpy, screen, *buf);
        if(vi) {
          break;
        }
      }
    }

    if (vi == NULL) {
      std::string errstr="Unable to create ";
      switch(buffer) {
      default:
        errstr+="???";
        break;
      case 1:
        errstr+"single";
        break;
      case 2:
        errstr+"double";
        break;
      }
      errstr+=" buffer window";
      throw(GemException(errstr));
      return false;
    }

    if(vi->depth<24) {
      ::verbose(0, "Only using %d color bits", vi->depth);
    }
    if (vi->c_class != TrueColor && vi->c_class != DirectColor) {
      ::error("TrueColor visual required for this program (got %d)",
              vi->c_class);
      return false;
    }
    // create the rendering context
    try {
      // first check whether we have a shared context for 'display'
      GLXContext sharedContext=0;
      if(s_shared.count(display)>0) {
        sharedContext=s_shared[display].glxcontext;;
      }
      glxcontext = glXCreateContext(dpy, vi, sharedContext, GL_TRUE);
    } catch(void*e) {
      glxcontext=NULL;
    }
    if (glxcontext == NULL) {
      throw(GemException("Could not create rendering context"));
      return false;
    }
    // create the X color map
    cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
                           vi->visual, AllocNone);
    if (!cmap) {
      throw(GemException("Could not create X colormap"));
      return false;
    }

    XSetWindowAttributes swa;
    swa.colormap = cmap;
    swa.border_pixel = 0;
    // event_mask creates signal that window has been created
    swa.event_mask = EVENT_MASK;

    int flags;
#ifdef HAVE_LIBXXF86VM
    if (fullscreen) {
      int bestMode=0;
      /* look for mode with requested resolution */
      for (int i = 0; i < modeNum; i++) {
        if ((modes[i]->hdisplay == w) && (modes[i]->vdisplay == w)) {
          bestMode = i;
        }
      }

      XF86VidModeSwitchToMode(dpy, screen, modes[bestMode]);
      XF86VidModeSetViewPort(dpy, screen, 0, 0);
      w = modes[bestMode]->hdisplay;
      h = modes[bestMode]->vdisplay;
      x=y=0;
      XFree(modes);

      swa.override_redirect = True;
      flags=CWBorderPixel|CWColormap|CWEventMask|CWOverrideRedirect;
    } else
#endif
    {
      // !fullscren
      if (border) {
        swa.override_redirect = False;
        flags=CWBorderPixel|CWColormap|CWEventMask|CWOverrideRedirect;
      } else {
        swa.override_redirect = True;
        flags=CWBorderPixel|CWColormap|CWEventMask|CWOverrideRedirect;
      }
    }
    fs = fullscreen;
    win = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
                        x, y, w, h,
                        0, vi->depth, InputOutput,
                        vi->visual, flags, &swa);
    XFree( vi );

    if (!win) {
      throw(GemException("Could not create X window"));
      return false;
    }

    have_border=(True==swa.override_redirect);

    XSelectInput(dpy, win, EVENT_MASK);

    inputMethod = XOpenIM(dpy, NULL, NULL, NULL);
    if(inputMethod) {
      XIMStyle style=0;
      XIMStyles *stylePtr=NULL;
      const char *preedit_attname = NULL;
      XVaNestedList preedit_attlist = NULL;

      if ((XGetIMValues(inputMethod, XNQueryInputStyle, &stylePtr,
                        NULL) != NULL)) {
        stylePtr=NULL;
      }


      /*
       * Select the best input style supported by both the IM and Tk.
       */
      if(stylePtr) {
        for (int i = 0; i < stylePtr->count_styles; i++) {
          XIMStyle thisStyle = stylePtr->supported_styles[i];
          if (thisStyle == (XIMPreeditPosition | XIMStatusNothing)) {
            style = thisStyle;
            break;
          } else if (thisStyle == (XIMPreeditNothing | XIMStatusNothing)) {
            style = thisStyle;
          }
        }
        XFree(stylePtr);
      }

      if (style & XIMPreeditPosition) {
        XPoint spot = {0, 0};
        XFontSet inputXfs;
        memset(&inputXfs, 0, sizeof(inputXfs));
        preedit_attname = XNPreeditAttributes;
        preedit_attlist = XVaCreateNestedList(0,
                                              XNSpotLocation, &spot,
                                              XNFontSet, inputXfs,
                                              NULL);
      }

      inputContext=XCreateIC(inputMethod,
                             XNInputStyle, style,
                             XNClientWindow, win,
                             XNFocusWindow, win,
                             preedit_attname, preedit_attlist,
                             NULL);
    }



    /* found a bit at
     * http://biology.ncsa.uiuc.edu/library/SGI_bookshelves/SGI_Developer/books/OpenGL_Porting/sgi_html/apf.html
     * LATER think about reacting on this event...
     */
    delete_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
    if (delete_atom != None) {
      XSetWMProtocols(dpy, win, &delete_atom,1);
    }

    try {
      xerr=0;
      glXMakeCurrent(dpy, win, glxcontext);

      if(xerr!=0) {
        /* seems like the error-handler was called; so something did not work the way it should
         * should we really prevent window-creation in this case?
         * LATER re-think the entire dual-context thing
         */

        throw(GemException("problems making glX-context current: refusing to continue\ntry setting the environment variable GEM_SINGLE_CONTEXT=1"));
        return false;
      }
      Window winDummy;
      unsigned int depthDummy;
      unsigned int borderDummy;
      //int x, y;

      XGetGeometry(dpy, win,
                   &winDummy,
                   &x, &y,
                   &w, &h,
                   &borderDummy, &depthDummy);
    } catch(void*e) {
      throw(GemException("Could not make glX-context current"));
      return false;
    }
    return true;
  }
Esempio n. 17
0
XIC X11DRV_CreateIC(XIM xim, struct x11drv_win_data *data)
{
    XPoint spot = {0};
    XVaNestedList preedit = NULL;
    XVaNestedList status = NULL;
    XIC xic;
    XICCallback destroy = {(XPointer)data, (XICProc)X11DRV_DestroyIC};
    XICCallback P_StartCB, P_DoneCB, P_DrawCB, P_CaretCB;
    LANGID langid = PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale()));
    Window win = data->whole_window;

    TRACE("xim = %p\n", xim);

    wine_tsx11_lock();

    /* use complex and slow XIC initialization method only for CJK */
    if (langid != LANG_CHINESE &&
        langid != LANG_JAPANESE &&
        langid != LANG_KOREAN)
    {
        xic = XCreateIC(xim,
                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
                        XNClientWindow, win,
                        XNFocusWindow, win,
                        XNDestroyCallback, &destroy,
                        NULL);
        wine_tsx11_unlock();
        data->xic = xic;
        return xic;
    }

    /* create callbacks */
    P_StartCB.client_data = NULL;
    P_DoneCB.client_data = NULL;
    P_DrawCB.client_data = NULL;
    P_CaretCB.client_data = NULL;
    P_StartCB.callback = (XICProc)XIMPreEditStartCallback;
    P_DoneCB.callback = (XICProc)XIMPreEditDoneCallback;
    P_DrawCB.callback = (XICProc)XIMPreEditDrawCallback;
    P_CaretCB.callback = (XICProc)XIMPreEditCaretCallback;

    if ((ximStyle & (XIMPreeditNothing | XIMPreeditNone)) == 0)
    {
        preedit = XVaCreateNestedList(0,
                        XNSpotLocation, &spot,
                        XNPreeditStartCallback, &P_StartCB,
                        XNPreeditDoneCallback, &P_DoneCB,
                        XNPreeditDrawCallback, &P_DrawCB,
                        XNPreeditCaretCallback, &P_CaretCB,
                        NULL);
        TRACE("preedit = %p\n", preedit);
    }
    else
    {
        preedit = XVaCreateNestedList(0,
                        XNPreeditStartCallback, &P_StartCB,
                        XNPreeditDoneCallback, &P_DoneCB,
                        XNPreeditDrawCallback, &P_DrawCB,
                        XNPreeditCaretCallback, &P_CaretCB,
                        NULL);

        TRACE("preedit = %p\n", preedit);
    }

    if ((ximStyle & (XIMStatusNothing | XIMStatusNone)) == 0)
    {
        status = XVaCreateNestedList(0,
            NULL);
        TRACE("status = %p\n", status);
     }

    if (preedit != NULL && status != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNPreeditAttributes, preedit,
              XNStatusAttributes, status,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
     }
    else if (preedit != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNPreeditAttributes, preedit,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }
    else if (status != NULL)
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNStatusAttributes, status,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }
    else
    {
        xic = XCreateIC(xim,
              XNInputStyle, ximStyle,
              XNClientWindow, win,
              XNFocusWindow, win,
              XNDestroyCallback, &destroy,
              NULL);
    }

    TRACE("xic = %p\n", xic);
    data->xic = xic;

    if (preedit != NULL)
        XFree(preedit);
    if (status != NULL)
        XFree(status);

    wine_tsx11_unlock();

    return xic;
}
Esempio n. 18
0
bool TWindow::CreateInputContext()
{
	if (!fInputContext)
	{
		XIM xim = gApplication->GetInputMethod();
		if (!xim)
			return false;
		
		XIMStyles* supportedStyles;
		XGetIMValues(xim, XNQueryInputStyle, &supportedStyles, NULL, NULL);
		if (!supportedStyles || supportedStyles->count_styles == 0)
			return false;
			
		XIMStyle* bestStyle = NULL;
		for (unsigned short i = 0; i < supportedStyles->count_styles; i++)
		{
			XIMStyle* style = &supportedStyles->supported_styles[i];
			
			// first check to see if it is supported
			if ((*style & (XIMPreeditPosition | XIMPreeditNothing | XIMPreeditNone)) &&
				(*style & ( /*XIMStatusCallbacks |*/ XIMStatusNothing | XIMStatusNone)))
			{
				if (bestStyle)
				{
					if (((*style & XIMPreeditPosition) && !(*bestStyle & XIMPreeditPosition)) ||
						((*style & XIMStatusCallbacks) && !(*bestStyle & XIMStatusCallbacks)))
						bestStyle = style;			
					else if (((*style & XIMPreeditNothing) && !(*bestStyle & (XIMPreeditPosition | XIMPreeditNothing))) ||
							 ((*style & XIMStatusNothing) && !(*bestStyle & (XIMStatusCallbacks | XIMStatusNothing))))
						bestStyle = style;			
				}
				else
					bestStyle = style;
			}
		}
		
		XIMStyle style = (bestStyle ? *bestStyle : 0);
		XFree(supportedStyles);
		if (!bestStyle)
			return false;
		
		XPoint point;
		point.x = point.y = 0;
		XRectangle rect;
		rect.x = rect.y = 0;
		rect.width = rect.height = 0x7fff;
		
		TFont* font = GetFont();
		ASSERT(font && font->GetFontSet());
		XVaNestedList	preeditAttributes = XVaCreateNestedList(0, XNFontSet, font->GetFontSet(), XNSpotLocation, &point, XNArea, &rect, NULL);
		ASSERT(preeditAttributes);
	//	XVaNestedList	statusAttributes = XVaCreateNestedList(0, XNFontSet, font->GetFontSet(), NULL);
	//	ASSERT(statusAttributes);
	
		XIC xic = XCreateIC(xim, XNInputStyle, style, XNClientWindow, fWindow, XNFocusWindow, fWindow, XNPreeditAttributes, preeditAttributes, /*XNStatusAttributes, statusAttributes, */ NULL);
		if (xic)
			fInputContext = new TInputContext(xic);
			
		/*if (fInputContext)
		{
			long mask;
			XGetICValues(fInputContext->GetXIC(), XNFilterEvents, &mask, NULL);
			printf("XIC mask = %lx\n", mask);
 	   }*/
	}
		
	return (fInputContext != NULL);
}
void QXIMInputContext::setHolderWidget( QWidget *widget )
{
    if ( ! widget )
	return;

    QInputContext::setHolderWidget( widget );

#if !defined(QT_NO_XIM)
    if (! qt_xim) {
	qWarning("QInputContext: no input method context available");
	return;
    }

    if (! widget->isTopLevel()) {
	qWarning("QInputContext: cannot create input context for non-toplevel widgets");
	return;
    }

    XVaNestedList preedit_attr = 0;
    XIMCallback startcallback, drawcallback, donecallback;

    startcallback.client_data = (XPointer) this;
    startcallback.callback = (XIMProc) xic_start_callback;
    drawcallback.client_data = (XPointer) this;
    drawcallback.callback = (XIMProc)xic_draw_callback;
    donecallback.client_data = (XPointer) this;
    donecallback.callback = (XIMProc) xic_done_callback;

    preedit_attr = XVaCreateNestedList(0,
		   XNPreeditStartCallback, &startcallback,
		   XNPreeditDrawCallback, &drawcallback,
		   XNPreeditDoneCallback, &donecallback,
			   (char *) 0);

    if (preedit_attr)
    {
	ic = XCreateIC(qt_xim,
		       XNInputStyle, XIMPreeditCallbacks|XIMStatusCallbacks,
		       XNClientWindow, widget->winId(),
		       XNPreeditAttributes, preedit_attr,
		       (char *) 0);
	XFree(preedit_attr);
    }
    else
    {
	ic = XCreateIC(qt_xim,
		       XNInputStyle, XIMPreeditCallbacks|XIMStatusCallbacks,
		       XNClientWindow, widget->winId(),
		       (char *) 0);
    }

    if (! ic)
	qFatal("Failed to create XIM input context!");

    setComposePosition(1,1);

    // when resetting the input context, preserve the input state
    (void) XSetICValues((XIC) ic, XNResetState, XIMPreserveState, (char *) 0);

    if( ! ximContextList )
	ximContextList = new QPtrList<QXIMInputContext>;
    ximContextList->append( this );
#endif // !QT_NO_XIM
}
Esempio n. 20
0
static void
SizeNegotiation(XawIcTableList p, unsigned int width, unsigned int height)
{
    XRectangle		pe_area, st_area;
    XVaNestedList	pe_attr = NULL, st_attr = NULL;
    int			ic_cnt = 0;
    XRectangle		*pe_area_needed = NULL, *st_area_needed = NULL;
    XPointer		ic_a[5];

    if (p->input_style & XIMPreeditArea) {
	pe_attr = XVaCreateNestedList(0, XNAreaNeeded, &pe_area_needed, NULL);
	ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
    }
    if (p->input_style & XIMStatusArea) {
	st_attr = XVaCreateNestedList(0, XNAreaNeeded, &st_area_needed, NULL);
	ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
    }
    ic_a[ic_cnt] = (XPointer) NULL;

    if (ic_cnt > 0) {
	XGetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], NULL);
	if (pe_attr) XFree(pe_attr);
	if (st_attr) XFree(st_attr);
	if (p->xic == NULL) {
	    p->openic_error = True;
	    return;
	}
	pe_attr = st_attr = NULL;
	ic_cnt = 0;
	if (p->input_style & XIMStatusArea) {
	    st_area.height = st_area_needed->height;
	    st_area.x = 0;
	    st_area.y = height - st_area.height;
	    if (p->input_style & XIMPreeditArea) {
		st_area.width = st_area_needed->width;
	    } else {
		st_area.width = width;
	    }

	    XFree(st_area_needed);
	    st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
	    ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	    ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
	}
	if (p->input_style & XIMPreeditArea) {
	    if (p->input_style & XIMStatusArea) {
		pe_area.x = st_area.width;
		pe_area.width = width - st_area.width;
	    } else {
		pe_area.x = 0;
		pe_area.width = width;
	    }
	    pe_area.height = pe_area_needed->height;
	    XFree(pe_area_needed);
	    pe_area.y = height - pe_area.height;
	    pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
	    ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	    ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
	}
	ic_a[ic_cnt] = (XPointer) NULL;
	XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], NULL);
	if (pe_attr) XFree(pe_attr);
	if (st_attr) XFree(st_attr);
	if (p->xic == NULL) {
	    p->openic_error = True;
	    return;
	}
    }
}
Esempio n. 21
0
static void
SetICValues(Widget w, XawVendorShellExtPart *ve, Bool focus)
{
    XawIcTableList	p;
    XPoint		position;
    XRectangle		pe_area;
    XVaNestedList	pe_attr = NULL, st_attr = NULL;
    XPointer		ic_a[20], pe_a[20], st_a[20];
    int			ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
    XawTextMargin	*margin;
    int			height = 0;

    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
	(p->xic == NULL)) return;

    if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, TRUE);
    XFlush(XtDisplay(w));
    if (focus == FALSE &&
	!(p->flg & (CIFontSet | CIFg | CIBg |
		    CIBgPixmap | CICursorP | CILineS))) return;
#ifdef SPOT
    if ((p->input_style & XIMPreeditPosition)
	&& ((!IsSharedIC(ve) && ((p->flg & ~CIICFocus) == CICursorP))
	    || (IsSharedIC(ve) && p->flg == CICursorP))) {
	_XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
	_XipChangeSpot(p->xic, position.x, position.y);
	p->flg &= ~CICursorP;
	return;
    }
#endif

    if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
	if (p->flg & CIFontSet) {
	    pe_a[pe_cnt] = (XPointer) XNFontSet; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) p->font_set; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNFontSet; st_cnt++;
	    st_a[st_cnt] = (XPointer) p->font_set; st_cnt++;
	    if (p->font_set) {
		height = maxAscentOfFontSet(p->font_set)
		    + maxDescentOfFontSet(p->font_set);
	    }
	    height = SetVendorShellHeight(ve, height);
	}
	if (p->flg & CIFg) {
	    pe_a[pe_cnt] = (XPointer) XNForeground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->foreground; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNForeground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->foreground; st_cnt++;
	}
	if (p->flg & CIBg) {
	    pe_a[pe_cnt] = (XPointer) XNBackground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->background; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->background; st_cnt++;
	}
	if (p->flg & CIBgPixmap) {
	    pe_a[pe_cnt] = (XPointer) XNBackgroundPixmap; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackgroundPixmap; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; st_cnt++;
	}
	if (p->flg & CILineS) {
	    pe_a[pe_cnt] = (XPointer) XNLineSpace; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->line_spacing; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNLineSpace; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->line_spacing; st_cnt++;
	}
    }
    if (p->input_style & XIMPreeditPosition) {
	if (p->flg & CICursorP) {
	    _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
	    pe_a[pe_cnt] = (XPointer) XNSpotLocation; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) &position; pe_cnt++;
	}
    }
    if (IsSharedIC(ve)) {
	if (p->input_style & XIMPreeditPosition) {
	    pe_area.x = 0;
	    pe_area.y = 0;
	    pe_area.width = w->core.width;
	    pe_area.height = w->core.height;
	    margin = &(((TextWidget)w)->text.margin);
	    pe_area.x += margin->left;
	    pe_area.y += margin->top;
	    pe_area.width -= (margin->left + margin->right - 1);
	    pe_area.height -= (margin->top + margin->bottom - 1);
	    pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++;
	}
    }

    if (pe_cnt > 0) {
	pe_a[pe_cnt] = (XPointer) NULL;
	pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3],
				      pe_a[4], pe_a[5], pe_a[6], pe_a[7],
				      pe_a[8], pe_a[9], pe_a[10], pe_a[11],
				      pe_a[12], pe_a[13], pe_a[14], pe_a[15],
				      pe_a[16], pe_a[17], pe_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
    }
    if (st_cnt > 0) {
	st_a[st_cnt] = (XPointer) NULL;
	st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3],
				      st_a[4], st_a[5], st_a[6], st_a[7],
				      st_a[8], st_a[9], st_a[10], st_a[11],
				      st_a[12], st_a[13], st_a[14], st_a[15],
				      st_a[16], st_a[17], st_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
    }
    if (focus == TRUE) {
	ic_a[ic_cnt] = (XPointer) XNFocusWindow; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) (uintptr_t)XtWindow(w); ic_cnt++;
    }
    if (ic_cnt > 0) {
	ic_a[ic_cnt] = (XPointer) NULL;
	XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4],
		     ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9], ic_a[10],
		     ic_a[11], ic_a[12], ic_a[13], ic_a[14], ic_a[15],
		     ic_a[16], ic_a[17], ic_a[18], NULL);
	if (pe_attr) XtFree(pe_attr);
	if (st_attr) XtFree(st_attr);
    }

    if (IsSharedIC(ve) && p->flg & CIFontSet)
	SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);

    p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS);
}
Esempio n. 22
0
static void
CreateIC(Widget w, XawVendorShellExtPart *ve)
{
    XawIcTableList	p;
    XPoint		position;
    XRectangle		pe_area, st_area;
    XVaNestedList	pe_attr = NULL, st_attr = NULL;
    XPointer		ic_a[20], pe_a[20], st_a[20];
    Dimension		height = 0;
    int			ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
    XawTextMargin	*margin;

    if (!XtIsRealized(w)) return;
    if (((ve->im.xim == NULL) || (p = GetIcTableShared(w, ve)) == NULL) ||
	p->xic || (p->openic_error != FALSE)) return;

    p->input_style = GetInputStyleOfIC(ve);

    if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, FALSE);
    XFlush(XtDisplay(w));

    if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
	if (p->flg & CIFontSet) {
	    pe_a[pe_cnt] = (XPointer) XNFontSet; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) p->font_set; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNFontSet; st_cnt++;
	    st_a[st_cnt] = (XPointer) p->font_set; st_cnt++;
	    if (p->font_set) {
		height = maxAscentOfFontSet(p->font_set)
		    + maxDescentOfFontSet(p->font_set);
	    }
	    height = SetVendorShellHeight(ve, height);
	}
	if (p->flg & CIFg) {
	    pe_a[pe_cnt] = (XPointer) XNForeground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->foreground; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNForeground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->foreground; st_cnt++;
	}
	if (p->flg & CIBg) {
	    pe_a[pe_cnt] = (XPointer) XNBackground; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->background; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackground; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->background; st_cnt++;
	}
	if (p->flg & CIBgPixmap) {
	    pe_a[pe_cnt] = (XPointer) XNBackgroundPixmap; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNBackgroundPixmap; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->bg_pixmap; st_cnt++;
	}
	if (p->flg & CILineS) {
	    pe_a[pe_cnt] = (XPointer) XNLineSpace; pe_cnt++;
	    pe_a[pe_cnt] = (XPointer) (uintptr_t)p->line_spacing; pe_cnt++;
	    st_a[st_cnt] = (XPointer) XNLineSpace; st_cnt++;
	    st_a[st_cnt] = (XPointer) (uintptr_t)p->line_spacing; st_cnt++;
	}
    }
    if (p->input_style & XIMPreeditArea) {
	pe_area.x = 0;
	pe_area.y = ve->parent->core.height - height;
	pe_area.width = ve->parent->core.width;
	pe_area.height = height;
	pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++;
	pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++;
    }
    if (p->input_style & XIMPreeditPosition) {
	pe_area.x = 0;
	pe_area.y = 0;
	pe_area.width = w->core.width;
	pe_area.height = w->core.height;
	margin = &(((TextWidget)w)->text.margin);
	pe_area.x += margin->left;
	pe_area.y += margin->top;
	pe_area.width -= (margin->left + margin->right - 1);
	pe_area.height -= (margin->top + margin->bottom - 1);
	pe_a[pe_cnt] = (XPointer) XNArea; pe_cnt++;
	pe_a[pe_cnt] = (XPointer) &pe_area; pe_cnt++;
	if (p->flg & CICursorP) {
	    _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
	} else {
	    position.x = position.y = 0;
	}
	pe_a[pe_cnt] = (XPointer) XNSpotLocation; pe_cnt++;
	pe_a[pe_cnt] = (XPointer) &position; pe_cnt++;
    }
    if (p->input_style & XIMStatusArea) {
	st_area.x = 0;
	st_area.y = ve->parent->core.height - height;
	st_area.width = ve->parent->core.width;
	st_area.height = height;
	st_a[st_cnt] = (XPointer) XNArea; st_cnt++;
	st_a[st_cnt] = (XPointer) &st_area; st_cnt++;
    }

    ic_a[ic_cnt] = (XPointer) XNInputStyle; ic_cnt++;
    ic_a[ic_cnt] = (XPointer) (uintptr_t)p->input_style; ic_cnt++;
    ic_a[ic_cnt] = (XPointer) XNClientWindow; ic_cnt++;
    ic_a[ic_cnt] = (XPointer) (uintptr_t)XtWindow(ve->parent); ic_cnt++;
    ic_a[ic_cnt] = (XPointer) XNFocusWindow; ic_cnt++;
    ic_a[ic_cnt] = (XPointer) (uintptr_t)XtWindow(w); ic_cnt++;

    if (pe_cnt > 0) {
	pe_a[pe_cnt] = (XPointer) NULL;
	pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3],
				   pe_a[4], pe_a[5], pe_a[6], pe_a[7], pe_a[8],
				   pe_a[9], pe_a[10], pe_a[11], pe_a[12],
				   pe_a[13], pe_a[14], pe_a[15], pe_a[16],
				   pe_a[17], pe_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNPreeditAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) pe_attr; ic_cnt++;
    }

    if (st_cnt > 0) {
	st_a[st_cnt] = (XPointer) NULL;
	st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3],
				   st_a[4], st_a[5], st_a[6], st_a[7], st_a[8],
				   st_a[9], st_a[10], st_a[11], st_a[12],
				   st_a[13], st_a[14], st_a[15], st_a[16],
				   st_a[17], st_a[18],  NULL);
	ic_a[ic_cnt] = (XPointer) XNStatusAttributes; ic_cnt++;
	ic_a[ic_cnt] = (XPointer) st_attr; ic_cnt++;
    }
    ic_a[ic_cnt] = (XPointer) NULL;

    p->xic = XCreateIC(ve->im.xim, ic_a[0], ic_a[1], ic_a[2], ic_a[3],
		       ic_a[4], ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9],
		       ic_a[10], ic_a[11], ic_a[12], ic_a[13], ic_a[14],
		       ic_a[15], ic_a[16], ic_a[17], ic_a[18], NULL);
    if (pe_attr) XtFree(pe_attr);
    if (st_attr) XtFree(st_attr);

    if (p->xic == NULL) {
	p->openic_error = True;
	return;
    }

    SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);

    p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS);

    if (!IsSharedIC(ve)) {
	if (p->input_style & XIMPreeditPosition) {
	    XtAddEventHandler(w, (EventMask)StructureNotifyMask, FALSE,
			      (XtEventHandler)ConfigureCB, (Opaque)NULL);
	}
    }
}