home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.1 / Examples1 / asl / reqtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  17.3 KB  |  463 lines

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