home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume21 / pan / part01 / pan3.0 / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  7.1 KB  |  219 lines

  1. /*
  2. Post A Note V3.0
  3. Copyright (c) 1993, Jeffrey W. Bailey
  4. All rights reserved.
  5.  
  6. Permission is granted to distribute this program in exact, complete
  7. source form, which includes this copyright notice, as long as no fee
  8. other than media and distribution cost is charged.
  9.  
  10. This program may not be used in whole, or in part, in any other manner
  11. without prior written permission from the author.
  12.  
  13. This program may not be distributed in modified form without prior
  14. written permission from the author.  In other words, patches may be
  15. distributed, but modified source may not be distributed.
  16.  
  17. If there are any questions, comments or suggestions, the author may be
  18. contacted at:
  19.  
  20.     jeff@rd1.interlan.com
  21.  
  22.     or
  23.  
  24.     Jeffrey Bailey
  25.     Racal-Datacom, Inc.
  26.     Mail Stop E-110
  27.     1601 N. Harrison Parkway
  28.     Sunrise, FL  33323-2899
  29. */
  30.  
  31. #include "pan.h"
  32.  
  33. extern int errno;
  34. extern char *sys_errlist[];
  35.  
  36. /*
  37.     Handle the window exit event of the mouse pointer.  Used to do auto-saves.
  38.     This trick on a frame is not specifically documented, but seems to work.
  39.     I hope it doesn't break in the future.
  40. */
  41. frameexit(frame, event, arg)
  42.     Frame frame;
  43.     Event *event;
  44.     Notify_arg arg;
  45.     {
  46.     int  found = 0;
  47.     struct SubDir *sp;
  48.     struct Note *np;
  49.  
  50.     if(event_id(event) != LOC_WINEXIT) return;
  51.     if(debug_on) fprintf(stderr, "Got LOC_WINEXIT\n");
  52.  
  53.     sp = (struct SubDir *) LLM_first(&subdir_rt);
  54.     while(sp != NULL && !found)
  55.         {
  56.         np = (struct Note *) LLM_first(&sp->note_rt);
  57.         while(np != NULL && !found)
  58.             {
  59.             if(np->frame == frame && np->mapped)
  60.                 {
  61.                 update(np);
  62.                 updateinfo(np, NOFORCE);
  63.                 found = 1;
  64.                 }
  65.             np = (struct Note *) LLM_next(&sp->note_rt);
  66.             }
  67.         sp = (struct SubDir *) LLM_next(&subdir_rt);
  68.         }
  69.  
  70.     }
  71.  
  72. /*
  73.     Handles a drag & drop event from the file manager into a note, retrieving
  74.     the path & file name and inserting it into the note text.
  75. */
  76. dragdrop(window, event, arg)
  77.     Xv_Window window;
  78.     Event *event;
  79.     Notify_arg arg;
  80.     {
  81.     int  found = 0;
  82.     struct SubDir *sp;
  83.     struct Note *np;
  84.     Xv_Window twin;
  85.     int  n;
  86.     int  amount;
  87.     char buf[SELN_BUFSIZE];
  88.  
  89.     if(debug_on)
  90.         {
  91.         if(event_action(event) == ACTION_DRAG_MOVE)
  92.             fprintf(stderr, "Got ACTION_DRAG_MOVE event\n");
  93.         if(event_action(event) == ACTION_DRAG_LOAD)
  94.             fprintf(stderr, "Got ACTION_DRAG_LOAD event\n");
  95.         if(event_action(event) == ACTION_DRAG_COPY)
  96.             fprintf(stderr, "Got ACTION_DRAG_COPY event\n");
  97.         }
  98.     if(event_action(event) == ACTION_DRAG_LOAD)
  99.         {
  100.         sp = (struct SubDir *)LLM_first(&subdir_rt);
  101.         while(sp != NULL && !found)
  102.             {
  103.             np = (struct Note *) LLM_first(&sp->note_rt);
  104.             while(np != NULL && !found)
  105.                 {
  106.                 if(np->mapped)
  107.                     {
  108.                     twin = (Xv_Window) xv_get(np->textsw, OPENWIN_NTH_VIEW, 0);
  109.                     if(twin == window)
  110.                         {
  111.                         found = 1;
  112.                         n = xv_decode_drop(event, buf, sizeof(buf));
  113.                         buf[sizeof(buf) - 1] = 0;
  114.                         if(debug_on) fprintf(stderr, "buf {%s}\n", buf);
  115.                         if(n > 0)
  116.                             xv_set(np->textsw,
  117.                                 TEXTSW_INSERT_FROM_FILE, buf, NULL);
  118.                         }
  119.                     }
  120.                 np = (struct Note *) LLM_next(&sp->note_rt);
  121.                 }
  122.             sp = (struct SubDir *)LLM_next(&subdir_rt);
  123.             }
  124.         }
  125.     if((event_action(event) == ACTION_GO_PAGE_FORWARD || 
  126.        event_action(event) == ACTION_GO_PAGE_BACKWARD) && event_is_down(event))
  127.         {
  128.         if(debug_on) fprintf(stderr, "Got PAGE event\n");
  129.         sp = (struct SubDir *)LLM_first(&subdir_rt);
  130.         while(sp != NULL && !found)
  131.             {
  132.             np = (struct Note *) LLM_first(&sp->note_rt);
  133.             while(np != NULL && !found)
  134.                 {
  135.                 if(np->mapped)
  136.                     {
  137.                     twin = (Xv_Window) xv_get(np->textsw, OPENWIN_NTH_VIEW, 0);
  138.                     if(twin == window)
  139.                         {
  140.                         Textsw_index t_ndx;
  141.                         int  top, bottom;
  142.                         int  len;
  143.  
  144.                         found = 1;
  145.                         textsw_file_lines_visible(np->textsw, &top, &bottom);
  146.                         len = xv_get(np->textsw, TEXTSW_LENGTH);
  147.                         if(debug_on)
  148.                             fprintf(stderr, "len %d\n", len);
  149.                         amount = bottom - top + 1;
  150.                         if(event_action(event) == ACTION_GO_PAGE_BACKWARD)
  151.                             amount = -(amount);
  152.                         if(debug_on)
  153.                             fprintf(stderr, "top %d, bot %d\n", top, bottom);
  154.                         top += amount;
  155.                         if(top < 0) top = 0;
  156.                         t_ndx = textsw_index_for_file_line(np->textsw, top);
  157.                         if(debug_on)
  158.                             fprintf(stderr, "t_ndx %d\n",
  159.                                     t_ndx);
  160.                         if(t_ndx >= 0)
  161.                             {
  162.                             xv_set(np->textsw,
  163.                                    TEXTSW_INSERTION_POINT, t_ndx,
  164.                                    TEXTSW_UPPER_CONTEXT, 0,
  165.                                    NULL);
  166.                             textsw_normalize_view(np->textsw, t_ndx);
  167.                             }
  168.                         }
  169.                     }
  170.                 np = (struct Note *) LLM_next(&sp->note_rt);
  171.                 }
  172.             sp = (struct SubDir *)LLM_next(&subdir_rt);
  173.             }
  174.         }
  175.     if(event_id(event) == KBD_DONE)
  176.         {
  177.         if(debug_on) fprintf(stderr, "Got KBD_DONE event\n");
  178.         sp = (struct SubDir *)LLM_first(&subdir_rt);
  179.         while(sp != NULL && !found)
  180.             {
  181.             np = (struct Note *) LLM_first(&sp->note_rt);
  182.             while(np != NULL && !found)
  183.                 {
  184.                 if(np->mapped)
  185.                     {
  186.                     twin = (Xv_Window) xv_get(np->textsw, OPENWIN_NTH_VIEW, 0);
  187.                     if(twin == window)
  188.                         {
  189.                         found = 1;
  190.                         update(np);
  191.                         updateinfo(np, NOFORCE);
  192.                         }
  193.                     }
  194.                 np = (struct Note *) LLM_next(&sp->note_rt);
  195.                 }
  196.             sp = (struct SubDir *)LLM_next(&subdir_rt);
  197.             }
  198.         }
  199.     }
  200.  
  201. /*
  202.     Handles child process death notification.  Used with the print note
  203.     action.
  204. */
  205. Notify_value child_death(me, pid, status, rusage)
  206.     Notify_client me;
  207.     int  pid;
  208.     union wait *status;
  209.     struct rusage *rusage;
  210.     {
  211.     if(WIFEXITED(*status))
  212.         {
  213.         if(debug_on) fprintf(stderr, "Got child death\n");
  214.         cmd_printnote(NULL); /* allow next note to go, if any */
  215.         return(NOTIFY_DONE);
  216.         }
  217.     return(NOTIFY_IGNORED);
  218.     }
  219.