home *** CD-ROM | disk | FTP | other *** search
- @(#)BasLib 1.1 1993
- (c) Copyright 1992,1993 Chris Corbett
- All sources acknowledged.
-
- This software is distributed free of charge and may be used without
- restriction as long as the following conditions are adhered to:
-
- i) No charge must be made for re-distribution
- ii) All files must be included, especially this !Help file
- with the copyright notice.
-
- All helpful suggestions for changes, improvements, bug fixes etc.
- gratefully received. Additions to the library is encouraged, especially
- if I get a copy too!
-
- ##############################################################################
-
-
- Introduction to Basic Library
- =============================
-
- This directory contains a set of BASIC procedure libraries which implement
- some common tasks in programs designed for the WIMP.
- Most routines have been collected from PD and magazine sources and modified,
- added to, improved etc. to produce this library. The files in this directory
- and their contents are:
-
- Debug: Procedures to support the !Debug application (from RISC
- user?)
- Error: Error handling procedures (not finished!)
- Malloc: Memory allocation modelled after UNIX
- Menus: Support procedures for WIMP menus, modification of original
- described in BAU 1990.
- Text: Procedures to support text windows.
- Win: Procedures for window creation support.
-
- The procedures contained in each library are described in more detail in the
- following sections. To use any library in a BASIC program, use a LIBRARY
- statement as illustrated below:
- LIBRARY "<Basic$Lib>.Malloc"
- LIBRARY "<Basic$Lib>.Menus"
- LIBRARY "<Basic$Lib>.Debug"
- LIBRARY "<Basic$Lib>.Win"
- - where <Basic$Lib> is a system variable which defines the location of the
- libraries.
-
- +-----------+
- | Malloc |
- +-----------+
-
- Procedure: FNmalloc(size%)
-
- Description: Allocate a block of memory of size% bytes, starting on a
- word boundary. A pointer to the allocated memory is returned
- as an integer value. If the memory could not be allocated
- then a value of -1 is returned.
-
-
- Procedure: FNcalloc(size%)
-
- Description: Same as above, except that the allocated memory block is
- cleared to zero before returning to the calling program.
-
-
- Procedure: FNfree(ptr%)
-
- Description: Frees the memory previously allocated by Fnmalloc or
- FNcalloc above. The argument must be a valid pointer
- returned from a previous call to either of these functions.
-
-
- +-----------+
- | Menus |
- +-----------+
-
- Procedure: FNMenus_Load(menufile$)
-
- Description: Load a textual description of a menu structure into memory
- from the file menufile$. The structure of the menu data file
- and the code that handles it is derived from an article in
- BAU magazine, March 1990 issue. A syntactic definition of
- the file structure is:
- <menu file> ::= <menu> | <menu file>
- <menu> ::= <Menu title><item list><CR>
- <menu title>::= [ASCII 32 .. ASCII 127]
- <item list> ::= <menu item><CR> | <item list>
- <menu item> ::= <*>|< >|<-> <itemname> <action>
- <itemname> ::= [ASCII 32 .. ASCII 127]
- <action> ::= <!><windowname> |
- <@><submenu> |
- <*><writeable> |
- <{><wimpflags> |
- <\><function> (address of menu item passed)
- <windowname>::= [Basic integer variable]
- <submenu> ::= <menu>
- <writeable> ::= <function><,><fieldlen><,><validation>
- <wimpflags> ::= [0..2^32-1]
- <function> ::= [Basic function name - 'FN']<funcargs>
- <funcargs> ::= [(][&]|[&,..] (Use & to pass address of menu icon)
- <fieldlen> ::= [0..80]|[(0..80)"_"]
- <validation>::= [As PRM pp 1184-1186]
- It is recommended that all menu definition files are given the
- name "menus". Please refer to the example program !Compare
- which uses an example of menus. A much more detailed example
- may be found in the !Yadfs application.
- FNMenus_Load will return 1 if the menus file was loaded
- successfully. Loading the file prepares it for use by the
- remaining procedures described below. If the file does not
- exist than error number &101 will be raised.
-
-
-
- Procedure: FNMenus_Build(title$, height%)
-
- Description: Build a WIMP menu structure for the menu whose title is title$.
- The menu of that name must exist in the file previously loaded
- by the FNMenus_load function. If the menu does not exist than
- an error is raised, via the basic ERROR statement. If the menu
- is found it is formatted into the structure required by the WIMP
- ready for display to the user. A pointer to the constructed
- menu block is returned as an integer. In addition, the second
- argument to the function, height%, is declared as a RETURN value,
- and it is set to the full height of the constructed menu in pixels.
-
- Procedure: PROCMenus_Select(block%, menu$)
-
- Description: Call this procedure from within the WIMP Poll loop to decode
- the menu item selected and perform the action defined. The
- first parameter is a pointer to the WIMP control block
- filled in by the Wimp_Poll call. The second parameter is the
- name of the menu currently being displayed - this must be
- remembered in the calling program and passed to this
- routine. Typically, each time a user opens a menu by
- clicking "menu" over an application window, the program
- should open the menu and save the menu name in a variable
- ready to pass on to this procedure. An example can be found
- in the !Compare application.
-
-
-
- +-----------+
- | Win |
- +-----------+
-
- Procedure: FNWin_Create(template$, window$, RETURN winaddr%)
-
- Description: Create a window structure in memory given the window name
- and the name of the template file. The structure created is
- as required by a Wimp_Openwindow call. Thus function
- automatically calculates the memory requirements to store
- the window data and all its indirected strings. I assumes,
- of course, that you have constructed your window template
- file using the !FormEd application.
- The function returns the window handle of the created window
- ready for use in subsequent open and close window
- operations. The RETURN parameter, "winaddr%", is used to
- return the address in memory of the start of the window
- block. This can be used in a program to modify window
- attributes or icon attributes which are part of the window
- definition.
-
-
- Procedure: FNisind(flag%)
-
- Description: This function checks the indirected bits in the icon flag
- word passed as the parameter. It returns TRUE if the flag%
- value indicates that the icon contains indirected data,
- otherwise it returns false.
-
-
- Procedure: PROCPollAssign
-
- Description: This procedure sets a group of variable names to the values
- returned in a Wimp_Poll loop. This is a convenience call
- that allows readable names to be used inside the CASE
- statement of the Wimp_poll procedure when decoding the
- return value. The values assigned are listed below:
- Poll_Null_Reason_Code = 0
- Poll_Redraw_Window_Request = 1
- Poll_Open_Window_Request = 2
- Poll_Close_Window_Request = 3
- Poll_Pointer_Leaving_Window = 4
- Poll_Pointer_Entering_Window = 5
- Poll_Mouse_Click = 6
- Poll_User_Drag_Box = 7
- Poll_Key_Pressed = 8
- Poll_Menu_Selection = 9
- Poll_Scroll_Request = 10
- Poll_Lose_Caret = 11
- Poll_Gain_Caret = 12
- Poll_User_Message = 17
- Poll_User_Message_Recorded = 18
- Poll_User_Message_Acknowledged = 19
-
-
- Procedure: PROCMessageAssign
-
- Description: Like the previous procedure, this one sets up a set of
- variables whose values take on the various message types
- which may be passed to the program via the WIMP. The list
- of assigned values is given below:
- Message_Quit = 0
- Message_DataSave = 1
- Message_DataSaveAck = 2
- Message_DataLoad = 3
- Message_DataLoadAck = 4
- Message_DataOpen = 5
- Message_RAMFetch = 6
- Message_RAMTransmit = 7
- Message_PreQuit = 8
- Message_PaletteChange = 9
- Message_FilerOpenDir = &400
- Message_FilerCloseDir = &401
- Message_RequestHelp = &502
- Message_Notify = &40040
- Message_MenuWarning = &400C0
- Message_ModeChange = &400C1
- Message_TaskInitialise = &400C2
- Message_TaskCloseDown = &400C3
- Message_SlotSize = &400C4
- Message_SetSlot = &400C5
- Message_TaskNameRq = &400C6
- Message_TaskNameIs = &400C7
-
-
- Procedure: PROCWin_Open(win%, topleftx%, toplefty%, width%, height%)
-
- Description: This procedure acts as an interface to the "Wimp_OpenWindow"
- call. The first argument "win%" is the window handle, the
- next two define the screen coordinate of the top left corner
- of the window, and the last two define the initial width and
- height of the window as displayed.
-
-
- Procedure: PROCIcon_SetText(win%,icon%,text$)
-
- Description: Use this procedure to change the text stored in an icon. The
- first two parameters define the window handle and icon handle
- respectively. The third argument is the text string to insert
- into the icon's buffer. The procedure checks whether the icon
- contains an indirected text string or not, and stores the string
- appropriately. For non-indirected text, the string in text$ will
- be truncated to its first 12 characters, while for indirected
- text icons the string will be truncated to the length of the
- icon's buffer.
-
-
- Procedure: FNIcon_ReadText(win%, icon%)
-
- Description: This function will return the as a text string the text stored
- in the icon identified by the window handle win% and the icon
- handle icon%.
-
-
- Procedure: FNIcon_Select(icon%, win%)
-
- Description: Set an icon's selected bit in its flags word, and return the old
- value of the selected bit.
-
-
- Procedure: FNIcon_Deselect(icon%, win%)
-
- Description: Deselect an icon and return the old value of the icon's selected
- bit.
-
-
- +--------------+
- | Text Windows |
- +--------------+
-
- This procedure library is the most complex in the set. It consists of
- procedures in two main classes; those designed to be called as Wimp_Poll
- event handlers, and those designed to create and manipulate text windows.
- The procedures require a window template to be created separately, using
- !FormEd for example, and the window must have the title "Textdisplay".
-
- Procedure: FNText_CreateTextObject(title$)
-
- Description: Initialise a window, from the template called "Textdisplay"
- in the applications Templates file, and prepare it for
- accepting lines of text. The function returns an integer
- value which is a text object handle to be used in calls to
- subsequent procedures and functions in the text library.
- The text window will have the title string passed as the
- argument title$.
-
-
- Procedure: FNText_DeleteTextObject(objptr%)
-
- Description: This function deletes the text window object created by the
- previous function. All allocated memory is freed and the
- object cannot be referenced using its object handle any more.
-
-
- Procedure: PROCText_appline(objptr%, line$)
-
- Description: This procedure accepts an object handle created by a previous
- call to FNText_CreateTextObject, and a string containing a line
- of text. The line as added to the text window at the end of
- any current lines. If there are no lines displayed in the window,
- then line$ becomes the first line of the window.
-
-
- Procedure: PROCText_LoadFile(objptr%, file$)
-
- Description: This procedure accepts an object handle created by a previous
- call to FNText_CreateTextObject, and a string containing the
- name of a file. The entire file is loaded and displayed in the
- referenced text window. It is assumed for sensible results that
- the file does contain text lines rather than binary
- information.
-
-
- Procedure: PROCText_DeleteLine(objptr%, line%)
-
- Description: This procedure is called to delete a single line from the text
- window. The first argument gives the handle of the text window,
- while the second is the line number (counting from 0) to delete.
-
-
- Procedure: PROCText_init
-
- Description: This procedure must be called from a programs initialisation
- section, and certainly before any calls are made to the text window
- procedures and functions described above. It may be called while
- servicing the WIMP message Task_Initialise.
-
-
- Procedure: PROCText_Redraw(block%)
-
- Description: This procedure is provided for use in the WIMP's strategy for
- redrawing windows. It performs all the screen updates necessary
- to refresh the text windows. The procedure should be called
- in the Wimp_Poll loop when a Redraw_Window_Request event is
- received; see the !Compare program for an example. The procedure
- is as short as possible and makes several optimisations to
- ensure that the redrawing of the window takes as little time
- as possible - all in BASIC too!
-
-
- Procedure: PROCText_ModeInit
-
- Description: The routines used to display text use values which give the height
- and width of the characters on screen in pixels. These values are
- different for each mode, so it is important that on mode changes
- the new dimensions of characters are acted upon. This procedure is
- provided to perform all the necessary calculations based on the
- current screen mode. It should be placed in the main program in
- the section which deals with WIMP messages. The message type
- "Message_ModeChange" is sent to every program on a mode change,
- and when detected this procedure should be called; see the
- !Compare program for an example.
-