home *** CD-ROM | disk | FTP | other *** search
/ DOS Wares / doswares.zip / doswares / DATABASE / DBASE5 / CUA_SAMP.ZIP / ASCIIC.PRG < prev    next >
Encoding:
Text File  |  1994-06-24  |  17.4 KB  |  547 lines

  1.  
  2. *......................................................................
  3. *
  4. *   Program Name: ASCII.PRG           Copyright: Borland International
  5. *   Date Created: 01/21/94             Language: dBASE 5.0
  6. *   Time Created: 10:38:14               Author: David Veale
  7. *   /brief/library.src
  8. *......................................................................
  9.  
  10. #define kMinWidth   22
  11. #define kMaxWidth   72
  12. #define kMinHeight  18
  13.  
  14. #define kListWidth  15
  15.  
  16. #define kNULL        0
  17. #define kSpace      32
  18. #define kMaxStrLen  80
  19.  
  20. #define kTop 1
  21.  
  22. #define ALLTRIM(kStr) LTRIM(RTRIM(kStr))
  23.  
  24. *.................................................................
  25. * Procedure Name:  ASCII
  26. * Parameters:      None
  27. * Ext Memvars:     None
  28. * Description:     Displays an ASCII table in a dBASE 5.0 form
  29. *                  Codes are shown in decimal, hex, and character
  30. *.................................................................
  31. PROCEDURE ASCIIC
  32.     PRIVATE lVoid
  33.     
  34.     #include "TALKOFF.HDB"
  35.  
  36.     IF TYPE("_CmdWindow.dbASCII.top") = "N"  && if another instance of dbASCII is active
  37.         lVoid = _CmdWindow.dbASCII.lTable.Setfocus()
  38.         lVoid = _CmdWindow.dbASCII.Open()
  39.     ELSE
  40.         DO DEFASCII    
  41.     ENDIF
  42. RETURN
  43.  
  44.  
  45. *...............................................
  46. * Procedure Name:   DEFASCII
  47. * Parameters:       None
  48. * Ext Memvars:      None
  49. * Description:      Define the ASCII Chart form
  50. *...............................................
  51. PROCEDURE DEFASCII
  52.     PRIVATE lVoid
  53.  
  54.     DECLARE aCodes[256]     && array of 256 rows to hold codes
  55.  
  56.     *.............................
  57.     * define the ascii table form
  58.     *.............................
  59.     #include "ASCIIC.DFM"
  60.  
  61.     _CmdWindow.dbASCII = dbASCII
  62.  
  63.     DO InitCodes
  64.     
  65.     _CmdWindow.dbASCII.lTable.DataSource = "ARRAY aCodes"
  66.     _CmdWindow.dbASCII.ASCMenu.mEdit.mMin.Enabled = .F.
  67.     lVoid = _CmdWindow.dbASCII.lTable.Setfocus()
  68.     lVoid = _CmdWindow.dbASCII.Open()
  69.  
  70. RETURN
  71.  
  72.  
  73. *..............................................................
  74. * Procedure Name:   Cpy2Entr
  75. * Parameters:       None
  76. * Ext Memvars:      _CmdWindow.dbASCII.e1
  77. * Description:      Copies character from chart to entry field
  78. *..............................................................
  79. PROCEDURE Cpy2Entr
  80.     PRIVATE cValue, nSel, nTLen
  81.  
  82.     SET TALK OFF
  83.     
  84.     cValue = SPACE(kMaxStrLen + 1)
  85.     nSel   = 0
  86.     nTLen  = 0
  87.  
  88.     nSel = _CmdWindow.dbASCII.lTable.CurSel
  89.     nSel = nSel - 1
  90.     
  91.     DO CASE
  92.         CASE nSel = kNULL
  93.             RETURN
  94.         CASE nSel = kSpace
  95.             _CmdWindow.dbASCII.e1.nLen = _CmdWindow.dbASCII.e1.nLen + 1
  96.         OTHERWISE
  97.             cValue = RTRIM(_CmdWindow.dbASCII.e1.Value) + ""
  98.             nTLen = LEN(m->cValue)
  99.             DO WHILE nTLen < _CmdWindow.dbASCII.e1.nLen
  100.                 cValue = m->cValue + " "
  101.                 nTLen = LEN(m->cValue)
  102.             ENDDO
  103.             cValue = m->cValue + CHR(m->nSel)
  104.             _CmdWindow.dbASCII.e1.nLen = _CmdWindow.dbASCII.e1.nLen + 1   
  105.             cValue = m->cValue + SPACE(kMaxStrLen - LEN(m->cValue))
  106.             _CmdWindow.dbASCII.e1.Value = m->cValue
  107.     ENDCASE    
  108. RETURN
  109.  
  110.  
  111. *........................................................
  112. * Procedure Name:   CopyChar
  113. * Parameters:       None
  114. * Ext Memvars:      None
  115. * Description:      Copies character string to clipboard
  116. *........................................................
  117. PROCEDURE CopyChar
  118.     PRIVATE cValue
  119.         
  120.     cValue = _CmdWindow.dbASCII.e1.Value
  121.     
  122.     cValue = ALLTRIM(m->cValue) + ""
  123.     
  124.     _Clipboard.InsertLine = m->cValue
  125.     _Clipboard.ExtendSelection = .T.
  126.     _Clipboard.Column = 1
  127.     _Clipboard.ExtendSelection = .F.
  128. RETURN
  129.  
  130.  
  131. *.............................................................................
  132. * Procedure Name:   ResetLen
  133. * Parameters:       None
  134. * Ext Memvars:      _CmdWindow.dbASCII.e1
  135. * Description:      Resets the value of _CmdWindow.dbASCII.e1.nLen to the current length
  136. *                   of the string in _CmdWindow.dbASCII.e1.Value following a manual 
  137. *                   edit by the user.
  138. *.............................................................................
  139. PROCEDURE ResetLen
  140.     PRIVATE cValue, nTLen
  141.     
  142.     cValue = ""
  143.     nTLen  = 0
  144.     
  145.     cValue = RTRIM(_CmdWindow.dbASCII.e1.Value) + ""
  146.     nTLen  = LEN(m->cValue)
  147.     
  148.     _CmdWindow.dbASCII.e1.nLen  = m->nTLen
  149.     _CmdWindow.dbASCII.e1.Value = m->cValue + SPACE(kMaxStrLen - m->nTLen)
  150. RETURN
  151.  
  152.  
  153. *...................................................................
  154. * Procedure Name:   FixLen
  155. * Parameters:       None
  156. * Ext Memvars:      _CmdWindow.dbASCII.e1
  157. * Description:      Fixes the value of _CmdWindow.dbASCII.e1 to the current length
  158. *                   of the string in _CmdWindow.dbASCII.e1.Value.nLen on a manual 
  159. *                   edit by the user.
  160. *.............................................................................
  161. PROCEDURE FixLen
  162.     PRIVATE cValue, nTLen
  163.     
  164.     cValue = ""
  165.     nTLen  = 0
  166.     
  167.     cValue = RTRIM(_CmdWindow.dbASCII.e1.Value) + ""
  168.     nTLen = LEN(m->cValue)
  169.     DO WHILE nTLen < _CmdWindow.dbASCII.e1.nLen
  170.         cValue = m->cValue + " "
  171.         nTLen = LEN(m->cValue)
  172.     ENDDO
  173.     _CmdWindow.dbASCII.e1.Value = m->cValue + SPACE(kMaxStrLen - LEN(m->cValue))
  174. RETURN
  175.         
  176.  
  177. *.................................................................
  178. * Procedure Name:   SetTalk
  179. * Parameters:       None
  180. * Ext Memvars:      This.lSTalk
  181. * Description:      Saves the value of SET TALK and sets TALK OFF
  182. *.................................................................
  183. PROCEDURE SetTalk
  184.     IF TYPE("_CmdWindow.dbASCII.lSTalk") = "L"
  185.         _CmdWindow.dbASCII.lSTalk = SET("TALK") = "ON"
  186.     ELSE
  187.         dbASCII.lSTalk = SET("TALK") = "ON"            
  188.     ENDIF    
  189.     SET TALK OFF
  190. RETURN
  191.  
  192.  
  193. *............................................................................
  194. * Procedure Name:   ResetTalk
  195. * Parameters:       None
  196. * Ext Memvars:      This.lSTalk
  197. * Description:      Resets the value of SET TALK based on the value when the
  198. *                   object got focus
  199. *............................................................................
  200. PROCEDURE ResetTalk
  201.     IF _CmdWindow.dbASCII.lSTalk
  202.         SET TALK ON
  203.     ELSE
  204.         SET TALK OFF
  205.     ENDIF
  206. RETURN
  207.  
  208.  
  209. *....................................................
  210. * Procedure Name:   InitCodes
  211. * Parameters:       None
  212. * Ext Memvars:      aCodes[]
  213. * Description:      Initializes character code array
  214. *....................................................
  215. PROCEDURE InitCodes
  216.     PRIVATE i, j
  217.  
  218.     SET TALK OFF
  219.  
  220.     j = 0
  221.  
  222.     *........................
  223.     * initialize codes array
  224.     *........................
  225.     FOR m->i = 0 TO 255
  226.         j = m->i + 1
  227.         DO CASE                         && Character
  228.             CASE m->i = 0             
  229.                 aCodes[m->j] = "NUL    0   00"
  230.             CASE i = 32
  231.                 aCodes[m->j] = "SPC   32   20"
  232.             OTHERWISE
  233.                 aCodes[m->j] = " " + CHR(m->i) + "    " + STR(m->i,3,0) + "   " +;
  234.                     IIF(m->i > 15, Dec2Hex(m->i), "0" + Dec2Hex(m->i))
  235.         ENDCASE
  236.     ENDFOR
  237. RETURN
  238.  
  239.  
  240. *...................................
  241. * Procedure Name:   FileExit
  242. * Parameters:       None
  243. * Ext Memvars:      _CmdWindow.dbASCII
  244. * Description:      Release _CmdWindow.dbASCII
  245. *...................................
  246. PROCEDURE FileExit
  247.     PRIVATE lVoid
  248.     
  249.     lVoid = _CmdWindow.dbASCII.Close()
  250.     lVoid = _CmdWindow.dbASCII.Release()
  251.     _CmdWindow.dbASCII = .F.
  252.     RELEASE dbASCII
  253. RETURN
  254.  
  255.  
  256. *...............................................................
  257. * Procedure Name:   FixSize
  258. * Parameters:       None
  259. * Ext. Memvars:     _CmdWindow.dbASCII
  260. * Description:      Adjusts all objects in _CmdWindow.dbASCII when resized
  261. *...............................................................
  262. PROCEDURE FixSize
  263.     PRIVATE nHeight, nWidth, nTWidth, nLeft
  264.     
  265.     SET TALK OFF
  266.     
  267.     IF _CmdWindow.dbASCII.WindowState # 1
  268.  
  269.         nWidth  = 0     && form height
  270.         nTWidth = 0     && list box width
  271.         nLeft   = 0     && list box left
  272.  
  273.         * make sure the form was not made too small
  274.         IF _CmdWindow.dbASCII.Height < kMinHeight
  275.             _CmdWindow.dbASCII.Height = kMinHeight
  276.         ENDIF
  277.     
  278.         IF _CmdWindow.dbASCII.Width < kMinWidth
  279.             _CmdWindow.dbASCII.Width = kMinWidth
  280.         ENDIF
  281.     
  282.         * make sure the form was not made too wide
  283.         IF _CmdWindow.dbASCII.Width > kMaxWidth
  284.             _CmdWindow.dbASCII.Width = kMaxWidth
  285.         ENDIF        
  286.     
  287.         * save the new height and width
  288.         nHeight = _CmdWindow.dbASCII.Height
  289.         nWidth  = _CmdWindow.dbASCII.Width
  290.  
  291.         * adjust the button
  292.         _CmdWindow.dbASCII.bAdd.Top  = m->nHeight - (8 - kTop)
  293.         _CmdWindow.dbASCII.bAdd.Left = INT((m->nWidth / 2) - 6)
  294.     
  295.         * adjust the entry field
  296.         _CmdWindow.dbASCII.e1.Top   = m->nHeight - (6 - kTop)
  297.         _CmdWindow.dbASCII.e1.Width = m->nWidth - 6
  298.     
  299.         * adjust the list box
  300.         _CmdWindow.dbASCII.lTable.Height = m->nHeight - 10
  301.  
  302.         DO CASE
  303.             CASE m->nWidth < ((kMinWidth * 2) - 6)
  304.                 nTWidth                             =  kListWidth
  305.                 _CmdWindow.dbASCII.lTable.Width     =  m->nTWidth
  306.                 _CmdWindow.dbASCII.lTable.Column    =  1
  307.                 _CmdWindow.dbASCII.dbTitle2.Visible = .F.
  308.                 _CmdWindow.dbASCII.dbTitle3.Visible = .F.
  309.                 _CmdWindow.dbASCII.dbTitle4.Visible = .F.
  310.             CASE (m->nWidth >= ((kMinWidth * 2) -  6)) .AND.; 
  311.                  (m->nWidth <  ((kMinWidth * 3) - 11))        
  312.                 nTWidth                             = (kListWidth * 2) + 2
  313.                 _CmdWindow.dbASCII.lTable.Width     =  m->nTWidth
  314.                 _CmdWindow.dbASCII.lTable.Column    =  2
  315.                 _CmdWindow.dbASCII.dbTitle2.Visible = .T.
  316.                 _CmdWindow.dbASCII.dbTitle3.Visible = .F.
  317.             CASE (m->nWidth >= ((kMinWidth * 3) - 11)) .AND. (m->nWidth < kMaxWidth)
  318.                 nTWidth                             = (kListWidth * 3) + 4
  319.                 _CmdWindow.dbASCII.lTable.Width     =  m->nTWidth
  320.                 _CmdWindow.dbASCII.lTable.Column    =  3
  321.                 _CmdWindow.dbASCII.dbTitle3.Visible = .T.
  322.                 _CmdWindow.dbASCII.dbTitle4.Visible = .F.
  323.             CASE nWidth = kMaxWidth
  324.                 nTWidth                             = (kListWidth * 4) + 6
  325.                 _CmdWindow.dbASCII.lTable.Width     =  m->nTWidth
  326.                 _CmdWindow.dbASCII.lTable.Column    =  4
  327.                 _CmdWindow.dbASCII.dbTitle2.Visible = .T.
  328.                 _CmdWindow.dbASCII.dbTitle3.Visible = .T.
  329.                 _CmdWindow.dbASCII.dbTitle4.Visible = .T.
  330.         ENDCASE        
  331.     
  332.         * get the left coordinate for the text
  333.         nLeft = INT((m->nWidth / 2) - (m->nTWidth / 2) - 1)
  334.         _CmdWindow.dbASCII.lTable.Left = m->nLeft
  335.  
  336.         * adjust the title text
  337.         _CmdWindow.dbASCII.dbTitle1.Left = m->nLeft
  338.  
  339.         IF _CmdWindow.dbASCII.dbTitle2.Visible
  340.             _CmdWindow.dbASCII.dbTitle2.Left = m->nLeft + 17
  341.         ELSE
  342.             _CmdWindow.dbASCII.dbTitle2.Left = 0
  343.         ENDIF
  344.     
  345.         IF _CmdWindow.dbASCII.dbTitle3.Visible            
  346.             _CmdWindow.dbASCII.dbTitle3.Left = m->nLeft + 34
  347.         ELSE
  348.             _CmdWindow.dbASCII.dbTitle3.Left = 0
  349.         ENDIF
  350.     
  351.         IF _CmdWindow.dbASCII.dbTitle4.Visible        
  352.             _CmdWindow.dbASCII.dbTitle4.Left = m->nLeft + 51
  353.         ELSE
  354.             _CmdWindow.dbASCII.dbTitle4.Left = 0
  355.         ENDIF        
  356.     
  357.         IF (_CmdWindow.dbASCII.Width = kMinWidth) .AND. (_CmdWindow.dbASCII.Height = kMinHeight)
  358.             _CmdWindow.dbASCII.ASCMenu.mEdit.mMin.Enabled = .F.
  359.         ELSE
  360.             _CmdWindow.dbASCII.ASCMenu.mEdit.mMin.Enabled = .T.
  361.         ENDIF            
  362.  
  363.         IF (_CmdWindow.dbASCII.Width = kMaxWidth) .AND. (_CmdWindow.dbASCII.Height >= GetMaxHgt())
  364.             _CmdWindow.dbASCII.ASCMenu.mEdit.mMax.Enabled = .F.
  365.         ELSE
  366.             _CmdWindow.dbASCII.ASCMenu.mEdit.mMax.Enabled = .T.
  367.         ENDIF            
  368.     ENDIF
  369. RETURN
  370.  
  371.  
  372. *...............................................................
  373. * Procedure Name:   ASCMax
  374. * Parameters:       None
  375. * Ext Memvars:      _CmdWindow.dbASCII
  376. * Description:      Sets ASCII chart to maximum size for screen
  377. *...............................................................
  378. PROCEDURE ASCMax
  379.     _CmdWindow.dbASCII.Height = GetMaxHgt()
  380.     _CmdWindow.dbASCII.Top    = 0
  381.  
  382.     _CmdWindow.dbASCII.Width  = kMaxWidth
  383.  
  384.     IF _CmdWindow.dbASCII.Left > 6
  385.         _CmdWindow.dbASCII.Left = 6
  386.     ENDIF
  387.  
  388.     IF _CmdWindow.dbASCII.Left < 0
  389.         _CmdWindow.dbASCII.Left = 0
  390.     ENDIF
  391.         
  392.     DO FixSize
  393.  
  394.     _CmdWindow.dbASCII.dbTitle2.Visible = .T.
  395.     _CmdWindow.dbASCII.dbTitle3.Visible = .T.
  396. RETURN
  397.  
  398.  
  399. *....................................................
  400. * Procedure Name:   ASCMin
  401. * Parameters:       None
  402. * Ext Memvars:      _CmdWindow.dbASCII
  403. * Description:      Sets ASCII chart to minimum size
  404. *....................................................
  405. PROCEDURE ASCMin
  406.     PRIVATE nMaxHgt
  407.     
  408.     nMaxHgt = GetMaxHgt()
  409.     
  410.     _CmdWindow.dbASCII.Width  = kMinWidth
  411.     _CmdWindow.dbASCII.Height = kMinHeight
  412.  
  413.     IF _CmdWindow.dbASCII.Left > 56
  414.         _CmdWindow.dbASCII.Left = 56
  415.     ENDIF
  416.     
  417.     IF _CmdWindow.dbASCII.Left < 0
  418.         _CmdWindow.dbASCII.Left = 0
  419.     ENDIF    
  420.     
  421.     IF _CmdWindow.dbASCII.Top > (m->nMaxHgt - kMinHeight)
  422.         _CmdWindow.dbASCII.Top = m->nMaxHgt - kMinHeight
  423.     ENDIF
  424.  
  425.     DO FixSize
  426.  
  427.     _CmdWindow.dbASCII.dbTitle3.Visible = .F.
  428.     _CmdWindow.dbASCII.dbTitle4.Visible = .F.
  429. RETURN
  430.  
  431.  
  432. *............................................................................
  433. * Function Name:    GetMaxHgt()
  434. * Parameters:       None
  435. * Ext Memvars:      None
  436. * Return Value:     numeric, maximum form height for screen
  437. * Description:      compute the maximum form height for a form with a top
  438. *                   of 0.  The current number of lines on the screen and the
  439. *                   setting of SET STATUS are taken into account.
  440. *............................................................................
  441. FUNCTION GetMaxHgt
  442.     PRIVATE nLines
  443.         
  444.     * get the number of lines by looking at the display mode
  445.     nLines = VAL(RIGHT(RTRIM(SET("DISPLAY")), 2))
  446.     
  447.     IF m->nLines = 0       && if no number in display mode
  448.         nLines = 25
  449.     ENDIF
  450.         
  451.     IF SET("STATUS") = "ON"
  452.         nLines = m->nLines - 5     && put form 2 lines above status
  453.     ELSE                        && no status line
  454.         nLines = m->nLines - 3     && put form 2 lines above bottom
  455.     ENDIF
  456. RETURN m->nLines            
  457.     
  458. *...............................................................
  459. * Procedure Name:   AHAbout
  460. * Parameters:       None
  461. * Ext Memvars:      None
  462. * Description:      Displays an "About" box for the ASCII chart
  463. *...............................................................
  464. PROCEDURE AHAbout
  465.     PRIVATE lVoid
  466.     
  467.     lVoid = .T.
  468.  
  469.     #include "AHABOUT.DFM"
  470.     
  471.     lVoid = AHAbout.ReadModal()
  472.     
  473.     lVoid = AHAbout.Release()
  474.     RELEASE AHAbout
  475. RETURN
  476.  
  477.  
  478. PROCEDURE HUsing
  479. RETURN    
  480.  
  481.  
  482. *..........................................
  483. * Procedure Name:   PrAbout
  484. * Parameters:       None
  485. * Ext Memvars:      HAbout
  486. * Description:      Closes the form HAbout
  487. *..........................................
  488. PROCEDURE PrAbout
  489.     PRIVATE lVoid
  490.     
  491.     lVoid = AHAbout.Close()
  492. RETURN    
  493.  
  494.  
  495. *......................................................................
  496. * Procedure Name:   IDEHelp
  497. * Parameters:       None
  498. * Ext Memvars:      None
  499. * Description:      Calls the help system with current object's HelpID
  500. *......................................................................
  501. PROCEDURE IDEHelp
  502.     PRIVATE lVoid
  503.     
  504.     _SysHelp.HelpID = This.HelpID
  505.     lVoid = _SysHelp.ReadModal()
  506. RETURN    
  507.  
  508.  
  509. *.....................................................................
  510. * The following functions are from the dUFLP library maintained by
  511. * Ken Mayer of Team Borland.  These functions are in the public 
  512. * domain.  The library may be downloaded from the Borland dBASE Forum
  513. * on CompuServe.
  514. *.....................................................................
  515.  
  516.        
  517. FUNCTION Dec2Hex
  518. *-----------------------------------------------------------------------
  519. *-- Programmer..: Jay Parsons (CIS: 72662,1302)
  520. *-- Date........: 03/01/1992
  521. *-- Notes.......: Converts an unsigned integer ( in decimal notation)
  522. *--               to a hexadecimal string
  523. *-- Written for.: dBASE IV, 1.1
  524. *-- Rev. History: 03/01/1992
  525. *-- Calls.......: None
  526. *-- Called by...: Any
  527. *-- Usage.......: Dec2Hex(<nDecimal>)
  528. *-- Example.....: ? Dec2Hex( 118 )
  529. *-- Returns.....: Character = Hexadecimal equivalent ( "F6" in example )
  530. *-- Parameters..: nDecimal = number to convert
  531. *-----------------------------------------------------------------------
  532.    
  533.    parameters nDecimal
  534.    private nD, cH
  535.  
  536.    m->nD = int( m->nDecimal )
  537.    m->cH= ""
  538.    do while m->nD > 0
  539.      m->cH = substr( "0123456789ABCDEF", mod( m->nD, 16 ) + 1 , 1 );
  540.                           + m->cH
  541.      m->nD = int( m->nD / 16 )
  542.    enddo
  543.    
  544. RETURN iif( "" = m->cH, "0", m->cH )
  545. *-- Eof: Dec2Hex()
  546.  
  547.