home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0935.lha / AmiCDROM / intui.c < prev    next >
C/C++ Source or Header  |  1993-12-20  |  6KB  |  220 lines

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