home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / 3_1EXAM1.DMS / in.adf / asl / asltester / reqtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  17.3 KB  |  464 lines

  1.  
  2. /*
  3. COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1992-1993
  4. Commodore-Amiga, Inc.  All rights reserved.
  5.  
  6. DISCLAIMER: This software is provided "as is".  No representations or
  7. warranties are made with respect to the accuracy, reliability, performance,
  8. currentness, or operation of this software, and all use is at your own risk.
  9. Neither commodore nor the authors assume any responsibility or liability
  10. whatsoever with respect to your use of this software.
  11. */
  12.  
  13.  
  14. /****************************************************************************/
  15.  
  16.  
  17. #include <exec/types.h>
  18. #include <intuition/intuition.h>
  19. #include <graphics/displayinfo.h>
  20. #include <utility/hooks.h>
  21. #include <libraries/asl.h>
  22. #include <libraries/locale.h>
  23. #include <dos/dosasl.h>
  24. #include <string.h>
  25.  
  26. #include <clib/exec_protos.h>
  27. #include <clib/intuition_protos.h>
  28. #include <clib/asl_protos.h>
  29. #include <clib/locale_protos.h>
  30. #include <clib/dos_protos.h>
  31. #include <clib/alib_protos.h>
  32.  
  33. #include <pragmas/exec_pragmas.h>
  34. #include <pragmas/intuition_pragmas.h>
  35. #include <pragmas/asl_pragmas.h>
  36. #include <pragmas/locale_pragmas.h>
  37. #include <pragmas/dos_pragmas.h>
  38.  
  39. #include "reqtest.h"
  40. #include "gadgets.h"
  41.  
  42.  
  43. /****************************************************************************/
  44.  
  45.  
  46. extern struct Library *IntuitionBase;
  47. extern struct Library *LocaleBase;
  48. extern struct Library *SysBase;
  49. extern struct Library *AslBase;
  50. extern struct Library *DOSBase;
  51. extern struct Window  *window;
  52. extern struct Screen  *screen;
  53.  
  54.  
  55. /****************************************************************************/
  56.  
  57.  
  58. VOID kprintf(STRPTR,...);
  59.  
  60.  
  61. /****************************************************************************/
  62.  
  63.  
  64. /* Say something to the user... */
  65. static VOID Report(STRPTR text)
  66. {
  67. struct EasyStruct est;
  68.  
  69.     est.es_StructSize   = sizeof(struct EasyStruct);
  70.     est.es_Flags        = 0;
  71.     est.es_Title        = NULL;
  72.     est.es_TextFormat   = text;
  73.     est.es_GadgetFormat = "Continue";
  74.  
  75.     EasyRequestArgs(window,&est,NULL,NULL);
  76. }
  77.  
  78.  
  79. /*****************************************************************************/
  80.  
  81.  
  82. /* This function gets called whenever a new file or directory is about to be
  83.  * added to to the list in a file requester. It lets an application filter out
  84.  * entries it doesn't want. You can look at the fields in the AnchorPath
  85.  * structure to decide whether you want this entry added to the list or not.
  86.  * Return TRUE if the entry should be added, return FALSE otherwise.
  87.  */
  88. static ULONG __asm FileFilter(register __a0 struct Hook *hook,
  89.                               register __a2 struct FileRequester *fr,
  90.                               register __a1 struct AnchorPath *anchor)
  91. {
  92.     kprintf("FileFilter(): name is '%s'\n",anchor->ap_Info.fib_FileName);
  93.     return(TRUE);
  94. }
  95.  
  96.  
  97. /*****************************************************************************/
  98.  
  99.  
  100. /* This function gets called whenever a new font or size is about to be
  101.  * added to to the lists in a font requester. It lets an application filter out
  102.  * entries it doesn't want. You can look at the fields in the TextAttr
  103.  * structure to decide whether you want this entry added to the list or not.
  104.  * Return TRUE if the entry should be added, return FALSE otherwise.
  105.  */
  106. static ULONG __asm FontFilter(register __a0 struct Hook *hook,
  107.                               register __a2 struct FontRequester *fo,
  108.                               register __a1 struct TextAttr *textAttr)
  109. {
  110.     kprintf("FontFilter(): name is '%s', size is %ld\n",textAttr->ta_Name,textAttr->ta_YSize);
  111.     return(TRUE);
  112. }
  113.  
  114.  
  115. /*****************************************************************************/
  116.  
  117.  
  118. /* This function gets called whenever a new screen mode is about to be
  119.  * added to to the list in a screen mode requester. It lets an application
  120.  * filter out entries it doesn't want. You can query the display database
  121.  * using the provided mode id to decide whether you want this entry added to
  122.  * the list or not. Return TRUE if the entry should be added, return FALSE
  123.  * otherwise.
  124.  */
  125. static ULONG __asm ScreenModeFilter(register __a0 struct Hook *hook,
  126.                                     register __a2 struct ScreenModeRequester *smr,
  127.                                     register __a1 ULONG modeID)
  128. {
  129.     kprintf("ScreenModeFilter(): mode is id 0x%08lx\n",modeID);
  130.     return(TRUE);
  131. }
  132.  
  133.  
  134. /*****************************************************************************/
  135.  
  136.  
  137. /* This function gets called whenever an IntuiMessage comes in to a
  138.  * requester IDCMP, which is not meant for the requester itself. That is,
  139.  * when the IntuiMessage's IDCMPWindow field does not point to the
  140.  * requester's window. This happens when an IDCMP is shared between a
  141.  * parent window and a requester. Within this function, you can attend to
  142.  * the IDCMP event for your window. If your application is using many windows,
  143.  * you can look at the IDCMPWindow field of the event to figure out to
  144.  * which window this event is addressed.
  145.  *
  146.  * This function is typically used to refresh damage that occurs in a window
  147.  * while an ASL requester is up.
  148.  */
  149. static ULONG __asm IntuiMsgFunc(register __a0 struct Hook *hook,
  150.                                 register __a1 struct IntuiMessage *intuiMsg,
  151.                                 register __a2 struct Requester *req)
  152. {
  153.     kprintf("IntuiMsgFunc(): class is 0x%08lx, code = 0x%04lx\n",intuiMsg->Class,intuiMsg->Code);
  154.     return(TRUE);
  155. }
  156.  
  157.  
  158. /*****************************************************************************/
  159.  
  160.  
  161. #define SETTAG(tag,value) {tags[cnt].ti_Tag = tag; tags[cnt].ti_Data = (ULONG)value; cnt++;}
  162. #define SETTEXTTAG(tag,value) {if (value[0]) {tags[cnt].ti_Tag = tag; tags[cnt].ti_Data = (ULONG)value; cnt++;}}
  163. #define SETHOOKTAG(tag,state,hook,function) {if (state) {hook.h_Entry = (HOOKFUNC)function; SETTAG(tag,&hook)}}
  164.  
  165.  
  166. /* This is where it all happens...
  167.  *
  168.  * This function opens up an ASL requester. The requester's options are set in
  169.  * accordance to the contents of the 4 structure passed as parameter. The
  170.  * requesterType variable determines which type of requester gets displayed.
  171.  */
  172. VOID TestRequester(struct CommonData *cd,
  173.                    struct FileReqData *frd,
  174.                    struct FontReqData *fod,
  175.                    struct ScreenModeReqData *smrd,
  176.                    ULONG requesterType)
  177. {
  178. APTR                requester;
  179. struct TagItem      tags[80];
  180. ULONG               cnt;
  181. struct Requester    sleepReq;
  182. BOOL                sleeping;
  183. struct Locale      *locale;
  184. struct TextAttr     textAttr;
  185. struct Hook         filterHook;
  186. struct Hook         intuiMsgHook;
  187. char                acceptPattern[sizeof(frd->AcceptPattern)];
  188. char                rejectPattern[sizeof(frd->RejectPattern)];
  189. STRPTR              fmodes[5];
  190. struct List         dmodeList;
  191. struct DisplayMode  dmode;
  192. struct Window      *refWindow;
  193. struct Screen      *refScreen1;
  194. struct Screen      *refScreen2;
  195. STRPTR              refName;
  196.  
  197.     InitRequester(&sleepReq);
  198.     sleeping = Request(&sleepReq,window);
  199.     SetWindowPointer(window,WA_BusyPointer,TRUE,TAG_DONE);
  200.  
  201.     memset(tags,0,sizeof(tags));
  202.     cnt = 0;
  203.  
  204.     locale = NULL;
  205.     if (cd->Locale[0])
  206.         locale = OpenLocale(cd->Locale);
  207.  
  208.     textAttr.ta_Name  = cd->FontName;
  209.     textAttr.ta_YSize = cd->FontSize;
  210.     textAttr.ta_Style = 0;
  211.     textAttr.ta_Flags = FPF_DISKFONT;
  212.  
  213.     refWindow  = NULL;
  214.     refScreen1 = NULL;
  215.     refScreen2 = NULL;
  216.     refName    = NULL;
  217.     if (cd->RefObject == REF_WINDOW)
  218.     {
  219.         refWindow = OpenWindowTags(NULL,WA_Width,         200,
  220.                                         WA_Height,        screen->WBorTop + screen->Font->ta_YSize + 1,
  221.                                         WA_Title,         "Reference Window",
  222.                                         WA_PubScreen,     screen,
  223.                                         WA_DragBar,       TRUE,
  224.                                         WA_DepthGadget,   TRUE,
  225.                                         WA_NoCareRefresh, TRUE,
  226.                                         WA_SimpleRefresh, TRUE,
  227.                                         WA_AutoAdjust,    TRUE,
  228.                                         TAG_DONE);
  229.     }
  230.     else if (cd->RefObject == REF_SCREEN)
  231.     {
  232.         refScreen1 = OpenScreenTags(NULL,SA_LikeWorkbench,TRUE,
  233.                                          SA_Title,        "ASLTESTER",
  234.                                          TAG_DONE);
  235.     }
  236.     else if (cd->RefObject == REF_PUBSCREENNAME)
  237.     {
  238.         refName    = "ASLTESTER";
  239.         refScreen2 = OpenScreenTags(NULL,SA_LikeWorkbench, TRUE,
  240.                                          SA_PubName,       "ASLTESTER",
  241.                                          SA_Title,         "ASLTESTER",
  242.                                          TAG_DONE);
  243.  
  244.         if (refScreen2)
  245.             PubScreenStatus(refScreen2,0);
  246.     }
  247.  
  248.     if (requesterType == REQ_FILE)
  249.     {
  250.         SETTAG(ASLFR_Window,refWindow);
  251.         SETTAG(ASLFR_Screen,refScreen1);
  252.         SETTAG(ASLFR_PubScreenName,refName);
  253.         SETTAG(ASLFR_InitialLeftEdge,cd->InitialLeftEdge);
  254.         SETTAG(ASLFR_InitialTopEdge,cd->InitialTopEdge);
  255.         SETTAG(ASLFR_InitialWidth,cd->InitialWidth);
  256.         SETTAG(ASLFR_InitialHeight,cd->InitialHeight);
  257.         SETTEXTTAG(ASLFR_TitleText,cd->TitleText);
  258.         SETTEXTTAG(ASLFR_PositiveText,cd->PositiveText);
  259.         SETTEXTTAG(ASLFR_NegativeText,cd->NegativeText);
  260.         SETTAG(ASLFR_Locale,locale);
  261.         SETTAG(ASLFR_PrivateIDCMP,cd->PrivateIDCMP);
  262.         SETTAG(ASLFR_SleepWindow,cd->SleepWindow);
  263.         SETHOOKTAG(ASLFR_IntuiMsgFunc,cd->IntuiMsgFunc,intuiMsgHook,IntuiMsgFunc);
  264.         SETHOOKTAG(ASLFR_FilterFunc,cd->FilterFunc,filterHook,FileFilter);
  265.  
  266.         if (cd->FontName[0])
  267.             SETTAG(ASLFR_TextAttr,&textAttr);
  268.  
  269.         SETTEXTTAG(ASLFR_InitialFile,frd->InitialFile);
  270.         SETTEXTTAG(ASLFR_InitialDrawer,frd->InitialDrawer);
  271.         SETTEXTTAG(ASLFR_InitialPattern,frd->InitialPattern);
  272.         SETTAG(ASLFR_DoSaveMode,frd->DoSaveMode);
  273.         SETTAG(ASLFR_DoMultiSelect,frd->DoMultiSelect);
  274.         SETTAG(ASLFR_DoPatterns,frd->DoPatterns);
  275.         SETTAG(ASLFR_DrawersOnly,frd->DrawersOnly);
  276.         SETTAG(ASLFR_RejectIcons,frd->RejectIcons);
  277.         SETTAG(ASLFR_FilterDrawers,frd->FilterDrawers);
  278.  
  279.         ParsePatternNoCase(frd->AcceptPattern,acceptPattern,sizeof(acceptPattern));
  280.         SETTEXTTAG(ASLFR_AcceptPattern,acceptPattern);
  281.  
  282.         ParsePatternNoCase(frd->RejectPattern,rejectPattern,sizeof(rejectPattern));
  283.         SETTEXTTAG(ASLFR_RejectPattern,rejectPattern);
  284.     }
  285.     else if (requesterType == REQ_FONT)
  286.     {
  287.         SETTAG(ASLFO_Window,refWindow);
  288.         SETTAG(ASLFO_Screen,refScreen1);
  289.         SETTAG(ASLFO_PubScreenName,refName);
  290.         SETTAG(ASLFO_InitialLeftEdge,cd->InitialLeftEdge);
  291.         SETTAG(ASLFO_InitialTopEdge,cd->InitialTopEdge);
  292.         SETTAG(ASLFO_InitialWidth,cd->InitialWidth);
  293.         SETTAG(ASLFO_InitialHeight,cd->InitialHeight);
  294.         SETTEXTTAG(ASLFO_TitleText,cd->TitleText);
  295.         SETTEXTTAG(ASLFO_PositiveText,cd->PositiveText);
  296.         SETTEXTTAG(ASLFO_NegativeText,cd->NegativeText);
  297.         SETTAG(ASLFO_Locale,locale);
  298.         SETTAG(ASLFO_PrivateIDCMP,cd->PrivateIDCMP);
  299.         SETTAG(ASLFO_SleepWindow,cd->SleepWindow);
  300.         SETHOOKTAG(ASLFO_IntuiMsgFunc,cd->IntuiMsgFunc,intuiMsgHook,IntuiMsgFunc);
  301.         SETHOOKTAG(ASLFO_FilterFunc,cd->FilterFunc,filterHook,FontFilter);
  302.  
  303.         if (cd->FontName[0])
  304.             SETTAG(ASLFO_TextAttr,&textAttr);
  305.  
  306.         SETTEXTTAG(ASLFO_InitialName,fod->InitialName);
  307.         SETTAG(ASLFO_InitialSize,fod->InitialSize);
  308.         SETTAG(ASLFO_InitialFrontPen,fod->InitialFrontPen);
  309.         SETTAG(ASLFO_InitialBackPen,fod->InitialBackPen);
  310.         SETTAG(ASLFO_InitialStyle,fod->InitialStyle);
  311.         SETTAG(ASLFO_InitialDrawMode,fod->InitialDrawMode);
  312.         SETTAG(ASLFO_DoFrontPen,fod->DoFrontPen);
  313.         SETTAG(ASLFO_DoBackPen,fod->DoBackPen);
  314.         SETTAG(ASLFO_DoStyle,fod->DoStyle);
  315.         SETTAG(ASLFO_DoDrawMode,fod->DoDrawMode);
  316.         SETTAG(ASLFO_FixedWidthOnly,fod->FixedWidthOnly);
  317.         SETTAG(ASLFO_MinHeight,fod->MinHeight);
  318.         SETTAG(ASLFO_MaxHeight,fod->MaxHeight);
  319.         SETTAG(ASLFO_MaxFrontPen,fod->MaxFrontPen);
  320.         SETTAG(ASLFO_MaxBackPen,fod->MaxBackPen);
  321.  
  322.         if (fod->ModeList)
  323.         {
  324.             /* Create an array of values to replace the name and label of
  325.              * the Mode gadget with custom stuff...
  326.              */
  327.             fmodes[0] = "MyModes";
  328.             fmodes[1] = "Custom-1";
  329.             fmodes[2] = "Custom-2";
  330.             fmodes[3] = "Custom-3";
  331.             fmodes[4] = NULL;
  332.             SETTAG(ASLFO_ModeList,&fmodes);
  333.         }
  334.     }
  335.     else /* if (requesterType == REQ_SCREENMODE) */
  336.     {
  337.         SETTAG(ASLSM_Window,refWindow);
  338.         SETTAG(ASLSM_Screen,refScreen1);
  339.         SETTAG(ASLSM_PubScreenName,refName);
  340.         SETTAG(ASLSM_InitialLeftEdge,cd->InitialLeftEdge);
  341.         SETTAG(ASLSM_InitialTopEdge,cd->InitialTopEdge);
  342.         SETTAG(ASLSM_InitialWidth,cd->InitialWidth);
  343.         SETTAG(ASLSM_InitialHeight,cd->InitialHeight);
  344.         SETTEXTTAG(ASLSM_TitleText,cd->TitleText);
  345.         SETTEXTTAG(ASLSM_PositiveText,cd->PositiveText);
  346.         SETTEXTTAG(ASLSM_NegativeText,cd->NegativeText);
  347.         SETTAG(ASLFO_Locale,locale);
  348.         SETTAG(ASLSM_PrivateIDCMP,cd->PrivateIDCMP);
  349.         SETTAG(ASLSM_SleepWindow,cd->SleepWindow);
  350.         SETHOOKTAG(ASLSM_IntuiMsgFunc,cd->IntuiMsgFunc,intuiMsgHook,IntuiMsgFunc);
  351.         SETHOOKTAG(ASLSM_FilterFunc,cd->FilterFunc,filterHook,ScreenModeFilter);
  352.  
  353.         if (cd->FontName[0])
  354.             SETTAG(ASLSM_TextAttr,&textAttr);
  355.  
  356.         SETTAG(ASLSM_InitialDisplayID,smrd->InitialDisplayID);
  357.         SETTAG(ASLSM_InitialDisplayWidth,smrd->InitialDisplayWidth);
  358.         SETTAG(ASLSM_InitialDisplayHeight,smrd->InitialDisplayHeight);
  359.         SETTAG(ASLSM_InitialDisplayDepth,smrd->InitialDisplayDepth);
  360.         SETTAG(ASLSM_InitialOverscanType,smrd->InitialOverscanType);
  361.         SETTAG(ASLSM_InitialInfoLeftEdge,smrd->InitialInfoLeftEdge);
  362.         SETTAG(ASLSM_InitialInfoTopEdge,smrd->InitialInfoTopEdge);
  363.         SETTAG(ASLSM_InitialInfoOpened,smrd->InitialInfoOpened);
  364.         SETTAG(ASLSM_InitialAutoScroll,smrd->InitialAutoScroll);
  365.         SETTAG(ASLSM_DoWidth,smrd->DoWidth);
  366.         SETTAG(ASLSM_DoHeight,smrd->DoHeight);
  367.         SETTAG(ASLSM_DoDepth,smrd->DoDepth);
  368.         SETTAG(ASLSM_DoOverscanType,smrd->DoOverscanType);
  369.         SETTAG(ASLSM_DoAutoScroll,smrd->DoAutoScroll);
  370.         SETTAG(ASLSM_PropertyFlags,smrd->PropertyFlags);
  371.         SETTAG(ASLSM_PropertyMask,smrd->PropertyMask);
  372.         SETTAG(ASLSM_MinWidth,smrd->MinWidth);
  373.         SETTAG(ASLSM_MaxWidth,smrd->MaxWidth);
  374.         SETTAG(ASLSM_MinHeight,smrd->MinHeight);
  375.         SETTAG(ASLSM_MaxHeight,smrd->MaxHeight);
  376.         SETTAG(ASLSM_MinDepth,smrd->MinDepth);
  377.         SETTAG(ASLSM_MaxDepth,smrd->MaxDepth);
  378.  
  379.         if (smrd->CustomSMList)
  380.         {
  381.             /* Create a list containing a single DisplayMode structure to use
  382.              * for a custom screen mode list
  383.              */
  384.             memset(&dmode,0,sizeof(struct DimensionInfo));
  385.             dmode.dm_Node.ln_Name                   = "Custom Mode";
  386.             dmode.dm_PropertyFlags                  = DIPF_IS_PAL|DIPF_IS_GENLOCK|DIPF_IS_WB;
  387.             dmode.dm_DimensionInfo.Header.StructID  = DTAG_DIMS;
  388.             dmode.dm_DimensionInfo.Header.DisplayID = 0xFFFF0001;
  389.             dmode.dm_DimensionInfo.Header.SkipID    = TAG_SKIP;
  390.             dmode.dm_DimensionInfo.Header.Length    = sizeof(struct DimensionInfo);
  391.             dmode.dm_DimensionInfo.MaxDepth         = 24;
  392.             dmode.dm_DimensionInfo.MinRasterWidth   = 16;
  393.             dmode.dm_DimensionInfo.MinRasterHeight  = 16;
  394.             dmode.dm_DimensionInfo.MaxRasterWidth   = 2048;
  395.             dmode.dm_DimensionInfo.MaxRasterHeight  = 2048;
  396.             dmode.dm_DimensionInfo.Nominal.MinX     = 0;
  397.             dmode.dm_DimensionInfo.Nominal.MinY     = 0;
  398.             dmode.dm_DimensionInfo.Nominal.MaxX     = 640;
  399.             dmode.dm_DimensionInfo.Nominal.MaxY     = 200;
  400.             dmode.dm_DimensionInfo.TxtOScan         = dmode.dm_DimensionInfo.Nominal;
  401.             dmode.dm_DimensionInfo.MaxOScan         = dmode.dm_DimensionInfo.Nominal;
  402.             dmode.dm_DimensionInfo.VideoOScan       = dmode.dm_DimensionInfo.Nominal;
  403.             dmode.dm_DimensionInfo.StdOScan         = dmode.dm_DimensionInfo.Nominal;
  404.  
  405.             NewList(&dmodeList);
  406.             AddHead(&dmodeList,&dmode);
  407.  
  408.             SETTAG(ASLSM_CustomSMList,&dmodeList);
  409.         }
  410.     }
  411.  
  412.     if (AslBase = OpenLibrary("asl.library",39))
  413.     {
  414.         if (requester = AllocAslRequest(requesterType,tags))
  415.         {
  416.             if (AslRequest(requester,NULL))
  417.             {
  418.                 // OK was selected
  419.                 // To be useful, we should now open a window and show the
  420.                 // values returned in the various requester structures
  421.             }
  422.             else
  423.             {
  424.                 if (IoErr())
  425.                 {
  426.                     Report("Could not present requester!");
  427.                 }
  428.                 else
  429.                 {
  430.                     Report("Cancel was selected.");
  431.                 }
  432.             }
  433.  
  434.             FreeAslRequest(requester);
  435.         }
  436.         else
  437.         {
  438.             Report("Could not create requester!");
  439.         }
  440.  
  441.         CloseLibrary(AslBase);
  442.     }
  443.     else
  444.     {
  445.         Report("Could not open asl.library V39!");
  446.     }
  447.  
  448.     if (refWindow)
  449.         CloseWindow(refWindow);
  450.  
  451.     if (refScreen1)
  452.         CloseScreen(refScreen1);
  453.  
  454.     if (refScreen2)
  455.         CloseScreen(refScreen2);
  456.  
  457.     CloseLocale(locale);
  458.  
  459.     if (sleeping)
  460.         EndRequest(&sleepReq,window);
  461.  
  462.     ClearPointer(window);
  463. }
  464.