home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / SmartIcon / src / reveal.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  4KB  |  129 lines

  1. /***************************************************************************/
  2. /*                                       */
  3. /* SmartIcon, release 1.0 - An Intuition object iconifier for the Amiga    */
  4. /* Copyright (c) 1988 Gauthier H. Groult                                   */
  5. /*                                       */
  6. /* Written in January 1988 by Gauthier H. Groult               */
  7. /*                  33, Boulevard Saint Denis,           */
  8. /*                  92400 Courbevoie                   */
  9. /*                  France - Europe                   */
  10. /*                  Tel: (16) 1 47 89 09 54                      */
  11. /*                  email: mcvax!inria!litp!germinal!groult       */
  12. /*                                       */
  13. /* This source code is not in public domain, please do not distribute.       */
  14. /* The binary program is shareaware. Read docs files for details.       */
  15. /*                                       */
  16. /***************************************************************************/
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <libraries/dos.h>
  21. #include <libraries/dosextens.h>
  22. #include <workbench/workbench.h>
  23. #include <workbench/startup.h>
  24. #include <string.h>
  25.  
  26. VOID  main(), Cleanup(), RevealWindow();
  27.  
  28. LONG     IconBase;
  29. struct     LayersBase    *LayersBase;
  30. struct     IntuitionBase    *IntuitionBase;
  31. struct     WBStartup    *wbStartup;
  32. struct     FileInfoBlock    *theIconInfo;
  33. struct     Lock        *theIconLock;
  34.  
  35. extern struct WBStartup *WBenchMsg;
  36.  
  37. /* This program is the one that un-iconifies a window when the user       */
  38. /* double-clicks on the icon. Its is actually written to the ram-disk       */
  39. /* by the iconofier program at iconification times. Thus it is           */
  40. /* contained in a binary format in the iconifier program itself.       */
  41. /* The program bin2txt was written to translate the executable form       */
  42. /* of this program to a C array.                       */
  43. /*                                       */
  44. /* This code read a window pointer from the comment field of it's icon.    */
  45. /* Then it calls reveal window to reset the window layer and leaves       */
  46. /* after having destroyed it's own ram-disk file.                          */
  47. /*                                       */
  48. /* See icon.c for more details.                        */
  49.  
  50. VOID
  51. main(argc, argv)
  52. UBYTE argc, **argv;
  53. {
  54.    UBYTE    filename[30];
  55.    struct   WBArg       *wbArgs;
  56.    struct   Window       *window;
  57.  
  58.    IntuitionBase = (struct IntuitionBase *)
  59.            OpenLibrary("intuition.library", 0);
  60.    if (!LayersBase) Cleanup(10);
  61.  
  62.    LayersBase = (struct LayersBase *)OpenLibrary("layers.library", 0);
  63.    if (!LayersBase) Cleanup(11);
  64.  
  65.    IconBase = OpenLibrary("icon.library",0);
  66.    if (!IconBase) Cleanup(12);
  67.  
  68.    theIconInfo = (struct FileInfoBlock *)
  69.          AllocMem(sizeof(struct FileInfoBlock), MEMF_CHIP);
  70.    if (!theIconInfo) Cleanup(20);
  71.  
  72.    if (!argc)
  73.       {
  74.       wbStartup = WBenchMsg;
  75.       wbArgs = wbStartup->sm_ArgList;
  76.       theIconLock = (struct Lock *)Lock(wbArgs[0].wa_Name, MODE_OLDFILE);
  77.       if (!theIconLock) Cleanup(30);
  78.       if (!Examine(theIconLock, theIconInfo))
  79.      {
  80.      UnLock(theIconLock);
  81.      Cleanup(31);
  82.      }
  83.  
  84.       Forbid();
  85.       window = (struct Window *)atoi(theIconInfo->fib_Comment);
  86.       RevealWindow(window->WScreen, window);
  87.       Permit();
  88.  
  89.       UnLock(theIconLock);
  90.       DeleteFile(wbArgs[0].wa_Name);
  91.       sprintf(filename, "%s.info", wbArgs[0].wa_Name);
  92.       DeleteFile(filename);
  93.       }
  94.    else printf("Must execute from WorkBench!!\n");
  95.  
  96.    Cleanup(0);
  97. }
  98.  
  99. VOID
  100. Cleanup(error)
  101. USHORT error;
  102. {
  103.    if (error>10) DisplayBeep(NULL);
  104.  
  105.    if (theIconInfo)     FreeMem(theIconInfo, sizeof(struct FileInfoBlock));
  106.  
  107.    if (IconBase)        CloseLibrary(IconBase);
  108.    if (LayersBase)      CloseLibrary(LayersBase);
  109.    if (IntuitionBase)   CloseLibrary(IntuitionBase);
  110. }
  111.  
  112. VOID
  113. RevealWindow(screen, window)
  114. struct     Screen   *screen;
  115. struct     Window   *window;
  116. {
  117.    struct   Layer    *layer;
  118.    struct   Layer_Info    *linfo;
  119.  
  120.    layer = window->RPort->Layer;
  121.    linfo = layer->LayerInfo;
  122.  
  123.    MoveLayer(linfo, layer,
  124.          window->LeftEdge - screen->Width  + 1,
  125.          window->TopEdge  - screen->Height + 1);
  126.    SizeLayer(linfo, layer, window->Width-1, window->Height-1);
  127.    WindowToFront(window);
  128. }
  129.