home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / intuition_init.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  9KB  |  380 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: intuition_init.c,v 1.22 1997/01/27 00:36:40 ldp Exp $
  4.  
  5.     Desc: Library header for intuition
  6.     Lang: english
  7. */
  8. #define AROS_ALMOST_COMPATIBLE
  9. #include <string.h>
  10. #include <exec/lists.h>
  11. #include <exec/resident.h>
  12. #include <exec/memory.h>
  13. #include <exec/execbase.h>
  14. #include <proto/exec.h>
  15. #include <proto/intuition.h>
  16. #include <proto/alib.h>
  17. #include <dos/dos.h>
  18. #include <dos/dosextens.h>
  19. #include <dos/dostags.h>
  20. #include <proto/dos.h>
  21. #ifndef INTUITION_CLASSES_H
  22. #   include <intuition/classes.h>
  23. #endif
  24. #ifndef UTILITY_HOOKS_H
  25. #   include <utility/hooks.h>
  26. #endif
  27. #include <utility/utility.h>
  28. #include <aros/asmcall.h>
  29. #include "intuition_intern.h"
  30.  
  31. static const char name[];
  32. static const char version[];
  33. static const APTR inittabl[4];
  34. static void *const Intuition_functable[];
  35. struct IntuitionBase *AROS_SLIB_ENTRY(init,Intuition) ();
  36. extern const char Intuition_end;
  37.  
  38. AROS_UFP3(static ULONG, rootDispatcher,
  39.     AROS_UFPA(Class *,  cl,  A0),
  40.     AROS_UFPA(Object *, obj, A2),
  41.     AROS_UFPA(Msg,      msg, A1)
  42. );
  43.  
  44. /* There has to be a better way... */
  45. struct IClass *InitImageClass (struct IntuitionBase * IntuitionBase);
  46. struct IClass *InitFrameIClass (struct IntuitionBase * IntuitionBase);
  47. struct IClass *InitICClass (struct IntuitionBase * IntuitionBase);
  48. struct IClass *InitGadgetClass (struct IntuitionBase * IntuitionBase);
  49. struct IClass *InitButtonGClass (struct IntuitionBase * IntuitionBase);
  50.  
  51. int Intuition_entry(void)
  52. {
  53.     /* If the library was executed by accident return error code. */
  54.     return -1;
  55. }
  56.  
  57. const struct Resident Intuition_resident=
  58. {
  59.     RTC_MATCHWORD,
  60.     (struct Resident *)&Intuition_resident,
  61.     (APTR)&Intuition_end,
  62.     RTF_AUTOINIT,
  63.     39,
  64.     NT_LIBRARY,
  65.     0,
  66.     (char *)name,
  67.     (char *)&version[6],
  68.     (ULONG *)inittabl
  69. };
  70.  
  71. static const char name[]="intuition.library";
  72.  
  73. static const char version[]="$VER: intuition.library 39.0 (12.8.96)\n\015";
  74.  
  75. static const APTR inittabl[4]=
  76. {
  77.     (APTR)sizeof(struct IntIntuitionBase),
  78.     (APTR)Intuition_functable,
  79.     NULL,
  80.     &AROS_SLIB_ENTRY(init,Intuition)
  81. };
  82.  
  83. static Class rootclass =
  84. {
  85.     { { NULL, NULL }, AROS_ASMSYMNAME(rootDispatcher), NULL, NULL },
  86.     0,        /* reserved */
  87.     NULL,    /* No superclass */
  88.     (ClassID)ROOTCLASS,  /* ClassID */
  89.  
  90.     0, 0,    /* No offset and size */
  91.  
  92.     0,        /* UserData */
  93.     0,        /* SubClassCount */
  94.     0,        /* ObjectCount */
  95.     0,        /* Flags */
  96. };
  97.  
  98. void intui_ProcessEvents (void);
  99.  
  100. struct Process * inputDevice;
  101.  
  102. AROS_LH2(struct IntuitionBase *, init,
  103.  AROS_LHA(struct IntuitionBase *, IntuitionBase, D0),
  104.  AROS_LHA(BPTR,               segList,   A0),
  105.        struct ExecBase *, sysBase, 0, Intuition)
  106. {
  107.     AROS_LIBFUNC_INIT
  108.     SysBase = sysBase;
  109.  
  110.     NEWLIST (PublicClassList);
  111.  
  112.     if (!intui_init (IntuitionBase))
  113.     return NULL;
  114.  
  115.     /* Create semaphore and initialize it */
  116.     GetPrivIBase(IntuitionBase)->SigSem = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
  117.  
  118.     if (!GetPrivIBase(IntuitionBase)->SigSem)
  119.     return NULL;
  120.  
  121.     InitSemaphore (GetPrivIBase(IntuitionBase)->SigSem);
  122.  
  123.     /* The rootclass is created statically */
  124.     rootclass.cl_UserData = (IPTR) IntuitionBase;
  125.     AddClass (&rootclass);
  126.  
  127.     /* Add all other classes */
  128.     InitImageClass (IntuitionBase); /* After ROOTCLASS */
  129.     InitFrameIClass (IntuitionBase); /* After IMAGECLASS */
  130.  
  131.     InitICClass (IntuitionBase); /* After ROOTCLASS */
  132.  
  133.     InitGadgetClass (IntuitionBase); /* After ROOTCLASS */
  134.     InitButtonGClass (IntuitionBase); /* After GADGETCLASS */
  135.  
  136.     /* You would return NULL if the init failed */
  137.     return IntuitionBase;
  138.     AROS_LIBFUNC_EXIT
  139. }
  140.  
  141. AROS_LH1(struct IntuitionBase *, open,
  142.  AROS_LHA(ULONG, version, D0),
  143.        struct IntuitionBase *, IntuitionBase, 1, Intuition)
  144. {
  145.     AROS_LIBFUNC_INIT
  146.     struct TagItem screenTags[] =
  147.     {
  148.     { SA_Depth, 4            },
  149.     { SA_Type,  WBENCHSCREEN    },
  150.     { SA_Title, (IPTR)"Workbench"   },
  151.     { TAG_END, 0 }
  152.     };
  153.     struct TagItem inputTask[]=
  154.     {
  155.     { NP_UserData,    0L },
  156.     { NP_Entry,    (IPTR)intui_ProcessEvents },
  157.     { NP_Input,    0L },
  158.     { NP_Output,    0L },
  159.     { NP_Name,    (IPTR)"input.device" },
  160.     { NP_Priority,    50 },
  161.     { TAG_END, 0 }
  162.     };
  163.  
  164.     /* Keep compiler happy */
  165.     version=0;
  166.  
  167.     /* TODO Create input.device. This is a bad hack. */
  168.     if (!inputDevice)
  169.     {
  170.     inputTask[0].ti_Data = (IPTR)IntuitionBase;
  171.  
  172.     inputDevice = CreateNewProc (inputTask);
  173.  
  174.     if (!inputDevice)
  175.         return NULL;
  176.     }
  177.  
  178.     if (!GfxBase)
  179.     {
  180.     if (!(GfxBase = (void *)OpenLibrary (GRAPHICSNAME, 39)) )
  181.         return NULL;
  182.     }
  183.  
  184.     if (!UtilityBase)
  185.     {
  186.     if (!(UtilityBase = (void *)OpenLibrary (UTILITYNAME, 39)) )
  187.         return NULL; /* don't close anything */
  188.     }
  189.  
  190.     if (!GetPrivIBase(IntuitionBase)->WorkBench)
  191.     {
  192.     struct Screen * screen;
  193.  
  194.     screen = OpenScreenTagList (NULL, screenTags);
  195.  
  196.     if (!screen)
  197.         return NULL;
  198.  
  199.     IntuitionBase->FirstScreen =
  200.         IntuitionBase->ActiveScreen =
  201.         GetPrivIBase(IntuitionBase)->WorkBench = screen;
  202.     }
  203.  
  204.     if (!intui_open (IntuitionBase))
  205.     return NULL;
  206.  
  207.     /* I have one more opener. */
  208.     IntuitionBase->LibNode.lib_OpenCnt++;
  209.     IntuitionBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  210.  
  211.     /* You would return NULL if the open failed. */
  212.     return IntuitionBase;
  213.     AROS_LIBFUNC_EXIT
  214. }
  215.  
  216. AROS_LH0(BPTR, close,
  217.        struct IntuitionBase *, IntuitionBase, 2, Intuition)
  218. {
  219.     AROS_LIBFUNC_INIT
  220.  
  221.     /* I have one fewer opener. */
  222.     if(!--IntuitionBase->LibNode.lib_OpenCnt)
  223.     {
  224.     intui_close (IntuitionBase);
  225.  
  226.     /* Delayed expunge pending? */
  227.     if(IntuitionBase->LibNode.lib_Flags&LIBF_DELEXP)
  228.         /* Then expunge the library */
  229.         return expunge();
  230.     }
  231.     return 0;
  232.     AROS_LIBFUNC_EXIT
  233. }
  234.  
  235. AROS_LH0(BPTR, expunge,
  236.        struct IntuitionBase *, IntuitionBase, 3, Intuition)
  237. {
  238.     AROS_LIBFUNC_INIT
  239.  
  240.     /* Test for openers. */
  241.     if(IntuitionBase->LibNode.lib_OpenCnt)
  242.     {
  243.     /* Set the delayed expunge flag and return. */
  244.     IntuitionBase->LibNode.lib_Flags|=LIBF_DELEXP;
  245.     return 0;
  246.     }
  247.  
  248.     /* Free unecessary memory */
  249.     if (GetPrivIBase(IntuitionBase)->WorkBench)
  250.     CloseScreen (GetPrivIBase(IntuitionBase)->WorkBench);
  251.  
  252.     if (UtilityBase)
  253.     CloseLibrary ((struct Library *)UtilityBase);
  254.  
  255.     if (GfxBase)
  256.     CloseLibrary ((struct Library *)GfxBase);
  257.  
  258.     /* Let the driver do the same */
  259.     intui_expunge (IntuitionBase);
  260.  
  261. #ifdef DISK_BASED /* Don't remove a ROM library */
  262.     FreeImageClass ();
  263.  
  264.     /* Get rid of the library. Remove it from the list. */
  265.     Remove(&IntuitionBase->LibNode.lib_Node);
  266.  
  267.     /* Free the memory. */
  268.     FreeMem((char *)IntuitionBase-IntuitionBase->LibNode.lib_NegSize,
  269.         IntuitionBase->LibNode.lib_NegSize+IntuitionBase->LibNode.lib_PosSize);
  270. #endif
  271.  
  272.     return 0L;
  273.     AROS_LIBFUNC_EXIT
  274. }
  275.  
  276. AROS_LH0I(int, null,
  277.         struct IntuitionBase *, IntuitionBase, 4, Intuition)
  278. {
  279.     AROS_LIBFUNC_INIT
  280.     return 0;
  281.     AROS_LIBFUNC_EXIT
  282. }
  283.  
  284. #undef IntuitionBase
  285. #define IntuitionBase    ((struct IntuitionBase *)(cl->cl_UserData))
  286.  
  287. /******************************************************************************
  288.  
  289.     NAME */
  290.     AROS_UFH3(static IPTR, rootDispatcher,
  291.  
  292. /*  SYNOPSIS */
  293.     AROS_UFHA(Class  *, cl,  A0),
  294.     AROS_UFHA(Object *, o,   A2),
  295.     AROS_UFHA(Msg,      msg, A1))
  296.  
  297. /*  FUNCTION
  298.     internal !
  299.  
  300.     Processes all messages sent to the RootClass. Unknown messages are
  301.     silently ignored.
  302.  
  303.     INPUTS
  304.     cl - Pointer to the RootClass
  305.     o - This object was the destination for the message in the first
  306.         place
  307.     msg - This is the message.
  308.  
  309.     RESULT
  310.     Processes the message. The meaning of the result depends on the
  311.     type of the message.
  312.  
  313.     NOTES
  314.     This is a good place to debug BOOPSI objects since every message
  315.     should eventually show up here.
  316.  
  317.     EXAMPLE
  318.  
  319.     BUGS
  320.  
  321.     SEE ALSO
  322.  
  323.     HISTORY
  324.     14.09.93    ada created
  325.  
  326. ******************************************************************************/
  327. {
  328.     AROS_USERFUNC_INIT
  329.     IPTR retval = 0;
  330.  
  331.     switch (msg->MethodID)
  332.     {
  333.     case OM_NEW: {
  334.     cl = _OBJECT(o)->o_Class;
  335.  
  336.     /* Nur Speicher besorgen. Im Object steht, wieviel.
  337.        (Das Object ist keines. Es ist der Class-Pointer selbst !) */
  338.     retval = (IPTR) AllocMem (cl->cl_InstOffset
  339.         + cl->cl_InstSize
  340.         + sizeof (struct _Object)
  341.         , MEMF_ANY
  342.         );
  343.  
  344.     retval = (IPTR) BASEOBJECT(retval);
  345.     break; }
  346.  
  347.     case OM_DISPOSE:
  348.     /* Speicher freigeben. Aufrufer ist verantwortlich,
  349.        dass bereits alles andere freigegeben wurde ! */
  350.     FreeMem (_OBJECT(o)
  351.         , cl->cl_InstOffset
  352.         + cl->cl_InstSize
  353.         + sizeof (struct _Object)
  354.         );
  355.     break;
  356.  
  357.     case OM_ADDTAIL:
  358.     /* Fuege <o> an Liste an. */
  359.     AddTail (((struct opAddTail *)msg)->opat_List,
  360.             (struct Node *) _OBJECT(o));
  361.     break;
  362.  
  363.     case OM_REMOVE:
  364.     /* Entferne Object aus der Liste */
  365.     Remove ((struct Node *) _OBJECT(o));
  366.     break;
  367.  
  368.     default:
  369.     /* Ignore */
  370.     break;
  371.  
  372.     } /* switch */
  373.  
  374.     return (retval);
  375.     AROS_USERFUNC_EXIT
  376. } /* rootDispatcher */
  377.  
  378.  
  379.  
  380.