home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume7 / xdm / patch1.02 / xroutines.c < prev   
Encoding:
C/C++ Source or Header  |  1990-06-08  |  2.7 KB  |  137 lines

  1. #include "xdmconsole.h"
  2.  
  3. Display   *disp;
  4. Window     win;
  5. GC         wingc;
  6. XFontStruct        *font;
  7. XEvent     thebigevent;
  8. XSizeHints hinthint;
  9. Cursor     wincurs, opwincurs;
  10. int        screen;
  11. long       foreg, backg;
  12. int       winw, winh;
  13.  
  14.  
  15. int initwin(width, height, x, y, border, trans, name)
  16. int width, height, x, y, border, trans;
  17. char *name;
  18. {
  19.  
  20.     if (win > 0) return(-1);
  21.  
  22.     if ((disp = XOpenDisplay("unix:0.0")) == NULL) exit(0);
  23.     screen=DefaultScreen(disp);
  24.  
  25.     if (x < 0) x = (int) ((DisplayWidth(disp, screen) - width) /2);
  26.     if (y < 0) y = (int) (DisplayHeight(disp, screen) - (height + 30));
  27.  
  28.         backg=WhitePixel(disp, screen);
  29.         foreg=BlackPixel(disp, screen);
  30.  
  31.     win=XCreateSimpleWindow(disp, DefaultRootWindow(disp),
  32.                 x, y, width, height, 
  33.                 border, foreg, backg);
  34.  
  35.         wingc=XCreateGC(disp, win, 0, 0);
  36.         XSetBackground(disp, wingc, backg);
  37.         XSetForeground(disp, wingc, foreg);
  38.  
  39.         XStoreName(disp, win, name);
  40.  
  41.     if (trans) XSetTransientForHint(disp, win, win);
  42.     winh=height;
  43.     winw=width;
  44. }
  45.  
  46. int winfont(fontname)
  47. char *fontname;
  48. {
  49.     int ndirs;
  50.     char **dir;
  51.  
  52.     dir = XGetFontPath(disp, &ndirs);
  53.     dir[ndirs] = (char *) malloc(sizeof("/usr/lib/X11/fonts/75dpi")+2);
  54.     strcpy(dir[ndirs++], "/usr/lib/X11/fonts/75dpi");
  55.     XSetFontPath(disp, dir, ndirs);
  56.     font=XLoadQueryFont(disp, fontname);
  57.         XSetFont(disp, wingc, font->fid);
  58.     XFreeFontPath(dir);
  59. }
  60.  
  61. int wincursor(cursor)
  62. char *cursor;
  63. {
  64.         wincurs=XCreateFontCursor(disp, XC_gumby);
  65.         XDefineCursor(disp, win, wincurs);
  66. }
  67.  
  68. int winevents(event) 
  69. long event;
  70. {
  71.     XSelectInput(disp, win, event);
  72. }
  73.  
  74.  
  75. int winprint(x, y, string)
  76. int x, y;
  77. char *string;
  78. {
  79.     XDrawString(disp, win, wingc, x, y, string, strlen(string));
  80.     XFlush(disp);
  81. }
  82.  
  83. int winwrapprint(x, y, string, inc)
  84. int x, y;
  85. char *string;
  86. int inc;
  87. {
  88.     int count=0;
  89.     if (XTextWidth(font, string, strlen(string)) > winw)
  90.     {
  91.         for (count=strlen(string); XTextWidth(font, string, count) > winw; count--);
  92.         XDrawString(disp, win, wingc, x, y, string, count);
  93.         scrollup(inc);
  94.         XDrawString(disp, win, wingc, x, y, &string[count+1], strlen(&string[count+1]));
  95.         XFlush(disp);
  96.         return(1);
  97.     }
  98.     XDrawString(disp, win, wingc, x, y, string, strlen(string));
  99.     XFlush(disp);
  100.     return(0);
  101. }
  102.  
  103. int showwin()
  104. {
  105.     XMapRaised(disp, win);
  106.     XFlush(disp);
  107.     XNextEvent(disp, &thebigevent);
  108. }
  109.  
  110. int clearwin()
  111. {
  112.     XClearWindow(disp, win);
  113. }
  114.  
  115. int scrollup(lineheight)
  116. int lineheight;
  117. {
  118.     int     x, y, height, width;
  119.  
  120.     x=0;
  121.     y=lineheight;
  122.     width=winw;
  123.     height=winh-lineheight;
  124.     XCopyArea(disp, win, win, wingc, x, y, width, height, 0, 0);
  125.     XClearArea(disp, win, 0, height, width, lineheight, False);
  126.     XFlush(disp);
  127. }
  128.  
  129. int windeath()
  130. {
  131.     XFreeFont(disp, font);
  132.     XFreeGC(disp, wingc);
  133.     XDestroyWindow(disp, win);
  134.     win = 0;
  135.     XCloseDisplay(disp);
  136. }
  137.