home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / windows / openloo / 4922 < prev    next >
Encoding:
Text File  |  1992-12-28  |  7.8 KB  |  248 lines

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