The asl.library

What is the asl.library

The asl.library provides requesters for various purposes. Since it is a part of the Workbench, everybody with a OS higher 2.0 is able to use it without extra installation. On the other hand it is style-conform, so it is the best to support it within your programs. There also are other libraries providing similar functions (arp.library or reqtools.library), but you should always use asl. At least, there are patches to replace a asl-requester with another one, so it really does not matter.

How to use it within Blitz

The first step is to allocate a Requester structure. We use the system call AllocAslRequest_(type,taglist) (the underscore indicates a system function within blitz) to receive a structure for our requester. This structure is a kind of a plot which is needed to open up our requester. The type argument is used to set the requester type, we want to get a structure for. Valid values are :
     #ASL_FileRequest          a file requester (load/save/directory)
     #ASL_FontRequest          a font requester
     #ASL_ScreenModeRequest    a screenmode requester

The Function returns a Pointer to the mentioned structure if everything was fine. If not so (not enough memory etc.) it will return a 0. It is important to check it to avoid a guru.

File Requester

Now we have the structure and so are able to open up our file requester. The system call we need for this job is AslRequest_ (structure,tags). Its arguments are: the structured we received with AllocAslRequest_() and a taglist to specify some attributes. A tag is always a definition and with its value. There are lot of attribute tags, please check the example code below ...

AslRequest_ () will pop up a requester if everything went fine. If it returns FALSE, something went wrong. You should always check it.
You remember the structure we allocated in the beginning ? Well, it now contains all changes/selections done by the user. The most important is : which file was chosen ? The answer is quite simple

  FileName$     =   Peek$(*AslFile\fr_File)
  DrawerName$   =   Peek$(*AslFile\fr_Drawer)

But this is not the end. As we allocated a sctructure from the system, we also have to give it free with :
  FreeAslRequest_(*AslFile)

That's it !

Font Requester

ScreenMode Requester


