# tclfile -*- TCL -*- Created: ramsan Oct-1995, Modified: ramsan Apr-1996

# 	$Id: tclfile-opengl,v 1.71 2003/10/17 16:46:21 escolano Exp $	


#source "/soft1/ajuba/TclPro1.4.1/linux-ix86/bin/prodebug.tcl"

#debugger_init

set GIDDEFAULT $env(GIDDEFAULT)
set GIDDEFAULTTCL $GIDDEFAULT
catch { set GIDDEFAULTTCL $env(GIDDEFAULTTCL) }

#----------------------Configuration section-----------------------------

# configuration is now in a separated file

source [file join $GIDDEFAULTTCL ConfigureProgram.tcl]

#----------------------End configuration section-------------------------



if { $GIDDEFAULT == "" } {
    puts [_ " (in tclfile) to run 'gid is necessary to set the environment variable: GIDDEFAULT to the path of the executables"]
    destroy .
}

set winole 0
catch { set winole [ gidolewin]}
if { $winole == "0" } {
    toplevel .gid
} else {
    toplevel .gid -use $winole
}
wm withdraw .

if { [info exists GidPriv(SplashWindow)] && [IsSplashWindowOnInDefaults] } {
    toplevel .splash
    set im [image create photo -file $GidPriv(SplashWindow)]
    set x [expr [winfo screenwidth .splash]/2-[image width $im]/2]
    set y [expr [winfo screenheight .splash]/2-[image height $im]/2]
    
    wm withdraw .gid
    wm geom .splash +$x+$y
    wm transient .splash .gid
    wm overrideredirect .splash 1
    pack [label .splash.l -image $im -relief ridge -bd 2]
    bind .splash <1> "destroy .splash"
    #raise .splash .gid
    #grab .splash
    #after 1000
    after 2000 "if { [ winfo exist .splash] } { 
	destroy .splash
    }"
}

# until here splash
###puts SetOptions
SetOptions

#set tcl_interactive 0
set tk_strictMotif 0
# precision in floating point operations
set tcl_precision 17


#source $GIDDEFAULTTCL/init.tcl
#set auto_path "$GIDDEFAULTTCL"

#source $GIDDEFAULTTCL/tk.tcl
#source $GIDDEFAULTTCL/GrDataMenus
###puts SetAllMenusVariables
SetAllMenusVariables

# this is to avoid send commands
tk appname gid
#catch { rename send "" }

wm protocol .gid WM_DELETE_WINDOW {.gid.central.s process escape escape escape \
	escape quit}
ChangeWindowTitle UNNAMED
#wm title . GID

if { $AlterNativeConfFile != "" && $AlterNativeConfFile != "NONE" } {
    if { [file readable $AlterNativeConfFile] } {
	ReadDefaultValues $AlterNativeConfFile
    } else {
	after idle [list tk_dialogRAM "" [_ "Error window"] \
			[_ "Window configuration file not found"] \
			error 0 [_ "OK"]]
    }
}
###puts ReadDefaultValues
if { $AlterNativeConfFile != "NONE" } {
    ReadDefaultValues [GiveGidDefaultsFile]
} 
ReadDefaultValues [GiveBestGidDefaults]

SetGUIAppearanceColor

wm minsize .gid 1 1

set aa "exec xprop -root | grep SERVER_OVERLAY_VISUAL | grep -v CUT_BUFFER"

if { $tcl_platform(os) != "SunOS" } { 
    set overlay_flag 1
} else {
    set overlay_flag 0
}

if { $overlay_flag && ![catch { eval $aa } bb] } {
    regexp {.*=[ ]*([^ ,]+).*} $bb trash GidPriv(SERVER_OVERLAY_VISUALS)
    option add *OverlayWindowN*Visual $GidPriv(SERVER_OVERLAY_VISUALS)
} else { set GidPriv(SERVER_OVERLAY_VISUALS) ""}

#proc grab { args } { }


#option add *Menu*overlay true
###puts "frame .gid.phantom"
frame .gid.phantom -class OverlayWindowN

if { [winfo cells .gid.phantom] < 6 } {
    option add *Menu*selectColor black
    option add *Menu*disabledForeground white
} else {
    option add *Menu*disabledForeground grey60 
}
#destroy .phantom

#frame .phantom

menu .gid.phantom.display3dbutton -tearoff no

