#
# $Log: not supported by cvs2svn $
# Revision 1.16  2006/08/10 20:23:33  soliday
# Added the contextHelpImage to display a PNG image for all the basic APS widgets.
#
# Revision 1.15  2005/09/30 19:12:51  soliday
# Fixed problem with last change.
#
# Revision 1.14  2005/09/30 18:49:24  soliday
# Fixed issue with the overview screen when the text box is wider than 40
# characters.
#
# Revision 1.13  2005/08/15 20:21:23  soliday
# Added the option to create an info windows that you can copy the text from.
#
# Revision 1.12  2001/02/06 19:44:22  soliday
# Fixed some tcl warning messages found with procheck
#
# Revision 1.11  2000/06/27 16:20:02  soliday
# Added catch statements around all the grab commands.
#
# Revision 1.10  1996/10/04 19:53:06  saunders
# Added "print", "save as..", and "email..." buttons to APSAlertBox.
# In doing so, I removed functionally duplicate procedures, and created
# generic APSPrint and APSSaveDialog. Also addes "save as.." to APSExecLog.
# Removed "Enscript" buttons, since "Print" is adequate.
#
# Revision 1.9  1996/06/06 19:43:11  borland
# Added -width option for APSInfoWindow (overrides automatic method of
# setting window width).  Added Information item to Help menu for APSApplication,
# to give host, OS, start time, and username of any application.
#
# Revision 1.8  1996/02/13  15:52:10  saunders
# APSInfoWindow uses -width option for short messages, and -aspect option
# for long ones.
#
# Revision 1.7  1996/02/06  21:34:40  saunders
# Fixed so that aspect ratio is honored.
#
# Revision 1.6  1996/01/16  21:20:04  saunders
# Added Log for CVS. Should have done this a long time ago.
#
#

proc APSInfoWindowHelp {} {
    return "Usage: APSInfoWindow widget \n\
\[-parent <string>\]\n\
\[-noPack 1\]\n\
\[-packOption <list>\]\n\
\[-name <string\]\n\
\[-infoMessage <string>\]\n\
\[-modal 1]\n\
\[-copyable 1]\n\
\[-width <chars>\]\n\
\[-contextHelp <string>\]\n\
\n\
Creates\t\$parent\$widget.\n\
\tmsg\n\
\tbuttonRow.ok.button\n"
}

proc APSInfoWindow {widget args} {
    global apsContextHelp apsttk
    set parent ""
    set noPack 0
    set packOption "-side top -fill x"
    set name "UntitledInfo"
    set infoMessage "No Info"
    set infoImage ""
    set modal 0
    set width 0
    set contextHelp ""
    set copyable 0

    APSStrictParseArguments {parent noPack packOption name infoMessage infoImage \
			       contextHelp modal width copyable}
    append name " [clock format [clock seconds] -format {%H:%M:%S}]"

    if {[info exists apsttk] && ($apsttk != 0)} {
        set ttkPrefix ttk::
    } else {
        set ttkPrefix ""
    }
    if {$contextHelp != ""} {
	set apsContextHelp($parent$widget) $contextHelp
    }

    set windowExists [winfo exists $parent$widget]
    if {$parent == ""} {
	if {$windowExists} {
	    raise $widget
	} else {
	    toplevel $widget
	    wm title $widget $name
	}
    } else {
	${ttkPrefix}frame $parent$widget
	if {!$noPack} {
	    eval pack $parent$widget $packOption
	}
    }
    if {$windowExists} {
        if {$copyable} {
            $parent$widget.msg configure -state normal
            $parent$widget.msg delete 1.0 end
            $parent$widget.msg insert end "$infoMessage"
            $parent$widget.msg configure -state disabled
        } else {
            if {[file exists $infoImage]} {
                if {![winfo exists $parent$widget.image]} {
                    ${ttkPrefix}label $parent$widget.image -image [image create photo -file $infoImage]
                    pack $parent$widget.image -before $parent$widget.msg
                } else {
                    $parent$widget.image configure -image [image create photo -file $infoImage]
                }
            } else {
                if {[winfo exists $parent$widget.image]} {
                    destroy $parent$widget.image
                }
            }
            $parent$widget.msg configure -text "$infoMessage\n                            "
        }
    } else {
        if {$copyable} {
            set rows [llength [split $infoMessage \n]]
            if {!$width} {
                if {[string length $infoMessage] < 40} {
                    text $parent$widget.msg -relief raised  -bd 2 \
			-width 40 -height $rows
                    $parent$widget.msg insert end "$infoMessage"
                    $parent$widget.msg configure -state disabled
                } else {
                    set i [string first \\n $infoMessage]
                    while {$i != -1} {
                        set infoMessage [string replace $infoMessage $i [expr $i + 1] " "]
                        set i [string first \\n $infoMessage]
                    }
                    text $parent$widget.msg -relief raised  -bd 2 -wrap word \
                      -width 60 -height [expr (2 + [string length $infoMessage] / 60)]
                    $parent$widget.msg insert end $infoMessage
                    $parent$widget.msg configure -state disabled
                }
            } else {
		if {$rows==1} {
		    set rows [expr (2 + [string length $infoMessage] / 60)]
		}
                text $parent$widget.msg -relief raised  -bd 2 \
                  -width $width -height $rows
                $parent$widget.msg insert end "$infoMessage"
                $parent$widget.msg configure -state disabled
            }
        } else {
            if {[file exists $infoImage]} {
                ${ttkPrefix}label $parent$widget.image -image [image create photo -file $infoImage]
                pack $parent$widget.image
            }
            if {!$width} {
                if {[string length $infoMessage] < 40} {
                    message $parent$widget.msg -relief raised -justify left -bd 2 \
                      -width 40c -text "$infoMessage"
                } else {
                    message $parent$widget.msg -relief raised -justify left -bd 2 \
                      -aspect 200 -text "$infoMessage"
                }
            } else {
                message $parent$widget.msg -relief raised -justify left -bd 2 \
                  -width ${width}c  -text "$infoMessage"
            }
        }

	pack $parent$widget.msg -side top -fill both -expand 1
	
	${ttkPrefix}frame $parent$widget.buttonRow -relief raised -borderwidth 2
	pack $parent$widget.buttonRow -side bottom -fill x
	
	APSButton .ok -parent $parent$widget.buttonRow -text OK \
	  -command "destroy $parent$widget" -highlight 1 -width ""
    }
    if {$modal == 1} {
        update idletasks
        catch {exec wmctrl -R $name -t -1}
	set grabList [grab current $parent$widget]
	focus $parent$widget
	catch {grab $parent$widget}
	tkwait window $parent$widget
	catch {grab set $grabList}
    }
}    