DEFTYPE.FileRequester *AslFile
*AslFile =  AllocAslRequest_(#ASL_FileRequest,0)
If *AslFile  <>  0
  DTAslTags(0)\ti_Tag   = #ASLFR_InitialHeight   :  DTAslTags(0)\ti_Data  =  DTAslSetup\height
  DTAslTags(1)\ti_Tag   = #ASLFR_InitialWidth    :  DTAslTags(1)\ti_Data  =  DTAslSetup\width
  DTAslTags(2)\ti_Tag   = #ASLFR_InitialLeftEdge :  DTAslTags(2)\ti_Data  =  DTAslSetup\left
  DTAslTags(3)\ti_Tag   = #ASLFR_InitialTopEdge  :  DTAslTags(3)\ti_Data  =  DTAslSetup\top
  DTAslTags(4)\ti_Tag   = #ASLFR_SleepWindow     :  DTAslTags(4)\ti_Data  = (DTAslSetup\flags AND $8)
  DTAslTags(5)\ti_Tag   = #ASLFR_Window          :  DTAslTags(5)\ti_Data  = *win
  DTAslTags(6)\ti_Tag   = #TAG_MORE
  DTAslTags(6)\ti_Data  = tagsadr
   If AslRequest_(*DTAslFile,&DTAslTags(0))
    succ=True
    If (DTAslSetup\flags AND $1)=False  ; NOPOSREMEMBER
      DTAslSetup\left   = *DTAslFile\fr_LeftEdge
      DTAslSetup\top    = *DTAslFile\fr_TopEdge
      DTAslSetup\width  = *DTAslFile\fr_Width
      DTAslSetup\height = *DTAslFile\fr_Height
    EndIf
   EndIf
 FreeAslRequest_(*DTAslFile)
EndIf
Function Return succ
End Function



;==================================================================
;
; DTAslLib
;
; $VER  = 1.0 (05.02.1996 21:50)
;
; by Peter 'dreamy' Traskalik
;    dream technologies inc.
;
;
; commands
;
; DTAslWindow{x,y,w,h,flags}        global definition asl-winsize
; DTAslFileRequest{&moretags(0)}    open a filerequest
; DTAslFontRequest{&moretags(0)}    open a fontrequest
; DTAslScreenRequest{&moretags(0)}  open a screenmoderequest
;
; requires amigalibs.res to be resident
;
;==================================================================
DEFTYPE.FileRequester *DTAslFile
DEFTYPE.FontRequester *DTAslFont
DEFTYPE.ScreenModeRequester *DTAslScreen
NEWTYPE.DTAslSetup
     left.w
      top.w
    width.w
   height.w
    title.s
    flags.l
End NEWTYPE
DEFTYPE.DTAslSetup DTAslSetup
Dim DTAslTags.TagItem(6)
;------------------------------------------------------------------
Statement DTAslWindow{x.w,y.w,w.w,h.w,fl.l}
 SHARED DTAslSetup
  DTAslSetup\left   = x
  DTAslSetup\top    = y
  DTAslSetup\width  = w
  DTAslSetup\height = h
  DTAslSetup\flags  = f
End Statement
;------------------------------------------------------------------
Function.b DTAslFileRequest{tagsadr.l}
SHARED *DTAslFile,DTAslTags(),DTAslSetup
win=Used Window
  *win.Window=Peek.l(Addr Window(win))
succ=False
*DTAslFile=AllocAslRequest_(#ASL_FileRequest,0)
If *DTAslFile  <>  0
  DTAslTags(0)\ti_Tag   = #ASLFR_InitialHeight   :  DTAslTags(0)\ti_Data  =  DTAslSetup\height
  DTAslTags(1)\ti_Tag   = #ASLFR_InitialWidth    :  DTAslTags(1)\ti_Data  =  DTAslSetup\width
  DTAslTags(2)\ti_Tag   = #ASLFR_InitialLeftEdge :  DTAslTags(2)\ti_Data  =  DTAslSetup\left
  DTAslTags(3)\ti_Tag   = #ASLFR_InitialTopEdge  :  DTAslTags(3)\ti_Data  =  DTAslSetup\top
  DTAslTags(4)\ti_Tag   = #ASLFR_SleepWindow     :  DTAslTags(4)\ti_Data  = (DTAslSetup\flags AND $8)
  DTAslTags(5)\ti_Tag   = #ASLFR_Window          :  DTAslTags(5)\ti_Data  = *win
  DTAslTags(6)\ti_Tag   = #TAG_MORE
  DTAslTags(6)\ti_Data  = tagsadr
   If AslRequest_(*DTAslFile,&DTAslTags(0))
    succ=True
    If (DTAslSetup\flags AND $1)=False  ; NOPOSREMEMBER
      DTAslSetup\left   = *DTAslFile\fr_LeftEdge
      DTAslSetup\top    = *DTAslFile\fr_TopEdge
      DTAslSetup\width  = *DTAslFile\fr_Width
      DTAslSetup\height = *DTAslFile\fr_Height
    EndIf
   EndIf
 FreeAslRequest_(*DTAslFile)
EndIf
Function Return succ
End Function
;------------------------------------------------------------------
Function.b DTAslFontRequest{tagsadr.l}
SHARED *DTAslFont,DTAslTags(),DTAslSetup
win=Used Window
  *win.Window=Peek.l(Addr Window(win))
succ=False
*DTAslFont=AllocAslRequest_(#ASL_FontRequest,0)
If *DTAslFont  <>  0
  DTAslTags(0)\ti_Tag   = #ASLFO_InitialHeight   :  DTAslTags(0)\ti_Data  =  DTAslSetup\height
  DTAslTags(1)\ti_Tag   = #ASLFO_InitialWidth    :  DTAslTags(1)\ti_Data  =  DTAslSetup\width
  DTAslTags(2)\ti_Tag   = #ASLFO_InitialLeftEdge :  DTAslTags(2)\ti_Data  =  DTAslSetup\left
  DTAslTags(3)\ti_Tag   = #ASLFO_InitialTopEdge  :  DTAslTags(3)\ti_Data  =  DTAslSetup\top
  DTAslTags(4)\ti_Tag   = #ASLFO_SleepWindow     :  DTAslTags(4)\ti_Data  = (DTAslSetup\flags AND $8)
  DTAslTags(5)\ti_Tag   = #ASLFO_Window          :  DTAslTags(5)\ti_Data  = *win
  DTAslTags(6)\ti_Tag   = #TAG_MORE
  DTAslTags(6)\ti_Data  = tagsadr
   If AslRequest_(*DTAslFont,&DTAslTags(0))
    succ=True
    If (DTAslSetup\flags AND $1)=False  ; NOPOSREMEMBER
      DTAslSetup\left   = *DTAslFont\fo_LeftEdge
      DTAslSetup\top    = *DTAslFont\fo_TopEdge
      DTAslSetup\width  = *DTAslFont\fo_Width
      DTAslSetup\height = *DTAslFont\fo_Height
    EndIf
   EndIf
 FreeAslRequest_(*DTAslFont)
EndIf
Function Return succ
End Function
;------------------------------------------------------------------
Function.b DTAslScreenRequest{tagsadr.l}
SHARED *DTAslScreen,DTAslTags(),DTAslSetup
win=Used Window
  *win.Window=Peek.l(Addr Window(win))
succ=False
*DTAslScreen=AllocAslRequest_(#ASL_ScreenModeRequest,0)
If *DTAslScreen  <>  0
  DTAslTags(0)\ti_Tag   = #ASLSM_InitialHeight   :  DTAslTags(0)\ti_Data  =  DTAslSetup\height
  DTAslTags(1)\ti_Tag   = #ASLSM_InitialWidth    :  DTAslTags(1)\ti_Data  =  DTAslSetup\width
  DTAslTags(2)\ti_Tag   = #ASLSM_InitialLeftEdge :  DTAslTags(2)\ti_Data  =  DTAslSetup\left
  DTAslTags(3)\ti_Tag   = #ASLSM_InitialTopEdge  :  DTAslTags(3)\ti_Data  =  DTAslSetup\top
  DTAslTags(4)\ti_Tag   = #ASLSM_SleepWindow     :  DTAslTags(4)\ti_Data  = (DTAslSetup\flags AND $8)
  DTAslTags(5)\ti_Tag   = #ASLSM_Window          :  DTAslTags(5)\ti_Data  = *win
  DTAslTags(6)\ti_Tag   = #TAG_MORE
  DTAslTags(6)\ti_Data  = tagsadr
   If AslRequest_(*DTAslScreen,&DTAslTags(0))
    succ=True
    If (DTAslSetup\flags AND $1)=False  ; NOPOSREMEMBER
      DTAslSetup\left   = *DTAslScreen\sm_LeftEdge
      DTAslSetup\top    = *DTAslScreen\sm_TopEdge
      DTAslSetup\width  = *DTAslScreen\sm_Width
      DTAslSetup\height = *DTAslScreen\sm_Height
    EndIf
   EndIf
 FreeAslRequest_(*DTAslScreen)
EndIf
Function Return succ
End Function
;==================================================================




;
; Example
;

;
; open a screen and window
;

FindScreen   0
Window 0,10,10,500,230,$10000+$400+14,"DTLocaleLib test",0,0

  ;
  ; Set the global size etc. of the asl windows
  ;

  ; leftedge  10
  ; topedge   20
  ; width     200
  ; height    250
  ; flags     0    (remember new position)

  DTAslWindow{10,20,800,250,$0}

Goto hihiman

  ;
  ; simple FileRequest
  ;

  If DTAslFileRequest{0}    ; no additional tags

    FileName$     =   Peek$(*DTAslFile\fr_File)
    DrawerName$   =   Peek$(*DTAslFile\fr_Drawer)

    NPrint  "File   : "+FileName$
    NPrint  "Drawer : "+DrawerName$

  Else

    NPrint "asl failed / nothing selected / cancelled"

    ;
    ; you can use afterwards IoErr_ to recognize why...
    ;

    NPrint "dos Error : "+Str$(IoErr_)

  EndIf

  ;
  ; FileRequest with add tags
  ;

  ;
  ; define a taglist
  ;

  Dim Tags.TagItem(3)

    ; creates a savemode-requester with black background
    ; a double click is not allowed

    Tags(0)\ti_Tag = #ASLFR_DoSaveMode      : Tags(0)\ti_Data  =  True

    ; begin in the drawer "Work:Test/"

    drawer.s="Work:Test/"
    Tags(1)\ti_Tag = #ASLFR_InitialDrawer   : Tags(1)\ti_Data  =  &drawer

    ; ban the icons !

    Tags(2)\ti_Tag = #ASLFR_RejectIcons     : Tags(2)\ti_Data =  True

    ; tags done

    Tags(3)\ti_Tag = #TAG_DONE : Tags(3)\ti_Data  = 0

  If DTAslFileRequest{&Tags(0)}

    FileName$     =   Peek$(*DTAslFile\fr_File)
    DrawerName$   =   Peek$(*DTAslFile\fr_Drawer)
    NPrint  "File   : "+FileName$
    NPrint  "Drawer : "+DrawerName$

  Else

    NPrint "asl failed / nothing selected / cancelled"
    NPrint "dos Error : "+Str$(IoErr_)

  EndIf


  ;-------------------------------------------------

  ;
  ; simple FontRequest
  ;

  If DTAslFontRequest{0}

    FontName$     =   Peek$(*DTAslFont\fo_Attr\ta_Name)
    FontYSize     =   *DTAslFont\fo_Attr\ta_YSize
    NPrint  "FontName : "+FontName$
    NPrint  "FontSize : "+Str$(FontYSize)

  Else

    NPrint "asl failed / nothing selected / cancelled"
    NPrint "dos Error : "+Str$(IoErr_)

  EndIf


  ;-------------------------------------------------

hihiman:

  ;
  ; simple ScreenModeRequest
  ;

  If DTAslScreenRequest{0}

    DisplayID.l=*DTAslScreen\sm_DisplayID

    NPrint "DisplayID : "+Hex$(DisplayID)
    NPrint "Width     : ",*DTAslScreen\sm_DisplayWidth
    NPrint "Height    : ",*DTAslScreen\sm_DisplayHeight

    DEFTYPE.NameInfo NameInfo
    dummy=GetDisplayInfoData_(0,&NameInfo,SizeOf.NameInfo,#DTAG_NAME,DisplayID)
    DisplayName.s=Peek$(&NameInfo\Name[0])

    NPrint "Name      : "+DisplayName

  Else

    NPrint "asl failed / nothing selected / cancelled"
    NPrint "dos Error : "+Str$(IoErr_)

  EndIf



Repeat
  ev.l=WaitEvent    ; Wait for IDCMP_CLOSEWINDOW
Until ev=$200


CloseWindow 0
End