###puts Create3rdButtonMenu
Create3rdButtonMenu .gid.phantom.display3dbutton
if { $tcl_platform(platform) != "windows" } {
    wm colormapwindows .gid .gid.phantom
}

###puts WmGidGeom

WmGidGeom .gid $MainWindowGeom
#wm deiconify .gid
#wm withdraw .gid

if { [winfo exists .splash] } { 
  wm deiconify .gid
  raise .splash .gid 
}
#wm geometry . $MainWindowGeom
###puts "update idletasks"
update idletasks
#wm withdraw .
###puts "frame .gid.central"
if { $tcl_platform(platform) != "windows" } {
    frame .gid.central
} else {
    frame .gid.central -relief sunken -bd 2
}

set extra_flags ""

if { $tcl_platform(platform) == "windows" } {
    if { ![info exists GidPriv(SoftwareOpenGL)] } {
	set GidPriv(SoftwareOpenGL) 0
    }

    if { [ info exist OpenGLConfig] } {
	wm withdraw .gid

	set UseLocalOpenGL $GidPriv(SoftwareOpenGL)

	toplevel .softogl -class OverlayWindow
	set sx [ winfo screenwidth .]
	set sy [ winfo screenheight .]
	wm geometry .softogl +[ expr ( $sx - 300) / 2]+[ expr ( $sy - 200) / 2]

	frame .softogl.f -bd 2 -relief groove
	radiobutton .softogl.f.rd1 \
	    -text [_ "Yes I'm confident about my Graphic Card and want to use its capabilities at my own risk."] \
	    -value 0 -variable UseLocalOpenGL -justify left -wraplength 180
	radiobutton .softogl.f.rd2 \
	    -text [_ "Yes I'm experiencing troubles with my Graphic Card and want to use a Software OpenGL."] \
	    -value 1 -variable UseLocalOpenGL -justify left -wraplength 180

	button .softogl.b1 -text Ok -bd 1 -command {
	    if { $GidPriv(SoftwareOpenGL) != $UseLocalOpenGL} {
		set GidPriv(SoftwareOpenGL) $UseLocalOpenGL
		if { $GidPriv(SoftwareOpenGL)} {
		    WarnWin [_ "Changing to software rendering."]
		} else {
		    WarnWin [_ "Changing to accelerated OpenGL."]
		}
	    }
	    destroy .softogl
	}
	button .softogl.b2 -text Cancel -bd 1 -command "destroy .softogl"
	
	grid .softogl.f.rd1 -sticky news -padx 4 -pady 2
	grid .softogl.f.rd2 -sticky news -padx 4 -pady 2
	grid .softogl.f -sticky news -padx 4 -pady 2 -columnspan 2
	grid columnconfigure .softogl.f 0 -weight 1
	grid rowconfigure .softogl.f 0 -weight 1
	grid rowconfigure .softogl.f 1 -weight 1
	
	grid .softogl.b1 .softogl.b2 -pady 4 -sticky s
	grid columnconfigure .softogl 0 -weight 1
	grid columnconfigure .softogl 1 -weight 1
	grid rowconfigure .softogl 0 -weight 1
	grid rowconfigure .softogl 1 -weight 1

	tkwait window .softogl
	wm deiconify .gid
	raise .gid
    }

    if { $GidPriv(SoftwareOpenGL)} {
	set extra_flags "-softrender true"
    }
}

###puts togl
#-alpha true -> aunque sea lo correcto en windows con algunos drivers "no certificados"
#da problemas al hacer el c.fill
if { [catch { \
	eval [ subst "togl .gid.central.s -rgba true -alpha false -double true   \
	-depth true -ident GID -privatecmap false -overlay $overlay_flag $extra_flags" ]}]} {
    eval [ subst "togl .gid.central.s -rgba true -alpha false -double true  \
	    -depth true -ident GID -privatecmap false -overlay 0 $extra_flags"]
}

if { [.gid.central.s disable windows] } {
  wm withdraw .gid
} else {
  wm deiconify .gid
}


