示例#1
0
static int DefWndProc(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event)
{
    XComposeStatus status;
    KeySym         keysym;
    char           c[BUFSIZE+1];

#ifdef DEBUG
    printf("DefWndProc\n");
#endif
    switch (event->type)
    {
        case Expose:
        case ButtonPress:
        case KeyPress:
            if (HelpPressed(event))
            {
                return HELPPRESSED;
            }
            else
            {
                XLookupString(&(event->xkey), c, BUFSIZE, &keysym, &status);
                if ((keysym == XK_Return) || (keysym == XK_KP_Enter))
                {
                    return ENTERPRESSED;
                }
            }
            break;
        case EnterNotify:
            dlgitem->win.bFocus = TRUE;
            ShowCaret(x11, dlgitem);
            /*    LightBorder(x11->disp,dlgitem->win.self,x11->fg); */
            break;
        case LeaveNotify:
            dlgitem->win.bFocus = FALSE;
            HideCaret(x11, dlgitem);
            /*    LightBorder(x11->disp,dlgitem->win.self,x11->bg); */
            break;
        default:
            XBell(x11->disp, 50);
    }
    return ITEMOK;
}
示例#2
0
static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event)
{
    t_edittext *et;
    t_windata  *win;
    KeySym      keysym;
    char        c[BUFSIZE+1], *bp;
    char        scrbuf[STRLEN];
    int         i, xp, xtitle, ewidth;

    if (dlgitem->type != edlgET)
    {
        gmx_incons("st processing");
    }
    et  = &(dlgitem->u.edittext);
    win = &(dlgitem->win);

    /* Copy string part that is visible into screen buffer */
    for (i = 0; (i < et->buflen); i++)
    {
        scrbuf[i] = et->buf[i+et->strbegin];
    }
    scrbuf[i] = '\0';

    switch (event->type)
    {
        case Expose:
            XSetForeground(x11->disp, x11->gc, x11->fg);
            xtitle = XTextWidth(x11->font, win->text, strlen(win->text));
            ewidth = win->width-xtitle;
            TextInRect(x11, win->self, win->text,
                       0, 0, xtitle-1, win->height, eXLeft, eYCenter);
            XClearArea(x11->disp, win->self, xtitle, 0, ewidth+XCARET, win->height, False);
            TextInRect(x11, win->self, scrbuf,
                       xtitle+XCARET, 0, ewidth, win->height, eXLeft, eYCenter);
#ifdef DEBUG
            printf("Expose\n");
#endif
            if (win->bFocus)
            {
                ShowCaret(x11, dlgitem);
            }
            break;
        case ButtonPress:
            /* Calculate new position for caret */
            et->pos = strlen(et->buf);
            bp      = strdup(et->buf);
            xp      = event->xbutton.x-XTextWidth(x11->font, win->text, strlen(win->text))-
                XCARET;
            while ((et->pos > 0) && (XTextWidth(x11->font, bp, strlen(bp)) > xp))
            {
                et->pos--;
                bp[et->pos] = '\0';
            }
            sfree(bp);
            et->bChanged = TRUE;
            return ETCHANGED;
        case KeyPress:
            /* Check for HelpKey */
            if (HelpPressed(event))
            {
                return DefWndProc(x11, dlgitem, event);
            }
            XLookupString(&(event->xkey), c, BUFSIZE, &keysym, NULL);
#ifdef DEBUG
            printf("Keysym: %x\n", keysym);
#endif
            switch (keysym)
            {
                case XK_Delete:
                    if (my_delete(et->buf, &(et->pos)))
                    {
                        et->bChanged = TRUE;
                        return ETCHANGED;
                    }
                    else
                    {
                        XBell(x11->disp, 50);
                    }
                    break;
                case XK_BackSpace:
                    if (my_backspace(et->buf, &(et->pos)))
                    {
                        et->bChanged = TRUE;
                        return ETCHANGED;
                    }
                    else
                    {
                        XBell(x11->disp, 50);
                    }
                    break;
                case XK_KP_Enter:
                case XK_Return:
                    return ENTERPRESSED;
                case XK_Home:
                    et->pos      = 0;
                    et->strbegin = 0;
                    et->bChanged = TRUE;
                    return ETCHANGED;
                case XK_End:
                    if (strlen(et->buf) <= et->buflen)
                    {
                        et->pos = strlen(et->buf);
                    }
                    else
                    {
                        et->pos      = et->buflen;
                        et->strbegin = strlen(et->buf)-et->buflen;
                    }
                    et->bChanged = TRUE;
                    return ETCHANGED;
                case XK_Left:
                    et->pos      = max(0, et->pos-1);
                    et->strbegin = min(et->strbegin, et->pos);
                    et->bChanged = TRUE;
                    return ETCHANGED;
                case XK_Right:
                    if ((et->pos < et->buflen) && (et->strbegin+et->buflen > strlen(et->buf)))
                    {
                        et->pos++;
                    }
                    else if ((et->buflen   < strlen(et->buf)) &&
                             (et->strbegin < strlen(et->buf)-et->buflen))
                    {
                        et->strbegin++;
                    }
                    else
                    {
                        break;
                    }
                    et->bChanged = TRUE;
                    return ETCHANGED;
                default:
                    if (keysym < 256)
                    {
                        if (insert(et->buf, c[0], &(et->pos)))
                        {
                            et->bChanged = TRUE;
                            return ETCHANGED;
                        }
                    }
                    XBell(x11->disp, 50);
                    break;
            }
            break;
        case LeaveNotify:
            win->bFocus = FALSE;
            HideCaret(x11, dlgitem);
            if (et->bChanged)
            {
                et->bChanged = FALSE;
            }
            break;
        default:
            return DefWndProc(x11, dlgitem, event);
    }
    return ITEMOK;
}
示例#3
0
static bool DlgCB(t_x11 *x11,XEvent *event, Window w, void *data)
{
  t_dlg     *dlg=(t_dlg *)data;
  int	    i,nWndProc;
  t_dlgitem *dlgitem;
  
  if ((dlgitem=FindWin(dlg,w))!=NULL) {
    nWndProc=(dlgitem->WndProc)(x11,dlgitem,event);
#ifdef DEBUG
    fprintf(x11->console,
	    "window: %s, nWndProc: %d\n",dlgitem->win.text,nWndProc);
    x11->Flush(x11);
#endif
    switch (nWndProc) {
    case ENTERPRESSED:
      if ((dlgitem->type==edlgBN) && (dlgitem->u.button.bDefault)) {
	if (dlg->cb)
	  dlg->cb(x11,DLG_EXIT,dlgitem->ID,dlgitem->win.text,dlg->data);
	else
	  ExitDlg(dlg);
      }
      else {
	for(i=0; (i<dlg->nitem); i++)
	  if ((dlg->dlgitem[i]->type==edlgBN) && 
	      (dlg->dlgitem[i]->u.button.bDefault)) {
	    PushMouse(x11->disp,dlg->dlgitem[i]->win.self,
		      dlg->dlgitem[i]->win.width/2,
		      dlg->dlgitem[i]->win.height/2);
	    break;
	  }
      }
      break;
    case BNPRESSED:
      if (dlg->cb)
	dlg->cb(x11,DLG_EXIT,dlgitem->ID,dlgitem->win.text,dlg->data);
      else 
	ExitDlg(dlg);
      break;
    case RBPRESSED: {
      int  gid=dlgitem->GroupID;
      t_id tid=RBSelected(dlg,gid);
#ifdef DEBUG
      fprintf(stderr,"RBPRESSED\n");
#endif
      if (tid != -1) {
	t_dlgitem *dit=FindItem(dlg,tid);
	dit->u.radiobutton.bSelect=FALSE;
	ExposeWin(x11->disp,dit->win.self);
      }
      else
	gmx_fatal(FARGS,"No RB Selected initially!\n");
      dlgitem->u.radiobutton.bSelect=TRUE;
      ExposeWin(x11->disp,dlgitem->win.self);
      if (dlg->cb)
	dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->win.text,dlg->data);
      break;
    }
    case CBPRESSED:
      ExposeWin(x11->disp,dlgitem->win.self);
      if (dlg->cb)
	dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->set,dlg->data);
      break;
    case ETCHANGED:
      ExposeWin(x11->disp,dlgitem->win.self);
      if (dlg->cb)
	dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->u.edittext.buf,dlg->data);
      break;
    case HELPPRESSED:
      HelpNow(dlg,dlgitem);
      break;
    case ITEMOK:
      break;
    default:
      gmx_fatal(FARGS,"Invalid return code (%d) from wndproc\n",nWndProc);
    }
  }
  else if (w==dlg->win.self) {
    switch(event->type) {
    case Expose:
      EnterDlg(dlg);
      break;
    case ButtonPress:
    case KeyPress:
      if (HelpPressed(event))
	HelpDlg(dlg);
      else
	XBell(x11->disp,50);
      break;
    default:
      break;
    }
  }
  return FALSE;
}