########################################################################
#
# "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 

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 -side left -padx 18 -pady 5 
pack .replace_window.go.2 -side right -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 -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
button .digest.close -text " Ĥ " \
               -highlightbackground black  \
               -highlightthickness 1 \
               -command digest_close 
place .digest.close -relx 1.0 -rely 1.0 -x -23 -y -20 -anchor se 

####################################################
# 
####################################################

.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
