home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume21 / pan / part01 / pan3.0 / dnd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  4.2 KB  |  145 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. #ifdef PAN_DND
  32.  
  33. #include "pan.h"
  34. #include <xview/dragdrop.h>
  35.  
  36. struct Note *drag_find();
  37.  
  38. static Xv_Server dnd_server;
  39.  
  40. drag_init(server)
  41.     Xv_Server server;
  42.     {
  43.     dnd_server = server;
  44.     }
  45.  
  46. drag_proc(item, value, event)
  47.     Xv_opaque item;
  48.     unsigned int value;
  49.     Event *event;
  50.     {
  51.     struct Note *np;
  52.     Selection_requestor sel_req;
  53.  
  54.     sel_req = xv_get(item, PANEL_DROP_SEL_REQ);
  55.     switch(event_action(event))
  56.         {
  57.         case ACTION_DRAG_MOVE : /* Do nothing for now, textsw handles it */
  58.             break;
  59.         case ACTION_DRAG_COPY : /* Do nothing for now, textsw handles it */
  60.             break;
  61.         case LOC_DRAG :
  62.             np = drag_find(item);
  63.             if(np)
  64.                 {
  65.                 int txt_len;
  66.                 char *text;
  67.                 char fname[MAXBUFLEN];
  68.                 Atom list[3];
  69.  
  70.                 /* Set up file name */
  71.                 makename(fname, np);
  72.                 if(!np->got_itms)
  73.                     {
  74.                     np->sel_itm1 = xv_create(np->drag_obj,SELECTION_ITEM,NULL);
  75.                     np->sel_itm2 = xv_create(np->drag_obj,SELECTION_ITEM,NULL);
  76.                     np->sel_itm3 = xv_create(np->drag_obj,SELECTION_ITEM,NULL);
  77.                     np->got_itms = 1;
  78.                     }
  79.                 xv_set(np->sel_itm1,
  80.                     SEL_DATA, fname,
  81.                     SEL_FORMAT, 8,
  82.                     SEL_LENGTH, strlen(fname),
  83.                     SEL_TYPE_NAME, "FILE_NAME",
  84.                     SEL_COPY, TRUE,
  85.                     SEL_OWN, TRUE,
  86.                     NULL);
  87.                 /* Set up for text transfer */
  88.                 txt_len = xv_get(np->textsw, TEXTSW_LENGTH) + 1;
  89.                 text = malloc(txt_len);
  90.                 if(text == NULL)
  91.                     {
  92.                     fprintf(stderr, "pan:  Memory allocation failure\n");
  93.                     cleanup(1);
  94.                     }
  95.                 xv_get(np->textsw, TEXTSW_CONTENTS, 0, text, txt_len);
  96.                 xv_set(np->sel_itm2,
  97.                     SEL_DATA, text,
  98.                     SEL_FORMAT, 8,
  99.                     SEL_LENGTH, strlen(text),
  100.                     SEL_TYPE_NAME, "STRING",
  101.                     SEL_COPY, TRUE,
  102.                     SEL_OWN, TRUE,
  103.                     NULL);
  104.                 free(text);
  105.                 list[0] = (Atom) xv_get(dnd_server, SERVER_ATOM, "TARGETS");
  106.                 list[1] = (Atom) xv_get(dnd_server, SERVER_ATOM, "FILE_NAME");
  107.                 list[2] = (Atom) xv_get(dnd_server, SERVER_ATOM, "STRING");
  108.                 xv_set(np->sel_itm3,
  109.                     SEL_DATA, list,
  110.                     SEL_FORMAT, 32,
  111.                     SEL_LENGTH, 3,
  112.                     SEL_TYPE_NAME, "TARGETS",
  113.                     SEL_COPY, TRUE,
  114.                     SEL_OWN, TRUE,
  115.                     NULL);
  116.                 }
  117.             break;
  118.         default :
  119.             printf("unknown event %d\n", event_action(event));
  120.             break;
  121.         }
  122.     return(XV_OK);
  123.     }
  124.  
  125. struct Note *drag_find(item)
  126.     Xv_opaque item;
  127.     {
  128.     struct SubDir *sp;
  129.     struct Note *np;
  130.  
  131.     sp = (struct SubDir *) LLM_first(&subdir_rt);
  132.     while(sp != NULL)
  133.         {
  134.         np = (struct Note *) LLM_first(&sp->note_rt);
  135.         while(np != NULL)
  136.             {
  137.             if(np->drag_tgt == item) return(np);
  138.             np = (struct Note *) LLM_next(&sp->note_rt);
  139.             }
  140.         sp = (struct SubDir *) LLM_next(&subdir_rt);
  141.         }
  142.     return(NULL);
  143.     }
  144. #endif
  145.