home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / show / amiga / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-16  |  13.3 KB  |  594 lines

  1. #include "defines.h"
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/execbase.h>
  12. #include <exec/libraries.h>
  13. #include <intuition/screens.h>
  14. #include <intuition/intuition.h>
  15. #include <graphics/gfx.h>
  16. #include <graphics/text.h>
  17. #include <libraries/amigaguide.h>
  18. #include <libraries/gadtools.h>
  19. #include <utility/hooks.h>
  20. #include <utility/tagitem.h>
  21.  
  22. #include <clib/alib_protos.h>
  23. #include <clib/amigaguide_protos.h>
  24. #include <clib/dos_protos.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/gadtools_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/intuition_protos.h>
  29. #include <clib/utility_protos.h>
  30.  
  31. #include <pragmas/amigaguide_pragmas.h>
  32. #include <pragmas/dos_pragmas.h>
  33. #include <pragmas/exec_pragmas.h>
  34. #include <pragmas/gadtools_pragmas.h>
  35. #include <pragmas/graphics_pragmas.h>
  36. #include <pragmas/intuition_pragmas.h>
  37. #include <pragmas/utility_pragmas.h>
  38.  
  39. #include "globals.h"
  40. #include "amscreen.h"
  41. #include "gad_def.h"
  42. #include "prefwin.h"
  43.  
  44. #include "globals.i"
  45. #include "am_requ.i"
  46. #include "help.i"
  47.  
  48.  
  49. /*
  50.  * Fuer die locale-Library:
  51.  *
  52.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  53.  * Achtung:
  54.  * Es muss/sollte 'multiple-include' erlaubt sein!
  55.  */
  56. #include "local.i"
  57.  
  58. #undef  CATCOMP_ARRAY
  59. #undef  CATCOMP_BLOCK
  60. #undef  CATCOMP_STRINGS
  61. #define CATCOMP_NUMBERS
  62. #include "localstr.h"
  63.  
  64.  
  65. extern ULONG     sig_amigaguide_long;
  66.  
  67. extern struct Window    * MessWin;
  68. extern struct Window    * PrefWin;
  69.  
  70. #define ASM        __asm __saveds
  71. #define REG(x)        register __ ## x
  72.  
  73. #define BASENAME    "SHOWDVI"
  74. #define BASENAME_LENGTH    7
  75.  
  76.  
  77.  
  78. STRPTR AIcontext[] =
  79. {
  80.     "MAIN",
  81.     "STATUS",
  82.     NULL
  83. };
  84.  
  85. #define WWIN_NONE    0
  86. #define WWIN_SDVI    1
  87. #define WWIN_PREF    2
  88. #define WWIN_MESS    3
  89.  
  90.  
  91. struct AppInfo
  92. {
  93.     unsigned long                ai_RegA4;        /* REGISTER A4 (erspart __saveds) */
  94.  
  95.     struct Process        *ai_Process;        /* Our process address */
  96.     struct Screen        *ai_Screen;        /* Screen that our application will open on */
  97.     struct Window        *ai_Window;        /* Window pointer */
  98.     
  99.     /* Help related information */
  100.     LONG             ai_NHID;        /* Unique id */
  101.     ULONG             ai_NHFlags;        /* Help related flags */
  102.     UBYTE             ai_NHName[64];        /* Unique name */
  103.     struct Hook             ai_NHHook;        /* Dynamic node host hook */
  104.     struct AmigaGuideHost    *ai_NH;            /* Dynamic node host */
  105.     AMIGAGUIDECONTEXT         ai_AmigaGuide;        /* Pointer to the AmigaGuide context */
  106.     struct NewAmigaGuide     ai_NAG;        /* Used to start AmigaGuide */
  107.     LONG             ai_Region;        /* Region that the mouse if over */
  108.     LONG             ai_WhichWin;        /* über welchem Fenster... */
  109.  
  110.     /* Control information */
  111.     BOOL             ai_Done;        /* Done yet? */
  112. };
  113.  
  114. struct AppInfo * AiPtr = NULL;
  115.  
  116.  
  117. #define    AGHF_CONTINUOUS    (1L<<0)
  118.  
  119.  
  120. extern struct Library * AmigaGuideBase;
  121.  
  122.  
  123.  
  124. static VOID DisplayError (LONG err)
  125. {
  126.     MessageStr("AmigaGuide: %s", GetAmigaGuideString (err));
  127. }
  128.  
  129. STRPTR nodeNames[] =
  130. {
  131.     "WINDOW",
  132.     "PROCESS",
  133.     NULL,
  134. };
  135.  
  136. STRPTR nodeTitles[] =
  137. {
  138.     "Project Window Information",
  139.     "Project Process Information",
  140. };
  141.  
  142. enum
  143. {
  144.     NM_WINDOW,
  145.     NM_PROCESS,
  146. };
  147.  
  148. static LONG Tokenize (struct AppInfo *ai, STRPTR name)
  149. {
  150.     UBYTE buffer[32];
  151.     LONG i;
  152.  
  153.     /* Chop the prefix from the node name */
  154.     strcpy (buffer, &name[strlen(BASENAME)+1]);
  155.  
  156.     /* Find the token */
  157.     for (i = 0; nodeNames[i]; i++)
  158.     if (Stricmp (buffer, nodeNames[i]) == 0)
  159.         return i;
  160.     return -1;
  161. }
  162.  
  163.  
  164. ULONG __asm nodehost (REG (a0) struct Hook *h, REG (a2) STRPTR o, REG (a1) Msg msg)
  165. {
  166.     struct AppInfo *ai = (struct AppInfo *) h->h_Data;
  167.     struct opFindHost *ofh = (struct opFindHost *)msg;
  168.     struct opNodeIO *onm = (struct opNodeIO *)msg;
  169.     ULONG retval = FALSE;
  170.     LONG token;
  171.     ULONG id;
  172.  
  173.     putreg(REG_A4, ai->ai_RegA4);
  174.     
  175.     D(bug("NODEHOST Node %s\n", ofh->ofh_Node));
  176.  
  177.     switch (msg->MethodID)
  178.     {
  179.     case HM_FINDNODE:
  180.         /* Get the help group */
  181.         id = GetTagData (AGA_HelpGroup, 0L, ofh->ofh_Attrs);
  182.  
  183.         /* Request for the initial main node? */
  184.         if (id == 0)
  185.         {
  186.         /* We have to have a MAIN node, even if we never use it */
  187.         if (Stricmp (ofh->ofh_Node, "main") == 0)
  188.         {
  189.             /* Show that it is ours */
  190.             retval = TRUE;
  191.         }
  192.         }
  193.         /* Request for one of our true dynamic nodes? */
  194.         else if (id == ai->ai_NHID)
  195.         {
  196.         if ((Strnicmp (ofh->ofh_Node, BASENAME, BASENAME_LENGTH) == 0) &&
  197.             ((token = Tokenize (ai, ofh->ofh_Node)) >= 0))
  198.         {
  199.             /* Show that it is ours */
  200.             retval = TRUE;
  201.  
  202.             /* Set the node title */
  203.             ofh->ofh_Title = nodeTitles[token];
  204.         }
  205.         }
  206.         break;
  207.  
  208.     case HM_OPENNODE:
  209.         /* Allocate the document buffer */
  210.         if (onm->onm_DocBuffer = AllocVec (512, MEMF_CLEAR))
  211.         {
  212.         /* Build the document */
  213.         switch (token = Tokenize (ai, onm->onm_Node))
  214.         {
  215.             case NM_WINDOW:
  216.             sprintf (onm->onm_DocBuffer, "Window: %08lx\n  Size: %ld, %ld, %ld, %ld\n Group: %ld\n",
  217.                  ai->ai_Window,
  218.                  (LONG) ai->ai_Window->LeftEdge, (LONG) ai->ai_Window->TopEdge,
  219.                  (LONG) ai->ai_Window->Width, (LONG) ai->ai_Window->Height,
  220.                  ai->ai_NHID);
  221.             break;
  222.  
  223.             case NM_PROCESS:
  224.             sprintf (onm->onm_DocBuffer, "Process: %08lx\n",
  225.                  ai->ai_Process);
  226.             break;
  227.         }
  228.  
  229.         /* Set the buffer length */
  230.         onm->onm_BuffLen = strlen (onm->onm_DocBuffer);
  231.  
  232.         /* Remove the node from the database when done */
  233.         onm->onm_Flags |= HTNF_CLEAN;
  234.  
  235.         /* Show successful open */
  236.         retval = TRUE;
  237.         }
  238.         break;
  239.  
  240.     case HM_CLOSENODE:
  241.         /* Free the document buffer */
  242.         FreeVec (onm->onm_DocBuffer);
  243.         retval = TRUE;
  244.         break;
  245.  
  246.     case HM_EXPUNGE:
  247.         break;
  248.     }
  249.  
  250.     return retval;
  251. }
  252.  
  253.  
  254.  
  255.  
  256. void InitHelpFirst(void)
  257. {
  258.   struct AppInfo * ai;
  259.  
  260.   if (!AmigaGuideBase) return;
  261.  
  262.   AiPtr = ai = (struct AppInfo *)AllocVec (sizeof (struct AppInfo), MEMF_CLEAR);
  263.   if (!ai) Fatal(10, MSG_NO_MEM);
  264.  
  265.   ai->ai_RegA4 = getreg(REG_A4);
  266.  
  267.   /* Our process */
  268.   ai->ai_Process = (struct Process *) FindTask (NULL);
  269.  
  270.   /* Initialize the node host hook */
  271.   ai->ai_NHHook.h_Entry = (ULONG (*)()) nodehost;
  272.   ai->ai_NHHook.h_Data  = ai;
  273.  
  274.   /* Build the unique name */
  275.   ai->ai_NHID = GetUniqueID();
  276.   sprintf (ai->ai_NHName, "%s.%ld", BASENAME, ai->ai_NHID);
  277.  
  278.   /* Start the Dynamic Node Host */
  279.   ai->ai_NH = AddAmigaGuideHost (&ai->ai_NHHook, ai->ai_NHName, NULL);
  280.  
  281.   /* Initialize the global data */
  282.   ai->ai_Region = -1;
  283.   ai->ai_AmigaGuide = NULL;
  284.   ai->ai_WhichWin = WWIN_NONE;
  285. }
  286.  
  287. void FreeHelpLast(void)
  288. {
  289.   if (AiPtr) {
  290.     if (AiPtr->ai_NH) {
  291.       while (RemoveAmigaGuideHost(AiPtr->ai_NH, NULL) > 0)
  292.         Delay (10);
  293.     }
  294.   
  295.     FreeVec(AiPtr);
  296.   }
  297.   AiPtr = NULL;
  298. }
  299.  
  300.  
  301. long GetHelpNum(void)
  302. {
  303.   if (AiPtr) {
  304.     return AiPtr->ai_NHID;
  305.   }
  306.   else {
  307.     return -1;
  308.   }
  309. }
  310.  
  311.  
  312.  
  313.  
  314. void StartHelp(struct Screen * scr, struct Window * win)
  315. {
  316.   if (!AiPtr) return;
  317.  
  318.   AiPtr->ai_Screen = scr;
  319.   AiPtr->ai_Window = win;
  320.  
  321.   /* Turn on gadget help */
  322.   HelpControl (AiPtr->ai_Window, HC_GADGETHELP);
  323.  
  324.   /* Remember the AppInfo */
  325.   AiPtr->ai_Window->UserData = (APTR) AiPtr;
  326.  
  327.   /* We don't want the window to automatically activate */
  328.   AiPtr->ai_NAG.nag_Flags = HTF_NOACTIVATE;
  329.  
  330.   /* auf diesem Screen soll AmigaGuide aufgehen */
  331.   AiPtr->ai_NAG.nag_Screen = scr;
  332.  
  333.   /* Set the application base name */
  334.   AiPtr->ai_NAG.nag_BaseName = BASENAME;
  335.  
  336.   /* Set the document name */
  337.   AiPtr->ai_NAG.nag_Name = "TeX:config/ShowDVI.guide";
  338.  
  339.   /* establish the base name to use for hypertext ARexx port */
  340.   AiPtr->ai_NAG.nag_ClientPort = "SHOWDVI_HELP";
  341.  
  342.   /* Set up the context table */
  343.   AiPtr->ai_NAG.nag_Context = AIcontext;
  344.  
  345.   /* Open the help system */
  346.   AiPtr->ai_AmigaGuide = OpenAmigaGuideAsync (&AiPtr->ai_NAG,
  347.                          AGA_HelpGroup, AiPtr->ai_NHID,
  348.                          TAG_DONE);
  349.  
  350.   /* Signal-Maske holen */
  351.   sig_amigaguide_long = AmigaGuideSignal (AiPtr->ai_AmigaGuide);
  352.  
  353.   /* Clear the AmigaGuide context */
  354.   SetAmigaGuideContext (AiPtr->ai_AmigaGuide, 0L, NULL);
  355.  
  356.   /* alles ist bereit... */
  357.   set_amigaguide;
  358. }
  359.  
  360.  
  361.  
  362. void StopHelp(void)
  363. {
  364.   if (AiPtr && AiPtr->ai_AmigaGuide && AiPtr->ai_Window) {
  365.     /* Shutdown the help system */
  366.     CloseAmigaGuide(AiPtr->ai_AmigaGuide);
  367.     AiPtr->ai_AmigaGuide = NULL;
  368.     AiPtr->ai_Window = NULL;  // !!
  369.     unset_amigaguide;
  370.   }
  371. }
  372.  
  373.  
  374. /* ein AmigaGuide Signal ist angekommen */
  375. long work_with_help(void)
  376. {
  377.   long ex = 0;
  378.   struct AmigaGuideMsg *agm;
  379.   
  380.   if (!(is_amigaguide && AiPtr)) return ex;
  381.       
  382.   
  383.   /* process amigaguide messages */
  384.   while (agm = GetAmigaGuideMsg (AiPtr->ai_AmigaGuide)) {
  385.  
  386.     /* check message types */
  387.     switch (agm->agm_Type) {
  388.     /* AmigaGuide is ready for us */
  389.       case ActiveToolID:
  390.     break;
  391.  
  392.     /* This is a reply to our cmd */
  393.       case ToolCmdReplyID:
  394.     if (agm->agm_Pri_Ret)
  395.         DisplayError (agm->agm_Sec_Ret);
  396.     break;
  397.  
  398.     /* This is a status message */
  399.       case ToolStatusID:
  400.     if (agm->agm_Pri_Ret)
  401.         DisplayError (agm->agm_Sec_Ret);
  402.     break;
  403.  
  404.     /* Shutdown message */
  405.       case ShutdownMsgID:
  406.     if (agm->agm_Pri_Ret)
  407.         DisplayError (agm->agm_Sec_Ret);
  408.     break;
  409.  
  410.       default:
  411.     break;
  412.     }
  413.  
  414.     /* Reply to the message */
  415.     ReplyAmigaGuideMsg (agm);
  416.   }
  417.   
  418.   return ex;
  419. }
  420.  
  421.  
  422. long work_with_gadgethelp(struct IntuiMessage * imsg)
  423. {
  424.   long ex = 0;  
  425.   long region, qhelp;
  426.   long isgad = FALSE;
  427.   
  428.   if (!(is_amigaguide && AiPtr)) return ex;
  429.  
  430.   qhelp = region = -1;
  431.   if (imsg->IAddress == NULL) {
  432.     /* Not over our window */
  433.     AiPtr->ai_WhichWin = WWIN_NONE;
  434.     AiPtr->ai_Region = -1;
  435.     D(bug("HELP: Irgendwo...aber nicht bei uns\n"));
  436.   }
  437.   else if (imsg->IAddress == (APTR)AiPtr->ai_Window) {
  438.     /* Over our window */
  439.     qhelp = region = 0;
  440.     AiPtr->ai_WhichWin = WWIN_SDVI;
  441.     AiPtr->ai_Region = 0;
  442.     D(bug("HELP: Irgendwo über unserem Fenster\n"));
  443.   }
  444.   else if (MessWin && imsg->IAddress == (APTR)MessWin) {
  445.     qhelp = region = 0;
  446.     AiPtr->ai_WhichWin = WWIN_MESS;
  447.     AiPtr->ai_Region = 0;
  448.     D(bug("HELP: Irgendwo über dem MessWin Fenster\n"));
  449.   }
  450.   else if (PrefWin && imsg->IAddress == (APTR)PrefWin) {
  451.     qhelp = region = 0;
  452.     AiPtr->ai_WhichWin = WWIN_PREF;
  453.     AiPtr->ai_Region = 0;
  454.     D(bug("HELP: Irgendwo über dem PrefWin Fenster\n"));
  455.   }
  456.   else {
  457.  
  458.     /*
  459.      * Detect system gadgets.  Figure out by looking at
  460.      * system-gadget-type bits in GadgetType field:
  461.      */
  462.  
  463.     LONG sysgtype = ((struct Gadget *) imsg->IAddress)->GadgetType & 0xF0;
  464.     
  465.     isgad = TRUE;
  466.  
  467.     /* Set the region */
  468.     qhelp = (sysgtype >> 4) + 5;
  469.     region = HTFC_SYSGADS + sysgtype;
  470.  
  471.     switch (sysgtype) {
  472.       case GTYP_SIZING:
  473.       case GTYP_WDRAGGING:
  474.       case GTYP_WUPFRONT:
  475.       case GTYP_WDOWNBACK:
  476.       case GTYP_CLOSE:
  477.     break;
  478.  
  479.       case 0:
  480.         qhelp = region = (LONG) ((struct Gadget *)imsg->IAddress)->GadgetID;
  481.     break;
  482.  
  483.       default:
  484.     break;
  485.     }
  486.  
  487.     /* Remember the region */
  488.     AiPtr->ai_Region = region;
  489.  
  490.   }
  491.   
  492.   /* Send the command immediately if we are continuous */
  493.   if ((isgad || (AiPtr->ai_Region >= 0)) && (AiPtr->ai_NHFlags & AGHF_CONTINUOUS)) {
  494.     /* Display the node */
  495.     HelpKeyAGuide(FALSE);
  496.   }
  497.  
  498.  
  499.   return ex;
  500. }
  501.  
  502.  
  503. void do_menu_help(long sel, int checked, int enabeled, int is_barlabel)
  504. {
  505.   static char mnode[64];
  506.  
  507.   if (is_amigaguide && AiPtr) {
  508.     /* Display the node */
  509.     long men  = MENUNUM(sel);
  510.     long item = ITEMNUM(sel);
  511.     long sub  = SUBNUM(sel);
  512.     if (is_barlabel) {
  513.       strcpy(mnode, "link menu_barlabel");
  514.     }
  515.     else if (sub != NOSUB) {
  516.       sprintf(mnode, "link menu_%d_%d_%d", men, item, sub);
  517.     }
  518.     else {
  519.       if (item != 63) {
  520.         sprintf(mnode, "link menu_%d_%d", men, item);
  521.       }
  522.       else {
  523.         sprintf(mnode, "link menu_%d", men);
  524.       }
  525.     }
  526.  
  527.     D(bug("Zeige Node %s (Menü)\n", mnode));
  528.     SendAmigaGuideCmd (AiPtr->ai_AmigaGuide, mnode, TAG_DONE);
  529.   }
  530. }
  531.  
  532. static char * prefwincontext[] = {
  533.   "xsize", "ysize", "lace", "default", "dvisze", "use", "cancel", "ownscr",
  534.   "4col", "scrmode", "scrmname", NULL
  535. };
  536.  
  537. void HelpKeyAGuide(int conthelp)
  538. {
  539.   static char hnode[64];
  540.   
  541.   if (conthelp) {
  542.     /* toggle */
  543.     if (AiPtr->ai_NHFlags & AGHF_CONTINUOUS) AiPtr->ai_NHFlags &= (~AGHF_CONTINUOUS);
  544.     else                       AiPtr->ai_NHFlags |= AGHF_CONTINUOUS;
  545.   }
  546.   
  547.   if (is_amigaguide && AiPtr) {
  548.     if (AiPtr->ai_Region == -1) {
  549.       strcpy(hnode, "link Main");
  550.     }
  551.     else if (AiPtr->ai_Region == 0) {
  552.       switch (AiPtr->ai_WhichWin) {
  553.         case WWIN_SDVI:
  554.           strcpy(hnode, "link ShowWin");
  555.           break;
  556.         case WWIN_PREF:
  557.           strcpy(hnode, "link PrefWin");
  558.           break;
  559.         case WWIN_MESS:
  560.           strcpy(hnode, "link MessWin");
  561.           break;
  562.         default:
  563.           strcpy(hnode, "link Main");
  564.       }
  565.     }
  566.     else {
  567.       if (AiPtr->ai_Region >= HTFC_SYSGADS) {
  568.         sprintf(hnode, "link SGAD_%d", (AiPtr->ai_Region - HTFC_SYSGADS) >> 5);
  569.       }
  570.       else {
  571.         if (AiPtr->ai_Region >= PG_POT_GAD_NR && AiPtr->ai_Region <= PG_INT_GAD_NR) {
  572.           strcpy(hnode, "link PAGEGAD");
  573.         }
  574.         else if (AiPtr->ai_Region >= POTX_PFEIL_LINKS_GAD_NR && AiPtr->ai_Region <= POTX_GAD_NR) {
  575.           strcpy(hnode, "link POTXGAD");
  576.         }
  577.         else if (AiPtr->ai_Region >= POTY_PFEIL_OBEN_GAD_NR && AiPtr->ai_Region <= POTY_GAD_NR) {
  578.           strcpy(hnode, "link POTYGAD");
  579.         }
  580.         else if (AiPtr->ai_Region >= GAD_xsize && AiPtr->ai_Region <= GAD_scrmname) {
  581.           sprintf(hnode, "link PREF_%s", prefwincontext[AiPtr->ai_Region - GAD_xsize]);
  582.         }
  583.         else {
  584.           sprintf(hnode, "link GAD%d", AiPtr->ai_Region);
  585.         }
  586.       }
  587.     }
  588.     
  589.     D(bug("Zeige Node %s (Gadget/Window)\n", hnode));
  590.     SendAmigaGuideCmd(AiPtr->ai_AmigaGuide, hnode, TAG_DONE);
  591.   }
  592. }
  593.  
  594.