########################################################################
#
# "main_tk" : Tvi, メインの Tk ウィジェット
#
# Copyright (c) 1998,1999  Motomu Nakashima
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option) 
# any later version.
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details.
#
########################################################################

#######################################
#   仮想 text ウィジェット .virtual   #
#   通常はこれに focus されている     #
#######################################
frame .virtual
place .virtual -x 0 -y 0

# その他の処理上用いるウィジェット
frame .virtual_delete -highlightthickness 0
place .virtual_delete -x 0 -y 0
frame .virtual_yank
place .virtual_yank -x 0 -y 0
frame .garbage
place .garbage -x 0 -y 0
frame .line_yank
place .line_yank -x 0 -y 0
entry .text_for_redo -width 1000000 -textvariable text_for_redo
text .search_text 
entry .tmp 

#########################
# バッファウィンドゥ
#########################
toplevel .buffer
.buffer configure 
wm title .buffer "Brandnew Buffer"
wm withdraw .buffer
text  .buffer.yanked_text -height 20 -width 76 -wrap none \
           -xscrollcommand { .buffer.xscroll set } \
           -yscrollcommand { .buffer.yscroll set } \
           -highlightthickness 0
text  .buffer.linenumber

frame .buffer.button 
button .buffer.button.1 -text "OK" \
          -command "buffer_ok" 
button .buffer.button.2 -text "All clear" \
          -command " .buffer.yanked_text delete 1.0 end "  
pack \
      .buffer.button.1 \
      .buffer.button.2 \
              -side right -padx 20
scrollbar .buffer.xscroll \
         -command { .buffer.yanked_text xview } -width 14 \
         -orient horizontal 
scrollbar .buffer.yscroll \
         -command { .buffer.yanked_text yview } -width 14 
pack \
        .buffer.xscroll \
            -side top -fill x
pack \
        .buffer.button \
           -side bottom
pack \
        .buffer.yanked_text \
        .buffer.yscroll \
           -side left -fill y
focus .buffer.yanked_text


text .replaced_text
entry .replaced_entry

frame .virtual_replace_many
# frame .virtual_replace_one
text .virtual_replace_one

frame .topmenu -bg $panel_color -relief raised -bd 1
frame .textandyscroll -bg $panel_color
frame .textandline -bg $panel_color -relief sunken -bd 2

. configure -bg $panel_color

##############################
#    メインのテキスト画面    #
##############################
text .text -relief flat   -bd 2 \
           -xscrollcommand { .xscroll set } \
           -yscrollcommand { .yscroll set } \
           -highlightthickness 0 \
           -foreground $fore_color \
           -background $back_color \
           -insertbackground $fore_color \
           -height 3 -width 76 -wrap none \
           -setgrid 1 


text .text_linenumber  -relief flat -bd 2 \
           -xscrollcommand { .xscroll set } \
           -highlightthickness 0 \
           -foreground $fore_color \
           -background $back_color \
           -height 3 -width 7 -state normal

scrollbar .xscroll -command { .text xview } -width 10  \
          -orient horizontal \
          -bg $panel_color -highlightbackground $panel_color \
          -troughcolor $panel_color -highlightcolor $panel_color
scrollbar .yscroll -command { text_yview } -width 14 \
          -bg $panel_color -highlightbackground $panel_color \
          -troughcolor $panel_color -highlightcolor $panel_color

# 上側のナビゲーション行
menubutton .load -text "File"  \
              -bg $panel_color \
              -highlightbackground $panel_color \
              -relief flat \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -highlightthickness 0 \
              -menu .load.menu

