home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
epmspch.zip
/
ETKSPCH.E
< prev
next >
Wrap
Text File
|
1995-02-08
|
7KB
|
239 lines
const
GLUE_LEFT = 1
GLUE_RIGHT = 2
UPPERCASE = 4
LOWERCASE = 8
CAPITALIZE = 16
NOPRINT = 32
NEWPARAGRAPH = 64
NEWLINE = 128
-------- User Messages ----------
ETKSPCH_MIKEON = 8197 -- WM_USER + 0x1005
ETKSPCH_MIKEOFF = 8198 -- WM_USER + 0x1006
ETKSPCH_CORRECT = 8199 -- WM_USER + 0x1007
definit
universal hwndDictation, pData
hwndDictation = 0
pData = 0
defc SPFirstInfirm
universal ibcol, ibline
ibcol = .col ; ibline = .line
defc SPInfirms
universal ibcol, ibline
'SPDeleteInfirms'
ibcol = .col ; ibline = .line
keyin arg(1)
defc SPDeleteInfirms
universal ibcol, ibline, stream_mode
i=0 -- I keep this here in case something goes wrong.
-- It's a protection against infinte loops
-- Here, we should be in stream editing. If not, backspace on col 1 will fail
stream_m = stream_mode
if not stream_m then 'stream_toggle' endif -- toggle to stram mode first
-- Backspace until all infirm words are deleted.
while .line>ibline or (.line=ibline and .col>ibcol) and i<255 do
executekey backspace
i=i+1
endwhile
if not stream_m then 'stream_toggle' endif -- restore stream state
defc SPFirm
universal ibcol, ibline
'SPDeleteInfirms'
parse value arg(1) with tag format \1 wordd \1 bGlueLeft bNewline bNewpar bCapital bLower bUpper
-- wordd is the word to be inserted
-- First check the format
l = length(wordd)
word2 = wordd
if et(format, GLUE_LEFT) then
-- Glue to preceding word
'SPGlueLeft'
endif
if et(format, NEWLINE) then
-- insert a new line
executekey enter
beginline
endif
if et(format, NEWPARAGRAPH) then
-- insert a new paragraph
executekey enter
executekey enter
endif
if not et(format, NOPRINT) then
-- we have to insert the word now
if et(format, CAPITALIZE) then
-- capitalize the word
word2 = upcase(substr(wordd, 1, 1))
if l>1 then
word2 = word2 || substr(wordd, 2, l-1)
endif
endif
if et(format, LOWERCASE) then
-- lowercase the word
word2 = lowcase(wordd)
endif
if et(format, UPPERCASE) then
-- uppercase the word
word2 = upcase(wordd)
endif
if tag<>4294967295 and tag<>-1 then
-- type the first letter and add the attribute
keyin substr(word2, 1, 1)
left
-- insert attribute now there
class = 13 ; ccol = .col ; llin = .line ; off = -1
insert_attribute class, tag, 0, off, ccol, llin
insert_attribute class, tag, 1, off, ccol, llin
-- go right and type the rest
right
if l>1 then
-- type the rest of the word
keyin substr(word2, 2, l-1)
endif
else
-- just type the word (no attribute)
keyin word2
endif
endif
ibcol = .col ; ibline = .line
defc SPGlueLeft
if .col>1 then
getline line
currentchar = substr(line, .col-1, 1)
if currentchar=' ' then
-- space : we can glue
executekey backspace
endif
else
executekey backspace
endif
if .col>1 then
getline line
currentchar = substr(line, .col-1, 1)
if currentchar=' ' then
-- space : we can glue
executekey backspace
if .col>1 then
getline line
currentchar = substr(line, .col-1, 1)
if currentchar=' ' then
-- cursor is on a space : we can glue
executekey backspace
if .col>1 then
getline line
currentchar = substr(line, .col-1, 1)
if currentchar=' ' then
-- cursor is on a space : we can glue
executekey backspace
endif
endif
endif
endif
endif
endif
defproc et(a,b)
return (a % b)// 2
defc SPDictationWindow
universal hwndDictation, pData
parse arg hwndDictation pData
call register_mousehandler(1, '1 SECONDCLK 0', 'SPCorrectWord')
defc SPStartDictationSupport
universal hwndDictation
hwndEdit = getpminfo(5)
if SPIsStarted()==0 then
sayerror 'Starting Dictation support'
'start epmspch /connect /min /hwnd='hwndEdit
else
sayerror 'Dictation support started : selecting edit window '
call dynalink('ETKSPCH',
'ETKSPCHSELECTEDITWND',
atol_swap(hwndEdit))
endif
defproc SPIsStarted()
bufhndl = buffer(1, 'EPMSPCH.DAT');
if bufhndl<>0 then
call psave_pos(save_pos)
buffer(2, bufhndl);
call prestore_pos(save_pos)
endif
return bufhndl
defc SPMikeOn
universal hwndDictation
call windowmessage(0, hwndDictation, ETKSPCH_MIKEON, 0, 0)
defc SPMikeOff
universal hwndDictation
call windowmessage(0, hwndDictation, ETKSPCH_MIKEOFF, 0, 0)
defc SPCorrectWord
if SPCurrentChar()<>' ' then
wtag = SPMarkWord()
if wtag then
'SPCorrect 'wtag
endif
else
unmark
sayerror 'Cursor on a space'
endif
defc SPCorrect
universal hwndDictation
parse arg wordtag
call windowmessage(0, hwndDictation, ETKSPCH_CORRECT, wordtag, 0)
defproc SPMarkWord()
unmark
valu = 0
ccol = .col ; cline = .line
call pmark_word()
call pbegin_mark() ; bcol = .col
call pend_mark() ; ecol = .col
-- search for first speech attrib left of cursor
class = 13 ; off = 0 ; col = ccol ; lin = cline
attribute_action 2, class, off, col, lin
if class=13 and lin=cline and col>=bcol and col<=ecol then
startcol = col
query_attribute class, valu, push, off, col, lin
-- search for first speech attrib right of cursor
class = 13 ; off = 0 ; col = ccol ; lin = cline
attribute_action 1, class, off, col, lin
if class=13 and lin=cline and col>=bcol and col<=ecol then
endcol = col
if col>bcol then
endcol = endcol -1
endif
else
endcol = ecol
endif
-- mark from startcol to endcol (current line)
.line= cline ; .col = endcol ; unmark ; mark_char ; .col = startcol ; mark_char
else
-- No attribute found in this word (left of the cursor).
-- This means we can't correct it -> unmark & restore cursor pos
unmark ; .col = ccol; .line = cline
endif
return valu
defc SPDelete
'SPGlueLeft'
delete_mark
defc SPCorrectReplace
delete_mark
'SPFirstInfirm'
'SPFirm 'arg(1)
defproc SPCurrentChar()
return substr(textline(.line), .col, 1)