#!/usr/local/bin/tclsh
# Undocumented program. Don't use it.
#
# Usage:
# 
# 	tixmkpref option name.src > name.tcl
#

set fontOptions {
    font Font
}

proc option {opt args} {
    global isFont fontOptions

    set spec [lindex $args 0]
    set names [split $spec *]
    set resName [lindex $names [expr [llength $names] -1]]
    set names [split $resName .]
    set resName [lindex $names [expr [llength $names] -1]]

    if {[lsearch $fontOptions $resName] >= 0} {
	if {$isFont} {
	    puts "option add $args"
	}
    } else {
	if {$isFont == 0} {
	    puts "option add $args"
	}
    }
}

proc tixDefOption {classes specs} {
    global isFont 

    foreach class $classes {
	foreach spec $specs {
	    # Trick.
	    # Since the spec is quoated by curly brackets,
	    # they were not substituted. The uplevel command
	    # force this to be evaluted in the previous level,
	    # so that $spec can be substituted.
	    #
	    if [string match *ont* $spec] {
		if {$isFont} {
		    puts "option add *$class$spec 79"
		}
	    } else {
		uplevel 1 eval option add *$class$spec 79
	    }
	}
    }
}

proc tixInitOptionDatabase {strictTK} {
    global tixOption isFont

    # general stuff, everything gets these defaults unless otherwise specified
    #-------------------------------------------------------------------------
    if {$isFont} {
	puts {option add *Font			$tixOption(font)	79}
    	puts {option add *font			$tixOption(font)	79}
    }

    option add *background 		$tixOption(bg)		10
    option add *Background		$tixOption(bg)		79
    option add *background		$tixOption(bg)		79
    option add *Foreground		$tixOption(fg)		79
    option add *foreground		$tixOption(fg)		79
    option add *activeBackground	$tixOption(active_bg)	79
    option add *activeForeground	$tixOption(active_fg)	79
    option add *HighlightBackground	$tixOption(bg)		79
if 0 {
    option add *disabledForeground	$tixOption(disabled_fg)	79
}
    option add *anchor			w			79
    option add *selectBackground	$tixOption(select_bg)	79
    option add *selectForeground	$tixOption(select_fg)	79
    option add *selectBorderWidth	0			79


    #----------------------------------------
    # Standard TK Widget Options
    #
    # We set up the options for the TK widgets only if
    # the strictTK option is not selected.
    #----------------------------------------

    tixDefOption {Button} {
	{.borderWidth		2}
	{.buff			true}
	{.anchor		c}
    }

    tixDefOption {Checkbutton Radiobutton} {
	{.selectColor		$tixOption(selector)}
    }

    tixDefOption {Entry} {
	{.relief		sunken}
	{.highlightBacground	$tixOption(bg)}
	{.background		$tixOption(input1_bg)}
	{.foreground		black}
	{.insertBackground	black}
    }

    tixDefOption {Label} {
	{.anchor		w}
	{.borderWidth		0}
	{.font              	$tixOption(bold_font)}
    }

    tixDefOption {Listbox} {
	{.background		$tixOption(light1_bg)}
	{.relief		sunken}
    }

    tixDefOption {Menu TixMenu} {
	{*font			$tixOption(menu_font)}
	{*selectColor		$tixOption(selector)}
    }

    tixDefOption {Menubutton} {
	{*font			$tixOption(menu_font)}
    }

    tixDefOption {Scale} {
	{.foreground		$tixOption(fg)}
	{.activeForeground	$tixOption(bg)}
	{.background		$tixOption(bg)}
	{.sliderForeground	$tixOption(bg)}
	{.sliderBackground	$tixOption(light1_bg)}
	{.font			$tixOption(italic_font)}
    }

    tixDefOption {Scrollbar} {
	{.background		$tixOption(bg)}
	{.troughColor		$tixOption(light1_bg)}
	{.relief		sunken}
	{.borderWidth		1}
	{.width			15}
    }

    tixDefOption {Text} {
	{.background		$tixOption(input1_bg)}
	{.relief		sunken}
    }

    #----------------------------------------------------------------------
    # TIX WIDGETS
    #----------------------------------------------------------------------

    tixDefOption {TixBalloon} {
	{*background 			#ffff60}
	{*foreground 			black}
	{.background 			black}

    }

    tixDefOption {TixBitmapButton} {
	{*label.font 			$tixOption(font)}
    }

    tixDefOption {TixControl} {
	{*entry.highlightBacground	$tixOption(bg)}
	{*entry.background		$tixOption(input1_bg)}
	{*entry.foreground		black}
	{*entry.insertBackground	black}
	{*label.font              	$tixOption(bold_font)}
    }

    # DLG_BTNS
    #
    tixDefOption {TixStdButtonBox} {
    }

    # DIR_LIST
    #
    tixDefOption {TixDirTree} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*hlist.highlightBacground	$tixOption(bg)}
	{*hlist.background		$tixOption(light1_bg)}
    }

    tixDefOption {TixDirList} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*hlist.highlightBacground	$tixOption(bg)}
	{*hlist.background		$tixOption(light1_bg)}
    }

    tixDefOption {TixFileEntry} {
	{*Entry.background 		$tixOption(input1_bg)}
    }

    tixDefOption {TixHList} {
    }

    tixDefOption {TixLabelFrame} {
	{*label.font 	 		$tixOption(bold_font)}
    }

    tixDefOption {TixMultiList} {
	{*Listbox.borderWidth		0}
	{*Listbox.highlightThickness	0}
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*Scrollbar.relief		sunken}
	{*Scrollbar.width		15}
	{*f1.borderWidth		2}
	{*f1.relief			sunken}
	{*f1.highlightThickness		2}
    }

    # MwmClient
    #
    tixDefOption {TixMwmClient} {
	{*title.font			$tixOption(menu_font)}
    }

    tixDefOption {TixMDIMenuBar} {
	{*menubar.relief		raised}
	{*menubar.borderWidth		2}
	{*Menubutton.padY 		2}
    }

    # NoteBook
    #
    tixDefOption {TixNoteBook} {
	{.Background			$tixOption(bg)}
	{.nbframe.Background		$tixOption(bg)}
	{.nbframe.font			$tixOption(menu_font)}
	{.nbframe.backPageColor		$tixOption(bg)}
	{.nbframe.inactiveBackground	$tixOption(inactive_bg)}
    }
 
    # OPTION_MENU
    #
    tixDefOption {TixOptionMenu} {
	{*menubutton.font		$tixOption(font)}
    }

    # PANED_WINDOW
    #
    tixDefOption {TixPanedWindow} {
	{.handleActiveBg 		$tixOption(active_bg)}
	{.seperatorBg    		$tixOption(bg)}
	{.handleBg       		$tixOption(dark1_bg)}
    }

    # POPUP MENU
    #
    tixDefOption {TixPopupMenu} {
	{*menubutton.background 	$tixOption(dark1_bg)}
    }

    # SCROLLED_HLIST
    #
    tixDefOption {TixScrolledHList TixDirTree} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*hlist.highlightBacground	$tixOption(bg)}
	{*hlist.background		$tixOption(light1_bg)}
    }

    tixDefOption {TixScrolledTList} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*tlist.highlightBacground	$tixOption(bg)}
	{*tlist.background		$tixOption(light1_bg)}
    }

    # SCROLLED_LISTBOX, .. ETC
    #
    tixDefOption {TixScrolledListBox} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{*listbox.highlightBacground	$tixOption(bg)}
	{*listbox.background		$tixOption(light1_bg)}
    }

    tixDefOption {TixScrolledText} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
    }


    # SCROLLED_WINDOW
    #
    tixDefOption {TixScrolledWindow} {
	{*Scrollbar.background		$tixOption(bg)}
	{*Scrollbar.troughColor		$tixOption(light1_bg)}
	{.frame.background		$tixOption(light1_bg)}
    }


    # SELECT
    #
    tixDefOption {TixSelect} {
    }

    # NON ALPHABETICAL ORDER WIDGETS

    # Since TK's option database follows the order-of-declaration rule, not
    # specific-vs-general rule, the options of the widgets below depends on
    # the options of the widget above, so their options must be defined here

    # COMBOBOX
    tixDefOption {TixComboBox} {
	{*Entry.font				$tixOption(font)}
	{*Entry.highlightBacground		$tixOption(bg)}
	{*Entry.background			$tixOption(input1_bg)}
	{*Entry.foreground			black}
	{*Entry.insertBackground		black}
    }

    # FILE_SELECT_BOX
    #
    tixDefOption {TixFileSelectBox} {
	{*Label.font            		$tixOption(bold_font)}
    }

    tixDefOption {TixExFileSelectBox} {
    }
}