# . conf -cursor "@$GIDDEFAULT/bitmaps/gid_mini red"
###puts bindings
bind .gid.central.s <1> { 
    focus -force .gid.comm.e
    set GidPriv(PressingButton1) 1
    .gid.central.s button 1 %x %y
    after 300 [list catch {  unset GidPriv(PressingButton1) } ]
}
bind .gid.central.s <ButtonRelease-1> {
    if { [info exists GidPriv(PressingButton1)] } {
	.gid.central.s button -r -f 1 %x %y 
	break
    }
    .gid.central.s button -r 1 %x %y 
}
bind .gid.central.s <2> { .gid.central.s button 2 %x %y }
##### to handle mouse wheel
if { $GidPriv(GiDRuedas)} {
    proc MouseWheelEventToButtonEvent { increment } {
	if { $increment > 0 } {
	    .gid.central.s button 4 $increment 0
	} else {
	    .gid.central.s button 5 $increment 0
	}
    }
    catch {
	bind .gid.central.s <4> { .gid.central.s button 4 %x %y }
	bind .gid.central.s <5> { .gid.central.s button 5 %x %y }
    }
    bind .gid <MouseWheel> { MouseWheelEventToButtonEvent %D }
}
bind .gid.central.s <Motion> { .gid.central.s motion %x %y }
bind .gid.central.s <Leave> { .gid.central.s leave %x %y }
bind .gid.central.s <Enter> { .gid.central.s enter %x %y }
bind .gid <Unmap> "UnMapAllWindows %W"
bind .gid <Map> "MapAllWindows %W"
bind .gid <Control-a> SelectJoinOrNoJoin

set mxbutwidth 5 ; set PostButStack ""

bind .gid.central.s <3> {
    #%W gidmakecurrent
    set x [expr [winfo rootx .gid.central.s]+%x+2]
    set y [expr [winfo rooty .gid.central.s]+%y]
    catch {
	tk_popup .gid.phantom.display3dbutton $x $y 0
    }
}

#bind .gid.central.s <Control-ButtonRelease-1> "ContextualEntity::Activate %W %x %y; break"
bind .gid.central.s <Control-ButtonPress-1> "ContextualEntity::Activate %W %x %y; break"



bind Listbox <4> {
    %W yview scroll -3 units
}

bind Listbox <5> {
    %W yview scroll 3 units
}

bind Text <4> {
    %W yview scroll -3 units
}

bind Text <5> {
    %W yview scroll 3 units
}

pack .gid.central.s -fill both -expand yes -side left
pack .gid.central -fill both -expand yes


set WarnLineVar ""
set ActionsMenuVar ""
set ActionsMenuVarType "INTERP"
set EntryVar ""
set EntryVarHilit ""

proc ChangeWarnLineVar { val } {
    global WarnLineVar uparrow vecToUseInVectors
    if { [string index $val 0] == "\r" } {
	set WarnLineVar "[.gid.comm.fwarn.list get end] [string range $val 1 end]"
	.gid.comm.fwarn.list del end
    } else {
	set WarnLineVar $val
    }
    .gid.comm.fwarn.list insert end $WarnLineVar
    set uparrow [.gid.comm.fwarn.list size]
    .gid.comm.fwarn.list yview [expr $uparrow-2]
    if { [info exist vecToUseInVectors] } { GetVarVecs $val }
}

proc procTraceVar { name elm op } {
    global uparrow vecToUseInVectors
    upvar $name x
    #puts "value for $name is $x"

    if { $name ==  "ActionsMenuVar" } { 
	SetButtons
    }
    if { $name ==  "WarnLineVar" } {
	.gid.comm.fwarn.list insert end $x
	set uparrow [.gid.comm.fwarn.list size]
	.gid.comm.fwarn.list yview [expr $uparrow-2]
	if { [info exist vecToUseInVectors] } { GetVarVecs $x }
    }
    if { $name ==  "EntryVar"} { .gid.comm.e delete 0 end ; .gid.comm.e insert 0 $x }
    if { $name ==  "EntryVarHilit" } { .gid.comm.e select from 0 ; .gid.comm.e select to end }
}
trace variable ActionsMenuVar w procTraceVar
trace variable EntryVar w procTraceVar
trace variable EntryVarHilit w procTraceVar

#wm geometry . $MainWindowGeom

#wm deiconify .

#update idletasks
###puts "OpenOutsideWindows PRE"
OpenOutsideWindows PRE
###puts CreateIcon
CreateIcon

#image create photo gidquestionhead -data {
#    R0lGODlhKAAoAKUAA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wFXEiAcElrGCDg840EYDbJC4QAMe
#    xFDGERfocMAdBdywAQI5HinllFRWaeWVWB4RBAA7
#}

