#!/usr/bin/wish8.4
#
# window configure
. configure -background #facd8a
#. configure -cursor bottom_tee
font create largefont -family Helvetica -size 14 -weight normal
font create smallfont -family Helvetica -size 12 -weight normal
font create smallerfont -family Helvetica -size 10 -weight normal
. configure -padx 15 -pady 15
foreach class { Button Checkbutton Entry Label Listbox Menu Menubutton \
	Message Radiobutton Scale MessageBox Text Dialog.msg } { \
        option add *$class.font smallfont widgetDefault }
#
# frame backcolor
set frcolor #D4E7B2
# entry backcolor
set entrycolor #606060
set textcolor white
# button color
set buttoncolor1 #f5ba5c
set buttoncolor2 #f6b28f
set buttoncolor3 #909090
set javabutt #00b1ae
set buttforecolor1 #ffffff
set buttforecolor2 #000000
set editbutt #c0c0c0
# this is the HTML table background color
set tablecolor #bedfc4
#this is the HTML page background color
set pagecolor "rgb(225, 225, 225)"
# .............................................format variables
set entrywidth 11
set buttonwidth 6
set smallbuttonwidth 4
set bigbuttonwidth 8
set buttonheight 1
set padding 2
set framepad 5
#
set initialdir [pwd]
set lastindex 1.0
set indxa 1.0
set indxb "$indxa + 1 char"
# .............................................frames.....
frame .textframe \
	-padx $framepad -pady $framepad\
	-relief groove \
	-borderwidth 3 \
	-background $frcolor
frame .textframe.menubar \
	-padx 2 -pady 2\
	-relief groove \
	-borderwidth 3 \
	-background #c0c0c0
# ..............................................file menu items ..................
menubutton .textframe.menubar.file -text "file" -menu .textframe.menubar.file.menu\
	-background #c0c0c0\
	-relief groove\
	-borderwidth 3 \
	-font smallfont
menu .textframe.menubar.file.menu
.textframe.menubar.file.menu add command -label "Open..."\
	-font smallfont \
 	-command {
	global initialdir;
	set initialdir [pwd];
	set file_types { \
 		{ "HTML Files" { .html .HTML .htm .HTM } } \
		{ "Text Files" { .txt .TXT .dat .DAT } } \
		{ "Tcl Files" { .tcl .TCL .tk .TK } } \
		{ "awk Files" { .awk .AWK } } \
		{ "doc Files" { .doc .DOC } } \
		};
	set infilename [tk_getOpenFile \
		-initialdir $initialdir \
		-filetypes $file_types \
		-initialfile $infilename \
		-parent .textframe.maintextbox];
	set lastindex 1.0;
	set outputfile $infilename;
	set fileid [open $infilename r];
	global fileid;
	set inscratch [read $fileid];
	close $fileid;
	.textframe.maintextbox delete @1,0 end;
	.textframe.maintextbox insert end $inscratch;	
	}
.textframe.menubar.file.menu add command -label "Save as..."\
	-font smallfont \
	-command {
	.textframe.maintextbox mark set beginmark 1.0;
	cd $initialdir;
	set initialdir [pwd];
	set file_types { \
		{ "HTML Files" { .html .HTML .htm .HTM } } \
		{ "Text Files" { .txt .TXT .dat .DAT } } \
 		{ "Tcl Files" { .tcl .TCL .tk .TK } } \
		{ "awk Files" { .awk .AWK } } \
		};
	set outputfile [tk_getSaveFile \
	-initialdir $initialdir \
	-filetypes $file_types \
	-initialfile $outputfile \
	-parent .textframe.maintextbox];
	set newchannel [open $outputfile w+];
	set stufftowrite [.textframe.maintextbox get 1.0 {end -1c} ];
	puts $newchannel [.textframe.maintextbox get beginmark end];
	close $newchannel;
	}
#
.textframe.menubar.file.menu add command -label "Clear"\
	-font smallfont \
	 -command {
	.textframe.maintextbox mark set beginmark2 1.0;
	set lastindex 1.0;
	set clearanswer [tk_messageBox -icon question -message "Clear Text Window?" \
	-parent .textframe.maintextbox \
	-title "Are you sure?" -type yesno];
	if {$clearanswer ==yes} then {
	.textframe.maintextbox delete beginmark2 end
	}
	}

.textframe.menubar.file.menu add command -label "Exit"\
	-font smallfont \
	 -command {
	set exitanswer [tk_messageBox -icon question -message "are you sure?" \
	-parent .textframe.maintextbox \
	-title "Exit?" -type yesno];
	if {$exitanswer ==yes} then { clipboard clear;
	exit}
}

# ..............................................tag menu items ..................
menubutton .textframe.menubar.tag -text "html" -menu .textframe.menubar.tag.menu\
	-background $editbutt\
	-relief groove\
	-borderwidth 3 \
	-font smallfont
menu .textframe.menubar.tag.menu\
	-background $entrycolor \
	-foreground $textcolor 