menu .load.menu -bg $panel_color -tearoff False
     .load.menu add command -label "ファイルを開く" \
                            -accelerator {(:e[Space])} \
                            -command { set new_or_insert 0 ; openfile } 
     .load.menu add command -label "ファイルを挿入読み込みで開く" \
                            -accelerator {(:r[Space])} \
                            -command { set new_or_insert 1 ; openfile }
     .load.menu add command -label "ファイルを保存する" \
                            -accelerator {(:w[Enter])} \
                            -command save_colon_w
     .load.menu add command -label "名前を指定してファイルを保存する" \
                            -accelerator {(:w[Space])} \
                            -command savefile
     .load.menu add command -label "端末を開く" \
                            -accelerator "(Alt+T)" \
                            -command terminal_popup
     .load.menu add separator
     .load.menu add command -label "(保存して)コンパイル" \
                            -accelerator "(Alt+C)" \
                            -command compiling
     .load.menu add command -label "xdvi の起動" \
                            -accelerator "(Alt+X)" \
                            -command xdvi_popup
     .load.menu add command -label "プリント" \
                            -accelerator "(Alt+P)" \
                            -command print_window
     .load.menu add separator
     .load.menu add command -label "ヘルプ" \
                            -accelerator "(Alt+H)" \
                            -command help_popup
     .load.menu add separator
     .load.menu add command -label "保存して終了" \
                            -accelerator {(:wq[Enter])} \
          -command { set f [ open $filename w ]
                     puts -nonewline $f [.text get 1.0 end ]
                     close $f
                     catch { eval exec rm -f [glob tvi_*.ppm]  }
                     exit
                    }
     .load.menu add command -label "終了" \
                            -accelerator {(:q[Enter])} \
                            -command {
                 if { $saved_flag == 1 } {
                    catch { eval exec rm -f [glob tvi_*.ppm]  }
                    exit
                 } else {  
                   .navi.main delete 0 end 
                   .navi.main insert insert "`$short_filename'" 
                   .navi.main insert insert { [Modified]} 
                   .navi.main configure -state disabled 
                    belll
                    focus .virtual
                    cursor_put
                 } }      

menubutton .mode -text "Screen" \
              -bg $panel_color -highlightbackground $panel_color \
              -relief flat \
              -highlightthickness 0  \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -menu .mode.menu 

# LaTeX 用 tk 部
menu .mode.menu -bg $panel_color -tearoff False
     .mode.menu add command -label "色付け" \
                            -accelerator "(Alt+L)" \
             -command { uncolorize ; set colored 1 ; colorize 1.0 end }
     .mode.menu add command -label "色付け解除" \
                            -accelerator "(Alt+N)" \
                            -command { set colored 0 ; uncolorize }
     .mode.menu add command \
                   -label "(保存して)ispell によるスペルチェック" \
                            -accelerator "(Alt+I)" \
                            -command spellcheck
     .mode.menu add command -label "しおりをはさむ／参照する" \
                            -accelerator "(Alt+B)" \
                            -command bookmark_popup

frame  .replace -bg $panel_color -relief flat -bd 0

#button .replace.label -text " Search/Replace:" \
#              -bg $panel_color -highlightbackground $panel_color \
#              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
#              -highlightthickness 0 -relief flat -padx 0 \
#              -command search_popup

menubutton .replace.label -text " Search/Replace:" \
              -bg $panel_color -highlightbackground $panel_color \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -highlightthickness 0 -relief flat -padx 0 \
              -menu .replace.label.menu

menu .replace.label.menu -bg $panel_color -tearoff False
     .replace.label.menu add command -label "前方検索" \
                            -accelerator "(/)" \
                            -command search_forward

     .replace.label.menu add command -label "後方検索" \
                            -accelerator "(?)" \
                            -command replace_backward

     .replace.label.menu add command -label "sed による置換" \
                            -accelerator "(Alt+R)" \
                            -command replace_popup


label .replace.direction -text "  " \
              -bg $panel_color -highlightbackground $panel_color \
              -highlightthickness 0 -relief flat -padx 1 -pady 1 

#label .replace.direction -text "↓" \
#              -bg $panel_color -highlightbackground $panel_color \
#              -highlightthickness 0 -relief raised -padx 1 -pady 1 

entry .replace.search -width 20 -textvariable navi_search \
               -highlightbackground $panel_color -relief sunken  \
               -highlightthickness 0 \
               -bg $panel_color \
               -fg $fore_color \
               -state disabled

label .pattern_not_found -width 20 \
               -highlightbackground $fore_color -relief flat  \
               -highlightthickness 0 \
               -padx 0 -pady 0 \
               -bg $fore_color -fg $back_color \
               -text {[Pattern not found]}

