'変換テーブルによる漢字置換 / ver. 0.60 / by Kabuneko 2000/05/25
proc main
dllname USER
type POINT
x as default
y as default
end type
cdeclare int MapWindowPoints(HWND, HWND, POINT *, int);
dim pt as POINT
dim i, k, n, r, sel, check, file$, table$, line$
dim in$, out$, item$[25], list$[20]
'変換した文字につける目印の設定
const tag$ = "‡"
'リストファイルの指定
file$ = @@QxDirectory$ + "\" + "l_qkanji.lst"
'リストファイルを読込む
n = 1
if dir$(file$) <> "" then
open file$ for input as #1
do until eof(1)
lineinput #1, line$
list$[n++] = line$
loop
close #1
end if
'メニューアイテムの設定
i = 1
item$[i++] = "◆ 漢字変換テーブル選択"
item$[i++] = "-"
for n = 1 to 20
if list$[n] = "" then exit for '履歴リストが終わるまで追加
item$[i++] = "&" + chr$(&h41+n-1) + " : " + list$[n]
next
item$[i++] = "&" + chr$(&h41+i-4) + " : " + "【 リスト以外から選択 】"
item$[i++] = "&" + chr$(&h41+i-4) + " : " + "【 リストファイル編集 】"
item$[i++] = "&" + chr$(&h41+i-4) + " : " + "【 目印 一括削除 】"
'ポップアップメニューを表示・選択させる
sel = popupmenu(item$)
if sel < 3 then exit proc
'リスト以外から選択を選んだ場合
if instr(item$[sel], "リスト以外から選択") then
table$ = getfilename$(@@QXDirectory$, "*.*", "変換テーブルを選択")
if table$ = "" then exit proc
open file$ for append as #1
print #1, table$
close #1
elseif instr(item$[sel], "リストファイル編集") then
call @@OpenFile(file$)
exit proc
elseif instr(item$[sel], "目印 一括削除") then
@MoveFileTop
@ReplaceString2 tag$, "", 1
exit proc
else
table$ = list$[sel - 2]
end if
if @Select <> 0 then
call msgbox("範囲選択での処理はできません。")
exit proc
end if
'変換テーブルを変数に読込み
open table$ for input as #1
do until eof(1)
lineinput #1, line$
if mid$(line$, 1, 1) <> ";" 'テーブルのコメント行は読まない
in$ = in$ + mid$(line$, 1, 1)
out$ = out$ + mid$(line$, 2, 1)
end if
loop
close #1
r = msgbox(table$ + " を使って変換します。" + \
chr$(10) + chr$(10) + "1文字ずつ確認しますか?", MB_YESNOCANCEL)
if r = IDCANCEL then
exit proc
elseif r = IDYES then
check = 1
end if
'ここから実際に置換処理
@UndoBlock = 1
call iskeypressed(&h1B) '[ESC] キーを監視
do while @Code <> CODE_EOF
'置換対象を漢字だけに限る
if @Code < asc("亜") then
@MoveRightChar
else
i = instr(in$, chr$(@Code))
if i = 0 then
@MoverightChar
'カーソル上の文字が変換対象であるとき
else
r = 1 '基本的には置換実行
'逐次確認の場合は毎回たずねる
if check = 1 then
pt.x = @CursorPosX
pt.y = @CursorPosY
'ドキュメント座標をスクリーン座標に変換
MapWindowPoints(@hwnd, 0, pt, 1)
'キー入力を受け取って処理
do while 1
@@PopupString mid$(out$, i, 1) + \
" に変換? (Y[RET], N[SP])", pt.x, pt.y
n = inputkey
if n = &h59 or n = KEY_RETURN or n = KEY_RIGHT then
exit do
elseif n = &h4E or n = KEY_SPACE or n = KEY_LEFT then
r = 0 '置換をキャンセル
@MoveRightChar
exit do
elseif n = &h1B then '[ESC] で終了
@@PopupString ""
print str$(k) + " 個の漢字を変換しました。"
exit proc
end if
loop
end if
'一括のときと確認で YES のとき置換
if iskeypressed(&h1B) then exit do
if r = 1 then
@Deletechar
@Insert tag$ + mid$(out$, i, 1)
k++
end if
end if
end if
loop
@@PopupString ""
print str$(k) + " 個の漢字を変換しました。"
@UndoBlock = 0
end proc