#
.textframe.menubar.tag.menu add command -label "html"\
	-font smallfont \
 	-command {
	.textframe.maintextbox insert sel.first \
	"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
	 \"http://www.w3.org/TR/html4/loose.dtd\">\n\
	<html>\n\
	<head>\n\
	<title>PageName</title>\n\
	<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=iso-8859-1\">\n\
	<META NAME=\"GENERATOR\" CONTENT=\"Htags written by magicme\">\n\
	<META NAME=\"AUTHOR\" CONTENT=\"magicme\">\n\
	<META NAME=\"KEYWORDS\" CONTENT=\"mynotes\">\n\
	<META NAME=\"robots\" CONTENT=\"noindex, nofollow, noarchive\">\n\n\
	</head>\n\n\
	<BODY style=\"background-color: $pagecolor ; color: rgb(0, 0, 200);\">\n";
	.textframe.maintextbox insert sel.last \
	"</body>\n\n\
	</html>\n" }
#
#
.textframe.menubar.tag.menu add command -label "style(1)"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<style type=\"text/css\">\n\
	p {font-family: \"Arial\",\"Helvetica\", sans-serif;font-size:100%;line-height:125%;}\n\
	li {font-family: \"Arial\",\"Helvetica\", sans-serif;font-size:100%;line-height:125%;}\n\
 	h2 {font-family: \"Arial\",\"Helvetica\", sans-serif;font-size:135%;line-height:100%;}\n\
 	h3 {font-family: \"Arial\",\"Helvetica\", sans-serif;font-size:125%;line-height:100%;}\n\
 	h4 {font-family: \"Arial\",\"Helvetica\", sans-serif;font-size:115%;line-height:100%;}\n\
	</style>\n"\
	}

#
.textframe.menubar.tag.menu add command -label "style(2)"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<style type=\"text/css\">\n\
	p {font-family: \"Comic Sans MS\", sans-serif;font-size:120%;line-height:125%;}\n\
	li {font-family: \"Comic Sans MS\", sans-serif;font-size:120%;line-height:125%;}\n\
 	h2 {font-family: \"Comic Sans MS\", sans-serif;font-size:145%;line-height:100%;}\n\
 	h3 {font-family: \"Comic Sans MS\", sans-serif;font-size:135%;line-height:100%;}\n\
 	h4 {font-family: \"Comic Sans MS\", sans-serif;font-size:125%;line-height:100%;}\n\
	</style>\n"\
	}
#
.textframe.menubar.tag.menu add command -label "Heading(2)"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<h2>";
	.textframe.maintextbox insert sel.last "</h2>";
	}
#

.textframe.menubar.tag.menu add command -label "Heading(3)"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<h3>";
	.textframe.maintextbox insert sel.last "</h3>";
	}
#
.textframe.menubar.tag.menu add command -label "Heading(4)"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<h4>";
	.textframe.maintextbox insert sel.last "</h4>";
	}
#
.textframe.menubar.tag.menu add command -label "paragraph"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<p>";
	.textframe.maintextbox insert sel.last "</p>";
	}
#
.textframe.menubar.tag.menu add command -label "list"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<ul>";
	.textframe.maintextbox insert sel.last "</ul>";
	}
#
.textframe.menubar.tag.menu add command -label "list item"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<li>";
	.textframe.maintextbox insert sel.last "</li>";
	}
#
.textframe.menubar.tag.menu add separator
#
.textframe.menubar.tag.menu add command -label "blackfont"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<FONT color=\"black\"> \n";
	.textframe.maintextbox insert sel.last "</font>";
	}
#
.textframe.menubar.tag.menu add command -label "redfont"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<FONT color=\"red\"> \n";
	.textframe.maintextbox insert sel.last "</font>";
	}
#
.textframe.menubar.tag.menu add command -label "bluefont"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<FONT color=\"blue\"> \n";
	.textframe.maintextbox insert sel.last "</font>";
	}
#
.textframe.menubar.tag.menu add command -label "greenfont"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<FONT color=\"green\"> \n";
	.textframe.maintextbox insert sel.last "</font>";
	}
#
.textframe.menubar.tag.menu add command -label "bold"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<b>";
	.textframe.maintextbox insert sel.last "</b>";
	}
#
.textframe.menubar.tag.menu add command -label "italic"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<i>";
	.textframe.maintextbox insert sel.last "</i>";
	}
#
.textframe.menubar.tag.menu add command -label "big"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<big>";
	.textframe.maintextbox insert sel.last "</big>";
	}
#
.textframe.menubar.tag.menu add command -label "small"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<small>";
	.textframe.maintextbox insert sel.last "</small>";
	}
#
.textframe.menubar.tag.menu add command -label "subscript"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<sub>";
	.textframe.maintextbox insert sel.last "</sub>";
	}
#
.textframe.menubar.tag.menu add command -label "superscript"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<sup>";
	.textframe.maintextbox insert sel.last "</sup>";
	}
#
.textframe.menubar.tag.menu add separator
#
.textframe.menubar.tag.menu add command -label "insert link"\
	-font smallfont \
	-command { .textframe.maintextbox insert sel.first \
	"<a href=\"filename.html\">";
	.textframe.maintextbox insert sel.last "</a>";
	}