pack \
       .replace.label \
       .replace.search \
       .replace.direction \
               -side left -pady 0 -padx 1

menubutton .conf -text "Misc" \
              -bg $panel_color -highlightbackground $panel_color \
              -relief flat \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -highlightthickness 0 \
              -menu .conf.menu 

menu .conf.menu -bg $panel_color -tearoff False
     .conf.menu add command -label "コンパイルコマンド・コンパイルファイルの変更" \
                            -command change_compile_command

     .conf.menu add command -label "コンパイルログの閲覧" \
                            -command show_compile_log

     .conf.menu add command -label "Tab による補完機能のオンオフ" \
                            -command change_complement

     .conf.menu add command -label "タイプミスチェック機能のオンオフ" \
                            -command change_latex_check

button .exit -text "終了" -command "exit" \
              -bg $panel_color -highlightbackground $panel_color \
              -relief flat \
              -highlightthickness 0 


label .cursor_blank  -text "    "  \
              -bg $panel_color -highlightbackground $panel_color 
entry .cursor_x -width 6 -textvariable cursor_now_x \
              -state disabled \
              -bg $panel_color -highlightbackground $panel_color
label .cursor_x_label  -text "column:"  \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -bg $panel_color -highlightbackground $panel_color
entry .cursor_y -width 6 -textvariable cursor_now_y \
              -state disabled \
              -bg $panel_color -highlightbackground $panel_color
label .cursor_y_label  -text "line:" \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -bg $panel_color -highlightbackground $panel_color




# 下側のナビゲーション行
frame .navi -bg $panel_color -bd 0
entry .navi.main -width 35 -textvariable navi_main \
               -highlightbackground $panel_color -relief sunken \
               -highlightthickness 0 \
               -bg $back_color \
               -fg $fore_color \
               -state disabled
entry .navi.edit  -width 20  -relief sunken -textvariable navi_edit \
              -highlightthickness 0 \
              -bg $back_color \
              -fg $fore_color \
              -state disabled
label .navi.edit_label  -text "   Edit:" \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -bg $panel_color -highlightbackground $panel_color
entry .navi.buffer -width 15 -relief sunken \
                     -textvariable buffer_text \
                     -highlightthickness 0 \
                     -fg $fore_color \
                     -bg $back_color \
                     -state disabled
label  .navi.blank_buffer -bg $panel_color -text " "

button .navi.buffer_label  -text "Buffer:" \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -bg $panel_color -highlightbackground $panel_color \
              -highlightthickness 0 -padx 0 -pady 0 -relief flat \
              -command  "buffer_popup"


menu .navi.buffer_label.menu -bg $panel_color -tearoff False
     .navi.buffer_label.menu add command -label "最新バッファ" \
                            -command toplevel_yanked_text 

pack \
         .navi.main \
         .navi.edit_label \
         .navi.edit \
         .navi.blank_buffer \
         .navi.buffer_label \
         .navi.buffer \
             -pady 3  -side left 

pack .load .mode .conf .replace \
         -in .topmenu  -side left -pady 0 -padx 0

pack \
    .cursor_x \
    .cursor_x_label \
    .cursor_y \
    .cursor_y_label \
     -in .topmenu  -side right -pady 0 -padx 0



pack .topmenu -side top -fill x

frame .menubuttons -bg $panel_color -bd 1 -relief raised 

image create photo img_blank -width 30 -height 30 
image create photo img_open  -height 30 -width 30
image create photo img_save -height 30 -width 30
image create photo img_colon -height 30 -width 30
image create photo img_coloff -height 30 -width 30
image create photo img_equation -height 30 -width 30
image create photo img_spell -height 30 -width 30
image create photo img_xdvi -height 30 -width 30
image create photo img_compile -height 30 -width 50
image create photo img_print -height 30 -width 30 
image create photo img_help -height 30 -width 30
image create photo img_ghost -height 30 -width 30
image create photo img_bookmark -height 30 -width 30
image create photo img_terminal -height 30 -width 30
image create photo img_digest -height 30 -width 30

