home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / source.lha / src / RSysClip.c < prev    next >
C/C++ Source or Header  |  1995-01-09  |  4KB  |  185 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *    RSysClip.c
  6. *
  7. * Inhalt:
  8. *    void SaveListToClip(struct List *list, char *text);
  9. *    void RSysListToClip(void);
  10. *    void RSysEntryToClip(void);
  11. *
  12. * Bemerkungen:
  13. *    Unterstützung des ClipBoard-Devices.
  14. *
  15. * Erstellungsdatum:
  16. *    07-Jul-93    Rolf Böhme
  17. *
  18. * Änderungen:
  19. *    07-Jul-93    Rolf Böhme    Erstellung
  20. *
  21. ***************************************************************************
  22. */
  23.  
  24. #include "RSysFunc.h"
  25. #include "RSysDebug.h"
  26.  
  27. #define ID_FTXT  MAKE_ID('F','T','X','T')
  28. #define ID_CHRS  MAKE_ID('C','H','R','S')
  29.  
  30. void
  31. SaveListToClip(struct List *list,char *text)
  32. {
  33.    char Success = FALSE;
  34.    struct Node *node;
  35.    int len;
  36.    struct IFFHandle *Handle;
  37.  
  38.    DPOS;
  39.  
  40.    if (IFFParseBase = OpenLibrary ((UBYTE *)"iffparse.library", 0L))
  41.    {
  42.       if(Handle = AllocIFF())
  43.       {
  44.          if(Handle->iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  45.          {
  46.             InitIFFasClip(Handle);
  47.  
  48.             if(!OpenIFF(Handle,IFFF_WRITE))
  49.             {
  50.                if(!PushChunk(Handle,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN))
  51.                {
  52.                   if(!PushChunk(Handle,0,ID_CHRS,IFFSIZE_UNKNOWN))
  53.                   {
  54.                      if(list != NULL)
  55.                      {
  56.                         for(node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
  57.                         {
  58.                            len = strlen(node->ln_Name);
  59.  
  60.                            if(WriteChunkBytes(Handle,node->ln_Name,len) != len)
  61.                               break;
  62.  
  63.                            if(WriteChunkBytes(Handle,"\n",1) != 1)
  64.                               break;
  65.                         }
  66.                      }
  67.                      else
  68.                      {
  69.                         len = strlen(text);
  70.  
  71.                         if(WriteChunkBytes(Handle,(STRPTR)text,len) != len)
  72.                            Success = FALSE;
  73.                      }
  74.  
  75.                      if(!PopChunk(Handle))
  76.                         Success = TRUE;
  77.                   }
  78.                }
  79.  
  80.                if(Success)
  81.                {
  82.                   if(PopChunk(Handle))
  83.                      Success = FALSE;
  84.                }
  85.  
  86.                CloseIFF(Handle);
  87.             }
  88.  
  89.             CloseClipboard((struct ClipboardHandle *)Handle->iff_Stream);
  90.          }
  91.  
  92.          FreeIFF(Handle);
  93.       }
  94.  
  95.       CloseLibrary (IFFParseBase);
  96.    }
  97.  
  98.    if(!Success)
  99.       ErrorHandle(CLIPBOARD_ERR, WRITE_FAIL, NO_KILL);
  100.  
  101.    return;
  102. }
  103.  
  104. void
  105. RSysListToClip(void)
  106. {
  107.    PrintInfo("Saving List to clipboard", SPEAK, 0);
  108.  
  109.    SaveListToClip(&ListeLVList, NULL);
  110.  
  111.    PrintStatistics();
  112.  
  113.    return;
  114. }
  115.  
  116. void
  117. RSysEntryToClip(void)
  118. {
  119.    register struct IntuiMessage *message;
  120.    APTR object;
  121.    ULONG class,
  122.          code;
  123.  
  124.    DPOS;
  125.  
  126.    Flags.quit_clip = 0;
  127.  
  128.    PrintInfo("Select list entry (ESC to cancel)", SPEAK, 0);
  129.  
  130.    do
  131.    {
  132.          /*
  133.           * Warten auf folgende Events:
  134.           * - ^C wurde eingegeben
  135.           * - Events vom Hauptfenster
  136.           */
  137.       Wait(1L << SysWnd->UserPort->mp_SigBit);
  138.  
  139.       while ((message = (struct IntuiMessage *)
  140.               GT_GetIMsg(SysWnd->UserPort)) != NULL)
  141.       {
  142.             /*
  143.              * Die wichtigsten Daten werden aus der erhaltenen
  144.              * Nachricht kopiert.
  145.              */
  146.          object = message->IAddress;
  147.          class = message->Class;
  148.          code = message->Code;
  149.  
  150.             /*
  151.              * Die Nachricht wird sofort beantwortet, damit
  152.              * Intuition nicht länger als notwendig auf eine
  153.              * Antwort wartet.
  154.              */
  155.          GT_ReplyIMsg(message);
  156.  
  157.          if(class == IDCMP_GADGETUP)
  158.          {
  159.             if(((struct Gadget *)object)->GadgetID == GD_ListeLV)
  160.             {
  161.                struct Node *node;
  162.  
  163.                if(node = GetNode(&ListeLVList,code))
  164.                {
  165.                   SaveListToClip(NULL, node->ln_Name);
  166.                   Flags.quit_clip = 1;
  167.                }
  168.             }
  169.          }
  170.  
  171.          if((class == IDCMP_VANILLAKEY) && (code == '\33'))
  172.          {
  173.             Flags.quit_clip = 1;
  174.             PrintInfo("Selection aborted!",SPEAK, SEC);
  175.          }
  176.       }
  177.    }
  178.    while(NOT(Flags.quit_clip));
  179.  
  180.    PrintStatistics();
  181.  
  182.    return;
  183. }
  184.  
  185.