home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-1 / wbarg.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  170 lines

  1. /* wbarg.c
  2.  * How to get an icon from a Workbench argument
  3.  * Written by David N. Junod, 27-Aug-90
  4.  */
  5. /*
  6. Copyright (c) 1990 Commodore-Amiga, Inc.
  7.  
  8. This example is provided in electronic form by Commodore-Amiga,
  9. Inc. for use with the Amiga Mail Volume II technical publication.
  10. Amiga Mail Volume II contains additional information on the correct
  11. usage of the techniques and operating system functions presented in
  12. these examples.  The source and executable code of these examples may
  13. only be distributed in free electronic form, via bulletin board or
  14. as part of a fully non-commercial and freely redistributable
  15. diskette.  Both the source and executable code (including comments)
  16. must be included, without modification, in any copy.  This example
  17. may not be published in printed form or distributed with any
  18. commercial product. However, the programming techniques and support
  19. routines set forth in these examples may be used in the development
  20. of original executable software products for Commodore Amiga
  21. computers.
  22.  
  23. All other rights reserved.
  24.  
  25. This example is provided "as-is" and is subject to change; no
  26. warranties are made.  All use is at your own risk. No liability or
  27. responsibility is assumed.
  28. */
  29.  
  30. #include <exec/types.h>
  31. #include <exec/memory.h>
  32. #include <exec/libraries.h>
  33. #include <libraries/dos.h>
  34. #include <workbench/icon.h>
  35. #include <workbench/startup.h>
  36. #include <clib/dos_protos.h>
  37. #include <clib/exec_protos.h>
  38. #include <clib/wb_protos.h>
  39. #include <pragmas/dos_pragmas.h>
  40. #include <pragmas/exec_pragmas.h>
  41. #include <pragmas/wb_pragmas.h>
  42. #include <string.h>
  43.  
  44. extern struct Library *IconBase, *DOSBase, *SysBase;
  45.  
  46. struct DiskObject *GetDiskObjectNew (STRPTR name);
  47. struct DiskObject *GetDiskObject (STRPTR name);
  48.  
  49. #pragma libcall IconBase GetDiskObjectNew 84 801
  50.  
  51. /****** wbarg/IconFromWBArg ********************************************
  52. *
  53. *   NAME
  54. *    IconFromWBArg - Obtains the icon from a Workbench argument.
  55. *
  56. *   SYNOPSIS
  57. *    dob = IconFromWBArg (wbarg);
  58. *
  59. *    struct DiskObject *dob;
  60. *    struct WBArg *wbarg;
  61. *
  62. *   FUNCTION
  63. *    Given a valid Workbench argument, this command will return the
  64. *    proper icon.  This call uses the new (V36) GetDiskObjectNew call
  65. *    to ensure that an icon will be returned.
  66. *
  67. *    This functions requires dos.library and icon.library to be opened
  68. *    by the application.
  69. *
  70. *   INPUTS
  71. *    wbarg    - Pointer to a filled in WBArg structure.
  72. *
  73. *   RESULTS
  74. *    dob    - Pointer to a DiskObject structure.  Application must call
  75. *          FreeDiskObject when done with the icon.
  76. *
  77. **********************************************************************/
  78.  
  79. struct DiskObject *IconFromWBArg (struct WBArg * arg)
  80. {
  81.     struct DiskObject *dob = NULL;
  82.     UBYTE work_name[34];
  83.     BPTR old, new;
  84.  
  85.     /* Copy the WBArg contents */
  86.     strcpy (work_name, arg->wa_Name);
  87.  
  88.     /* Duplicate the lock */
  89.     if (new = DupLock (arg->wa_Lock))
  90.     {
  91.     BOOL success = FALSE;
  92.  
  93.     /*
  94.      * If we don't have a name, then get one. Only Tools & Projects have a
  95.      * valid name.
  96.      */
  97.     if (strlen (work_name) == 0)
  98.     {
  99.         LONG msize = sizeof (struct FileInfoBlock);
  100.         struct FileInfoBlock *info;
  101.  
  102.         /* This block needs to be longword aligned, so allocate it */
  103.         if (info = (struct FileInfoBlock *) AllocMem (msize, MEMF_CLEAR))
  104.         {
  105.         /* Examine the lock, so that we can figure out the name */
  106.         if (Examine (new, info))
  107.         {
  108.             /* Copy the name of the lock */
  109.             strcpy (work_name, info->fib_FileName);
  110.  
  111.             /* See if the lock is a directory */
  112.             if (info->fib_DirEntryType > 0)
  113.             {
  114.             /* Unlock the existing lock */
  115.             UnLock (new);
  116.  
  117.             /* Go to the parent drawer */
  118.             if ((new = ParentDir (arg->wa_Lock)) == NULL)
  119.             {
  120.                 /* A disk icon was passed */
  121.                 strcpy (work_name, "disk");
  122.                 new = DupLock (arg->wa_Lock);
  123.  
  124.             }    /* End of if disk */
  125.             }        /* End of if directory */
  126.  
  127.             /* We have a name */
  128.             success = TRUE;
  129.  
  130.         }        /* End of examine */
  131.  
  132.         /* Free the temporary block */
  133.         FreeMem ((APTR) info, msize);
  134.         }
  135.     }
  136.     else
  137.     {
  138.         /* Show that we have a name to work with */
  139.         success = TRUE;
  140.     }
  141.  
  142.     /* See if we should try getting the icon */
  143.     if (success)
  144.     {
  145.         /* go to the directory where the icon resides */
  146.         old = CurrentDir (new);
  147.  
  148.         /*
  149.          * GetDiskObjectNew is a new function, for AmigaOS version 2.0,
  150.          * therefore we need to check the version level.
  151.          */
  152.         if (IconBase->lib_Version >= 36)
  153.         dob = GetDiskObjectNew (work_name);
  154.         else
  155.         dob = GetDiskObject (work_name);
  156.  
  157.         /* go back to where we used to be */
  158.         CurrentDir (old);
  159.     }
  160.  
  161.     /* release the duplicated lock */
  162.     UnLock (new);
  163.     }
  164.  
  165.     /* return the icon */
  166.     return (dob);
  167. }
  168.  
  169.  
  170.