#
.textframe.menubar.tag.menu add command -label "break"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<br> \n" }
#
.textframe.menubar.tag.menu add command -label "insert line"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<hr width=\"600\" align=\"left\" size=\"3\">\n" }
#
.textframe.menubar.tag.menu add command -label "insert anchor"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<A NAME=\"anchorname\"></A>\n" }
#
.textframe.menubar.tag.menu add command -label "insert jpg"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<img src=\"image.jpg\" width=\"600\" height=\"450\" alt=\"jpg\" ><br> \n" }
#
.textframe.menubar.tag.menu add command -label "insert png"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<img src=\"image.png\" width=\"600\" height=\"450\" alt=\"png\" ><br> \n" }
#
.textframe.menubar.tag.menu add command -label "insert gif"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"<img src=\"image.gif\" width=\"600\" height=\"450\" alt=\"gif\" ><br>  \n" }
#
.textframe.menubar.tag.menu add command -label "pagebreak"\
	-font smallfont \
	-command {.textframe.maintextbox insert "insert" \
	"\n<p style=\"page-break-before:always\"></p> \n" }
#

# ........................pop-up menu items...................
bind all <Button-3> {
	set gx [winfo rootx %W]
	set gy [winfo rooty %W]
	set mx [expr $gx + %x]
	set my [expr $gy + %y]
	tk_popup .popup1 $mx $my
}
menu .popup1
.popup1 add command -label "cut" \
	-font smallfont \
	-command {
	set owner [selection own];
	clipboard clear;
	catch {clipboard append [selection get];
	.textframe.maintextbox delete sel.first sel.last;}
	}
.popup1 add command -label "copy" \
	-font smallfont \
	-command {set owner [selection own];
	clipboard clear;
	catch {clipboard append [selection get]};
	}
.popup1 add command -label "insert paste" \
	-font smallfont \
	-command {
	catch {set clip [selection get -selection CLIPBOARD]};
	catch {set idx [.textframe.maintextbox index insert];
	.textframe.maintextbox insert $idx $clip;}
	}
.popup1 add command -label "overpaste" \
	-font smallfont \
	-command {
	.textframe.maintextbox delete sel.first sel.last;
	catch {set clip [selection get -selection CLIPBOARD]};
	catch {set idx [.textframe.maintextbox index insert];
	.textframe.maintextbox insert $idx $clip;}
	}
.popup1 add command -label "delete" \
	-font smallfont \
	-command {.textframe.maintextbox delete sel.first sel.last;}
.popup1 add command -label "color" \
	-font smallfont \
	-command {set newcolor [tk_chooseColor \
	-title "Color" \
	-parent .textframe.maintextbox];\
	.textframe.maintextbox configure -background $newcolor
	}
.popup1 add command -label "textcolor" \
	-font smallfont \
	-command {set newcolor [tk_chooseColor \
	-title "Color" \
	-parent .textframe.maintextbox];\
	.textframe.maintextbox configure -foreground $newcolor
	}
.popup1 add command -label "yellow" \
	-font smallfont \
	-command {
	set owner [selection own];
	clipboard clear;
	catch {clipboard append [selection get];
	.textframe.maintextbox tag add hitagyellow sel.first sel.last;
	.textframe.maintextbox tag configure hitagyellow -background yellow -foreground black;}
	}
.popup1 add command -label "red" \
	-font smallfont \
	-command {
	set owner [selection own];
	clipboard clear;
	catch {clipboard append [selection get];
	.textframe.maintextbox tag add hitagred sel.first sel.last;
	.textframe.maintextbox tag configure hitagred -background red -foreground white;}
	}


# .......................text frame widgets........
#
text .textframe.maintextbox \
	-state normal \
	-height 35 \
	-width 80 \
	-wrap word \
	-font smallfont \
	-background $entrycolor \
	-foreground $textcolor\
	-xscrollcommand ".textframe.h_scroll set" \
	-yscrollcommand ".textframe.v_scroll set"
#
# horizontal scrollbar 
scrollbar .textframe.h_scroll -orient horizontal \
	-command ".textframe.maintextbox xview" \
	-width 15
#
# vertical scrollbar 
scrollbar .textframe.v_scroll -orient vertical \
	-command ".textframe.maintextbox yview" \
	-width 15


#
entry .textframe.infile \
	-textvariable infilename \
	-font smallfont \
	-width 80 \
	-justify left \
	-background $entrycolor\
	-foreground $textcolor
#
entry .textframe.outfile \
	-textvariable outputfile \
	-font smallfont \
	-width 80 \
	-justify left \
	-foreground $textcolor \
	-background $entrycolor
#
#
#.........................................................grid

#
pack .textframe
pack .textframe.menubar -anchor w
pack .textframe.menubar.file -side left
pack .textframe.menubar.tag -side left
pack .textframe.infile .textframe.outfile -anchor w
pack .textframe.v_scroll -side right -fill y
pack .textframe.maintextbox -side left

focus .textframe.maintextbox 
#

