#----------------------------------------------------------------------
# The default fontset and schemes
#
#----------------------------------------------------------------------
proc tixSetFontset {} {
    global tixOption

    set tixOption(font)         -Adobe-Helvetica-Medium-R-Normal--*-120-*
    set tixOption(bold_font)    -Adobe-Helvetica-Bold-R-Normal--*-120-*
    set tixOption(menu_font)    -Adobe-Helvetica-Bold-R-Normal--*-120-*
    set tixOption(italic_font)  -Adobe-Helvetica-Bold-O-Normal--*-120-*
    set tixOption(courier_font) -*-courier-medium-r-*-*-14-*-*-*-*-*-*-*
}

proc tixSetScheme-Color {} {
    set tixOption(bg)           bisque1
    set tixOption(fg)           black

    set tixOption(dark1_bg)     bisque3
    set tixOption(dark1_fg)     black
    set tixOption(dark2_bg)     bisque4
    set tixOption(dark2_fg)     black
    set tixOption(inactive_bg)  bisque4
    set tixOption(inactive_fg)  black

    set tixOption(light1_bg)    bisque1
    set tixOption(light1_fg)    white
    set tixOption(light2_bg)    bisque1
    set tixOption(light2_fg)    white

    set tixOption(active_bg)    $tixOption(dark1_bg)
    set tixOption(active_fg)    $tixOption(fg)
    set tixOption(disabled_fg)  gray55

    set tixOption(input1_bg)    bisque2
    set tixOption(input2_bg)    bisque2
    set tixOption(output1_bg)   $tixOption(dark1_bg)
    set tixOption(output2_bg)   $tixOption(bg)

    set tixOption(select_fg)    black
    set tixOption(select_bg)    lightblue

    set tixOption(selector)	    yellow
}

