home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Box / box_event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  3.0 KB  |  154 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include "box_types.h"
  4. #include "box_global.h"
  5.  
  6. BoxEvent(gnrc,event)
  7.  
  8. BoxStatus *gnrc;
  9. XEvent *event;
  10.  
  11. {
  12.   XWindowAttributes xwa;
  13.   XWindowChanges xwc;
  14.   int i;
  15.  
  16.   switch(event->type) {
  17.  
  18.      case Expose:
  19.  
  20.        if(event->xexpose.count > 0) {
  21.           break;
  22.          }
  23.  
  24.  
  25.        if(event->xexpose.window == gnrc->TitleWindow) {
  26.           ReDrawBoxTitleWindow(gnrc);
  27.           break;
  28.          }
  29.  
  30.        if(event->xexpose.window == gnrc->MessageWindow) {
  31.           ReDrawBoxMessageWindow(gnrc);
  32.           break;
  33.          }
  34.  
  35.        if(event->xexpose.window == gnrc->TopWindow) {
  36.           ReDrawBoxTopWindow(gnrc);
  37.           break;
  38.          }
  39.  
  40.        break;
  41.  
  42.      case ButtonPress:
  43.        if(event->xbutton.window == gnrc->TopWindow) {
  44.           BoxButtonPress(gnrc,event);
  45.          }
  46.        break;
  47.  
  48.      case KeyPress:
  49.        if(event->xkey.window == gnrc->TopWindow) {
  50.           BoxKeyPressEvent(gnrc,event);
  51.          }
  52.        break;
  53.  
  54.      case ConfigureNotify:
  55.        if(event->xconfigure.window == gnrc->TopWindow) {
  56.           ReDrawBoxMessageWindow(gnrc);
  57.           ReDrawBoxTitleWindow(gnrc);
  58.          }
  59.        break;
  60.  
  61.      default:
  62.        break;
  63.     }
  64.  
  65. }
  66.  
  67.  
  68. BoxUrgentWindowDialogue(gnrc,prompt_string,return_string)
  69.  
  70. BoxStatus *gnrc;
  71. char *prompt_string,*return_string;
  72.  
  73. /* Routine returns the length of the dialogue string */
  74.  
  75. {
  76.  
  77.   int x,y,pstn;
  78.   char chrctr[2];
  79.   XFontStruct *fontstruct;
  80.   XEvent event;
  81.   XWindowAttributes xwa;
  82.   XWindowChanges xwc;
  83.  
  84.   if(gnrc->UrgentWindow == (Window) 0) return(0);
  85.  
  86.   XGetWindowAttributes(dpy,gnrc->TopWindow,&xwa);
  87.   xwc.width = xwa.width;
  88.   xwc.y = xwa.height/2;
  89.  
  90.   XConfigureWindow(dpy,gnrc->UrgentWindow,(CWWidth|CWY),&xwc);
  91.  
  92.   XMapRaised(dpy,gnrc->UrgentWindow);
  93.  
  94.   XGrabKeyboard(dpy,gnrc->UrgentWindow,False,
  95.                 GrabModeAsync,GrabModeAsync,
  96.                 CurrentTime);
  97.  
  98.   XDrawString(dpy,gnrc->UrgentWindow,gnrc->gc,
  99.               BOX_PAD,BOX_PAD+gnrc->fth,prompt_string,
  100.               strlen(prompt_string));
  101.  
  102.   /* Edit the filename */
  103.  
  104.   fontstruct = gnrc->fontstruct;
  105.  
  106.   pstn = 0;
  107.   chrctr[0] = 0;
  108.   chrctr[1] = 0;   /* for string manipulation */
  109.  
  110.   y = BOX_PAD + gnrc->fth;
  111.   x = BOX_PAD + XTextWidth(fontstruct,prompt_string,strlen(prompt_string));
  112.  
  113.  
  114.   while(chrctr[0] != '\r') {
  115.  
  116.      if((chrctr[0] >= 33) && (chrctr[0] <= 126)) {
  117.  
  118.         XDrawString(dpy,gnrc->UrgentWindow,
  119.                     gnrc->gc,x,y,chrctr,1);
  120.  
  121.         x += XTextWidth(fontstruct,chrctr,1);
  122.  
  123.         return_string[pstn] = chrctr[0];
  124.         pstn++;
  125.  
  126.        }
  127.  
  128.      if((chrctr[0] == 8) || (chrctr[0] == 127)) {
  129.  
  130.         if(pstn > 0) {
  131.            pstn--;
  132.            x -= XTextWidth(fontstruct,&(return_string[pstn]),1);
  133.            XDrawImageString(dpy,gnrc->UrgentWindow,
  134.                             gnrc->gc,x,y," ",1);
  135.           }
  136.  
  137.        }
  138.  
  139.      XMaskEvent(dpy,KeyPressMask,&event);
  140.      if(XLookupString(&(event.xkey),chrctr,1,NULL,NULL) == 0) {
  141.         chrctr[0] = 0;
  142.        }
  143.     }
  144.  
  145.   return_string[pstn] = 0;
  146.  
  147.   XUngrabKeyboard(dpy,CurrentTime);
  148.   XUnmapWindow(dpy,gnrc->UrgentWindow);
  149.  
  150.   return(pstn);
  151.  
  152. }
  153.  
  154.