button .menubuttons_open -padx 0 -pady 0 -image img_open \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0  \
              -command { set new_or_insert 0 ; openfile }

button .menubuttons_save -padx 0 -pady 0 -image img_save \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0  -command savefile

button .menubuttons_colon -padx 2 -pady 5 -image img_colon \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 \
              -command { uncolorize ; set colored 1 ; colorize 1.0 end }

button .menubuttons_coloff -padx 2 -pady 5 -image img_coloff \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 \
              -command { set colored 0 ; uncolorize }

button .menubuttons_spell -padx 2 -pady 5 -image img_spell \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command spellcheck

button .menubuttons_equation -padx 2 -pady 5 -image img_equation \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command equation_panel_onoff

button .menubuttons_xdvi -padx 2 -pady 5 -image img_xdvi \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command xdvi_popup

button .menubuttons_digest -padx 2 -pady 5 -image img_digest \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command digest_popup

button .menubuttons_compile -padx 2 -pady 5 -image img_compile \
              -relief raised -bd 2 -bg $panel_color  \
              -font -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-* \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command compiling

button .menubuttons_print -padx 2 -pady 5 -image img_print \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command print_window

button .menubuttons_help -padx 2 -pady 5 -image img_help \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command help_popup

button .menubuttons_view -padx 2 -pady 5 -image img_blank \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command wysiwyg

button .menubuttons_command -padx 2 -pady 5 -image img_blank \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command wysiwyg

button .menubuttons_bookmark -padx 2 -pady 5 -image img_bookmark \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command bookmark_popup

button .menubuttons_terminal -padx 2 -pady 5 -image img_terminal \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command terminal_popup

button .menubuttons_ghost -padx 2 -pady 5 -image img_ghost \
              -relief raised -bd 2 -bg $panel_color  \
              -highlightcolor $panel_color \
              -highlightthickness 0 -command ghostview_popup

label  .menubuttons_blank1 -padx 0 -pady 0 -text " " \
              -bd 0 -bg $panel_color  
label  .menubuttons_blank2 -padx 0 -pady 0 -text "  " \
              -bd 0 -bg $panel_color  
label  .menubuttons_blank3 -padx 0 -pady 0 -text "  " \
              -bd 0 -bg $panel_color  
label  .menubuttons_blank4 -padx 0 -pady 0 -text "  " \
              -bd 0 -bg $panel_color  
label  .menubuttons_blank5 -padx 0 -pady 0 -text " " \
              -bd 0 -bg $panel_color  

# バルーンを出すための処理群
proc baloon { w comment } {
    bind $w <Enter>  { baloon_start %W }
    bind $w <Leave>  { baloon_end %W } 
    bind $w <Button-1>  { baloon_end %W } 
    label ${w}baloon -text $comment -bg #ffffff \
                  -highlightthickness 1 -highlightbackground #000000
    lower ${w}baloon
}

proc baloon_start { w } {
    global baloon_flag baloon_now id_after
    set baloon_now $w
    set baloon_flag 1
    set id_after [ after 1000 { baloon_raise } ]
}

proc baloon_raise { } {
    global baloon_flag baloon_now
    if {[string compare $baloon_now ".menubuttons_help"] == 0 } {
    # ヘルプのときには位置を変える
       set x [ expr [winfo pointerx . ] - [winfo x . ] -100 ]
       set y [ expr [winfo pointery . ] - [winfo y . ] +5  ]
    } elseif {[string compare $baloon_now ".menubuttons_print"] == 0 } {
    # プリントのときにも位置を変える
       set x [ expr [winfo pointerx . ] - [winfo x . ] -130 ]
       set y [ expr [winfo pointery . ] - [winfo y . ] +20  ]
    } elseif {[string compare $baloon_now ".menubuttons_digest"]== 0 } {
    # ダイジェストウィンドウのときにも位置を変える
       set x [ expr [winfo pointerx . ] - [winfo x . ] -70 ]
       set y [ expr [winfo pointery . ] - [winfo y . ] +20  ]
    } else {
       set x [ expr [winfo pointerx . ] - [winfo x . ] +0 ]
       set y [ expr [winfo pointery . ] - [winfo y . ] +20 ]
    }
    place ${baloon_now}baloon -x $x -y $y
    lower ${baloon_now}baloon
    if { $baloon_flag == 1 } {
        raise ${baloon_now}baloon
    }
}

