home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d902 / sltchr.lha / SltChr / SltChr.c < prev    next >
Text File  |  1993-08-26  |  7KB  |  268 lines

  1. /* Select a character from ASDG CygnusEd */
  2. /* assign to function key for easy access */
  3.  
  4. /* Njål Fisketjøn */
  5.  
  6. #include <clib/alib_protos.h>
  7. #include <clib/exec_protos.h>
  8. #include <clib/graphics_protos.h>
  9. #include <clib/intuition_protos.h>
  10. #include <clib/gadtools_protos.h>
  11. #include <clib/rexxsyslib_protos.h>
  12.  
  13. #include <stdio.h>
  14.  
  15. #ifdef LATTICE
  16. int CXBRK(void)        { return(0); }
  17. int chkabort(void)    { return(0); }
  18. #endif
  19.  
  20. #define RXFB_RESULT 17
  21.  
  22. struct RexxMsg TheMessage;
  23. struct MsgPort *CedPort;
  24. struct MsgPort *MyPort;
  25. char TheCommand[80];
  26.  
  27. struct TextAttr Topaz80 = {"topaz.font", 8, 0, 0, } ;
  28.  
  29. struct IntuiText Copyright = {2, 0, JAM1, 300, 160, NULL, 
  30.     "Copyright © 1993 N Fisketjøn", NULL};
  31.  
  32. struct IntuiText IText7 = {1, 0, JAM1, 14, 143,    NULL,
  33.     "à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ",
  34.     &Copyright};
  35.  
  36. struct IntuiText IText6 = {1, 0, JAM1, 14, 127,    NULL,
  37.     "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß", &IText7};
  38.  
  39. unsigned char string5b[]={0xa8,0x00};
  40. struct IntuiText IText5b = {1, 0, JAM1, 142, 111, NULL, string5b, &IText6};
  41.  
  42. struct IntuiText IText5 = {1, 0, JAM1, 14, 111,    NULL,
  43.     "  ¡ ¢ £ ¤ ¥ ¦ §   © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿", &IText5b};
  44.  
  45. unsigned char string4[]={0x80,0x20,0x81,0x20,0x82,0x20,0x83,0x20,0x84,0x20,0x85,0x20,0x86,0x20,0x87,0x20,
  46.                 0x88,0x20,0x89,0x20,0x8a,0x20,0x8b,0x20,0x8c,0x20,0x8d,0x20,0x8e,0x20,0x8f,0x20,
  47.                 0x90,0x20,0x91,0x20,0x92,0x20,0x93,0x20,0x94,0x20,0x95,0x20,0x96,0x20,0x97,0x20,
  48.                 0x98,0x20,0x99,0x20,0x9a,0x20,0x9b,0x20,0x9c,0x20,0x9d,0x20,0x9e,0x20,0x9f,0x20,0x00};
  49. struct IntuiText IText4 = {1, 0, JAM1, 14, 95,    NULL, string4, &IText5};
  50.  
  51. struct IntuiText IText3 = {1, 0, JAM1, 14, 79,    NULL,
  52.     "` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ ", &IText4};
  53.  
  54. unsigned char string2b[]={0x5c,0x00};
  55. struct IntuiText IText2b = {1, 0, JAM1, 462, 63, NULL, string2b, &IText3};
  56.  
  57. struct IntuiText IText2 = {1, 0, JAM1, 14, 63,    NULL,
  58.     "@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [   ] ^ _", &IText2b};
  59.  
  60. unsigned char string1b[]={0x22,0x00};
  61. struct IntuiText IText1b = {1, 0, JAM1, 46, 47,    NULL, string1b, &IText2};
  62.  
  63. struct IntuiText IText1 = {1, 0, JAM1, 14, 47,    NULL,
  64.     "  !   # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?", &IText1b};
  65.  
  66. unsigned char string0[]={0x20,0x20,0x01,0x20,0x02,0x20,0x03,0x20,0x04,0x20,0x05,0x20,0x06,0x20,0x07,0x20,
  67.                 0x08,0x20,0x09,0x20,0x0a,0x20,0x0b,0x20,0x0c,0x20,0x0d,0x20,0x0e,0x20,0x0f,0x20,
  68.                 0x10,0x20,0x11,0x20,0x12,0x20,0x13,0x20,0x14,0x20,0x15,0x20,0x16,0x20,0x17,0x20,
  69.                 0x18,0x20,0x19,0x20,0x1a,0x20,0x1b,0x20,0x1c,0x20,0x1d,0x20,0x1e,0x20,0x1f,0x20,0x00};
  70. struct IntuiText IText0 = {1, 0, JAM1, 14, 31,    NULL, string0, &IText1};
  71.  
  72. struct Library *IntuitionBase;
  73. struct Library *GfxBase;
  74. struct Library *GadToolsBase;
  75.  
  76. void version(void)
  77. {
  78.     printf("$VER: SltChr 1.1 20.7.93");
  79. }
  80.  
  81. void errorMessage(STRPTR error)
  82. {
  83. if (error)
  84.     printf("Error: %s\n",error);
  85. }
  86.  
  87. struct Gadget *createAllGadgets(struct Gadget **glistptr, void *vi,
  88.     UWORD topborder)
  89. {
  90. int i,j;
  91.  
  92. struct NewGadget ng;
  93. struct Gadget *gad;
  94.  
  95. gad= CreateContext(glistptr);
  96.  
  97. ng.ng_Height     = 16;
  98. ng.ng_Width         = 16;
  99. ng.ng_GadgetText = "";
  100. ng.ng_TextAttr     = &Topaz80;
  101. ng.ng_VisualInfo = vi;
  102. ng.ng_Flags         = NG_HIGHLABEL;
  103.  
  104. for(i=0; i<=31; i++)
  105. {
  106.     for(j=0; j<=7; j++)
  107.     {
  108.     ng.ng_TopEdge    = 10 + (j*ng.ng_Height) + topborder;
  109.     ng.ng_LeftEdge    = 10 + (i*ng.ng_Width);
  110.     ng.ng_GadgetID    = j*32 + i;
  111.     gad = CreateGadget(BUTTON_KIND, gad, &ng, TAG_END);
  112.     }
  113. }
  114.  
  115. return(gad);
  116. }
  117.  
  118. VOID SendCygnusEdMessageGetReply(char *TheCommand)
  119.  
  120. {
  121.     TheMessage.rm_Args[0] = TheCommand;
  122.     TheMessage.rm_Node.mn_Node.ln_Type = NT_MESSAGE;
  123.     TheMessage.rm_Node.mn_Length = sizeof(struct RexxMsg);
  124.     TheMessage.rm_Action= 1l << RXFB_RESULT;
  125.     TheMessage.rm_Result2 = 0;
  126.  
  127.     if (!(CedPort = FindPort("rexx_ced")))
  128.         errorMessage(" Unable to find Ced rexx port");
  129.     else
  130.     {
  131.         if (!(MyPort = CreatePort("SltChr", 0L)))
  132.             errorMessage(" Unable to create message port");
  133.         else
  134.         {
  135.             TheMessage.rm_Node.mn_ReplyPort    = MyPort;
  136.             PutMsg(CedPort, &TheMessage);
  137.             WaitPort(MyPort);
  138.             DeletePort(MyPort);
  139.         }
  140.     }
  141. }
  142.  
  143. VOID process_window_events(struct Window *mywin)
  144. {
  145. struct IntuiMessage *imsg;
  146. ULONG imsgClass;
  147. UWORD imsgCode;
  148. struct Gadget *gad;
  149. BOOL terminated = FALSE;
  150.  
  151. while (!terminated)
  152.     {
  153.     Wait (1 << mywin->UserPort->mp_SigBit);
  154.  
  155.     while ((!terminated) &&
  156.            (imsg = GT_GetIMsg(mywin->UserPort)))
  157.         {
  158.         gad = (struct Gadget *)imsg->IAddress;
  159.  
  160.         imsgClass = imsg->Class;
  161.         imsgCode = imsg->Code;
  162.  
  163.         GT_ReplyIMsg(imsg);
  164.  
  165.         switch (imsgClass)
  166.             {
  167.             case IDCMP_GADGETDOWN:
  168.             case IDCMP_MOUSEMOVE:
  169.             case IDCMP_GADGETUP:
  170.                 PrintIText(mywin->RPort,&IText0,0,0);
  171.                 sprintf(TheCommand,"enter ascii %i",gad->GadgetID);
  172.                 SendCygnusEdMessageGetReply(TheCommand);
  173.                 break;
  174.             case IDCMP_CLOSEWINDOW:
  175.                 terminated = TRUE;
  176.                 break;
  177.             case IDCMP_REFRESHWINDOW:
  178.                 GT_BeginRefresh(mywin);
  179.                 GT_EndRefresh(mywin, TRUE);
  180.                 break;
  181.             }
  182.         }
  183.     }
  184. }
  185.  
  186. VOID gadtoolsWindow(void)
  187. {
  188. struct TextFont *font;
  189. struct Screen    *mysc;
  190. struct Window    *mywin;
  191. struct Gadget    *glist;
  192. void            *vi;
  193. UWORD            topborder;
  194.  
  195. if (NULL == (font = OpenFont(&Topaz80)))
  196.     errorMessage( "Failed to open Topaz 80");
  197. else
  198.     {
  199.     if (NULL == (mysc = LockPubScreen(NULL)))
  200.         errorMessage( "Couldn't lock default public screen");
  201.     else
  202.         {
  203.         if (NULL == (vi = GetVisualInfo(mysc, TAG_END)))
  204.             errorMessage( "GetVisualInfo() failed");
  205.         else
  206.             {
  207.             topborder = mysc->WBorTop + (mysc->Font->ta_YSize + 1);
  208.  
  209.             if (NULL == createAllGadgets(&glist, vi, topborder))
  210.                 errorMessage( "createAllGadgets() failed");
  211.             else
  212.                 {
  213.                 ScreenToFront(mysc);
  214.                 if (NULL == (mywin = OpenWindowTags(NULL,
  215.                         WA_Title,      "Select character(s) and close window",
  216.                         WA_Gadgets,      glist,      WA_AutoAdjust,    TRUE,
  217.                         WA_Width,        532,      WA_MinWidth,           0,
  218.                         WA_InnerHeight, 165,      WA_MinHeight,           0,
  219.                         WA_DragBar,       TRUE,      WA_DepthGadget,  FALSE,
  220.                         WA_Activate,   TRUE,      WA_CloseGadget,    TRUE,
  221.                         WA_SizeGadget, FALSE,      WA_SimpleRefresh, TRUE,
  222.                         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
  223.                             BUTTONIDCMP ,
  224.                         WA_PubScreen, mysc,
  225.                         TAG_END)))
  226.                     errorMessage( "OpenWindow() failed");
  227.                 else
  228.                     {
  229.                     PrintIText(mywin->RPort,&IText0,0,0);
  230.                     GT_RefreshWindow(mywin, NULL);
  231.                     process_window_events(mywin);
  232.                     CloseWindow(mywin);
  233.                     }
  234.                 }
  235.             FreeGadgets(glist);
  236.             FreeVisualInfo(vi);
  237.             }
  238.         UnlockPubScreen(NULL, mysc);
  239.         }
  240.     CloseFont(font);
  241.     }
  242. }
  243.  
  244. VOID main(void)
  245. {
  246.  
  247. if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
  248.     errorMessage( "Requires V37 intuition.library");
  249. else
  250.     {
  251.     if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
  252.         errorMessage(" Requires V37 graphics.library");
  253.     else
  254.         {
  255.         if (NULL == (GadToolsBase = OpenLibrary("gadtools.library", 37)))
  256.             errorMessage(" Requires V37 gadtools.library");
  257.         else
  258.             {
  259.             gadtoolsWindow();
  260.             CloseLibrary(GadToolsBase);
  261.             }
  262.         CloseLibrary(GfxBase);
  263.         }
  264.     CloseLibrary(IntuitionBase);
  265.     }
  266. SendCygnusEdMessageGetReply("Cedtofront");
  267. }
  268.