# Source all of the files required for using the install wizard

if [info exists blt_version] {
    set has_blt 1
} else {
    set has_blt 0
}
set has_blt 0

# It is necessary to set ::wizard_guibase or ::guibase_dir before
# executing the wizard_driver

proc wizard_find_guibase {} {
    global env
    
    set dirs ". ./guibase ../guibase"
    if [info exists env(GUIBASE_DIR)] {
	lappend dirs $env(GUIBASE_DIR)
    }
    
    if [info exists env(ICEM_ACN)] {
	lappend dirs $env(ICEM_ACN)/lib/guibase
    }
    
    foreach dir $dirs {
	if {[file isdirectory $dir] && [file exists $dir/wizard.tcl]} {
	    return $dir
	}
    }
    return ""
}

if ![info exists ::wizard_guibase] {
    if ![info exists ::guibase_dir] {
	set ::guibase_dir [wizard_find_guibase]
	if {$::guibase_dir == ""} {
	    error "GUIBASE directory not found.  Please set GUIBASE_DIR or cd \
 to that directory"
	}
    }
    set ::wizard_guibase $::guibase_dir
}

proc wizard_source_file {file} {
    global env
    
    set base [file rootname $file]
    set ext [file extension $file]
    
    # try both the .tcl and .ptcl file.  If both exist, take
    # later one.  Otherwise if only one exists, use it directly
    
    set is80 [catch {set env(USE_40)}]
    if {($ext == ".tcl" || $ext == ".ptcl") && $is80} {
	if {$ext == ".tcl"} {
	    set file2 ${base}.ptcl
	} else {
	    set file2 ${base}.tcl
	}
	if {[file exists $file] && [file exists $file2]} {
	    if {[file mtime $file2] > [file mtime $file]} {
		set file $file2
	    }
	} else {
	    if {![file exists $file] && [file exists $file2]} {
		set file $file2
	    }
	}
    }
    puts "loading $file"
    uplevel \#0 "source $file"	
}

foreach f {
    toplevel
    bltemu
    exec_cmds
    query
    misc
    fileselect
    settings
    help
    sizes
    forms
    formutil
    foptionMenu
    poll
    configfile
    my-tkerror
    wizard
} {
    wizard_source_file $::wizard_guibase/$f.tcl
}

::wizard::create_path
compute_sizes