proc baloon_end { w } {
    global baloon_flag baloon_now id_after
    set baloon_flag 0
    after cancel $id_after ; # after もキャンセル
    lower ${baloon_now}baloon
}

# バルーンの手続き
baloon  .menubuttons_open     "ファイルを開く(e:\[Space\])" 
baloon  .menubuttons_save     "名前を指定してファイルを保存する(:w\[Space\])" 
baloon  .menubuttons_colon    "色付け(Alt+L)" 
baloon  .menubuttons_coloff   "色付け解除(Alt+N)" 
baloon  .menubuttons_equation "数式パネルを開く／閉じる(Alt+M)" 
baloon  .menubuttons_spell    "(保存して)ispell によるスペルチェック(Alt+I)" 
baloon  .menubuttons_compile  "(保存して)コンパイル(Alt+C)" 
baloon  .menubuttons_xdvi     "xdviの起動(Alt+X)" 
baloon  .menubuttons_digest   "ダイジェストウィンドウの起動(Alt+D)" 
baloon  .menubuttons_ghost    "ghostviewの起動(Alt+G)" 
baloon  .menubuttons_print    "プリント(dvi -> ps | lpr)(Alt+P)" 
baloon  .menubuttons_help     "ヘルプ(Alt+H)" 
baloon  .menubuttons_bookmark "しおりをはさむ／参照する(Alt+B)" 
baloon  .menubuttons_terminal "端末を開く(Alt+T)" 

pack \
     .menubuttons_blank1 \
     .menubuttons_open \
     .menubuttons_save \
     .menubuttons_terminal \
     .menubuttons_blank2 \
     .menubuttons_colon \
     .menubuttons_coloff \
     .menubuttons_spell \
     .menubuttons_bookmark \
     .menubuttons_blank3 \
     .menubuttons_compile \
     .menubuttons_blank4 \
     .menubuttons_xdvi \
     .menubuttons_print \
       -in .menubuttons \
       -side left -padx 0 -pady 4

#     .menubuttons_digest \
#     .menubuttons_equation 
#     .menubuttons_blank4 \

pack \
     .menubuttons_blank5 \
     .menubuttons_help \
       -in .menubuttons \
       -side right -padx 0 -pady 0

pack .menubuttons -side top -fill x 


#  スペルチェック用
text .spell_text
entry .spell_tmp 

menu .ispell -tearoff False
.ispell add command -label "この回だけOK" \
            -command ispell_current_ok
.ispell add separator
.ispell add command -label "同じ単語はすべてOK" \
            -command ispell_same_word_ok
.ispell add separator
.ispell add command -label "すべての単語がOK(チェックをすべて外す)" \
            -command ispell_all_ok
.ispell add separator
.ispell add command \
            -label "個人辞書に登録して同じ単語のチェックも外す" \
            -command ispell_regist_dic_following_ok
.ispell add separator
.ispell add command \
            -label "個人辞書に登録するが同じ単語のチェックは外さない" \
            -command ispell_regist_dic
.ispell add separator
.ispell add command -label "キャンセル" 
.ispell add separator
    
#############################
# 全体の packing
#############################

pack .text_linenumber -padx 0  -side left  -fill y  -in .textandline 

pack \
         .text \
         -padx 0  -side right  -fill both  -in .textandline -expand 1 


pack \
         .textandline \
         -padx 0  -side left  -fill both  -in .textandyscroll -expand 1

pack \
         .yscroll \
             -padx 0  -side right -fill y -in .textandyscroll 


pack .textandyscroll -expand 1 -fill both

pack .xscroll -side top -fill x

pack .navi -side top 

label .cursor -text " " \
              -bd 0 -bg $fore_color -fg $back_color \
              -highlightthickness 0 -relief flat -padx 0 -pady 0 

