home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12780.ZIP / GENERAL.BAS < prev    next >
BASIC Source File  |  1990-10-25  |  12KB  |  367 lines

  1. '============================================================================
  2. '
  3. '     GENERAL.BAS - General Routines for the User Interface Toolbox in
  4. '           Microsoft BASIC 7.1, Professional Development System
  5. '              Copyright (C) 1987-1990, Microsoft Corporation
  6. '
  7. '  NOTE:    This sample source code toolbox is intended to demonstrate some
  8. '           of the extended capabilities of Microsoft BASIC 7.1 Professional
  9. '           Development system that can help to leverage the professional
  10. '           developer's time more effectively.  While you are free to use,
  11. '           modify, or distribute the routines in this module in any way you
  12. '           find useful, it should be noted that these are examples only and
  13. '           should not be relied upon as a fully-tested "add-on" library.
  14. '
  15. '  PURPOSE: These are the general purpose routines needed by the other
  16. '           modules in the user interface toolbox.
  17. '
  18. '  NOTE: These routines have been modified to support under OS/2 both
  19. '        full-screen and windowed command prompts using OS/2 API functions
  20. '        to provide similar effect to the DOS based code.
  21. '
  22. '  All sections of code that have been modified will have a comment
  23. '  preseeding the modifications in the following manner :
  24. '
  25. '  '| --- Modified to support OS/2 changes ---
  26. '  '|
  27. '  '| Description of changes
  28. '  '| ----------------------
  29. '  '|
  30. '
  31. '  THIS IS SAMPLE CODE AND IS NOT TO BE CONSIDERED A COMPLETE BUG FREE
  32. '  PACKAGE.  THIS CODE IS DESIGNED SPECIFICALLY TO RUN UNDER OS/2 PROTECTED
  33. '  MODE.  THE ORIGINAL CODE HAS NOT BEEN MODIFIED IN ANY WAY, EXCEPT TO
  34. '  PROVIDE THIS FUNCTIONALITY.
  35. '
  36. '
  37. '============================================================================
  38.  
  39. DEFINT A-Z
  40.  
  41. '$INCLUDE: 'general.bi'
  42. '$INCLUDE: 'mouse.bi'
  43.  
  44. '| --- Modified to support OS/2 changes ---
  45. '|
  46. '| Description of changes
  47. '| ----------------------
  48. '|
  49. '| Added module global variables to be used by the OS/2 Keyboard handlers
  50. '| for GetShiftState function.
  51. '|
  52.  
  53. COMMON SHARED /APIKeys/ KeyBoardOpen   as integer
  54. COMMON SHARED /APIKeys/ KeyBoardHandle as integer
  55.  
  56. '| Added TYPE...END TYPE's to be used with the OS/2 API calls
  57.  
  58. TYPE tCell
  59.     Char as string * 1
  60.     Attr as string * 1
  61. END TYPE
  62.  
  63. TYPE tKbdPeek
  64.     chChar     as string * 1
  65.     chScan     as string * 1
  66.     Status     as string * 1
  67.     Reserved   as string * 1
  68.     ShiftState as integer
  69.     TimeStamp  as long
  70. END TYPE
  71.  
  72. Type tKbdGetStatus
  73.     cb as integer
  74.     mask as integer
  75.     turnaround as integer
  76.     interim as integer
  77.     state as integer
  78. end type
  79.  
  80. '| DECLARE Statements for OS/2 Keyboard API functions
  81.  
  82. DECLARE FUNCTION KbdPeek%      ( SEG   pvData  AS tKbdPeek, _
  83.                                  BYVAL hDevice as integer   _
  84.                                )
  85.  
  86. DECLARE FUNCTION KbdFreeFocus% ( BYVAL hDevice as integer )
  87.  
  88. DECLARE FUNCTION KbdGetFocus%  ( BYVAL fWait   as integer, _
  89.                                  BYVAL hDevice as integer  _
  90.                                )
  91.  
  92. DECLARE FUNCTION kbdOpen%      ( SEG hDevice as integer )
  93.  
  94. DECLARE FUNCTION KbdGetStatus% ( SEG   pvData  as tKbdGetStatus, _
  95.                                  BYVAL hDevice as Integer        _
  96.                                )
  97.  
  98.  
  99. '| Declare Statement for OS/2 Video I/O API functions
  100.  
  101. DECLARE FUNCTION VioScrollUp%  ( BYVAL ULRow       as Integer, _
  102.                                  BYVAL ULCOL       as Integer, _
  103.                                  BYVAL LRRow       as Integer, _
  104.                                  BYVAL LRCol       as Integer, _
  105.                                  BYVAL Lines       as Integer, _
  106.                                  SEG   Cell        as tCell,   _
  107.                                  BYVAL VideoHandle as Integer  _
  108.                                )
  109.  
  110. DECLARE FUNCTION VioScrollDn%  ( BYVAL ULRow       as Integer, _
  111.                                  BYVAL ULCOL       as Integer, _
  112.                                  BYVAL LRRow       as Integer, _
  113.                                  BYVAL LRCol       as Integer, _
  114.                                  BYVAL Lines       as Integer, _
  115.                                  SEG   Cell        as tCell,   _
  116.                                  BYVAL VideoHandle as Integer  _
  117.                                )
  118.  
  119.  
  120.  
  121. FUNCTION AltToASCII$ (kbd$)
  122.     ' =======================================================================
  123.     ' Converts Alt+A to A,Alt+B to B, etc.  You send it a string.  The right
  124.     ' most character is compared to the string below, and is converted to
  125.     ' the proper character.
  126.     ' =======================================================================
  127.     index = INSTR("xyz{|}~Çü !" + CHR$(34) + "#$%&,-./012éâ", RIGHT$(kbd$, 1))
  128.  
  129.     IF index = 0 THEN
  130.         AltToASCII = ""
  131.     ELSE
  132.         AltToASCII = MID$("1234567890QWERTYUIOPASDFGHJKLZXCVBNM-=", index, 1)
  133.     END IF
  134.  
  135. END FUNCTION
  136.  
  137. SUB Box (row1, col1, row2, col2, fore, back, border$, fillFlag) STATIC
  138.  
  139.     '=======================================================================
  140.     '  Use default border if an illegal border$ is passed
  141.     '=======================================================================
  142.  
  143.     IF LEN(border$) < 9 THEN
  144.         t$ = "┌─┐│ │└─┘"
  145.     ELSE
  146.         t$ = border$
  147.     END IF
  148.  
  149.     ' =======================================================================
  150.     ' Check coordinates for validity, then draw box
  151.     ' =======================================================================
  152.  
  153.     IF col1 <= (col2 - 2) AND row1 <= (row2 - 2) AND col1 >= MINCOL AND row1 >= MINROW AND col2 <= MAXCOL AND row2 <= MAXROW THEN
  154.         MouseHide
  155.         BoxWidth = col2 - col1 + 1
  156.         BoxHeight = row2 - row1 + 1
  157.         LOCATE row1, col1
  158.         COLOR fore, back
  159.         PRINT LEFT$(t$, 1); STRING$(BoxWidth - 2, MID$(t$, 2, 1)); MID$(t$, 3, 1)
  160.         LOCATE row2, col1
  161.         PRINT MID$(t$, 7, 1); STRING$(BoxWidth - 2, MID$(t$, 8, 1)); MID$(t$, 9, 1);
  162.  
  163.         FOR a = row1 + 1 TO row1 + BoxHeight - 2
  164.             LOCATE a, col1
  165.             PRINT MID$(t$, 4, 1);
  166.  
  167.             IF fillFlag THEN
  168.                 PRINT STRING$(BoxWidth - 2, MID$(t$, 5, 1));
  169.             ELSE
  170.                 LOCATE a, col1 + BoxWidth - 1
  171.             END IF
  172.  
  173.             PRINT MID$(t$, 6, 1);
  174.         NEXT a
  175.         LOCATE row1 + 1, col1 + 1
  176.         MouseShow
  177.     END IF
  178.  
  179. END SUB
  180.  
  181. SUB GetBackground (row1, col1, row2, col2, buffer$) STATIC
  182.  
  183.     ' =======================================================================
  184.     ' Create enough space in buffer$ to hold the screen info behind the box
  185.     ' Then, call GetCopyBox to store the background in buffer$
  186.     ' =======================================================================
  187.  
  188.     IF row1 >= 1 AND row2 <= MAXROW AND col1 >= 1 AND col2 <= MAXCOL THEN
  189.         Wid = col2 - col1 + 1
  190.         Hei = row2 - row1 + 1
  191.         size = 4 + (2 * Wid * Hei)
  192.         buffer$ = SPACE$(size)
  193.  
  194.         CALL GetCopyBox(row1, col1, row2, col2, buffer$)
  195.     END IF
  196.  
  197. END SUB
  198.  
  199. '| --- Modified to support OS/2 changes ---
  200. '|
  201. '| Description of changes
  202. '| ----------------------
  203. '|
  204. '| Added OpenKeyboard Function to open the keyboard and reduce the size
  205. '| of GetShiftState function.
  206.  
  207. Function OpenKeyBoard%
  208.  
  209.     If NOT KeyBoardOpen then
  210.         Rtn% = KbdOpen% (KeyBoardHandle)
  211.         if NOT Rtn% then
  212.             KeyBoardOpen = TRUE
  213.         End if
  214.     End if
  215.  
  216.     OpenKeyBoard% = KeyBoardOpen
  217.  
  218. END Function
  219.  
  220. '| --- Modified to support OS/2 changes ---
  221. '|
  222. '| Description of changes
  223. '| ----------------------
  224. '|
  225. '| Modified GetShiftState function to work according to the differences
  226. '| between the DOS GetShiftState and the OS/2 equal by functionality.
  227.  
  228. FUNCTION GetShiftState% (bit%)
  229.  
  230.     DIM KeyBoardInfo as tKbdPeek
  231.     DIM KeyBoardStatus as tKbdGetStatus
  232.  
  233.     RtnState% = False
  234.  
  235.     If NOT KeyBoardOpen then
  236.         rtn% = OpenKeyboard%
  237.     end if
  238.  
  239.     IF bit% >= 0 and bit% <= 7 then
  240.  
  241.         rtn% = kbdgetfocus% (iowait%, keyboardhandle)
  242.  
  243.         if kbdpeek% (keyboardinfo, keyboardhandle) <> 0 then
  244.             'Skip
  245.         elseif keyboardinfo.status = chr$(0) then
  246.  
  247.             keyboardstatus.cb = len(keyboardstatus)
  248.  
  249.             if kbdgetstatus (keyboardstatus, keyhandle%) = 0 then
  250.                 if keyboardstatus.state <> 0 then
  251.                     ShiftState% = keyboardstatus.state
  252.                 end if
  253.             end if
  254.  
  255.         else
  256.             ShiftState% = keyboardinfo.ShiftState
  257.         end if
  258.  
  259.         Rtn% = kbdFreeFocus (KeyHandle%)
  260.  
  261.         if ShiftState% and 2 ^ bit% then
  262.             RtnState% = TRUE
  263.         end if
  264.  
  265.     end if
  266.  
  267.     GetShiftState% = RtnState%
  268.  
  269. END FUNCTION
  270.  
  271.  
  272. SUB PutBackground (row, col, buffer$)
  273.  
  274.     ' =======================================================================
  275.     ' This sub checks the boundries before executing the put command
  276.     ' =======================================================================
  277.  
  278.     IF row >= 1 AND row <= MAXROW AND col >= 1 AND col <= MAXCOL THEN
  279.         CALL PutCopyBox(row, col, buffer$)
  280.     END IF
  281.  
  282. END SUB
  283.  
  284. '| --- Modified to support OS/2 changes ---
  285. '|
  286. '| Description of changes
  287. '| ----------------------
  288. '|
  289. '| Modified Scroll SUB to work with the OS/2 API video functions that scroll
  290. '| the screen.
  291. '|
  292. '| The OS/2 API VIO calls replace the Call Interrupt service routines
  293.  
  294. SUB scroll (row1, col1, row2, col2, lines, attr)
  295.  
  296.     ULRow% = Row1
  297.     ULCOl% = Col1
  298.  
  299.     LRRow% = Row2
  300.     LRCOl% = Col2
  301.  
  302.     IF ULRow% > LRRow% Then Swap ULRow%, LRRow%
  303.  
  304.     IF ULCol% > LRCol% Then Swap ULCol%, LRCol%
  305.  
  306.  
  307.     IF row1 >= MINROW AND row2 <= MAXROW AND col1 >= MINCOL AND col2 <= MAXCOL THEN
  308.  
  309.         DIM Cell as TCell
  310.  
  311.         Cell.Char = chr$(32)
  312.         Cell.Attr = chr$(attr * 16)
  313.  
  314.         ScrollLines% = lines
  315.  
  316.         TopRow%   = ULRow% - 1
  317.         LeftCol%  = ULCol% - 1
  318.  
  319.         BotRow%   = LRRow% - 1
  320.         RightCol% = LRCol% - 1
  321.  
  322.         IF lines < 0 THEN
  323.  
  324.             '| Scroll the screen down
  325.  
  326.             Rtn% = VioScrollDn% ( TopRow%,      _
  327.                                   LeftCol%,     _
  328.                                   BotRow%,      _
  329.                                   RightCol%,    _
  330.                                   ScrollLines%, _
  331.                                   Cell,         _
  332.                                   VideoHandle%  _
  333.                                 )
  334.  
  335.         ELSEIf Lines = 0 Then
  336.  
  337.             ScrollLines% = BotRow% - TopRow% + 1
  338.  
  339.             Rtn% = VioScrollDn% ( TopRow%,      _
  340.                                   LeftCol%,     _
  341.                                   BotRow%,      _
  342.                                   RightCol%,    _
  343.                                   ScrollLines%, _
  344.                                   Cell,         _
  345.                                   VideoHandle%  _
  346.                                 )
  347.  
  348.  
  349.         ELSE
  350.  
  351.             '| Scroll the screen up
  352.  
  353.             Rtn% = VioScrollUp% ( TopRow%,      _
  354.                                   LeftCol%,     _
  355.                                   BotRow%,      _
  356.                                   RightCol%,    _
  357.                                   ScrollLines%, _
  358.                                   Cell,         _
  359.                                   VideoHandle%  _
  360.                                 )
  361.  
  362.         END IF
  363.  
  364.     END IF
  365.  
  366. END SUB
  367.