Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "ASL Library"
Steven Solie (talk | contribs) |
Steven Solie (talk | contribs) |
||
Line 45: | Line 45: | ||
| ASLxx_FilterFunc || Function to call for each item (file, font or mode) encountered. If the function returns TRUE, the item is displayed in the list view gadget, otherwise it is rejected and not displayed. (This replaces the ASL_HookFunc tag and the FILF_DOWILDFUNC and FONF_DOWILDFUNC flags in ASL_FuncFLags used in V37.) |
| ASLxx_FilterFunc || Function to call for each item (file, font or mode) encountered. If the function returns TRUE, the item is displayed in the list view gadget, otherwise it is rejected and not displayed. (This replaces the ASL_HookFunc tag and the FILF_DOWILDFUNC and FONF_DOWILDFUNC flags in ASL_FuncFLags used in V37.) |
||
|} |
|} |
||
− | |||
− | == Creating a Font Requester == |
||
− | |||
− | The ASL library also contains a font requester. Using the font requester is very similar to using the file requester. First, allocate a requester structure with AllocAslRequest() or AllocAslRequestTags(). The type should be set to ASL_FontRequest in order to get a FontRequester structure: |
||
− | |||
− | <syntaxhighlight> |
||
− | struct FontRequester { |
||
− | APTR fo_Reserved1[2]; |
||
− | struct TextAttr fo_Attr; /* Returned TextAttr */ |
||
− | UBYTE fo_FrontPen; /* Returned pens, if selected */ |
||
− | UBYTE fo_BackPen; |
||
− | UBYTE fo_DrawMode; |
||
− | APTR fo_UserData; |
||
− | /* missing from asl.h but present in this structure */ |
||
− | SHORT fo_LeftEdge, fo_TopEdge, fo_Width, fo_Height; |
||
− | }; |
||
− | </syntaxhighlight> |
||
− | |||
− | Once the requester is set up, call AslRequest() or AslRequestTags() to make the requester appear on screen. These functions return TRUE if the user makes a selection. In that case, the font selected is returned as a TextAttr structure in the fo_Attr field of the FontRequester structure. (The TextAttr structure is defined in <graphics/text.h>. See the SDK for a complete listing.) If the user cancels the font requester FALSE is returned. |
||
− | |||
− | [[File:LibFig16-2.png|frame|center|The ASL Font Requester]] |
||
− | |||
− | When the requester is no longer needed, call FreeAslRequest() to deallocate the requester data structure. |
||
− | |||
− | === Specifying Font Requester Options With TagItems === |
||
− | |||
− | As with a file requester, the font requester is specified with a TagItem list. There are several tags that are specific to the font requester: |
||
− | |||
− | {| class="wikitable" |
||
− | ! Font Requester Tag Name |
||
− | ! Used For |
||
− | |- |
||
− | | ASLFO_InitialName || Initial font name selection |
||
− | |- |
||
− | | ASLFO_InitialSize || Initial font size |
||
− | |- |
||
− | | ASLFO_InitialStyle || Initial setting of font Style gadget |
||
− | |- |
||
− | | ASLFO_Flags || Various font requester options |
||
− | |- |
||
− | | ASLFO_InitialFrontPen || Initial setting of Front Color gadget |
||
− | |- |
||
− | | ASLFO_InitialBackPen || Initial setting of Back Color gadget |
||
− | |- |
||
− | | ASLFO_ModeList || Alternate strings for Mode cycle gadget (see below) |
||
− | |- |
||
− | | ASLFO_MinHeight || Specifies the minimum height of fonts to be listed |
||
− | |- |
||
− | | ASLFO_MaxHeight || Specifies the maximum height of fonts to be listed |
||
− | |- |
||
− | | ASLFO_DoFrontPen || Causes the requester to display the Front Color selection gadget (this replaces the FONF_FRONTCOLOR flag in ASL_FuncFlags used in V37). |
||
− | |- |
||
− | | ASLFO_DoBackPen || Causes the requester to display the Back Color selection gadget (this replaces the FONF_BACKCOLOR flag in ASL_FuncFlags used in V37). |
||
− | |- |
||
− | | ASLFO_DoStyle || Causes the requester to display Style checkbox gadgets (this replaces the FONF_STYLES flag in ASL_FuncFlags used in V37). |
||
− | |- |
||
− | | ASLFO_DoDrawMode || Causes the requester to display the Mode cycle gadget.(this replaces the FONF_DRAWMODE flag in ASL_FuncFlags used in V37). |
||
− | |- |
||
− | | ASLFO_FixedWidthOnly || Causes the requester to list only fixed-width fonts (this replaces the FONF_FIXEDWIDTH flag in ASL_FuncFlags used in V37). |
||
− | |- |
||
− | | ASLFO_InitialDrawMode || Initial setting of the font Mode gadget. |
||
− | |} |
||
− | |||
− | Note that the last two tags only limit the range of font sizes that the font requester displays, the user is free to type in any value. |
||
− | |||
− | Font requesters have additional special options that are controlled through the ASL_FuncFlags tag. This tag works the same way as it does with file requesters but with different options available. Recall that the data for this tag is divided into bit fields, each of which controls a requester option. The flags used with the ASL_FuncFlags tag in a font requester are defined in <libraries/asl.h>: |
||
− | |||
− | {| class="wikitable" |
||
− | ! Font Requester Flags |
||
− | ! Used For |
||
− | |- |
||
− | | FONF_FRONTCOLOR |
||
− | | Enables font color selection gadgets |
||
− | |- |
||
− | | FONF_BACKCOLOR |
||
− | | Enables font background color selection gadget |
||
− | |- |
||
− | | FONF_STYLES |
||
− | | Enables font style selection gadget |
||
− | |- |
||
− | | FONF_FIXEDWIDTH |
||
− | | Limits display to fixed width fonts only |
||
− | |- |
||
− | | FONF_DRAWMODE |
||
− | | Enables font draw mode gadget |
||
− | |} |
||
− | |||
− | A simple font requester (one without any of the above FONF_ flags set) only lets the user choose a font and a Y size. Setting the flags above adds options to the font requester. FONF_FRONTCOLOR and FONF_BACKCOLOR add color selection gadgets to the requester, one for choosing a font's foreground color (labeled "Text") and the other for choosing the background color (labeled "Field"). The font requester records the user's setting in the FontRequester's fo_FrontPen and fo_BackPen fields. |
||
− | |||
− | FONF_STYLES sets up several gadgets to choose the style of the font (bold, italics, underline). The font requester saves these settings in the fo_Attr.ta_Style bit field according to the style flags defined in <graphics/text.h>. FONF_FIXEDWIDTH limits the font name display to fixed width (non-proportional) fonts (note that this does not prevent the user from typing in a proportional font name). |
||
− | |||
− | FONF_DRAWMODE adds a cycle gadget to the font requester so the user can choose the draw mode. The draw mode is saved in the requester's fo_DrawMode field. The number stored there corresponds to the draw mode's position in the gadget's cycle. |
||
− | |||
− | The draw mode cycle gadget initially is labeled "Mode" and has three elements in its cycle: "JAM1", "JAM2", and "Complement". These yield a result of 0, 1, and 2, respectively. It is possible to change the names and number of draw modes with the ASL_ModeList tag. This tag accepts a pointer to an array of strings. The first string replaces "Mode" as the label for the draw mode cycle gadget. The strings that follow replace the elements of the cycle gadget. The last entry in the array has to be NULL to tell the requester where the list of entries ends. |
||
− | |||
− | === Example Font Requester === |
||
− | |||
− | The following example illustrates how to use a font requester. |
||
− | |||
− | <syntaxhighlight> |
||
− | /* |
||
− | ** fontreq.c |
||
− | */ |
||
− | |||
− | #include <exec/types.h> |
||
− | #include <libraries/asl.h> |
||
− | |||
− | #include <proto/asl.h> |
||
− | #include <proto/exec.h> |
||
− | #include <proto/dos.h> |
||
− | |||
− | struct AslIFace *IAsl = NULL; |
||
− | |||
− | /* Our replacement strings for the "mode" cycle gadget. The |
||
− | ** first string is the cycle gadget's label. The other strings |
||
− | ** are the actual strings that will appear on the cycle gadget. |
||
− | */ |
||
− | CONST_STRPTR modelist[] = |
||
− | { |
||
− | "Amiga Modes", |
||
− | "Mode 0", |
||
− | "Mode 1", |
||
− | "Mode 2", |
||
− | "Mode 3", |
||
− | "Mode 4", |
||
− | NULL |
||
− | }; |
||
− | |||
− | |||
− | int main(int argc, char **argv) |
||
− | { |
||
− | struct FontRequester *fr; |
||
− | |||
− | struct Library *AslBase = IExec->OpenLibrary("asl.library", 50); |
||
− | IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, NULL); |
||
− | |||
− | if (IAsl != NULL) |
||
− | { |
||
− | if (fr = (struct FontRequester *) |
||
− | IAsl->AllocAslRequestTags(ASL_FontRequest, |
||
− | /* tell the requester to use my custom mode names */ |
||
− | ASL_ModeList, modelist, |
||
− | |||
− | /* Supply initial values for requester */ |
||
− | ASL_FontName, "topaz.font", |
||
− | ASL_FontHeight, 11, |
||
− | ASL_FontStyles, FSF_BOLD | FSF_ITALIC, |
||
− | ASL_FrontPen, 0x00, |
||
− | ASL_BackPen, 0x01, |
||
− | |||
− | /* Only display font sizes between 8 and 14, inclusive. */ |
||
− | ASL_MinHeight, 8, |
||
− | ASL_MaxHeight, 14, |
||
− | |||
− | /* Give all the gadgetry, but only display fixed width fonts */ |
||
− | ASL_FuncFlags, FONF_FRONTCOLOR | FONF_BACKCOLOR | |
||
− | FONF_DRAWMODE | FONF_STYLES | FONF_FIXEDWIDTH, |
||
− | TAG_END)) |
||
− | { |
||
− | /* Pop up the requester */ |
||
− | if (IAsl->AslRequest(fr, NULL)) |
||
− | { |
||
− | /* The user selected something, report their choice */ |
||
− | IDOS->Printf("%s\n YSize = %ld Style = 0x%lx Flags = 0x%lx\n" |
||
− | " FPen = 0x%lx BPen = 0x%lx DrawMode = 0x%lx\n", |
||
− | fr->fo_Attr.ta_Name, |
||
− | fr->fo_Attr.ta_YSize, |
||
− | fr->fo_Attr.ta_Style, |
||
− | fr->fo_Attr.ta_Flags, |
||
− | fr->fo_FrontPen, |
||
− | fr->fo_BackPen, |
||
− | fr->fo_DrawMode); |
||
− | } |
||
− | else |
||
− | /* The user cancelled the requester, or some kind of error |
||
− | ** occurred preventing the requester from opening. */ |
||
− | IDOS->Printf("Request Cancelled\n"); |
||
− | |||
− | IAsl->FreeAslRequest(fr); |
||
− | } |
||
− | } |
||
− | |||
− | IExec->DropInterface((struct Interface*)IAsl); |
||
− | IExec->CloseLibrary(AslBase); |
||
− | |||
− | return 0; |
||
− | } |
||
− | </syntaxhighlight> |
||
== Creating a Screen Mode Requester == |
== Creating a Screen Mode Requester == |
Revision as of 15:35, 25 April 2014
This page is currently being updated to AmigaOS 4.x. Some of the information contained here may not yet be applicable in part or totally. |
Contents
ASL Library
This chapter describes the asl.library. The sole purpose of this library is to provide standard file and font requesters for application programs.
It is easier to understand the asl.library if you are familiar with some basic concepts of the Amiga operating system, especially TagItem arrays (described in Utility Library), Intuition screens and windows, graphics library font structures, and AmigaDOS pattern matching.
About Requesters
Requesters are temporary sub-windows used for confirming actions or selecting options. The most common type of requester is a file requester which is used to pick a file name for a load or save operation.
Under earlier versions of the Amiga operating system there was limited support for requesters. Intuition provides simple requesters which can be used to request responses such as OK or Cancel from the user. More elaborate Intuition requesters can be created by adding additional features such as string gadgets, however the result of this is that each application writer develops their own style of requester. With asl.library, requesters are much easier to create and take less memory.
Requesters are very flexible and can be used for many different purposes. The asl.library supports the three most common type of requesters:
- File requesters for choosing a file name in a load or save operation
- Font requesters for choosing a font in a text operation
- Screen Mode requesters for choosing a new screen with specific attributes
Common Tags Used by All Requester Types
These tags apply to all three types of ASL requesters: the file requester, the font requester and the screen mode requester. Each tag in the list below is prepended with ASLxx_. The actual tag names used by ASL will be prepended with ASLFR_, ASLFO_ or ASLSM_ depending on what type of requester is being used.
Tag Name | Used For |
---|---|
ASLxx_PubScreenName | Name of a public screen on which to open the requester. |
ASLxx_Screen | Pointer to a screen on which to open the requester. |
ASLxx_PrivateIDCMP | Specifies separate IDCMP for the requester window (this replaces the FILF_NEWIDCMP and FONF_NEWIDCMP flags in the ASL_FuncFlags tag used in V37). |
ASLxx_IntuiMsgFunc | Function to call when an unknown message arrives at a shared IDCMP used by the requester window (this replaces the ASL_HookFunc tag and the FILF_DOMSGFUNC and FONF_DOMSGFUNC flags in the ASL_FuncFlags used in V37). |
ASLxx_SleepWindow | Modal requester. Specifies that input should be blocked in the parent window. |
ASLxx_UserData | A 32-bit value copied into the user data field of the requester structure. |
ASLxx_TextAttr | Font to use for requester window gadgets and menus. |
ASLxx_Locale | Locale (and language) to use for the requester window. |
ASLxx_FilterFunc | Function to call for each item (file, font or mode) encountered. If the function returns TRUE, the item is displayed in the list view gadget, otherwise it is rejected and not displayed. (This replaces the ASL_HookFunc tag and the FILF_DOWILDFUNC and FONF_DOWILDFUNC flags in ASL_FuncFLags used in V37.) |
Creating a Screen Mode Requester
The Screeen Mode requester provides application writers with a convenient way to ask the user for their screen display preferences. You create an ASL screen mode requester the same way you create an ASL file requester or font requester; only the tags and structures used are different.
There are three main functions to call:
AllocAslRequest() | Sets up the ScreenModeRequester structure you need. |
AslRequest() | Displays the requester you have set up with AllocAslRequest(). |
FreeAslRequest() | Frees the ScreenModeRequester structure and other resources. |
The first step is to set up a ScreenModeRequester structure with the AllocAslRequest() function. The ScreenModeRequester structure is defined in <libraries/asl.h> as follows:
struct ScreenModeRequester { ULONG sm_DisplayID; /* Display mode ID */ ULONG sm_DisplayWidth; /* Width of display in pixels */ ULONG sm_DisplayHeight; /* Height of display in pixels */ UWORD sm_DisplayDepth; /* Number of bit-planes of display */ UWORD sm_OverscanType; /* Type of overscan of display */ BOOL sm_AutoScroll; /* Display should auto-scroll? */ ULONG sm_BitMapWidth; /* Used to create your own BitMap */ ULONG sm_BitMapHeight; WORD sm_LeftEdge; /* Coordinates of requester on exit */ WORD sm_TopEdge; WORD sm_Width; WORD sm_Height; BOOL sm_InfoOpened; /* Info window opened on exit? */ WORD sm_InfoLeftEdge; /* Last coordinates of Info window */ WORD sm_InfoTopEdge; WORD sm_InfoWidth; WORD sm_InfoHeight; APTR sm_UserData; /* You can store your own data here */ };
The fields in this structure will be filled in with information obtained from the user. This information can then be used in your application to create the type of screen that the user prefers.
Note that for most programs, the user's preferred screen mode can be determined from the Amiga's Preferences subsystem. You do not have to use a screen mode requester. Consider carefully whether it is more appropriate to use an ASL requester or to obtain the information directly from the settings in Overscan and ScreenMode Preferences.
Listed below is a simple program that displays the new ASL screen mode requester including depth, width and height gadgets.
/* ** aslsm.c */ #include <exec/types.h> #include <libraries/asl.h> #include <utility/tagitem.h> #define SMRTITLE "Simplest ScreenMode Requester" struct AslIFace *IAsl; int main(int argc, char **argv) { struct ScreenModeRequester *smr; struct TagItem smrtags[5]; struct Library *AslBase = IExec->OpenLIbrary("asl.library", 50); IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, NULL); if( IAsl != NULL) { smrtags[0].ti_Tag=ASLSM_TitleText; smrtags[0].ti_Data=(ULONG)SMRTITLE; smrtags[1].ti_Tag=ASLSM_DoWidth; smrtags[1].ti_Data=TRUE; smrtags[2].ti_Tag=ASLSM_DoHeight; smrtags[2].ti_Data=TRUE; smrtags[3].ti_Tag=ASLSM_DoDepth; smrtags[3].ti_Data=TRUE; smrtags[4].ti_Tag=TAG_END; if( smr = (struct ScreenModeRequester *) IAsl->AllocAslRequest(ASL_ScreenModeRequest, smrtags) ) { if( IAsl->AslRequest(smr, 0L) ) { IDOS->Printf("Display type: $%lx (see graphics/displayinfo.h)\n", smr->sm_DisplayID); IDOS->Printf("Display width: %ld, height: %ld, depth: %ld\n", smr->sm_DisplayWidth, smr->sm_DisplayHeight, smr->sm_DisplayDepth); } else IDOS->Printf("User cancelled or error...\n"); IAsl->FreeAslRequest(smr); } } IExec->DropInterface((struct Interface*)IAsl); IExec->CloseLibrary(AslBase); return 0; }
As with other ASL requesters, the attributes of the screen mode requester are established using tag items when AllocAslRequest() is called. These attributes can later be changed by using different tag items in the AslRequest() call.
For instance, in the example above, tag items are used to specify that the screen mode requester should include gadgets for setting the display height (ASLSM_DoHeight), width (ASLSM_DoWidth) and depth (ASLSM_DoDepth).
Screen Mode Requester Tags
Here's a brief summary of the tag items that apply only to the ASL screen mode requester. For a complete listing of all ASL tag items, refer to the ASL include files and Autodocs.
Screen Mode Tag Name | Used For |
---|---|
ASLSM_Window | Parent window |
ASLSM_Screen | Screen to open on if no window |
ASLSM_PubScreenName | Name of public screen |
ASLSM_PrivateIDCMP | Allocate private IDCMP? |
ASLSM_IntuiMsgFunc | Function to handle IntuiMessages |
ASLSM_SleepWindow | Block input in ASLSM_Window? |
ASLSM_UserData | What to put in sm_UserData |
ASLSM_TextAttr | Text font to use for gadget text |
ASLSM_Locale | Locale ASL should use for text |
ASLSM_TitleText | Title of requester |
ASLSM_PositiveText | Positive gadget text |
ASLSM_NegativeText | Negative gadget text |
ASLSM_InitialLeftEdge | Initial requester left coordinate |
ASLSM_InitialTopEdge | Initial requester top coordinate |
ASLSM_InitialWidth | Initial requester width |
ASLSM_InitialHeight | Initial requester height |
ASLSM_InitialDisplayID | Initial display mode id |
ASLSM_InitialDisplayWidth | Initial display width |
ASLSM_InitialDisplayHeight | Initial display height |
ASLSM_InitialDisplayDepth | Initial display depth |
ASLSM_InitialOverscanType | Initial type of overscan |
ASLSM_InitialAutoScroll | Initial autoscroll setting |
ASLSM_InitialInfoOpened | Info window initially opened? |
ASLSM_InitialInfoLeftEdge | Initial Info window left coordinate |
ASLSM_InitialInfoTopEdge | Initial Info window top coordinate |
ASLSM_DoWidth | Display Width gadget? |
ASLSM_DoHeight | Display Height gadget? |
ASLSM_DoDepth | Display Depth gadget? |
ASLSM_DoOverscanType | Display Overscan Type gadget? |
ASLSM_DoAutoScroll | Display AutoScroll gadget? |
ASLSM_PropertyFlags | Must have these Property flags |
ASLSM_PropertyMask | Only these should be looked at |
ASLSM_MinWidth | Minimum display width to allow |
ASLSM_MaxWidth | Maximum display width to allow |
ASLSM_MinHeight | Minimum display height to allow |
ASLSM_MaxHeight | Maximum display height to allow |
ASLSM_MinDepth | Minimum display depth |
ASLSM_MaxDepth | Maximum display depth |
ASLSM_FilterFunc | Function to filter mode id's |
ASLSM_CustomSMList | Exec list of struct DisplayMode |
Calling Custom Functions from a Requester
The ASL_HookFunc tag passes an ASL requester a pointer to a custom function. The requester can use this function for two purposes. The first is to determine if the requester should display a particular file or font name. The other purpose is to process messages that the requester receives at its IDCMP port that are not meant for the requester. Hook functions are set up through flag values used with the ASL_FuncFlags tag:
Hook Function Flag | Used For |
---|---|
FILF_DOWILDFUNC | Call user hook function on each name in a file requester |
FONF_DOWILDFUNC | Call user hook function on each name in a font requester |
FILF_DOMSGFUNC | Call user hook function for IDCMP messages not used by a file requester |
FONF_DOMSGFUNC | Call user hook function for IDCMP messages not used by a font requester |
The FILF_DOWILDFUNC and FONF_DOWILDFUNC flags cause a requester to call the function you specify with the ASL_HookFunc tag for every file or font entry. The requester displays the file or font name only if your hook function tells it to. For a file requester, if your hook function returns a zero, the file requester will display the file name. For a font requester, if your hook function returns anything but zero, the font requester will display the font name and size.
The FILF_DOMSGFUNC and FONF_DOMSGFUNC flags cause a requester to call your hook function whenever it receives an IntuiMessage that it cannot use at the IDCMP port that it shares with your window. (See the section on "ASL Requesters and Custom Screens" earlier in this chapter for more information about sharing IDCMP ports.) If the requester receives any messages that are not meant for the requester it will call your hook function (specified with the ASL_HookFunc tag). Your hook function is responsible for returning a pointer to the IntuiMessage. The requester will take care of replying to the message.
Parameters Passed to Custom Hook Functions
A requester always passes three parameters to your custom hook function:
ULONG MyHookFunc(ULONG type, CPTR object, CPTR AslRequester)
If MyHookFunc() is called from a file requester doing _DOWILDFUNC, the three parameters are:
- type
- FILF_DOWILDFUNC
- object
- pointer to an AnchorPath structure (from <dos/dosasl.h>)
- AslRequester
- pointer to the FileRequester that called the hook function
The hook custom function should return a zero to display this file.
The AnchorPath structure is a dos.library structure used in pattern matching. Refer to the AmigaDOS Manual, 3rd Edition for more information.
If MyHookFunc() is called from a font requester doing _DOWILDFUNC, the three parameters are:
- type
- FONF_DOWILDFUNC
- object
- pointer to a TextAttr structure (from <graphics/text.h>)
- AslRequester
- pointer to the FontRequester that called the hook function
The hook custom function should return non-zero to display this particular font size.
If MyHookFunc() is called from a file or font requester doing _DOMSGFUNC, the three parameters are:
- type
- FILF_DOMSGFUNC (file requester) or FONF_DOMSGFUNC (font requester)
- object
- pointer to the IntuiMessage for the function to process
- AslRequester
- pointer to the FileRequester or FontRequester that called the hook function
The hook custom function should return a pointer to the IntuiMessage.
Notice that it is possible for a requester to use both _DOWILDFUNC and _DOMSGFUNC at the same time. Your hook function has to differentiate between the two cases by testing the type passed to it. It is not possible for a font and file requester to share a hook function for a _DOWILDFUNC, because FILF_DOWILDFUNC is defined to be the same value as FONF_DOWILDFUNC, so the hook function cannot tell if the object (from the prototype above) is a pointer to an AnchorPath structure or a pointer to a TextAttr structure. It is possible for font and file requesters to share one hook function for _DOMSGFUNC (even though FILF_DOMSGFUNC and FONF_DOMSGFUNC are equal) because, in this case, font and file requesters both call your hook function in the same manner.
Example ASL Requester With Custom Hook Function
The following example illustrates the use of a hook function for both _DOWILDFUNC and _DOMSGFUNC.
/* ** filehook.c */ #include <exec/types.h> #include <intuition/intuition.h> #include <dos/dosasl.h> #include <libraries/asl.h> #include <proto/exec.h> #include <proto/dos.h> #include <proto/asl.h> #include <proto/intuition.h> #define DESTPATLENGTH 20 struct AslIFace *IAsl = NULL; struct IntuitionIFace *IIntuition = NULL; struct Window *window = NULL; /* this is the pattern matching string that the hook function uses */ CONST_STRPTR sourcepattern = "(#?.info)"; TEXT pat[DESTPATLENGTH]; uint32 HookFunc(int32 type, APTR obj, struct FileRequester *fr); int main(int argc, char **argv) { struct FileRequester *fr; struct Library *AslBase = IExec->OpenLibrary("asl.library", 50); IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, NULL); struct Library *IntuitionBase = IExec->OpenLibrary("intuition.library", 50); IIntuition = (struct IntuitionIFace*)IExec->GetInterface(IntuitionBase, "main", 1, NULL); if (IAsl != NULL && IIntuition != NULL) { IDOS->ParsePattern(sourcepattern, pat, DESTPATLENGTH); /* open a window that gets ACTIVEWINDOW events */ if (window = IIntuition->OpenWindowTags(NULL, WA_Title, "ASL Hook Function Example", WA_IDCMP, IDCMP_ACTIVEWINDOW, WA_Flags, WFLG_DEPTHGADGET, TAG_END)) { if (fr = IAsl->AllocFileRequest()) { if (IAsl->AslRequestTags(fr, ASL_Dir, "SYS:Utilities", ASL_Window, window, ASL_TopEdge, 0, ASL_Height, 200, ASL_Hail, "Pick an icon, select save", ASL_HookFunc, HookFunc, ASL_FuncFlags, FILF_DOWILDFUNC | FILF_DOMSGFUNC | FILF_SAVE, ASL_OKText, "Save", TAG_END)) { IDOS_>Printf("PATH=%s FILE=%s\n", fr->rf_Dir, fr->rf_File); IDOS->Printf("To combine the path and filename, copy the path\n"); IDOS->Printf("to a buffer, add the filename with Dos AddPart().\n"); } IAsl->FreeFileRequest(fr); } IIntuition->CloseWindow(window); } } } IExec->DropInterface((struct Interface*)IIntuition); IExec->CloseLibrary(IntuitionBase); IExec->DropInterface((struct Interface*)IAsl); IExec->CloseLibrary(AslBase); return 0; } uint32 HookFunc(int32 type, APTR obj, struct FileRequester *fr) { static BOOL returnvalue; switch(type) { case FILF_DOMSGFUNC: /* We got a message meant for the window */ IDOS->Printf("You activated the window\n"); return(obj); break; case FILF_DOWILDFUNC: /* We got an AnchorPath structure, should ** the requester display this file? */ /* MatchPattern() is a dos.library function that ** compares a matching pattern (parsed by the ** ParsePattern() DOS function) to a string and ** returns true if they match. */ returnvalue = IDOS->MatchPattern(pat, ((struct AnchorPath *)obj)->ap_Info.fib_FileName); /* we have to negate MatchPattern()'s return value ** because the file requester expects a zero for ** a match not a TRUE value */ return( ! returnvalue ); break; } }
Function Reference
The following are brief descriptions of the ASL library functions. See the SDK for details on each function call.
Function | Description |
---|---|
AllocAslRequest() | Allocates an ASL font or file requester from a TagItem array |
AllocAslRequestTags() | Same as AllocAslRequest() but accepts tags directly |
AslRequest() | Displays an ASL requester with options set up in a TagItem array |
AslRequestTags() | Same as AslRequest() but accepts tags directly |
FreeAslRequest() | Deallocates an ASL requester created with AllocAslRequest() |