image create photo gidquestionhead -data {
    R0lGODlhKAAoAPcAAAAAAP///+/vpu/vp+7upu3tpubmpeXlpd/fpO7use3tsNjYoe3tsdfX
    odPTn8jImcbGmMPDl8DAlb6+lLOzja+vi6ysiamph6ysiqmpiJmZfYqKc4aGcIODbnh4Zmtr
    XGdnWl1dU1BQSVNTTFJSS01NR0REQEJCPkdHQ0ZGQj4+Ozs7Ojg4N8/Pz8XFxcTExMPDw7Cw
    sK+vr62traenp6amppubm5mZmY+Pj46OjoyMjIODg4KCgnd3d3Z2dnV1dXFxcWpqamhoaGRk
    ZGJiYl5eXl1dXVxcXFtbW1VVVVRUVFNTU1JSUlFRUUxMTEtLS0pKSklJSUhISEdHR0ZGRkRE
    REJCQkFBQT8/Pzw8PDs7Ozo6Ojk5OTg4ODMzMzIyMjExMTAwMC8vLy4uLi0tLSwsLCsrKykp
    KSgoKCcnJyYmJiUlJSQkJCIiIiEhISAgIBsbGxoaGhgYGBUVFRQUFBMTExISEhERERAQEA4O
    Dg0NDQgICAcHBwYGBgUFBQQEBP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAA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Pvyzjz37PPPQL8cEAA7
}

if { [lindex [.gid.central.s info Project] 8] == "debug" } {

    bind .gid <Control-x><Control-d> DebugMesherPost
    bind .gid <Control-x><Control-l> { auto_reset }

}
bind all <Triple-Button-1> {grab release [grab current .gid] }

#it is used in tkfbox and by RamDebugger in package mode
if { $::tcl_platform(platform) eq "windows" } {
    load [file join $::GIDDEFAULT tclreg11.dll] registry
}

# OLE commands in windows
if { [info command olednd] != "" } {
    olednd bindtarget .gid FileName <Drop> "LoadFileInGid"
}

if { $tcl_platform(platform) == "windows" && $GidPriv(Configuration) == "debug" } {
    catch {
	# enter here the path where you have installed RamDebugger, subdirectory addons
	# for example: c:\Program files\RamDebugger\addons
	lappend auto_path {C:\TclTk\RamDebugger3.1\addons}
	package require commR
	comm::register gid 1
    }
    bind all <F12> {
	# enter here the path where you have installed RamDebugger
	# for example: c:\Program files\RamDebugger
	lappend auto_path {C:\TclTk\RamDebugger3.1}
	lappend auto_path {E:\Programas\ActiveTcl8.4.1.0\lib} {E:\Programas\ActiveTcl8.4.1.0\lib\tcl8.4}
	package require RamDebugger
    }
}

# this func is to precalculate the problemtypes names t0 speed up the first menu check
catch {
    FastCacheFromProblemtypeMenu
}

#-----------------------------------------------Debug funcs---------------------------------

proc PrimitiveConsole {} {
    catch { destroy .gid.tt }
    toplevel .gid.tt
    pack [text .gid.tt.t]
    bind .gid.tt.t <Return> {
	set func [%W get "[%W index current] linestart" "[%W index current] lineend"]
	%W insert end \n[eval $func]
    }
}

proc SearchMenus { { w . } {init 1} } {
    global GidPriv
    if { $init } {
	set GidPriv(pp) ""
    }
    catch {
	set kk [$w cget -postcommand]
	if { [regexp {[a-zA-z]+} $kk] } {
	    append GidPriv(pp) "$w ---$kk---\n"
	}
    }
    foreach i [winfo children $w] {
	SearchMenus $i 0
    }
    if { $init } {
	return $GidPriv(pp)
    }
}

proc CheckPostCommands { {w . } } {

    catch {
	set cc [$w cget -postcommand]
	$w conf -postcommand "WarnWinText $w--$cc; $cc"
    }
    foreach i [winfo children $w] {
	CheckPostCommands $i
    }
}

#bind .gid <Control-x><Control-d> PrimitiveConsole


#---------------------------------------------------------------------------

