Advertisement
micha_b

Os 3.2 ReAction Demo 1

Oct 31st, 2022 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.60 KB | Fixit | 0 0
  1. /***************************************************
  2. *   Source:     raConvert.c                        *
  3. *   Program:    raConvert                          *
  4. *                                                  *
  5. *   Tutorial App for AmigaOS 3.2.x                 *
  6. *   ReAction C coding                              *
  7. *                                                  *
  8. *   Author: Micha B. 2022                          *
  9. *   Web:    http://amiga.mbergmann-sh.de           *
  10. *                                                  *
  11. *   sc NOSTACKCHECK raConvert.c LINK TO raConvert  *
  12. ****************************************************/
  13. #define USE_BUILTIN_MATH
  14. #define USE_SYSBASE
  15.  
  16. /* debugging memory */
  17. /*
  18. #include <exec/memory.h>
  19. #include <proto/exec.h>
  20.  
  21. //#define MWDEBUG=1
  22. */
  23. //#define _DEBUG=1
  24.  
  25. #include <memwatch.h> /* To enable memlib, you must #define MWDEBUG to 1 */
  26.  
  27. #include <exec/types.h>
  28. #include <libraries/dos.h>
  29. #include <workbench/workbench.h>
  30. #include <workbench/startup.h>
  31.  
  32. #include <intuition/classusr.h>
  33. #include <gadgets/layout.h>
  34. #include <gadgets/button.h>
  35. #include <gadgets/string.h>
  36. #include <classes/window.h>
  37. #include <classes/requester.h>
  38. #include <images/label.h>
  39. #include <images/bevel.h>
  40. #include <libraries/gadtools.h>
  41.  
  42. //#include <clib/icon_protos.h>
  43.  
  44. #define __CLIB_PRAGMA_LIBCALL
  45.  
  46. #include <proto/alib.h>
  47. #include <proto/exec.h>
  48. #include <proto/dos.h>
  49. #include <proto/layout.h>
  50. #include <proto/window.h>
  51. #include <proto/requester.h>
  52. #include <proto/string.h>
  53. #include <proto/label.h>
  54. #include <proto/bevel.h>
  55. #include <proto/intuition.h>
  56. #include <proto/button.h>
  57. #include <proto/icon.h>
  58.  
  59. #include <pragmas/requester_pragmas.h>
  60.  
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <string.h>
  64. #include "version.h"
  65.  
  66. /* --- Bases --- */
  67. struct IntuitionBase *IntuitionBase;
  68. struct Library *IconBase;
  69. struct Library *WindowBase;
  70. struct Library *LayoutBase;
  71. struct Library *ButtonBase;
  72. struct Library *LabelBase;
  73. struct Library *StringBase;
  74. struct Library *BevelBase;
  75. struct Library *RequesterBase;
  76.  
  77. void __stdargs kprintf(const char *, ...);
  78.  
  79. struct Hook IDCMPHook;
  80.  
  81. /* --- ASL Hook function */
  82. void __saveds __asm processIDCMP(register __a0 struct Hook *hook,
  83.                  register __a2 Object * obj,
  84.                  register __a1 struct IntuiMessage *msg)
  85. {
  86.     switch (msg->Class)
  87.     {
  88.         case IDCMP_GADGETDOWN:
  89.             /* Do something about it */
  90.             break;
  91.     }
  92. }
  93.  
  94. /* here we define a struct for our menu entries */
  95. struct NewMenu menu[] =
  96. {
  97.     { NM_TITLE, "Project", 0, 0, 0, 0 },                   /* first menu  */
  98.     { NM_ITEM, "About raConvert", "?", 0, 0, 0 },
  99.     { NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL},
  100.     { NM_ITEM, "GadgetHelp", "0", CHECKIT | CHECKED | MENUTOGGLE, 0, 0},
  101.     { NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL},
  102.     { NM_ITEM, "Quit", "Q", MIF_SHIFTCOMMSEQ, 0, 0 },    
  103.    
  104.     /* --- more Menus might be constructed just the same way... --- */
  105.    
  106.     { NM_END, NULL, 0, 0, 0, 0 }    /* MN_END finalizes Menu construction */
  107. };
  108.  
  109.  
  110. /* --- Window-related --- */
  111. struct Window *intuiwin = NULL; /* Window structure  */
  112. Object *windowObject    = NULL; /* our Window object */
  113.  
  114. /* --- Layout Objects --- */
  115. Object *topLayout     = NULL;   /* holds first Label                   */
  116. Object *string1Layout = NULL;   /* holds Label + first StringGadget    */
  117. Object *string2Layout = NULL;   /* holds Label + second StringGadget   */
  118. Object *buttonLayout  = NULL;   /* holds two ButtonGadgets             */
  119. Object *mainLayout    = NULL;   /* our main Layout Object              */
  120.  
  121. /* --- Requester Objects --- */
  122. Object *aboutReq   = NULL;
  123. Object *quitReq    = NULL;
  124. Object *emptyReq   = NULL;
  125. Object *noasciiReq = NULL;
  126.  
  127. /* --- Gadget Objects --- */
  128. Object *inString      = NULL;
  129. Object *outString     = NULL;
  130. Object *clearButton   = NULL;
  131. Object *convertButton = NULL;
  132. Object *helpButton    = NULL;
  133.  
  134. /* --- Gadget IDs (for IDCMP handling) --- */
  135. #define GID_INSTRING        1
  136. #define GID_OUTSTRING       2
  137. #define GID_CLEARBUTTON     3
  138. #define GID_CONVERTBUTTON   4
  139. #define GID_HELPBUTTON      5
  140.  
  141. /* --- define menu IDs --- */
  142. #define MN_ABOUT    63488
  143. #define MN_GADGETHELP 63552
  144. #define MN_QUIT     63616
  145.  
  146. /* --- Function Prototypes --- */
  147. void cleanexit(Object * windowObject);          /* exit gracefully                     */
  148. void processEvents(Object * windowObject);      /* handle IDCMP events                 */
  149. void clearGadgets(void);                        /* empty StringGadgets                 */
  150. void doASCII(void);                             /* convert character to its ASCII Code */
  151.    
  152.  
  153. int main(void)
  154. {
  155.     /* --- declare Titles for Screen and Window from Constants in "version.h" --- */
  156.     char screentitle[32];
  157.     char windowtitle[32];
  158.                
  159.     struct MsgPort *appPort;        /* we need a message port for Intuition messages */
  160.        
  161.     /* --- Let´s open needed Libraries --- */
  162.     if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 47)))
  163.         cleanexit(NULL);
  164.     if (!(IconBase = (struct Library *) OpenLibrary("icon.library", 47)))
  165.         cleanexit(NULL);
  166.     if (!(WindowBase = OpenLibrary("window.class", 47)))
  167.         cleanexit(NULL);
  168.     if (!(LayoutBase = OpenLibrary("gadgets/layout.gadget", 47)))
  169.         cleanexit(NULL);
  170.     if (!(ButtonBase = OpenLibrary("gadgets/button.gadget", 47)))
  171.         cleanexit(NULL);
  172.     if (!(StringBase = OpenLibrary("gadgets/string.gadget", 47)))
  173.         cleanexit(NULL);
  174.     if (!(LabelBase = OpenLibrary("images/label.image", 47)))
  175.         cleanexit(NULL);
  176.     if (!(BevelBase = OpenLibrary("images/bevel.image", 47)))
  177.         cleanexit(NULL);
  178.     if (!(RequesterBase = OpenLibrary("requester.class", 47))) 
  179.         cleanexit(NULL);  
  180.    
  181.     /* --- Requesters --- */
  182.     aboutReq = NewObject( REQUESTER_GetClass(), NULL,
  183.                             REQ_TitleText, "About raConvert",
  184.                             REQ_Type, REQTYPE_INFO,
  185.                             REQ_Image, REQIMAGE_INFO,
  186.                             REQ_BodyText, "raConvert is a ReAction-based graphical \ninterface for ASCII code conversion.\n\n AmigaOS 3.2.x is needed to run it.\n\nAuthor: Micha B. 2022\nWeb: www.amiga.mbergmann-sh.de ",
  187.                             REQ_GadgetText, "Understood",
  188.                             TAG_DONE);
  189.    
  190.     emptyReq = NewObject( REQUESTER_GetClass(), NULL,
  191.                             REQ_TitleText, "raConvert User Error",
  192.                             REQ_Type, REQTYPE_INFO,
  193.                             REQ_Image, REQIMAGE_WARNING,
  194.                             REQ_BodyText, "You did not enter a character.",
  195.                             REQ_GadgetText, "OK",
  196.                             TAG_DONE);
  197.                            
  198.     noasciiReq = NewObject( REQUESTER_GetClass(), NULL,
  199.                             REQ_TitleText, "raConvert ASCII Error",
  200.                             REQ_Type, REQTYPE_INFO,
  201.                             REQ_Image, REQIMAGE_INFO,
  202.                             REQ_BodyText, "That does not look like an ASCII character.\n Maybe a german Umlaut or some other special\ncharacter? ",
  203.                             REQ_GadgetText, "OK",
  204.                             TAG_DONE);
  205.    
  206.     quitReq = NewObject( REQUESTER_GetClass(), NULL,
  207.                             REQ_TitleText, "Quit raConvert",
  208.                             REQ_Type, REQTYPE_INFO,
  209.                             REQ_Image, REQIMAGE_QUESTION,
  210.                             REQ_BodyText, " Really terminate the program? ",
  211.                             REQ_GadgetText, "OK|Cancel",
  212.                             REQ_EvenButtons, TRUE,
  213.                             TAG_DONE);
  214.    
  215.     /*
  216.      * Define our Gadgets:    
  217.      --- This is our first StringGadget (takes character to convert) --- */
  218.     inString = NewObject( STRING_GetClass(), NULL,
  219.                             GA_ID, GID_INSTRING,
  220.                             GA_RelVerify, TRUE,
  221.                             STRINGA_TextVal, "",     /* this Tag holds the value of the Gadget! */
  222.                             STRINGA_MinVisible, 4,   /* this determines Gadget´s size */
  223.                             STRINGA_MaxChars, 2,     /* we want the user to input max. 1 charakter */
  224.                             STRINGA_Justification, GACT_STRINGCENTER,    /* center text in Gadget */                           
  225.                             TAG_DONE);
  226.                            
  227.     /* --- This is our second StringGadget (shows converted ASCII code) --- */
  228.     outString = NewObject( STRING_GetClass(), NULL,
  229.                             GA_ID, GID_OUTSTRING,
  230.                             GA_RelVerify, TRUE,
  231.                             STRINGA_TextVal, "",     /* this Tag holds the value of the Gadget! */
  232.                             STRINGA_MinVisible, 4,
  233.                             STRINGA_MaxChars, 4,     /* we need 3 characters for an ASCII-Code to display */
  234.                             STRINGA_Justification, GACT_STRINGCENTER,    /* center text in Gadget */                           
  235.                             TAG_DONE);
  236.                            
  237.     /* --- define clearButton instance (first ButtoGadget) --- */
  238.     clearButton = NewObject( BUTTON_GetClass(), NULL,
  239.                             GA_ID, GID_CLEARBUTTON,
  240.                             GA_RelVerify, TRUE,
  241.                             GA_Text, "C_lear",
  242.                             BUTTON_TextPadding, TRUE,
  243.                             GA_TabCycle, TRUE,
  244.                             TAG_DONE);
  245.                            
  246.     /* --- define convertButton instance (second ButtonGadget) --- */
  247.     convertButton = NewObject( BUTTON_GetClass(), NULL,
  248.                             GA_ID, GID_CONVERTBUTTON,
  249.                             GA_RelVerify, TRUE,
  250.                             GA_Text, "_Convert",
  251.                             BUTTON_TextPadding, TRUE,
  252.                             GA_TabCycle, TRUE,
  253.                             TAG_DONE);
  254.                            
  255.     /* --- this is the Label that will show Help messages ---*/
  256.     helpButton = NewObject( BUTTON_GetClass(), NULL,
  257.                             GA_ID, GID_HELPBUTTON,
  258.                             GA_ReadOnly, TRUE,
  259.                             GA_Text, "GadgetHelp is active",
  260.                             BUTTON_Justification, LJ_CENTRE,                          
  261.                    
  262.                             TAG_DONE);
  263.      
  264.     /*
  265.      * Define our Layouts:    
  266.      --- This is our beveled horizontal Layout that shows up first --- */
  267.     topLayout = NewObject(LAYOUT_GetClass(), NULL,
  268.                LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  269.                //LAYOUT_DeferLayout, TRUE,
  270.                LAYOUT_SpaceInner, TRUE,
  271.                LAYOUT_SpaceOuter, TRUE,
  272.                LAYOUT_BevelStyle, BVS_GROUP,
  273.                
  274.                /* --- Pseudo-Spacer! --- */
  275.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL, LABEL_Text, "",
  276.                 TAG_END),
  277.                 CHILD_WeightedWidth, 98,
  278.                
  279.                /* --- Add Label --- */
  280.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL,
  281.                    LABEL_Text, "Please enter a character\nand then press ´Convert´ or <Return>",
  282.                    LABEL_Justification, LJ_CENTRE,                          
  283.                    TAG_END),
  284.                    CHILD_WeightedWidth, 0,
  285.                
  286.                /* --- Pseudo-Spacer! --- */
  287.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL, LABEL_Text, "",
  288.                 TAG_END),
  289.                 CHILD_WeightedWidth, 98,               
  290.                TAG_DONE);
  291.                
  292.     /* --- This is our 1. non-beveled horizontal Layout holds first Label/StringGadget pair --- */
  293.     string1Layout = NewObject(LAYOUT_GetClass(), NULL,
  294.                LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  295.                //LAYOUT_DeferLayout, TRUE,
  296.                LAYOUT_SpaceInner, TRUE,
  297.                LAYOUT_SpaceOuter, TRUE,
  298.                LAYOUT_BevelStyle, BVS_NONE,  /* you could as well leave this Tag out! */
  299.                
  300.                /* --- Add Label -- */
  301.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL,
  302.                    LABEL_Text, "Enter character you wish to convert:",
  303.                    LABEL_Justification, LJ_LEFT,                          
  304.                    TAG_END),
  305.                    CHILD_WeightedWidth, 90,
  306.                /* --- Add 1. StringGadget --- */
  307.                LAYOUT_AddChild, inString,
  308.                CHILD_WeightedHeight, 0,
  309.                CHILD_WeightedWidth, 0,   /* make 1. StringGadget non-expanding */                          
  310.                TAG_DONE);
  311.  
  312.     /* --- This is our 2. non-beveled horizontal Layout holds second Label/StringGadget pair --- */
  313.     string2Layout = NewObject(LAYOUT_GetClass(), NULL,
  314.                LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  315.                //LAYOUT_DeferLayout, TRUE,
  316.                LAYOUT_SpaceInner, TRUE,
  317.                LAYOUT_SpaceOuter, TRUE,
  318.                LAYOUT_BevelStyle, BVS_NONE,  /* you could as well leave this Tag out! */
  319.                
  320.                /* --- Add Label -- */
  321.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL,
  322.                    LABEL_Text, "The ASCII Code for this character is:",
  323.                    LABEL_Justification, LJ_LEFT,                          
  324.                    TAG_END),
  325.                    CHILD_WeightedWidth, 90,
  326.                /* --- Add 2. StringGadget --- */
  327.                LAYOUT_AddChild, outString,
  328.                CHILD_WeightedHeight, 0,
  329.                CHILD_WeightedWidth, 0,   /* make 2. StringGadget non-expanding */                          
  330.                TAG_DONE);
  331.                
  332.     /* --- This is our 2. non-beveled horizontal Layout holds second Label/StringGadget pair --- */
  333.     buttonLayout = NewObject(LAYOUT_GetClass(), NULL,
  334.                LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  335.                //LAYOUT_DeferLayout, TRUE,
  336.                LAYOUT_SpaceInner, TRUE,
  337.                LAYOUT_SpaceOuter, TRUE,
  338.                LAYOUT_TopSpacing, 5,                 /* make some extra space! */
  339.                LAYOUT_BottomSpacing, 7,
  340.                LAYOUT_BevelStyle, BVS_SBAR_VERT,     /* puts a thin bevel frame around the Layout */
  341.                LAYOUT_Label, "Control Panel",        /* Bevel Text... */
  342.                LAYOUT_LabelPlace, BVJ_TOP_CENTER,    /* ...placed on Top of Bevel, centered */
  343.                /* --- Pseudo-Spacer! --- */
  344.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL, LABEL_Text, "",
  345.                 TAG_END),
  346.                 CHILD_WeightedWidth, 6,
  347.                
  348.                /* --- Add 1. ButtonGadget --- */
  349.                LAYOUT_AddChild, clearButton,
  350.                CHILD_WeightedHeight, 0,
  351.                CHILD_WeightedWidth, 42,
  352.                
  353.                /* --- Pseudo-Spacer! --- */
  354.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL, LABEL_Text, "",
  355.                 TAG_END),
  356.                 CHILD_WeightedWidth, 6,
  357.                
  358.                /* --- Add 2. ButtonGadget --- */
  359.                LAYOUT_AddChild, convertButton,
  360.                CHILD_WeightedHeight, 0,
  361.                CHILD_WeightedWidth, 42,
  362.                
  363.                /* --- Pseudo-Spacer! --- */
  364.                LAYOUT_AddImage, NewObject( LABEL_GetClass(), NULL, LABEL_Text, "",
  365.                 TAG_END),
  366.                 CHILD_WeightedWidth, 6,
  367.                                            
  368.                TAG_DONE);              
  369.    
  370.     /* --- This is our Main Layout. It holds all capsulated sub layouts --- */
  371.     mainLayout = NewObject(LAYOUT_GetClass(), NULL,
  372.                LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  373.                LAYOUT_DeferLayout, TRUE,
  374.                LAYOUT_SpaceInner, TRUE,
  375.                LAYOUT_SpaceOuter, TRUE,
  376.                //LAYOUT_BevelStyle, BVS_BUTTON,
  377.                
  378.                /* -- Add titeling Label -- */
  379.                LAYOUT_AddChild, topLayout,
  380.                CHILD_WeightedHeight, 0,
  381.                CHILD_WeightedWidth, 100,
  382.                
  383.                /* -- Add first Label/StringGadget pair --- */
  384.                LAYOUT_AddChild, string1Layout,
  385.                CHILD_WeightedHeight, 0,
  386.                CHILD_WeightedWidth, 100,
  387.                
  388.                /* -- Add second Label/StringGadget pair -- */
  389.                LAYOUT_AddChild, string2Layout,
  390.                CHILD_WeightedHeight, 0,
  391.                CHILD_WeightedWidth, 100,
  392.                
  393.                /* -- Add two-Button Layout -- */
  394.                LAYOUT_AddChild, buttonLayout,
  395.                CHILD_WeightedHeight, 0,
  396.                CHILD_WeightedWidth, 100,
  397.                
  398.                /* -- finaly, add a "StatusBar" -- */           
  399.                LAYOUT_AddChild, helpButton,
  400.                CHILD_WeightedHeight, 0,
  401.                CHILD_WeightedWidth, 100,
  402.                TAG_DONE);
  403.                
  404.     /* --- initialize IDCMPHook for listening to IDCMP Messages --- */
  405.     IDCMPHook.h_Entry = (ULONG(*)())processIDCMP;
  406.     IDCMPHook.h_SubEntry = NULL;
  407.     IDCMPHook.h_Data = NULL;
  408.     appPort = CreateMsgPort();
  409.    
  410.     /* --- Fill our window- and screen title with life... --- */
  411.     sprintf(windowtitle, "%s v%s.%s", PROGRAMNAME, VERSION, SUBVERSION);
  412.     sprintf(screentitle, "%s v%s.%s.%s %s", PROGRAMNAME, VERSION, SUBVERSION, REVISION, "by Micha B.");
  413.    
  414.     /* --- define our Window Object --- */
  415.     windowObject = NewObject(WINDOW_GetClass(), NULL,
  416.                  WINDOW_Position, WPOS_CENTERSCREEN,
  417.                  WA_Activate, TRUE,
  418.                  WA_Title, (ULONG) windowtitle,          /* here goes our constructed window title */
  419.                  WA_ScreenTitle, (ULONG) screentitle,    /* here goes our constructed screen title */
  420.                  WA_DragBar, TRUE,
  421.                  WA_CloseGadget, TRUE,
  422.                  WA_DepthGadget, TRUE,
  423.                  WA_SizeGadget, TRUE,
  424.                  WA_InnerWidth, 250,
  425.                  WA_InnerHeight, 50,
  426.                  WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW,
  427.                  WINDOW_GadgetHelp, TRUE,                /* enable Gadget help functionallity */
  428.                  WINDOW_Layout, mainLayout,
  429.                  WINDOW_IconifyGadget, TRUE,
  430.                  WINDOW_IDCMPHook, &IDCMPHook,
  431.                  WINDOW_IDCMPHookBits, IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW,
  432.                  WINDOW_AppPort, appPort,
  433.                  WINDOW_AppWindow, TRUE,
  434.                  //WINDOW_Icon, GetDiskObject("PROGDIR:raConvert"),    /* icon that is shown when app is iconified */
  435.                  WA_NewLookMenus, TRUE,
  436.                  WINDOW_NewMenu, menu,       /* here we attach our formerly defined window menu */
  437.                  TAG_DONE);
  438.                  
  439.    
  440.     /* --- was our Window Object created correctly? --- */
  441.     if (!windowObject)
  442.         cleanexit(NULL);
  443.        
  444.     /* --- Try to open our Window! --- */  
  445.     if (!(intuiwin = (struct Window *) DoMethod(windowObject, WM_OPEN, NULL)))
  446.         cleanexit(windowObject);
  447.        
  448.     /* --- let´s activate inString for user input (Focus) --- */
  449.     ActivateLayoutGadget((struct Gadget *)mainLayout, intuiwin, NULL, (ULONG)inString);
  450.        
  451.     /* --- Handle IDCMP messages --- */
  452.     processEvents(windowObject);
  453.    
  454.     /* --- After receiving a WMHI_CLOSEWINDOW message, close our Window --- */
  455.     DoMethod(windowObject, WM_CLOSE);
  456.    
  457.     /* --- Finally, free Requester Objects ---- */
  458.     /* IMPORTANT! You MUST free all declared    */
  459.     /* Requesters, even if you do not use them. */
  460.     /* Otherwise your program will crash when   */
  461.     /* restarted!                               */
  462.     DisposeObject( noasciiReq );
  463.     DisposeObject( aboutReq );
  464.     DisposeObject( quitReq );
  465.     DisposeObject( emptyReq );
  466.    
  467.     /* --- clean up things and quit the program --- */
  468.     cleanexit(windowObject);
  469.    
  470. }   /* main() END */
  471.  
  472. /*
  473.  * Function: clearGadgets()
  474.  *      empty the StringGadgets
  475.  */
  476. void clearGadgets(void)
  477. {
  478.     /* --- empty the StringGadgets... --- */
  479.     SetGadgetAttrs( (struct Gadget *)inString, intuiwin, NULL, STRINGA_TextVal, "", TAG_END );
  480.     SetGadgetAttrs( (struct Gadget *)outString, intuiwin, NULL, STRINGA_TextVal, "", TAG_END );
  481.    
  482.     /* --- ...and give the Focus back to our first StringGadget for input! --- */
  483.     ActivateLayoutGadget((struct Gadget *)mainLayout, intuiwin, NULL, (ULONG)inString);
  484. }
  485.  
  486.  
  487. /*
  488.  * Function: doASCII()
  489.  *      get inString content, convert to ASCII code, put result into outString
  490.  */
  491. void doASCII(void)
  492. {
  493.     char *inCharacter;
  494.     char *outCharacter = " ";
  495.     int i = 0;
  496.    
  497.     /* --- get character from inString StringGadget --- */
  498.     GetAttr(STRINGA_TextVal, (APTR)inString, (ULONG *)&inCharacter);
  499.    
  500.     /* --- if not empty, convert and put into outString StringGadget --- */
  501.     if(!(strcmp((char const *)inCharacter, "")))
  502.     {
  503.         OpenRequester(emptyReq, intuiwin);
  504.         clearGadgets();        
  505.     }
  506.     else
  507.     {
  508.         i = (int)inCharacter[0];
  509.        
  510.         /* --- convert! --- */          
  511.         sprintf(outCharacter, "%d", (int)inCharacter[0]);
  512.         /* --- put result into outString --- */
  513.         SetGadgetAttrs( (struct Gadget *)outString, intuiwin, NULL, STRINGA_TextVal, outCharacter, TAG_END );
  514.        
  515.         /* --- Umlaut or non-ASCII? ---*/
  516.         if (i <= 0)
  517.         {
  518.             OpenRequester(noasciiReq, intuiwin);
  519.             clearGadgets();
  520.         }      
  521.     }  
  522. }   /* doASCII() END */  
  523.  
  524.  
  525. /*
  526.  * Function: processEvents()
  527.  *      here, all event handling is done
  528.  */
  529. void processEvents(Object * windowObject)
  530. {
  531.     ULONG windowsignal;
  532.     ULONG receivedsignal;
  533.     ULONG result;
  534.     ULONG code;
  535.     ULONG req_button;
  536.     BOOL end = FALSE;
  537.    
  538.     GetAttr(WINDOW_SigMask, windowObject, &windowsignal);
  539.     while (!end)
  540.     {
  541.         receivedsignal = Wait(windowsignal);
  542.         while ((result = DoMethod(windowObject, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
  543.         {
  544.             switch (result & WMHI_CLASSMASK)
  545.             {
  546.                 /* --- Window IDCMP messages --- */
  547.                 case WMHI_CLOSEWINDOW:
  548.                     req_button = OpenRequester(quitReq, intuiwin);
  549.                     if(req_button)              
  550.                         end = TRUE;
  551.                     break;
  552.                 case WMHI_ICONIFY:
  553.                     DoMethod(windowObject, WM_ICONIFY, NULL);
  554.                     #ifdef _DEBUG
  555.                         kprintf("WMHI_ICONIFY - WARNING: Crash expected.\n");                      
  556.                     #endif         
  557.                     break;
  558.                 case WMHI_UNICONIFY:
  559.                     DoMethod(windowObject, WM_OPEN, NULL);
  560.                     /* --- ...and give the Focus back to our first StringGadget for input! --- */
  561.                     ActivateLayoutGadget((struct Gadget *)mainLayout, intuiwin, NULL, (ULONG)inString);
  562.                     #ifdef _DEBUG
  563.                         kprintf("WMHI_UNICONIFY - WARNING: Crash expected.\n");                    
  564.                     #endif
  565.                     break;
  566.                    
  567.                 case WMHI_ACTIVE:
  568.                     /* --- give the Focus back to our first StringGadget for input! --- */
  569.                     ActivateLayoutGadget((struct Gadget *)mainLayout, intuiwin, NULL, (ULONG)inString);
  570.                     break; 
  571.                 /* --- Menu IDCMP messages --- */  
  572.                 case WMHI_MENUPICK:
  573.                     /* Use this to find out menu entry addresses and put them in #defines: */
  574.                     #ifdef _DEBUG
  575.                         kprintf("\nSome Menu picked.\n");
  576.                         kprintf("Entry´s Adress: %ld\n",result & WMHI_MENUMASK);
  577.                     #endif
  578.                                                          
  579.                     switch (result & WMHI_MENUMASK)
  580.                     {
  581.                         case MN_ABOUT:                            
  582.                             /* --- display about message... --- */
  583.                             req_button = OpenRequester(aboutReq, intuiwin);                            
  584.                             /* --- ...and give the Focus back to our first StringGadget for input! --- */
  585.                             ActivateLayoutGadget((struct Gadget *)mainLayout, intuiwin, NULL, (ULONG)inString);                          
  586.                             break;
  587.                         case MN_GADGETHELP:
  588.                             /* --- find out if menu entry is checked --- */                            
  589.                             break;
  590.                         case MN_QUIT:
  591.                             /* --- ask if user wants to quit... --- */
  592.                             req_button = OpenRequester(quitReq, intuiwin);
  593.                             if(req_button)              
  594.                                 end = TRUE;
  595.                             break;                                                                                          
  596.                     }   /* switch WMHI_MENUMASK */                 
  597.                     break;
  598.                 case WMHI_GADGETUP:
  599.                     #ifdef _DEBUG
  600.                         kprintf("GadgetUP!\n");
  601.                     #endif
  602.                     switch (result & WMHI_GADGETMASK)
  603.                     {
  604.                         case GID_INSTRING:
  605.                             doASCII();
  606.                             break;
  607.                         case GID_CLEARBUTTON:
  608.                             clearGadgets();
  609.                             break;
  610.                         case GID_CONVERTBUTTON:
  611.                             doASCII();
  612.                             break;
  613.                     }   /* switch WMHI_GADGETMASK*/
  614.                     break;
  615.                 case WMHI_GADGETHELP:
  616.                     {                      
  617.                         STRPTR helptext;
  618.                        
  619.                         /* A gadget help message informs the application about the gadget
  620.                          * under the mouse pointer. The code WORD is set to the value the
  621.                          * gadget returned. Result code contains the ID of the gadget,
  622.                          * or NULL (not in the window) or WMHI_GADGETMASK (not over a gadget).
  623.                          */
  624.                    
  625.                         switch(result & WMHI_GADGETMASK)
  626.                         {
  627.                         case GID_INSTRING:
  628.                             helptext = "Insert here: Character to convert";
  629.                             break;
  630.                         case GID_OUTSTRING:
  631.                             helptext = "Show ASCII-Code";
  632.                             break; 
  633.                         case GID_CLEARBUTTON:
  634.                             helptext = "Clear input and result";
  635.                             break;
  636.                         case GID_CONVERTBUTTON:
  637.                             helptext = "Start Conversion to ASCII-Code";
  638.                             break;                             
  639.                         default:
  640.                             helptext = "";
  641.                             break;
  642.                         }
  643.                         /*
  644.                         if (SetGadgetAttrs( GL[G_Help], Win, NULL, GA_Text, helptext, TAG_END ))
  645.                             RefreshGList(GL[G_Help], Win, NULL, 1); */
  646.                            
  647.                         if(SetGadgetAttrs( (struct Gadget *)helpButton, intuiwin, NULL, GA_Text, helptext, TAG_END ))
  648.                             RefreshGadgets((struct Gadget *)helpButton, intuiwin, NULL);                           
  649.                     }
  650.                     break;
  651.             }  /* switch WMHI_CLASSMASK */
  652.         }  /* while result */
  653.     }   /* while !end */
  654. }   /* processEvent END */
  655.  
  656.  
  657. /*
  658.  *  Function: cleanexit()
  659.  *      here we clean up things before exiting
  660.  */
  661. void cleanexit(Object * windowObject)
  662. {
  663.     /* --- if theres a valid Window Object... --- */
  664.     if (windowObject)
  665.         DisposeObject(windowObject); /* ... we will dispose it.*/
  666.    
  667.     /* --- Afterwards, we´ll close all opened Libraries. --- */
  668.     CloseLibrary((struct Library *) IconBase);
  669.     CloseLibrary((struct Library *) IntuitionBase);
  670.     CloseLibrary(RequesterBase);
  671.     CloseLibrary(BevelBase);
  672.     CloseLibrary(LabelBase);
  673.     CloseLibrary(StringBase);
  674.     CloseLibrary(ButtonBase);
  675.     CloseLibrary(WindowBase);
  676.     CloseLibrary(LayoutBase);
  677.    
  678.     exit(0);
  679. }   /* cleanexit() END */
  680.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement