home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / csapi / csapi.api < prev    next >
Text File  |  1993-11-03  |  13KB  |  306 lines

  1. 'Spell Input Buffer Structure
  2. Type SpellInputBufferType
  3.     cch As Integer          'total characters in buffer area
  4.     cMdr As Integer         'count of MDR's specified in lrgMdr
  5.     cUdr As Integer         'count of UDR's specified in lrgUdr - should not reference Exclusion UDR's
  6.     wSpellState As Integer  'state relative to previous spellCheck() call
  7.     lrgch As Long           'pointer to buffer area of text to be spell checked
  8.     lrgMdr As Long          'list of main dictionaries to use when spelling the buffer
  9.     lrgUdr As Long          'list of user dictionaries to use when spelling the buffer - should not reference Exclusion UDR's
  10. End Type
  11.  
  12. 'Spell Return Buffer Structure
  13. Type SpellReturnBufferType
  14.     ichError As Integer     'position in the SIB
  15.     cchError As Integer     'length of error "word" in SIB
  16.     scrs As Integer         'spell check return status
  17.     csz As Integer          'count of sz's put in buffer
  18.     cchMac As Integer       'current total of chars in buffer
  19.     cch As Integer          'total space in lrgch. Set by App.
  20.     lrgsz As Long           'pointer to alternatives, null delimited
  21.     lrgbRating As Long      'pointer to rating value for each suggestion returned
  22.     cbRate As Integer       'number of elements in lrgbRating
  23. End Type
  24.  
  25. 'Main Dictionary Structure
  26. Type MdrType
  27.     Mdr As Integer
  28.     Lid As Integer
  29.     Udr As Long
  30. End Type
  31.  
  32. Type WizSpecCharsType
  33.     bIgnore As String * 1
  34.     bHyphenHard As String * 1
  35.     bHyphenSoft As String * 1
  36.     bHyphenNonBreaking As String * 1
  37.     bEmDash As String * 1
  38.     bEnDash As String * 1
  39.     bEllipsis As String * 1
  40.     rgLineBreak As String * 2
  41.     rgParaBreak As String * 2
  42. End Type
  43.  
  44. Declare Sub SpellVer Lib "msspell.dll" (spellVersion As Integer, SpellEngineType As Integer, spellFunctionality As Integer)
  45. Declare Function SpellVerifyMdr Lib "msspell.dll" (ByVal csMainDictionary As String, ByVal lidExpected As Integer, LanguageIdentifier As Integer) As Long
  46. Declare Function SpellInit Lib "msspell.dll" (csSpellIdentifier As Long, Wsc As WizSpecCharsType) As Integer
  47. Declare Function SpellOpenMdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal csMainDictionary As String, ByVal ExclusionDictionary As String, ByVal createUdrFlag As Integer, ByVal Cache As Integer, ByVal lidExpected As Integer, csMainDictionaryReference As MdrType) As Integer
  48. Declare Function SpellOpenUdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal csUserDictionary As String, ByVal createUdrFlag As Integer, ByVal udrPropertyType As Integer, ByVal udrReferenceId As Integer, ByVal udrReadOnlyFlag As Integer) As Integer
  49. Declare Function SpellOptions Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal SpellOption As Long) As Integer
  50. Declare Function SpellCheck Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal spellCheckCommand As Integer, spellInputBuffer As SpellInputBufferType, spellReturnBuffer As SpellReturnBufferType) As Integer
  51. Declare Function SpellAddChangeUdr Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal udrReferenceId As Integer, ByVal StringToReplace As String, ByVal StringToReplaceWith As String) As Integer
  52. Declare Function SpellTerminate Lib "msspell.dll" (ByVal csSpellIdentifier As Long, ByVal fForce As Integer) As Integer
  53.  
  54. 'Flag values for wSpellState field in Sib
  55. Global Const fssNoStateInfo = 0
  56. Global Const fssIsContinued = 1
  57. Global Const fssStartsSentence = 2
  58. Global Const fssIsEditedChange = 4
  59.  
  60. 'Ram Cache User Dictionary Reference
  61. Global Const udrChangeOnce = &HFFFC       'UDR reserved reference for Change Once List
  62. Global Const udrChangeAlways = &HFFFD     'UDR reserved reference for Change Always List
  63. Global Const udrIgnoreAlways = &HFFFE     'UDR reserved reference for Ignore Always List
  64.  
  65. 'Spell Language ID's
  66. Global Const lidAmerican = &H409
  67. Global Const lidAustralian = &HC09
  68.  
  69. 'Spell Language Definitions
  70. Global Const ldefAmerican = "American English"
  71. Global Const ldefAustralian = "English Australian"
  72.  
  73. 'Spell ID Engine's
  74. Global Const sidSA = 1      'SoftArt
  75. Global Const sidHM = 2      'Houghton-Mifflin
  76.  
  77. 'Spell ID Engine Definitions
  78. Global Const sdefSA = "SoftArt"
  79. Global Const sdefHM = "Houghton-Mifflin"
  80.  
  81. 'Spell Check Command Definitions
  82. Global Const sccVerifyWord = 1
  83. Global Const sccVerifyBuffer = 2
  84. Global Const sccSuggest = 3
  85. Global Const sccSuggestMore = 4
  86. Global Const sccHyphInfo = 5
  87. Global Const sccWildcard = 6
  88. Global Const sccAnagram = 7
  89.  
  90. 'Spell Check return status identifiers
  91. Global Const scrsNoErrors = 0               'all buffers processed
  92. Global Const scrsUnknownInputWord = 1       'unknown word
  93. Global Const scrsNoMoreSuggestions = 8      'no more suggestions
  94. Global Const scrsNoSentenceStartCap = 10    'start of sentence was not captialized
  95. Global Const scrsRepeatWord = 11            'repeat word found
  96.  
  97. Global csSpellIdentifier As Long
  98. Global csMainDictionaryReference As MdrType
  99. Global csMainDictionary As String
  100. Global csUserDictionary As String
  101. Global csTextBuffer As String
  102. Global csTextBufferOffset As Integer
  103. Global csSuggestionList As String
  104. Global csReturnStatus As Integer
  105.  
  106. Global csUnknownWordLength As Integer
  107. Global csUnknownWordStart As Integer
  108.  
  109. 'Spell Options Bitfield Definitions
  110. Global Const soFindUncappedSentences = &H10
  111. Global Const soFindRepeatWord = &H40
  112.  
  113. 'Common Speller
  114. Global Const csChange = 1
  115. Global Const csCancel = 2
  116. Global Const csDone = 3
  117. Global Const csError = 4
  118.  
  119. 'Common Speller Return Status
  120. Global Const csrsChange = 1
  121.  
  122. Dim spellReturnBuffer As SpellReturnBufferType
  123. Dim spellInputBuffer As SpellInputBufferType
  124.  
  125. Dim hInputBuffer%, lpszInputBuffer&, addrInputBuffer&
  126. Dim hAlternativesBuffer%, lpszAlternativesBuffer&, addrAlternativesBuffer&
  127. Dim hRatingsBuffer%, lpszRatingsBuffer&, addrRatingsBuffer&
  128.  
  129. Sub SpellerChange (newWord$)
  130.  
  131.     oldTextBuffer$ = csTextBuffer
  132.     xresume% = csUnknownWordStart + csUnknownWordLength - (Len(newWord$) = 0)
  133.     csTextBuffer = Left$(csTextBuffer, csUnknownWordStart - 1) & newWord$ & Mid$(csTextBuffer, xresume%)
  134.     If csTextBuffer <> oldTextBuffer$ Then csReturnStatus = csChange
  135.  
  136. End Sub
  137.  
  138. Sub SpellerCheck (spellState%, operation%, unknownWord$)
  139.     
  140.     buffer4098$ = Space$(4098)
  141.     rci% = CreateGlobalBuffer(buffer4098$, hInputBuffer%, lpszInputBuffer&, addrInputBuffer&)
  142.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hAlternativesBuffer%, lpszAlternativesBuffer&, addrAlternativesBuffer&)
  143.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hRatingsBuffer%, lpszRatingsBuffer&, addrRatingsBuffer&)
  144.     If rci% Then
  145.         'populate spell return buffer
  146.         spellReturnBuffer.ichError = 0
  147.         spellReturnBuffer.cchError = 0
  148.         spellReturnBuffer.cch = 4098
  149.         spellReturnBuffer.lrgsz = lpszAlternativesBuffer&
  150.         spellReturnBuffer.lrgbRating = lpszRatingsBuffer&
  151.         spellReturnBuffer.cbRate = 4098
  152.         'populate spell input buffer
  153.         spellInputBuffer.cMdr = 1
  154.         spellInputBuffer.cUdr = 0
  155.         spellInputBuffer.wSpellState = spellState%
  156.         spellInputBuffer.lrgch = lpszInputBuffer&
  157.         spellInputBuffer.lrgMdr = csMainDictionaryReference.Mdr
  158.         spellInputBuffer.lrgUdr = csMainDictionaryReference.Udr
  159.         Select Case operation%
  160.             Case sccVerifyBuffer
  161.                 csTextBufferOffset = csUnknownWordStart + csUnknownWordLength
  162.                 If Len(unknownWord$) = 0 Then unknownWord$ = Mid$(csTextBuffer, csTextBufferOffset)
  163.                 spellInputBuffer.cch = Len(unknownWord$) + 1
  164.                 Call hmemcpy(lpszInputBuffer&, unknownWord$, Len(unknownWord$))
  165.                 rci% = SpellCheck(csSpellIdentifier, sccVerifyBuffer, spellInputBuffer, spellReturnBuffer)
  166.                 If rci% Then
  167.                     csReturnStatus = csError
  168.                 Else
  169.                     Select Case spellReturnBuffer.scrs
  170.                         Case scrsNoSentenceStartCap
  171.                             csUnknownWordStart = spellReturnBuffer.ichError + csTextBufferOffset
  172.                             csUnknownWordLength = spellReturnBuffer.cchError
  173.                             csReturnStatus = scrsNoSentenceStartCap
  174.                         Case scrsNoErrors
  175.                             csReturnStatus = csDone
  176.                         Case scrsUnknownInputWord, 2, 3
  177.                             csUnknownWordStart = spellReturnBuffer.ichError + csTextBufferOffset
  178.                             csUnknownWordLength = spellReturnBuffer.cchError
  179.                             csReturnStatus = scrsUnknownInputWord
  180.                         Case scrsNoMoreSuggestions
  181.                             rcl& = lstrcpy(buffer4098$, lpszAlternativesBuffer&)
  182.                         Case scrsRepeatWord
  183.                             csUnknownWordStart = spellReturnBuffer.ichError + 1
  184.                             csUnknownWordLength = spellReturnBuffer.cchError
  185.                             csReturnStatus = scrsRepeatWord
  186.                     End Select
  187.                 End If
  188.             Case sccSuggest
  189.                 If Len(unknownWord$) = 0 Then
  190.                     csReturnStatus = csError
  191.                 Else
  192.                     csSuggestionList = ""
  193.                     spellCheckCommand% = sccSuggest
  194.                     spellInputBuffer.cch = Len(unknownWord$) + 1
  195.                     Call hmemcpy(lpszInputBuffer&, unknownWord$, Len(unknownWord$))
  196.                     Do
  197.                         rci% = SpellCheck(csSpellIdentifier, spellCheckCommand%, spellInputBuffer, spellReturnBuffer)
  198.                         If spellReturnBuffer.scrs = scrsNoErrors Then
  199.                             xstart% = 0
  200.                             Call hmemcpy(buffer4098$, lpszAlternativesBuffer&, spellReturnBuffer.cchMac)
  201.                             csSuggestionList = csSuggestionList & Trim$(buffer4098$)
  202.                             spellCheckCommand% = sccSuggestMore
  203.                         End If
  204.                     Loop While spellReturnBuffer.scrs <> scrsNoMoreSuggestions
  205.                 End If
  206.         End Select
  207.         Call DestroyGlobalBuffer(hInputBuffer%)
  208.         Call DestroyGlobalBuffer(hAlternativesBuffer%)
  209.         Call DestroyGlobalBuffer(hRatingsBuffer%)
  210.     End If
  211.     
  212. End Sub
  213.  
  214. Function SpellerGetGlobalMemory (initialValue$)
  215.     
  216.     buffer4098$ = Space$(4098)
  217.     rci% = CreateGlobalBuffer(initialValue$, hInputBuffer%, lpszInputBuffer&, addrInputBuffer&)
  218.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hAlternativesBuffer%, lpszAlternativesBuffer&, addrAlternativesBuffer&)
  219.     If rci% Then rci% = CreateGlobalBuffer(buffer4098$, hRatingsBuffer%, lpszRatingsBuffer&, addrRatingsBuffer&)
  220.     SpellerGetGlobalMemory = (rci% <> 0)
  221.  
  222. End Function
  223.  
  224. Sub SpellerIgnore ()
  225.  
  226.     unknownWord$ = spellerUnknownWord()
  227.     
  228.  
  229.  
  230. End Sub
  231.  
  232. Function SpellerInit (errorCode%) As Integer
  233.     
  234.     Dim lpWsc As WizSpecCharsType
  235.     errorCode% = SpellInit(csSpellIdentifier, lpWsc)
  236.     SpellerInit = errorCode%
  237.  
  238. End Function
  239.  
  240. Function SpellerKillGlobalMemory ()
  241.  
  242.     Call DestroyGlobalBuffer(hInputBuffer%)
  243.     Call DestroyGlobalBuffer(hAlternativesBuffer%)
  244.     Call DestroyGlobalBuffer(hRatingsBuffer%)
  245.  
  246. End Function
  247.  
  248. Function SpellerOpenMdr (majorError%, minorError%) As Integer
  249.     
  250.     createUdrFlag% = False: cacheFlag% = True: lidExpected% = 0
  251.     rci% = SpellOpenMdr(csSpellIdentifier, csMainDictionary$, csUserDictionary$, createUserFile%, cacheFlag%, languageIdExpected%, csMainDictionaryReference)
  252.     majorError% = rci% And &HFF&
  253.     minorError% = (rci% And &HFF00&) \ 256
  254.     SpellerOpenMdr = rci%
  255.  
  256. End Function
  257.  
  258. Function SpellerTerminate (errorCode%, fForce%)
  259.  
  260.     errorCode% = SpellTerminate(csSpellIdentifier, fForce%)
  261.     If Not errorCode% Then
  262.         csSpellIdentifier = 0
  263.         csMainDictionaryReference.Mdr = 0
  264.     End If
  265.     SpellerTerminate = errorCode%
  266.  
  267. End Function
  268.  
  269. Function spellerUnknownWord ()
  270.     
  271.     spellerUnknownWord = Mid$(csTextBuffer, csUnknownWordStart, csUnknownWordLength)
  272.  
  273. End Function
  274.  
  275. Function SpellerVerifyMdr () As String
  276.     
  277.     lidExpected% = True
  278.     rcl& = SpellVerifyMdr(csMainDictionary$, lidExpected%, Lid%)
  279.     If rcl& = 0 Then
  280.         Select Case Lid%
  281.             Case lidAmerican
  282.                 SpellerVerifyMdr = ldefAmerican
  283.             Case lidAustralian
  284.                 SpellerVerifyMdr = ldefAustralian
  285.         End Select
  286.     Else
  287.         SpellerVerifyMdr = "Error: " & rcl&
  288.     End If
  289.  
  290.  
  291. End Function
  292.  
  293. Function SpellerVersion () As String
  294.     
  295.     Call SpellVer(spellVersion%, spellEngine%, spellFunctionality%)
  296.     versionString$ = "Version " & ((spellVersion% And &HFF00&) \ 256) & "." & (spellVersion% And &HFF&)
  297.     Select Case spellEngine%
  298.         Case sidSA
  299.             SpellerVersion = versionString$ & " by " & sdefSA
  300.         Case sidHM
  301.             SpellerVersion = versionString$ & " by " & sdefHM
  302.     End Select
  303.  
  304. End Function
  305.  
  306.