home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / useful / dist / disk / cdrom / amicdrom / intui.c < prev    next >
C/C++ Source or Header  |  1994-01-07  |  7KB  |  245 lines

  1. /* intui.c:
  2.  *
  3.  * System requester stuff.
  4.  *
  5.  * ----------------------------------------------------------------------
  6.  * This code is (C) Copyright 1993,1994 by Frank Munkert.
  7.  * All rights reserved.
  8.  * This software may be freely distributed and redistributed for
  9.  * non-commercial purposes, provided this notice is included.
  10.  * ----------------------------------------------------------------------
  11.  * History:
  12.  * 
  13.  * 05-Jan-93   fmu   Retry displaying CD-DA icon if WB is not open.
  14.  * 02-Jan-94   fmu   Location for CD-DA icon may be defined by user.
  15.  * 11-Dec-93   fmu   Fixed AddAppIconA() call for DICE.
  16.  * 28-Nov-93   fmu   Added custom CD-DA icon; removed GetDefDiskObject() call.
  17.  * 09-Oct-93   fmu   SAS/C support added
  18.  */
  19.  
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22.  
  23. #include <exec/types.h>
  24. #include <intuition/intuition.h>
  25. #include <workbench/workbench.h>
  26. #include <workbench/startup.h>
  27.  
  28. #include <clib/exec_protos.h>
  29. #include <clib/intuition_protos.h>
  30. #include <clib/icon_protos.h>
  31. #include <clib/wb_protos.h>
  32. #ifdef AZTEC_C
  33. #include <pragmas/exec_lib.h>
  34. #include <pragmas/intuition_lib.h>
  35. #include <pragmas/icon_lib.h>
  36. #include <pragmas/wb_lib.h>
  37. #endif
  38. #ifdef LATTICE
  39. #include <pragmas/exec_pragmas.h>
  40. #include <pragmas/intuition_pragmas.h>
  41. #include <pragmas/icon_pragmas.h>
  42. #include <pragmas/wb_pragmas.h>
  43. #endif
  44. #if defined(_DCC) && defined(REGISTERED)
  45. #include <pragmas/exec_pragmas.h>
  46. #include <pragmas/intuition_pragmas.h>
  47. #include <pragmas/intuition_pragmas.h>
  48. #include <pragmas/icon_pragmas.h>
  49. #include <pragmas/wb_pragmas.h>
  50. extern struct Library *SysBase;
  51. #endif
  52.  
  53. #include "intui.h"
  54.  
  55. struct IntuitionBase *IntuitionBase;
  56. struct Library *IconBase;
  57. struct Library *WorkbenchBase;
  58.  
  59. struct MsgPort *g_app_port;
  60. struct AppIcon *g_app_icon;
  61. ULONG g_app_sigbit;
  62. int g_retry_show_cdda_icon = FALSE;
  63.  
  64. USHORT g_image_data[] = {
  65. /* Plane 0 */
  66.   0x0000,0x00FF,0xFE00,0x0000,0x0000,0x3F80,0x03F8,0x0000,
  67.   0x0003,0xC000,0x0007,0x8000,0x000C,0x0000,0x0000,0x6000,
  68.   0x0070,0x0000,0x0000,0x1C00,0x0080,0x0000,0x0000,0x0200,
  69.   0x0300,0x0000,0x0000,0x0080,0x0400,0x0000,0x0000,0x0040,
  70.   0x0800,0x0000,0x0000,0x0020,0x1000,0x0000,0x0000,0x0010,
  71.   0x2000,0x0000,0x0000,0x0008,0x4000,0x000F,0xE000,0x0004,
  72.   0x4000,0x003F,0xF800,0x0004,0x8000,0x0030,0x1800,0x0002,
  73.   0x8000,0x0040,0x0400,0x0002,0x8000,0x0040,0x0400,0x0002,
  74.   0x8000,0x0040,0x0400,0x0002,0x8000,0x0030,0x1800,0x0002,
  75.   0x4000,0x003F,0xF800,0x0004,0x4000,0x000F,0xE000,0x0004,
  76.   0x2000,0x0000,0x0000,0x0008,0x1000,0x0000,0x0000,0x0010,
  77.   0x0800,0x0000,0x0000,0x0020,0x0400,0x0000,0x0000,0x0040,
  78.   0x0200,0x0000,0x0000,0x0080,0x0080,0x0000,0x0000,0x0200,
  79.   0x0070,0x0000,0x0000,0x1C00,0x000C,0x0000,0x0000,0x6000,
  80.   0x0003,0xC000,0x0007,0x8000,0x0000,0x3F80,0x01F8,0x0000,
  81.   0x0000,0x00FF,0xFE00,0x0000,
  82. /* Plane 1 */
  83.   0x0000,0x0000,0x0000,0x0000,0x0000,0x007F,0xFC00,0x0000,
  84.   0x0000,0x3FFF,0xFFF8,0x0000,0x0003,0xFF00,0x01FF,0x8000,
  85.   0x000F,0xE0FF,0xFE0F,0xE000,0x007F,0x1FFF,0xFFF1,0xFC00,
  86.   0x00FC,0xFF80,0x03FE,0x7F00,0x03F3,0xF07F,0xFC1F,0x9F80,
  87.   0x07EF,0x8FC0,0x07E3,0xEFC0,0x0F9E,0x7E3F,0xF8FC,0xF3E0,
  88.   0x1F79,0xF9FF,0xFF3F,0x3DF0,0x3EF7,0xE7F0,0x1FCF,0xDEF8,
  89.   0x3EEF,0xDFC0,0x07F7,0xEEF8,0x7DEF,0xDFC0,0x07F7,0xEF7C,
  90.   0x7DDF,0xBF80,0x03FB,0xF77C,0x7DDF,0xBF80,0x03FB,0xF77C,
  91.   0x7DDF,0xBF80,0x03FB,0xF77C,0x7DEF,0xDFC0,0x07F7,0xEF7C,
  92.   0x3EEF,0xDFC0,0x07F7,0xEEF8,0x3EF7,0xE7F0,0x1FCF,0xDEF8,
  93.   0x1F79,0xF9FF,0xFF3F,0x3DF0,0x0F9E,0x7E3F,0xF8FC,0xF3E0,
  94.   0x07EF,0x8FC0,0x07E3,0xEFC0,0x03F3,0xF07F,0xFC1F,0x9F80,
  95.   0x01FC,0xFF80,0x03FE,0x7F00,0x007F,0x1FFF,0xFFF1,0xFC00,
  96.   0x000F,0xE0FF,0xFE0F,0xE000,0x0003,0xFF00,0x01FF,0x8000,
  97.   0x0000,0x3FFF,0xFFF8,0x0000,0x0000,0x007F,0xFE00,0x0000,
  98.   0x0000,0x0000,0x0000,0x0000
  99. };
  100.  
  101. struct Image g_disk_object_image = {
  102.   0, 0,            /* top corner */
  103.   63, 31, 2,        /* width, height, depth */
  104.   g_image_data,
  105.   0x03, 0x00,        /* planepick, planeonoff */
  106.   NULL,            /* next image */
  107. };
  108.  
  109. UBYTE *g_tool_types[] = {
  110.   NULL
  111. };
  112.  
  113. struct DiskObject g_disk_object = {
  114.   WB_DISKMAGIC,
  115.   WB_DISKVERSION,
  116.   {
  117.     NULL,
  118.     0, 0,
  119.     63, 32,
  120.     GADGIMAGE | GADGHCOMP,
  121.     RELVERIFY | GADGIMMEDIATE,
  122.     BOOLGADGET,
  123.     (APTR) &g_disk_object_image,
  124.     NULL,
  125.   },
  126.   0,
  127.   "",
  128.   (char **) g_tool_types,
  129.   NO_ICON_POSITION,
  130.   NO_ICON_POSITION,
  131.   NULL,
  132.   NULL,
  133.   0
  134. };
  135.  
  136. long g_xpos = NO_ICON_POSITION;
  137. long g_ypos = NO_ICON_POSITION;
  138.  
  139. void Init_Intui (void)
  140. {
  141.   IntuitionBase = (struct IntuitionBase *)
  142.      OpenLibrary ((UBYTE *) "intuition.library", 37);
  143.   IconBase = OpenLibrary ((UBYTE *) "icon.library", 37);
  144.   if (!IconBase)
  145.     Display_Error ("cannot open icon.library");
  146.   WorkbenchBase = OpenLibrary ((UBYTE *) "workbench.library", 37);
  147.   if (!WorkbenchBase)
  148.     Display_Error ("cannot open workbench.library");
  149.  
  150.   g_app_port = NULL;
  151.   g_app_sigbit = 0;
  152.   g_app_icon = NULL;
  153. }
  154.  
  155. void Close_Intui (void)
  156. {
  157.   if (WorkbenchBase)
  158.     CloseLibrary (WorkbenchBase);
  159.   if (IconBase)
  160.     CloseLibrary (IconBase);
  161.   if (IntuitionBase)
  162.     CloseLibrary ((struct Library *) IntuitionBase);
  163. }
  164.  
  165. void Display_Error (char *p_message, ...)
  166. {
  167.   va_list arg;
  168.  
  169.   static struct EasyStruct req = {
  170.     sizeof (struct EasyStruct),
  171.     0,
  172.     (UBYTE *) "CDROM Handler Error",
  173.     NULL,
  174.     (UBYTE *) "Abort"
  175.   };
  176.   
  177.   va_start (arg, p_message);
  178.   if (IntuitionBase) {
  179.     req.es_TextFormat = (UBYTE *) p_message;
  180.     EasyRequestArgs (NULL, &req, NULL, arg);
  181.   }
  182.   va_end (p_message);
  183. }
  184.  
  185. void Show_CDDA_Icon (void)
  186. {
  187.   if (!IconBase || !WorkbenchBase)
  188.     return;
  189.  
  190.   g_disk_object.do_CurrentX = g_xpos;
  191.   g_disk_object.do_CurrentY = g_ypos;
  192.  
  193.   if (g_app_icon)
  194.     Display_Error ("Show_CDDA_Icon called twice!");
  195.  
  196.   g_app_port = CreateMsgPort ();
  197.   if (!g_app_port)
  198.     return;
  199.  
  200.   g_app_sigbit = 1<<g_app_port->mp_SigBit;
  201.  
  202. #ifdef _DCC
  203.   {
  204.     struct DiskObject *tmp =
  205.       AddAppIconA (0, 0, (UBYTE *) "CD-DA", g_app_port,
  206.              NULL, &g_disk_object, NULL);
  207.     g_app_icon = tmp;
  208.   }
  209. #else
  210.   g_app_icon = AddAppIconA (0, 0, (UBYTE *) "CD-DA", g_app_port,
  211.                   NULL, &g_disk_object, NULL);
  212. #endif
  213.   /* AddAppIconA may fail if the Workbench has not yet been loaded.
  214.    */
  215.   if (!g_app_icon) {
  216.     DeleteMsgPort (g_app_port);
  217.     g_app_port = NULL;
  218.     g_retry_show_cdda_icon = TRUE;
  219.     return;
  220.   }
  221.   g_retry_show_cdda_icon = FALSE;
  222. }
  223.  
  224. void Hide_CDDA_Icon (void)
  225. {
  226.   struct Message *msg;
  227.  
  228.   g_retry_show_cdda_icon = FALSE;
  229.  
  230.   if (!IconBase || !WorkbenchBase)
  231.     return;
  232.  
  233.   if (g_app_icon)
  234.     RemoveAppIcon (g_app_icon);
  235.   if (g_app_port) {
  236.     while (msg = GetMsg (g_app_port))
  237.       ReplyMsg (msg);
  238.     DeleteMsgPort (g_app_port);
  239.   }
  240.  
  241.   g_app_port = NULL;
  242.   g_app_sigbit = 0;
  243.   g_app_icon = NULL;
  244. }
  245.