home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmspch.zip / ETKSPCH.E < prev    next >
Text File  |  1995-02-08  |  7KB  |  239 lines

  1. const
  2.    GLUE_LEFT          = 1
  3.    GLUE_RIGHT         = 2
  4.    UPPERCASE          = 4
  5.    LOWERCASE          = 8
  6.    CAPITALIZE         = 16
  7.    NOPRINT            = 32
  8.    NEWPARAGRAPH       = 64
  9.    NEWLINE            = 128
  10.    -------- User Messages ----------
  11.    ETKSPCH_MIKEON     = 8197        -- WM_USER + 0x1005
  12.    ETKSPCH_MIKEOFF    = 8198        -- WM_USER + 0x1006
  13.    ETKSPCH_CORRECT    = 8199        -- WM_USER + 0x1007
  14.  
  15. definit
  16.   universal hwndDictation, pData
  17.   hwndDictation = 0
  18.   pData = 0
  19.  
  20. defc SPFirstInfirm
  21.   universal ibcol, ibline
  22.   ibcol = .col ; ibline = .line
  23.  
  24. defc SPInfirms
  25.   universal ibcol, ibline
  26.   'SPDeleteInfirms'
  27.   ibcol = .col ; ibline = .line
  28.   keyin arg(1)
  29.  
  30. defc SPDeleteInfirms
  31.   universal ibcol, ibline, stream_mode
  32.   i=0 -- I keep this here in case something goes wrong.
  33.       -- It's a protection against infinte loops
  34.   -- Here, we should be in stream editing. If not, backspace on col 1 will fail
  35.   stream_m = stream_mode
  36.   if not stream_m then 'stream_toggle' endif -- toggle to stram mode first
  37.   -- Backspace until all infirm words are deleted.
  38.   while .line>ibline or (.line=ibline and .col>ibcol) and i<255 do
  39.     executekey backspace
  40.     i=i+1
  41.   endwhile
  42.   if not stream_m then 'stream_toggle' endif -- restore stream state
  43.  
  44. defc SPFirm
  45.   universal ibcol, ibline
  46.   'SPDeleteInfirms'
  47.   parse value arg(1) with tag format \1 wordd \1 bGlueLeft bNewline bNewpar bCapital bLower bUpper
  48.   -- wordd is the word to be inserted
  49.   -- First check the format
  50.   l = length(wordd)
  51.   word2 = wordd
  52.   if et(format, GLUE_LEFT) then
  53.     -- Glue to preceding word
  54.     'SPGlueLeft'
  55.   endif
  56.   if et(format, NEWLINE) then
  57.     -- insert a new line
  58.     executekey enter
  59.     beginline
  60.   endif
  61.   if et(format, NEWPARAGRAPH) then
  62.     -- insert a new paragraph
  63.     executekey enter
  64.     executekey enter
  65.   endif
  66.   if not et(format, NOPRINT) then
  67.     -- we have to insert the word now
  68.     if et(format, CAPITALIZE) then
  69.       -- capitalize the word
  70.       word2 = upcase(substr(wordd, 1, 1))
  71.       if l>1 then
  72.         word2 = word2 || substr(wordd, 2, l-1)
  73.       endif
  74.     endif
  75.     if et(format, LOWERCASE) then
  76.       -- lowercase the word
  77.       word2 = lowcase(wordd)
  78.     endif
  79.     if et(format, UPPERCASE) then
  80.       -- uppercase the word
  81.       word2 = upcase(wordd)
  82.     endif
  83.     if tag<>4294967295 and tag<>-1 then
  84.       -- type the first letter and add the attribute
  85.       keyin substr(word2, 1, 1)
  86.       left
  87.       -- insert attribute now there
  88.       class = 13 ; ccol = .col ; llin = .line ; off = -1
  89.       insert_attribute class, tag, 0, off, ccol, llin
  90.       insert_attribute class, tag, 1, off, ccol, llin
  91.       -- go right and type the rest
  92.       right
  93.       if l>1 then
  94.         -- type the rest of the word
  95.         keyin substr(word2, 2, l-1)
  96.       endif
  97.     else
  98.       -- just type the word (no attribute)
  99.       keyin word2
  100.     endif
  101.   endif
  102.   ibcol = .col ; ibline = .line
  103.  
  104. defc SPGlueLeft
  105.   if .col>1 then
  106.     getline line
  107.     currentchar = substr(line, .col-1, 1)
  108.     if currentchar=' ' then
  109.       -- space : we can glue
  110.       executekey backspace
  111.     endif
  112.   else
  113.     executekey backspace
  114.   endif
  115.   if .col>1 then
  116.     getline line
  117.     currentchar = substr(line, .col-1, 1)
  118.     if currentchar=' ' then
  119.       -- space : we can glue
  120.       executekey backspace
  121.       if .col>1 then
  122.         getline line
  123.         currentchar = substr(line, .col-1, 1)
  124.         if currentchar=' ' then
  125.           -- cursor is on a space : we can glue
  126.           executekey backspace
  127.           if .col>1 then
  128.             getline line
  129.             currentchar = substr(line, .col-1, 1)
  130.             if currentchar=' ' then
  131.               -- cursor is on a space : we can glue
  132.               executekey backspace
  133.             endif
  134.           endif
  135.         endif
  136.       endif
  137.     endif
  138.   endif
  139.  
  140. defproc et(a,b)
  141.   return  (a % b)// 2
  142.  
  143. defc SPDictationWindow
  144.   universal hwndDictation, pData
  145.   parse arg hwndDictation pData
  146.   call register_mousehandler(1, '1 SECONDCLK 0', 'SPCorrectWord')
  147.  
  148. defc SPStartDictationSupport
  149.   universal hwndDictation
  150.   hwndEdit = getpminfo(5)
  151.   if SPIsStarted()==0 then
  152.     sayerror 'Starting Dictation support'
  153.     'start epmspch /connect /min /hwnd='hwndEdit
  154.   else
  155.     sayerror 'Dictation support started : selecting edit window '
  156.     call dynalink('ETKSPCH',
  157.                   'ETKSPCHSELECTEDITWND',
  158.                   atol_swap(hwndEdit))
  159.   endif
  160.  
  161. defproc SPIsStarted()
  162.   bufhndl = buffer(1, 'EPMSPCH.DAT');
  163.   if bufhndl<>0 then
  164.     call psave_pos(save_pos)
  165.     buffer(2, bufhndl);
  166.     call prestore_pos(save_pos)
  167.   endif
  168.   return bufhndl
  169.  
  170. defc SPMikeOn
  171.   universal hwndDictation
  172.   call windowmessage(0, hwndDictation, ETKSPCH_MIKEON, 0, 0)
  173.  
  174. defc SPMikeOff
  175.   universal hwndDictation
  176.   call windowmessage(0, hwndDictation, ETKSPCH_MIKEOFF, 0, 0)
  177.  
  178. defc SPCorrectWord
  179.   if SPCurrentChar()<>' ' then
  180.     wtag = SPMarkWord()
  181.     if wtag then
  182.       'SPCorrect 'wtag
  183.     endif
  184.   else
  185.     unmark
  186.     sayerror 'Cursor on a space'
  187.   endif
  188.  
  189. defc SPCorrect
  190.   universal hwndDictation
  191.   parse arg wordtag
  192.   call windowmessage(0, hwndDictation, ETKSPCH_CORRECT, wordtag, 0)
  193.  
  194. defproc SPMarkWord()
  195.   unmark
  196.   valu = 0
  197.   ccol = .col ; cline = .line
  198.   call pmark_word()
  199.   call pbegin_mark() ; bcol = .col
  200.   call pend_mark()   ; ecol = .col
  201.   -- search for first speech attrib left of cursor
  202.   class = 13 ; off = 0 ; col   = ccol ; lin   = cline
  203.   attribute_action 2, class, off, col, lin
  204.   if class=13 and lin=cline and col>=bcol and col<=ecol then
  205.     startcol = col
  206.     query_attribute class, valu, push, off, col, lin
  207.     -- search for first speech attrib right of cursor
  208.     class = 13 ; off = 0 ; col   = ccol ; lin   = cline
  209.     attribute_action 1, class, off, col, lin
  210.     if class=13 and lin=cline and col>=bcol and col<=ecol then
  211.       endcol = col
  212.       if col>bcol then
  213.         endcol = endcol -1
  214.       endif
  215.     else
  216.       endcol = ecol
  217.     endif
  218.     -- mark from startcol to endcol (current line)
  219.     .line= cline ; .col = endcol ; unmark ; mark_char ; .col = startcol ; mark_char
  220.   else
  221.     -- No attribute found in this word (left of the cursor).
  222.     -- This means we can't correct it -> unmark & restore cursor pos
  223.     unmark ; .col = ccol; .line = cline
  224.   endif
  225.   return valu
  226.  
  227. defc SPDelete
  228.   'SPGlueLeft'
  229.   delete_mark
  230.  
  231. defc SPCorrectReplace
  232.   delete_mark
  233.   'SPFirstInfirm'
  234.   'SPFirm 'arg(1)
  235.  
  236. defproc SPCurrentChar()
  237.   return substr(textline(.line), .col, 1)
  238.  
  239.