# toplevel .ddd
# pack [button .ddd.b -text Try... -command LoadEventsFile] 
# pack [label .ddd.l -width 100] -fill x -expand yes
# pack [button .ddd.b2 -text cont -command "set GidPriv(eventtry) 1"]

set GidPriv(NoCoordEvents) "<Unmap> <FocusIn> <FocusOut> <Destroy>"
set GidPriv(DetailEvents) "<Enter> <Leave> <FocusIn> <FocusOut>"
set GidPriv(StupidEvents) "<Configure> <Map> <Unmap> <Motion> <Enter> <Leave>"

proc LoadEventsFile {} {
    global GidPriv
    set fileid [open event-list.txt-save r]

    rename grab grab-old
    proc grab { args } { }

    while { ![eof $fileid] } {
	set aa [gets $fileid]
	if { [string index $aa 0] != "<" } { continue }

	set seq [lindex $aa 0]

	if { $seq == "<Map>" || $seq == "<Configure>"} { continue }
#	if { $seq == "<Enter>" || $seq == "<Leave>"} { continue }
	if { [lindex $aa 1] == "" } { break }

	set what "event generate [lindex $aa 1] [lindex $aa 0]"
	
	if { [lindex $aa 2] != "??" && \
		[lsearch $GidPriv(NoCoordEvents) $seq] == -1 } {
	    append what " -x [lindex $aa 2]"
	}
	if { [lindex $aa 3] != "??" && \
		[lsearch $GidPriv(NoCoordEvents) $seq] == -1  } {
	    append what " -y [lindex $aa 3]"
	}
	if { [lindex $aa 4] != "??" && [lindex $aa 4] > 3 } {
	    update
	    focus [lindex $aa 1]
	    append what " -keycode [lindex $aa 4]"
	}
	if { [lindex $aa 5] != "??"  && \
		[lsearch $GidPriv(DetailEvents) *$seq*] != -1 } {
	    append what " -detail  [lindex $aa 5]"
	}
	if { [lindex $aa 6] != "??" && \
		[lsearch $GidPriv(DetailEvents) *$seq*] != -1  } {
	    append what " -mode  [lindex $aa 6]"
	}
	if { [lindex $aa 7] != "??" && \
		[lsearch $GidPriv(NoCoordEvents) $seq] == -1} {
	    append what " -rootx [lindex $aa 7]"
	}
	if { [lindex $aa 8] != "??" && \
		[lsearch $GidPriv(NoCoordEvents) $seq] == -1 } {
	    append what " -rooty [lindex $aa 8]"
	}
	.ddd.l conf -text $what
	update
	if { [lsearch $GidPriv(StupidEvents) $seq] == -1 } {
	    after 1000 
	}
	eval $what
    }
    close $fileid

    rename grab ""
    rename grab-old grab
}


proc SetBindingsForMouse1 { cmd x y } {

    eval .gid.central.s process $cmd
    .gid.central.s button 1 $x $y
    set ::savecmd [bind .gid.central.s <ButtonRelease-1>]
    
    bind .gid.central.s <ButtonRelease-1> {
	.gid.central.s button -r 1 %x %y 
	.gid.central.s process escape
	bind .gid.central.s <ButtonRelease-1> $::savecmd
	break
    }
}

foreach "mod cmd" [list Alt DynamicPan Shift "zoom dynamic" Alt-Shift "rotate trackball"] {
    bind .gid.central.s <$mod-ButtonPress-1> "[list SetBindingsForMouse1 $cmd %x %y] ; break"
}


if { [info exists GidPriv(ChangeButtonMeaning)] && $GidPriv(ChangeButtonMeaning)} {

    bind .gid.central.s <2> {
	.gid.central.s process zoom dynamic
	.gid.central.s button 1 %x %y
    }
    bind .gid.central.s <ButtonRelease-2> {
	.gid.central.s button -r 1 %x %y 
	.gid.central.s process escape
	
    }
    bind .gid.central.s <3> {
	.gid.central.s process DynamicPan
	.gid.central.s button 1 %x %y
    }
    bind .gid.central.s <ButtonRelease-3> {
	.gid.central.s button -r 1 %x %y 
	.gid.central.s process escape
    }
    
}
###puts "update idletasks"
###update idletasks
###puts fin
#ramsan
#proc .central.s { args } {
#    return [eval [concat .gid.central.s $args]]
#}

# to avoid printing anything
return
