#frontend.tcl
# Copyright (c) 2001-2004 Digi International Inc., All Rights Reserved
# 
# This software contains proprietary and confidential information of Digi
# International Inc.  By accepting transfer of this copy, Recipient agrees
# to retain this software in confidence, to prevent disclosure to others,
# and to make no use of this software other than that for which it was
# delivered.  This is an unpublished copyrighted work of Digi International
# Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
# prohibited.
# 
# Restricted Rights Legend
#
# Use, duplication, or disclosure by the Government is subject to
# restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
# Technical Data and Computer Software clause at DFARS 252.227-7031 or
# subparagraphs (c)(1) and (2) of the Commercial Computer Software -
# Restricted Rights at 48 CFR 52.227-19, as applicable.
#
# Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
#
# ***************************************************************************

namespace eval ::dg::fe {}
proc ::dg::fe::onMouse {intX intY {action {}} } {
    bind . <ButtonRelease-1> {}
    bind . <Motion> {::dg::fe::onMouse %x %y}
    if { $action != "leaving" } {
        . configure -cursor {}
    }
    if { $intX > 370 && $intX < 520 && $intY > 27 && $intY < 151 } {
        #Setup
        bind . <ButtonRelease-1> $::run($::dg::strOS,setup)
        . configure -cursor $::hand
    } elseif { $intX > 78 && $intX < 153 && $intY > 149 && $intY < 249 } {
        #Software
        bind . <ButtonRelease-1> [list ::dg::install::ListDialog .]
        . configure -cursor $::hand
    } elseif { $intX > 132 && $intX < 224 && $intY > 253 && $intY < 353 } {
        #Docs
        bind . <ButtonRelease-1> [list ::dg::browser::ViewFile $::support(docs)]
        . configure -cursor $::hand
    } elseif { $intX > 260 && $intX < 338 && $intY > 298 && $intY < 398 } {
        #Support
        bind . <ButtonRelease-1> [list ::dg::browser::ViewUrl $::support(support)]
        . configure -cursor $::hand
    } elseif { $intX > 409 && $intX < 483 && $intY > 273 && $intY < 376 } {
        #Register
        bind . <ButtonRelease-1> [list ::dg::browser::ViewUrl $::support(register)]
        . configure -cursor $::hand
    } elseif { $intX > 419 && $intX < 602 && $intY > 409 && $intY < 436 } {
        #digi.com
        bind . <ButtonRelease-1> [list ::dg::browser::ViewUrl $::support(digihome)]
        . configure -cursor $::hand
    } elseif { $intX > 27 && $intX < 121 && $intY > 19 && $intY < 95 } {
        #digi.com
        bind . <ButtonRelease-1> [list ::dg::browser::ViewUrl $::support(digihome)]
        . configure -cursor $::hand
    } elseif { $intX > 25 && $intX < 51 && $intY > 420 && $intY < 434 } {
        #Exit
        bind . <ButtonRelease-1> {exit 0}
        . configure -cursor $::hand
    } else {
        set strCoord Nothing
    }
}

proc ::dg::fe::FEMain {} {
    set dirImages [file join $dg::dirRoot frontend specific images $dg::strImgLang]
    image create photo imgBG -format ppm -file [file join $dirImages frontend.ppm]
    
    wm title . [mc title]
    wm resizable . 0 0
    set intWidth 630
    set intHeight 452
    set intX 0
    set intY 0
    bind . <Escape> {exit 0}
    bind . <Control-F1> ::dg::fe::myconsole
    canvas .body -width $intWidth -height $intHeight
    .body create image [expr $intWidth / 2] [expr $intHeight /2] -image imgBG
    pack .body
    pack propagate .body false
    ::window::center .
    
    if {$::support(boolAutolaunch)} {
        ## Cascade
        catch {set intX [winfo x .]}
        catch {set intY [winfo y .]}
        set intCascadeX [expr $intX - 60]
        if {$intCascadeX < 0} {set intCascadeX 0}
        set intCascadeY [expr $intY - 60]
        if {$intCascadeY < 0} {set intCascadeY 0}
        catch {wm geometry . +$intCascadeX+$intCascadeY} 
    }
    focus -force .
    
    bind . <Motion> {::dg::fe::onMouse %x %x}
    ## The very first Motion reports the wrong y coordinate, so 
    ## we "prime" the bind routine with an event generate
    event generate . <Motion> -x 0 -y 0
    
    if {$::support(boolAutolaunch)} {
        eval $::run($::dg::strOS,setup)
    }
    tkwait window .
}

proc ::dg::fe::myconsole {} {
    if {[string equal $::tcl_platform(platform) "windows"]} {
        console show
    } else {
        toplevel .con   
        ::console .con.c
        pack .con.c -fill both -expand 1 
    }
}
