#!/bin/sh
#
# ident "@(#)utxmessage.tcl	1.1 04/10/03 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# \
exec /usr/bin/wish "$0" "$@" #& exit

#
# A simple replacement for xmessage that does internationalization.
# Args are:
#	-title   "Window Title"
#	-message "The message you want to display to the user"
#	-buttons "label1:value1 label2:value2 ..."
#
# The -buttons argument allows you to specify multiple buttons that
# appear on the bottom of the window. It is a single argument that
# has space spearated items. Each item is a name and a return value
# separated by a colon ':'.
#

# default vars
set title {}
set message {}
set buttonSpec [list Dismiss:0]

# parse incoming args
set ix 0
while { $ix < $argc } {
	set a [lindex $argv $ix]
	switch -- "$a" {
		-title   { incr ix ; set title [lindex $argv $ix] }
		-message { incr ix ; set message [lindex $argv $ix] }
		-buttons { incr ix ; set buttonSpec [lindex $argv $ix] }
		default  {
			puts "[exec gettext "Error: arguments not recognized:"] $a"
			exit -1
		}
	}
	incr ix
}

# Validate buttonSpec
foreach item $buttonSpec {
	if {[llength [split $item ":"]] != 2} {
		puts "[exec gettext {Error: Invalid Button Specification:}] $item"
		exit -1
	}
}

proc setOptions {} {
	# Change the default Tk look
	option add *borderWidth 1 widgetDefault
	option add *activeBorderWidth 1 widgetDefault
	option add *selectBorderWidth 1 widgetDefault

	option add *padX 2
	option add *padY 4

	option add *Listbox.background white
	option add *Listbox.selectBorderWidth 0
	option add *Listbox.selectForeground white
	option add *Listbox.selectBackground #4a6984

	option add *Entry.background white
	option add *Entry.foreground black
	option add *Entry.selectBorderWidth 0
	option add *Entry.selectForeground white
	option add *Entry.selectBackground #4a6984

	option add *Text.selectBorderWidth 0
	option add *Text.selectForeground white
	option add *Text.selectBackground #4a6984

	option add *Menu.activeBackground #4a6984
	option add *Menu.activeForeground white
	option add *Menu.activeBorderWidth 0
	option add *Menu.highlightThickness 0
	option add *Menu.borderWidth 2

	option add *MenuButton.activeBackground #4a6984
	option add *MenuButton.activeForeground white
	option add *MenuButton.activeBorderWidth 0
	option add *MenuButton.highlightThickness 0
	option add *MenuButton.borderWidth 0

	option add *highlightThickness 0
	option add *troughColor #bdb6ad
}

proc layoutUI {} {
	global title
	global message
	global buttonSpec

	wm title . $title
	wm minsize . 150 100

	frame .top
	frame .sep -relief sunken -height 2 -bd 1
	frame .bottom

	set screenwidth [winfo screenwidth .]
	label .top.msg -text $message -justify left  -wraplength [expr $screenwidth * 0.8]
	pack .top.msg -in .top -expand 1 -fill x -pady 10

	frame .bottom.buttonBox
	foreach item $buttonSpec {
		set butt [lindex [split $item ":"] 0]
		set retVal [lindex [split $item ":"] 1]
		button .bottom.buttonBox.butt$butt -text $butt -command " exit $retVal "
		pack .bottom.buttonBox.butt$butt -side left -padx 10 -pady 4
	}

	pack .bottom.buttonBox

	pack .bottom -side bottom -anchor s -fill x
	pack .sep -side bottom -anchor s -fill x
	pack .top -side bottom -anchor nw -expand 1 -fill both
}

setOptions
layoutUI
