
set page_selected2 1
set b2press1 0
set b2press2 0
set b2press3 0
set b2press4 0

proc annotate_box2 { } {

    global annotate2
    global page_selected2
    set annotate2 .annotate_box2

    if [winfo exists $annotate2] { destroy $annotate2}
    global env
    set env(DISPLAY) :0.1
    toplevel $annotate2 -width 435 -height 375
    wm title $annotate2 "Annotate"

    label $annotate2.lab38 \
        -foreground #0000ca -height 0 -relief groove -text Annotate \
        -width 408

    text $annotate2.tex36 \
        -background white -height 240 -width 388 -wrap word \
        -yscroll "$annotate2.scr44 set" -font "HALVETICA 28"

    scrollbar $annotate2.scr44 \
        -width 21 -command {$annotate2.tex36 yview}


   global bpress1 bpress2 bpress3  bpress4

    # Create the four pages button for annotate
    button $annotate2.page1 \
        -height 0 -text 1 -command { if {$b2press1 == 1} { display_page2 1  } }
    button $annotate2.page2 \
        -height 0 -text 2 -command { if {$b2press2 == 1} { display_page2 2 } }
    button $annotate2.page3 \
        -height 0 -text 3 -command { if {$b2press3 == 1} { display_page2 3 } }
    button $annotate2.page4 \
        -height 0 -text 4 -command  { if {$b2press4 == 1}  { display_page2 4 } }
    place $annotate2.page1 \
        -x 20 -y 295 -anchor nw -bordermode ignore
    place $annotate2.page2 \
        -x 60 -y 295 -anchor nw -bordermode ignore
    place $annotate2.page3 \
        -x 100 -y 295 -anchor nw -bordermode ignore
    place $annotate2.page4 \
        -x 140 -y 295 -anchor nw -bordermode ignore

    bind $annotate2.page1 <ButtonPress-1> {
    	global page_selected2  b2press1 b2press2 b2press3 b2press4
    	    	
    	if {$b2press1 == 1} {
    		set b2press1 0
    		$annotate2.page1 configure -relief raise
    	} else {
    		set b2press1 1
    		$annotate2.page1 configure -relief sunken
    	}
    	
    	$annotate2.page2 configure -relief raise
    	set b2press2 0
    	$annotate2.page3 configure -relief raise
    	set b2press3 0
    	$annotate2.page4 configure -relief raise
    	set b2press4 0
    	
    	set page_selected2 1
    }

    bind $annotate2.page2 <ButtonPress-1> {
    	global page_selected2  b2press1 b2press2 b2press3 b2press4
    	
    	if {$b2press2 == 1} {
    		set b2press2 0
    		$annotate2.page2 configure -relief raise
    	} else {
    		set b2press2 1
    		$annotate2.page2 configure -relief sunken
    	}
    	
    	$annotate2.page1 configure -relief raise
    	set b2press1 0
    	$annotate2.page3 configure -relief raise
    	set b2press3 0
    	$annotate2.page4 configure -relief raise
    	set b2press4 0       	
    	set page_selected2 2
    }

    bind $annotate2.page3 <ButtonPress-1> {
    	global page_selected2  b2press1 b2press2 b2press3 b2press4

    	if {$b2press3 == 1} {
    		set b2press3 0
    		$annotate2.page3 configure -relief raise
    	} else {
    		set b2press3 1
    		$annotate2.page3 configure -relief sunken
    	}
    	
    	$annotate2.page1 configure -relief raise
    	set b2press1 0
    	$annotate2.page2 configure -relief raise
    	set b2press2 0
    	$annotate2.page4 configure -relief raise         	
    	set b2press4 0
    	
    	set page_selected2 3
    }

    bind $annotate2.page4 <ButtonPress-1> {
	global page_selected2  b2press1 b2press2 b2press3 b2press4
	
	
    	if {$b2press4 == 1} {
    		set b2press4 0
    		$annotate2.page4 configure -relief raise
    	} else {
    		set b2press4 1
    		$annotate2.page4 configure -relief sunken
    	}
    	
    	$annotate2.page1 configure -relief raise
    	set b2press1 0
    	$annotate2.page2 configure -relief raise
    	set b2press2 0
    	$annotate2.page3 configure -relief raise
    	set b2press3 0
    	set page_selected2 4
    }




    # Clear clear the overlay screen only
    button $annotate2.clr_box \
        -text "Clear Box" -command { $annotate2.tex36 delete 1.0 [$annotate2.tex36 index end] }
        		
    # Delete clear both the textbox and the overlay screen
    # Function "clear_overlay" is implemented in "annotate_box.tcl" file
    button $annotate2.clr_overlay \
        -text "Clear Overlay" -command {clear_overlay}	

    # Close the textbox
    button $annotate2.close \
        -text Close -command {destroy $annotate2}


    # Button to Display the text in overlay
    # Function "display_annotate $screen" is implemented in file "annotate_box.tcl"
    button $annotate2.display -text "Display"  -command {display_annotate 2}

    # Save the text in the pages selected
    button $annotate2.save -text "Save" -command saving_to_page2



    ###################
    # SETTING GEOMETRY
    ###################
    place $annotate2.tex36 \
        -x 15 -y 40 -width 388 -height 240 -anchor nw -bordermode ignore
    place $annotate2.lab38 \
        -x 15 -y 10 -width 408 -height 20 -anchor nw -bordermode ignore

    place $annotate2.clr_box -x 220 -y 295
    place $annotate2.clr_overlay -x 310 -y 295
    place $annotate2.display -x 220 -y 335
    place $annotate2.save -x 295 -y 335
    place $annotate2.close -x 355 -y 335

    place $annotate2.scr44 \
        -x 400 -y 41 -width 21 -height 237 -anchor nw -bordermode ignore


}


proc display_page2 { page } {
	global annotate2
	
	$annotate2.tex36 delete 1.0 [$annotate2.tex36 index end]
	$annotate2.tex36 insert 1.0 [get_page $page]
}


proc saving_to_page2 { } {
       global annotate2 b2press1 b2press2 b2press3 b2press4
       set count [$annotate2.tex36 index end]
       set msg [$annotate2.tex36 get 1.0  $count ]
       	
       if {$b2press1 == 1} {
       	save_page 1 $msg
       	return
       }

       if {$b2press2 == 1} {
       	save_page 2 $msg
       	return
       }

       if {$b2press3 == 1} {
       	save_page 3 $msg
       	return
       }

       if {$b2press4 == 1} {
       	save_page 4 $msg
       	return
       }

}


