home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / fj / maillis / xwindow / 18936 < prev    next >
Encoding:
Text File  |  1992-12-28  |  8.0 KB  |  253 lines

  1. Path: sparky!uunet!stanford.edu!sun-barr!sh.wide!wnoc-tyo-news!scslwide!wsgw!wsservra!onoe
  2. From: cpg@cs.utexas.edu (Carlos M. Puchol)
  3. Newsgroups: fj.mail-lists.x-window
  4. Subject: Scrolling canvases in XView3
  5. Message-ID: <1992Dec28.140121.25767@sm.sony.co.jp>
  6. Date: 28 Dec 92 14:01:21 GMT
  7. Sender: onoe@sm.sony.co.jp (Atsushi Onoe)
  8. Distribution: fj
  9. Organization: Department of Computer Sciences, UT Austin
  10. Lines: 240
  11. Approved: michael@sm.sony.co.jp
  12.  
  13. Date: 28 Dec 92 12:29:38 GMT
  14. Message-Id: <ljtspiINNb1v@thor.cs.utexas.edu>
  15. Newsgroups: comp.windows.open-look,comp.windows.x,alt.toolkits.xview
  16. Sender: xpert-request@expo.lcs.mit.edu
  17.  
  18. Hi I am having a problem with the XView toolkit. It may be a bug,
  19. since the behaviour I get is different than what it is said
  20. in the manual (Vol 7 of the X Series). If anyone has any clue
  21. if I am right and the manual is wrong or the opposite,
  22. please let me know.
  23.  
  24. I have a canvas and the canvas paint window is much bigger than
  25. the view window, so I install scrollbars in the canvas. Initially,
  26. C is visible and W is not.
  27.  
  28.     ------------------
  29.     |         |      |
  30.     | canvas  |      |
  31.     |   C     |  W   |
  32.     |         |      |
  33.     |---------.      |
  34.     |                |
  35.     |  paint window  |
  36.     |                |
  37.     ------------------
  38.  
  39. When the scrollbars are pushed, the resize callback is called. The
  40. params that it receives are the actual width and height of the paint
  41. window.
  42.  
  43. The manual (third edition, page 99) says that ...
  44.  
  45.     "If the user scrolls the canvas, your canvas repaint procedure
  46.      will be called provided that the canvas WIN_RETAINED is set
  47.      to FALSE."
  48.  
  49. If WIN_RETAINED is TRUE the repaint procedure is not called either.
  50.  
  51. Now, in my application, the graphics in the whole W area are drawn
  52. at the beginning of the program. If I draw some simple graphics (or
  53. strings or somesuch), when I scroll C to see part of the area in W,
  54. the graphics are there (no problem). I draw some simple junk graphics
  55. for debugging purposes.
  56.  
  57. In the "real" application I have several Pixmaps that I copy (XCopyArea)
  58. at the beginning of the program (basically shapes). There are lines which
  59. join the shapes. When the whole thing is up, if I scroll C to see part of
  60. W, I see "some" lines, but the rest of the window is blank (including the
  61. background, which should be filled with the bacground Pixmap in the Graphic
  62. Context).
  63.  
  64. My understanding after reading the manual is that the repaint proc should
  65. be called with the newly exposed area if:
  66.  
  67.     WIN_RETAINED is set to FALSE
  68. or
  69.     (WIN_RETAINED  is set to TRUE) _and_ (the server has not saved
  70.     the area just exposed)
  71.  
  72. I enclose a modified version of the program canvas_event.c from the manual,
  73. which ilustrates the problems I have. Note that in this case, in my server
  74. (and I guess in most servers) when the user scrolls, the strings are seen in
  75. the W area, since the server keeps it.
  76.  
  77. Thanks a bunch in advance,
  78.  
  79. -- Carlos Puchol (cpg@cs.utexas.edu)
  80.  
  81. /*
  82.  *  canvas_event.c
  83.  *  Demonstrates how to get keyboard and mouse events in an canvas
  84.  *  window.  Looks for keyboards, pointer movement and button
  85.  *  events and displays the info in the canvas.
  86.  */
  87. #include <X11/Xlib.h>
  88. #include <xview/xview.h>
  89. #include <xview/canvas.h>
  90. #include <xview/xv_xrect.h>
  91. #include <xview/scrollbar.h>
  92.  
  93. void    event_proc(), repaint_proc(), resize_proc();
  94. char    kbd_msg[128], ptr_msg[128], but_msg[128];
  95.  
  96. /*
  97.  * main()
  98.  *      Create a canvas specifying a repaint procedure.
  99.  *      Get the paint window for the canvas and set the input
  100.  *      mask and the event procedure.
  101.  */
  102. main(argc, argv)
  103. int argc;
  104. char *argv[];
  105. {
  106.     Frame       frame;
  107.     Canvas      canvas;
  108.  
  109.     /* Initialize XView */
  110.     xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  111.  
  112.     /* Create windows -- base frame and canvas. */
  113.     frame = (Frame)xv_create(NULL, FRAME, NULL);
  114.  
  115.     canvas = (Canvas)xv_create(frame, CANVAS,
  116.         XV_WIDTH,               400,
  117.         XV_HEIGHT,              400,
  118.     WIN_RETAINED, FALSE,
  119.     CANVAS_AUTO_EXPAND, TRUE,
  120.     CANVAS_AUTO_SHRINK, FALSE,
  121.         CANVAS_X_PAINT_WINDOW,  TRUE,
  122.         CANVAS_REPAINT_PROC,    repaint_proc,
  123.     CANVAS_RESIZE_PROC, resize_proc,
  124.         NULL);
  125.     window_fit(frame);
  126.  
  127.     xv_create(canvas, SCROLLBAR,
  128.     SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
  129.     SCROLLBAR_PIXELS_PER_UNIT, 25,
  130.     NULL);
  131.  
  132.     xv_create(canvas, SCROLLBAR,
  133.     SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
  134.     SCROLLBAR_PIXELS_PER_UNIT, 25,
  135.     NULL);
  136.  
  137.     xv_set(canvas,
  138.     CANVAS_WIDTH, 1200,
  139.     CANVAS_HEIGHT, 1200,
  140.     NULL);
  141.  
  142.  
  143.     /* No input mask */
  144.  
  145.     /* Initial messages */
  146.     strcpy(kbd_msg, "Keyboard: key press events");
  147.     strcpy(ptr_msg, "Pointer: pointer movement events");
  148.     strcpy(but_msg, "Button: button press events");
  149.  
  150.     /* Start event loop */
  151.     xv_main_loop(frame);
  152. }
  153.  
  154. /*
  155.  * event_proc()
  156.  *      Called when an event is received in the canvas window.
  157.  *      Updates the keyboard, pointer and button message strings
  158.  *      and then calls repaint_proc() to paint them to the window.
  159.  */
  160. void
  161. event_proc(window, event)
  162. Xv_Window window;
  163. Event    *event;
  164. {
  165.     if (event_is_ascii(event))
  166.         sprintf(kbd_msg, "Keyboard: key '%c' %d pressed at %d,%d",
  167.                 event_action(event), event_action(event),
  168.                 event_x(event), event_y(event));
  169.     else
  170.         switch (event_action(event)) {
  171.             case KBD_USE:
  172.                 sprintf(kbd_msg, "Keyboard: got keyboard focus");
  173.                 break;
  174.             case KBD_DONE:
  175.                 sprintf(kbd_msg, "Keyboard: lost keyboard focus");
  176.                 break;
  177.             case LOC_MOVE:
  178.                 sprintf(ptr_msg, "Pointer: moved to %d,%d",
  179.                     event_x(event), event_y(event));
  180.                 break;
  181.             case LOC_DRAG:
  182.                 sprintf(ptr_msg, "Pointer: dragged to %d,%d",
  183.                     event_x(event), event_y(event));
  184.                 break;
  185.             case LOC_WINENTER:
  186.                 sprintf(ptr_msg, "Pointer: entered window at %d,%d",
  187.                     event_x(event), event_y(event));
  188.                 break;
  189.             case LOC_WINEXIT:
  190.                 sprintf(ptr_msg, "Pointer: exited window at %d,%d",
  191.                     event_x(event), event_y(event));
  192.                 break;
  193.             case ACTION_SELECT:
  194.             case MS_LEFT:
  195.                 sprintf(but_msg, "Button: Select (Left) at %d,%d",
  196.                     event_x(event), event_y(event));
  197.                 break;
  198.             case ACTION_ADJUST:
  199.             case MS_MIDDLE:
  200.                 sprintf(but_msg, "Button: Adjust (Middle) at %d,%d",
  201.                     event_x(event), event_y(event));
  202.                 break;
  203.             case ACTION_MENU:
  204.             case MS_RIGHT:
  205.                 sprintf(but_msg, "Button: Menu (Right) at %d,%d",
  206.                     event_x(event), event_y(event));
  207.                 break;
  208.             default:
  209.                 return;
  210.         }
  211.  
  212.     /* call repaint proc directly to update messages */
  213.     repaint_proc((Canvas)NULL, window,
  214.         (Display *)xv_get(window, XV_DISPLAY),
  215.         xv_get(window, XV_XID), (Xv_xrectlist *) NULL);
  216. }
  217.  
  218. /*
  219.  * repaint_proc()
  220.  *      Called to repaint the canvas in response to damage events
  221.  *      and the initial painting of the canvas window.
  222.  *      Displays the keyboard, pointer and button message strings
  223.  *      after erasing the previous messages.
  224.  */
  225. void
  226. repaint_proc(canvas, paint_window, dpy, xwin, xrects)
  227. Canvas        canvas;           /* Ignored */
  228. Xv_Window     paint_window;     /* Ignored */
  229. Display      *dpy;
  230. Window        xwin;
  231. Xv_xrectlist *xrects;           /* Ignored */
  232. {
  233.     GC gc = DefaultGC(dpy, DefaultScreen(dpy));
  234.     int i;
  235.  
  236.     fprintf(stderr,"Repaint called.\n");
  237.     XClearWindow(dpy, xwin);
  238.     XDrawString(dpy, xwin, gc, 25, 25, kbd_msg, strlen(kbd_msg));
  239.     XDrawString(dpy, xwin, gc, 25, 50, ptr_msg, strlen(ptr_msg));
  240.     XDrawString(dpy, xwin, gc, 25, 75, but_msg, strlen(but_msg));
  241.     for (i=0; i < 100; i++)
  242.         XDrawString(dpy, xwin, gc, 25+i*10, 75+i*10, but_msg, strlen(but_msg));
  243. }
  244.  
  245.  
  246. void resize_proc(canvas, width, height)
  247. Canvas  canvas;
  248. int     width, height;
  249. {
  250.         fprintf(stderr, "Resize callback called with W:%d H:%d.\n",
  251.                 width, height);
  252. }
  253.