proc tixSetScheme-Mono {} {

    global tixOption

    set tixOption(bg)           lightgray
    set tixOption(fg)           black

    set tixOption(dark1_bg)     gray70
    set tixOption(dark1_fg)     black
    set tixOption(dark2_bg)     gray60
    set tixOption(dark2_fg)     white
    set tixOption(inactive_bg)  lightgray
    set tixOption(inactive_fg)  black

    set tixOption(light1_bg)    gray90
    set tixOption(light1_fg)    white
    set tixOption(light2_bg)    gray95
    set tixOption(light2_fg)    white

    set tixOption(active_bg)    gray90
    set tixOption(active_fg)    $tixOption(fg)
    set tixOption(disabled_fg)  gray55

    set tixOption(input1_bg)    $tixOption(light1_bg)
    set tixOption(input2_bg)    $tixOption(light1_bg)
    set tixOption(output1_bg)   $tixOption(light1_bg)
    set tixOption(output2_bg)   $tixOption(light1_bg)

    set tixOption(select_fg)    white
    set tixOption(select_bg)    black

    set tixOption(selector)	black
}

#----------------------------------------------------------------------
# Action:
#----------------------------------------------------------------------
if [string match TK* [lindex $argv 1]] {
    set isTK 1
} else {
    set isTK 0
}
set schemeName [lindex [split [lindex $argv 1] "."] 0]
source [lindex $argv 1]

tixSetFontset

if {[lindex $argv 0] == "-font"} {

    set isFont 1

    puts "proc tixPref:SetFontSet:$schemeName {} { "
    puts "global tixOption"
    if {! $isTK} {
	tixSetScheme-Mono
	tixInitOptionDatabase 0
    }

    puts "}"

    puts "proc tixPref:InitFontSet:$schemeName {} { "
    puts [info body tixSetFontset]
    puts "}"

} else {
    set isFont 0

    # Do the Color First
    #
    puts "proc tixPref:SetScheme-Color:$schemeName {} {"
    puts [info body tixSetScheme-Mono]
    if {! $isTK} {
	tixSetScheme-Color
	tixInitOptionDatabase 0
    }
    puts [info body tixSetScheme-Mono]
    puts "}"

    # Now Do the Mono
    #
    puts "proc tixPref:SetScheme-Mono:$schemeName {} {"
    puts [info body tixSetScheme-Mono]
    if {! $isTK} {
	tixSetScheme-Mono
	tixInitOptionDatabase 0
    }
    puts "}"
}