# ウィンドウの大きさを変えることを許す
wm minsize . 76 3
wm maxsize . 1000 1000
wm geometry . ${columns}x${lines}

# ウィンドウの geometry の設定
set results [catch { set geo $geometry }]
if {$results ==0} {
    wm geometry . $geometry
}

####################
# 置換のウィンドウ #
####################
toplevel .replace_window
wm withdraw .replace_window
wm transient .replace_window .

frame .replace_window.1 
label .replace_window.1.label1 -text "範囲："
entry .replace_window.1.entry1 -textvariable replace_from -width 13
label .replace_window.1.label2 -text "行〜"
entry .replace_window.1.entry2 -textvariable replace_to   -width 13
label .replace_window.1.label3 -text "行"

pack .replace_window.1.label1 \
     .replace_window.1.entry1 \
     .replace_window.1.label2 \
     .replace_window.1.entry2 \
     .replace_window.1.label3 \
          -side left 

label .replace_window.label1 -text "sed コマンド："
label .replace_window.label2 -text "(s/検索文字列/置換文字列/g など)"
text  .replace_window.text -height 5 -width 40 -wrap none 
.replace_window.text insert 1.0 "s///g"

frame .replace_window.go  -relief groove -bd 3
button .replace_window.go.1 -text "    実行    " \
               -command do_replace
button .replace_window.go.2 -text "   閉じる   " \
               -command "wm withdraw .replace_window"
pack .replace_window.go.1 \
     .replace_window.go.2 \
               -side left -padx 18 -pady 5

# 全体の packing
pack .replace_window.1     -side top -pady 3
pack .replace_window.label1 -side top -anchor w -pady 0
pack .replace_window.label2 -side top -anchor w -pady 0
pack .replace_window.text  -side top -anchor w -fill x -pady 0

pack \
     .replace_window.go \
           -side top -anchor w -fill x 

####################################################
# ダイジェストウィンドウ
####################################################
toplevel .digest
wm title .digest "Digest Window"
wm withdraw .digest
frame .digest.textandyscroll
text  .digest.text -height 18 -width 70 -wrap none \
           -xscrollcommand { .digest.xscroll set } \
           -yscrollcommand { .digest.yscroll set } \
           -spacing1 0 -setgrid 1 \
           -highlightthickness 0
.digest.text configure -cursor top_left_arrow
scrollbar .digest.xscroll \
         -command { .digest.text xview } -width 10 \
         -orient horizontal 
scrollbar .digest.yscroll \
         -command { .digest.text yview } -width 14 

pack .digest.text -side left -fill both \
             -in .digest.textandyscroll -expand 1
pack .digest.yscroll -side right -fill y \
             -in .digest.textandyscroll -padx 0
pack .digest.textandyscroll -side top -fill both -expand 1
pack .digest.xscroll -side bottom -fill x
text .digest.aux -width 0 -height 0

####################################################
# タグの設定
####################################################

.text tag configure ref      -relief raised -borderwidth 1

eval .text tag configure defun    $defun_conf
eval .text tag configure define   $define_conf
eval .text tag configure decl     $decl_conf
eval .text tag configure label    $label_conf
#.text tag configure formula  -foreground ForestGreen -background $back_color
eval .text tag configure include  $include_conf
eval .text tag configure crossref $crossref_conf
eval .text tag configure special  $special_conf
eval .text tag configure keyword  $keyword_conf
eval .text tag configure section  $section_conf
eval .text tag configure comment  $comment_conf
eval .text tag configure latex_error $latex_error_conf

# スペルチェック用
#.text tag configure bad_spell -background red -foreground $fore_color

# 挿入カーソル用
.text tag configure cur -background $fore_color \
                        -foreground $back_color  

# カットアンドペースト用
.text tag configure cut_and_paste -background $panel_color \
                                  -foreground $fore_color

# inserted_text 用
.text tag configure inserted_text_tag \
                 -background red -foreground $back_color

# 括弧のチェック用
.text tag configure brace -background $fore_color \
                          -foreground $back_color

# セレクションをカーソルのすぐ下に
.text tag lower sel cur
