Check-in [bd19f95d99]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:many changes to make BLT stubs enabled on Win32
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bd19f95d99f457e3b8c034771ec5b24e4fea7c68
User & Date: chw 2016-11-03 05:43:30
Context
2016-11-03
05:47
add BLT to undroidwish/vanilla build scripts check-in: b345d3cbfb user: chw tags: trunk
05:43
many changes to make BLT stubs enabled on Win32 check-in: bd19f95d99 user: chw tags: trunk
05:27
add another few Xlib stubs for Win32 check-in: 862eb620a0 user: chw tags: trunk
Changes

Changes to assets/blt2.4/demos/barchart1.tcl.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

set graph .bc

proc random {{max 1.0} {min 0.0}} {
................................................................................
}

source [file join [file dirname [info script]] scripts stipples.tcl]

image create photo bgTexture -file \
    [file join [file dirname [info script]] images rain.gif]

option add *tile			bgTexture

option add *Button.tile			""

option add *Htext.tileOffset		no
option add *Htext.font			{ Times 12 }

option add *Barchart.title		"A Simple Barchart"

option add *Axis.tickFont		{ Courier 10 }
option add *Axis.titleFont		{ Helvetica 12 bold }

option add *x.Title			"X Axis Label"
option add *x.Rotate			90
option add *x.Command			FormatLabel
option add *y.Title			"Y Axis Label"

option add *Element.Background		white







<







 







|
|
|
|
|
|
|
|
|
|
|







19
20
21
22
23
24
25

26
27
28
29
30
31
32
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]

set graph .bc

proc random {{max 1.0} {min 0.0}} {
................................................................................
}

source [file join [file dirname [info script]] scripts stipples.tcl]

image create photo bgTexture -file \
    [file join [file dirname [info script]] images rain.gif]

option add *Barchart.title		"A Simple Barchart"

if {[tk windowingsystem] eq "win32"} {
    option add *Barchart.font		{Arial 12 bold}
    option add *Axis.tickFont		{{Courier New} 8}
    option add *Axis.titleFont		{Arial 10 bold}
} else {
    option add *Barchart.font		{Helvetica 12 bold}
    option add *Axis.tickFont		{Courier 8}
    option add *Axis.titleFont		{Helvetica 10 bold}
}

option add *x.Title			"X Axis Label"
option add *x.Rotate			90
option add *x.Command			FormatLabel
option add *y.Title			"Y Axis Label"

option add *Element.Background		white

Changes to assets/blt2.4/demos/barchart3.tcl.

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]
source [file join [file dirname [info script]] scripts patterns.tcl]

option add *graph.xTitle "X Axis Label"
option add *graph.yTitle "Y Axis Label"
option add *graph.title "A Simple Barchart"
option add *graph.xFont *Times-Medium-R*12*
option add *graph.elemBackground white
option add *graph.elemRelief raised

set visual [winfo screenvisual .] 
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *print.background yellow
    option add *quit.background red







<







29
30
31
32
33
34
35

36
37
38
39
40
41
42
source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]
source [file join [file dirname [info script]] scripts patterns.tcl]

option add *graph.xTitle "X Axis Label"
option add *graph.yTitle "Y Axis Label"
option add *graph.title "A Simple Barchart"

option add *graph.elemBackground white
option add *graph.elemRelief raised

set visual [winfo screenvisual .] 
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *print.background yellow
    option add *quit.background red

Changes to assets/blt2.4/demos/barchart4.tcl.

50
51
52
53
54
55
56

57



58
59
60
61
62
63
64
option add *Barchart.baseline   	57.299

option add *Element.borderWidth		2
option add *Element.Background		white
option add *Element.Relief		raised

option add *x.Title			"X Axis"

option add *x.Font			*Times-Medium-R*10*



option add *y.Title			"Y Axis"
option add *LineMarker.Foreground	yellow

set visual [winfo screenvisual .] 
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *print.background yellow
    option add *quit.background red







>
|
>
>
>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
option add *Barchart.baseline   	57.299

option add *Element.borderWidth		2
option add *Element.Background		white
option add *Element.Relief		raised

option add *x.Title			"X Axis"
if {[tk windowingsystem] eq "win32"} {
    option add *x.Font			{Arial 10}
} else {
    option add *x.Font			{Helvetica 10}
}
option add *y.Title			"Y Axis"
option add *LineMarker.Foreground	yellow

set visual [winfo screenvisual .] 
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *print.background yellow
    option add *quit.background red

Changes to assets/blt2.4/demos/graph1.tcl.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

if { [winfo screenvisual .] != "staticgray" } {
    option add *print.background yellow
    option add *quit.background red
    set image [image create photo -file \
	[file join [file dirname [info script]] images rain.gif]]
    option add *Graph.Tile $image
    option add *Label.Tile $image
    option add *Frame.Tile $image
    option add *Htext.Tile $image
    option add *TileOffset 0
}

set graph [graph .g]

source [file join [file dirname [info script]] scripts graph1.tcl]

proc MultiplexView { args } { 
    eval .g axis view y $args
    eval .g axis view y2 $args
................................................................................
proc UpdateTable { graph p1 p2 how } {
    table configure . c0 -width [$graph extents leftmargin]
    table configure . c2 -width [$graph extents rightmargin]
    table configure . r0 -height [$graph extents topmargin]
    table configure . r2 -height [$graph extents bottommargin]
}

set blt98 [file join [file dirname [info script]] images blt98.gif]
set image2 [image create photo -file $blt98]
set sharky [file join [file dirname [info script]] bitmaps sharky.xbm]
.g element configure line2 -areapattern @$sharky
# -areaforeground blue -areabackground ""
.g element configure line3 -areatile $image2
.g configure -title [pwd]







<




<
<
<
<
<
<
<
<
<
<
<
<







 







<
<



<

20
21
22
23
24
25
26

27
28
29
30












31
32
33
34
35
36
37
..
97
98
99
100
101
102
103


104
105
106

107
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]













set graph [graph .g]

source [file join [file dirname [info script]] scripts graph1.tcl]

proc MultiplexView { args } { 
    eval .g axis view y $args
    eval .g axis view y2 $args
................................................................................
proc UpdateTable { graph p1 p2 how } {
    table configure . c0 -width [$graph extents leftmargin]
    table configure . c2 -width [$graph extents rightmargin]
    table configure . r0 -height [$graph extents topmargin]
    table configure . r2 -height [$graph extents bottommargin]
}



set sharky [file join [file dirname [info script]] bitmaps sharky.xbm]
.g element configure line2 -areapattern @$sharky
# -areaforeground blue -areabackground ""

.g configure -title [pwd]

Changes to assets/blt2.4/demos/graph2.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]

if { ![string match "*gray*" [winfo screenvisual .]] } {
    option add *Button.Background	red
................................................................................
    -title "X Axis"

if 1 {
    set sharky [file join [file dirname [info script]] bitmaps sharky.xbm]

    $graph element configure line1 \
	-areapattern solid -areaforeground green
#	-areatile $image 
    $graph element configure line3 \
	-areapattern @$sharky \
	-areaforeground red \
	-areabackground "" -areapattern solid
}

set fileName testImg.jpg







<







 







<







18
19
20
21
22
23
24

25
26
27
28
29
30
31
..
69
70
71
72
73
74
75

76
77
78
79
80
81
82
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]

if { ![string match "*gray*" [winfo screenvisual .]] } {
    option add *Button.Background	red
................................................................................
    -title "X Axis"

if 1 {
    set sharky [file join [file dirname [info script]] bitmaps sharky.xbm]

    $graph element configure line1 \
	-areapattern solid -areaforeground green

    $graph element configure line3 \
	-areapattern @$sharky \
	-areaforeground red \
	-areabackground "" -areapattern solid
}

set fileName testImg.jpg

Changes to assets/blt2.4/demos/graph3.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53

54
55
56
57
58
59
60
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]

set visual [winfo screenvisual .]
if { $visual != "staticgray" && $visual != "grayscale" } {
................................................................................
    option add *PolyMarker.Outline	""
    option add *PolyMarker.Stipple	fdiagonal1
    option add *activeLine.Color	red4
    option add *activeLine.Fill		red2
    option add *Element.Color		purple
}

image create photo bgTexture -file \
    [file join [file dirname [info script]] images chalk.gif]

option add *Tile		bgTexture
option add *Button.Tile		""

option add *Text.font			-*-times-bold-r-*-*-14-*-*
option add *header.font			-*-times-medium-r-*-*-14-*-*
option add *footer.font			-*-times-medium-r-*-*-14-*-*

option add *HighlightThickness		0

set graph [graph .g]
source [file join [file dirname [info script]] scripts graph3.tcl]

text .header \
    -wrap word \







<







 







|
|
<
|
|
>
|
|
|
>







18
19
20
21
22
23
24

25
26
27
28
29
30
31
..
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]
source [file join [file dirname [info script]] scripts stipples.tcl]

set visual [winfo screenvisual .]
if { $visual != "staticgray" && $visual != "grayscale" } {
................................................................................
    option add *PolyMarker.Outline	""
    option add *PolyMarker.Stipple	fdiagonal1
    option add *activeLine.Color	red4
    option add *activeLine.Fill		red2
    option add *Element.Color		purple
}

if {[tk windowingsystem] eq "win32"} {
    option add *Text.font		{Arial bold 14}

    option add *header.font		{Arial 14}
    option add *footer.font		{Arial 14}
} else {
    option add *Text.font		{Helvetica bold 14}
    option add *header.font		{Helvetica 14}
    option add *footer.font		{Helvetica 14}
}
option add *HighlightThickness		0

set graph [graph .g]
source [file join [file dirname [info script]] scripts graph3.tcl]

text .header \
    -wrap word \

Changes to assets/blt2.4/demos/graph4.tcl.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


51








52

53
54
55
56
57
58
59
60
61
62
63
64
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

set tcl_precision 15 

set graph .graph
image create photo bgTexture -file \
    [file join [file dirname [info script]] images chalk.gif]

option add *default			normal
option add *Button.tile			bgTexture

option add *Htext.font			-*-times-bold-r-*-*-14-*-*
option add *Text.font			-*-times-bold-r-*-*-14-*-*
option add *header.font			-*-times-medium-r-*-*-14-*-*
option add *footer.font			-*-times-medium-r-*-*-14-*-*
option add *Graph.relief		raised
#option add *Graph.borderWidth		2
option add *Graph.Legend.activeBackground white
option add *Graph.height		3i
option add *Graph.plotBackground	black
option add *Graph.width			5i
option add *Graph.tile			bgTexture


option add *Graph.halo			0










option add *Graph.title			"s27.out"
option add *Graph.font			-*-helvetica-bold-r-*-*-14-*

option add *Axis.tickFont		-*-courier-medium-r-*-*-12-*
option add *Axis.titleFont		-*-helvetica-bold-r-*-*-14-*
option add *Axis.titleColor		red2
option add *x.title			"Time"
option add *y.title			"Signals"

option add *Crosshairs.Color		white

option add *activeLine.Fill		navyblue
................................................................................
option add *Grid.color			grey50
option add *Grid.dashes			"2 4"
option add *Grid.hide			no

option add *Legend.ActiveRelief		sunken
option add *Legend.Position		right
option add *Legend.Relief		flat
option add *Legend.font			-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*
option add *Legend.Pad			0
option add *Legend.hide			no

option add *LineMarker.Dashes		5
option add *LineMarker.Foreground	white
option add *zoomOutline.outline		yellow








<




<
<

<
<


<

<
<
<
<



|

|
|
>
>
|
>
>
>
>
>
>
>
>
|
>

<

<
<







 







<







19
20
21
22
23
24
25

26
27
28
29


30


31
32

33




34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55


56
57
58
59
60
61
62
..
72
73
74
75
76
77
78

79
80
81
82
83
84
85
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]



set graph .graph



option add *default			normal






option add *Graph.relief		raised
#option add *Graph.borderWidth		2
option add *Graph.Legend.activeBackground white
option add *Graph.height		500
option add *Graph.plotBackground	black
option add *Graph.width			800
option add *Graph.halo			0

if {[tk windowingsystem] eq "win32"} {
    option add *Graph.font		{Arial 12 bold}
    option add *Axis.tickFont		{{Courier New} 8}
    option add *Axis.titleFont		{Arial 10 bold}
    option add *Legend.font		{Arial 10}
} else {
    option add *Graph.font		{Helvetica 12 bold}
    option add *Axis.tickFont		{Courier 8}
    option add *Axis.titleFont		{Helvetica 10 bold}
    option add *Legend.font		{Helvetica 10}
}

option add *Graph.title			"s27.out"




option add *Axis.titleColor		red2
option add *x.title			"Time"
option add *y.title			"Signals"

option add *Crosshairs.Color		white

option add *activeLine.Fill		navyblue
................................................................................
option add *Grid.color			grey50
option add *Grid.dashes			"2 4"
option add *Grid.hide			no

option add *Legend.ActiveRelief		sunken
option add *Legend.Position		right
option add *Legend.Relief		flat

option add *Legend.Pad			0
option add *Legend.hide			no

option add *LineMarker.Dashes		5
option add *LineMarker.Foreground	white
option add *zoomOutline.outline		yellow

Changes to assets/blt2.4/demos/graph5.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35





36
37
38

39
40
41
42
43
44
45
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    #namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

option add *Element.ScaleSymbols	true
option add *Axis.loose			true
option add *Pixels			.2c
option add *Element.lineWidth		0
option add *Legend.ActiveRelief		raised
option add *Legend.padY			0





option add *Button*Font			{ Courier 10 } widgetDefault
option add *Legend*Font			{ Courier 10 bold } widgetDefault
option add *Graph.Font			{ Courier 12 bold } widgetDefault

option add *Graph.title			"Element Symbol Types"
option add *Graph.width			5i
option add *Graph.height		3.5i
option add *Graph.plotPadY		.1i
option add *Graph.plotPadX		.1i

set graph .graph







<










>
>
>
>
>
|
|
|
>







18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]

option add *Element.ScaleSymbols	true
option add *Axis.loose			true
option add *Pixels			.2c
option add *Element.lineWidth		0
option add *Legend.ActiveRelief		raised
option add *Legend.padY			0
if {[tk windowingsystem] eq "win32"} {
    option add *Button*Font		{{Courier New} 10}
    option add *Legend*Font		{{Courier New} 10 bold}
    option add *Graph.Font		{{Courier New} 12 bold}
} else {
    option add *Button*Font		{Courier 10}
    option add *Legend*Font		{Courier 10 bold}
    option add *Graph.Font		{Courier 12 bold}
}
option add *Graph.title			"Element Symbol Types"
option add *Graph.width			5i
option add *Graph.height		3.5i
option add *Graph.plotPadY		.1i
option add *Graph.plotPadX		.1i

set graph .graph

Changes to assets/blt2.4/demos/graph6.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
70
71
72
73
74
75
76

77



78
79
80
81
82
83
84
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

set tcl_precision 15 

set graph .graph
................................................................................
option add *activeLine.Color		green1

#option add *Legend.Hide		yes
option add *Legend.Position		right
option add *Legend.Relief		flat
option add *Legend.activeRelief		sunken
option add *Legend.borderWidth		2

option add *Legend.Font		-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*



option add *Grid.hide			no
option add *Grid.dashes			"1 5"

#option add *foreground white
option add *zoomOutline.outline		yellow

graph .graph







<







 







>
|
>
>
>







18
19
20
21
22
23
24

25
26
27
28
29
30
31
..
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]

set tcl_precision 15 

set graph .graph
................................................................................
option add *activeLine.Color		green1

#option add *Legend.Hide		yes
option add *Legend.Position		right
option add *Legend.Relief		flat
option add *Legend.activeRelief		sunken
option add *Legend.borderWidth		2
if {[tk windowingsystem] eq "win32"} {
    option add *Legend.Font		{Arial 10}
} else {
    option add *Legend.Font		{Helvetica 10}
}
option add *Grid.hide			no
option add *Grid.dashes			"1 5"

#option add *foreground white
option add *zoomOutline.outline		yellow

graph .graph

Changes to assets/blt2.4/demos/graph7.tcl.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

image create photo bgTexture -file \
    [file join [file dirname [info script]] images buckskin.gif]

option add *Graph.Tile			bgTexture
option add *Label.Tile			bgTexture
option add *Frame.Tile			bgTexture
option add *Htext.Tile			bgTexture
option add *TileOffset			0
option add *HighlightThickness		0
option add *Element.ScaleSymbols	no
option add *Element.Smooth		linear
option add *activeLine.Color		yellow4
option add *activeLine.Fill		yellow
option add *activeLine.LineWidth	0
option add *Element.Pixels		3







<




<
<
<
<
<
<
<
<







23
24
25
26
27
28
29

30
31
32
33








34
35
36
37
38
39
40
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------

if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]









option add *HighlightThickness		0
option add *Element.ScaleSymbols	no
option add *Element.Smooth		linear
option add *activeLine.Color		yellow4
option add *activeLine.Fill		yellow
option add *activeLine.LineWidth	0
option add *Element.Pixels		3

Changes to assets/blt2.4/demos/spline.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

option add *graph.Element.ScaleSymbols true

# test to show spline over-shooting







<







18
19
20
21
22
23
24

25
26
27
28
29
30
31
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]

option add *graph.Element.ScaleSymbols true

# test to show spline over-shooting

Changes to assets/blt2.4/demos/stripchart1.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
306
307
308
309
310
311
312
313
314



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*
    namespace import -force blt::tile::*
}

source [file join [file dirname [info script]] scripts demo.tcl]

# ----------------------------------------------------------------------
#  EXAMPLE: simple driver for stripchart widget
# ----------------------------------------------------------------------
................................................................................
    }
    #$wv notify now
    if { [$xv length] > 100 } {
	$xv delete 0
	$yv delete 0
	$wv delete 0
    }
    update
    set win $sources($name-controls)



    set delay [$win.rate get]
    set sources($name-stream) [after $delay [list source_event $name $delay]]
}

# ----------------------------------------------------------------------
frame .mbar -borderwidth 2 -relief raised
pack .mbar -fill x

menubutton .mbar.main -text "Main" -menu .mbar.main.m
pack .mbar.main -side left -padx 4
menu .mbar.main.m
#.mbar.main.m add command -label "Add Source..." -command {
#    set x [expr [winfo rootx .]+50]
#    set y [expr [winfo rooty .]+50]
#    wm geometry .addSource +$x+$y
#    wm deiconify .addSource
#}
#.mbar.main.m add separator







<







 







|

>
>
>










|







18
19
20
21
22
23
24

25
26
27
28
29
30
31
...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#    namespace import blt::*
#    graph .g
#    table . .g -resize both
#
# --------------------------------------------------------------------------
if { $tcl_version >= 8.0 } {
    namespace import blt::*

}

source [file join [file dirname [info script]] scripts demo.tcl]

# ----------------------------------------------------------------------
#  EXAMPLE: simple driver for stripchart widget
# ----------------------------------------------------------------------
................................................................................
    }
    #$wv notify now
    if { [$xv length] > 100 } {
	$xv delete 0
	$yv delete 0
	$wv delete 0
    }
    if {[catch {update}]} return
    set win $sources($name-controls)
    if {[catch {winfo exists $win.rate} here] || !$here} {
	return
    }
    set delay [$win.rate get]
    set sources($name-stream) [after $delay [list source_event $name $delay]]
}

# ----------------------------------------------------------------------
frame .mbar -borderwidth 2 -relief raised
pack .mbar -fill x

menubutton .mbar.main -text "Main" -menu .mbar.main.m
pack .mbar.main -side left -padx 4
menu .mbar.main.m -tearoff 0
#.mbar.main.m add command -label "Add Source..." -command {
#    set x [expr [winfo rootx .]+50]
#    set y [expr [winfo rooty .]+50]
#    wm geometry .addSource +$x+$y
#    wm deiconify .addSource
#}
#.mbar.main.m add separator

Changes to assets/blt2.4/graph.tcl.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280





281
282
283
284
285
286
287
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495

496


497
498
499
500
501
502

	blt::AddBindTag $graph crosshairs-$graph
    } elseif { $state == "off" } {
	blt::RemoveBindTag $graph crosshairs-$graph
    }
}

proc blt::InitStack { graph } {
    global zoomInfo
    set zoomInfo($graph,interval) 100
    set zoomInfo($graph,afterId) 0
    set zoomInfo($graph,A,x) {}
    set zoomInfo($graph,A,y) {}
    set zoomInfo($graph,B,x) {}
    set zoomInfo($graph,B,y) {}
    set zoomInfo($graph,stack) {}
    set zoomInfo($graph,corner) A
}

proc blt::ZoomStack { graph {start "ButtonPress-1"} {reset "ButtonPress-3"} } {
    global zoomInfo zoomMod
    
    blt::InitStack $graph
    
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
	set modifier ""
    }
    bind zoom-$graph <${modifier}${start}> { blt::SetZoomPoint %W %x %y }
    bind zoom-$graph <${modifier}${reset}> { 
	if { [%W inside %x %y] } { 
	    blt::ResetZoom %W 
................................................................................
	after 200 blt::FlashPoint $graph $name $index $count
    } else {
	eval $graph marker delete [$graph marker names "bltClosest_*"]
    }
}

proc blt::GetCoords { graph x y index } {
    global zoomInfo
    if { [$graph cget -invertxy] } {
	set zoomInfo($graph,$index,x) $y
	set zoomInfo($graph,$index,y) $x
    } else {
	set zoomInfo($graph,$index,x) $x
	set zoomInfo($graph,$index,y) $y
    }
}

proc blt::MarkPoint { graph index } {
    global zoomInfo
    set x [$graph xaxis invtransform $zoomInfo($graph,$index,x)]
    set y [$graph yaxis invtransform $zoomInfo($graph,$index,y)]
    set marker "zoomText_$index"
    set text [format "x=%.4g\ny=%.4g" $x $y] 

    if [$graph marker exists $marker] {
     	$graph marker configure $marker -coords { $x $y } -text $text 
    } else {
    	$graph marker create text -coords { $x $y } -name $marker \
	    -text $text -anchor center -bg {} -justify left
    }
}

proc blt::DestroyZoomTitle { graph } {
    global zoomInfo

    if { $zoomInfo($graph,corner) == "A" } {
	catch { $graph marker delete "zoomTitle" }
    }
}

proc blt::PopZoom { graph } {
    global zoomInfo

    set zoomStack $zoomInfo($graph,stack)
    if { [llength $zoomStack] > 0 } {
	set cmd [lindex $zoomStack 0]
	set zoomInfo($graph,stack) [lrange $zoomStack 1 end]
	eval $cmd
	blt::ZoomTitleLast $graph
	if {[catch {busy hold $graph}]} {
	    update idletasks
	} else {
	    update
	    busy release $graph
................................................................................
	catch { $graph marker delete "zoomTitle" }
    }
}

# Push the old axis limits on the stack and set the new ones

proc blt::PushZoom { graph } {
    global zoomInfo
    eval $graph marker delete [$graph marker names "zoom*"]
    if { [info exists zoomInfo($graph,afterId)] } {
	after cancel $zoomInfo($graph,afterId)
    }
    set x1 $zoomInfo($graph,A,x)
    set y1 $zoomInfo($graph,A,y)
    set x2 $zoomInfo($graph,B,x)
    set y2 $zoomInfo($graph,B,y)

    if { ($x1 == $x2) || ($y1 == $y2) } { 
	# No delta, revert to start
	return
    }
    set cmd {}
    foreach margin { xaxis yaxis x2axis y2axis } {
................................................................................
	foreach axis [$graph $margin use] {
	    set min [$graph axis cget $axis -min] 
	    set max [$graph axis cget $axis -max]
	    set c [list $graph axis configure $axis -min $min -max $max]
	    append cmd "$c\n"
	}
    }
    set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]


    foreach margin { xaxis x2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis invtransform $axis $x1]
	    set max [$graph axis invtransform $axis $x2]
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
	    } else {
		$graph axis configure $axis -min $min -max $max
	    }
	}
    }
    foreach margin { yaxis y2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis invtransform $axis $y1]
	    set max [$graph axis invtransform $axis $y2]
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
	    } else {
		$graph axis configure $axis -min $min -max $max
	    }
	}





    }
    if {[catch {busy hold $graph}]} {
	update idletasks
    } else { 
	update
	busy release $graph
    }
................................................................................

#
# This routine terminates either an existing zoom, or pops back to
# the previous zoom level (if no zoom is in progress).
#

proc blt::ResetZoom { graph } {
    global zoomInfo 

    if { ![info exists zoomInfo($graph,corner)] } {
	blt::InitStack $graph 
    }
    eval $graph marker delete [$graph marker names "zoom*"]

    if { $zoomInfo($graph,corner) == "A" } {
	# Reset the whole axis
	blt::PopZoom $graph
    } else {
	global zoomMod

	if { [info exists zoomMod] } {
	    set modifier $zoomMod
	} else {
	    set modifier "Any-"
	}
	set zoomInfo($graph,corner) A
	blt::RemoveBindTag $graph select-region-$graph
	set android 0
	catch {set android [sdltk android]}
	if {$android} {
	    blt::PopZoom $graph
	}
    }
}

option add *zoomTitle.font	  -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-* 
option add *zoomTitle.shadow	  yellow4
option add *zoomTitle.foreground  yellow1
option add *zoomTitle.coords	  "-Inf Inf"

proc blt::ZoomTitleNext { graph } {
    global zoomInfo
    set level [expr [llength $zoomInfo($graph,stack)] + 1]
    if { [$graph cget -invertxy] } {
	set coords "-Inf -Inf"
    } else {
	set coords "-Inf Inf"
    }
    $graph marker create text -name "zoomTitle" -text "Zoom #$level" \
	-coords $coords -bindtags "" -anchor nw
}

proc blt::ZoomTitleLast { graph } {
    global zoomInfo

    set level [llength $zoomInfo($graph,stack)]
    if { $level > 0 } {
     	$graph marker create text -name "zoomTitle" -anchor nw \
	    -text "Zoom #$level" 
    }
}


proc blt::SetZoomPoint { graph x y } {
    global zoomInfo zoomMod
    if { ![info exists zoomInfo($graph,corner)] } {
	blt::InitStack $graph
    }
    blt::GetCoords $graph $x $y $zoomInfo($graph,corner)
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
	set modifier "Any-"
    }
    bind select-region-$graph <${modifier}Motion> { 
	blt::GetCoords %W %x %y B
	#blt::MarkPoint $graph B
	blt::Box %W
    }
    if { $zoomInfo($graph,corner) == "A" } {
	if { ![$graph inside $x $y] } {
	    return
	}
	# First corner selected, start watching motion events

	#blt::MarkPoint $graph A
	blt::ZoomTitleNext $graph 

	blt::AddBindTag $graph select-region-$graph
	set zoomInfo($graph,corner) B
    } else {
	# Delete the modal binding
	blt::RemoveBindTag $graph select-region-$graph
	blt::PushZoom $graph 
	set zoomInfo($graph,corner) A
    }
}

option add *zoomOutline.dashes		4	
option add *zoomTitle.anchor		nw
option add *zoomOutline.lineWidth	2
option add *zoomOutline.xor		yes

proc blt::MarchingAnts { graph offset } {
    global zoomInfo

    incr offset
    if { [$graph marker exists zoomOutline] } {
	$graph marker configure zoomOutline -dashoffset $offset 
	set interval $zoomInfo($graph,interval)
	set id [after $interval [list blt::MarchingAnts $graph $offset]]
	set zoomInfo($graph,afterId) $id
    }
}

proc blt::Box { graph } {
    global zoomInfo

    if { $zoomInfo($graph,A,x) > $zoomInfo($graph,B,x) } { 
	set x1 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
	set y1 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
	set x2 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
	set y2 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
    } else {
	set x1 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
	set y1 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
	set x2 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
	set y2 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
    }
    set coords { $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1 }
    if { [$graph marker exists "zoomOutline"] } {
	$graph marker configure "zoomOutline" -coords $coords 
    } else {
	set X [lindex [$graph xaxis use] 0]
	set Y [lindex [$graph yaxis use] 0]
	$graph marker create line -coords $coords -name "zoomOutline" \
	    -mapx $X -mapy $Y
	set interval $zoomInfo($graph,interval)
	set id [after $interval [list blt::MarchingAnts $graph 0]]
	set zoomInfo($graph,afterId) $id
    }
}


proc Blt_PostScriptDialog { graph } {
    set top $graph.top
    toplevel $top


    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set $graph.$var [$graph postscript cget -$var]
    }
    set row 1
    set col 0
    label $top.title -text "PostScript Options"
    table $top $top.title -cspan 7
    foreach bool { center landscape maxpect preview decorations } {
	set w $top.$bool-label
	label $w -text "-$bool"
	table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }
	set w $top.$bool-yes
	global $graph.$bool
	radiobutton $w -text "yes" -variable $graph.$bool -value 1
	table $top $row,$col+1 $w -anchor w
	set w $top.$bool-no
	radiobutton $w -text "no" -variable $graph.$bool -value 0
	table $top $row,$col+2 $w -anchor w
	incr row
    }
    label $top.modes -text "-colormode"
    table $top $row,0 $top.modes -anchor e  -pady { 2 0 } -padx { 0 4 }
    set col 1
    foreach m { color greyscale } {
	set w $top.$m

	radiobutton $w -text $m -variable $graph.colormode -value $m
	table $top $row,$col $w -anchor w
	incr col
    }
    set row 1
    frame $top.sep -width 2 -bd 1 -relief sunken
    table $top $row,3 $top.sep -fill y -rspan 6
    set col 4
    foreach value { padx pady paperwidth paperheight width height } {
	set w $top.$value-label
	label $w -text "-$value"
	table $top $row,$col $w -anchor e  -pady { 2 0 } -padx { 0 4 }
	set w $top.$value-entry
	global $graph.$value
	entry $w -textvariable $graph.$value -width 8
	table $top $row,$col+1 $w -cspan 2 -anchor w -padx 8
	incr row
    }
    table configure $top c3 -width .125i
    button $top.cancel -text "Cancel" -command "destroy $top"
    table $top $row,0 $top.cancel  -width 1i -pady 2 -cspan 3
    button $top.reset -text "Reset" -command "destroy $top"
    #table $top $row,1 $top.reset  -width 1i
    button $top.print -text "Print" -command "blt::ResetPostScript $graph"
    table $top $row,4 $top.print  -width 1i -pady 2 -cspan 2
}

proc blt::ResetPostScript { graph } {

    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set old [$graph postscript cget -$var]

	if {[catch {$graph postscript configure -$var [set $graph.$var]}] != 0 } {


	    $graph postscript configure -$var $old
	    set $graph.$var $old
	}
    }
    $graph postscript output "out.ps"
}








|
|
|
|
|
|
|
|
|



|
<

<
|
|







 







|

|
|

|
|




|
|
|












|

|





|

|


|







 







|

|
|

|
|
|
|







 







|
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>







 







|
<
|



<
|



|
<
|
|



|

<
<
<
|
<









|
|










|

|








|
|


|
|
|








|




<


<

|




|









|
<



|

|




|
<
|
|
|
|
|

|
|
|
|









|

|


<




<
>


<
|




|



|

|
|
|

|
|



|



>
|
|




|




|

|
|
|


|
|
|
|
|
|
|



>


<

>
|
>
>






>
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87

88
89
90
91
92
93
94
95
96
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
248
249
250
251
252
253
254
255


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
...
290
291
292
293
294
295
296
297

298
299
300
301

302
303
304
305
306

307
308
309
310
311
312
313



314

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422
423
424

425
426
427

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493
494
495
	blt::AddBindTag $graph crosshairs-$graph
    } elseif { $state == "off" } {
	blt::RemoveBindTag $graph crosshairs-$graph
    }
}

proc blt::InitStack { graph } {
    global ::blt::zoomInfo
    set ::blt::zoomInfo($graph,interval) 100
    set ::blt::zoomInfo($graph,afterId) 0
    set ::blt::zoomInfo($graph,A,x) {}
    set ::blt::zoomInfo($graph,A,y) {}
    set ::blt::zoomInfo($graph,B,x) {}
    set ::blt::zoomInfo($graph,B,y) {}
    set ::blt::zoomInfo($graph,stack) {}
    set ::blt::zoomInfo($graph,corner) A
}

proc blt::ZoomStack { graph {start "ButtonPress-1"} {reset "ButtonPress-3"} } {
    global ::blt::zoomInfo ::blt::zoomMod

    blt::InitStack $graph

    if { [info exists ::blt::zoomMod] } {
	set modifier $::blt::zoomMod
    } else {
	set modifier ""
    }
    bind zoom-$graph <${modifier}${start}> { blt::SetZoomPoint %W %x %y }
    bind zoom-$graph <${modifier}${reset}> { 
	if { [%W inside %x %y] } { 
	    blt::ResetZoom %W 
................................................................................
	after 200 blt::FlashPoint $graph $name $index $count
    } else {
	eval $graph marker delete [$graph marker names "bltClosest_*"]
    }
}

proc blt::GetCoords { graph x y index } {
    global ::blt::zoomInfo
    if { [$graph cget -invertxy] } {
	set ::blt::zoomInfo($graph,$index,x) $y
	set ::blt::zoomInfo($graph,$index,y) $x
    } else {
	set ::blt::zoomInfo($graph,$index,x) $x
	set ::blt::zoomInfo($graph,$index,y) $y
    }
}

proc blt::MarkPoint { graph index } {
    global ::blt::zoomInfo
    set x [$graph xaxis invtransform $::blt::zoomInfo($graph,$index,x)]
    set y [$graph yaxis invtransform $::blt::zoomInfo($graph,$index,y)]
    set marker "zoomText_$index"
    set text [format "x=%.4g\ny=%.4g" $x $y] 

    if [$graph marker exists $marker] {
     	$graph marker configure $marker -coords { $x $y } -text $text 
    } else {
    	$graph marker create text -coords { $x $y } -name $marker \
	    -text $text -anchor center -bg {} -justify left
    }
}

proc blt::DestroyZoomTitle { graph } {
    global ::blt::zoomInfo

    if { $::blt::zoomInfo($graph,corner) == "A" } {
	catch { $graph marker delete "zoomTitle" }
    }
}

proc blt::PopZoom { graph } {
    global ::blt::zoomInfo

    set zoomStack $::blt::zoomInfo($graph,stack)
    if { [llength $zoomStack] > 0 } {
	set cmd [lindex $zoomStack 0]
	set ::blt::zoomInfo($graph,stack) [lrange $zoomStack 1 end]
	eval $cmd
	blt::ZoomTitleLast $graph
	if {[catch {busy hold $graph}]} {
	    update idletasks
	} else {
	    update
	    busy release $graph
................................................................................
	catch { $graph marker delete "zoomTitle" }
    }
}

# Push the old axis limits on the stack and set the new ones

proc blt::PushZoom { graph } {
    global ::blt::zoomInfo
    eval $graph marker delete [$graph marker names "zoom*"]
    if { [info exists ::blt::zoomInfo($graph,afterId)] } {
	after cancel $::blt::zoomInfo($graph,afterId)
    }
    set x1 $::blt::zoomInfo($graph,A,x)
    set y1 $::blt::zoomInfo($graph,A,y)
    set x2 $::blt::zoomInfo($graph,B,x)
    set y2 $::blt::zoomInfo($graph,B,y)

    if { ($x1 == $x2) || ($y1 == $y2) } { 
	# No delta, revert to start
	return
    }
    set cmd {}
    foreach margin { xaxis yaxis x2axis y2axis } {
................................................................................
	foreach axis [$graph $margin use] {
	    set min [$graph axis cget $axis -min] 
	    set max [$graph axis cget $axis -max]
	    set c [list $graph axis configure $axis -min $min -max $max]
	    append cmd "$c\n"
	}
    }
    if {[catch {


	foreach margin { xaxis x2axis } {
	    foreach axis [$graph $margin use] {
		set min [$graph axis invtransform $axis $x1]
		set max [$graph axis invtransform $axis $x2]
		if { $min > $max } { 
		    $graph axis configure $axis -min $max -max $min
		} else {
		    $graph axis configure $axis -min $min -max $max
		}
	    }
	}
	foreach margin { yaxis y2axis } {
	    foreach axis [$graph $margin use] {
		set min [$graph axis invtransform $axis $y1]
		set max [$graph axis invtransform $axis $y2]
		if { $min > $max } { 
		    $graph axis configure $axis -min $max -max $min
		} else {
		    $graph axis configure $axis -min $min -max $max
		}
	    }
	}
    }]} {
	eval $cmd
    } else {
	set ::blt::zoomInfo($graph,stack) [linsert $::blt::zoomInfo($graph,stack) 0 $cmd]
    }
    if {[catch {busy hold $graph}]} {
	update idletasks
    } else { 
	update
	busy release $graph
    }
................................................................................

#
# This routine terminates either an existing zoom, or pops back to
# the previous zoom level (if no zoom is in progress).
#

proc blt::ResetZoom { graph } {
    global ::blt::zoomInfo 

    if { ![info exists ::blt::zoomInfo($graph,corner)] } {
	blt::InitStack $graph 
    }
    eval $graph marker delete [$graph marker names "zoom*"]

    if { $::blt::zoomInfo($graph,corner) == "A" } {
	# Reset the whole axis
	blt::PopZoom $graph
    } else {
	global ::blt::zoomMod

	if { [info exists ::blt::zoomMod] } {
	    set modifier $::blt::zoomMod
	} else {
	    set modifier "Any-"
	}
	set ::blt::zoomInfo($graph,corner) A
	blt::RemoveBindTag $graph select-region-$graph



	blt::PopZoom $graph

    }
}

option add *zoomTitle.font	  -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-* 
option add *zoomTitle.shadow	  yellow4
option add *zoomTitle.foreground  yellow1
option add *zoomTitle.coords	  "-Inf Inf"

proc blt::ZoomTitleNext { graph } {
    global ::blt::zoomInfo
    set level [expr [llength $::blt::zoomInfo($graph,stack)] + 1]
    if { [$graph cget -invertxy] } {
	set coords "-Inf -Inf"
    } else {
	set coords "-Inf Inf"
    }
    $graph marker create text -name "zoomTitle" -text "Zoom #$level" \
	-coords $coords -bindtags "" -anchor nw
}

proc blt::ZoomTitleLast { graph } {
    global ::blt::zoomInfo

    set level [llength $::blt::zoomInfo($graph,stack)]
    if { $level > 0 } {
     	$graph marker create text -name "zoomTitle" -anchor nw \
	    -text "Zoom #$level" 
    }
}


proc blt::SetZoomPoint { graph x y } {
    global ::blt::zoomInfo ::blt::zoomMod
    if { ![info exists ::blt::zoomInfo($graph,corner)] } {
	blt::InitStack $graph
    }
    blt::GetCoords $graph $x $y $::blt::zoomInfo($graph,corner)
    if { [info exists ::blt::zoomMod] } {
	set modifier $::blt::zoomMod
    } else {
	set modifier "Any-"
    }
    bind select-region-$graph <${modifier}Motion> { 
	blt::GetCoords %W %x %y B
	#blt::MarkPoint $graph B
	blt::Box %W
    }
    if { $::blt::zoomInfo($graph,corner) == "A" } {
	if { ![$graph inside $x $y] } {
	    return
	}
	# First corner selected, start watching motion events

	#blt::MarkPoint $graph A
	blt::ZoomTitleNext $graph 

	blt::AddBindTag $graph select-region-$graph
	set ::blt::zoomInfo($graph,corner) B
    } else {
	# Delete the modal binding
	blt::RemoveBindTag $graph select-region-$graph
	blt::PushZoom $graph 
	set ::blt::zoomInfo($graph,corner) A
    }
}

option add *zoomOutline.dashes		4	
option add *zoomTitle.anchor		nw
option add *zoomOutline.lineWidth	2
option add *zoomOutline.xor		yes

proc blt::MarchingAnts { graph offset } {
    global ::blt::zoomInfo

    incr offset
    if { [$graph marker exists zoomOutline] } {
	$graph marker configure zoomOutline -dashoffset $offset 
	set interval $::blt::zoomInfo($graph,interval)
	set id [after $interval [list blt::MarchingAnts $graph $offset]]
	set ::blt::zoomInfo($graph,afterId) $id
    }
}

proc blt::Box { graph } {
    global ::blt::zoomInfo

    if { $::blt::zoomInfo($graph,A,x) > $::blt::zoomInfo($graph,B,x) } { 
	set x1 [$graph xaxis invtransform $::blt::zoomInfo($graph,B,x)]
	set y1 [$graph yaxis invtransform $::blt::zoomInfo($graph,B,y)]
	set x2 [$graph xaxis invtransform $::blt::zoomInfo($graph,A,x)]
	set y2 [$graph yaxis invtransform $::blt::zoomInfo($graph,A,y)]
    } else {
	set x1 [$graph xaxis invtransform $::blt::zoomInfo($graph,A,x)]
	set y1 [$graph yaxis invtransform $::blt::zoomInfo($graph,A,y)]
	set x2 [$graph xaxis invtransform $::blt::zoomInfo($graph,B,x)]
	set y2 [$graph yaxis invtransform $::blt::zoomInfo($graph,B,y)]
    }
    set coords { $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1 }
    if { [$graph marker exists "zoomOutline"] } {
	$graph marker configure "zoomOutline" -coords $coords 
    } else {
	set X [lindex [$graph xaxis use] 0]
	set Y [lindex [$graph yaxis use] 0]
	$graph marker create line -coords $coords -name "zoomOutline" \
	    -mapx $X -mapy $Y
	set interval $::blt::zoomInfo($graph,interval)
	set id [after $interval [list blt::MarchingAnts $graph 0]]
	set ::blt::zoomInfo($graph,afterId) $id
    }
}


proc Blt_PostScriptDialog { graph } {
    set top $graph.top
    toplevel $top

    global ::blt::postscript
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {

	set ::blt::postscript($graph.$var) [$graph postscript cget -$var]
    }
    set row 1
    set col 0
    label $top.title -text "PostScript Options"
    blt::table $top $top.title -cspan 7
    foreach bool { center landscape maxpect preview decorations } {
	set w $top.$bool-label
	label $w -text "-$bool"
	blt::table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }
	set w $top.$bool-yes
	set var ::blt::postscript($graph.$bool)
	radiobutton $w -text "yes" -variable $var -value 1
	blt::table $top $row,$col+1 $w -anchor w
	set w $top.$bool-no
	radiobutton $w -text "no" -variable $var -value 0
	blt::table $top $row,$col+2 $w -anchor w
	incr row
    }
    label $top.modes -text "-colormode"
    blt::table $top $row,0 $top.modes -anchor e  -pady { 2 0 } -padx { 0 4 }
    set col 1
    foreach m { color greyscale } {
	set w $top.$m
	set var ::blt::postscript($graph.colormode)
	radiobutton $w -text $m -variable $var -value $m
	blt::table $top $row,$col $w -anchor w
	incr col
    }
    set row 1
    frame $top.sep -width 2 -bd 1 -relief sunken
    blt::table $top $row,3 $top.sep -fill y -rspan 6
    set col 4
    foreach value { padx pady paperwidth paperheight width height } {
	set w $top.$value-label
	label $w -text "-$value"
	blt::table $top $row,$col $w -anchor e  -pady { 2 0 } -padx { 0 4 }
	set w $top.$value-entry
	set var ::blt::postscript($graph.$value)
	entry $w -textvariable $var -width 8
	blt::table $top $row,$col+1 $w -cspan 2 -anchor w -padx 8
	incr row
    }
    blt::table configure $top c3 -width .125i
    button $top.cancel -text "Cancel" -command [list destroy $top]
    blt::table $top $row,0 $top.cancel  -width 1i -pady 2 -cspan 3
    button $top.reset -text "Reset" -command [list destroy $top]
    #blt::table $top $row,1 $top.reset  -width 1i
    button $top.print -text "Print" -command [list blt::ResetPostScript $graph]
    blt::table $top $row,4 $top.print  -width 1i -pady 2 -cspan 2
}

proc blt::ResetPostScript { graph } {
    global ::blt::postscript
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {

	set old [$graph postscript cget -$var]
	if {[catch {
	    $graph postscript configure -$var \
		[set ::blt::postscript($graph.$var)]
	}] != 0} {
	    $graph postscript configure -$var $old
	    set $graph.$var $old
	}
    }
    $graph postscript output "out.ps"
}

Changes to jni/blt/Android.mk.

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
103
104
105
106
107
108
109

110
111
112
113
114
115
116
	src/bltNsUtil.c \
	src/bltParse.c \
	src/bltPool.c \
	src/bltSpline.c \
	src/bltSwitch.c \
	src/bltUtil.c \
	src/bltWatch.c \
	src/bltVecCmd.c \
	src/bltVecObjCmd.c \
	src/bltVecMath.c \
	src/bltVector.c \
	src/bltConfig.c \
	src/bltImage.c \
	src/bltUnixImage.c \
	src/bltPs.c \
................................................................................
	-DNO_TREEVIEW=1 \
	-DNO_MOUNTAIN=1 \
	-DNO_TED=1 \
	-DNO_EPSCANV=1 \
	-DNO_SENDEVENT=1 \
	-DNO_COMBOTREE=1 \
	-DNO_HTEXT=1 \

	-O2

LOCAL_SHARED_LIBRARIES := libtcl libtk

LOCAL_LDLIBS :=

include $(BUILD_SHARED_LIBRARY)







<







 







>







50
51
52
53
54
55
56

57
58
59
60
61
62
63
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	src/bltNsUtil.c \
	src/bltParse.c \
	src/bltPool.c \
	src/bltSpline.c \
	src/bltSwitch.c \
	src/bltUtil.c \
	src/bltWatch.c \

	src/bltVecObjCmd.c \
	src/bltVecMath.c \
	src/bltVector.c \
	src/bltConfig.c \
	src/bltImage.c \
	src/bltUnixImage.c \
	src/bltPs.c \
................................................................................
	-DNO_TREEVIEW=1 \
	-DNO_MOUNTAIN=1 \
	-DNO_TED=1 \
	-DNO_EPSCANV=1 \
	-DNO_SENDEVENT=1 \
	-DNO_COMBOTREE=1 \
	-DNO_HTEXT=1 \
	-DTK_DRAWANGLEDCHARS=1 \
	-O2

LOCAL_SHARED_LIBRARIES := libtcl libtk

LOCAL_LDLIBS :=

include $(BUILD_SHARED_LIBRARY)

Changes to jni/blt/MANIFEST.

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
blt2.4z/src/bltTuple.h
blt2.4z/src/bltTupleCmd.c
blt2.4z/src/bltUnixDnd.c
blt2.4z/src/bltUnixImage.c
blt2.4z/src/bltUnixMain.c
blt2.4z/src/bltUnixPipe.c
blt2.4z/src/bltUtil.c
blt2.4z/src/bltVecCmd.c
blt2.4z/src/bltVecInt.h
blt2.4z/src/bltVecMath.c
blt2.4z/src/bltVecObjCmd.c
blt2.4z/src/bltVector.c
blt2.4z/src/bltVector.h
blt2.4z/src/bltWait.h
blt2.4z/src/bltWatch.c
................................................................................
blt2.4z/src/bltWinMain.c
blt2.4z/src/bltWinPipe.c
blt2.4z/src/bltWinPrnt.c
blt2.4z/src/bltWinUtil.c
blt2.4z/src/bltWindow.c
blt2.4z/src/bltWinop.c
blt2.4z/src/missing.h
blt2.4z/src/pure_api.c
blt2.4z/src/tkButton.c
blt2.4z/src/tkConsole.c
blt2.4z/src/tkFrame.c
blt2.4z/src/tkMenubutton.c
blt2.4z/src/tkScrollbar.c
blt2.4z/win
blt2.4z/win/install.tcl







<







 







<







349
350
351
352
353
354
355

356
357
358
359
360
361
362
...
368
369
370
371
372
373
374

375
376
377
378
379
380
381
blt2.4z/src/bltTuple.h
blt2.4z/src/bltTupleCmd.c
blt2.4z/src/bltUnixDnd.c
blt2.4z/src/bltUnixImage.c
blt2.4z/src/bltUnixMain.c
blt2.4z/src/bltUnixPipe.c
blt2.4z/src/bltUtil.c

blt2.4z/src/bltVecInt.h
blt2.4z/src/bltVecMath.c
blt2.4z/src/bltVecObjCmd.c
blt2.4z/src/bltVector.c
blt2.4z/src/bltVector.h
blt2.4z/src/bltWait.h
blt2.4z/src/bltWatch.c
................................................................................
blt2.4z/src/bltWinMain.c
blt2.4z/src/bltWinPipe.c
blt2.4z/src/bltWinPrnt.c
blt2.4z/src/bltWinUtil.c
blt2.4z/src/bltWindow.c
blt2.4z/src/bltWinop.c
blt2.4z/src/missing.h

blt2.4z/src/tkButton.c
blt2.4z/src/tkConsole.c
blt2.4z/src/tkFrame.c
blt2.4z/src/tkMenubutton.c
blt2.4z/src/tkScrollbar.c
blt2.4z/win
blt2.4z/win/install.tcl

Changes to jni/blt/Makefile.in.

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        done

clean:
	(cd src; $(MAKE) clean)
	(cd library; $(MAKE) clean)
	(cd man; $(MAKE) clean)
	(cd demos; $(MAKE) clean)
	$(RM) *.bak *\~ "#"* .pure*

GENERATED_FILES = \
	config.status config.cache config.log Makefile 

distclean: clean
	(cd src; $(MAKE) distclean)
	(cd library; $(MAKE) distclean)
	(cd man; $(MAKE) distclean)
	(cd demos; $(MAKE) distclean)
	$(RM) $(GENERATED_FILES)







|










62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        done

clean:
	(cd src; $(MAKE) clean)
	(cd library; $(MAKE) clean)
	(cd man; $(MAKE) clean)
	(cd demos; $(MAKE) clean)
	$(RM) *.bak *\~ "#"*

GENERATED_FILES = \
	config.status config.cache config.log Makefile 

distclean: clean
	(cd src; $(MAKE) distclean)
	(cd library; $(MAKE) distclean)
	(cd man; $(MAKE) distclean)
	(cd demos; $(MAKE) distclean)
	$(RM) $(GENERATED_FILES)

Changes to jni/blt/Makefile.vc.

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	$(INSTALL_DATA) $(srcdir)/NEWS $(scriptdir)

clean:
	(cd src; $(MAKE) -f Makefile.vc clean) 
	(cd demos; $(MAKE) -f Makefile.vc clean) 
	(cd library; $(MAKE) -f Makefile.vc clean) 
	(cd html; $(MAKE) -f Makefile.vc clean) 
	$(RM) *.bak *\~ "#"* *pure* .pure*

GENERATED_FILES = \
	config.status config.cache config.log Makefile 

distclean: clean
	(cd src; $(MAKE) -f Makefile.vc distclean) 
	(cd demos; $(MAKE) -f Makefile.vc distclean) 
	(cd library; $(MAKE) -f Makefile.vc distclean) 
	(cd html; $(MAKE) -f Makefile.vc distclean) 
	$(RM) $(GENERATED_FILES)







|










46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	$(INSTALL_DATA) $(srcdir)/NEWS $(scriptdir)

clean:
	(cd src; $(MAKE) -f Makefile.vc clean) 
	(cd demos; $(MAKE) -f Makefile.vc clean) 
	(cd library; $(MAKE) -f Makefile.vc clean) 
	(cd html; $(MAKE) -f Makefile.vc clean) 
	$(RM) *.bak *\~ "#"*

GENERATED_FILES = \
	config.status config.cache config.log Makefile 

distclean: clean
	(cd src; $(MAKE) -f Makefile.vc distclean) 
	(cd demos; $(MAKE) -f Makefile.vc distclean) 
	(cd library; $(MAKE) -f Makefile.vc distclean) 
	(cd html; $(MAKE) -f Makefile.vc distclean) 
	$(RM) $(GENERATED_FILES)

Changes to jni/blt/blt.mak.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	cd $(MAKEDIR)\src
	$(MAKE) -f blt.mak all
	cd $(MAKEDIR)

install: install-all

install-all:
 	wish$(v2)d.exe win/install.tcl $(v1) $(srcdir)

clean:
	cd $(MAKEDIR)\src
	$(MAKE) -f blt.mak clean
	cd $(MAKEDIR)
	$(RM) *.bak *\~ "#"* *pure* .pure*

distclean: clean








|





|



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	cd $(MAKEDIR)\src
	$(MAKE) -f blt.mak all
	cd $(MAKEDIR)

install: install-all

install-all:
	wish$(v2)d.exe win/install.tcl $(v1) $(srcdir)

clean:
	cd $(MAKEDIR)\src
	$(MAKE) -f blt.mak clean
	cd $(MAKEDIR)
	$(RM) *.bak *\~ "#"*

distclean: clean

Changes to jni/blt/configure.

3235
3236
3237
3238
3239
3240
3241



3242
3243
3244



3245
3246
3247



3248
3249
3250
3251
3252
3253
3254
....
3258
3259
3260
3261
3262
3263
3264



3265
3266
3267



3268
3269
3270



3271
3272
3273
3274
3275
3276
3277
....
3281
3282
3283
3284
3285
3286
3287



3288
3289
3290
3291
3292
3293
3294

  for dir in \
   $blt_with_tk \
   $blt_with_tcl 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"



      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"



      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"



      break
    fi
  done
else 

  # Search for Tk configuration file.  

................................................................................
   $prefix \
   $exec_prefix \
   $blt_cv_tk_lib \
   $blt_cv_tcl_lib 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"



      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"



      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"



      break
    fi
  done

  #  2. Search source directories.

  if test "x$tk_config_sh" = "x" ; then
................................................................................
     ../../tcl \
     `ls -dr ../../tk[4-9].[0-9]* 2>/dev/null` \
     ../../../tcl \
     `ls -dr ../../../tk[4-9].[0-9]* 2>/dev/null`
    do
      if test -r "$dir/$blt_platform/tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/tkConfig.sh"



	break
      fi
    done
  fi

  #  3. Search standard locations.








>
>
>



>
>
>



>
>
>







 







>
>
>



>
>
>



>
>
>







 







>
>
>







3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
....
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
....
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315

  for dir in \
   $blt_with_tk \
   $blt_with_tcl 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"
      break
    elif test -r "$dir/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/sdl2tkConfig.sh"
      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"
      break
    elif test -r "$dir/lib/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
      break
    fi
  done
else 

  # Search for Tk configuration file.  

................................................................................
   $prefix \
   $exec_prefix \
   $blt_cv_tk_lib \
   $blt_cv_tcl_lib 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"
      break
    elif test -r "$dir/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/sdl2tkConfig.sh"
      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"
      break
    elif test -r "$dir/lib/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/lib/sdl2tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
      break
    fi
  done

  #  2. Search source directories.

  if test "x$tk_config_sh" = "x" ; then
................................................................................
     ../../tcl \
     `ls -dr ../../tk[4-9].[0-9]* 2>/dev/null` \
     ../../../tcl \
     `ls -dr ../../../tk[4-9].[0-9]* 2>/dev/null`
    do
      if test -r "$dir/$blt_platform/tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/tkConfig.sh"
	break
      elif test -r "$dir/$blt_platform/sdl2tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
	break
      fi
    done
  fi

  #  3. Search standard locations.

Changes to jni/blt/configure.in.

567
568
569
570
571
572
573



574
575
576



577
578
579



580
581
582
583
584
585
586
...
590
591
592
593
594
595
596



597
598
599



600
601
602



603
604
605
606
607
608
609
...
613
614
615
616
617
618
619



620
621
622
623
624
625
626

  for dir in \
   $blt_with_tk \
   $blt_with_tcl 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"



      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"



      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"



      break
    fi
  done
else 

  # Search for Tk configuration file.  

................................................................................
   $prefix \
   $exec_prefix \
   $blt_cv_tk_lib \
   $blt_cv_tcl_lib 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"



      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"



      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"



      break
    fi
  done

  #  2. Search source directories.

  if test "x$tk_config_sh" = "x" ; then
................................................................................
     ../../tcl \
     `ls -dr ../../tk[[4-9]].[[0-9]]* 2>/dev/null` \
     ../../../tcl \
     `ls -dr ../../../tk[[4-9]].[[0-9]]* 2>/dev/null`
    do
      if test -r "$dir/$blt_platform/tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/tkConfig.sh"



	break
      fi
    done
  fi

  #  3. Search standard locations.








>
>
>



>
>
>



>
>
>







 







>
>
>



>
>
>



>
>
>







 







>
>
>







567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
...
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

  for dir in \
   $blt_with_tk \
   $blt_with_tcl 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"
      break
    elif test -r "$dir/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/sdl2tkConfig.sh"
      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"
      break
    elif test -r "$dir/lib/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/lib/sdl2tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
      break
    fi
  done
else 

  # Search for Tk configuration file.  

................................................................................
   $prefix \
   $exec_prefix \
   $blt_cv_tk_lib \
   $blt_cv_tcl_lib 
  do
    if test -r "$dir/tkConfig.sh" ; then
      tk_config_sh="$dir/tkConfig.sh"
      break
    elif test -r "$dir/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/sdl2tkConfig.sh"
      break
    elif test -r "$dir/lib/tkConfig.sh" ; then
      tk_config_sh="$dir/lib/tkConfig.sh"
      break
    elif test -r "$dir/lib/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/lib/sdl2tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/tkConfig.sh"
      break
    elif test -r "$dir/$blt_platform/sdl2tkConfig.sh" ; then
      tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
      break
    fi
  done

  #  2. Search source directories.

  if test "x$tk_config_sh" = "x" ; then
................................................................................
     ../../tcl \
     `ls -dr ../../tk[[4-9]].[[0-9]]* 2>/dev/null` \
     ../../../tcl \
     `ls -dr ../../../tk[[4-9]].[[0-9]]* 2>/dev/null`
    do
      if test -r "$dir/$blt_platform/tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/tkConfig.sh"
	break
      elif test -r "$dir/$blt_platform/sdl2tkConfig.sh"; then
	tk_config_sh="$dir/$blt_platform/sdl2tkConfig.sh"
	break
      fi
    done
  fi

  #  3. Search standard locations.

Changes to jni/blt/library/graph.tcl.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
    $graph legend bind all <ButtonPress-1> [list blt::HighlightLegend $graph]
}

proc Blt_Crosshairs { graph } {
    blt::Crosshairs $graph 
}

proc Blt_ResetCrosshairs { graph state } {
    blt::Crosshairs $graph "Any-Motion" $state
}

proc Blt_ZoomStack { graph } {
    blt::ZoomStack $graph
}

................................................................................
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set $graph.$var [$graph postscript cget -$var]
    }
    set row 1
    set col 0
    label $top.title -text "PostScript Options"
    table $top $top.title -cspan 7
    foreach bool { center landscape maxpect preview decorations } {
	set w $top.$bool-label
	label $w -text "-$bool" -font *courier*-r-*12* 
	table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }
	set w $top.$bool-yes
	global $graph.$bool
	radiobutton $w -text "yes" -variable $graph.$bool -value 1
	table $top $row,$col+1 $w -anchor w
	set w $top.$bool-no
	radiobutton $w -text "no" -variable $graph.$bool -value 0
	table $top $row,$col+2 $w -anchor w
	incr row
    }
    label $top.modes -text "-colormode" -font *courier*-r-*12* 
    table $top $row,0 $top.modes -anchor e  -pady { 2 0 } -padx { 0 4 }
    set col 1
    foreach m { color greyscale } {
	set w $top.$m
	radiobutton $w -text $m -variable $graph.colormode -value $m
	table $top $row,$col $w -anchor w
	incr col
    }
    set row 1
    frame $top.sep -width 2 -bd 1 -relief sunken
    table $top $row,3 $top.sep -fill y -rspan 6
    set col 4
    foreach value { padx pady paperwidth paperheight width height } {
	set w $top.$value-label
	label $w -text "-$value" -font *courier*-r-*12* 
	table $top $row,$col $w -anchor e  -pady { 2 0 } -padx { 0 4 }
	set w $top.$value-entry
	global $graph.$value
	entry $w -textvariable $graph.$value -width 8
	table $top $row,$col+1 $w -cspan 2 -anchor w -padx 8
	incr row
    }
    table configure $top c3 -width .125i
    button $top.cancel -text "Cancel" -command "destroy $top"
    table $top $row,0 $top.cancel  -width 1i -pady 2 -cspan 3
    button $top.reset -text "Reset" -command "destroy $top"
    #table $top $row,1 $top.reset  -width 1i
    button $top.print -text "Print" -command "blt::ResetPostScript $graph"
    table $top $row,4 $top.print  -width 1i -pady 2 -cspan 2
}

proc blt::ResetPostScript { graph } {
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set old [$graph postscript cget -$var]







|







 







|



|



|


|



|




|




|




|



|


|

|

|

|







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
    $graph legend bind all <ButtonPress-1> [list blt::HighlightLegend $graph]
}

proc Blt_Crosshairs { graph } {
    blt::Crosshairs $graph 
}

proc Blt_ResetCrosshairs { graph {state off}} {
    blt::Crosshairs $graph "Any-Motion" $state
}

proc Blt_ZoomStack { graph } {
    blt::ZoomStack $graph
}

................................................................................
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set $graph.$var [$graph postscript cget -$var]
    }
    set row 1
    set col 0
    label $top.title -text "PostScript Options"
    blt::table $top $top.title -cspan 7
    foreach bool { center landscape maxpect preview decorations } {
	set w $top.$bool-label
	label $w -text "-$bool" -font *courier*-r-*12* 
	blt::table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }
	set w $top.$bool-yes
	global $graph.$bool
	radiobutton $w -text "yes" -variable $graph.$bool -value 1
	blt::table $top $row,$col+1 $w -anchor w
	set w $top.$bool-no
	radiobutton $w -text "no" -variable $graph.$bool -value 0
	blt::table $top $row,$col+2 $w -anchor w
	incr row
    }
    label $top.modes -text "-colormode" -font *courier*-r-*12* 
    blt::table $top $row,0 $top.modes -anchor e  -pady { 2 0 } -padx { 0 4 }
    set col 1
    foreach m { color greyscale } {
	set w $top.$m
	radiobutton $w -text $m -variable $graph.colormode -value $m
	blt::table $top $row,$col $w -anchor w
	incr col
    }
    set row 1
    frame $top.sep -width 2 -bd 1 -relief sunken
    blt::table $top $row,3 $top.sep -fill y -rspan 6
    set col 4
    foreach value { padx pady paperwidth paperheight width height } {
	set w $top.$value-label
	label $w -text "-$value" -font *courier*-r-*12* 
	blt::table $top $row,$col $w -anchor e  -pady { 2 0 } -padx { 0 4 }
	set w $top.$value-entry
	global $graph.$value
	entry $w -textvariable $graph.$value -width 8
	blt::table $top $row,$col+1 $w -cspan 2 -anchor w -padx 8
	incr row
    }
    blt::table configure $top c3 -width .125i
    button $top.cancel -text "Cancel" -command "destroy $top"
    blt::table $top $row,0 $top.cancel  -width 1i -pady 2 -cspan 3
    button $top.reset -text "Reset" -command "destroy $top"
    #blt::table $top $row,1 $top.reset  -width 1i
    button $top.print -text "Print" -command "blt::ResetPostScript $graph"
    blt::table $top $row,4 $top.print  -width 1i -pady 2 -cspan 2
}

proc blt::ResetPostScript { graph } {
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set old [$graph postscript cget -$var]

Changes to jni/blt/library/hiertable.tcl.

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Bindings for the BLT hiertable widget
# ----------------------------------------------------------------------
#   AUTHOR:  George Howlett
#            Bell Labs Innovations for Lucent Technologies
#            gah@lucent.com
#            http://www.tcltk.com/blt
#
#      RCS:  $Id: hiertable.tcl,v 1.1 2002/02/03 20:00:43 ghowlett Exp $
#
# ----------------------------------------------------------------------
# Copyright (c) 1998  Lucent Technologies, Inc.
# ======================================================================
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
................................................................................
# of use, data or profits, whether in an action of contract, negligence
# or other tortuous action, arising out of or in connection with the use
# or performance of this software.
#
# ======================================================================

namespace eval blt::Hiertable {
    set afterId ""
    set scroll 0
    set column ""
    set space   off
    set x 0
    set y 0
}

# 
# ButtonPress assignments
#
#	B1-Enter	start auto-scrolling
#	B1-Leave	stop auto-scrolling







<
<







 







|
|
|
|
|
|







3
4
5
6
7
8
9


10
11
12
13
14
15
16
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Bindings for the BLT hiertable widget
# ----------------------------------------------------------------------
#   AUTHOR:  George Howlett
#            Bell Labs Innovations for Lucent Technologies
#            gah@lucent.com
#            http://www.tcltk.com/blt
#


# ----------------------------------------------------------------------
# Copyright (c) 1998  Lucent Technologies, Inc.
# ======================================================================
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
................................................................................
# of use, data or profits, whether in an action of contract, negligence
# or other tortuous action, arising out of or in connection with the use
# or performance of this software.
#
# ======================================================================

namespace eval blt::Hiertable {
    variable afterId ""
    variable scroll 0
    variable column ""
    variable space   off
    variable x 0
    variable y 0
}

# 
# ButtonPress assignments
#
#	B1-Enter	start auto-scrolling
#	B1-Leave	stop auto-scrolling

Changes to jni/blt/library/pkgIndex.tcl.in.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    set prefix "%LIB_PREFIX%"
    set suffix [info sharedlibextension]
    regsub {\.} $version {} version_no_dots

    # Determine whether to load the full BLT library or
    # the "lite" tcl-only version.
    
    if {[package vcompare [info tclversion] 8.2] < 0} {
        set taillib ${version}.so.8.0
    } elseif {[package vcompare [info tclversion] 8.3] < 0} {
        set taillib ${version}.so.8.2
    } elseif {[package vcompare [info tclversion] 8.4] < 0} {
        set taillib ${version}.so.8.3
    } elseif {[package vcompare [info tclversion] 8.5] < 0} {
        set taillib ${version}.so.8.4
    } else {
        set taillib ${version}.so.8.5
    }

    if { [info commands tk] == "tk" } {
        set name ${prefix}BLT.${taillib}
    } else {
        set name ${prefix}BLTlite.${taillib}
    }
    
    global tcl_platform
    if { $tcl_platform(platform) == "unix" } {
        if { [info commands tk] == "tk" } {
          set library libBLT.${taillib}
        } else {
          set library libBLTlite.${taillib}
        }
	if { ![file exists $library] } {
	    # Try the parent directory.
	    set library [file join [file dirname $dir] $name]
	}
	if { ![file exists $library] } {
	    # Default to the path generated at compilation.
	    set library [file join "/usr/lib" $name]
	}
    } else {
	set library $name
    }
    load $library BLT
}

set version "%VERSION%"
set libdir  "/usr/lib"

package ifneeded BLT $version [list LoadBLT $version $dir]

# End of package index file







<
<
<
<
<
<
<
<
<
<
<
<

|

|




<
|
<
<
<






|


|





<




5
6
7
8
9
10
11












12
13
14
15
16
17
18
19

20



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
    set prefix "%LIB_PREFIX%"
    set suffix [info sharedlibextension]
    regsub {\.} $version {} version_no_dots

    # Determine whether to load the full BLT library or
    # the "lite" tcl-only version.
    












    if { [info commands tk] == "tk" } {
        set name ${prefix}BLT${version_no_dots}${suffix}
    } else {
        set name ${prefix}BLTlite${version_no_dots}${suffix}
    }
    
    global tcl_platform
    if { $tcl_platform(platform) == "unix" } {

	set library [file join $dir $name]



	if { ![file exists $library] } {
	    # Try the parent directory.
	    set library [file join [file dirname $dir] $name]
	}
	if { ![file exists $library] } {
	    # Default to the path generated at compilation.
	    set library [file join "%LIB_DIR%" $name]
	}
    } else {
	set library [file join $dir $name]
    }
    load $library BLT
}

set version "%VERSION%"


package ifneeded BLT $version [list LoadBLT $version $dir]

# End of package index file

Changes to jni/blt/man/watch.mann.

124
125
126
127
128
129
130
131
132
133
134
135
136
137
.TP
\fBwatch info \fIwatchName\fR 
Returns the configuration information associated with the 
watch \fIwatchName\fR.  \fIWatchName\fR is the name of a watch.
.TP
\fBwatch names\fR ?\fIstate\fR?
Lists the names of the watches for a given state.  \fIState\fR may be
one of the following: \f(CWactive\fR, \f(CWidle\fR, or \f(CWignore\fR.  If a
\fIstate\fR argument isn't specified,
 all watches are
listed.
.RE
.SH KEYWORDS
debug, profile







|






124
125
126
127
128
129
130
131
132
133
134
135
136
137
.TP
\fBwatch info \fIwatchName\fR 
Returns the configuration information associated with the 
watch \fIwatchName\fR.  \fIWatchName\fR is the name of a watch.
.TP
\fBwatch names\fR ?\fIstate\fR?
Lists the names of the watches for a given state.  \fIState\fR may be
one of the following: \fBactive\fR, \fBidle\fR, or \fBignore\fR.  If a
\fIstate\fR argument isn't specified,
 all watches are
listed.
.RE
.SH KEYWORDS
debug, profile

Changes to jni/blt/src/Makefile-cyg.in.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
		bltParse.o \
		bltPool.o \
		bltSpline.o \
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUtil.o \
		bltVecCmd.o \
		bltVecMath.o \
		bltVecObjCmd.o \
		bltVector.o \
		bltWatch.o  \
		bltWinPipe.o \
		bltWinUtil.o \
		bltWinDde.o \
		pure_api.o

DEMO_OBJS     =	tkConsole.o bltWinMain.o

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
................................................................................

xref:
	$(XREF) $(XREFFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

clean:
	$(RM) $(OBJS) bltInit.o $(lib_a) $(tcl_only_lib_a) \
		$(lib_so) $(tcl_only_lib_so) \
		$(bltsh)* $(bltwish)* .pure* *~

distclean: clean
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  Makefile
	$(RM) bltConfig.h bltHash.h Makefile TAGS

.c.o:
	$(CC) -c $(CC_SWITCHES) $<








<






|
<







 







|








80
81
82
83
84
85
86

87
88
89
90
91
92
93

94
95
96
97
98
99
100
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
		bltParse.o \
		bltPool.o \
		bltSpline.o \
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUtil.o \

		bltVecMath.o \
		bltVecObjCmd.o \
		bltVector.o \
		bltWatch.o  \
		bltWinPipe.o \
		bltWinUtil.o \
		bltWinDde.o


DEMO_OBJS     =	tkConsole.o bltWinMain.o

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
................................................................................

xref:
	$(XREF) $(XREFFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

clean:
	$(RM) $(OBJS) bltInit.o $(lib_a) $(tcl_only_lib_a) \
		$(lib_so) $(tcl_only_lib_so) \
		$(bltsh)* $(bltwish)* *~

distclean: clean
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  Makefile
	$(RM) bltConfig.h bltHash.h Makefile TAGS

.c.o:
	$(CC) -c $(CC_SWITCHES) $<

Changes to jni/blt/src/Makefile.bc.

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
MSVCRT        =	
!endif

# Turn off the following bcc warnings:
#   -w-pro	Call to function with no prototype
#   -w-par	Parameter is never used.
#   -w-sus 	Suspicious pointer conversion (bltCanvEps.c).
#   -w-eff	Code has no effect (pure_api.c).
#
WARNINGS      =	-w-pro -w-par -w-eff -w-sus 

#   -q		Suppress compiler identification banner.
#   -g1		Stop after the first warning.
#   -tWC	Target is a Windows console application.
#   -X		Disable compiler autodependency output.
................................................................................
		bltParse.obj \
		bltPool.obj \
		bltSpline.obj \
		bltSwitch.obj \
		bltTree.obj \
		bltTreeCmd.obj \
		bltUtil.obj \
		bltVecCmd.obj \
		bltVecMath.obj \
		bltVecObjCmd.obj \
		bltVector.obj \
		bltWatch.obj  \
		bltWinPipe.obj \
		bltWinUtil.obj \
		bltWinDde.obj \
		pure_api.obj

DEMO_OBJS     =	tkConsole.obj bltWinMain.obj

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.obj \
		bltBind.obj \







<







 







<






|
<







88
89
90
91
92
93
94

95
96
97
98
99
100
101
...
186
187
188
189
190
191
192

193
194
195
196
197
198
199

200
201
202
203
204
205
206
MSVCRT        =	
!endif

# Turn off the following bcc warnings:
#   -w-pro	Call to function with no prototype
#   -w-par	Parameter is never used.
#   -w-sus 	Suspicious pointer conversion (bltCanvEps.c).

#
WARNINGS      =	-w-pro -w-par -w-eff -w-sus 

#   -q		Suppress compiler identification banner.
#   -g1		Stop after the first warning.
#   -tWC	Target is a Windows console application.
#   -X		Disable compiler autodependency output.
................................................................................
		bltParse.obj \
		bltPool.obj \
		bltSpline.obj \
		bltSwitch.obj \
		bltTree.obj \
		bltTreeCmd.obj \
		bltUtil.obj \

		bltVecMath.obj \
		bltVecObjCmd.obj \
		bltVector.obj \
		bltWatch.obj  \
		bltWinPipe.obj \
		bltWinUtil.obj \
		bltWinDde.obj


DEMO_OBJS     =	tkConsole.obj bltWinMain.obj

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.obj \
		bltBind.obj \

Changes to jni/blt/src/Makefile.in.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
...
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUnixPipe.o \
		bltUtil.o \
		bltVector.o \
		bltVecMath.o \
		bltVecCmd.o \
		bltVecObjCmd.o \
		bltWatch.o  

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
................................................................................
LINT =		lint
LINTFLAGS =	-axhbns
XREF =		cxref
XREFFLAGS =	-dltR
LN_S =		@LN_S@
VPATH =		$(srcdir)

all: $(bltsh) $(bltwish) @SHLIB_TARGET@


build_shared:
	(cd shared; $(MAKE) CFLAGS="$(CFLAGS)" all) 

$(bltwish): $(lib_a) $(srcdir)/bltUnixMain.c
	$(RM) $(bltwish)
	$(CC) $(CC_SWITCHES) $(LDFLAGS) -o $(bltwish) \
................................................................................
$(tcl_only_lib_a):  $(TCL_ONLY_OBJS) $(srcdir)/bltInit.c
	$(CC) -c $(CC_SWITCHES) -DTCL_ONLY -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		$(srcdir)/bltInit.c
	$(RM) $@
	$(AR) $@ $(TCL_ONLY_OBJS) bltInit.o
	$(RANLIB) $@

install: mkdirs install-lib install-demo install-headers


install-demo: $(bltwish) $(bltsh)
	$(INSTALL) -m 0755 $(bltwish) $(INSTALL_ROOT)$(bindir)
	$(INSTALL) -m 0755 $(bltsh) $(INSTALL_ROOT)$(bindir)

install-lib: $(lib_a) $(tcl_only_lib_a)
	$(INSTALL_DATA) $(lib_a) $(INSTALL_ROOT)$(libdir)/$(libvers_a)
................................................................................
	$(LINT) $(LINTFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

xref:
	$(XREF) $(XREFFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

clean:
	$(RM) $(OBJS) bltInit.o $(lib_a) $(tcl_only_lib_a) \
		$(bltsh)* $(bltwish)* .pure*
	(cd shared; $(MAKE) clean) 

distclean: clean
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  Makefile
	$(RM) bltConfig.h bltHash.h Makefile TAGS
	(cd shared; $(MAKE) distclean)

.c.o:
	$(CC) -c $(CC_SWITCHES) $<

PUREFLAGS=
pure: $(lib_a)
	$(PURIFYHOME)/purify $(PUREFLAGS) $(CC) $(CC_SWITCHES) \
		$(srcdir)/bltUnixMain.c -o bltwish $(lib_a) $(LIBS)

QUANTIFYFLAGS=
quant: $(lib_a)
	$(QUANTIFYHOME)/quantify $(QUANTIFYFLAGS) $(CC) $(CC_SWITCHES) \
		$(srcdir)/bltUnixMain.c -o bltwish $(lib_a) $(LIBS)







<







 







|
>







 







|
>







 







|










<
<
<
<
<
<
<
<
<
80
81
82
83
84
85
86

87
88
89
90
91
92
93
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239









		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUnixPipe.o \
		bltUtil.o \
		bltVector.o \
		bltVecMath.o \

		bltVecObjCmd.o \
		bltWatch.o  

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
................................................................................
LINT =		lint
LINTFLAGS =	-axhbns
XREF =		cxref
XREFFLAGS =	-dltR
LN_S =		@LN_S@
VPATH =		$(srcdir)

#all: $(bltsh) $(bltwish) @SHLIB_TARGET@
all: @SHLIB_TARGET@

build_shared:
	(cd shared; $(MAKE) CFLAGS="$(CFLAGS)" all) 

$(bltwish): $(lib_a) $(srcdir)/bltUnixMain.c
	$(RM) $(bltwish)
	$(CC) $(CC_SWITCHES) $(LDFLAGS) -o $(bltwish) \
................................................................................
$(tcl_only_lib_a):  $(TCL_ONLY_OBJS) $(srcdir)/bltInit.c
	$(CC) -c $(CC_SWITCHES) -DTCL_ONLY -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		$(srcdir)/bltInit.c
	$(RM) $@
	$(AR) $@ $(TCL_ONLY_OBJS) bltInit.o
	$(RANLIB) $@

#install: mkdirs install-lib install-demo install-headers
install: mkdirs install-lib install-headers

install-demo: $(bltwish) $(bltsh)
	$(INSTALL) -m 0755 $(bltwish) $(INSTALL_ROOT)$(bindir)
	$(INSTALL) -m 0755 $(bltsh) $(INSTALL_ROOT)$(bindir)

install-lib: $(lib_a) $(tcl_only_lib_a)
	$(INSTALL_DATA) $(lib_a) $(INSTALL_ROOT)$(libdir)/$(libvers_a)
................................................................................
	$(LINT) $(LINTFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

xref:
	$(XREF) $(XREFFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

clean:
	$(RM) $(OBJS) bltInit.o $(lib_a) $(tcl_only_lib_a) \
		$(bltsh)* $(bltwish)* *~
	(cd shared; $(MAKE) clean) 

distclean: clean
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  Makefile
	$(RM) bltConfig.h bltHash.h Makefile TAGS
	(cd shared; $(MAKE) distclean)

.c.o:
	$(CC) -c $(CC_SWITCHES) $<










Changes to jni/blt/src/Makefile.vc.

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
		bltParse.o \
		bltPool.o \
		bltSpline.o \
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUtil.o \
		bltVecCmd.o \
		bltVecMath.o \
		bltVecObjCmd.o \
		bltVector.o \
		bltWatch.o  \
		bltWinPipe.o \
		bltWinUtil.o \
		bltWinDde.o







<







148
149
150
151
152
153
154

155
156
157
158
159
160
161
		bltParse.o \
		bltPool.o \
		bltSpline.o \
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUtil.o \

		bltVecMath.o \
		bltVecObjCmd.o \
		bltVector.o \
		bltWatch.o  \
		bltWinPipe.o \
		bltWinUtil.o \
		bltWinDde.o

Changes to jni/blt/src/blt.h.

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#endif

#include <bltVector.h>
#include <bltHash.h>

typedef char *Blt_Uid;

EXTERN Blt_Uid Blt_GetUid _ANSI_ARGS_((char *string));
EXTERN void Blt_FreeUid _ANSI_ARGS_((Blt_Uid uid));
EXTERN Blt_Uid Blt_FindUid _ANSI_ARGS_((char *string));

#if (TCL_MAJOR_VERSION >= 8)
EXTERN int Blt_GetArrayFromObj _ANSI_ARGS_((Tcl_Interp *interp, 
	Tcl_Obj *objPtr, Blt_HashTable **tablePtrPtr));
EXTERN Tcl_Obj *Blt_NewArrayObj _ANSI_ARGS_((int objc, Tcl_Obj *objv[]));
EXTERN void Blt_RegisterArrayObj _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int Blt_IsArrayObj _ANSI_ARGS_((Tcl_Obj *obj));
#endif /* TCL_MAJOR_VERSION >= 8 */

#endif /*_BLT_H*/







|

|

<





<


51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66

67
68
#endif

#include <bltVector.h>
#include <bltHash.h>

typedef char *Blt_Uid;

EXTERN Blt_Uid Blt_GetUid _ANSI_ARGS_((CONST char *string));
EXTERN void Blt_FreeUid _ANSI_ARGS_((Blt_Uid uid));
EXTERN Blt_Uid Blt_FindUid _ANSI_ARGS_((CONST char *string));


EXTERN int Blt_GetArrayFromObj _ANSI_ARGS_((Tcl_Interp *interp, 
	Tcl_Obj *objPtr, Blt_HashTable **tablePtrPtr));
EXTERN Tcl_Obj *Blt_NewArrayObj _ANSI_ARGS_((int objc, Tcl_Obj *objv[]));
EXTERN void Blt_RegisterArrayObj _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int Blt_IsArrayObj _ANSI_ARGS_((Tcl_Obj *obj));


#endif /*_BLT_H*/

Changes to jni/blt/src/blt.mak.

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUnixPipe.o \
		bltUtil.o \
		bltVector.o \
		bltVecMath.o \
		bltVecCmd.o \
		bltVecObjCmd.o \
		bltWatch.o  

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \







<







151
152
153
154
155
156
157

158
159
160
161
162
163
164
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUnixPipe.o \
		bltUtil.o \
		bltVector.o \
		bltVecMath.o \

		bltVecObjCmd.o \
		bltWatch.o  

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \

Changes to jni/blt/src/bltAlloc.c.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 *
 *	These global variables allow you to override the default
 *	memory allocation/deallocation routines, simply by setting the
 *	pointers to your own C functions.  By default, we try to use
 *	the same memory allocation scheme that Tcl is using: generally
 *	that's Tcl_Alloc and Tcl_Free.
 */
#ifdef WIN32

#ifdef __GNUC__
extern char *Tcl_Alloc _ANSI_ARGS_((unsigned int size));
extern void Tcl_Free _ANSI_ARGS_((char * ptr));
extern char *Tcl_Realloc _ANSI_ARGS_((char *ptr, unsigned int size));
#endif /*__GNUC__*/

Blt_MallocProc *Blt_MallocProcPtr = (Blt_MallocProc *)Tcl_Alloc;
Blt_FreeProc *Blt_FreeProcPtr = (Blt_FreeProc *)Tcl_Free; 
Blt_ReallocProc *Blt_ReallocProcPtr = (Blt_ReallocProc *)Tcl_Realloc; 

#else

/* 
 * Try to use the same memory allocator/deallocator that Tcl is
 * using. Before 8.1 it used malloc/free.
 */

#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
/* 
 * We're pointing to the private TclpAlloc/TclpFree instead of public
 * Tcl_Alloc/Tcl_Free routines because they don't automatically cause
 * a panic when not enough memory is available. There are cases (such 
 * as allocating a very large vector) where it's recoverable.
 *
 * Using private is dangerous.
 * Tcl changes mem functions for debug which will conflict then with BLT
 * stick to public API
 */
//EXTERN Blt_MallocProc TclpAlloc;
//EXTERN Blt_FreeProc TclpFree;
//EXTERN Blt_ReallocProc TclpRealloc;


//Blt_MallocProc *Blt_MallocProcPtr = TclpAlloc;
//Blt_FreeProc *Blt_FreeProcPtr = TclpFree; 
//Blt_ReallocProc *Blt_ReallocProcPtr = TclpRealloc;


Blt_MallocProc *Blt_MallocProcPtr = (Blt_MallocProc *)Tcl_Alloc;
Blt_FreeProc *Blt_FreeProcPtr = (Blt_FreeProc *)Tcl_Free; 
Blt_ReallocProc *Blt_ReallocProcPtr = (Blt_ReallocProc *)Tcl_Realloc; 

#else

Blt_MallocProc *Blt_MallocProcPtr = malloc;
Blt_FreeProc *Blt_FreeProcPtr = free; 
Blt_ReallocProc *Blt_ReallocProcPtr = realloc;

#endif /* >= 8.1.0 */
#endif /* WIN32 */

void *
Blt_Calloc(nElems, sizeOfElem)
    unsigned int nElems; 
    size_t sizeOfElem;
{
    char *ptr;







<
<
<
<
<
<
<
<
<
<
<
<
<






<










<
<
<

>
|
|
|
<
>



<
<
<
<
<
<
<
<
|







11
12
13
14
15
16
17













18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33



34
35
36
37
38

39
40
41
42








43
44
45
46
47
48
49
50
 *
 *	These global variables allow you to override the default
 *	memory allocation/deallocation routines, simply by setting the
 *	pointers to your own C functions.  By default, we try to use
 *	the same memory allocation scheme that Tcl is using: generally
 *	that's Tcl_Alloc and Tcl_Free.
 */














/* 
 * Try to use the same memory allocator/deallocator that Tcl is
 * using. Before 8.1 it used malloc/free.
 */


/* 
 * We're pointing to the private TclpAlloc/TclpFree instead of public
 * Tcl_Alloc/Tcl_Free routines because they don't automatically cause
 * a panic when not enough memory is available. There are cases (such 
 * as allocating a very large vector) where it's recoverable.
 *
 * Using private is dangerous.
 * Tcl changes mem functions for debug which will conflict then with BLT
 * stick to public API
 */




#ifdef USE_TCL_STUBS
Blt_MallocProc *Blt_MallocProcPtr = NULL;
Blt_FreeProc *Blt_FreeProcPtr = NULL;
Blt_ReallocProc *Blt_ReallocProcPtr = NULL;

#else
Blt_MallocProc *Blt_MallocProcPtr = (Blt_MallocProc *)Tcl_Alloc;
Blt_FreeProc *Blt_FreeProcPtr = (Blt_FreeProc *)Tcl_Free; 
Blt_ReallocProc *Blt_ReallocProcPtr = (Blt_ReallocProc *)Tcl_Realloc; 








#endif

void *
Blt_Calloc(nElems, sizeOfElem)
    unsigned int nElems; 
    size_t sizeOfElem;
{
    char *ptr;

Changes to jni/blt/src/bltArrayObj.c.

42
43
44
45
46
47
48


















































49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







74
75
76
77
78
79
80
..
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
190
191
192
193
194
195
196
197
198



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
				 * from one object to another. */
    UpdateStringOfArray,	/* Creates string representation from
				 * an object's internal representation. */
    SetArrayFromAny,		/* Creates valid internal representation 
				 * from an object's string representation. */
};



















































static int
SetArrayFromAny(interp, objPtr)
    Tcl_Interp *interp;
    Tcl_Obj *objPtr;
{
    Blt_HashEntry *hPtr;
    Blt_HashTable *tablePtr;
    Tcl_Obj *elemObjPtr;
    Tcl_ObjType *oldTypePtr = (Tcl_ObjType *) objPtr->typePtr;
    char **elemArr;
    char *string;
    int isNew;
    int nElem;
    register int i;

    if (objPtr->typePtr == &arrayObjType) {
	return TCL_OK;
    }
    /*
     * Get the string representation. Make it up-to-date if necessary.
     */
    string = Tcl_GetString(objPtr);
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }







    tablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(tablePtr);
    Blt_InitHashTable(tablePtr, BLT_STRING_KEYS);
    for (i = 0; i < nElem; i += 2) {
	hPtr = Blt_CreateHashEntry(tablePtr, elemArr[i], &isNew);
	elemObjPtr = Tcl_NewStringObj(elemArr[i + 1], -1);
	Blt_SetHashValue(hPtr, elemObjPtr);
................................................................................
    }
    objPtr->internalRep.otherValuePtr = (VOID *)tablePtr;
    objPtr->typePtr = &arrayObjType;
    Blt_Free(elemArr);

    return TCL_OK;
}


static void
DupArrayInternalRep(srcPtr, destPtr)
    Tcl_Obj *srcPtr;		/* Object with internal rep to copy. */
    Tcl_Obj *destPtr;		/* Object with internal rep to set. */
{
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Blt_HashTable *srcTablePtr, *destTablePtr;
    Tcl_Obj *valueObjPtr;
    char *key;
    int isNew;

    srcTablePtr = (Blt_HashTable *)srcPtr->internalRep.otherValuePtr;
    destTablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(destTablePtr);
    Blt_InitHashTable(destTablePtr, BLT_STRING_KEYS);
    for (hPtr = Blt_FirstHashEntry(srcTablePtr, &cursor); hPtr != NULL;
	 hPtr = Blt_NextHashEntry(&cursor)) {
	key = Blt_GetHashKey(srcTablePtr, hPtr);
	Blt_CreateHashEntry(destTablePtr, key, &isNew);
	valueObjPtr = (Tcl_Obj *)Blt_GetHashValue(hPtr);

	Blt_SetHashValue(hPtr, valueObjPtr);

	/* Make sure we increment the reference count now that both
	 * array objects are using the same elements. */
	Tcl_IncrRefCount(valueObjPtr);
    }
    Tcl_InvalidateStringRep(destPtr);
    destPtr->internalRep.otherValuePtr = (VOID *)destTablePtr;
................................................................................

    tablePtr = (Blt_HashTable *)objPtr->internalRep.otherValuePtr;
    Tcl_DStringInit(&dString);
    for (hPtr = Blt_FirstHashEntry(tablePtr, &cursor); hPtr != NULL;
	 hPtr = Blt_NextHashEntry(&cursor)) {
	elemObjPtr = (Tcl_Obj *)Blt_GetHashValue(hPtr);
	Tcl_DStringAppendElement(&dString, Blt_GetHashKey(tablePtr, hPtr));
	Tcl_DStringAppendElement(&dString, Tcl_GetString(elemObjPtr));
    }
    objPtr->bytes = Blt_Strdup(Tcl_DStringValue(&dString));
    objPtr->length = strlen(Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);
}

static void
................................................................................
    int objc;
    Tcl_Obj *objv[];
{
    Blt_HashEntry *hPtr;
    Blt_HashTable *tablePtr;
    Tcl_Obj *arrayObjPtr, *objPtr;
    int isNew;
    register int i;




    tablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(tablePtr);
    Blt_InitHashTable(tablePtr, BLT_STRING_KEYS);

    for (i = 0; i < objc; i += 2) {
	hPtr = Blt_CreateHashEntry(tablePtr, Tcl_GetString(objv[i]), &isNew);
	if ((i + 1) == objc) {
	    objPtr = bltEmptyStringObjPtr;
	} else {
	    objPtr = objv[i+1];
	}
	Tcl_IncrRefCount(objPtr);
	if (!isNew) {
	    Tcl_Obj *oldObjPtr;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








|




|











>
>
>
>
>
>
>







 







>






|













|

>
|







 







|







 







|

>
>
>







|







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
				 * from one object to another. */
    UpdateStringOfArray,	/* Creates string representation from
				 * an object's internal representation. */
    SetArrayFromAny,		/* Creates valid internal representation 
				 * from an object's string representation. */
};

#if 1     
static int
SetArrayFromAny(interp, objPtr)
    Tcl_Interp *interp;
    Tcl_Obj *objPtr;
{
    Blt_HashEntry *hPtr;
    Blt_HashTable *tablePtr;
    Tcl_Obj *elemObjPtr, **vobjv;
    CONST Tcl_ObjType *oldTypePtr;
    char *string;
    int isNew;
    int nElem;
    int i;

    if (objPtr->typePtr == &arrayObjType) {
	return TCL_OK;
    }
    if (Tcl_ListObjGetElements(interp, objPtr, &nElem, &vobjv) != TCL_OK) {
        return TCL_ERROR;
    }
    if (nElem%2) {
        if (interp != NULL) {
	    string = Tcl_GetString(objPtr);
            Tcl_AppendResult(interp, "odd length: ", string, 0);
        }
        return TCL_ERROR;
    }
    tablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(tablePtr);
    Blt_InitHashTable(tablePtr, BLT_STRING_KEYS);
    for (i = 0; i < nElem; i += 2) {
	hPtr = Blt_CreateHashEntry(tablePtr, Tcl_GetString(vobjv[i]), &isNew);
	elemObjPtr = vobjv[i + 1];
	Blt_SetHashValue(hPtr, elemObjPtr);

	/* Make sure we increment the reference count */
	Tcl_IncrRefCount(elemObjPtr);
    }
    
    oldTypePtr = objPtr->typePtr;
    if ((oldTypePtr != NULL) && (oldTypePtr->freeIntRepProc != NULL)) {
        oldTypePtr->freeIntRepProc(objPtr);
    }
    objPtr->internalRep.otherValuePtr = (VOID *)tablePtr;
    objPtr->typePtr = &arrayObjType;

    return TCL_OK;
}
#else
static int
SetArrayFromAny(interp, objPtr)
    Tcl_Interp *interp;
    Tcl_Obj *objPtr;
{
    Blt_HashEntry *hPtr;
    Blt_HashTable *tablePtr;
    Tcl_Obj *elemObjPtr;
    Tcl_ObjType *oldTypePtr = objPtr->typePtr;
    char **elemArr;
    char *string;
    int isNew;
    int nElem;
    int i;

    if (objPtr->typePtr == &arrayObjType) {
	return TCL_OK;
    }
    /*
     * Get the string representation. Make it up-to-date if necessary.
     */
    string = Tcl_GetString(objPtr);
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }
    if (nElem%2) {
        if (interp != NULL) {
            Tcl_AppendResult(interp, "odd length: ", string, 0);
        }
        Blt_Free(elemArr);
        return TCL_ERROR;
    }
    tablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(tablePtr);
    Blt_InitHashTable(tablePtr, BLT_STRING_KEYS);
    for (i = 0; i < nElem; i += 2) {
	hPtr = Blt_CreateHashEntry(tablePtr, elemArr[i], &isNew);
	elemObjPtr = Tcl_NewStringObj(elemArr[i + 1], -1);
	Blt_SetHashValue(hPtr, elemObjPtr);
................................................................................
    }
    objPtr->internalRep.otherValuePtr = (VOID *)tablePtr;
    objPtr->typePtr = &arrayObjType;
    Blt_Free(elemArr);

    return TCL_OK;
}
#endif

static void
DupArrayInternalRep(srcPtr, destPtr)
    Tcl_Obj *srcPtr;		/* Object with internal rep to copy. */
    Tcl_Obj *destPtr;		/* Object with internal rep to set. */
{
    Blt_HashEntry *hPtr, *h2Ptr;
    Blt_HashSearch cursor;
    Blt_HashTable *srcTablePtr, *destTablePtr;
    Tcl_Obj *valueObjPtr;
    char *key;
    int isNew;

    srcTablePtr = (Blt_HashTable *)srcPtr->internalRep.otherValuePtr;
    destTablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(destTablePtr);
    Blt_InitHashTable(destTablePtr, BLT_STRING_KEYS);
    for (hPtr = Blt_FirstHashEntry(srcTablePtr, &cursor); hPtr != NULL;
	 hPtr = Blt_NextHashEntry(&cursor)) {
	key = Blt_GetHashKey(srcTablePtr, hPtr);
	h2Ptr = Blt_CreateHashEntry(destTablePtr, key, &isNew);
	valueObjPtr = (Tcl_Obj *)Blt_GetHashValue(hPtr);
        assert (valueObjPtr != NULL);
	Blt_SetHashValue(h2Ptr, valueObjPtr );

	/* Make sure we increment the reference count now that both
	 * array objects are using the same elements. */
	Tcl_IncrRefCount(valueObjPtr);
    }
    Tcl_InvalidateStringRep(destPtr);
    destPtr->internalRep.otherValuePtr = (VOID *)destTablePtr;
................................................................................

    tablePtr = (Blt_HashTable *)objPtr->internalRep.otherValuePtr;
    Tcl_DStringInit(&dString);
    for (hPtr = Blt_FirstHashEntry(tablePtr, &cursor); hPtr != NULL;
	 hPtr = Blt_NextHashEntry(&cursor)) {
	elemObjPtr = (Tcl_Obj *)Blt_GetHashValue(hPtr);
	Tcl_DStringAppendElement(&dString, Blt_GetHashKey(tablePtr, hPtr));
	Tcl_DStringAppendElement(&dString, elemObjPtr == NULL?"":Tcl_GetString(elemObjPtr));
    }
    objPtr->bytes = Blt_Strdup(Tcl_DStringValue(&dString));
    objPtr->length = strlen(Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);
}

static void
................................................................................
    int objc;
    Tcl_Obj *objv[];
{
    Blt_HashEntry *hPtr;
    Blt_HashTable *tablePtr;
    Tcl_Obj *arrayObjPtr, *objPtr;
    int isNew;
    int i;

    if (objc % 2) {
        return NULL;
    }
    tablePtr = Blt_Malloc(sizeof(Blt_HashTable));
    assert(tablePtr);
    Blt_InitHashTable(tablePtr, BLT_STRING_KEYS);

    for (i = 0; i < objc; i += 2) {
	hPtr = Blt_CreateHashEntry(tablePtr, Tcl_GetString(objv[i]), &isNew);
	if ((i + 1) == objc) {
	    objPtr = Tcl_NewStringObj("",-1);
	} else {
	    objPtr = objv[i+1];
	}
	Tcl_IncrRefCount(objPtr);
	if (!isNew) {
	    Tcl_Obj *oldObjPtr;

Changes to jni/blt/src/bltBgexec.c.

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
...
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
...
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
...
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
...
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
...
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
...
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
....
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
....
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
....
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
....
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
....
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
....
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
....
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
....
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
....
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
....
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
....
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
....
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
....
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
....
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
#include <sys/param.h>
#endif
#include <sys/types.h>

#include "bltWait.h"
#include "bltSwitch.h"

#if (TCL_MAJOR_VERSION == 7)
#define FILEHANDLER_USES_TCLFILES 1
#else
typedef int Tcl_File;
#endif

static Tcl_CmdProc BgexecCmd;

#ifdef WIN32
typedef struct {
    DWORD pid;
    HANDLE hProcess;
} Process;
#else
typedef int Process;
#endif

#if (TCL_VERSION_NUMBER <  _VERSION(8,1,0)) 
typedef void *Tcl_Encoding;	/* Make up dummy type for encoding.  */
#endif

#define ENCODING_ASCII		((Tcl_Encoding)NULL)
#define ENCODING_BINARY		((Tcl_Encoding)1)

/*
 *	As of Tcl 7.6, we're using our own version of the old
 *	Tcl_CreatePipeline routine.  I would have tried to use
 *	Tcl_OpenCommandChannel but you can't get at the array of
................................................................................
				 * updated as data is read from the
				 * pipe. */

    char **updateCmd;		/* Start of a Tcl command executed
				 * whenever data is read from the
				 * pipe. */

#if (TCL_MAJOR_VERSION >= 8)
    Tcl_Obj **objv;		/*  */
    int objc;			/*  */
#endif

    int flags;			

    Tcl_File file;		/* Used for backward compatability
				 * with Tcl 7.5 */
    Tcl_Encoding encoding;
    int fd;			/* File descriptor of the pipe. */
    int status;

................................................................................

static Blt_SwitchParseProc StringToSignal;
static Blt_SwitchCustom killSignalSwitch =
{
    StringToSignal, (Blt_SwitchFreeProc *)NULL, (ClientData)0,
};

static Blt_SwitchSpec switchSpecs[] = 
{
    {BLT_SWITCH_STRING, "-decodeoutput", 
         Blt_Offset(BackgroundInfo, outputEncodingName), 0},
    {BLT_SWITCH_STRING, "-decodeerror", 
         Blt_Offset(BackgroundInfo, errorEncodingName), 0},
    {BLT_SWITCH_BOOLEAN, "-echo", 
         Blt_Offset(BackgroundInfo, sink2.echo), 0},
    {BLT_SWITCH_STRING, "-error", 
         Blt_Offset(BackgroundInfo, sink2.doneVar), 0},
    {BLT_SWITCH_STRING, "-update", 
	Blt_Offset(BackgroundInfo, sink1.updateVar), 0},
    {BLT_SWITCH_STRING, "-output", 
        Blt_Offset(BackgroundInfo, sink1.doneVar), 0},
    {BLT_SWITCH_STRING, "-lasterror", 
	Blt_Offset(BackgroundInfo, sink2.updateVar), 0},
    {BLT_SWITCH_STRING, "-lastoutput", 
	Blt_Offset(BackgroundInfo, sink1.updateVar), 0},
    {BLT_SWITCH_LIST, "-onerror", 
	Blt_Offset(BackgroundInfo, sink2.updateCmd), 0},
    {BLT_SWITCH_LIST, "-onoutput", 
	Blt_Offset(BackgroundInfo, sink1.updateCmd), 0},
    {BLT_SWITCH_BOOLEAN, "-keepnewline", 
	Blt_Offset(BackgroundInfo, keepNewline), 0},
    {BLT_SWITCH_INT, "-check",
	Blt_Offset(BackgroundInfo, interval), 0},
    {BLT_SWITCH_CUSTOM, "-killsignal", 
	Blt_Offset(BackgroundInfo, signalNum), 0, &killSignalSwitch},
    {BLT_SWITCH_BOOLEAN, "-linebuffered", 
	Blt_Offset(BackgroundInfo, lineBuffered), 0},
    {BLT_SWITCH_END, NULL, 0, 0}
};

static char *VariableProc _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, char *part1, char *part2, int flags));
static void TimerProc _ANSI_ARGS_((ClientData clientData));
................................................................................
    }
    if (isdigit(UCHAR(string[0]))) {
	if (Tcl_GetInt(interp, string, &signalNum) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	char *name;
	register SignalId *sigPtr;

	name = string;

	/*  Clip off any "SIG" prefix from the signal name */
	if ((name[0] == 'S') && (name[1] == 'I') && (name[2] == 'G')) {
	    name += 3;
	}
................................................................................
 *----------------------------------------------------------------------
 *
 * NextBlock --
 *
 *	Returns the next block of data since the last time this
 *	routine was called.
 *
 *---------------------------------------------------------------------- 
 */
static unsigned char *
NextBlock(sinkPtr, lengthPtr)
    Sink *sinkPtr;
    int *lengthPtr;
{
    unsigned char *string;
    int length;

    string = sinkPtr->byteArr + sinkPtr->lastMark;
    length = sinkPtr->mark - sinkPtr->lastMark;
    sinkPtr->lastMark = sinkPtr->mark;
    if (length > 0) {
	if ((!(sinkPtr->flags & SINK_KEEP_NL)) && 
	    (string[length - 1] == '\n')) {
	    length--;
	}
	*lengthPtr = length;
	return string;
    }
    return NULL;
................................................................................
NextLine(sinkPtr, lengthPtr)
    Sink *sinkPtr;
    int *lengthPtr;
{
    if (sinkPtr->mark > sinkPtr->lastMark) {
	unsigned char *string;
	int newBytes;
	register int i;

	string = sinkPtr->byteArr + sinkPtr->lastMark;
	newBytes = sinkPtr->mark - sinkPtr->lastMark;
	for (i = 0; i < newBytes; i++) {
	    if (string[i] == '\n') {
		int length;
		
		length = i + 1;
		sinkPtr->lastMark += length;
		if (!(sinkPtr->flags & SINK_KEEP_NL)) {
		    length--;		/* Backup over the newline. */
		}
		*lengthPtr = length;
		return string;
................................................................................
 * ResetSink --
 *
 *	Removes the bytes already processed from the buffer, possibly
 *	resetting it to empty.  This used when we don't care about
 *	keeping all the data collected from the channel (no -output
 *	flag and the process is detached).
 *
 *---------------------------------------------------------------------- 
 */
static void
ResetSink(sinkPtr)
    Sink *sinkPtr;
{ 
    if ((sinkPtr->flags & SINK_BUFFERED) && 
	(sinkPtr->fill > sinkPtr->lastMark)) {
	register size_t i, j;

	/* There may be bytes remaining in the buffer, awaiting
	 * another read before we see the next newline.  So move the
	 * bytes to the front of the array. */

 	for (i = 0, j = sinkPtr->lastMark; j < sinkPtr->fill; i++, j++) {
	    sinkPtr->byteArr[i] = sinkPtr->byteArr[j];
................................................................................
    sinkPtr->size = DEF_BUFFER_SIZE;
    sinkPtr->encoding = encoding;
    if (bgPtr->keepNewline) {
	sinkPtr->flags |= SINK_KEEP_NL;
    }
    if (bgPtr->lineBuffered) {
	sinkPtr->flags |= SINK_BUFFERED;
    }	
    if ((sinkPtr->updateCmd != NULL) || 
	(sinkPtr->updateVar != NULL) ||
	(sinkPtr->echo)) {
	sinkPtr->flags |= SINK_NOTIFY;
    }
#if (TCL_MAJOR_VERSION >= 8)
    if (sinkPtr->updateCmd != NULL) {
	Tcl_Obj **objArr;
	char **p;
	int count;
	register int i;

	count = 0;
	for (p = sinkPtr->updateCmd; *p != NULL; p++) {
	    count++;
	}
	objArr = Blt_Malloc((count + 1) * sizeof(Tcl_Obj *));
	for (i = 0; i < count; i++) {
	    objArr[i] = Tcl_NewStringObj(sinkPtr->updateCmd[i], -1);
	    Tcl_IncrRefCount(objArr[i]);
	}
	sinkPtr->objv = objArr;
	sinkPtr->objc = count + 1;
    }
#endif
    ResetSink(sinkPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * FreeSinkBuffer --
................................................................................
    Sink *sinkPtr;
{
    if (sinkPtr->byteArr != sinkPtr->staticSpace) {
	Blt_Free(sinkPtr->byteArr);
    }
    sinkPtr->fd = -1;
    sinkPtr->file = (Tcl_File)NULL;
#if (TCL_MAJOR_VERSION >= 8)
    if (sinkPtr->objv != NULL) {
	register int i;

	for (i = 0; i < sinkPtr->objc - 1; i++) {
	    Tcl_DecrRefCount(sinkPtr->objv[i]);
	}
	Blt_Free(sinkPtr->objv);
    }
#endif
}


/*
 *----------------------------------------------------------------------
 *
 * ExtendSinkBuffer --
 *
 *	Doubles the size of the current buffer.
................................................................................
 *----------------------------------------------------------------------
 */
static int
ExtendSinkBuffer(sinkPtr)
    Sink *sinkPtr;
{
    unsigned char *arrayPtr;
    register unsigned char *srcPtr, *destPtr, *endPtr;
    /*
     * Allocate a new array, double the old size
     */
    sinkPtr->size += sinkPtr->size;
    arrayPtr = Blt_Malloc(sizeof(unsigned char) * sinkPtr->size);
    if (arrayPtr == NULL) {
	return -1;
................................................................................
 *----------------------------------------------------------------------
 */
static void
ReadBytes(sinkPtr)
    Sink *sinkPtr;
{
    int nBytes, bytesLeft;
    register int i;
    unsigned char *array;

    /*
     * ------------------------------------------------------------------
     *
     * 	Worry about indefinite postponement.
     *
................................................................................
    }
    sinkPtr->status = nBytes;
}

#define IsOpenSink(sinkPtr)  ((sinkPtr)->fd != -1)

static void
CloseSink(interp, sinkPtr) 
    Tcl_Interp *interp;
    Sink *sinkPtr;
{
    if (IsOpenSink(sinkPtr)) {
	close(sinkPtr->fd);
#ifdef FILEHANDLER_USES_TCLFILES
	Tcl_DeleteFileHandler(sinkPtr->file);
................................................................................

#if WINDEBUG
	PurifyPrintf("CloseSink: set done var %s\n", sinkPtr->name);
#endif
	if (sinkPtr->doneVar != NULL) {
	    unsigned char *data;
	    size_t length;
	    /* 
	     * If data is to be collected, set the "done" variable
	     * with the contents of the buffer.  
	     */
	    GetSinkData(sinkPtr, &data, &length);
#if (TCL_VERSION_NUMBER <  _VERSION(8,1,0)) 
	    data[length] = '\0';
	    if (Tcl_SetVar(interp, sinkPtr->doneVar, data, 
			   TCL_GLOBAL_ONLY) == NULL) {
		Tcl_BackgroundError(interp);
	    }
#else
	    if (Tcl_SetVar2Ex(interp, sinkPtr->doneVar, NULL, 
			      Tcl_NewByteArrayObj(data, length),
			      (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG)) == NULL) {
		Tcl_BackgroundError(interp);
	    }
#endif
	}
#if WINDEBUG
	PurifyPrintf("CloseSink %s: done\n", sinkPtr->name);
#endif
    }
}
/*
................................................................................
#ifdef WIN32
    size_t oldMark;

    oldMark = sinkPtr->mark;
#endif
    if (sinkPtr->encoding == ENCODING_BINARY) { /* binary */
	/* No translation needed. */
	sinkPtr->mark = sinkPtr->fill; 
    } else if (sinkPtr->encoding == ENCODING_ASCII) { /* ascii */
#if (TCL_VERSION_NUMBER <  _VERSION(8,1,0)) 
	/* Convert NUL bytes to question marks. */
	srcPtr = sinkPtr->byteArr + sinkPtr->mark;
	endPtr = sinkPtr->byteArr + sinkPtr->fill;
	while (srcPtr < endPtr) {
	    if (*srcPtr == '\0') {
		*srcPtr = '?';
	    }
	    srcPtr++;
	}
#endif /* < 8.1.0 */
	/* One-to-one translation. mark == fill. */
	sinkPtr->mark = sinkPtr->fill;
#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
    } else { /* unicode. */
	int nSrcCooked, nCooked;
	int result;
	size_t cookedSize, spaceLeft, needed;
	size_t nRaw, nLeftOver;
	unsigned char *destPtr;
	unsigned char *raw, *cooked;
	unsigned char leftover[100];
	
	raw = sinkPtr->byteArr + sinkPtr->mark;
	nRaw = sinkPtr->fill - sinkPtr->mark;
	/* Ideally, the cooked buffer size should be smaller */
	cookedSize = nRaw * TCL_UTF_MAX + 1;
	cooked = Blt_Malloc(cookedSize);
	result = Tcl_ExternalToUtf(interp, sinkPtr->encoding, 
			(char *)raw, nRaw, 0, NULL, (char *)cooked, 
			cookedSize, &nSrcCooked, &nCooked, NULL);
	nLeftOver = 0;
	if (result == TCL_CONVERT_MULTIBYTE) {
	    /* 
	     * Last multibyte sequence wasn't completed.  Save the
	     * extra characters in a temporary buffer.  
	     */
	    nLeftOver = (nRaw - nSrcCooked);
	    srcPtr = sinkPtr->byteArr + (sinkPtr->mark + nSrcCooked); 
	    endPtr = srcPtr + nLeftOver;
	    destPtr = leftover;
	    while (srcPtr < endPtr) {
		*destPtr++ = *srcPtr++;
	    }
	} 
	/*
	 * Create a bigger 
	 */
						 
	needed = nLeftOver + nCooked;
	spaceLeft = sinkPtr->size - sinkPtr->mark;
	if (spaceLeft >= needed) {
	    spaceLeft = ExtendSinkBuffer(sinkPtr);
	}
	assert(spaceLeft > needed);
	/* 
	 * Replace the characters from the mark with the translated 
	 * characters.
	 */
	srcPtr = cooked;
	endPtr = cooked + nCooked;
	destPtr = sinkPtr->byteArr + sinkPtr->mark;
	while (srcPtr < endPtr) {
	    *destPtr++ = *srcPtr++;
	}
	/* Add the number of newly translated characters to the mark */
	sinkPtr->mark += nCooked;
	
	srcPtr = leftover;
	endPtr = leftover + nLeftOver;
	while (srcPtr < endPtr) {
	    *destPtr++ = *srcPtr++;
	}
	sinkPtr->fill = sinkPtr->mark + nLeftOver;
#endif /* >= 8.1.0  */
    }
#ifdef WIN32
    /* 
     * Translate CRLF character sequences to LF characters.  We have to
     * do this after converting the string to UTF from UNICODE.
     */
    if (sinkPtr->encoding != ENCODING_BINARY) {
	int count;
	unsigned char *destPtr;

................................................................................
	return -1;
    }
#if WINDEBUG
    PurifyPrintf("WAITPID: waiting for 0x%x\n", child.hProcess);
#endif
    timeout = (flags & WNOHANG) ? 0 : INFINITE;
    status = WaitForSingleObject(child.hProcess, timeout);
				 
#if WINDEBUG
    PurifyPrintf("WAITPID: wait status is %d\n", status);
#endif
    switch (status) {
    case WAIT_FAILED:
	errno = ECHILD;
	*statusPtr = ECHILD;
................................................................................
    if ((proc.hProcess == NULL) || (proc.hProcess == INVALID_HANDLE_VALUE)) {
	errno = EINVAL;
	return -1;
    }

    EnumWindows(EnumWindowsProc, (LPARAM)&proc);

    /* 
     * Wait on the handle. If it signals, great. If it times out,
     * then call TerminateProcess on it.  
     *
     * On Windows 95/98 this also has the added benefit of stopping
     * KERNEL32.dll from dumping.  The 2 second number is arbitrary.
     * (1 second seems to fail intermittently).
     */
    status = WaitForSingleObject(proc.hProcess, 2000);
    if (status == WAIT_OBJECT_0) {
................................................................................
	return -1;
    }
    return 0;
}

#endif /* WIN32 */

#if (TCL_VERSION_NUMBER < _VERSION(8,1,0)) 

static void
NotifyOnUpdate(interp, sinkPtr, data, nBytes)
    Tcl_Interp *interp;
    Sink *sinkPtr;
    unsigned char *data;
    int nBytes;
{
    char save;

#if WINDEBUG_0
    PurifyPrintf("read %s\n", data);
#endif
    if (data[0] == '\0') {
	return;
    }
    save = data[nBytes];
    data[nBytes] = '\0';
    if (sinkPtr->echo) {
	Tcl_Channel channel;
	
	channel = Tcl_GetStdChannel(TCL_STDERR);
	if (channel == NULL) {
	    Tcl_AppendResult(interp, "can't get stderr channel", (char *)NULL);
	    Tcl_BackgroundError(interp);
	    sinkPtr->echo = FALSE;
	} else {
	    Tcl_Write(channel, data, nBytes);
	    if (save == '\n') {
		Tcl_Write(channel, "\n", 1);
	    }
	    Tcl_Flush(channel);
	}
    }
    if (sinkPtr->updateCmd != NULL) {
	Tcl_DString dString;
	int result;
	register char **p;

	Tcl_DStringInit(&dString);
	for (p = sinkPtr->updateCmd; *p != NULL; p++) {
	    Tcl_DStringAppendElement(&dString, *p);
	}
	Tcl_DStringAppendElement(&dString, data);
	result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dString));
	Tcl_DStringFree(&dString);
	if (result != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
    }
    if (sinkPtr->updateVar != NULL) {
	int flags;
	char *result;

	flags = (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
	result = Tcl_SetVar(interp, sinkPtr->updateVar, data, flags);
	if (result == NULL) {
	    Tcl_BackgroundError(interp);
	}
    }
    data[nBytes] = save;
}

#else 

static void
NotifyOnUpdate(interp, sinkPtr, data, nBytes)
    Tcl_Interp *interp;
    Sink *sinkPtr;
    unsigned char *data;
    int nBytes;
{
................................................................................
    PurifyPrintf("read %s\n", data);
#endif
    if ((nBytes == 0) || (data[0] == '\0')) {
	return;
    }
    if (sinkPtr->echo) {
	Tcl_Channel channel;
	
	channel = Tcl_GetStdChannel(TCL_STDERR);
	if (channel == NULL) {
	    Tcl_AppendResult(interp, "can't get stderr channel", (char *)NULL);
	    Tcl_BackgroundError(interp);
	    sinkPtr->echo = FALSE;
	} else {
	    if (data[nBytes] == '\n') {
................................................................................
	if (result != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
    }
    if (sinkPtr->updateVar != NULL) {
	Tcl_Obj *result;

	result = Tcl_SetVar2Ex(interp, sinkPtr->updateVar, NULL, objPtr, 
	       (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
	if (result == NULL) {
	    Tcl_BackgroundError(interp);
	}
    }
    Tcl_DecrRefCount(objPtr);
}

#endif /* < 8.1.0 */

static int
CollectData(bgPtr, sinkPtr)
    BackgroundInfo *bgPtr;
    Sink *sinkPtr;
{
    if ((bgPtr->detached) && (sinkPtr->doneVar == NULL)) {
	ResetSink(sinkPtr);
    }
    ReadBytes(sinkPtr);
    CookSink(bgPtr->interp, sinkPtr);
    if ((sinkPtr->mark > sinkPtr->lastMark) && 
	(sinkPtr->flags & SINK_NOTIFY)) {
	unsigned char *data;
	int length;

	if (sinkPtr->flags & SINK_BUFFERED) {
	    /* For line-by-line updates, call NotifyOnUpdate for each
	     * new complete line.  */
................................................................................

static void
DisableTriggers(bgPtr)
    BackgroundInfo *bgPtr;	/* Background info record. */
{

    if (bgPtr->traced) {
	Tcl_UntraceVar(bgPtr->interp, bgPtr->statVar, TRACE_FLAGS, 
		VariableProc, bgPtr);
	bgPtr->traced = FALSE;
    }
    if (IsOpenSink(&bgPtr->sink1)) {
	CloseSink(bgPtr->interp, &bgPtr->sink1);
    }
    if (IsOpenSink(&bgPtr->sink2)) {
................................................................................
DestroyBackgroundInfo(bgPtr)
    BackgroundInfo *bgPtr;	/* Background info record. */
{
    DisableTriggers(bgPtr);
    FreeSinkBuffer(&bgPtr->sink2);
    FreeSinkBuffer(&bgPtr->sink1);
    if (bgPtr->procArr != NULL) {
	register int i;

	for (i = 0; i < bgPtr->nProcs; i++) {
	    if (bgPtr->signalNum > 0) {
		kill(bgPtr->procArr[i], bgPtr->signalNum);
	    }
#ifdef WIN32
	    Tcl_DetachPids(1, (Tcl_Pid *)&bgPtr->procArr[i].pid);
#else
#if (TCL_MAJOR_VERSION == 7)
	    Tcl_DetachPids(1, &bgPtr->procArr[i]);
#else
	    Tcl_DetachPids(1, (Tcl_Pid *)bgPtr->procArr[i]);
#endif /* TCL_MAJOR_VERSION == 7 */
#endif /* WIN32 */
	}
    }
    FreeBackgroundInfo(bgPtr);
    Tcl_ReapDetachedProcs();
}

................................................................................
    int flags)
{
    if (flags & TRACE_FLAGS) {
	BackgroundInfo *bgPtr = clientData;

	/* Kill all child processes that remain alive. */
	if ((bgPtr->procArr != NULL) && (bgPtr->signalNum > 0)) {
	    register int i;

	    for (i = 0; i < bgPtr->nProcs; i++) {
		kill(bgPtr->procArr[i], bgPtr->signalNum);
	    }
	}
    }
    return NULL;
................................................................................
 *----------------------------------------------------------------------
 */
static void
TimerProc(clientData)
    ClientData clientData;
{
    BackgroundInfo *bgPtr = clientData;
    register int i;
    unsigned int lastPid;
    int pid;
    enum PROCESS_STATUS { 
	PROCESS_EXITED, PROCESS_STOPPED, PROCESS_KILLED, PROCESS_UNKNOWN
    } pcode;
    WAIT_STATUS_TYPE waitStatus, lastStatus;
    int nLeft;			/* Number of processes still not reaped */
    char string[200];
    Tcl_DString dString;
    int code;
................................................................................
	     */
	    lastStatus = waitStatus;
	    lastPid = (unsigned int)pid;
	}
    }
    bgPtr->nProcs = nLeft;

    if ((nLeft > 0) || (IsOpenSink(&bgPtr->sink1)) || 
	(IsOpenSink(&bgPtr->sink2))) {
	/* Keep polling for the status of the children that are left */
	bgPtr->timerToken = Tcl_CreateTimerHandler(bgPtr->interval, TimerProc,
	   bgPtr);
#if WINDEBUG
	PurifyPrintf("schedule TimerProc(nProcs=%d)\n", nLeft);
#endif
................................................................................
#endif
    Tcl_DStringAppendElement(&dString, Blt_Itoa(code));
    switch(pcode) {
    case PROCESS_EXITED:
	Tcl_DStringAppendElement(&dString, "child completed normally");
	break;
    case PROCESS_KILLED:
	Tcl_DStringAppendElement(&dString, 
				Tcl_SignalMsg((int)(WTERMSIG(lastStatus))));
	break;
    case PROCESS_STOPPED:
	Tcl_DStringAppendElement(&dString, 
		 Tcl_SignalMsg((int)(WSTOPSIG(lastStatus))));
	break;
    case PROCESS_UNKNOWN:
	sprintf(string, "child completed with unknown status 0x%x",
	    *((int *)&lastStatus));
	Tcl_DStringAppendElement(&dString, string);
	break;
    }
    if (bgPtr->exitCodePtr != NULL) {
	*bgPtr->exitCodePtr = code;
    }
    DisableTriggers(bgPtr);
    result = Tcl_SetVar(bgPtr->interp, bgPtr->statVar, 
	Tcl_DStringValue(&dString), TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
    Tcl_DStringFree(&dString);
    if (result == NULL) {
	Tcl_BackgroundError(bgPtr->interp);
    }
    if (bgPtr->detached) {
	DestroyBackgroundInfo(bgPtr);
................................................................................
    bgPtr->detached = detached;
    bgPtr->keepNewline = FALSE;
    bgPtr->statVar = Blt_Strdup(argv[1]);

    /* Try to clean up any detached processes */
    Tcl_ReapDetachedProcs();

    i = Blt_ProcessSwitches(interp, switchSpecs, argc - 2, argv + 2, 
	(char *)bgPtr, BLT_SWITCH_ARGV_PARTIAL);
    if (i < 0) {
	FreeBackgroundInfo(bgPtr);
	return TCL_ERROR;
    }
    i += 2;
    /* Must be at least one argument left as the command to execute. */
................................................................................
    bgPtr->traced = TRUE;

    encoding = ENCODING_ASCII;
    if (bgPtr->outputEncodingName != NULL) {
	if (strcmp(bgPtr->outputEncodingName, "binary") == 0) {
	    encoding = ENCODING_BINARY;
	} else {
#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
	    encoding = Tcl_GetEncoding(interp, bgPtr->outputEncodingName);
	    if (encoding == NULL) {
		goto error;
	    }
#endif
	}
    }
    InitSink(bgPtr, &bgPtr->sink1, "stdout", encoding);
    if (bgPtr->errorEncodingName != NULL) {
	if (strcmp(bgPtr->errorEncodingName, "binary") == 0) {
	    encoding = ENCODING_BINARY;
	} else {
#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
	    encoding = Tcl_GetEncoding(interp, bgPtr->errorEncodingName);
	    if (encoding == NULL) {
		goto error;
	    }
#endif
	}
    }
    InitSink(bgPtr, &bgPtr->sink2, "stderr", encoding);

    outFdPtr = errFdPtr = (int *)NULL;
#ifdef WIN32
    if ((!bgPtr->detached) || 
	(bgPtr->sink1.doneVar != NULL) || 
	(bgPtr->sink1.updateVar != NULL) || 
	(bgPtr->sink1.updateCmd != NULL)) {
	outFdPtr = &bgPtr->sink1.fd;
    }
#else
    outFdPtr = &bgPtr->sink1.fd;
#endif
    if ((bgPtr->sink2.doneVar != NULL) || 
	(bgPtr->sink2.updateVar != NULL) ||
	(bgPtr->sink2.updateCmd != NULL) || 
	(bgPtr->sink2.echo)) {
	errFdPtr = &bgPtr->sink2.fd;
    }
    nProcs = Blt_CreatePipeline(interp, argc - i, argv + i, &pidPtr,
	(int *)NULL, outFdPtr, errFdPtr);
    if (nProcs < 0) {
	goto error;
................................................................................
    } else if (CreateSinkHandler(bgPtr, &bgPtr->sink1, StdoutProc) != TCL_OK) {
	goto error;
    }
    if ((bgPtr->sink2.fd != -1) &&
	(CreateSinkHandler(bgPtr, &bgPtr->sink2, StderrProc) != TCL_OK)) {
 	goto error;
    }
    if (bgPtr->detached) {	
	char string[200];

	/* If detached, return a list of the child process ids instead
	 * of the output of the pipeline. */
	for (i = 0; i < nProcs; i++) {
#ifdef WIN32
	    sprintf(string, "%u", (unsigned int)bgPtr->procArr[i].pid);
#else 
	    sprintf(string, "%d", bgPtr->procArr[i]);
#endif
	    Tcl_AppendElement(interp, string);
	}
    } else {
	int exitCode;
	int done;
................................................................................
	DisableTriggers(bgPtr);
	if ((exitCode == 0) && (bgPtr->sink1.doneVar == NULL)) {
	    unsigned char *data;
	    size_t length;

	    /* Return the output of the pipeline. */
	    GetSinkData(&bgPtr->sink1, &data, &length);
#if (TCL_VERSION_NUMBER <  _VERSION(8,1,0)) 
	    data[length] = '\0';
	    Tcl_SetResult(interp, data, TCL_VOLATILE);
#else
	    Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(data, length));
#endif
	}
	/* Clean up resources used. */
	DestroyBackgroundInfo(bgPtr);
	if (exitCode != 0) {
	    Tcl_AppendResult(interp, "child process exited abnormally",
		(char *)NULL);
	    return TCL_ERROR;







<
<
<

<












<
<
<
<







 







<


<

|







 







|

|

|

|

|

|

|

|

|

|

|

|



|

|







 







|







 







|













|







 







|






|







 







|




|
|

|







 







|
|




<




|













<







 







<

|






<

<







 







|







 







|







 







|







 







|

|


<
<
<
<
<
<
<
|




<







 







|

<
<
<
<
<
<
<
<
<
<
<


<








|





|
|



|

|


|





|

|

|






|
|










|






<


|







 







|







 







|

|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







|








<
<










|







 







|







 







|








<
<
<

<







 







|







 







|


|







 







|







 







|



|












|







 







|







 







<




<







<




<






|
|
|






|

|







 







|







|







 







<
<
<
<

<







37
38
39
40
41
42
43



44

45
46
47
48
49
50
51
52
53
54
55
56




57
58
59
60
61
62
63
...
259
260
261
262
263
264
265

266
267

268
269
270
271
272
273
274
275
276
...
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
...
640
641
642
643
644
645
646
647
648
649
650
651
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670

671
672
673
674
675
676
677
...
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702

703

704
705
706
707
708
709
710
...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
...
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
...
845
846
847
848
849
850
851
852
853
854
855
856







857
858
859
860
861

862
863
864
865
866
867
868
...
890
891
892
893
894
895
896
897
898











899
900

901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

961
962
963
964
965
966
967
968
969
970
....
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
....
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
....
1131
1132
1133
1134
1135
1136
1137


































































1138
1139
1140
1141
1142
1143
1144
....
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
....
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194


1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
....
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
....
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366



1367

1368
1369
1370
1371
1372
1373
1374
....
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
....
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
....
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
....
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
....
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
....
1741
1742
1743
1744
1745
1746
1747

1748
1749
1750
1751

1752
1753
1754
1755
1756
1757
1758

1759
1760
1761
1762

1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
....
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
....
1835
1836
1837
1838
1839
1840
1841




1842

1843
1844
1845
1846
1847
1848
1849
#include <sys/param.h>
#endif
#include <sys/types.h>

#include "bltWait.h"
#include "bltSwitch.h"




typedef int Tcl_File;


static Tcl_CmdProc BgexecCmd;

#ifdef WIN32
typedef struct {
    DWORD pid;
    HANDLE hProcess;
} Process;
#else
typedef int Process;
#endif





#define ENCODING_ASCII		((Tcl_Encoding)NULL)
#define ENCODING_BINARY		((Tcl_Encoding)1)

/*
 *	As of Tcl 7.6, we're using our own version of the old
 *	Tcl_CreatePipeline routine.  I would have tried to use
 *	Tcl_OpenCommandChannel but you can't get at the array of
................................................................................
				 * updated as data is read from the
				 * pipe. */

    char **updateCmd;		/* Start of a Tcl command executed
				 * whenever data is read from the
				 * pipe. */


    Tcl_Obj **objv;		/*  */
    int objc;			/*  */


    int flags;

    Tcl_File file;		/* Used for backward compatability
				 * with Tcl 7.5 */
    Tcl_Encoding encoding;
    int fd;			/* File descriptor of the pipe. */
    int status;

................................................................................

static Blt_SwitchParseProc StringToSignal;
static Blt_SwitchCustom killSignalSwitch =
{
    StringToSignal, (Blt_SwitchFreeProc *)NULL, (ClientData)0,
};

static Blt_SwitchSpec switchSpecs[] =
{
    {BLT_SWITCH_STRING, "-decodeoutput",
         Blt_Offset(BackgroundInfo, outputEncodingName), 0},
    {BLT_SWITCH_STRING, "-decodeerror",
         Blt_Offset(BackgroundInfo, errorEncodingName), 0},
    {BLT_SWITCH_BOOLEAN, "-echo",
         Blt_Offset(BackgroundInfo, sink2.echo), 0},
    {BLT_SWITCH_STRING, "-error",
         Blt_Offset(BackgroundInfo, sink2.doneVar), 0},
    {BLT_SWITCH_STRING, "-update",
	Blt_Offset(BackgroundInfo, sink1.updateVar), 0},
    {BLT_SWITCH_STRING, "-output",
        Blt_Offset(BackgroundInfo, sink1.doneVar), 0},
    {BLT_SWITCH_STRING, "-lasterror",
	Blt_Offset(BackgroundInfo, sink2.updateVar), 0},
    {BLT_SWITCH_STRING, "-lastoutput",
	Blt_Offset(BackgroundInfo, sink1.updateVar), 0},
    {BLT_SWITCH_LIST, "-onerror",
	Blt_Offset(BackgroundInfo, sink2.updateCmd), 0},
    {BLT_SWITCH_LIST, "-onoutput",
	Blt_Offset(BackgroundInfo, sink1.updateCmd), 0},
    {BLT_SWITCH_BOOLEAN, "-keepnewline",
	Blt_Offset(BackgroundInfo, keepNewline), 0},
    {BLT_SWITCH_INT, "-check",
	Blt_Offset(BackgroundInfo, interval), 0},
    {BLT_SWITCH_CUSTOM, "-killsignal",
	Blt_Offset(BackgroundInfo, signalNum), 0, &killSignalSwitch},
    {BLT_SWITCH_BOOLEAN, "-linebuffered",
	Blt_Offset(BackgroundInfo, lineBuffered), 0},
    {BLT_SWITCH_END, NULL, 0, 0}
};

static char *VariableProc _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, char *part1, char *part2, int flags));
static void TimerProc _ANSI_ARGS_((ClientData clientData));
................................................................................
    }
    if (isdigit(UCHAR(string[0]))) {
	if (Tcl_GetInt(interp, string, &signalNum) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	char *name;
	SignalId *sigPtr;

	name = string;

	/*  Clip off any "SIG" prefix from the signal name */
	if ((name[0] == 'S') && (name[1] == 'I') && (name[2] == 'G')) {
	    name += 3;
	}
................................................................................
 *----------------------------------------------------------------------
 *
 * NextBlock --
 *
 *	Returns the next block of data since the last time this
 *	routine was called.
 *
 *----------------------------------------------------------------------
 */
static unsigned char *
NextBlock(sinkPtr, lengthPtr)
    Sink *sinkPtr;
    int *lengthPtr;
{
    unsigned char *string;
    int length;

    string = sinkPtr->byteArr + sinkPtr->lastMark;
    length = sinkPtr->mark - sinkPtr->lastMark;
    sinkPtr->lastMark = sinkPtr->mark;
    if (length > 0) {
	if ((!(sinkPtr->flags & SINK_KEEP_NL)) &&
	    (string[length - 1] == '\n')) {
	    length--;
	}
	*lengthPtr = length;
	return string;
    }
    return NULL;
................................................................................
NextLine(sinkPtr, lengthPtr)
    Sink *sinkPtr;
    int *lengthPtr;
{
    if (sinkPtr->mark > sinkPtr->lastMark) {
	unsigned char *string;
	int newBytes;
	int i;

	string = sinkPtr->byteArr + sinkPtr->lastMark;
	newBytes = sinkPtr->mark - sinkPtr->lastMark;
	for (i = 0; i < newBytes; i++) {
	    if (string[i] == '\n') {
		int length;

		length = i + 1;
		sinkPtr->lastMark += length;
		if (!(sinkPtr->flags & SINK_KEEP_NL)) {
		    length--;		/* Backup over the newline. */
		}
		*lengthPtr = length;
		return string;
................................................................................
 * ResetSink --
 *
 *	Removes the bytes already processed from the buffer, possibly
 *	resetting it to empty.  This used when we don't care about
 *	keeping all the data collected from the channel (no -output
 *	flag and the process is detached).
 *
 *----------------------------------------------------------------------
 */
static void
ResetSink(sinkPtr)
    Sink *sinkPtr;
{
    if ((sinkPtr->flags & SINK_BUFFERED) &&
	(sinkPtr->fill > sinkPtr->lastMark)) {
	size_t i, j;

	/* There may be bytes remaining in the buffer, awaiting
	 * another read before we see the next newline.  So move the
	 * bytes to the front of the array. */

 	for (i = 0, j = sinkPtr->lastMark; j < sinkPtr->fill; i++, j++) {
	    sinkPtr->byteArr[i] = sinkPtr->byteArr[j];
................................................................................
    sinkPtr->size = DEF_BUFFER_SIZE;
    sinkPtr->encoding = encoding;
    if (bgPtr->keepNewline) {
	sinkPtr->flags |= SINK_KEEP_NL;
    }
    if (bgPtr->lineBuffered) {
	sinkPtr->flags |= SINK_BUFFERED;
    }
    if ((sinkPtr->updateCmd != NULL) ||
	(sinkPtr->updateVar != NULL) ||
	(sinkPtr->echo)) {
	sinkPtr->flags |= SINK_NOTIFY;
    }

    if (sinkPtr->updateCmd != NULL) {
	Tcl_Obj **objArr;
	char **p;
	int count;
	int i;

	count = 0;
	for (p = sinkPtr->updateCmd; *p != NULL; p++) {
	    count++;
	}
	objArr = Blt_Malloc((count + 1) * sizeof(Tcl_Obj *));
	for (i = 0; i < count; i++) {
	    objArr[i] = Tcl_NewStringObj(sinkPtr->updateCmd[i], -1);
	    Tcl_IncrRefCount(objArr[i]);
	}
	sinkPtr->objv = objArr;
	sinkPtr->objc = count + 1;
    }

    ResetSink(sinkPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * FreeSinkBuffer --
................................................................................
    Sink *sinkPtr;
{
    if (sinkPtr->byteArr != sinkPtr->staticSpace) {
	Blt_Free(sinkPtr->byteArr);
    }
    sinkPtr->fd = -1;
    sinkPtr->file = (Tcl_File)NULL;

    if (sinkPtr->objv != NULL) {
	int i;

	for (i = 0; i < sinkPtr->objc - 1; i++) {
	    Tcl_DecrRefCount(sinkPtr->objv[i]);
	}
	Blt_Free(sinkPtr->objv);
    }

}


/*
 *----------------------------------------------------------------------
 *
 * ExtendSinkBuffer --
 *
 *	Doubles the size of the current buffer.
................................................................................
 *----------------------------------------------------------------------
 */
static int
ExtendSinkBuffer(sinkPtr)
    Sink *sinkPtr;
{
    unsigned char *arrayPtr;
    unsigned char *srcPtr, *destPtr, *endPtr;
    /*
     * Allocate a new array, double the old size
     */
    sinkPtr->size += sinkPtr->size;
    arrayPtr = Blt_Malloc(sizeof(unsigned char) * sinkPtr->size);
    if (arrayPtr == NULL) {
	return -1;
................................................................................
 *----------------------------------------------------------------------
 */
static void
ReadBytes(sinkPtr)
    Sink *sinkPtr;
{
    int nBytes, bytesLeft;
    int i;
    unsigned char *array;

    /*
     * ------------------------------------------------------------------
     *
     * 	Worry about indefinite postponement.
     *
................................................................................
    }
    sinkPtr->status = nBytes;
}

#define IsOpenSink(sinkPtr)  ((sinkPtr)->fd != -1)

static void
CloseSink(interp, sinkPtr)
    Tcl_Interp *interp;
    Sink *sinkPtr;
{
    if (IsOpenSink(sinkPtr)) {
	close(sinkPtr->fd);
#ifdef FILEHANDLER_USES_TCLFILES
	Tcl_DeleteFileHandler(sinkPtr->file);
................................................................................

#if WINDEBUG
	PurifyPrintf("CloseSink: set done var %s\n", sinkPtr->name);
#endif
	if (sinkPtr->doneVar != NULL) {
	    unsigned char *data;
	    size_t length;
	    /*
	     * If data is to be collected, set the "done" variable
	     * with the contents of the buffer.
	     */
	    GetSinkData(sinkPtr, &data, &length);







	    if (Tcl_SetVar2Ex(interp, sinkPtr->doneVar, NULL,
			      Tcl_NewByteArrayObj(data, length),
			      (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG)) == NULL) {
		Tcl_BackgroundError(interp);
	    }

	}
#if WINDEBUG
	PurifyPrintf("CloseSink %s: done\n", sinkPtr->name);
#endif
    }
}
/*
................................................................................
#ifdef WIN32
    size_t oldMark;

    oldMark = sinkPtr->mark;
#endif
    if (sinkPtr->encoding == ENCODING_BINARY) { /* binary */
	/* No translation needed. */
	sinkPtr->mark = sinkPtr->fill;
    } else if (sinkPtr->encoding == ENCODING_ASCII) { /* ascii */











	/* One-to-one translation. mark == fill. */
	sinkPtr->mark = sinkPtr->fill;

    } else { /* unicode. */
	int nSrcCooked, nCooked;
	int result;
	size_t cookedSize, spaceLeft, needed;
	size_t nRaw, nLeftOver;
	unsigned char *destPtr;
	unsigned char *raw, *cooked;
	unsigned char leftover[100];

	raw = sinkPtr->byteArr + sinkPtr->mark;
	nRaw = sinkPtr->fill - sinkPtr->mark;
	/* Ideally, the cooked buffer size should be smaller */
	cookedSize = nRaw * TCL_UTF_MAX + 1;
	cooked = Blt_Malloc(cookedSize);
	result = Tcl_ExternalToUtf(interp, sinkPtr->encoding,
			(char *)raw, nRaw, 0, NULL, (char *)cooked,
			cookedSize, &nSrcCooked, &nCooked, NULL);
	nLeftOver = 0;
	if (result == TCL_CONVERT_MULTIBYTE) {
	    /*
	     * Last multibyte sequence wasn't completed.  Save the
	     * extra characters in a temporary buffer.
	     */
	    nLeftOver = (nRaw - nSrcCooked);
	    srcPtr = sinkPtr->byteArr + (sinkPtr->mark + nSrcCooked);
	    endPtr = srcPtr + nLeftOver;
	    destPtr = leftover;
	    while (srcPtr < endPtr) {
		*destPtr++ = *srcPtr++;
	    }
	}
	/*
	 * Create a bigger
	 */

	needed = nLeftOver + nCooked;
	spaceLeft = sinkPtr->size - sinkPtr->mark;
	if (spaceLeft >= needed) {
	    spaceLeft = ExtendSinkBuffer(sinkPtr);
	}
	assert(spaceLeft > needed);
	/*
	 * Replace the characters from the mark with the translated
	 * characters.
	 */
	srcPtr = cooked;
	endPtr = cooked + nCooked;
	destPtr = sinkPtr->byteArr + sinkPtr->mark;
	while (srcPtr < endPtr) {
	    *destPtr++ = *srcPtr++;
	}
	/* Add the number of newly translated characters to the mark */
	sinkPtr->mark += nCooked;

	srcPtr = leftover;
	endPtr = leftover + nLeftOver;
	while (srcPtr < endPtr) {
	    *destPtr++ = *srcPtr++;
	}
	sinkPtr->fill = sinkPtr->mark + nLeftOver;

    }
#ifdef WIN32
    /*
     * Translate CRLF character sequences to LF characters.  We have to
     * do this after converting the string to UTF from UNICODE.
     */
    if (sinkPtr->encoding != ENCODING_BINARY) {
	int count;
	unsigned char *destPtr;

................................................................................
	return -1;
    }
#if WINDEBUG
    PurifyPrintf("WAITPID: waiting for 0x%x\n", child.hProcess);
#endif
    timeout = (flags & WNOHANG) ? 0 : INFINITE;
    status = WaitForSingleObject(child.hProcess, timeout);

#if WINDEBUG
    PurifyPrintf("WAITPID: wait status is %d\n", status);
#endif
    switch (status) {
    case WAIT_FAILED:
	errno = ECHILD;
	*statusPtr = ECHILD;
................................................................................
    if ((proc.hProcess == NULL) || (proc.hProcess == INVALID_HANDLE_VALUE)) {
	errno = EINVAL;
	return -1;
    }

    EnumWindows(EnumWindowsProc, (LPARAM)&proc);

    /*
     * Wait on the handle. If it signals, great. If it times out,
     * then call TerminateProcess on it.
     *
     * On Windows 95/98 this also has the added benefit of stopping
     * KERNEL32.dll from dumping.  The 2 second number is arbitrary.
     * (1 second seems to fail intermittently).
     */
    status = WaitForSingleObject(proc.hProcess, 2000);
    if (status == WAIT_OBJECT_0) {
................................................................................
	return -1;
    }
    return 0;
}

#endif /* WIN32 */



































































static void
NotifyOnUpdate(interp, sinkPtr, data, nBytes)
    Tcl_Interp *interp;
    Sink *sinkPtr;
    unsigned char *data;
    int nBytes;
{
................................................................................
    PurifyPrintf("read %s\n", data);
#endif
    if ((nBytes == 0) || (data[0] == '\0')) {
	return;
    }
    if (sinkPtr->echo) {
	Tcl_Channel channel;

	channel = Tcl_GetStdChannel(TCL_STDERR);
	if (channel == NULL) {
	    Tcl_AppendResult(interp, "can't get stderr channel", (char *)NULL);
	    Tcl_BackgroundError(interp);
	    sinkPtr->echo = FALSE;
	} else {
	    if (data[nBytes] == '\n') {
................................................................................
	if (result != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
    }
    if (sinkPtr->updateVar != NULL) {
	Tcl_Obj *result;

	result = Tcl_SetVar2Ex(interp, sinkPtr->updateVar, NULL, objPtr,
	       (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
	if (result == NULL) {
	    Tcl_BackgroundError(interp);
	}
    }
    Tcl_DecrRefCount(objPtr);
}



static int
CollectData(bgPtr, sinkPtr)
    BackgroundInfo *bgPtr;
    Sink *sinkPtr;
{
    if ((bgPtr->detached) && (sinkPtr->doneVar == NULL)) {
	ResetSink(sinkPtr);
    }
    ReadBytes(sinkPtr);
    CookSink(bgPtr->interp, sinkPtr);
    if ((sinkPtr->mark > sinkPtr->lastMark) &&
	(sinkPtr->flags & SINK_NOTIFY)) {
	unsigned char *data;
	int length;

	if (sinkPtr->flags & SINK_BUFFERED) {
	    /* For line-by-line updates, call NotifyOnUpdate for each
	     * new complete line.  */
................................................................................

static void
DisableTriggers(bgPtr)
    BackgroundInfo *bgPtr;	/* Background info record. */
{

    if (bgPtr->traced) {
	Tcl_UntraceVar(bgPtr->interp, bgPtr->statVar, TRACE_FLAGS,
		VariableProc, bgPtr);
	bgPtr->traced = FALSE;
    }
    if (IsOpenSink(&bgPtr->sink1)) {
	CloseSink(bgPtr->interp, &bgPtr->sink1);
    }
    if (IsOpenSink(&bgPtr->sink2)) {
................................................................................
DestroyBackgroundInfo(bgPtr)
    BackgroundInfo *bgPtr;	/* Background info record. */
{
    DisableTriggers(bgPtr);
    FreeSinkBuffer(&bgPtr->sink2);
    FreeSinkBuffer(&bgPtr->sink1);
    if (bgPtr->procArr != NULL) {
	int i;

	for (i = 0; i < bgPtr->nProcs; i++) {
	    if (bgPtr->signalNum > 0) {
		kill(bgPtr->procArr[i], bgPtr->signalNum);
	    }
#ifdef WIN32
	    Tcl_DetachPids(1, (Tcl_Pid *)&bgPtr->procArr[i].pid);
#else



	    Tcl_DetachPids(1, (Tcl_Pid *)bgPtr->procArr[i]);

#endif /* WIN32 */
	}
    }
    FreeBackgroundInfo(bgPtr);
    Tcl_ReapDetachedProcs();
}

................................................................................
    int flags)
{
    if (flags & TRACE_FLAGS) {
	BackgroundInfo *bgPtr = clientData;

	/* Kill all child processes that remain alive. */
	if ((bgPtr->procArr != NULL) && (bgPtr->signalNum > 0)) {
	    int i;

	    for (i = 0; i < bgPtr->nProcs; i++) {
		kill(bgPtr->procArr[i], bgPtr->signalNum);
	    }
	}
    }
    return NULL;
................................................................................
 *----------------------------------------------------------------------
 */
static void
TimerProc(clientData)
    ClientData clientData;
{
    BackgroundInfo *bgPtr = clientData;
    int i;
    unsigned int lastPid;
    int pid;
    enum PROCESS_STATUS {
	PROCESS_EXITED, PROCESS_STOPPED, PROCESS_KILLED, PROCESS_UNKNOWN
    } pcode;
    WAIT_STATUS_TYPE waitStatus, lastStatus;
    int nLeft;			/* Number of processes still not reaped */
    char string[200];
    Tcl_DString dString;
    int code;
................................................................................
	     */
	    lastStatus = waitStatus;
	    lastPid = (unsigned int)pid;
	}
    }
    bgPtr->nProcs = nLeft;

    if ((nLeft > 0) || (IsOpenSink(&bgPtr->sink1)) ||
	(IsOpenSink(&bgPtr->sink2))) {
	/* Keep polling for the status of the children that are left */
	bgPtr->timerToken = Tcl_CreateTimerHandler(bgPtr->interval, TimerProc,
	   bgPtr);
#if WINDEBUG
	PurifyPrintf("schedule TimerProc(nProcs=%d)\n", nLeft);
#endif
................................................................................
#endif
    Tcl_DStringAppendElement(&dString, Blt_Itoa(code));
    switch(pcode) {
    case PROCESS_EXITED:
	Tcl_DStringAppendElement(&dString, "child completed normally");
	break;
    case PROCESS_KILLED:
	Tcl_DStringAppendElement(&dString,
				Tcl_SignalMsg((int)(WTERMSIG(lastStatus))));
	break;
    case PROCESS_STOPPED:
	Tcl_DStringAppendElement(&dString,
		 Tcl_SignalMsg((int)(WSTOPSIG(lastStatus))));
	break;
    case PROCESS_UNKNOWN:
	sprintf(string, "child completed with unknown status 0x%x",
	    *((int *)&lastStatus));
	Tcl_DStringAppendElement(&dString, string);
	break;
    }
    if (bgPtr->exitCodePtr != NULL) {
	*bgPtr->exitCodePtr = code;
    }
    DisableTriggers(bgPtr);
    result = Tcl_SetVar(bgPtr->interp, bgPtr->statVar,
	Tcl_DStringValue(&dString), TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
    Tcl_DStringFree(&dString);
    if (result == NULL) {
	Tcl_BackgroundError(bgPtr->interp);
    }
    if (bgPtr->detached) {
	DestroyBackgroundInfo(bgPtr);
................................................................................
    bgPtr->detached = detached;
    bgPtr->keepNewline = FALSE;
    bgPtr->statVar = Blt_Strdup(argv[1]);

    /* Try to clean up any detached processes */
    Tcl_ReapDetachedProcs();

    i = Blt_ProcessSwitches(interp, switchSpecs, argc - 2, argv + 2,
	(char *)bgPtr, BLT_SWITCH_ARGV_PARTIAL);
    if (i < 0) {
	FreeBackgroundInfo(bgPtr);
	return TCL_ERROR;
    }
    i += 2;
    /* Must be at least one argument left as the command to execute. */
................................................................................
    bgPtr->traced = TRUE;

    encoding = ENCODING_ASCII;
    if (bgPtr->outputEncodingName != NULL) {
	if (strcmp(bgPtr->outputEncodingName, "binary") == 0) {
	    encoding = ENCODING_BINARY;
	} else {

	    encoding = Tcl_GetEncoding(interp, bgPtr->outputEncodingName);
	    if (encoding == NULL) {
		goto error;
	    }

	}
    }
    InitSink(bgPtr, &bgPtr->sink1, "stdout", encoding);
    if (bgPtr->errorEncodingName != NULL) {
	if (strcmp(bgPtr->errorEncodingName, "binary") == 0) {
	    encoding = ENCODING_BINARY;
	} else {

	    encoding = Tcl_GetEncoding(interp, bgPtr->errorEncodingName);
	    if (encoding == NULL) {
		goto error;
	    }

	}
    }
    InitSink(bgPtr, &bgPtr->sink2, "stderr", encoding);

    outFdPtr = errFdPtr = (int *)NULL;
#ifdef WIN32
    if ((!bgPtr->detached) ||
	(bgPtr->sink1.doneVar != NULL) ||
	(bgPtr->sink1.updateVar != NULL) ||
	(bgPtr->sink1.updateCmd != NULL)) {
	outFdPtr = &bgPtr->sink1.fd;
    }
#else
    outFdPtr = &bgPtr->sink1.fd;
#endif
    if ((bgPtr->sink2.doneVar != NULL) ||
	(bgPtr->sink2.updateVar != NULL) ||
	(bgPtr->sink2.updateCmd != NULL) ||
	(bgPtr->sink2.echo)) {
	errFdPtr = &bgPtr->sink2.fd;
    }
    nProcs = Blt_CreatePipeline(interp, argc - i, argv + i, &pidPtr,
	(int *)NULL, outFdPtr, errFdPtr);
    if (nProcs < 0) {
	goto error;
................................................................................
    } else if (CreateSinkHandler(bgPtr, &bgPtr->sink1, StdoutProc) != TCL_OK) {
	goto error;
    }
    if ((bgPtr->sink2.fd != -1) &&
	(CreateSinkHandler(bgPtr, &bgPtr->sink2, StderrProc) != TCL_OK)) {
 	goto error;
    }
    if (bgPtr->detached) {
	char string[200];

	/* If detached, return a list of the child process ids instead
	 * of the output of the pipeline. */
	for (i = 0; i < nProcs; i++) {
#ifdef WIN32
	    sprintf(string, "%u", (unsigned int)bgPtr->procArr[i].pid);
#else
	    sprintf(string, "%d", bgPtr->procArr[i]);
#endif
	    Tcl_AppendElement(interp, string);
	}
    } else {
	int exitCode;
	int done;
................................................................................
	DisableTriggers(bgPtr);
	if ((exitCode == 0) && (bgPtr->sink1.doneVar == NULL)) {
	    unsigned char *data;
	    size_t length;

	    /* Return the output of the pipeline. */
	    GetSinkData(&bgPtr->sink1, &data, &length);




	    Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(data, length));

	}
	/* Clean up resources used. */
	DestroyBackgroundInfo(bgPtr);
	if (exitCode != 0) {
	    Tcl_AppendResult(interp, "child process exited abnormally",
		(char *)NULL);
	    return TCL_ERROR;

Changes to jni/blt/src/bltBind.c.

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
...
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
...
533
534
535
536
537
538
539

540
541
542
543
544
545
546
547
...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
    } else {
	(*bindPtr->tagProc) (bindPtr, item, context, bindIds);
    }
    nIds = Blt_ListGetLength(bindIds);
    if (nIds > 0) {
	ClientData *idArray;
	ClientData tags[32];
	register Blt_ListNode node;
	
	idArray = tags;
	if (nIds >= 32) {
	    idArray = Blt_Malloc(sizeof(ClientData) * nIds);
	    
	} 
	nIds = 0;
................................................................................

int
Blt_ConfigureBindings(interp, bindPtr, item, argc, argv)
    Tcl_Interp *interp;
    struct Blt_BindTableStruct *bindPtr;
    ClientData item;
    int argc;
    char **argv;
{
    char *command;
    unsigned long mask;
    char *seq;

    if (argc == 0) {
	Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
	return TCL_OK;
    }
    if (argc == 1) {
	command = Tk_GetBinding(interp, bindPtr->bindingTable, item, argv[0]);
	if (command == NULL) {
	    return TCL_ERROR;
	}
	Tcl_SetResult(interp, command, TCL_VOLATILE);
	return TCL_OK;
    }

    seq = argv[0];
    command = argv[1];

    if (command[0] == '\0') {
................................................................................
		 "only key, button, motion, enter, leave, and virtual ",
		 "events may be used", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}


#if (TCL_MAJOR_VERSION >= 8)

int
Blt_ConfigureBindingsFromObj(interp, bindPtr, item, objc, objv)
    Tcl_Interp *interp;
    struct Blt_BindTableStruct *bindPtr;
    ClientData item;
    int objc;
    Tcl_Obj *CONST *objv;
................................................................................

    if (objc == 0) {
	Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
	return TCL_OK;
    }
    string = Tcl_GetString(objv[0]);
    if (objc == 1) {

	command = Tk_GetBinding(interp, bindPtr->bindingTable, item, string);
	if (command == NULL) {
	    Tcl_ResetResult(interp);
	    Tcl_AppendResult(interp, "invalid binding event \"", string, "\"", 
		(char *)NULL);
	    return TCL_ERROR;
	}
	Tcl_SetResult(interp, command, TCL_VOLATILE);
................................................................................
	Tcl_AppendResult(interp, "requested illegal events; ",
		 "only key, button, motion, enter, leave, and virtual ",
		 "events may be used", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}
#endif

Blt_BindTable
Blt_CreateBindingTable(interp, tkwin, clientData, pickProc, tagProc)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    ClientData clientData;
    Blt_BindPickProc *pickProc;







|







 







|

|

|










|







 







<
<
<







 







>
|







 







<







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
...
511
512
513
514
515
516
517



518
519
520
521
522
523
524
...
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
...
569
570
571
572
573
574
575

576
577
578
579
580
581
582
    } else {
	(*bindPtr->tagProc) (bindPtr, item, context, bindIds);
    }
    nIds = Blt_ListGetLength(bindIds);
    if (nIds > 0) {
	ClientData *idArray;
	ClientData tags[32];
	Blt_ListNode node;
	
	idArray = tags;
	if (nIds >= 32) {
	    idArray = Blt_Malloc(sizeof(ClientData) * nIds);
	    
	} 
	nIds = 0;
................................................................................

int
Blt_ConfigureBindings(interp, bindPtr, item, argc, argv)
    Tcl_Interp *interp;
    struct Blt_BindTableStruct *bindPtr;
    ClientData item;
    int argc;
    CONST char **argv;
{
    CONST char *command;
    unsigned long mask;
    CONST char *seq;

    if (argc == 0) {
	Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
	return TCL_OK;
    }
    if (argc == 1) {
	command = Tk_GetBinding(interp, bindPtr->bindingTable, item, argv[0]);
	if (command == NULL) {
	    return TCL_ERROR;
	}
	Tcl_SetResult(interp, (char *) command, TCL_VOLATILE);
	return TCL_OK;
    }

    seq = argv[0];
    command = argv[1];

    if (command[0] == '\0') {
................................................................................
		 "only key, button, motion, enter, leave, and virtual ",
		 "events may be used", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}




int
Blt_ConfigureBindingsFromObj(interp, bindPtr, item, objc, objv)
    Tcl_Interp *interp;
    struct Blt_BindTableStruct *bindPtr;
    ClientData item;
    int objc;
    Tcl_Obj *CONST *objv;
................................................................................

    if (objc == 0) {
	Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
	return TCL_OK;
    }
    string = Tcl_GetString(objv[0]);
    if (objc == 1) {
	command = (char *)
	    Tk_GetBinding(interp, bindPtr->bindingTable, item, string);
	if (command == NULL) {
	    Tcl_ResetResult(interp);
	    Tcl_AppendResult(interp, "invalid binding event \"", string, "\"", 
		(char *)NULL);
	    return TCL_ERROR;
	}
	Tcl_SetResult(interp, command, TCL_VOLATILE);
................................................................................
	Tcl_AppendResult(interp, "requested illegal events; ",
		 "only key, button, motion, enter, leave, and virtual ",
		 "events may be used", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}


Blt_BindTable
Blt_CreateBindingTable(interp, tkwin, clientData, pickProc, tagProc)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    ClientData clientData;
    Blt_BindPickProc *pickProc;

Changes to jni/blt/src/bltBind.h.

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
EXTERN void Blt_DestroyBindingTable _ANSI_ARGS_((Blt_BindTable table));

EXTERN Blt_BindTable Blt_CreateBindingTable _ANSI_ARGS_((Tcl_Interp *interp,
	Tk_Window tkwin, ClientData clientData, Blt_BindPickProc *pickProc,
	Blt_BindTagProc *tagProc));

EXTERN int Blt_ConfigureBindings _ANSI_ARGS_((Tcl_Interp *interp,
	Blt_BindTable table, ClientData item, int argc, char **argv));

#if (TCL_MAJOR_VERSION >= 8)
EXTERN int Blt_ConfigureBindingsFromObj _ANSI_ARGS_((Tcl_Interp *interp,
	Blt_BindTable table, ClientData item, int objc, Tcl_Obj *CONST *objv));
#endif

EXTERN void Blt_PickCurrentItem _ANSI_ARGS_((Blt_BindTable table));

EXTERN void Blt_DeleteBindings _ANSI_ARGS_((Blt_BindTable table,
	ClientData object));

EXTERN void Blt_MoveBindingTable _ANSI_ARGS_((Blt_BindTable table, 







|

<


<







88
89
90
91
92
93
94
95
96

97
98

99
100
101
102
103
104
105
EXTERN void Blt_DestroyBindingTable _ANSI_ARGS_((Blt_BindTable table));

EXTERN Blt_BindTable Blt_CreateBindingTable _ANSI_ARGS_((Tcl_Interp *interp,
	Tk_Window tkwin, ClientData clientData, Blt_BindPickProc *pickProc,
	Blt_BindTagProc *tagProc));

EXTERN int Blt_ConfigureBindings _ANSI_ARGS_((Tcl_Interp *interp,
	Blt_BindTable table, ClientData item, int argc, CONST char **argv));


EXTERN int Blt_ConfigureBindingsFromObj _ANSI_ARGS_((Tcl_Interp *interp,
	Blt_BindTable table, ClientData item, int objc, Tcl_Obj *CONST *objv));


EXTERN void Blt_PickCurrentItem _ANSI_ARGS_((Blt_BindTable table));

EXTERN void Blt_DeleteBindings _ANSI_ARGS_((Blt_BindTable table,
	ClientData object));

EXTERN void Blt_MoveBindingTable _ANSI_ARGS_((Blt_BindTable table, 

Changes to jni/blt/src/bltBitmap.c.

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
...
600
601
602
603
604
605
606

























607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
...
630
631
632
633
634
635
636
637

638
639
640
641

642
643
644
645
646
647
648
...
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
...
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
...
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
....
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
....
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
....
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
....
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
....
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
....
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
....
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
    0x80, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x01, 0x00, 0x57, 0x55, 0x55,
    0x55, 0x55, 0xd5, 0x00, 0x00, 0xac, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a, 0x00,
    0x00, 0xf0, 0xff, 0x57, 0x55, 0x55, 0x1d, 0x00, 0x00, 0x00, 0x00, 0xf8,
    0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static Tcl_CmdProc BitmapCmd;
static Tcl_InterpDeleteProc BitmapInterpDeleteProc;

/*
 * -----------------------------------------------------------------------
 *
 * GetHexValue --
 *
................................................................................
 */
static int
GetHexValue(interp, string, valuePtr)
    Tcl_Interp *interp;
    char *string;
    int *valuePtr;
{
    register int c;
    register char *s;
    register int value;

    s = string;
    if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
	s += 2;
    }
    if (s[0] == '\0') {
	Tcl_AppendResult(interp, "expecting hex value: got \"", string, "\"",
................................................................................
	}
	value = (value << 4) + hexTable[c];
    }
    *valuePtr = value;
    return TCL_OK;
}

#ifdef WIN32
/*
 * -----------------------------------------------------------------------
 *
 * BitmapToData --
 *
 *	Converts a bitmap into an data array.
 *
................................................................................
    Pixmap bitmap,		/* Bitmap to be queried */
    int width, int height,	/* Dimensions of the bitmap */
    int flip,
    unsigned char **bitsPtr)	/* Pointer to converted array of data */
{
    int value, bitMask;
    unsigned long pixel;
    register int x, y;
    int count;
    int arraySize, bytes_per_line;
    unsigned char *bits;
    unsigned char *srcPtr, *srcBits;
    int bytesPerRow;

    *bitsPtr = NULL;
................................................................................
    Pixmap bitmap;		/* Bitmap to be queried */
    int width, height;		/* Dimensions of the bitmap */
    int flip;
    unsigned char **bitsPtr;	/* Pointer to converted array of data */
{
    int value, bitMask;
    unsigned long pixel;
    register int x, y;
    int count;
    int arraySize, bytes_per_line;
    Display *display;
    XImage *imagePtr;
    unsigned char *bits;

    display = Tk_Display(tkwin);
................................................................................
    unsigned char **bitsPtr;	/* data array (output) */
{
    int arraySize;		/* Number of bytes of data */
    int value;			/* from an input line */
    int padding;		/* to handle alignment */
    int bytesPerLine;		/* per scanline of data */
    unsigned char *bits;
    register int count;
    enum Formats {
	V10, V11
    } format;
    register int i;		/*  */
    char **valueArr;
    int nValues;

    /* First time through initialize the ascii->hex translation table */
    if (!initialized) {
	Blt_InitHexTable(hexTable);
	initialized = 1;
    }
................................................................................
ParseListData(interp, string, widthPtr, heightPtr, bitsPtr)
    Tcl_Interp *interp;
    char *string;
    int *widthPtr;
    int *heightPtr;
    unsigned char **bitsPtr;
{
    register char *p;
    char **elemArr;
    int nElem;
    int width, height;
    int result;
    int arraySize;

    arraySize = -1;
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return -1;
    }
    if (nElem == 2) {
	char **dimArr;
	int nDim;
	
	if (Tcl_SplitList(interp, elemArr[0], &nDim, &dimArr) != TCL_OK) {
	    goto error;
	}
	if (nDim != 2) {
	    Tcl_AppendResult(interp, "wrong # of bitmap dimensions: ",
................................................................................
	    result = ((Tcl_GetInt(interp, dimArr[0], &width) == TCL_OK) &&
		      (Tcl_GetInt(interp, dimArr[1], &height) == TCL_OK));
	}
	Blt_Free(dimArr);
	if (!result) {
	    goto error;
	}
	string = elemArr[1];
    } else if (nElem == 3) {
	if ((Tcl_GetInt(interp, elemArr[0], &width) != TCL_OK) ||
	    (Tcl_GetInt(interp, elemArr[1], &height) != TCL_OK)) {
	    goto error;
	}
	string = elemArr[2];
    } else {
	Tcl_AppendResult(interp, "wrong # of bitmap data components: ",
			 "should be \"dimensions sourceData\"", (char *)NULL);
	goto error;
    }
    if ((width < 1) || (height < 1)) {
	Tcl_AppendResult(interp, "bad bitmap dimensions", (char *)NULL);
................................................................................
 *		#define foo_y_hot 3
 *		static char foo_bits[] = {
 *
 * The x_hot and y_hot lines may or may not be present.  It's
 * important to check for "char" in the last line, in order to
 * reject old X10-style bitmaps that used shorts.
 */


























static int
ParseStructData(interp, string, widthPtr, heightPtr, bitsPtr)
    Tcl_Interp *interp;
    char *string;
    int *widthPtr;
    int *heightPtr;
    unsigned char **bitsPtr;
{
    int width, height;
    int hotX, hotY;
    char *line, *nextline;
    register char *p;
    Tcl_RegExp re;
    char *name, *value, *data;
    int len;
    int arraySize;

    width = height = 0;
    hotX = hotY = -1;
................................................................................
	nextline = strchr(line, '\n');
	if ((nextline == NULL) || (line == nextline)) {
	    continue;		/* Empty line */
	}
	*nextline = '\0';
	re = Tcl_RegExpCompile(interp, " *# *define +");
	if (Tcl_RegExpExec(interp, re, line, line)) {
	    char *start, *end;


	    Tcl_RegExpRange(re, 0, &start, &end);
	    name = strtok(end, " \t"); 
	    value = strtok(NULL, " \t");

	    if ((name == NULL) || (value == NULL)) {
		return TCL_ERROR;
	    }
	    len = strlen(name);
	    if ((len >= 6) && (name[len-6] == '_') && 
		(strcmp(name+len-6, "_width") == 0)) {
		if (Tcl_GetInt(interp, value, &width) != TCL_OK) {
................................................................................
ScaleRotateData(
    Tcl_Interp *interp,		/* Interpreter to report results to */
    BitmapData *srcPtr,		/* Source bitmap to transform. */
    double theta,		/* Number of degrees to rotate the bitmap. */
    double scale,		/* Factor to scale the bitmap. */
    BitmapData *destPtr)	/* Destination bitmap. */
{
    register int x, y, sx, sy;
    double srcX, srcY, destX, destY;	/* Origins of source and destination
					 * bitmaps */
    double dx, dy;
    double sinTheta, cosTheta;
    double rotWidth, rotHeight;
    double radians;
    unsigned char *bits;
................................................................................
    Tk_Window tkwin;		/* Main window of interpreter */
    Pixmap bitmap;		/* Bitmap to be queried */
    Tcl_DString *resultPtr;	/* Dynamic string to output results to */
{
    unsigned char *bits;
    char *separator;
    int arraySize;
    register int i;
    char string[200];
    int width, height;

    /* Get the dimensions of the bitmap */
    Tk_SizeOfBitmap(Tk_Display(tkwin), bitmap, &width, &height);
    arraySize = BitmapToData(tkwin, bitmap, width, height, 0, &bits);
#define BYTES_PER_OUTPUT_LINE 24
................................................................................
 *--------------------------------------------------------------
 */
static int
ComposeOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of arguments */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;		/* Dimensions of bitmap */
    Pixmap bitmap;		/* Text bitmap */
    unsigned char *bits;	/* Data array derived from text bitmap */
    int arraySize;
    BitmapInfo info;		/* Text rotation and font information */
................................................................................
 */
/* ARGSUSED */
static int
DefineOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of arguments */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;		/* Dimensions of bitmap */
    unsigned char *bits;	/* working variable */
    register char *p;
    char *defn;			/* Definition of bitmap. */
    BitmapInfo info;		/* Not used. */
    int arraySize;
    int result;
    double theta;
    Pixmap bitmap;
    Blt_HashEntry *hPtr;
................................................................................
 */
/*ARGSUSED*/
static int
ExistsOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    Tcl_ResetResult(interp);
    if (bitmap != None) {
................................................................................
 */
/*ARGSUSED*/
static int
HeightOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;
    Pixmap bitmap;
    
    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
WidthOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;
    Pixmap bitmap;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
SourceOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;
    Tcl_DString dString;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
DataOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;
    int width, height;
    Tcl_DString dString;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
................................................................................
 */
/*ARGSUSED*/
static int
BitmapCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;
    char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nBitmapOps, bitmapOps, BLT_OP_ARG1, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;







<







 







|
|
|







 







|







 







|







 







|







 







|



|
|







 







|
|










|







 







|





|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












|







 







|
>


<
|
>







 







|







 







|







 







|







 







|




|







 







|







 







|







 







|







 







|







 







|







 







|







215
216
217
218
219
220
221

222
223
224
225
226
227
228
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
...
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
...
654
655
656
657
658
659
660
661
662
663
664

665
666
667
668
669
670
671
672
673
...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
...
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
...
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
....
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
....
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
....
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
....
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
....
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
....
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
....
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
    0x80, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x01, 0x00, 0x57, 0x55, 0x55,
    0x55, 0x55, 0xd5, 0x00, 0x00, 0xac, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a, 0x00,
    0x00, 0xf0, 0xff, 0x57, 0x55, 0x55, 0x1d, 0x00, 0x00, 0x00, 0x00, 0xf8,
    0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};


static Tcl_InterpDeleteProc BitmapInterpDeleteProc;

/*
 * -----------------------------------------------------------------------
 *
 * GetHexValue --
 *
................................................................................
 */
static int
GetHexValue(interp, string, valuePtr)
    Tcl_Interp *interp;
    char *string;
    int *valuePtr;
{
    int c;
    char *s;
    int value;

    s = string;
    if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
	s += 2;
    }
    if (s[0] == '\0') {
	Tcl_AppendResult(interp, "expecting hex value: got \"", string, "\"",
................................................................................
	}
	value = (value << 4) + hexTable[c];
    }
    *valuePtr = value;
    return TCL_OK;
}

#if defined(WIN32) && !defined(PLATFORM_SDL)
/*
 * -----------------------------------------------------------------------
 *
 * BitmapToData --
 *
 *	Converts a bitmap into an data array.
 *
................................................................................
    Pixmap bitmap,		/* Bitmap to be queried */
    int width, int height,	/* Dimensions of the bitmap */
    int flip,
    unsigned char **bitsPtr)	/* Pointer to converted array of data */
{
    int value, bitMask;
    unsigned long pixel;
    int x, y;
    int count;
    int arraySize, bytes_per_line;
    unsigned char *bits;
    unsigned char *srcPtr, *srcBits;
    int bytesPerRow;

    *bitsPtr = NULL;
................................................................................
    Pixmap bitmap;		/* Bitmap to be queried */
    int width, height;		/* Dimensions of the bitmap */
    int flip;
    unsigned char **bitsPtr;	/* Pointer to converted array of data */
{
    int value, bitMask;
    unsigned long pixel;
    int x, y;
    int count;
    int arraySize, bytes_per_line;
    Display *display;
    XImage *imagePtr;
    unsigned char *bits;

    display = Tk_Display(tkwin);
................................................................................
    unsigned char **bitsPtr;	/* data array (output) */
{
    int arraySize;		/* Number of bytes of data */
    int value;			/* from an input line */
    int padding;		/* to handle alignment */
    int bytesPerLine;		/* per scanline of data */
    unsigned char *bits;
    int count;
    enum Formats {
	V10, V11
    } format;
    int i;		/*  */
    CONST char **valueArr;
    int nValues;

    /* First time through initialize the ascii->hex translation table */
    if (!initialized) {
	Blt_InitHexTable(hexTable);
	initialized = 1;
    }
................................................................................
ParseListData(interp, string, widthPtr, heightPtr, bitsPtr)
    Tcl_Interp *interp;
    char *string;
    int *widthPtr;
    int *heightPtr;
    unsigned char **bitsPtr;
{
    char *p;
    CONST char **elemArr;
    int nElem;
    int width, height;
    int result;
    int arraySize;

    arraySize = -1;
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return -1;
    }
    if (nElem == 2) {
	CONST char **dimArr;
	int nDim;
	
	if (Tcl_SplitList(interp, elemArr[0], &nDim, &dimArr) != TCL_OK) {
	    goto error;
	}
	if (nDim != 2) {
	    Tcl_AppendResult(interp, "wrong # of bitmap dimensions: ",
................................................................................
	    result = ((Tcl_GetInt(interp, dimArr[0], &width) == TCL_OK) &&
		      (Tcl_GetInt(interp, dimArr[1], &height) == TCL_OK));
	}
	Blt_Free(dimArr);
	if (!result) {
	    goto error;
	}
	string = (char *) elemArr[1];
    } else if (nElem == 3) {
	if ((Tcl_GetInt(interp, elemArr[0], &width) != TCL_OK) ||
	    (Tcl_GetInt(interp, elemArr[1], &height) != TCL_OK)) {
	    goto error;
	}
	string = (char *) elemArr[2];
    } else {
	Tcl_AppendResult(interp, "wrong # of bitmap data components: ",
			 "should be \"dimensions sourceData\"", (char *)NULL);
	goto error;
    }
    if ((width < 1) || (height < 1)) {
	Tcl_AppendResult(interp, "bad bitmap dimensions", (char *)NULL);
................................................................................
 *		#define foo_y_hot 3
 *		static char foo_bits[] = {
 *
 * The x_hot and y_hot lines may or may not be present.  It's
 * important to check for "char" in the last line, in order to
 * reject old X10-style bitmaps that used shorts.
 */

static char *
internal_strtok_r(char *str, CONST char *sep, char **end)
{
    if (str == NULL) {
	str = *end;
    }
    while (*str && strchr(sep, *str)) {
	++str;
    }
    if (*str) {
	char *start = str;

	*end = start + 1;
	while (**end && !strchr(sep, **end)) {
	    ++*end;
	}
	if (**end) {
	    **end = '\0';
	    ++*end;
	}
	return start;
    }
    return NULL;
}

static int
ParseStructData(interp, string, widthPtr, heightPtr, bitsPtr)
    Tcl_Interp *interp;
    char *string;
    int *widthPtr;
    int *heightPtr;
    unsigned char **bitsPtr;
{
    int width, height;
    int hotX, hotY;
    char *line, *nextline;
    char *p;
    Tcl_RegExp re;
    char *name, *value, *data;
    int len;
    int arraySize;

    width = height = 0;
    hotX = hotY = -1;
................................................................................
	nextline = strchr(line, '\n');
	if ((nextline == NULL) || (line == nextline)) {
	    continue;		/* Empty line */
	}
	*nextline = '\0';
	re = Tcl_RegExpCompile(interp, " *# *define +");
	if (Tcl_RegExpExec(interp, re, line, line)) {
	    CONST char *start, *end;
	    char *cp;

	    Tcl_RegExpRange(re, 0, &start, &end);

	    name = internal_strtok_r((char *) end, " \t", &cp); 
	    value = internal_strtok_r(NULL, " \t", &cp);
	    if ((name == NULL) || (value == NULL)) {
		return TCL_ERROR;
	    }
	    len = strlen(name);
	    if ((len >= 6) && (name[len-6] == '_') && 
		(strcmp(name+len-6, "_width") == 0)) {
		if (Tcl_GetInt(interp, value, &width) != TCL_OK) {
................................................................................
ScaleRotateData(
    Tcl_Interp *interp,		/* Interpreter to report results to */
    BitmapData *srcPtr,		/* Source bitmap to transform. */
    double theta,		/* Number of degrees to rotate the bitmap. */
    double scale,		/* Factor to scale the bitmap. */
    BitmapData *destPtr)	/* Destination bitmap. */
{
    int x, y, sx, sy;
    double srcX, srcY, destX, destY;	/* Origins of source and destination
					 * bitmaps */
    double dx, dy;
    double sinTheta, cosTheta;
    double rotWidth, rotHeight;
    double radians;
    unsigned char *bits;
................................................................................
    Tk_Window tkwin;		/* Main window of interpreter */
    Pixmap bitmap;		/* Bitmap to be queried */
    Tcl_DString *resultPtr;	/* Dynamic string to output results to */
{
    unsigned char *bits;
    char *separator;
    int arraySize;
    int i;
    char string[200];
    int width, height;

    /* Get the dimensions of the bitmap */
    Tk_SizeOfBitmap(Tk_Display(tkwin), bitmap, &width, &height);
    arraySize = BitmapToData(tkwin, bitmap, width, height, 0, &bits);
#define BYTES_PER_OUTPUT_LINE 24
................................................................................
 *--------------------------------------------------------------
 */
static int
ComposeOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of arguments */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;		/* Dimensions of bitmap */
    Pixmap bitmap;		/* Text bitmap */
    unsigned char *bits;	/* Data array derived from text bitmap */
    int arraySize;
    BitmapInfo info;		/* Text rotation and font information */
................................................................................
 */
/* ARGSUSED */
static int
DefineOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of arguments */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;		/* Dimensions of bitmap */
    unsigned char *bits;	/* working variable */
    CONST char *p;
    char *defn;			/* Definition of bitmap. */
    BitmapInfo info;		/* Not used. */
    int arraySize;
    int result;
    double theta;
    Pixmap bitmap;
    Blt_HashEntry *hPtr;
................................................................................
 */
/*ARGSUSED*/
static int
ExistsOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    Tcl_ResetResult(interp);
    if (bitmap != None) {
................................................................................
 */
/*ARGSUSED*/
static int
HeightOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;
    Pixmap bitmap;
    
    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
WidthOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    int width, height;
    Pixmap bitmap;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
SourceOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;
    Tcl_DString dString;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
    if (bitmap == None) {
................................................................................
 */
/*ARGSUSED*/
static int
DataOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Not used. */
    CONST char **argv;		/* Argument list */
{
    BitmapInterpData *dataPtr = clientData;
    Pixmap bitmap;
    int width, height;
    Tcl_DString dString;

    bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2]));
................................................................................
 */
/*ARGSUSED*/
static int
BitmapCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Thread-specific data for bitmaps. */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;
    CONST char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nBitmapOps, bitmapOps, BLT_OP_ARG1, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;

Changes to jni/blt/src/bltBusy.c.

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
...
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
...
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
    Tk_Cursor cursor;		/* Cursor for the busy window. */

    Blt_HashEntry *hashPtr;	/* Used the delete the busy window entry 
				 * out of the global hash table. */
    Blt_HashTable *tablePtr;
} Busy;

#ifdef WIN32
#define DEF_BUSY_CURSOR "wait"
#else
#define DEF_BUSY_CURSOR "watch"
#endif

static Tk_ConfigSpec configSpecs[] =
{
................................................................................
	 * Always raise the busy window just in case new sibling
	 * windows have been created in the meantime. Can't use
	 * Tk_RestackWindow because it doesn't work under Win32.
	 */
	XRaiseWindow(Tk_Display(busyPtr->tkBusy), 
	     Tk_WindowId(busyPtr->tkBusy));
    }
#ifdef WIN32
    {
	POINT point;
	/*
	 * Under Win32, cursors aren't associated with windows.  Tk
	 * fakes this by watching Motion events on its windows.  So Tk
	 * will automatically change the cursor when the pointer
	 * enters the Busy window.  But Windows doesn't immediately
................................................................................
static void
HideBusyWindow(busyPtr)
    Busy *busyPtr;
{
    if (busyPtr->tkBusy != NULL) {
	Tk_UnmapWindow(busyPtr->tkBusy); 
    }
#ifdef WIN32
    {
	POINT point;
	/*
	 * Under Win32, cursors aren't associated with windows.  Tk
	 * fakes this by watching Motion events on its windows.  So Tk
	 * will automatically change the cursor when the pointer
	 * enters the Busy window.  But Windows doesn't immediately
................................................................................
 *	when it's hidden, the busy window is unmapped.
 *
 * -------------------------------------------------------------------
 */
static void
RefWinEventProc(clientData, eventPtr)
    ClientData clientData;	/* Busy window record */
    register XEvent *eventPtr;	/* Event which triggered call to routine */
{
    register Busy *busyPtr = clientData;

    switch (eventPtr->type) {
    case ReparentNotify:
    case DestroyNotify:

	/*
	 * Arrange for the busy structure to be removed at a proper time.
................................................................................
    busyPtr->width = Tk_Width(tkRef);
    busyPtr->height = Tk_Height(tkRef);
    busyPtr->x = Tk_X(tkRef);
    busyPtr->y = Tk_Y(tkRef);
    busyPtr->cursor = None;
    busyPtr->isBusy = FALSE;
    Tk_SetClass(tkBusy, "Busy");
#if (TK_MAJOR_VERSION > 4)
    Blt_SetWindowInstanceData(tkBusy, busyPtr);
#endif
    winPtr = (Tk_FakeWin *) tkRef;
    if (winPtr->flags & TK_REPARENTED) {
	/*
	 * This works around a bug in the implementation of menubars
	 * for non-MacIntosh window systems (Win32 and X11).  Tk
	 * doesn't reset the pointers to the parent window when the
	 * menu is reparented (winPtr->parentPtr points to the
	 * wrong window). We get around this by determining the parent
	 * via the native API calls.
	 */
#ifdef WIN32
	{
	    HWND hWnd;
	    RECT rect;

	    hWnd = GetParent(Tk_GetHWND(Tk_WindowId(tkRef)));
	    parent = (Window) hWnd;
	    if (GetWindowRect(hWnd, &rect)) {
................................................................................
	    }
	}
#else
	parent = Blt_GetParent(Tk_Display(tkRef), Tk_WindowId(tkRef));
#endif
    } else {
	parent = Tk_WindowId(tkParent);
#ifdef WIN32
	parent = (Window) Tk_GetHWND(parent);
#endif
    }
    Blt_MakeTransparentWindowExist(tkBusy, parent, TRUE);

#if BUSYDEBUG
    PurifyPrintf("menubar1: width=%d, height=%d\n", busyPtr->width, 
................................................................................
    ClientData clientData;	/* Interpreter-specific data. */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;
    char **argv;
{
    BusyInterpData *dataPtr = clientData;
    Busy *busyPtr;
    register int i;

    for (i = 2; i < argc; i++) {
	if (GetBusy(dataPtr, interp, argv[i], &busyPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	/* Unmap the window even though it will be soon destroyed */
	HideBusyWindow(busyPtr);
................................................................................
HoldOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Interpreter-specific data. */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;
    char **argv;		/* Window name and option pairs */
{
    BusyInterpData *dataPtr = clientData;
    register int i, count;

    if ((argv[1][0] == 'h') && (strcmp(argv[1], "hold") == 0)) {
	argc--, argv++;		/* Command used "hold" keyword */
    }
    for (i = 1; i < argc; i++) {
	/*
	 * Find the end of the option-value pairs for this window.







|







 







|







 







|







 







|

|







 







<

<










|







 







|







 







|







 







|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
517
518
519
520
521
522
523

524

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
...
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
...
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
    Tk_Cursor cursor;		/* Cursor for the busy window. */

    Blt_HashEntry *hashPtr;	/* Used the delete the busy window entry 
				 * out of the global hash table. */
    Blt_HashTable *tablePtr;
} Busy;

#if defined(WIN32) && !defined(PLATFORM_SDL)
#define DEF_BUSY_CURSOR "wait"
#else
#define DEF_BUSY_CURSOR "watch"
#endif

static Tk_ConfigSpec configSpecs[] =
{
................................................................................
	 * Always raise the busy window just in case new sibling
	 * windows have been created in the meantime. Can't use
	 * Tk_RestackWindow because it doesn't work under Win32.
	 */
	XRaiseWindow(Tk_Display(busyPtr->tkBusy), 
	     Tk_WindowId(busyPtr->tkBusy));
    }
#if defined(WIN32) && !defined(PLATFORM_SDL)
    {
	POINT point;
	/*
	 * Under Win32, cursors aren't associated with windows.  Tk
	 * fakes this by watching Motion events on its windows.  So Tk
	 * will automatically change the cursor when the pointer
	 * enters the Busy window.  But Windows doesn't immediately
................................................................................
static void
HideBusyWindow(busyPtr)
    Busy *busyPtr;
{
    if (busyPtr->tkBusy != NULL) {
	Tk_UnmapWindow(busyPtr->tkBusy); 
    }
#if defined(WIN32) && !defined(PLATFORM_SDL)
    {
	POINT point;
	/*
	 * Under Win32, cursors aren't associated with windows.  Tk
	 * fakes this by watching Motion events on its windows.  So Tk
	 * will automatically change the cursor when the pointer
	 * enters the Busy window.  But Windows doesn't immediately
................................................................................
 *	when it's hidden, the busy window is unmapped.
 *
 * -------------------------------------------------------------------
 */
static void
RefWinEventProc(clientData, eventPtr)
    ClientData clientData;	/* Busy window record */
    XEvent *eventPtr;	/* Event which triggered call to routine */
{
    Busy *busyPtr = clientData;

    switch (eventPtr->type) {
    case ReparentNotify:
    case DestroyNotify:

	/*
	 * Arrange for the busy structure to be removed at a proper time.
................................................................................
    busyPtr->width = Tk_Width(tkRef);
    busyPtr->height = Tk_Height(tkRef);
    busyPtr->x = Tk_X(tkRef);
    busyPtr->y = Tk_Y(tkRef);
    busyPtr->cursor = None;
    busyPtr->isBusy = FALSE;
    Tk_SetClass(tkBusy, "Busy");

    Blt_SetWindowInstanceData(tkBusy, busyPtr);

    winPtr = (Tk_FakeWin *) tkRef;
    if (winPtr->flags & TK_REPARENTED) {
	/*
	 * This works around a bug in the implementation of menubars
	 * for non-MacIntosh window systems (Win32 and X11).  Tk
	 * doesn't reset the pointers to the parent window when the
	 * menu is reparented (winPtr->parentPtr points to the
	 * wrong window). We get around this by determining the parent
	 * via the native API calls.
	 */
#if defined(WIN32) && !defined(PLATFORM_SDL)
	{
	    HWND hWnd;
	    RECT rect;

	    hWnd = GetParent(Tk_GetHWND(Tk_WindowId(tkRef)));
	    parent = (Window) hWnd;
	    if (GetWindowRect(hWnd, &rect)) {
................................................................................
	    }
	}
#else
	parent = Blt_GetParent(Tk_Display(tkRef), Tk_WindowId(tkRef));
#endif
    } else {
	parent = Tk_WindowId(tkParent);
#if defined(WIN32) && !defined(PLATFORM_SDL)
	parent = (Window) Tk_GetHWND(parent);
#endif
    }
    Blt_MakeTransparentWindowExist(tkBusy, parent, TRUE);

#if BUSYDEBUG
    PurifyPrintf("menubar1: width=%d, height=%d\n", busyPtr->width, 
................................................................................
    ClientData clientData;	/* Interpreter-specific data. */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;
    char **argv;
{
    BusyInterpData *dataPtr = clientData;
    Busy *busyPtr;
    int i;

    for (i = 2; i < argc; i++) {
	if (GetBusy(dataPtr, interp, argv[i], &busyPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	/* Unmap the window even though it will be soon destroyed */
	HideBusyWindow(busyPtr);
................................................................................
HoldOp(clientData, interp, argc, argv)
    ClientData clientData;	/* Interpreter-specific data. */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;
    char **argv;		/* Window name and option pairs */
{
    BusyInterpData *dataPtr = clientData;
    int i, count;

    if ((argv[1][0] == 'h') && (strcmp(argv[1], "hold") == 0)) {
	argc--, argv++;		/* Command used "hold" keyword */
    }
    for (i = 1; i < argc; i++) {
	/*
	 * Find the end of the option-value pairs for this window.

Changes to jni/blt/src/bltCanvEps.c.

22
23
24
25
26
27
28


29
30
31
32
33
34
35
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
...
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
...
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
...
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
....
1698
1699
1700
1701
1702
1703
1704


 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 *
 * EPS canvas item created by George Howlett.
 */



/*
 * To do:
 *
 *	1. Add -rotate option.  Allow arbitrary rotation of image and EPS.
 *	2. Draw color images instead of photos. This will eliminate the need
 *	   to create hidden photo images.
 *	3. Create a spiffy demo that lets you edit your page description.
................................................................................
    int relief;

    TextStyle titleStyle;	/* Font, color, etc. for title */

    Pixmap stipple;		/* Stipple for image fill */

    ClientData tiffPtr;
#ifdef WIN32
    HENHMETAFILE *hMetaFile;	/* Windows metafile. */
#endif
} EpsItem;

static Tk_ConfigSpec configSpecs[] =
{
    {TK_CONFIG_ANCHOR, "-anchor", (char *)NULL, (char *)NULL,
................................................................................
}

static int
ReadPsLine(piPtr)
     ParseInfo *piPtr;
{
    if (Tcl_Tell(piPtr->channel) < piPtr->maxBytes) {
	Tcl_DStringSetLength(&piPtr->line, 0);
	if (Tcl_Gets(piPtr->channel, &piPtr->dsLine) >= 0) {
	    piPtr->lineNumber++;
#if DEBUG_READER
	    PurifyPrintf("%d: %s\n", piPtr->lineNumber, piPtr->line);
#endif
	    return TRUE;
	}
    }
    return FALSE;
}

................................................................................
 * Results:
 *	The converted byte is returned.
 *
 *----------------------------------------------------------------------
 */
INLINE static unsigned char
ReverseBits(byte)
    register unsigned char byte;
{
    byte = ((byte >> 1) & 0x55) | ((byte << 1) & 0xaa);
    byte = ((byte >> 2) & 0x33) | ((byte << 2) & 0xcc);
    byte = ((byte >> 4) & 0x0f) | ((byte << 4) & 0xf0);
    return byte;
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
GetHexValue(piPtr, bytePtr)
    ParseInfo *piPtr;
    unsigned char *bytePtr;
{
    register char *p;
    unsigned int byte;

    p = piPtr->nextPtr;
    if (p == NULL) {
      nextLine:
	if (!ReadPsLine(piPtr)) {
#if DEBUG_READER
................................................................................
	    PurifyPrintf("short file\n");
#endif
	    return TCL_ERROR;	/* Short file */
	}
	p = Tcl_DStringValue(&piPtr->dsLine);
	if (p[0] != '%') {
#if DEBUG_READER
	    PurifyPrintf("line doesn't start with %% (%s)\n", piPtr->line);
#endif
	    return TCL_ERROR;
	}
	if ((p[1] == '%') &&
	    (strncmp(p + 2, "EndPreview", 10) == 0)) {
#if DEBUG_READER
	    PurifyPrintf("end of preview (%s)\n", piPtr->line);
#endif
	    return TCL_RETURN;
	}
	p++;
    }
    while (*p && isspace((int)*p)) {
	p++;			/* Skip spaces */
    }
    if (*p == '\0') {
	goto nextLine;
    }
    if ((!isxdigit((int)p[0])) || (!isxdigit((int)p[1]))) {
#if DEBUG_READER
	PurifyPrintf("not a hex digit (%s)\n", piPtr->line);
#endif
	return TCL_ERROR;
    }
    byte = (piPtr->hexTable[(int)p[0]] << 4) | piPtr->hexTable[(int)p[1]];
    p += 2;
    piPtr->nextPtr = p;
    *bytePtr = byte;
................................................................................
    epsPtr->firstLine = piPtr->lineNumber;
    Blt_InitHexTable(piPtr->hexTable);
    piPtr->nextPtr = NULL;
    image = Blt_CreateColorImage(width, height);

    if (bitsPerPixel == 8) {
	int result;
	register Pix32 *destPtr;
	register int x, y;
	unsigned char byte;

	for (y = height - 1; y >= 0; y--) {
	    destPtr = Blt_ColorImageBits(image) + (y * width);
	    for (x = 0; x < width; x++, destPtr++) {
		result = GetHexValue(piPtr, &byte);
		if (result == TCL_ERROR) {
................................................................................
		}
		destPtr->Red = destPtr->Green = destPtr->Blue = ~byte;
		destPtr->Alpha = 0xFF;
	    }
	}
    } else if (bitsPerPixel == 1) {
	int result;
	register Pix32 *destPtr;
	register int x, y;
	unsigned char byte;
	register int bit;

	destPtr = Blt_ColorImageBits(image);
	for (y = 0; y < height; y++) {
	    bit = 8;
	    for (x = 0; x < width; x++, destPtr++) {
		if (bit == 8) {
		    result = GetHexValue(piPtr, &byte);
................................................................................
    Tcl_Interp *interp;		/* Not used. */
{
    Tk_CreateItemType(&epsItemType);
    /* Initialize custom canvas option routines. */
    tagsOption.parseProc = (Tk_OptionParseProc *)Tk_CanvasTagsParseProc;
    tagsOption.printProc = (Tk_OptionPrintProc *)Tk_CanvasTagsPrintProc;
}









>
>







 







|







 







|



|







 







|







 







|







 







|






|













|







 







|
|







 







|
|

|







 







>
>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
....
1700
1701
1702
1703
1704
1705
1706
1707
1708
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 *
 * EPS canvas item created by George Howlett.
 */

#ifndef NO_EPSCANV

/*
 * To do:
 *
 *	1. Add -rotate option.  Allow arbitrary rotation of image and EPS.
 *	2. Draw color images instead of photos. This will eliminate the need
 *	   to create hidden photo images.
 *	3. Create a spiffy demo that lets you edit your page description.
................................................................................
    int relief;

    TextStyle titleStyle;	/* Font, color, etc. for title */

    Pixmap stipple;		/* Stipple for image fill */

    ClientData tiffPtr;
#if defined(WIN32) && !defined(PLATFORM_SDL)
    HENHMETAFILE *hMetaFile;	/* Windows metafile. */
#endif
} EpsItem;

static Tk_ConfigSpec configSpecs[] =
{
    {TK_CONFIG_ANCHOR, "-anchor", (char *)NULL, (char *)NULL,
................................................................................
}

static int
ReadPsLine(piPtr)
     ParseInfo *piPtr;
{
    if (Tcl_Tell(piPtr->channel) < piPtr->maxBytes) {
	Tcl_DStringSetLength(&piPtr->dsLine, 0);
	if (Tcl_Gets(piPtr->channel, &piPtr->dsLine) >= 0) {
	    piPtr->lineNumber++;
#if DEBUG_READER
	    PurifyPrintf("%d: %s\n", piPtr->lineNumber, piPtr->dsLine);
#endif
	    return TRUE;
	}
    }
    return FALSE;
}

................................................................................
 * Results:
 *	The converted byte is returned.
 *
 *----------------------------------------------------------------------
 */
INLINE static unsigned char
ReverseBits(byte)
    unsigned char byte;
{
    byte = ((byte >> 1) & 0x55) | ((byte << 1) & 0xaa);
    byte = ((byte >> 2) & 0x33) | ((byte << 2) & 0xcc);
    byte = ((byte >> 4) & 0x0f) | ((byte << 4) & 0xf0);
    return byte;
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
GetHexValue(piPtr, bytePtr)
    ParseInfo *piPtr;
    unsigned char *bytePtr;
{
    char *p;
    unsigned int byte;

    p = piPtr->nextPtr;
    if (p == NULL) {
      nextLine:
	if (!ReadPsLine(piPtr)) {
#if DEBUG_READER
................................................................................
	    PurifyPrintf("short file\n");
#endif
	    return TCL_ERROR;	/* Short file */
	}
	p = Tcl_DStringValue(&piPtr->dsLine);
	if (p[0] != '%') {
#if DEBUG_READER
	    PurifyPrintf("line doesn't start with %% (%s)\n", piPtr->dsLine);
#endif
	    return TCL_ERROR;
	}
	if ((p[1] == '%') &&
	    (strncmp(p + 2, "EndPreview", 10) == 0)) {
#if DEBUG_READER
	    PurifyPrintf("end of preview (%s)\n", piPtr->dsLine);
#endif
	    return TCL_RETURN;
	}
	p++;
    }
    while (*p && isspace((int)*p)) {
	p++;			/* Skip spaces */
    }
    if (*p == '\0') {
	goto nextLine;
    }
    if ((!isxdigit((int)p[0])) || (!isxdigit((int)p[1]))) {
#if DEBUG_READER
	PurifyPrintf("not a hex digit (%s)\n", piPtr->dsLine);
#endif
	return TCL_ERROR;
    }
    byte = (piPtr->hexTable[(int)p[0]] << 4) | piPtr->hexTable[(int)p[1]];
    p += 2;
    piPtr->nextPtr = p;
    *bytePtr = byte;
................................................................................
    epsPtr->firstLine = piPtr->lineNumber;
    Blt_InitHexTable(piPtr->hexTable);
    piPtr->nextPtr = NULL;
    image = Blt_CreateColorImage(width, height);

    if (bitsPerPixel == 8) {
	int result;
	Pix32 *destPtr;
	int x, y;
	unsigned char byte;

	for (y = height - 1; y >= 0; y--) {
	    destPtr = Blt_ColorImageBits(image) + (y * width);
	    for (x = 0; x < width; x++, destPtr++) {
		result = GetHexValue(piPtr, &byte);
		if (result == TCL_ERROR) {
................................................................................
		}
		destPtr->Red = destPtr->Green = destPtr->Blue = ~byte;
		destPtr->Alpha = 0xFF;
	    }
	}
    } else if (bitsPerPixel == 1) {
	int result;
	Pix32 *destPtr;
	int x, y;
	unsigned char byte;
	int bit;

	destPtr = Blt_ColorImageBits(image);
	for (y = 0; y < height; y++) {
	    bit = 8;
	    for (x = 0; x < width; x++, destPtr++) {
		if (bit == 8) {
		    result = GetHexValue(piPtr, &byte);
................................................................................
    Tcl_Interp *interp;		/* Not used. */
{
    Tk_CreateItemType(&epsItemType);
    /* Initialize custom canvas option routines. */
    tagsOption.parseProc = (Tk_OptionParseProc *)Tk_CanvasTagsParseProc;
    tagsOption.printProc = (Tk_OptionPrintProc *)Tk_CanvasTagsPrintProc;
}

#endif /* NO_EPSCANV */

Changes to jni/blt/src/bltChain.c.

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
 */
void
Blt_ChainSort(chainPtr, proc)
    Blt_Chain *chainPtr;	/* Chain to traverse */
    Blt_ChainCompareProc *proc;
{
    Blt_ChainLink **linkArr;
    register Blt_ChainLink *linkPtr;
    register int i;

    if (chainPtr->nLinks < 2) {
	return;
    }
    linkArr = Blt_Malloc(sizeof(Blt_ChainLink *) * (chainPtr->nLinks + 1));
    if (linkArr == NULL) {
	return;			/* Out of memory. */







|
|







408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
 */
void
Blt_ChainSort(chainPtr, proc)
    Blt_Chain *chainPtr;	/* Chain to traverse */
    Blt_ChainCompareProc *proc;
{
    Blt_ChainLink **linkArr;
    Blt_ChainLink *linkPtr;
    int i;

    if (chainPtr->nLinks < 2) {
	return;
    }
    linkArr = Blt_Malloc(sizeof(Blt_ChainLink *) * (chainPtr->nLinks + 1));
    if (linkArr == NULL) {
	return;			/* Out of memory. */

Changes to jni/blt/src/bltColor.c.

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
387
388
389
390
391
392
393

394
395
396
397
398
399
400
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
507
508
509
510
511
512
513

514

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
...
546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
...
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
...
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
...
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
 *
 *	-ramp number		Number of colors to use in a linear ramp.
 *
 */

#include "bltInt.h"

#ifndef WIN32

#include "bltHash.h"
#include "bltImage.h"

#define NCOLORS		256


static void
GetPaletteSizes(nColors, nRedsPtr, nGreensPtr, nBluesPtr)
    int nColors;		/* Number of colors requested. */
    unsigned int *nRedsPtr;	/* (out) Number of red components. */
    unsigned int *nGreensPtr;	/* (out) Number of green components. */
    unsigned int *nBluesPtr;	/* (out) Number of blue components. */
................................................................................
}

static void
BuildColorRamp(palettePtr, nColors)
    Pix32 *palettePtr;
    int nColors;
{
    register unsigned int r, g, b;
    unsigned int short red, green, blue;
    unsigned int nReds, nGreens, nBlues;

    GetPaletteSizes(nColors, &nReds, &nGreens, &nBlues);
    for (r = 0; r < nReds; r++) {
	red = (r * USHRT_MAX) / (nReds - 1);
	for (g = 0; g < nGreens; g++) {
................................................................................
    Display *display;
    Colormap colorMap;
    XColor mapColors[];
    int *numMapColorsPtr;
{
    unsigned long int pixelValues[NCOLORS];
    int numAvail, numMapColors;
    register int i;
    register XColor *colorPtr;
    register unsigned long *indexPtr;
    int inUse[NCOLORS];

    /* Initially, we assume all color cells are allocated. */
    memset((char *)inUse, 0, sizeof(int) * NCOLORS);

    /*
     * Start allocating color cells.  This will tell us which color cells
................................................................................
static void
FindClosestColor(colorPtr, mapColors, numMapColors)
    ColorInfo *colorPtr;
    XColor mapColors[];
    int numMapColors;
{
    double r, g, b;
    register int i;
    double dist, min;
    XColor *lastMatch;
    register XColor *mapColorPtr;

    min = DBL_MAX;	/* Any color is closer. */
    lastMatch = NULL;

    /* Linear search of color */

    mapColorPtr = mapColors;
................................................................................
    int numColors;
    int numAvailColors;
    int numMapColors;
    XColor mapColors[NCOLORS];
{
    int numMatched;
    float sum;
    register int i;
    register ColorInfo *colorPtr;

    /*
     * For each quantized color, compute and store the error (i.e
     * the distance from a color that's already been allocated).
     * We'll use this information to sort the colors based upon how
     * badly they match and their frequency to the color image.
     */
................................................................................
    
static int
AllocateColors(nImageColors, colorTabPtr, matchOnly)
    int nImageColors;
    struct ColorTableStruct *colorTabPtr;
    int matchOnly;
{
    register int i;
    register ColorInfo *colorPtr;
    unsigned long int pixelValue;

    for (i = 0; i < nImageColors; i++) {
	colorPtr = colorTabPtr->sortedColors[i];
	if (matchOnly) {
	    XAllocColor(colorTabPtr->display, colorTabPtr->colorMap,
		&colorPtr->best);
................................................................................
    }
    Blt_Free(colorTabPtr);
}

extern int redAdjust, greenAdjust, blueAdjust;
extern int redMaskShift, greenMaskShift, blueMaskShift;


/*
 *----------------------------------------------------------------------
 *
 * Blt_DirectColorTable --
 *
 *	Creates a color table using the DirectColor visual.  We try
 *	to allocate colors across the color spectrum.
................................................................................
    Display *display;
    XColor color;
    int nr, ng, nb;
    int rBand, gBand, bBand;
    int rLast, gLast, bLast;
    unsigned int r, g, b;
    unsigned int value;
    register int i;

    display = Tk_Display(tkwin);
    visualPtr = Tk_Visual(tkwin);

    colorTabPtr = Blt_CreateColorTable(tkwin);
    /*
     * Compute the number of distinct colors in each band
................................................................................
	while (bLast < b) {
	    colorTabPtr->blue[bLast++] = value;
	}
    }
    colorTabPtr->nPixels = i;
    return colorTabPtr;
}



/*
 * First attempt:
 *	Allocate colors all the colors in the image (up to NCOLORS). Bail out
 *	on the first failure or if we need more than NCOLORS.
 */
static int
GetUniqueColors(image)
    Blt_ColorImage image;
{
    register int i, nColors;
    register Pix32 *pixelPtr;
    Pix32 color;
    Blt_HashEntry *hPtr;
    int isNew, nPixels;
    int refCount;
    Blt_HashTable colorTable;

    Blt_InitHashTable(&colorTable, BLT_ONE_WORD_KEYS);
................................................................................
	    refCount++;
	}
	Blt_SetHashValue(hPtr, (ClientData)refCount);
    }
    Blt_DeleteHashTable(&colorTable);
    return nColors;
}


#define Blt_DefaultColormap(tkwin)  \
	DefaultColormap(Tk_Display(tkwin), Tk_ScreenNumber(tkwin))


#ifndef PLATFORM_SDL
static void
PrivateColormap(interp, colorTabPtr, image, tkwin)
    Tcl_Interp *interp;
    struct ColorTableStruct *colorTabPtr;
    Blt_ColorImage image;
    Tk_Window tkwin;
{
    int keepColors = 0;
    register int i;
    XColor usedColors[NCOLORS];
    int nFreeColors, nUsedColors;
    Colormap colorMap;
    int inUse[NCOLORS];
    XColor *colorPtr;
    XColor *imageColors;

................................................................................
static void
ConvoleColorImage(srcImage, destImage, kernelPtr)
    Blt_ColorImage srcImage, destImage;
    ConvoleKernel *kernelPtr;
{
    Pix32 *srcPtr, *destPtr;
    Pix32 *src[MAXROWS];
    register int x, y, i, j;
    int red, green, blue;

    /* i = 0 case, ignore left column of pixels */

    srcPtr = Blt_ColorImageBits(srcImage);
    destPtr = Blt_ColorImageBits(destImage);

................................................................................
	error[RED] = colorPtr->Red - srcPtr->Red * (NCOLORS + 1);

	/* translate pixel to colorInfoPtr to get error */
	colorTabPtr->lut[r][g][b];
	colorPtr = PixelToColorInfo(pixel);
	error = colorPtr->error;

	register rle_pixel *optr;
	register int j;
	register short *thisptr, *nextptr = NULL;
	int chan;
	static int nchan = 0;
	int lastline = 0, lastpixel;
	static int *cval = 0;
	static rle_pixel *pixel = 0;

	if (nchan != in_hdr->ncolors)
................................................................................
    Blt_Free(thisline);
    Blt_Free(nextline);
    Blt_Free(cache);

    return newpic;
}


static void
DitherImage(image)
    Blt_ColorImage image;
{
    int width, height;



}

#endif

#endif /* WIN32 */







|





<







 







|







 







|
|
|







 







|


|







 







|
|







 







|
|







 







>







 







|







 







>

>









|
|







 







>



<










|







 







|







 







|
|
|







 







<





<
<
<





66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
...
548
549
550
551
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
...
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
...
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
...
969
970
971
972
973
974
975

976
977
978
979
980



981
982
983
984
985
 *
 *	-ramp number		Number of colors to use in a linear ramp.
 *
 */

#include "bltInt.h"

#if !defined(WIN32) || defined(PLATFORM_SDL)

#include "bltHash.h"
#include "bltImage.h"

#define NCOLORS		256


static void
GetPaletteSizes(nColors, nRedsPtr, nGreensPtr, nBluesPtr)
    int nColors;		/* Number of colors requested. */
    unsigned int *nRedsPtr;	/* (out) Number of red components. */
    unsigned int *nGreensPtr;	/* (out) Number of green components. */
    unsigned int *nBluesPtr;	/* (out) Number of blue components. */
................................................................................
}

static void
BuildColorRamp(palettePtr, nColors)
    Pix32 *palettePtr;
    int nColors;
{
    unsigned int r, g, b;
    unsigned int short red, green, blue;
    unsigned int nReds, nGreens, nBlues;

    GetPaletteSizes(nColors, &nReds, &nGreens, &nBlues);
    for (r = 0; r < nReds; r++) {
	red = (r * USHRT_MAX) / (nReds - 1);
	for (g = 0; g < nGreens; g++) {
................................................................................
    Display *display;
    Colormap colorMap;
    XColor mapColors[];
    int *numMapColorsPtr;
{
    unsigned long int pixelValues[NCOLORS];
    int numAvail, numMapColors;
    int i;
    XColor *colorPtr;
    unsigned long *indexPtr;
    int inUse[NCOLORS];

    /* Initially, we assume all color cells are allocated. */
    memset((char *)inUse, 0, sizeof(int) * NCOLORS);

    /*
     * Start allocating color cells.  This will tell us which color cells
................................................................................
static void
FindClosestColor(colorPtr, mapColors, numMapColors)
    ColorInfo *colorPtr;
    XColor mapColors[];
    int numMapColors;
{
    double r, g, b;
    int i;
    double dist, min;
    XColor *lastMatch;
    XColor *mapColorPtr;

    min = DBL_MAX;	/* Any color is closer. */
    lastMatch = NULL;

    /* Linear search of color */

    mapColorPtr = mapColors;
................................................................................
    int numColors;
    int numAvailColors;
    int numMapColors;
    XColor mapColors[NCOLORS];
{
    int numMatched;
    float sum;
    int i;
    ColorInfo *colorPtr;

    /*
     * For each quantized color, compute and store the error (i.e
     * the distance from a color that's already been allocated).
     * We'll use this information to sort the colors based upon how
     * badly they match and their frequency to the color image.
     */
................................................................................
    
static int
AllocateColors(nImageColors, colorTabPtr, matchOnly)
    int nImageColors;
    struct ColorTableStruct *colorTabPtr;
    int matchOnly;
{
    int i;
    ColorInfo *colorPtr;
    unsigned long int pixelValue;

    for (i = 0; i < nImageColors; i++) {
	colorPtr = colorTabPtr->sortedColors[i];
	if (matchOnly) {
	    XAllocColor(colorTabPtr->display, colorTabPtr->colorMap,
		&colorPtr->best);
................................................................................
    }
    Blt_Free(colorTabPtr);
}

extern int redAdjust, greenAdjust, blueAdjust;
extern int redMaskShift, greenMaskShift, blueMaskShift;

#ifndef PLATFORM_SDL
/*
 *----------------------------------------------------------------------
 *
 * Blt_DirectColorTable --
 *
 *	Creates a color table using the DirectColor visual.  We try
 *	to allocate colors across the color spectrum.
................................................................................
    Display *display;
    XColor color;
    int nr, ng, nb;
    int rBand, gBand, bBand;
    int rLast, gLast, bLast;
    unsigned int r, g, b;
    unsigned int value;
    int i;

    display = Tk_Display(tkwin);
    visualPtr = Tk_Visual(tkwin);

    colorTabPtr = Blt_CreateColorTable(tkwin);
    /*
     * Compute the number of distinct colors in each band
................................................................................
	while (bLast < b) {
	    colorTabPtr->blue[bLast++] = value;
	}
    }
    colorTabPtr->nPixels = i;
    return colorTabPtr;
}
#endif

#ifdef notused
/*
 * First attempt:
 *	Allocate colors all the colors in the image (up to NCOLORS). Bail out
 *	on the first failure or if we need more than NCOLORS.
 */
static int
GetUniqueColors(image)
    Blt_ColorImage image;
{
    int i, nColors;
    Pix32 *pixelPtr;
    Pix32 color;
    Blt_HashEntry *hPtr;
    int isNew, nPixels;
    int refCount;
    Blt_HashTable colorTable;

    Blt_InitHashTable(&colorTable, BLT_ONE_WORD_KEYS);
................................................................................
	    refCount++;
	}
	Blt_SetHashValue(hPtr, (ClientData)refCount);
    }
    Blt_DeleteHashTable(&colorTable);
    return nColors;
}
#endif

#define Blt_DefaultColormap(tkwin)  \
	DefaultColormap(Tk_Display(tkwin), Tk_ScreenNumber(tkwin))


#ifndef PLATFORM_SDL
static void
PrivateColormap(interp, colorTabPtr, image, tkwin)
    Tcl_Interp *interp;
    struct ColorTableStruct *colorTabPtr;
    Blt_ColorImage image;
    Tk_Window tkwin;
{
    int keepColors = 0;
    int i;
    XColor usedColors[NCOLORS];
    int nFreeColors, nUsedColors;
    Colormap colorMap;
    int inUse[NCOLORS];
    XColor *colorPtr;
    XColor *imageColors;

................................................................................
static void
ConvoleColorImage(srcImage, destImage, kernelPtr)
    Blt_ColorImage srcImage, destImage;
    ConvoleKernel *kernelPtr;
{
    Pix32 *srcPtr, *destPtr;
    Pix32 *src[MAXROWS];
    int x, y, i, j;
    int red, green, blue;

    /* i = 0 case, ignore left column of pixels */

    srcPtr = Blt_ColorImageBits(srcImage);
    destPtr = Blt_ColorImageBits(destImage);

................................................................................
	error[RED] = colorPtr->Red - srcPtr->Red * (NCOLORS + 1);

	/* translate pixel to colorInfoPtr to get error */
	colorTabPtr->lut[r][g][b];
	colorPtr = PixelToColorInfo(pixel);
	error = colorPtr->error;

	rle_pixel *optr;
	int j;
	short *thisptr, *nextptr = NULL;
	int chan;
	static int nchan = 0;
	int lastline = 0, lastpixel;
	static int *cval = 0;
	static rle_pixel *pixel = 0;

	if (nchan != in_hdr->ncolors)
................................................................................
    Blt_Free(thisline);
    Blt_Free(nextline);
    Blt_Free(cache);

    return newpic;
}


static void
DitherImage(image)
    Blt_ColorImage image;
{
    int width, height;



}

#endif

#endif /* WIN32 */

Changes to jni/blt/src/bltConfig.c.

33
34
35
36
37
38
39
40
41
42
43
44
45
46


47
48
49
50
51
52
53

54
55
56
57


58
59
60
61
62
63
64
65
66
67
68


69
70
71
72
73


74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89


90
91
92
93
94


95
96
97
98
99
100
101
102
103
104


105
106
107
108

109
110

111
112
113
114


115
116
117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132
133
134
135
136


137
138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153

154
155
156
157


158
159
160
161
162
163
164
165
...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
...
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
...
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
...
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
...
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
...
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
....
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
....
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
....
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
....
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
....
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
....
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
....
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
#endif

#ifndef NO_TILE
#include "bltTile.h"
#endif

static int StringToFill _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
static char *FillToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltFillOption =
{


    StringToFill, FillToString, (ClientData)0
};

static int StringToPad _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int offset));
static char *PadToString _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin,

	char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltPadOption =
{


    StringToPad, PadToString, (ClientData)0
};

static int StringToDistance _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
static char *DistanceToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltDistanceOption =
{


    StringToDistance, DistanceToString, (ClientData)PIXELS_NONNEGATIVE
};

Tk_CustomOption bltPositiveDistanceOption =
{


    StringToDistance, DistanceToString, (ClientData)PIXELS_POSITIVE
};

Tk_CustomOption bltAnyDistanceOption =
{


    StringToDistance, DistanceToString, (ClientData)PIXELS_ANY
};

static int StringToCount _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
static char *CountToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltCountOption =
{


    StringToCount, CountToString, (ClientData)COUNT_NONNEGATIVE
};

Tk_CustomOption bltPositiveCountOption =
{


    StringToCount, CountToString, (ClientData)COUNT_POSITIVE
};

static int StringToDashes _ANSI_ARGS_((ClientData, Tcl_Interp *, Tk_Window,
	char *, char *, int));
static char *DashesToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltDashesOption =
{


    StringToDashes, DashesToString, (ClientData)0
};

static int StringToShadow _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,

	Tk_Window tkwin, char *string, char *widgRec, int offset));
static char *ShadowToString _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin,

	char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltShadowOption =
{


    StringToShadow, ShadowToString, (ClientData)0
};

static int StringToUid _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
static char *UidToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltUidOption =
{


    StringToUid, UidToString, (ClientData)0
};

static int StringToState _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
static char *StateToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltStateOption =
{


    StringToState, StateToString, (ClientData)0
};

static int StringToList _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,
	Tk_Window tkwin, char *string, char *widgRec, int flags));
static char *ListToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltListOption =
{


    StringToList, ListToString, (ClientData)0
};

#ifndef NO_TILE
static int StringToTile _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,
	Tk_Window tkwin, char *value, char *widgRec, int flags));
static char *TileToString _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin,

	char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltTileOption =
{


    StringToTile, TileToString, (ClientData)0
};
#endif

/*
 *----------------------------------------------------------------------
 *
 * Blt_NameOfFill --
................................................................................
 */
/*ARGSUSED*/
static int
StringToFill(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    int *fillPtr = (int *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToFlag(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Bit mask to be tested in status word */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    unsigned int mask = (unsigned int)clientData;	/* Bit to be tested */
    int *flagPtr = (int *)(widgRec + offset);
    int bool;

................................................................................
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetPixels(interp, tkwin, string, check, valuePtr)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    char *string;
    int check;			/* Can be PIXELS_POSITIVE, PIXELS_NONNEGATIVE,
				 * or PIXELS_ANY, */
    int *valuePtr;
{
    int length;

    if (Tk_GetPixels(interp, tkwin, string, &length) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToDistance(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Indicated how to check distance */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pixel size in record */
{
    int *valuePtr = (int *)(widgRec + offset);
    return Blt_GetPixels(interp, tkwin, string, (int)clientData, valuePtr);
}

................................................................................
    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

int
Blt_GetInt(interp, string, check, valuePtr)
    Tcl_Interp *interp;
    char *string;
    int check;			/* Can be COUNT_POSITIVE, COUNT_NONNEGATIVE,
				 * or COUNT_ANY, */
    int *valuePtr;
{
    int count;

    if (Tcl_GetInt(interp, string, &count) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToCount(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Indicated how to check distance */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pixel size in record */
{
    int *valuePtr = (int *)(widgRec + offset);
    return Blt_GetInt(interp, string, (int)clientData, valuePtr);
}

................................................................................
 */
/*ARGSUSED*/
static int
StringToPad(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pad in widget */
{
    Blt_Pad *padPtr = (Blt_Pad *)(widgRec + offset);
    int nElem;
    int pad, result;
    char **padArr;

    if (Tcl_SplitList(interp, string, &nElem, &padArr) != TCL_OK) {
	return TCL_ERROR;
    }
    result = TCL_ERROR;
    if ((nElem < 1) || (nElem > 2)) {
	Tcl_AppendResult(interp, "wrong # elements in padding list",
................................................................................
 */
/*ARGSUSED*/
static int
StringToShadow(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pad in widget */
{
    Shadow *shadowPtr = (Shadow *) (widgRec + offset);
    XColor *colorPtr;
    int dropOffset;

    colorPtr = NULL;
    dropOffset = 0;
    if ((string != NULL) && (string[0] != '\0')) {
	int nElem;
	char **elemArr;

	if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((nElem < 1) || (nElem > 2)) {
	    Tcl_AppendResult(interp, "wrong # elements in drop shadow value",
		(char *)NULL);
................................................................................
 *
 *
 *----------------------------------------------------------------------
 */
static int
GetDashes(interp, string, dashesPtr)
    Tcl_Interp *interp;
    char *string;
    Blt_Dashes *dashesPtr;
{
    if ((string == NULL) || (*string == '\0')) {
	dashesPtr->values[0] = 0;
    } else if (strcmp(string, "dash") == 0) {	/* 5 2 */
	dashesPtr->values[0] = 5;
	dashesPtr->values[1] = 2;
................................................................................
	dashesPtr->values[0] = 2;
	dashesPtr->values[1] = 4;
	dashesPtr->values[2] = 2;
	dashesPtr->values[3] = 2;
	dashesPtr->values[4] = 0;
    } else {
	int nValues;
	char **strArr;
	long int value;
	register int i;

	if (Tcl_SplitList(interp, string, &nValues, &strArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nValues > 11) {	/* This is the postscript limit */
	    Tcl_AppendResult(interp, "too many values in dash list \"", 
			     string, "\"", (char *)NULL);
................................................................................
 */
/*ARGSUSED*/
static int
StringToDashes(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* New dash value list */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to Dashes structure */
{
    Blt_Dashes *dashesPtr = (Blt_Dashes *)(widgRec + offset);

    return GetDashes(interp, string, dashesPtr);
}
................................................................................
 */
/*ARGSUSED*/
static int
StringToUid(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    Blt_Uid *uidPtr = (Blt_Uid *)(widgRec + offset);
    Blt_Uid newId;

    newId = NULL;
................................................................................
 */
/*ARGSUSED*/
static int
StringToState(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representation of option value */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of field in record */
{
    int *statePtr = (int *)(widgRec + offset);

    if (strcmp(string, "normal") == 0) {
	*statePtr = STATE_NORMAL;
................................................................................
 */
/*ARGSUSED*/
static int
StringToList(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representation of option value */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of field in record */
{
    char ***listPtr = (char ***)(widgRec + offset);
    char **elemArr;
    int nElem;

    if (*listPtr != NULL) {
	Blt_Free(*listPtr);
	*listPtr = NULL;
    }
    if ((string == NULL) || (*string == '\0')) {
................................................................................
    ClientData clientData;	/* Not used. */
    Tk_Window tkwin;		/* Not used. */
    char *widgRec;		/* Widget structure record. */
    int offset;			/* Offset of fill in widget record. */
    Tcl_FreeProc **freeProcPtr;	/* Not used. */
{
    char **list = *(char ***)(widgRec + offset);
    register char **p;
    char *result;
    Tcl_DString dString;

    if (list == NULL) {
	return "";
    }
    Tcl_DStringInit(&dString);
    for (p = list; *p != NULL; p++) {
	Tcl_DStringAppendElement(&dString, *p);
    }
    result = Tcl_DStringValue(&dString);
    if (result == dString.staticSpace) {
	result = Blt_Strdup(result);
    }
    Tcl_DStringFree(&dString);
    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

#ifndef NO_TILE
/*
................................................................................
 */
/*ARGSUSED*/
static int
StringToTile(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window on same display as tile */
    char *string;		/* Name of image */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
{
    Blt_Tile *tilePtr = (Blt_Tile *)(widgRec + offset);
    Blt_Tile tile, oldTile;

    oldTile = *tilePtr;
................................................................................
 *----------------------------------------------------------------------
 */
int Blt_ConfigModified
TCL_VARARGS_DEF(Tk_ConfigSpec *, arg1)
{
    va_list argList;
    Tk_ConfigSpec *specs;
    register Tk_ConfigSpec *specPtr;
    register char *option;

    specs = TCL_VARARGS_START(Tk_ConfigSpec *, arg1, argList);
    while ((option = va_arg(argList, char *)) != NULL) {
	for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
	    if ((Tcl_StringMatch(specPtr->argvName, option)) &&
		(specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)) {
		va_end(argList);
................................................................................
 */
int
Blt_ConfigureWidget(interp, tkwin, specs, argc, argv, widgRec, flags)
    Tcl_Interp *interp;
    Tk_Window tkwin;		/* Window to associate with component */
    Tk_ConfigSpec *specs;
    int argc;
    char **argv;
    char *widgRec;
    int flags;
{
  int i, nspec;
  char *value;
  char **valuesIn;
  Tk_ConfigSpec *specPtr;

  /* before configure get all the config values */
  nspec = 0 ;
  for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) nspec++;
  valuesIn = (char**) Tcl_Alloc(nspec*sizeof(char*));
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_ConfigureWidgetComponent(interp, parent, resName, className, specsPtr, 
	argc, argv, widgRec, flags)
    Tcl_Interp *interp;
    Tk_Window parent;		/* Window to associate with component */
    char resName[];		/* Name of component */
    char className[];
    Tk_ConfigSpec *specsPtr;
    int argc;
    char *argv[];
    char *widgRec;
    int flags;
{
    Tk_Window tkwin;
    int result;
    char *tempName;
    int isTemporary = FALSE;
................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToEnum(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Vectors of valid strings. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String to match. */
    char *widgRec;		/* Widget record. */
    int offset;			/* Offset of field in record */
{
    int *enumPtr = (int *)(widgRec + offset);
    char c;
    register char **p;
    register int i;
    int count;

    c = string[0];
    count = 0;
    for (p = (char **)clientData; *p != NULL; p++) {
	if ((c == p[0][0]) && (strcmp(string, *p) == 0)) {
	    *enumPtr = count;







|






>
>
|



|

|
>
|



>
>
|



|

|
|



>
>
|




>
>
|




>
>
|



|

|
|



>
>
|




>
>
|



|
|
|



>
>
|


|
>
|
|
>
|



>
>
|



|






>
>
|



|

|
|



>
>
|



|
|
|



>
>
|




|
|
>
|



>
>
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|






|







 







|











|







 







|







 







|

|







 







|







 







|







 







|







 







|



|
|







 







|










|
<
<
<







 







|







 







|
|







 







|




|







 







|
|


|







 







|





|
|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
...
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
...
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
...
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
...
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
...
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
...
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
...
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
....
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132



1133
1134
1135
1136
1137
1138
1139
....
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
....
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
....
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
....
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
....
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
#endif

#ifndef NO_TILE
#include "bltTile.h"
#endif

static int StringToFill _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
static char *FillToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltFillOption =
{
    (Tk_OptionParseProc *)StringToFill,
    (Tk_OptionPrintProc *)FillToString,
    (ClientData)0
};

static int StringToPad _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int offset));
static char *PadToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset,
	Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltPadOption =
{
    (Tk_OptionParseProc *)StringToPad,
    (Tk_OptionPrintProc *)PadToString,
    (ClientData)0
};

static int StringToDistance _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
static char *DistanceToString _ANSI_ARGS_((ClientData, Tk_Window,
	char *, int, Tcl_FreeProc **));

Tk_CustomOption bltDistanceOption =
{
    (Tk_OptionParseProc *)StringToDistance,
    (Tk_OptionPrintProc *)DistanceToString,
    (ClientData)PIXELS_NONNEGATIVE
};

Tk_CustomOption bltPositiveDistanceOption =
{
    (Tk_OptionParseProc *)StringToDistance,
    (Tk_OptionPrintProc *)DistanceToString,
    (ClientData)PIXELS_POSITIVE
};

Tk_CustomOption bltAnyDistanceOption =
{
    (Tk_OptionParseProc *)StringToDistance,
    (Tk_OptionPrintProc *)DistanceToString,
    (ClientData)PIXELS_ANY
};

static int StringToCount _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
static char *CountToString _ANSI_ARGS_((ClientData, Tk_Window, char *,
	int, Tcl_FreeProc **));

Tk_CustomOption bltCountOption =
{
    (Tk_OptionParseProc *)StringToCount,
    (Tk_OptionPrintProc *)CountToString,
    (ClientData)COUNT_NONNEGATIVE
};

Tk_CustomOption bltPositiveCountOption =
{
    (Tk_OptionParseProc *)StringToCount,
    (Tk_OptionPrintProc *)CountToString,
    (ClientData)COUNT_POSITIVE
};

static int StringToDashes _ANSI_ARGS_((ClientData, Tcl_Interp *, Tk_Window,
	CONST char *, char *, int));
static char *DashesToString _ANSI_ARGS_((ClientData, Tk_Window, char *,
	int, Tcl_FreeProc **));

Tk_CustomOption bltDashesOption =
{
    (Tk_OptionParseProc *)StringToDashes,
    (Tk_OptionPrintProc *)DashesToString,
    (ClientData)0
};

static int StringToShadow _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string,
	char *widgRec, int offset));
static char *ShadowToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset,
	Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltShadowOption =
{
    (Tk_OptionParseProc *)StringToShadow,
    (Tk_OptionPrintProc *)ShadowToString,
    (ClientData)0
};

static int StringToUid _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
static char *UidToString _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
	Tcl_FreeProc **));

Tk_CustomOption bltUidOption =
{
    (Tk_OptionParseProc *)StringToUid,
    (Tk_OptionPrintProc *)UidToString,
    (ClientData)0
};

static int StringToState _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
static char *StateToString _ANSI_ARGS_((ClientData, Tk_Window, char *,
	int, Tcl_FreeProc **));

Tk_CustomOption bltStateOption =
{
    (Tk_OptionParseProc *)StringToState,
    (Tk_OptionPrintProc *)StateToString,
    (ClientData)0
};

static int StringToList _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,
	Tk_Window tkwin, CONST char *string, char *widgRec, int flags));
static char *ListToString _ANSI_ARGS_((ClientData, Tk_Window, char *,
	int, Tcl_FreeProc **));

Tk_CustomOption bltListOption =
{
    (Tk_OptionParseProc *)StringToList,
    (Tk_OptionPrintProc *)ListToString,
    (ClientData)0
};

#ifndef NO_TILE
static int StringToTile _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,
	Tk_Window tkwin, CONST char *value, char *widgRec, int flags));
static char *TileToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset,
	Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltTileOption =
{
    (Tk_OptionParseProc *)StringToTile,
    (Tk_OptionPrintProc *)TileToString,
    (ClientData)0
};
#endif

/*
 *----------------------------------------------------------------------
 *
 * Blt_NameOfFill --
................................................................................
 */
/*ARGSUSED*/
static int
StringToFill(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    int *fillPtr = (int *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToFlag(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Bit mask to be tested in status word */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    unsigned int mask = (unsigned int)clientData;	/* Bit to be tested */
    int *flagPtr = (int *)(widgRec + offset);
    int bool;

................................................................................
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetPixels(interp, tkwin, string, check, valuePtr)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    CONST char *string;
    int check;			/* Can be PIXELS_POSITIVE, PIXELS_NONNEGATIVE,
				 * or PIXELS_ANY, */
    int *valuePtr;
{
    int length;

    if (Tk_GetPixels(interp, tkwin, string, &length) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToDistance(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Indicated how to check distance */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    CONST char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pixel size in record */
{
    int *valuePtr = (int *)(widgRec + offset);
    return Blt_GetPixels(interp, tkwin, string, (int)clientData, valuePtr);
}

................................................................................
    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

int
Blt_GetInt(interp, string, check, valuePtr)
    Tcl_Interp *interp;
    CONST char *string;
    int check;			/* Can be COUNT_POSITIVE, COUNT_NONNEGATIVE,
				 * or COUNT_ANY, */
    int *valuePtr;
{
    int count;

    if (Tcl_GetInt(interp, string, &count) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToCount(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Indicated how to check distance */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pixel size in record */
{
    int *valuePtr = (int *)(widgRec + offset);
    return Blt_GetInt(interp, string, (int)clientData, valuePtr);
}

................................................................................
 */
/*ARGSUSED*/
static int
StringToPad(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    CONST char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pad in widget */
{
    Blt_Pad *padPtr = (Blt_Pad *)(widgRec + offset);
    int nElem;
    int pad, result;
    CONST char **padArr;

    if (Tcl_SplitList(interp, string, &nElem, &padArr) != TCL_OK) {
	return TCL_ERROR;
    }
    result = TCL_ERROR;
    if ((nElem < 1) || (nElem > 2)) {
	Tcl_AppendResult(interp, "wrong # elements in padding list",
................................................................................
 */
/*ARGSUSED*/
static int
StringToShadow(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window */
    CONST char *string;		/* Pixel value string */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pad in widget */
{
    Shadow *shadowPtr = (Shadow *) (widgRec + offset);
    XColor *colorPtr;
    int dropOffset;

    colorPtr = NULL;
    dropOffset = 0;
    if ((string != NULL) && (string[0] != '\0')) {
	int nElem;
	CONST char **elemArr;

	if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((nElem < 1) || (nElem > 2)) {
	    Tcl_AppendResult(interp, "wrong # elements in drop shadow value",
		(char *)NULL);
................................................................................
 *
 *
 *----------------------------------------------------------------------
 */
static int
GetDashes(interp, string, dashesPtr)
    Tcl_Interp *interp;
    CONST char *string;
    Blt_Dashes *dashesPtr;
{
    if ((string == NULL) || (*string == '\0')) {
	dashesPtr->values[0] = 0;
    } else if (strcmp(string, "dash") == 0) {	/* 5 2 */
	dashesPtr->values[0] = 5;
	dashesPtr->values[1] = 2;
................................................................................
	dashesPtr->values[0] = 2;
	dashesPtr->values[1] = 4;
	dashesPtr->values[2] = 2;
	dashesPtr->values[3] = 2;
	dashesPtr->values[4] = 0;
    } else {
	int nValues;
	CONST char **strArr;
	long int value;
	int i;

	if (Tcl_SplitList(interp, string, &nValues, &strArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nValues > 11) {	/* This is the postscript limit */
	    Tcl_AppendResult(interp, "too many values in dash list \"", 
			     string, "\"", (char *)NULL);
................................................................................
 */
/*ARGSUSED*/
static int
StringToDashes(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* New dash value list */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to Dashes structure */
{
    Blt_Dashes *dashesPtr = (Blt_Dashes *)(widgRec + offset);

    return GetDashes(interp, string, dashesPtr);
}
................................................................................
 */
/*ARGSUSED*/
static int
StringToUid(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Fill style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    Blt_Uid *uidPtr = (Blt_Uid *)(widgRec + offset);
    Blt_Uid newId;

    newId = NULL;
................................................................................
 */
/*ARGSUSED*/
static int
StringToState(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representation of option value */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of field in record */
{
    int *statePtr = (int *)(widgRec + offset);

    if (strcmp(string, "normal") == 0) {
	*statePtr = STATE_NORMAL;
................................................................................
 */
/*ARGSUSED*/
static int
StringToList(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representation of option value */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of field in record */
{
    CONST char ***listPtr = (CONST char ***)(widgRec + offset);
    CONST char **elemArr;
    int nElem;

    if (*listPtr != NULL) {
	Blt_Free(*listPtr);
	*listPtr = NULL;
    }
    if ((string == NULL) || (*string == '\0')) {
................................................................................
    ClientData clientData;	/* Not used. */
    Tk_Window tkwin;		/* Not used. */
    char *widgRec;		/* Widget structure record. */
    int offset;			/* Offset of fill in widget record. */
    Tcl_FreeProc **freeProcPtr;	/* Not used. */
{
    char **list = *(char ***)(widgRec + offset);
    char **p;
    char *result;
    Tcl_DString dString;

    if (list == NULL) {
	return "";
    }
    Tcl_DStringInit(&dString);
    for (p = list; *p != NULL; p++) {
	Tcl_DStringAppendElement(&dString, *p);
    }
    result = Blt_Strdup(Tcl_DStringValue(&dString));



    Tcl_DStringFree(&dString);
    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

#ifndef NO_TILE
/*
................................................................................
 */
/*ARGSUSED*/
static int
StringToTile(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window on same display as tile */
    CONST char *string;		/* Name of image */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
{
    Blt_Tile *tilePtr = (Blt_Tile *)(widgRec + offset);
    Blt_Tile tile, oldTile;

    oldTile = *tilePtr;
................................................................................
 *----------------------------------------------------------------------
 */
int Blt_ConfigModified
TCL_VARARGS_DEF(Tk_ConfigSpec *, arg1)
{
    va_list argList;
    Tk_ConfigSpec *specs;
    Tk_ConfigSpec *specPtr;
    char *option;

    specs = TCL_VARARGS_START(Tk_ConfigSpec *, arg1, argList);
    while ((option = va_arg(argList, char *)) != NULL) {
	for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
	    if ((Tcl_StringMatch(specPtr->argvName, option)) &&
		(specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)) {
		va_end(argList);
................................................................................
 */
int
Blt_ConfigureWidget(interp, tkwin, specs, argc, argv, widgRec, flags)
    Tcl_Interp *interp;
    Tk_Window tkwin;		/* Window to associate with component */
    Tk_ConfigSpec *specs;
    int argc;
    CONST char **argv;
    char *widgRec;
    int flags;
{
  int i, nspec;
  CONST char *value;
  char **valuesIn;
  Tk_ConfigSpec *specPtr;

  /* before configure get all the config values */
  nspec = 0 ;
  for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) nspec++;
  valuesIn = (char**) Tcl_Alloc(nspec*sizeof(char*));
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_ConfigureWidgetComponent(interp, parent, resName, className, specsPtr, 
	argc, argv, widgRec, flags)
    Tcl_Interp *interp;
    Tk_Window parent;		/* Window to associate with component */
    CONST char resName[];	/* Name of component */
    CONST char className[];
    Tk_ConfigSpec *specsPtr;
    int argc;
    CONST char *argv[];
    char *widgRec;
    int flags;
{
    Tk_Window tkwin;
    int result;
    char *tempName;
    int isTemporary = FALSE;
................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToEnum(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Vectors of valid strings. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String to match. */
    char *widgRec;		/* Widget record. */
    int offset;			/* Offset of field in record */
{
    int *enumPtr = (int *)(widgRec + offset);
    char c;
    char **p;
    int i;
    int count;

    c = string[0];
    count = 0;
    for (p = (char **)clientData; *p != NULL; p++) {
	if ((c == p[0][0]) && (strcmp(string, *p) == 0)) {
	    *enumPtr = count;

Changes to jni/blt/src/bltContainer.c.

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
166
167
168
169
170
171
172
173
174


175
176
177


178
179
180
181

182
183


184
185
186
187
188


189
190
191
192
193
194
195
196
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
...
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
....
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
....
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
....
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
....
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
....
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
#define DEF_CONTAINER_HIGHLIGHT_WIDTH	"2"
#define DEF_CONTAINER_RELIEF		"sunken"
#define DEF_CONTAINER_TAKE_FOCUS	"0"
#define DEF_CONTAINER_TIMEOUT		"20"
#define DEF_CONTAINER_WIDTH		"0"
#define DEF_CONTAINER_WINDOW		(char *)NULL

#if (TK_MAJOR_VERSION == 4)
#define TK_REPARENTED			0x2000
#endif

typedef struct SearchInfoStruct SearchInfo;
typedef void (SearchProc) _ANSI_ARGS_((Display *display, Window window, 
       SearchInfo *searchPtr));

struct SearchInfoStruct {
    SearchProc *proc;
    char *pattern;		/* Search pattern. */
................................................................................
				 * released it's returned to it's
				 * original dimensions. */

    int timeout;
} Container;


static Tk_OptionParseProc StringToXID;
static Tk_OptionPrintProc XIDToString;



static Tk_CustomOption XIDOption =
{


    StringToXID, XIDToString, (ClientData)(SEARCH_TKWIN | SEARCH_XID),
};

#ifndef WIN32

static Tk_CustomOption XIDNameOption =
{


    StringToXID, XIDToString, (ClientData)SEARCH_NAME,
};

static Tk_CustomOption XIDCmdOption =
{


    StringToXID, XIDToString, (ClientData)SEARCH_CMD,
};
#endif

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveCountOption;

static Tk_ConfigSpec configSpecs[] =
................................................................................
	DEF_CONTAINER_BACKGROUND, Tk_Offset(Container, border),
	TK_CONFIG_COLOR_ONLY},
    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0},
    {TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0},
    {TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_CONTAINER_BORDERWIDTH, Tk_Offset(Container, borderWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
#ifndef WIN32
    {TK_CONFIG_CUSTOM, "-command", "command", "Command",
	DEF_CONTAINER_WINDOW, Tk_Offset(Container, adopted),
	TK_CONFIG_DONT_SET_DEFAULT, &XIDCmdOption},
#endif
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_CONTAINER_CURSOR, Tk_Offset(Container, cursor), TK_CONFIG_NULL_OK},
    {TK_CONFIG_CUSTOM, "-height", "height", "Height",
................................................................................
    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_CONTAINER_HIGHLIGHT_COLOR, 
	Tk_Offset(Container, highlightColor), 0},
    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness",
	DEF_CONTAINER_HIGHLIGHT_WIDTH, Tk_Offset(Container, highlightWidth),
	TK_CONFIG_DONT_SET_DEFAULT},
#ifndef WIN32
    {TK_CONFIG_CUSTOM, "-name", "name", "Name",
	DEF_CONTAINER_WINDOW, Tk_Offset(Container, adopted),
	TK_CONFIG_DONT_SET_DEFAULT, &XIDNameOption},
#endif
    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
	DEF_CONTAINER_RELIEF, Tk_Offset(Container, relief), 0},
    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
................................................................................
GetXID(tkwin)
    Tk_Window tkwin;
{
    HWND hWnd;
    TkWinWindow *twdPtr;

    hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
#if (TK_MAJOR_VERSION > 4)
    if (Tk_IsTopLevel(tkwin)) {
	hWnd = GetParent(hWnd);
    }
#endif /* TK_MAJOR_VERSION > 4 */
    twdPtr = Blt_Malloc(sizeof(TkWinWindow));
    twdPtr->handle = hWnd;
    twdPtr->type = TWD_WINDOW;
    twdPtr->winPtr = tkwin;
    return (Window)twdPtr;
}
#endif
................................................................................
	} 
	sprintf(string, "0x%x", (unsigned int)window);
	return string;
    }
    return "";			/* Return empty string if XID is None. */
}

#ifndef WIN32
/*
 *----------------------------------------------------------------------
 *
 * XGeometryErrorProc --
 *
 *	Flags errors generated from XGetGeometry calls to the X server.
 *
................................................................................

    if (!XQueryTree(display, window, &dummy /*parent*/, &dummy /*root*/, 
		   &children, &nChildren)) {
	return NULL;
    }
    if (nChildren > 0) {
	Blt_Chain *chainPtr;
	register int i;

	chainPtr = Blt_ChainCreate();
	for (i = 0; i < nChildren; i++) {
	    /*
	     *  XQuery returns windows in bottom to top order.
	     *  We'll reverse the order.
	     */
................................................................................
	    Tcl_AppendResult(interp, "can't reparent non-toplevel Tk windows",
			     (char *)NULL);
	    return TCL_ERROR;
	}
	tkAdopted = tkwin;
	Tk_MakeWindowExist(tkwin);
	window = Blt_GetRealWindowId(tkwin);
#ifndef WIN32
    } else if ((flags & SEARCH_XID) && (string[0] == '0') && 
	       (string[1] == 'x')) {
	int token;

	/* Hexidecimal string specifying the Window token. */
	if (Tcl_GetInt(interp, string, &token) != TCL_OK) {
	    return TCL_ERROR;
................................................................................
    cntrPtr->display = Tk_Display(tkwin);
    cntrPtr->interp = interp;
    cntrPtr->flags = 0;
    cntrPtr->timeout = SEARCH_INTERVAL;
    cntrPtr->borderWidth = cntrPtr->highlightWidth = 2;
    cntrPtr->relief = TK_RELIEF_SUNKEN;
    Tk_SetClass(tkwin, "Container");
#if (TK_MAJOR_VERSION > 4)
    Blt_SetWindowInstanceData(tkwin, cntrPtr);
#endif
    if (ConfigureContainer(interp, cntrPtr, argc - 2, argv + 2, 0) != TCL_OK) {
	Tk_DestroyWindow(cntrPtr->tkwin);
	return TCL_ERROR;
    }
    mask = (StructureNotifyMask | ExposureMask | FocusChangeMask);
    Tk_CreateEventHandler(tkwin, mask, ContainerEventProc, cntrPtr);
    cntrPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], ContainerInstCmd,
................................................................................
	return;			/* Window has been destroyed. */
    }
    if (!Tk_IsMapped(cntrPtr->tkwin)) {
	return;
    }
    drawable = Tk_WindowId(cntrPtr->tkwin);

#ifndef WIN32
    if (cntrPtr->tkToplevel == NULL) {
	Window window;
	Tk_Window tkToplevel;

	/* Create an event handler for the toplevel of the container. */
	tkToplevel = Blt_Toplevel(cntrPtr->tkwin);
	window = Blt_GetRealWindowId(tkToplevel);
................................................................................
	if (cntrPtr->tkToplevel != NULL) {
	    Tk_CreateEventHandler(cntrPtr->tkToplevel, StructureNotifyMask, 
		ToplevelEventProc, cntrPtr);
	}
    }
#endif /* WIN32 */
    if (cntrPtr->adopted != None) {
#ifndef WIN32
	if (cntrPtr->flags & CONTAINER_MOVE) {
	    /* 
	     * Some applications like Netscape cache its location to
	     * position its popup menus. But when it's reparented, it
	     * thinks it's always at the same position.  It doesn't
	     * know when the container's moved.  The hack here is to
	     * force the application to update its coordinates by
................................................................................
	    cntrPtr->adoptedWidth = width;
	    cntrPtr->adoptedHeight = height;
	    cntrPtr->adoptedX = cntrPtr->adoptedY = cntrPtr->inset;
	    if (cntrPtr->tkAdopted != NULL) {
		Tk_ResizeWindow(cntrPtr->tkAdopted, width, height);
	    }
	}
#ifndef WIN32
	if (!(cntrPtr->flags & CONTAINER_MAPPED)) {
	    XMapWindow(cntrPtr->display, cntrPtr->adopted);
	    cntrPtr->flags |= CONTAINER_MAPPED;
	}
#endif
	if (cntrPtr->borderWidth > 0) {
	    Blt_Draw3DRectangle(cntrPtr->tkwin, drawable, cntrPtr->border,
................................................................................
	    }
	}
    }
    return TCL_OK;
}
#endif

#ifndef WIN32
/*
 *----------------------------------------------------------------------
 *
 * FindOp --
 *
 *----------------------------------------------------------------------
 */
................................................................................
 *
 * --------------------------------------------------------------
 */
static Blt_OpSpec opSpecs[] =
{
    {"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",},
    {"configure", 2, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",},
#ifndef WIN32
    {"find", 1, (Blt_Op)FindOp, 3, 4, "?-command|-name? pattern",},
#endif /*WIN32*/
#ifdef notdef
    {"send", 1, (Blt_Op)SendOp, 4, 4, "window string",},
#endif
};








<
<
<
<







 







|
|
>
>



>
>
|


<
>


>
>
|




>
>
|







 







|







 







|







 







<



<







 







|







 







|







 







|







 







<

<







 







|







 







|







 







|







 







|







 







|







69
70
71
72
73
74
75




76
77
78
79
80
81
82
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
290
291
292
293
294
295
296

297
298
299

300
301
302
303
304
305
306
...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
...
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
....
1318
1319
1320
1321
1322
1323
1324

1325

1326
1327
1328
1329
1330
1331
1332
....
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
....
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
....
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
....
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
#define DEF_CONTAINER_HIGHLIGHT_WIDTH	"2"
#define DEF_CONTAINER_RELIEF		"sunken"
#define DEF_CONTAINER_TAKE_FOCUS	"0"
#define DEF_CONTAINER_TIMEOUT		"20"
#define DEF_CONTAINER_WIDTH		"0"
#define DEF_CONTAINER_WINDOW		(char *)NULL





typedef struct SearchInfoStruct SearchInfo;
typedef void (SearchProc) _ANSI_ARGS_((Display *display, Window window, 
       SearchInfo *searchPtr));

struct SearchInfoStruct {
    SearchProc *proc;
    char *pattern;		/* Search pattern. */
................................................................................
				 * released it's returned to it's
				 * original dimensions. */

    int timeout;
} Container;


static int StringToXID _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp,
    Tk_Window tkwin, CONST char *value, char *widgRec, int offset));
static CONST char *XIDToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption XIDOption =
{
    (Tk_OptionParseProc *)StringToXID,
    (Tk_OptionPrintProc *)XIDToString,
    (ClientData)(SEARCH_TKWIN | SEARCH_XID),
};


#if !defined(WIN32) || defined(PLATFORM_SDL)
static Tk_CustomOption XIDNameOption =
{
    (Tk_OptionParseProc *)StringToXID,
    (Tk_OptionPrintProc *)XIDToString,
    (ClientData)SEARCH_NAME,
};

static Tk_CustomOption XIDCmdOption =
{
    (Tk_OptionParseProc *)StringToXID,
    (Tk_OptionPrintProc *)XIDToString,
    (ClientData)SEARCH_CMD,
};
#endif

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveCountOption;

static Tk_ConfigSpec configSpecs[] =
................................................................................
	DEF_CONTAINER_BACKGROUND, Tk_Offset(Container, border),
	TK_CONFIG_COLOR_ONLY},
    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0},
    {TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0},
    {TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_CONTAINER_BORDERWIDTH, Tk_Offset(Container, borderWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
#if !defined(WIN32) || defined(PLATFORM_SDL)
    {TK_CONFIG_CUSTOM, "-command", "command", "Command",
	DEF_CONTAINER_WINDOW, Tk_Offset(Container, adopted),
	TK_CONFIG_DONT_SET_DEFAULT, &XIDCmdOption},
#endif
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_CONTAINER_CURSOR, Tk_Offset(Container, cursor), TK_CONFIG_NULL_OK},
    {TK_CONFIG_CUSTOM, "-height", "height", "Height",
................................................................................
    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_CONTAINER_HIGHLIGHT_COLOR, 
	Tk_Offset(Container, highlightColor), 0},
    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness",
	DEF_CONTAINER_HIGHLIGHT_WIDTH, Tk_Offset(Container, highlightWidth),
	TK_CONFIG_DONT_SET_DEFAULT},
#if !defined(WIN32) || defined(PLATFORM_SDL)
    {TK_CONFIG_CUSTOM, "-name", "name", "Name",
	DEF_CONTAINER_WINDOW, Tk_Offset(Container, adopted),
	TK_CONFIG_DONT_SET_DEFAULT, &XIDNameOption},
#endif
    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
	DEF_CONTAINER_RELIEF, Tk_Offset(Container, relief), 0},
    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
................................................................................
GetXID(tkwin)
    Tk_Window tkwin;
{
    HWND hWnd;
    TkWinWindow *twdPtr;

    hWnd = Tk_GetHWND(Tk_WindowId(tkwin));

    if (Tk_IsTopLevel(tkwin)) {
	hWnd = GetParent(hWnd);
    }

    twdPtr = Blt_Malloc(sizeof(TkWinWindow));
    twdPtr->handle = hWnd;
    twdPtr->type = TWD_WINDOW;
    twdPtr->winPtr = tkwin;
    return (Window)twdPtr;
}
#endif
................................................................................
	} 
	sprintf(string, "0x%x", (unsigned int)window);
	return string;
    }
    return "";			/* Return empty string if XID is None. */
}

#if !defined(WIN32) || defined(PLATFORM_SDL)
/*
 *----------------------------------------------------------------------
 *
 * XGeometryErrorProc --
 *
 *	Flags errors generated from XGetGeometry calls to the X server.
 *
................................................................................

    if (!XQueryTree(display, window, &dummy /*parent*/, &dummy /*root*/, 
		   &children, &nChildren)) {
	return NULL;
    }
    if (nChildren > 0) {
	Blt_Chain *chainPtr;
	int i;

	chainPtr = Blt_ChainCreate();
	for (i = 0; i < nChildren; i++) {
	    /*
	     *  XQuery returns windows in bottom to top order.
	     *  We'll reverse the order.
	     */
................................................................................
	    Tcl_AppendResult(interp, "can't reparent non-toplevel Tk windows",
			     (char *)NULL);
	    return TCL_ERROR;
	}
	tkAdopted = tkwin;
	Tk_MakeWindowExist(tkwin);
	window = Blt_GetRealWindowId(tkwin);
#if !defined(WIN32) || defined(PLATFORM_SDL)
    } else if ((flags & SEARCH_XID) && (string[0] == '0') && 
	       (string[1] == 'x')) {
	int token;

	/* Hexidecimal string specifying the Window token. */
	if (Tcl_GetInt(interp, string, &token) != TCL_OK) {
	    return TCL_ERROR;
................................................................................
    cntrPtr->display = Tk_Display(tkwin);
    cntrPtr->interp = interp;
    cntrPtr->flags = 0;
    cntrPtr->timeout = SEARCH_INTERVAL;
    cntrPtr->borderWidth = cntrPtr->highlightWidth = 2;
    cntrPtr->relief = TK_RELIEF_SUNKEN;
    Tk_SetClass(tkwin, "Container");

    Blt_SetWindowInstanceData(tkwin, cntrPtr);

    if (ConfigureContainer(interp, cntrPtr, argc - 2, argv + 2, 0) != TCL_OK) {
	Tk_DestroyWindow(cntrPtr->tkwin);
	return TCL_ERROR;
    }
    mask = (StructureNotifyMask | ExposureMask | FocusChangeMask);
    Tk_CreateEventHandler(tkwin, mask, ContainerEventProc, cntrPtr);
    cntrPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], ContainerInstCmd,
................................................................................
	return;			/* Window has been destroyed. */
    }
    if (!Tk_IsMapped(cntrPtr->tkwin)) {
	return;
    }
    drawable = Tk_WindowId(cntrPtr->tkwin);

#if !defined(WIN32) || defined(PLATFORM_SDL)
    if (cntrPtr->tkToplevel == NULL) {
	Window window;
	Tk_Window tkToplevel;

	/* Create an event handler for the toplevel of the container. */
	tkToplevel = Blt_Toplevel(cntrPtr->tkwin);
	window = Blt_GetRealWindowId(tkToplevel);
................................................................................
	if (cntrPtr->tkToplevel != NULL) {
	    Tk_CreateEventHandler(cntrPtr->tkToplevel, StructureNotifyMask, 
		ToplevelEventProc, cntrPtr);
	}
    }
#endif /* WIN32 */
    if (cntrPtr->adopted != None) {
#if !defined(WIN32) || defined(PLATFORM_SDL)
	if (cntrPtr->flags & CONTAINER_MOVE) {
	    /* 
	     * Some applications like Netscape cache its location to
	     * position its popup menus. But when it's reparented, it
	     * thinks it's always at the same position.  It doesn't
	     * know when the container's moved.  The hack here is to
	     * force the application to update its coordinates by
................................................................................
	    cntrPtr->adoptedWidth = width;
	    cntrPtr->adoptedHeight = height;
	    cntrPtr->adoptedX = cntrPtr->adoptedY = cntrPtr->inset;
	    if (cntrPtr->tkAdopted != NULL) {
		Tk_ResizeWindow(cntrPtr->tkAdopted, width, height);
	    }
	}
#if !defined(WIN32) || defined(PLATFORM_SDL)
	if (!(cntrPtr->flags & CONTAINER_MAPPED)) {
	    XMapWindow(cntrPtr->display, cntrPtr->adopted);
	    cntrPtr->flags |= CONTAINER_MAPPED;
	}
#endif
	if (cntrPtr->borderWidth > 0) {
	    Blt_Draw3DRectangle(cntrPtr->tkwin, drawable, cntrPtr->border,
................................................................................
	    }
	}
    }
    return TCL_OK;
}
#endif

#if !defined(WIN32) || defined(PLATFORM_SDL)
/*
 *----------------------------------------------------------------------
 *
 * FindOp --
 *
 *----------------------------------------------------------------------
 */
................................................................................
 *
 * --------------------------------------------------------------
 */
static Blt_OpSpec opSpecs[] =
{
    {"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",},
    {"configure", 2, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",},
#if !defined(WIN32) || defined(PLATFORM_SDL)
    {"find", 1, (Blt_Op)FindOp, 3, 4, "?-command|-name? pattern",},
#endif /*WIN32*/
#ifdef notdef
    {"send", 1, (Blt_Op)SendOp, 4, 4, "window string",},
#endif
};

Changes to jni/blt/src/bltCutbuffer.c.

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	if (GetCutNumber(interp, argv[2], &buffer) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    string = XFetchBuffer(Tk_Display(tkwin), &nBytes, buffer);
    if (string != NULL) {
	int limit;
	register char *p;
	register int i;
	int c;

	if (string[nBytes - 1] == '\0') {
	    limit = nBytes - 1;
	} else {
	    limit = nBytes;
	}







|
|







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	if (GetCutNumber(interp, argv[2], &buffer) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    string = XFetchBuffer(Tk_Display(tkwin), &nBytes, buffer);
    if (string != NULL) {
	int limit;
	char *p;
	int i;
	int c;

	if (string[nBytes - 1] == '\0') {
	    limit = nBytes - 1;
	} else {
	    limit = nBytes;
	}

Changes to jni/blt/src/bltDebug.c.

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
...
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
#include <time.h>
#endif /* HAVE_SYS_TIME_H */
#endif /* TIME_WITH_SYS_TIME */

#include "bltChain.h"
static Blt_Chain watchChain;

static Tcl_CmdTraceProc DebugProc;
static Tcl_CmdProc DebugCmd;

typedef struct {
    char *pattern;
    char *name;
} WatchInfo;

static WatchInfo *
GetWatch(name)
................................................................................
/*ARGSUSED*/
static void
DebugProc(clientData, interp, level, command, proc, cmdClientData,
    argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Not used. */
    int level;			/* Current level */
    char *command;		/* Command before substitution */
    Tcl_CmdProc *proc;		/* Not used. */
    ClientData cmdClientData;	/* Not used. */
    int argc;
    char **argv;		/* Command after parsing, but before
				 * evaluation */
{
    static unsigned char traceStack[200];
    register int i;
    char *string;
    Tcl_Channel errChannel;
    Tcl_DString dString;
    char prompt[200];
    register char *p;
    char *lineStart;
    int count;

    /* This is pretty crappy, but there's no way to trigger stack pops */
    for (i = level + 1; i < 200; i++) {
	traceStack[i] = 0;
    }
    if (Blt_ChainGetLength(&watchChain) > 0) {
................................................................................

/*ARGSUSED*/
static int
DebugCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    static Tcl_Trace token;
    static int level;
    int newLevel;
    char c;
    int length;
    WatchInfo *infoPtr;
    Blt_ChainLink *linkPtr;
    register int i;

    if (argc == 1) {
	Tcl_SetResult(interp, Blt_Itoa(level), TCL_VOLATILE);
	return TCL_OK;
    }
    c = argv[1][0];
    length = strlen(argv[1]);
................................................................................
    } else {
	return TCL_ERROR;
    }
    if (token != 0) {
	Tcl_DeleteTrace(interp, token);
    }
    if (newLevel > 0) {
	token = Tcl_CreateTrace(interp, newLevel, DebugProc, (ClientData)0);

    }
    level = newLevel;
    Tcl_SetResult(interp, Blt_Itoa(level), TCL_VOLATILE);
    return TCL_OK;
}

int







<
<
<







 







|



|



|




<
|







 







|








|







 







|
>







37
38
39
40
41
42
43



44
45
46
47
48
49
50
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include <time.h>
#endif /* HAVE_SYS_TIME_H */
#endif /* TIME_WITH_SYS_TIME */

#include "bltChain.h"
static Blt_Chain watchChain;




typedef struct {
    char *pattern;
    char *name;
} WatchInfo;

static WatchInfo *
GetWatch(name)
................................................................................
/*ARGSUSED*/
static void
DebugProc(clientData, interp, level, command, proc, cmdClientData,
    argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Not used. */
    int level;			/* Current level */
    CONST char *command;		/* Command before substitution */
    Tcl_CmdProc *proc;		/* Not used. */
    ClientData cmdClientData;	/* Not used. */
    int argc;
    CONST char **argv;		/* Command after parsing, but before
				 * evaluation */
{
    static unsigned char traceStack[200];
    int i;
    char *string;
    Tcl_Channel errChannel;
    Tcl_DString dString;
    char prompt[200];

    CONST char *p, *lineStart;
    int count;

    /* This is pretty crappy, but there's no way to trigger stack pops */
    for (i = level + 1; i < 200; i++) {
	traceStack[i] = 0;
    }
    if (Blt_ChainGetLength(&watchChain) > 0) {
................................................................................

/*ARGSUSED*/
static int
DebugCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    static Tcl_Trace token;
    static int level;
    int newLevel;
    char c;
    int length;
    WatchInfo *infoPtr;
    Blt_ChainLink *linkPtr;
    int i;

    if (argc == 1) {
	Tcl_SetResult(interp, Blt_Itoa(level), TCL_VOLATILE);
	return TCL_OK;
    }
    c = argv[1][0];
    length = strlen(argv[1]);
................................................................................
    } else {
	return TCL_ERROR;
    }
    if (token != 0) {
	Tcl_DeleteTrace(interp, token);
    }
    if (newLevel > 0) {
	token = Tcl_CreateTrace(interp, newLevel,
			(Tcl_CmdTraceProc *)DebugProc, (ClientData)0);
    }
    level = newLevel;
    Tcl_SetResult(interp, Blt_Itoa(level), TCL_VOLATILE);
    return TCL_OK;
}

int

Changes to jni/blt/src/bltDragdrop.c.

25
26
27
28
29
30
31





32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
...
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
....
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
....
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
....
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
....
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
....
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
....
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 *
 *	The "drag&drop" command was created by Michael J. McLennan.
 */
#include "bltInt.h"






#ifndef NO_DRAGDROP
#include "bltHash.h"
#include "bltChain.h"

#include <X11/Xatom.h>

#ifdef WIN32
#define MAX_PROP_SIZE 255	/* Maximum size of property. */
typedef HWND WINDOW;
#else
#define MAX_PROP_SIZE 1000	/* Maximum size of property. */
typedef Window WINDOW;
static Atom dndAtom;
#endif
................................................................................
    Window *childArr;
    unsigned int nChildren;
    Window dummy;

    chainPtr = NULL;
    if ((XQueryTree(display, window, &dummy, &dummy, &childArr, &nChildren)) &&
	(nChildren > 0)) {
	register int i;

	chainPtr = Blt_ChainCreate();
	for (i = 0; i < nChildren; i++) {
	    /*
	     *  XQuery returns windows in bottom to top order.
	     *  We only care about the top window.
	     */
................................................................................
    Blt_InitHashTable(&(srcPtr->handlerTable), BLT_STRING_KEYS);
    if (ConfigureSource(interp, srcPtr, 0, (char **)NULL, 0) != TCL_OK) {
	DestroySource(srcPtr);
	return NULL;
    }
    Blt_SetHashValue(hPtr, srcPtr);
    /*
     *  Arrange for the window to unregister itself when it
     *  is destroyed.
     */
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, SourceEventProc, srcPtr);
    return srcPtr;
}
 
/*
................................................................................
 *	reconfigure) a drag&drop source widget.
 *
 * ------------------------------------------------------------------------
 */
static int
ConfigureSource(interp, srcPtr, argc, argv, flags)
    Tcl_Interp *interp;		/* current interpreter */
    register Source *srcPtr;	/* drag&drop source widget record */
    int argc;			/* number of arguments */
    char **argv;		/* argument strings */
    int flags;			/* flags controlling interpretation */
{
    unsigned long gcMask;
    XGCValues gcValues;
    GC newGC;
................................................................................
     * Arrange for the target to removed if the host window is destroyed.  
     */
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, TargetEventProc,
	  targetPtr);
    /*
     *  If this is a new target, attach a property to identify
     *  window as "drag&drop" target, and arrange for the window
     *  to un-register itself when it is destroyed.
     */
    Tk_MakeWindowExist(targetPtr->tkwin);
    AddTargetProperty(interp, targetPtr);
    return targetPtr;
}

/*
................................................................................
 *	Invoked after a drop operation to send data to the drop
 *	application.
 *
 * ------------------------------------------------------------------------
 */
static void
DndSend(srcPtr)
    register Source *srcPtr;	/* drag&drop source record */
{
    int status;
    SubstDescriptors subs[3];
    Tcl_DString dString;
    Blt_HashEntry *hPtr;
    char *dataType;
    char **targetInfo;
................................................................................
 */
static AnyWindow *
FindTopWindow(srcPtr, x, y)
    Source *srcPtr;
    int x, y;
{
    AnyWindow *rootPtr;
    register Blt_ChainLink *linkPtr;
    register AnyWindow *windowPtr;
    WINDOW nativeTokenWindow;

    rootPtr = srcPtr->rootPtr;
    if (!rootPtr->initialized) {
	QueryWindow(srcPtr->display, rootPtr);
    }
    if ((x < rootPtr->x1) || (x > rootPtr->x2) ||
................................................................................
    XFree((char *)data);
    if (result != TCL_OK) {
	return FALSE;		/* Malformed property list. */
    }
    srcPtr->windowPtr = newPtr;
    /* Interpreter name, target name, type1, type2, ... */
    if (nElems > 2) {
	register char **s;
	int count;
	register int i;

	/*
	 * The candidate target has a list of possible types.
	 * Compare this with what types the source is willing to
	 * transmit and compress the list down to just the matching
	 * types.  It's up to the target to request the specific type
	 * it wants.
................................................................................
static char *
ExpandPercents(string, subsArr, nSubs, resultPtr)
    char *string;		/* Incoming command string */
    SubstDescriptors *subsArr;	/* Array of known substitutions */
    int nSubs;			/* Number of elements in subs array */
    Tcl_DString *resultPtr;
{
    register char *chunk, *p;
    char letter;
    char percentSign;
    int i;

    /*
     *  Scan through the copy of the input string, look for
     *  the next '%' character, and try to make the substitution.







>
>
>
>
>







|







 







|







 







|







 







|







 







|







 







|







 







|
|







 







|

|







 







|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
....
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
....
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
....
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
....
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
....
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
....
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
....
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 *
 *	The "drag&drop" command was created by Michael J. McLennan.
 */
#include "bltInt.h"

#ifdef PLATFORM_SDL
#undef  NO_DRAGDROP
#define NO_DRAGDROP
#endif

#ifndef NO_DRAGDROP
#include "bltHash.h"
#include "bltChain.h"

#include <X11/Xatom.h>

#if defined(WIN32) && !defined(PLATFORM_SDL)
#define MAX_PROP_SIZE 255	/* Maximum size of property. */
typedef HWND WINDOW;
#else
#define MAX_PROP_SIZE 1000	/* Maximum size of property. */
typedef Window WINDOW;
static Atom dndAtom;
#endif
................................................................................
    Window *childArr;
    unsigned int nChildren;
    Window dummy;

    chainPtr = NULL;
    if ((XQueryTree(display, window, &dummy, &dummy, &childArr, &nChildren)) &&
	(nChildren > 0)) {
	int i;

	chainPtr = Blt_ChainCreate();
	for (i = 0; i < nChildren; i++) {
	    /*
	     *  XQuery returns windows in bottom to top order.
	     *  We only care about the top window.
	     */
................................................................................
    Blt_InitHashTable(&(srcPtr->handlerTable), BLT_STRING_KEYS);
    if (ConfigureSource(interp, srcPtr, 0, (char **)NULL, 0) != TCL_OK) {
	DestroySource(srcPtr);
	return NULL;
    }
    Blt_SetHashValue(hPtr, srcPtr);
    /*
     *  Arrange for the window to unitself when it
     *  is destroyed.
     */
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, SourceEventProc, srcPtr);
    return srcPtr;
}
 
/*
................................................................................
 *	reconfigure) a drag&drop source widget.
 *
 * ------------------------------------------------------------------------
 */
static int
ConfigureSource(interp, srcPtr, argc, argv, flags)
    Tcl_Interp *interp;		/* current interpreter */
    Source *srcPtr;	/* drag&drop source widget record */
    int argc;			/* number of arguments */
    char **argv;		/* argument strings */
    int flags;			/* flags controlling interpretation */
{
    unsigned long gcMask;
    XGCValues gcValues;
    GC newGC;
................................................................................
     * Arrange for the target to removed if the host window is destroyed.  
     */
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, TargetEventProc,
	  targetPtr);
    /*
     *  If this is a new target, attach a property to identify
     *  window as "drag&drop" target, and arrange for the window
     *  to un-itself when it is destroyed.
     */
    Tk_MakeWindowExist(targetPtr->tkwin);
    AddTargetProperty(interp, targetPtr);
    return targetPtr;
}

/*
................................................................................
 *	Invoked after a drop operation to send data to the drop
 *	application.
 *
 * ------------------------------------------------------------------------
 */
static void
DndSend(srcPtr)
    Source *srcPtr;	/* drag&drop source record */
{
    int status;
    SubstDescriptors subs[3];
    Tcl_DString dString;
    Blt_HashEntry *hPtr;
    char *dataType;
    char **targetInfo;
................................................................................
 */
static AnyWindow *
FindTopWindow(srcPtr, x, y)
    Source *srcPtr;
    int x, y;
{
    AnyWindow *rootPtr;
    Blt_ChainLink *linkPtr;
    AnyWindow *windowPtr;
    WINDOW nativeTokenWindow;

    rootPtr = srcPtr->rootPtr;
    if (!rootPtr->initialized) {
	QueryWindow(srcPtr->display, rootPtr);
    }
    if ((x < rootPtr->x1) || (x > rootPtr->x2) ||
................................................................................
    XFree((char *)data);
    if (result != TCL_OK) {
	return FALSE;		/* Malformed property list. */
    }
    srcPtr->windowPtr = newPtr;
    /* Interpreter name, target name, type1, type2, ... */
    if (nElems > 2) {
	char **s;
	int count;
	int i;

	/*
	 * The candidate target has a list of possible types.
	 * Compare this with what types the source is willing to
	 * transmit and compress the list down to just the matching
	 * types.  It's up to the target to request the specific type
	 * it wants.
................................................................................
static char *
ExpandPercents(string, subsArr, nSubs, resultPtr)
    char *string;		/* Incoming command string */
    SubstDescriptors *subsArr;	/* Array of known substitutions */
    int nSubs;			/* Number of elements in subs array */
    Tcl_DString *resultPtr;
{
    char *chunk, *p;
    char letter;
    char percentSign;
    int i;

    /*
     *  Scan through the copy of the input string, look for
     *  the next '%' character, and try to make the substitution.

Changes to jni/blt/src/bltGrAxis.c.

76
77
78
79
80
81
82
83
84
85
86

87
88
89

90
91
92
93
94




























95
96


97
98
99
100
101


102
103
104
105


106
107
108
109


110
111
112
113


114
115
116
117


118
119
120
121


122
123
124
125


126
127
128
129


130
131
132
133
134
135
136
137
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
...
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
...
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
...
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
...
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
...
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
....
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
....
1422
1423
1424
1425
1426
1427
1428








1429
1430
1431
1432
1433
1434
1435
1436
....
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
....
1552
1553
1554
1555
1556
1557
1558








1559
1560
1561
1562
1563
1564
1565
1566
....
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
....
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
....
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
....
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
....
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
....
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
....
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
....
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
....
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
....
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
....
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
....
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
....
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
....
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
....
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
....
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
....
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
....
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
....
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
....
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
....
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
....
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
....
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
....
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
....
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
....
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
....
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
....
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
....
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
....
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
....
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
....
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
....
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
....
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
....
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
....
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
....
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
} AxisInfo;

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltListOption;

static Tk_OptionParseProc StringToLimit;
static Tk_OptionPrintProc LimitToString;
static Tk_OptionParseProc StringToTicks;
static Tk_OptionPrintProc TicksToString;

static Tk_OptionParseProc StringToAxis;
static Tk_OptionPrintProc AxisToString;
static Tk_OptionParseProc StringToAnyAxis;

static Tk_OptionParseProc StringToFormat;
static Tk_OptionPrintProc FormatToString;
static Tk_OptionParseProc StringToLoose;
static Tk_OptionPrintProc LooseToString;





























static Tk_CustomOption limitOption =
{


    StringToLimit, LimitToString, (ClientData)0
};

static Tk_CustomOption majorTicksOption =
{


    StringToTicks, TicksToString, (ClientData)AXIS_CONFIG_MAJOR,
};
static Tk_CustomOption minorTicksOption =
{


    StringToTicks, TicksToString, (ClientData)AXIS_CONFIG_MINOR,
};
Tk_CustomOption bltXAxisOption =
{


    StringToAxis, AxisToString, (ClientData)&bltXAxisUid
};
Tk_CustomOption bltYAxisOption =
{


    StringToAxis, AxisToString, (ClientData)&bltYAxisUid
};
Tk_CustomOption bltAnyXAxisOption =
{


    StringToAnyAxis, AxisToString, (ClientData)&bltXAxisUid
};
Tk_CustomOption bltAnyYAxisOption =
{


    StringToAnyAxis, AxisToString, (ClientData)&bltYAxisUid
};
static Tk_CustomOption formatOption =
{


    StringToFormat, FormatToString, (ClientData)0,
};
static Tk_CustomOption looseOption =
{


    StringToLoose, LooseToString, (ClientData)0,
};

/* Axis flags: */

#define DEF_AXIS_COMMAND		(char *)NULL
#define DEF_AXIS_DESCENDING		"no"
#define DEF_AXIS_FOREGROUND		RGB_BLACK
................................................................................
#define DEF_AXIS_SHIFTBY		"0.0"
#define DEF_AXIS_SHOWTICKS		"yes"
#define DEF_AXIS_STEP			"0.0"
#define DEF_AXIS_STEP			"0.0"
#define DEF_AXIS_SUBDIVISIONS		"2"
#define DEF_AXIS_TAGS			"all"
#define DEF_AXIS_TICKS			"0"
#ifdef WIN32
#define DEF_AXIS_TICK_FONT		"{Arial Narrow} 8"
#else
#define DEF_AXIS_TICK_FONT		"*-Helvetica-Medium-R-Normal-*-10-*"
#endif
#define DEF_AXIS_TICK_LENGTH		"8"
#define DEF_AXIS_TITLE_ALTERNATE	"0"
#define DEF_AXIS_TITLE_FG		RGB_BLACK
................................................................................
	(char *)NULL, Tk_Offset(Axis, titleTextStyle.shadow),
	TK_CONFIG_MONO_ONLY | ALL_GRAPHS, &bltShadowOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

/* Forward declarations */
static void DestroyAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr));
static int GetAxis _ANSI_ARGS_((Graph *graphPtr, char *name, Blt_Uid classUid,
	Axis **axisPtrPtr));
static void FreeAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr));

INLINE static int
Round(register double x)
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

static void
SetAxisRange(AxisRange *rangePtr, double min, double max)
{
................................................................................
 *	If the value is within the interval [min..max], 1 is 
 *	returned; 0 otherwise.
 *
 * ----------------------------------------------------------------------
 */
INLINE static int
InRange(x, rangePtr)
    register double x;
    AxisRange *rangePtr;
{
    if (rangePtr->range < DBL_EPSILON) {
#ifdef notdef
	return (((rangePtr->max - x) >= (FABS(x) * DBL_EPSILON)) &&
		((x - rangePtr->min) >= (FABS(x) * DBL_EPSILON)));
#endif
................................................................................
/*ARGSUSED*/
static int
StringToAnyAxis(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Class identifier of the type of 
				 * axis we are looking for. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph. */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis **axisPtrPtr = (Axis **)(widgRec + offset);
    Blt_Uid classUid = *(Blt_Uid *)clientData;
    Graph *graphPtr;
    Axis *axisPtr;
................................................................................
/*ARGSUSED*/
static int
StringToAxis(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Class identifier of the type of 
				 * axis we are looking for. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph. */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis **axisPtrPtr = (Axis **)(widgRec + offset);
    Blt_Uid classUid = *(Blt_Uid *)clientData;
    Graph *graphPtr;

................................................................................
 */
/*ARGSUSED*/
static int
StringToFormat(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis *axisPtr = (Axis *)(widgRec);
    char **argv;
    int argc;

    if (axisPtr->limitsFormats != NULL) {
	Blt_Free(axisPtr->limitsFormats);
    }
    axisPtr->limitsFormats = NULL;
    axisPtr->nFormats = 0;
................................................................................
/*ARGSUSED*/
static int
StringToLimit(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Either AXIS_CONFIG_MIN or AXIS_CONFIG_MAX.
				 * Indicates which axis limit to set. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    double *limitPtr = (double *)(widgRec + offset);

    if ((string == NULL) || (*string == '\0')) {
	*limitPtr = VALUE_UNDEFINED;
................................................................................
 */
/*ARGSUSED*/
static int
StringToTicks(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    unsigned int mask = (unsigned int)clientData;
    Axis *axisPtr = (Axis *)widgRec;
    Ticks **ticksPtrPtr = (Ticks **) (widgRec + offset);
    int nTicks;
    Ticks *ticksPtr;

    nTicks = 0;
    ticksPtr = NULL;
    if ((string != NULL) && (*string != '\0')) {
	int nExprs;
	char **exprArr;

	if (Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nExprs > 0) {
	    register int i;
	    int result = TCL_ERROR;
	    double value;

	    ticksPtr = Blt_Malloc(sizeof(Ticks) + (nExprs * sizeof(double)));
	    assert(ticksPtr);
	    for (i = 0; i < nExprs; i++) {
		result = Tcl_ExprDouble(interp, exprArr[i], &value);
................................................................................
    Tk_Window tkwin;		/* Not used. */
    char *widgRec;		/* */
    int offset;
    Tcl_FreeProc **freeProcPtr;
{
    Ticks *ticksPtr = *(Ticks **) (widgRec + offset);
    char string[TCL_DOUBLE_SPACE + 1];
    register int i;
    char *result;
    Tcl_DString dString;
    Graph *graphPtr;

    if (ticksPtr == NULL) {
	return "";
    }
................................................................................
 */
/*ARGSUSED*/
static int
StringToLoose(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis *axisPtr = (Axis *)(widgRec);
    register int i;
    int argc;
    char **argv;
    int values[2];

    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((argc < 1) || (argc > 2)) {
	Tcl_AppendResult(interp, "wrong # elements in loose value \"",
................................................................................
}

static Ticks *
GenerateTicks(sweepPtr)
    TickSweep *sweepPtr;
{
    Ticks *ticksPtr;
    register int i;

    ticksPtr = Blt_Malloc(sizeof(Ticks) + (sweepPtr->nSteps * sizeof(double)));
    assert(ticksPtr);

    if (sweepPtr->step == 0.0) { 
	static double logTable[] = /* Precomputed log10 values [1..10] */
	{
................................................................................
    double range;
    double tickMin, tickMax;
    double majorStep, minorStep;
    int nMajor, nMinor;

    nMajor = nMinor = 0;
    majorStep = minorStep = 0.0;








    if (min < max) {
	min = (min != 0.0) ? log10(FABS(min)) : 0.0;
	max = (max != 0.0) ? log10(FABS(max)) : 1.0;
	
	tickMin = floor(min);
	tickMax = ceil(max);
	range = tickMax - tickMin;
	
................................................................................
	    nMajor++;
	}
	if ((axisPtr->looseMax == TICK_RANGE_TIGHT) ||
	    ((axisPtr->looseMax == TICK_RANGE_LOOSE) &&
	     (DEFINED(axisPtr->reqMax)))) {
	    tickMax = max;
	}
    }
    axisPtr->majorSweep.step = majorStep;
    axisPtr->majorSweep.initial = floor(tickMin);
    axisPtr->majorSweep.nSteps = nMajor;
    axisPtr->minorSweep.initial = axisPtr->minorSweep.step = minorStep;
    axisPtr->minorSweep.nSteps = nMinor;
    SetAxisRange(&axisPtr->axisRange, tickMin, tickMax);
}
................................................................................
    double range, step;
    double tickMin, tickMax;
    double axisMin, axisMax;
    int nTicks;

    nTicks = 0;
    tickMin = tickMax = 0.0;








    if (min < max) {
	range = max - min;
	
	/* Calculate the major tick stepping. */
	if (axisPtr->reqStep > 0.0) {
	    /* An interval was designated by the user.  Keep scaling it
	     * until it fits comfortably within the current range of the
	     * axis.  */
................................................................................
	}
	
	/* Find the outer tick values. Add 0.0 to prevent getting -0.0. */
	axisMin = tickMin = floor(min / step) * step + 0.0;
	axisMax = tickMax = ceil(max / step) * step + 0.0;
	
	nTicks = Round((tickMax - tickMin) / step) + 1;
    }
    axisPtr->majorSweep.step = step;
    axisPtr->majorSweep.initial = tickMin;
    axisPtr->majorSweep.nSteps = nTicks;
    
    /*
     * The limits of the axis are either the range of the data
     * ("tight") or at the next outer tick interval ("loose").  The
................................................................................
	/* Axis baseline */
	MakeAxisLine(graphPtr, axisPtr, info.axis, segPtr);
	segPtr++;
    }
    if (axisPtr->showTicks) {
	double t1, t2;
	double labelPos;
	register int i, j;
	int isHoriz;
	TickLabel *labelPtr;
	Blt_ChainLink *linkPtr;
	Segment2D seg;

	isHoriz = AxisIsHorizontal(graphPtr, axisPtr);
	for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) {
................................................................................
		axisPtr->max = EXP10(axisPtr->max);
	    }
	    Blt_UpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix,
		(viewMax / worldWidth), (viewMin / worldWidth));
	}
    }
    if (axisPtr->showTicks) {
	register Blt_ChainLink *linkPtr;
	TickLabel *labelPtr;

	for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); linkPtr != NULL;
	    linkPtr = Blt_ChainNextLink(linkPtr)) {	
	    /* Draw major tick labels */
	    labelPtr = Blt_ChainGetValue(linkPtr);
	    Blt_DrawText(graphPtr->tkwin, drawable, labelPtr->string,
................................................................................
    Axis *axisPtr;
{
    if (axisPtr->title != NULL) {
	Blt_TextToPostScript(psToken, axisPtr->title, &axisPtr->titleTextStyle, 
		axisPtr->titlePos.x, axisPtr->titlePos.y);
    }
    if (axisPtr->showTicks) {
	register Blt_ChainLink *linkPtr;
	TickLabel *labelPtr;

	for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    labelPtr = Blt_ChainGetValue(linkPtr);
	    Blt_TextToPostScript(psToken, labelPtr->string, 
		&axisPtr->tickTextStyle, labelPtr->anchorPos.x, 
................................................................................
    Graph *graphPtr;
    Axis *axisPtr;
    Segment2D **segPtrPtr;
    int *nSegmentsPtr;
{
    int needed;
    Ticks *t1Ptr, *t2Ptr;
    register int i;
    double value;
    Segment2D *segments, *segPtr;

    *nSegmentsPtr = 0;
    *segPtrPtr = NULL;
    if (axisPtr == NULL) {
	return;
................................................................................
	return;			/* Can't allocate memory for grid. */
    }

    segPtr = segments;
    for (i = 0; i < t1Ptr->nTicks; i++) {
	value = t1Ptr->values[i];
	if (graphPtr->gridPtr->minorGrid) {
	    register int j;
	    double subValue;

	    for (j = 0; j < t2Ptr->nTicks; j++) {
		subValue = value +
		    (axisPtr->majorSweep.step * t2Ptr->values[j]);
		if (InRange(subValue, &axisPtr->axisRange)) {
		    MakeGridLine(graphPtr, axisPtr, subValue, segPtr);
................................................................................
    height = 0;
    if (axisPtr->lineWidth > 0) {
	/* Leave room for axis baseline (and pad) */
	height += axisPtr->lineWidth + 2;
    }
    if (axisPtr->showTicks) {
	int pad;
	register int i, nLabels;
	int lw, lh;
	double x, x2;
	int maxWidth, maxHeight;
	TickLabel *labelPtr;

	SweepTicks(axisPtr);
	
................................................................................
    *axisPtrPtr = NULL;
    return TCL_ERROR;
}

static int
GetAxis(graphPtr, axisName, classUid, axisPtrPtr)
    Graph *graphPtr;
    char *axisName;
    Blt_Uid classUid;
    Axis **axisPtrPtr;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, axisName, &axisPtr) != TCL_OK) {
	return TCL_ERROR;
................................................................................
    Blt_ChainDestroy(graphPtr->axes.displayList);
}

int
Blt_DefaultAxes(graphPtr)
    Graph *graphPtr;
{
    register int i;
    Axis *axisPtr;
    Blt_Chain *chainPtr;
    static char *axisNames[4] = { "x", "y", "x2", "y2" } ;
    int flags;

    flags = Blt_GraphType(graphPtr);
    for (i = 0; i < 4; i++) {
	chainPtr = Blt_ChainCreate();
	graphPtr->axisChain[i] = chainPtr;

................................................................................
	/*
	 * Blt_ConfigureWidgetComponent creates a temporary child window 
	 * by the name of the axis.  It's used so that the Tk routines
	 * that access the X resource database can describe a single 
	 * component and not the entire graph.
	 */
	if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
		axisPtr->name, "Axis", configSpecs, 0, (char **)NULL,
		(char *)axisPtr, flags) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	axisPtr->linkPtr = Blt_ChainAppend(chainPtr, axisPtr);
................................................................................
 *----------------------------------------------------------------------
 */
static int
BindOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;
    char **argv;
{
    Tcl_Interp *interp = graphPtr->interp;

    return Blt_ConfigureBindings(interp, graphPtr->bindTable,
          Blt_MakeAxisTag(graphPtr, axisPtr->name), argc, argv);
}
          
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    char *argv[];
{
    return Tk_ConfigureValue(graphPtr->interp, graphPtr->tkwin, configSpecs,
	(char *)axisPtr, argv[0], Blt_GraphType(graphPtr));
}

/*
 * ----------------------------------------------------------------------
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;
    char *argv[];
{
    int flags;

    flags = TK_CONFIG_ARGV_ONLY | Blt_GraphType(graphPtr);
    if (argc == 0) {
	return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs,
	    (char *)axisPtr, (char *)NULL, flags);
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;                 /* Not used. */
    char *argv[];
{
    Tcl_Interp *interp = graphPtr->interp;
    register Axis *axisPtr;

    axisPtr = (Axis *)Blt_GetCurrentItem(graphPtr->bindTable);
    /* Report only on axes. */
    if ((axisPtr != NULL) && 
	((axisPtr->classUid == bltXAxisUid) ||
	 (axisPtr->classUid == bltYAxisUid) || 
	 (axisPtr->classUid == NULL))) {
................................................................................
 */
/*ARGSUSED*/
static int
LimitsOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    char **argv;		/* Not used. */

{
    Tcl_Interp *interp = graphPtr->interp;
    double min, max;

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
................................................................................
 */
/*ARGSUSED*/
static int
InvTransformOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    char **argv;
{
    int x;			/* Integer window coordinate*/
    double y;			/* Real graph coordinate */

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
................................................................................
 */
/*ARGSUSED*/
static int
TransformOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;		/* Axis */
    int argc;			/* Not used. */
    char **argv;
{
    double x;

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
    if (Tcl_ExprDouble(graphPtr->interp, argv[0], &x) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
UseOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;		/* Not used. */
    int argc;
    char **argv;
{
    Blt_Chain *chainPtr;
    int nNames;
    char **names;
    Blt_ChainLink *linkPtr;
    int i;
    Blt_Uid classUid;
    int margin;

    margin = (int)argv[-1];
    chainPtr = graphPtr->margins[margin].axes;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
CreateVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Axis *axisPtr;
    int flags;

    axisPtr = CreateAxis(graphPtr, argv[3], MARGIN_NONE);
    if (axisPtr == NULL) {
	return TCL_ERROR;
................................................................................
 *----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
BindVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Tcl_Interp *interp = graphPtr->interp;

    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;
................................................................................
 * ----------------------------------------------------------------------
 */
/* ARGSUSED */
static int
CgetVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char *argv[];
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return CgetOp(graphPtr, axisPtr, argc - 4, argv + 4);
................................................................................
 *
 * ----------------------------------------------------------------------
 */
static int
ConfigureVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char *argv[];
{
    Axis *axisPtr;
    int nNames, nOpts;
    char **options;
    register int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
DeleteVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char **argv;
{
    register int i;
    Axis *axisPtr;

    for (i = 3; i < argc; i++) {
	if (NameToAxis(graphPtr, argv[i], &axisPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	axisPtr->deletePending = TRUE;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
InvTransformVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    char **argv;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return InvTransformOp(graphPtr, axisPtr, argc - 4, argv + 4);
................................................................................
 *--------------------------------------------------------------
 */
/*ARGSUSED*/
static int
LimitsVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    char **argv;		/* Not used. */

{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
 */

/*ARGSUSED*/
static int
NamesVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    char **argv;		/* Not used. */
{
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Axis *axisPtr;
    register int i;

    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
	if (axisPtr->deletePending) {
	    continue;
	}
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
TransformVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    char **argv;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return TransformOp(graphPtr, axisPtr, argc - 4, argv + 4);
}

static int
ViewOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Axis *axisPtr;
    Tcl_Interp *interp = graphPtr->interp;
    double axisOffset, scrollUnits;
    double fract;
    double viewMin, viewMax, worldMin, worldMax;
    double viewWidth, worldWidth;
................................................................................
}

int
Blt_VirtualAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;
    int result;
    static Blt_OpSpec axisOps[] =
    {
	{"bind", 1, (Blt_Op)BindVirtualOp, 3, 6, 
	     "axisName sequence command",},
................................................................................
}

int
Blt_AxisOp(graphPtr, margin, argc, argv)
    Graph *graphPtr;
    int margin;
    int argc;
    char **argv;
{
    int result;
    Blt_Op proc;
    Axis *axisPtr;
    static Blt_OpSpec axisOps[] =
    {
	{"bind", 1, (Blt_Op)BindOp, 2, 5, "sequence command",},
................................................................................
void
Blt_MapAxes(graphPtr)
    Graph *graphPtr;
{
    Axis *axisPtr;
    Blt_Chain *chainPtr;
    Blt_ChainLink *linkPtr;
    register int margin;
    int offset;
    
    for (margin = 0; margin < 4; margin++) {
	chainPtr = graphPtr->margins[margin].axes;
	offset = 0;
	for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
	     linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
void
Blt_DrawAxes(graphPtr, drawable)
    Graph *graphPtr;
    Drawable drawable;
{
    Axis *axisPtr;
    Blt_ChainLink *linkPtr;
    register int i;

    for (i = 0; i < 4; i++) {
	for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    axisPtr = Blt_ChainGetValue(linkPtr);
	    if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) {
		DrawAxis(graphPtr, drawable, axisPtr);
................................................................................
void
Blt_AxesToPostScript(graphPtr, psToken)
    Graph *graphPtr;
    PsToken psToken;
{
    Axis *axisPtr;
    Blt_ChainLink *linkPtr;
    register int i;

    for (i = 0; i < 4; i++) {
	for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    axisPtr = Blt_ChainGetValue(linkPtr);
	    if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) {
		AxisToPostScript(psToken, axisPtr);
................................................................................
{
    Axis *axisPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Dim2D textDim;
    int isHoriz;
    char *minPtr, *maxPtr;
    char *minFormat, *maxFormat;
    char minString[200], maxString[200];
    int vMin, hMin, vMax, hMax;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padLeft + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2;	/* Offsets */

................................................................................
{
    Axis *axisPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    double vMin, hMin, vMax, hMax;
    char string[200];
    int textWidth, textHeight;
    char *minFmt, *maxFmt;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padLeft + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2;	/* Offsets */
    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
................................................................................
}

Axis *
Blt_NearestAxis(graphPtr, x, y)
    Graph *graphPtr;
    int x, y;                 /* Point to be tested */
{
    register Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Axis *axisPtr;
    int width, height;
    double rotWidth, rotHeight;
    Point2D bbox[5];
    
    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
................................................................................
	 hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
	if ((axisPtr->hidden) || (!(axisPtr->flags & AXIS_ONSCREEN))) {
	    continue;		/* Don't check hidden axes or axes
				 * that are virtual. */
	}
	if (axisPtr->showTicks) {
	    register Blt_ChainLink *linkPtr;
	    TickLabel *labelPtr;
	    Point2D t;

	    for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); 
		 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {	
		labelPtr = Blt_ChainGetValue(linkPtr);
		Blt_GetBoundingBox(labelPtr->width, labelPtr->height, 
................................................................................
    }
    return NULL;
}
 
ClientData
Blt_MakeAxisTag(graphPtr, tagName)
    Graph *graphPtr;
    char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->axes.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->axes.tagTable, hPtr);
}







|
|
|
<
>
|
|
<
>
|
|
|
<

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
|




>
>
|



>
>
|



>
>
|



>
>
|



>
>
|



>
>
|



>
>
|



>
>
|







 







|







 







|
|



|







 







|







 







|







 







|







 







|




|







 







|







 







|













|





|







 







|







 







|




|

|







 







|







 







>
>
>
>
>
>
>
>
|







 







|







 







>
>
>
>
>
>
>
>
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|


|







 







|







 







|







 







|







 







|







 







|


|







 







|
<







 







|







 







|







 







|



|







 







|







 







|







 







|







 







|



|
|







 







|

|







 







|







 







|







 







|




|







 







|













|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|








76
77
78
79
80
81
82
83
84
85

86
87
88

89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
...
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
...
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
....
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
....
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
....
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
....
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
....
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
....
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
....
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
....
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
....
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
....
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
....
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
....
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
....
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
....
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
....
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
....
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
....
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
....
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
....
3569
3570
3571
3572
3573
3574
3575
3576

3577
3578
3579
3580
3581
3582
3583
....
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
....
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
....
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
....
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
....
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
....
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
....
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
....
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
....
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
....
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
....
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
....
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
....
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
....
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
....
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
....
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
....
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
....
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
....
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
....
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
....
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
....
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
} AxisInfo;

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltListOption;

static int StringToLimit _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *LimitToString _ANSI_ARGS_((ClientData, Tk_Window tkwin,
    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));


static int StringToTicks _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *TicksToString _ANSI_ARGS_((ClientData, Tk_Window tkwin,
    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToAxis _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *AxisToString _ANSI_ARGS_((ClientData, Tk_Window tkwin,
    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToAnyAxis _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static int StringToFormat _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *FormatToString _ANSI_ARGS_((ClientData, Tk_Window tkwin,
    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToLoose _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *LooseToString _ANSI_ARGS_((ClientData, Tk_Window tkwin,
    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption limitOption =
{
    (Tk_OptionParseProc *)StringToLimit,
    (Tk_OptionPrintProc *)LimitToString,
    (ClientData)0
};

static Tk_CustomOption majorTicksOption =
{
    (Tk_OptionParseProc *)StringToTicks,
    (Tk_OptionPrintProc *)TicksToString,
    (ClientData)AXIS_CONFIG_MAJOR,
};
static Tk_CustomOption minorTicksOption =
{
    (Tk_OptionParseProc *)StringToTicks,
    (Tk_OptionPrintProc *)TicksToString,
    (ClientData)AXIS_CONFIG_MINOR,
};
Tk_CustomOption bltXAxisOption =
{
    (Tk_OptionParseProc *)StringToAxis,
    (Tk_OptionPrintProc *)AxisToString,
    (ClientData)&bltXAxisUid
};
Tk_CustomOption bltYAxisOption =
{
    (Tk_OptionParseProc *)StringToAxis,
    (Tk_OptionPrintProc *)AxisToString,
    (ClientData)&bltYAxisUid
};
Tk_CustomOption bltAnyXAxisOption =
{
    (Tk_OptionParseProc *)StringToAnyAxis,
    (Tk_OptionPrintProc *)AxisToString,
    (ClientData)&bltXAxisUid
};
Tk_CustomOption bltAnyYAxisOption =
{
    (Tk_OptionParseProc *)StringToAnyAxis,
    (Tk_OptionPrintProc *)AxisToString,
    (ClientData)&bltYAxisUid
};
static Tk_CustomOption formatOption =
{
    (Tk_OptionParseProc *)StringToFormat,
    (Tk_OptionPrintProc *)FormatToString,
    (ClientData)0,
};
static Tk_CustomOption looseOption =
{
    (Tk_OptionParseProc *)StringToLoose,
    (Tk_OptionPrintProc *)LooseToString,
    (ClientData)0,
};

/* Axis flags: */

#define DEF_AXIS_COMMAND		(char *)NULL
#define DEF_AXIS_DESCENDING		"no"
#define DEF_AXIS_FOREGROUND		RGB_BLACK
................................................................................
#define DEF_AXIS_SHIFTBY		"0.0"
#define DEF_AXIS_SHOWTICKS		"yes"
#define DEF_AXIS_STEP			"0.0"
#define DEF_AXIS_STEP			"0.0"
#define DEF_AXIS_SUBDIVISIONS		"2"
#define DEF_AXIS_TAGS			"all"
#define DEF_AXIS_TICKS			"0"
#if defined(WIN32) && !defined(PLATFORM_SDL)
#define DEF_AXIS_TICK_FONT		"{Arial Narrow} 8"
#else
#define DEF_AXIS_TICK_FONT		"*-Helvetica-Medium-R-Normal-*-10-*"
#endif
#define DEF_AXIS_TICK_LENGTH		"8"
#define DEF_AXIS_TITLE_ALTERNATE	"0"
#define DEF_AXIS_TITLE_FG		RGB_BLACK
................................................................................
	(char *)NULL, Tk_Offset(Axis, titleTextStyle.shadow),
	TK_CONFIG_MONO_ONLY | ALL_GRAPHS, &bltShadowOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

/* Forward declarations */
static void DestroyAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr));
static int GetAxis _ANSI_ARGS_((Graph *graphPtr, CONST char *name,
	Blt_Uid classUid, Axis **axisPtrPtr));
static void FreeAxis _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr));

INLINE static int
Round(double x)
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

static void
SetAxisRange(AxisRange *rangePtr, double min, double max)
{
................................................................................
 *	If the value is within the interval [min..max], 1 is 
 *	returned; 0 otherwise.
 *
 * ----------------------------------------------------------------------
 */
INLINE static int
InRange(x, rangePtr)
    double x;
    AxisRange *rangePtr;
{
    if (rangePtr->range < DBL_EPSILON) {
#ifdef notdef
	return (((rangePtr->max - x) >= (FABS(x) * DBL_EPSILON)) &&
		((x - rangePtr->min) >= (FABS(x) * DBL_EPSILON)));
#endif
................................................................................
/*ARGSUSED*/
static int
StringToAnyAxis(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Class identifier of the type of 
				 * axis we are looking for. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph. */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis **axisPtrPtr = (Axis **)(widgRec + offset);
    Blt_Uid classUid = *(Blt_Uid *)clientData;
    Graph *graphPtr;
    Axis *axisPtr;
................................................................................
/*ARGSUSED*/
static int
StringToAxis(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Class identifier of the type of 
				 * axis we are looking for. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph. */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis **axisPtrPtr = (Axis **)(widgRec + offset);
    Blt_Uid classUid = *(Blt_Uid *)clientData;
    Graph *graphPtr;

................................................................................
 */
/*ARGSUSED*/
static int
StringToFormat(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to. */
    Tk_Window tkwin;		/* Used to look up pointer to graph */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis *axisPtr = (Axis *)(widgRec);
    CONST char **argv;
    int argc;

    if (axisPtr->limitsFormats != NULL) {
	Blt_Free(axisPtr->limitsFormats);
    }
    axisPtr->limitsFormats = NULL;
    axisPtr->nFormats = 0;
................................................................................
/*ARGSUSED*/
static int
StringToLimit(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Either AXIS_CONFIG_MIN or AXIS_CONFIG_MAX.
				 * Indicates which axis limit to set. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    double *limitPtr = (double *)(widgRec + offset);

    if ((string == NULL) || (*string == '\0')) {
	*limitPtr = VALUE_UNDEFINED;
................................................................................
 */
/*ARGSUSED*/
static int
StringToTicks(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    unsigned int mask = (unsigned int)clientData;
    Axis *axisPtr = (Axis *)widgRec;
    Ticks **ticksPtrPtr = (Ticks **) (widgRec + offset);
    int nTicks;
    Ticks *ticksPtr;

    nTicks = 0;
    ticksPtr = NULL;
    if ((string != NULL) && (*string != '\0')) {
	int nExprs;
	CONST char **exprArr;

	if (Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nExprs > 0) {
	    int i;
	    int result = TCL_ERROR;
	    double value;

	    ticksPtr = Blt_Malloc(sizeof(Ticks) + (nExprs * sizeof(double)));
	    assert(ticksPtr);
	    for (i = 0; i < nExprs; i++) {
		result = Tcl_ExprDouble(interp, exprArr[i], &value);
................................................................................
    Tk_Window tkwin;		/* Not used. */
    char *widgRec;		/* */
    int offset;
    Tcl_FreeProc **freeProcPtr;
{
    Ticks *ticksPtr = *(Ticks **) (widgRec + offset);
    char string[TCL_DOUBLE_SPACE + 1];
    int i;
    char *result;
    Tcl_DString dString;
    Graph *graphPtr;

    if (ticksPtr == NULL) {
	return "";
    }
................................................................................
 */
/*ARGSUSED*/
static int
StringToLoose(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing new value. */
    char *widgRec;		/* Pointer to structure record. */
    int offset;			/* Offset of field in structure. */
{
    Axis *axisPtr = (Axis *)(widgRec);
    int i;
    int argc;
    CONST char **argv;
    int values[2];

    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((argc < 1) || (argc > 2)) {
	Tcl_AppendResult(interp, "wrong # elements in loose value \"",
................................................................................
}

static Ticks *
GenerateTicks(sweepPtr)
    TickSweep *sweepPtr;
{
    Ticks *ticksPtr;
    int i;

    ticksPtr = Blt_Malloc(sizeof(Ticks) + (sweepPtr->nSteps * sizeof(double)));
    assert(ticksPtr);

    if (sweepPtr->step == 0.0) { 
	static double logTable[] = /* Precomputed log10 values [1..10] */
	{
................................................................................
    double range;
    double tickMin, tickMax;
    double majorStep, minorStep;
    int nMajor, nMinor;

    nMajor = nMinor = 0;
    majorStep = minorStep = 0.0;
    if (min > max) {
	double m;
	m = min;
	min = max;
	max = m;
    } else if (min == max) {
	max = min + 1.0;
    }
    /* if (min < max) { */
	min = (min != 0.0) ? log10(FABS(min)) : 0.0;
	max = (max != 0.0) ? log10(FABS(max)) : 1.0;
	
	tickMin = floor(min);
	tickMax = ceil(max);
	range = tickMax - tickMin;
	
................................................................................
	    nMajor++;
	}
	if ((axisPtr->looseMax == TICK_RANGE_TIGHT) ||
	    ((axisPtr->looseMax == TICK_RANGE_LOOSE) &&
	     (DEFINED(axisPtr->reqMax)))) {
	    tickMax = max;
	}
    /* } */
    axisPtr->majorSweep.step = majorStep;
    axisPtr->majorSweep.initial = floor(tickMin);
    axisPtr->majorSweep.nSteps = nMajor;
    axisPtr->minorSweep.initial = axisPtr->minorSweep.step = minorStep;
    axisPtr->minorSweep.nSteps = nMinor;
    SetAxisRange(&axisPtr->axisRange, tickMin, tickMax);
}
................................................................................
    double range, step;
    double tickMin, tickMax;
    double axisMin, axisMax;
    int nTicks;

    nTicks = 0;
    tickMin = tickMax = 0.0;
    if (min > max) {
	double m;
	m = min;
	min = max;
	max = m;
    } else if (min == max) {
	max = min + 1.0;
    }
    /* if (min < max) { */
	range = max - min;
	
	/* Calculate the major tick stepping. */
	if (axisPtr->reqStep > 0.0) {
	    /* An interval was designated by the user.  Keep scaling it
	     * until it fits comfortably within the current range of the
	     * axis.  */
................................................................................
	}
	
	/* Find the outer tick values. Add 0.0 to prevent getting -0.0. */
	axisMin = tickMin = floor(min / step) * step + 0.0;
	axisMax = tickMax = ceil(max / step) * step + 0.0;
	
	nTicks = Round((tickMax - tickMin) / step) + 1;
    /* } */
    axisPtr->majorSweep.step = step;
    axisPtr->majorSweep.initial = tickMin;
    axisPtr->majorSweep.nSteps = nTicks;
    
    /*
     * The limits of the axis are either the range of the data
     * ("tight") or at the next outer tick interval ("loose").  The
................................................................................
	/* Axis baseline */
	MakeAxisLine(graphPtr, axisPtr, info.axis, segPtr);
	segPtr++;
    }
    if (axisPtr->showTicks) {
	double t1, t2;
	double labelPos;
	int i, j;
	int isHoriz;
	TickLabel *labelPtr;
	Blt_ChainLink *linkPtr;
	Segment2D seg;

	isHoriz = AxisIsHorizontal(graphPtr, axisPtr);
	for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) {
................................................................................
		axisPtr->max = EXP10(axisPtr->max);
	    }
	    Blt_UpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix,
		(viewMax / worldWidth), (viewMin / worldWidth));
	}
    }
    if (axisPtr->showTicks) {
	Blt_ChainLink *linkPtr;
	TickLabel *labelPtr;

	for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); linkPtr != NULL;
	    linkPtr = Blt_ChainNextLink(linkPtr)) {	
	    /* Draw major tick labels */
	    labelPtr = Blt_ChainGetValue(linkPtr);
	    Blt_DrawText(graphPtr->tkwin, drawable, labelPtr->string,
................................................................................
    Axis *axisPtr;
{
    if (axisPtr->title != NULL) {
	Blt_TextToPostScript(psToken, axisPtr->title, &axisPtr->titleTextStyle, 
		axisPtr->titlePos.x, axisPtr->titlePos.y);
    }
    if (axisPtr->showTicks) {
	Blt_ChainLink *linkPtr;
	TickLabel *labelPtr;

	for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    labelPtr = Blt_ChainGetValue(linkPtr);
	    Blt_TextToPostScript(psToken, labelPtr->string, 
		&axisPtr->tickTextStyle, labelPtr->anchorPos.x, 
................................................................................
    Graph *graphPtr;
    Axis *axisPtr;
    Segment2D **segPtrPtr;
    int *nSegmentsPtr;
{
    int needed;
    Ticks *t1Ptr, *t2Ptr;
    int i;
    double value;
    Segment2D *segments, *segPtr;

    *nSegmentsPtr = 0;
    *segPtrPtr = NULL;
    if (axisPtr == NULL) {
	return;
................................................................................
	return;			/* Can't allocate memory for grid. */
    }

    segPtr = segments;
    for (i = 0; i < t1Ptr->nTicks; i++) {
	value = t1Ptr->values[i];
	if (graphPtr->gridPtr->minorGrid) {
	    int j;
	    double subValue;

	    for (j = 0; j < t2Ptr->nTicks; j++) {
		subValue = value +
		    (axisPtr->majorSweep.step * t2Ptr->values[j]);
		if (InRange(subValue, &axisPtr->axisRange)) {
		    MakeGridLine(graphPtr, axisPtr, subValue, segPtr);
................................................................................
    height = 0;
    if (axisPtr->lineWidth > 0) {
	/* Leave room for axis baseline (and pad) */
	height += axisPtr->lineWidth + 2;
    }
    if (axisPtr->showTicks) {
	int pad;
	int i, nLabels;
	int lw, lh;
	double x, x2;
	int maxWidth, maxHeight;
	TickLabel *labelPtr;

	SweepTicks(axisPtr);
	
................................................................................
    *axisPtrPtr = NULL;
    return TCL_ERROR;
}

static int
GetAxis(graphPtr, axisName, classUid, axisPtrPtr)
    Graph *graphPtr;
    CONST char *axisName;
    Blt_Uid classUid;
    Axis **axisPtrPtr;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, axisName, &axisPtr) != TCL_OK) {
	return TCL_ERROR;
................................................................................
    Blt_ChainDestroy(graphPtr->axes.displayList);
}

int
Blt_DefaultAxes(graphPtr)
    Graph *graphPtr;
{
    int i;
    Axis *axisPtr;
    Blt_Chain *chainPtr;
    static CONST char *axisNames[4] = { "x", "y", "x2", "y2" } ;
    int flags;

    flags = Blt_GraphType(graphPtr);
    for (i = 0; i < 4; i++) {
	chainPtr = Blt_ChainCreate();
	graphPtr->axisChain[i] = chainPtr;

................................................................................
	/*
	 * Blt_ConfigureWidgetComponent creates a temporary child window 
	 * by the name of the axis.  It's used so that the Tk routines
	 * that access the X resource database can describe a single 
	 * component and not the entire graph.
	 */
	if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
		axisPtr->name, "Axis", configSpecs, 0, NULL,
		(char *)axisPtr, flags) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	axisPtr->linkPtr = Blt_ChainAppend(chainPtr, axisPtr);
................................................................................
 *----------------------------------------------------------------------
 */
static int
BindOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;
    CONST char **argv;
{
    Tcl_Interp *interp = graphPtr->interp;

    return Blt_ConfigureBindings(interp, graphPtr->bindTable,
          Blt_MakeAxisTag(graphPtr, axisPtr->name), argc, argv);
}
          
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    CONST char *argv[];
{
    return Tk_ConfigureValue(graphPtr->interp, graphPtr->tkwin, configSpecs,
	(char *)axisPtr, argv[0], Blt_GraphType(graphPtr));
}

/*
 * ----------------------------------------------------------------------
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;
    CONST char *argv[];
{
    int flags;

    flags = TK_CONFIG_ARGV_ONLY | Blt_GraphType(graphPtr);
    if (argc == 0) {
	return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs,
	    (char *)axisPtr, (char *)NULL, flags);
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;                 /* Not used. */
    CONST char *argv[];
{
    Tcl_Interp *interp = graphPtr->interp;
    Axis *axisPtr;

    axisPtr = (Axis *)Blt_GetCurrentItem(graphPtr->bindTable);
    /* Report only on axes. */
    if ((axisPtr != NULL) && 
	((axisPtr->classUid == bltXAxisUid) ||
	 (axisPtr->classUid == bltYAxisUid) || 
	 (axisPtr->classUid == NULL))) {
................................................................................
 */
/*ARGSUSED*/
static int
LimitsOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    CONST char **argv;		/* Not used. */

{
    Tcl_Interp *interp = graphPtr->interp;
    double min, max;

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
................................................................................
 */
/*ARGSUSED*/
static int
InvTransformOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;
    int argc;			/* Not used. */
    CONST char **argv;
{
    int x;			/* Integer window coordinate*/
    double y;			/* Real graph coordinate */

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
................................................................................
 */
/*ARGSUSED*/
static int
TransformOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;		/* Axis */
    int argc;			/* Not used. */
    CONST char **argv;
{
    double x;

    if (graphPtr->flags & RESET_AXES) {
	Blt_ResetAxes(graphPtr);
    }
    if (Tcl_ExprDouble(graphPtr->interp, argv[0], &x) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
UseOp(graphPtr, axisPtr, argc, argv)
    Graph *graphPtr;
    Axis *axisPtr;		/* Not used. */
    int argc;
    CONST char **argv;
{
    Blt_Chain *chainPtr;
    int nNames;
    CONST char **names;
    Blt_ChainLink *linkPtr;
    int i;
    Blt_Uid classUid;
    int margin;

    margin = (int)argv[-1];
    chainPtr = graphPtr->margins[margin].axes;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
CreateVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Axis *axisPtr;
    int flags;

    axisPtr = CreateAxis(graphPtr, argv[3], MARGIN_NONE);
    if (axisPtr == NULL) {
	return TCL_ERROR;
................................................................................
 *----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
BindVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Tcl_Interp *interp = graphPtr->interp;

    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;
................................................................................
 * ----------------------------------------------------------------------
 */
/* ARGSUSED */
static int
CgetVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char *argv[];
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return CgetOp(graphPtr, axisPtr, argc - 4, argv + 4);
................................................................................
 *
 * ----------------------------------------------------------------------
 */
static int
ConfigureVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char *argv[];
{
    Axis *axisPtr;
    int nNames, nOpts;
    CONST char **options;
    int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
DeleteVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    int i;
    Axis *axisPtr;

    for (i = 3; i < argc; i++) {
	if (NameToAxis(graphPtr, argv[i], &axisPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	axisPtr->deletePending = TRUE;
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
InvTransformVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    CONST char **argv;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return InvTransformOp(graphPtr, axisPtr, argc - 4, argv + 4);
................................................................................
 *--------------------------------------------------------------
 */
/*ARGSUSED*/
static int
LimitsVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    CONST char **argv;		/* Not used. */

{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
 */

/*ARGSUSED*/
static int
NamesVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    CONST char **argv;		/* Not used. */
{
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Axis *axisPtr;
    int i;

    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
	if (axisPtr->deletePending) {
	    continue;
	}
................................................................................
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
TransformVirtualOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;			/* Not used. */
    CONST char **argv;
{
    Axis *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    return TransformOp(graphPtr, axisPtr, argc - 4, argv + 4);
}

static int
ViewOp(graphPtr, argc, argv)
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Axis *axisPtr;
    Tcl_Interp *interp = graphPtr->interp;
    double axisOffset, scrollUnits;
    double fract;
    double viewMin, viewMax, worldMin, worldMax;
    double viewWidth, worldWidth;
................................................................................
}

int
Blt_VirtualAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;
    int result;
    static Blt_OpSpec axisOps[] =
    {
	{"bind", 1, (Blt_Op)BindVirtualOp, 3, 6, 
	     "axisName sequence command",},
................................................................................
}

int
Blt_AxisOp(graphPtr, margin, argc, argv)
    Graph *graphPtr;
    int margin;
    int argc;
    CONST char **argv;
{
    int result;
    Blt_Op proc;
    Axis *axisPtr;
    static Blt_OpSpec axisOps[] =
    {
	{"bind", 1, (Blt_Op)BindOp, 2, 5, "sequence command",},
................................................................................
void
Blt_MapAxes(graphPtr)
    Graph *graphPtr;
{
    Axis *axisPtr;
    Blt_Chain *chainPtr;
    Blt_ChainLink *linkPtr;
    int margin;
    int offset;
    
    for (margin = 0; margin < 4; margin++) {
	chainPtr = graphPtr->margins[margin].axes;
	offset = 0;
	for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
	     linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
void
Blt_DrawAxes(graphPtr, drawable)
    Graph *graphPtr;
    Drawable drawable;
{
    Axis *axisPtr;
    Blt_ChainLink *linkPtr;
    int i;

    for (i = 0; i < 4; i++) {
	for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    axisPtr = Blt_ChainGetValue(linkPtr);
	    if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) {
		DrawAxis(graphPtr, drawable, axisPtr);
................................................................................
void
Blt_AxesToPostScript(graphPtr, psToken)
    Graph *graphPtr;
    PsToken psToken;
{
    Axis *axisPtr;
    Blt_ChainLink *linkPtr;
    int i;

    for (i = 0; i < 4; i++) {
	for (linkPtr = Blt_ChainFirstLink(graphPtr->margins[i].axes); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	    axisPtr = Blt_ChainGetValue(linkPtr);
	    if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) {
		AxisToPostScript(psToken, axisPtr);
................................................................................
{
    Axis *axisPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Dim2D textDim;
    int isHoriz;
    char *minPtr, *maxPtr;
    CONST char *minFormat, *maxFormat;
    char minString[200], maxString[200];
    int vMin, hMin, vMax, hMax;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padLeft + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2;	/* Offsets */

................................................................................
{
    Axis *axisPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    double vMin, hMin, vMax, hMax;
    char string[200];
    int textWidth, textHeight;
    CONST char *minFmt, *maxFmt;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padLeft + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padBottom - 2;	/* Offsets */
    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
................................................................................
}

Axis *
Blt_NearestAxis(graphPtr, x, y)
    Graph *graphPtr;
    int x, y;                 /* Point to be tested */
{
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Axis *axisPtr;
    int width, height;
    double rotWidth, rotHeight;
    Point2D bbox[5];
    
    for (hPtr = Blt_FirstHashEntry(&graphPtr->axes.table, &cursor);
................................................................................
	 hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	axisPtr = (Axis *)Blt_GetHashValue(hPtr);
	if ((axisPtr->hidden) || (!(axisPtr->flags & AXIS_ONSCREEN))) {
	    continue;		/* Don't check hidden axes or axes
				 * that are virtual. */
	}
	if (axisPtr->showTicks) {
	    Blt_ChainLink *linkPtr;
	    TickLabel *labelPtr;
	    Point2D t;

	    for (linkPtr = Blt_ChainFirstLink(axisPtr->tickLabels); 
		 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {	
		labelPtr = Blt_ChainGetValue(linkPtr);
		Blt_GetBoundingBox(labelPtr->width, labelPtr->height, 
................................................................................
    }
    return NULL;
}
 
ClientData
Blt_MakeAxisTag(graphPtr, tagName)
    Graph *graphPtr;
    CONST char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->axes.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->axes.tagTable, hPtr);
}

Changes to jni/blt/src/bltGrAxis.h.

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    unsigned short int titleWidth, titleHeight;	

    int lineWidth;		/* Width of lines representing axis
				 * (including ticks).  If zero, then
				 * no axis lines or ticks are
				 * drawn. */

    char **limitsFormats;	/* One or two strings of sprintf-like
				 * formats describing how to display
				 * virtual axis limits. If NULL,
				 * display no limits. */
    int nFormats;

    TextStyle limitsTextStyle;	/* Text attributes (color, font,
				 * rotation, etc.)  of the limits. */







|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    unsigned short int titleWidth, titleHeight;	

    int lineWidth;		/* Width of lines representing axis
				 * (including ticks).  If zero, then
				 * no axis lines or ticks are
				 * drawn. */

    CONST char **limitsFormats;	/* One or two strings of sprintf-like
				 * formats describing how to display
				 * virtual axis limits. If NULL,
				 * display no limits. */
    int nFormats;

    TextStyle limitsTextStyle;	/* Text attributes (color, font,
				 * rotation, etc.)  of the limits. */

Changes to jni/blt/src/bltGrBar.c.

23
24
25
26
27
28
29

30
31
32
33
34
35
36
...
197
198
199
200
201
202
203
204
205
206
207










208
209
210


211
212
213
214
215


216
217
218
219
220
221
222
223
...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
...
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
...
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
...
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
...
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
...
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
...
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
....
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
....
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
....
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
....
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
....
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
....
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
....
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
....
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
....
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
....
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
....
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
....
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
....
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */

#include "bltGraph.h"
#include <X11/Xutil.h>


#include "bltGrElem.h"

typedef struct {
    char *name;			/* Pen style identifier.  If NULL pen
				 * was statically allocated. */
    Blt_Uid classUid;		/* Type of pen */
................................................................................
extern Tk_CustomOption bltXAxisOption;
extern Tk_CustomOption bltYAxisOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltFillOption;
extern Tk_CustomOption bltColorOption;
extern Tk_CustomOption bltStateOption;

extern Tk_OptionParseProc Blt_StringToStyles;
extern Tk_OptionPrintProc Blt_StylesToString;
static Tk_OptionParseProc StringToBarMode;
static Tk_OptionPrintProc BarModeToString;











static Tk_CustomOption stylesOption =
{


    Blt_StringToStyles, Blt_StylesToString, (ClientData)sizeof(BarPenStyle)
};

Tk_CustomOption bltBarModeOption =
{


    StringToBarMode, BarModeToString, (ClientData)0
};

#define DEF_BAR_ACTIVE_PEN		"activeBar"
#define DEF_BAR_AXIS_X			"x"
#define DEF_BAR_AXIS_Y			"y"
#define DEF_BAR_BACKGROUND		"navyblue"
#define DEF_BAR_BG_MONO			BLACK
................................................................................
static ElementToPostScriptProc ActiveBarToPostScript;
static ElementToPostScriptProc NormalBarToPostScript;
static ElementSymbolToPostScriptProc SymbolToPostScript;
static ElementMapProc MapBar;

INLINE static int
Round(x)
    register double x;
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

/*
 * ----------------------------------------------------------------------
 * Custom option parse and print procedures
................................................................................
 */
/*ARGSUSED*/
static int
StringToBarMode(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Mode style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    BarMode *modePtr = (BarMode *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
/* 
 * Zero out the style's number of rectangles and errorbars. 
 */
static void
ClearPalette(palette)
    Blt_Chain *palette;
{
    register BarPenStyle *stylePtr;
    Blt_ChainLink *linkPtr;

    for (linkPtr = Blt_ChainFirstLink(palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->xErrorBarCnt = stylePtr->yErrorBarCnt = stylePtr->nRects = 0;
    }
................................................................................
    penPtr->errorBarShow = SHOW_BOTH;
    penPtr->valueShow = SHOW_NONE;
    penPtr->borderWidth = 2;
}

Pen *
Blt_BarPen(penName)
    char *penName;
{
    BarPen *penPtr;

    penPtr = Blt_Calloc(1, sizeof(BarPen));
    assert(penPtr);
    InitPen(penPtr);
    penPtr->name = Blt_Strdup(penName);
................................................................................
static void
CheckStacks(graphPtr, pairPtr, minPtr, maxPtr)
    Graph *graphPtr;
    Axis2D *pairPtr;
    double *minPtr, *maxPtr;	/* Current minimum maximum for y-axis */
{
    FreqInfo *infoPtr;
    register int i;

    if ((graphPtr->mode != MODE_STACKED) || (graphPtr->nStacks == 0)) {
	return;
    }
    infoPtr = graphPtr->freqArr;
    for (i = 0; i < graphPtr->nStacks; i++) {
	if ((infoPtr->axes.x == pairPtr->x) && 
................................................................................
 *
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
ConfigureBar(graphPtr, elemPtr)
    Graph *graphPtr;
    register Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    Blt_ChainLink *linkPtr;

    if (ConfigurePen(graphPtr, (Pen *)&(barPtr->builtinPen)) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
    } else {
	if (extsPtr->top > 0.0) {
	    extsPtr->top = 0.0;
	}
    }
    /* Correct the extents for error bars if they exist. */
    if (elemPtr->xError.nValues > 0) {
	register int i;
	double x;
	
	/* Correct the data limits for error bars */
	nPoints = MIN(elemPtr->xError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
	    if (x > extsPtr->right) {
................................................................................
	    }
	    if (left < extsPtr->left) {
		extsPtr->left = left;
	    }
	}
    }
    if (elemPtr->yError.nValues > 0) {
	register int i;
	double y;
	
	nPoints = MIN(elemPtr->yError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
	    if (y > extsPtr->bottom) {
		extsPtr->bottom = y;
................................................................................
    Bar *barPtr = (Bar *)elemPtr;
    Point2D *pointPtr, *endPtr;
    Point2D t, outline[5];
    XRectangle *rectPtr;
    double left, right, top, bottom;
    double minDist, dist;
    int imin;
    register int i;

    minDist = searchPtr->dist;
    imin = 0;
    
    rectPtr = barPtr->rectangles;
    for (i = 0; i < barPtr->nRects; i++) {
	if (PointInRectangle(rectPtr, searchPtr->x, searchPtr->y)) {
................................................................................
    /* We have more than one style. Group bar segments of like pen
     * styles together.  */

    if (barPtr->nRects > 0) {
	XRectangle *rectangles;
	int *rectToData;
	int dataIndex;
	register XRectangle *rectPtr;
	register int *indexPtr;
	register int i;

	rectangles = Blt_Malloc(barPtr->nRects * sizeof(XRectangle));
	rectToData = Blt_Malloc(barPtr->nRects * sizeof(int));
	assert(rectangles && rectToData);

	rectPtr = rectangles, indexPtr = rectToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
................................................................................
	Blt_Free(barPtr->rectToData);
	barPtr->rectToData = rectToData;
    }
    if (barPtr->xErrorBarCnt > 0) {
	Segment2D *errorBars, *segPtr;
	int *errorToData, *indexPtr;
	int dataIndex;
	register int i;

	errorBars = Blt_Malloc(barPtr->xErrorBarCnt * sizeof(Segment2D));
	errorToData = Blt_Malloc(barPtr->xErrorBarCnt * sizeof(int));
	assert(errorBars);
	segPtr = errorBars, indexPtr = errorToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
	Blt_Free(barPtr->xErrorToData);
	barPtr->xErrorToData = errorToData;
    }
    if (barPtr->yErrorBarCnt > 0) {
	Segment2D *errorBars, *segPtr;
	int *errorToData, *indexPtr;
	int dataIndex;
	register int i;

	errorBars = Blt_Malloc(barPtr->yErrorBarCnt * sizeof(Segment2D));
	errorToData = Blt_Malloc(barPtr->yErrorBarCnt * sizeof(int));
	assert(errorBars);
	segPtr = errorBars, indexPtr = errorToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
	barPtr->activeToData = NULL;
    }
    barPtr->nActive = 0;

    if (barPtr->nActiveIndices > 0) {
	XRectangle *activeRects;
	int *activeToData;
	register int i, n;
	register int count;

	activeRects = Blt_Malloc(sizeof(XRectangle) * barPtr->nActiveIndices);
	assert(activeRects);
	activeToData = Blt_Malloc(sizeof(int) * barPtr->nActiveIndices);
	assert(activeToData);
	count = 0;
	for (i = 0; i < barPtr->nRects; i++) {
................................................................................
    double barWidth, barOffset;
    double baseline;
    double dx, dy;
    int *rectToData;		/* Maps rectangles to data point indices */
    int height;
    int invertBar;
    int nPoints, count;
    register XRectangle *rectPtr, *rectangles;
    register int i;
    int size;
    Blt_ChainLink *linkPtr;
    BarPenStyle *stylePtr;

    ResetBar(barPtr);
    nPoints = NumberOfPoints(barPtr);
    if (nPoints < 1) {
................................................................................
DrawBarSegments(
    Graph *graphPtr,
    Drawable drawable,		/* Pixmap or window to draw into */
    BarPen *penPtr,
    XRectangle *rectangles,
    int nRects)
{
    register XRectangle *rectPtr;

    if ((penPtr->border == NULL) && (penPtr->fgColor == NULL)) {
	return;
    }
    XFillRectangles(graphPtr->display, drawable, penPtr->gc, rectangles, 
		    nRects);
    if ((penPtr->border != NULL) && (penPtr->borderWidth > 0) && 
................................................................................
    Graph *graphPtr;
    Drawable drawable;
    Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    int count;
    Blt_ChainLink *linkPtr;
    register BarPenStyle *stylePtr;
    BarPen *penPtr;

    count = 0;
    for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	penPtr = stylePtr->penPtr;
................................................................................
}

static void
SegmentsToPostScript(graphPtr, psToken, penPtr, rectPtr, nRects)
    Graph *graphPtr;
    PsToken psToken;
    BarPen *penPtr;
    register XRectangle *rectPtr;
    int nRects;
{
    XRectangle *endPtr;

    if ((penPtr->border == NULL) && (penPtr->fgColor == NULL)) {
	return;
    }
................................................................................
NormalBarToPostScript(graphPtr, psToken, elemPtr)
    Graph *graphPtr;
    PsToken psToken;
    Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    Blt_ChainLink *linkPtr;
    register BarPenStyle *stylePtr;
    int count;
    BarPen *penPtr;
    XColor *colorPtr;

    count = 0;
    for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................

Element *
Blt_BarElement(graphPtr, name, type)
    Graph *graphPtr;
    char *name;
    Blt_Uid type;
{
    register Bar *barPtr;

    barPtr = Blt_Calloc(1, sizeof(Bar));
    assert(barPtr);
    barPtr->normalPenPtr = &(barPtr->builtinPen);
    barPtr->procsPtr = &barProcs;
    barPtr->specsPtr = barElemConfigSpecs;
    barPtr->labelRelief = TK_RELIEF_FLAT;
................................................................................
 *
 * ----------------------------------------------------------------------
 */
void
Blt_InitFreqTable(graphPtr)
    Graph *graphPtr;
{
    register Element *elemPtr;
    Blt_ChainLink *linkPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Bar *barPtr;
    int isNew, count;
    int nStacks, nSegs;
    int nPoints;
    FreqKey key;
    Blt_HashTable freqTable;
    register int i;
    double *xArr;
    /*
     * Free resources associated with a previous frequency table. This
     * includes the array of frequency information and the table itself
     */
    if (graphPtr->freqArr != NULL) {
	Blt_Free(graphPtr->freqArr);
................................................................................
{
    Element *elemPtr;
    Bar *barPtr;
    FreqKey key;
    Blt_ChainLink *linkPtr;
    Blt_HashEntry *hPtr;
    int nPoints;
    register int i;
    register FreqInfo *infoPtr;
    double *xArr, *yArr;

    if ((graphPtr->mode != MODE_STACKED) || (graphPtr->nStacks == 0)) {
	return;
    }
    /* Reset the sums for all duplicate values to zero. */

................................................................................
    }
}

void
Blt_ResetStacks(graphPtr)
    Graph *graphPtr;
{
    register FreqInfo *infoPtr, *endPtr;

    for (infoPtr = graphPtr->freqArr, 
	     endPtr = graphPtr->freqArr + graphPtr->nStacks;
	 infoPtr < endPtr; infoPtr++) {
	infoPtr->lastY = 0.0;
	infoPtr->count = 0;
    }
}








>







 







|
|
|
<
>
>
>
>
>
>
>
>
>
>



>
>
|




>
>
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|
|
|







 







|







 







|







 







|
|







 







|
|







 







|







 







|







 







|







 







|







 







|







 







|









|







 







|
|







 







|









23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
...
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
...
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
....
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
....
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
....
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
....
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
....
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
....
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
....
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
....
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
....
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
....
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
....
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
....
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
....
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */

#include "bltGraph.h"
#include <X11/Xutil.h>
#include <X11/Xlib.h>

#include "bltGrElem.h"

typedef struct {
    char *name;			/* Pen style identifier.  If NULL pen
				 * was statically allocated. */
    Blt_Uid classUid;		/* Type of pen */
................................................................................
extern Tk_CustomOption bltXAxisOption;
extern Tk_CustomOption bltYAxisOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltFillOption;
extern Tk_CustomOption bltColorOption;
extern Tk_CustomOption bltStateOption;

extern int Blt_StringToStyles _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


extern char *Blt_StylesToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToBarMode _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *BarModeToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption stylesOption =
{
    (Tk_OptionParseProc *)Blt_StringToStyles,
    (Tk_OptionPrintProc *)Blt_StylesToString,
    (ClientData)sizeof(BarPenStyle)
};

Tk_CustomOption bltBarModeOption =
{
    (Tk_OptionParseProc *)StringToBarMode,
    (Tk_OptionPrintProc *)BarModeToString,
    (ClientData)0
};

#define DEF_BAR_ACTIVE_PEN		"activeBar"
#define DEF_BAR_AXIS_X			"x"
#define DEF_BAR_AXIS_Y			"y"
#define DEF_BAR_BACKGROUND		"navyblue"
#define DEF_BAR_BG_MONO			BLACK
................................................................................
static ElementToPostScriptProc ActiveBarToPostScript;
static ElementToPostScriptProc NormalBarToPostScript;
static ElementSymbolToPostScriptProc SymbolToPostScript;
static ElementMapProc MapBar;

INLINE static int
Round(x)
    double x;
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

/*
 * ----------------------------------------------------------------------
 * Custom option parse and print procedures
................................................................................
 */
/*ARGSUSED*/
static int
StringToBarMode(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Mode style string */
    char *widgRec;		/* Cubicle structure record */
    int offset;			/* Offset of style in record */
{
    BarMode *modePtr = (BarMode *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
/* 
 * Zero out the style's number of rectangles and errorbars. 
 */
static void
ClearPalette(palette)
    Blt_Chain *palette;
{
    BarPenStyle *stylePtr;
    Blt_ChainLink *linkPtr;

    for (linkPtr = Blt_ChainFirstLink(palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->xErrorBarCnt = stylePtr->yErrorBarCnt = stylePtr->nRects = 0;
    }
................................................................................
    penPtr->errorBarShow = SHOW_BOTH;
    penPtr->valueShow = SHOW_NONE;
    penPtr->borderWidth = 2;
}

Pen *
Blt_BarPen(penName)
    CONST char *penName;
{
    BarPen *penPtr;

    penPtr = Blt_Calloc(1, sizeof(BarPen));
    assert(penPtr);
    InitPen(penPtr);
    penPtr->name = Blt_Strdup(penName);
................................................................................
static void
CheckStacks(graphPtr, pairPtr, minPtr, maxPtr)
    Graph *graphPtr;
    Axis2D *pairPtr;
    double *minPtr, *maxPtr;	/* Current minimum maximum for y-axis */
{
    FreqInfo *infoPtr;
    int i;

    if ((graphPtr->mode != MODE_STACKED) || (graphPtr->nStacks == 0)) {
	return;
    }
    infoPtr = graphPtr->freqArr;
    for (i = 0; i < graphPtr->nStacks; i++) {
	if ((infoPtr->axes.x == pairPtr->x) && 
................................................................................
 *
 * ----------------------------------------------------------------------
 */
/*ARGSUSED*/
static int
ConfigureBar(graphPtr, elemPtr)
    Graph *graphPtr;
    Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    Blt_ChainLink *linkPtr;

    if (ConfigurePen(graphPtr, (Pen *)&(barPtr->builtinPen)) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
    } else {
	if (extsPtr->top > 0.0) {
	    extsPtr->top = 0.0;
	}
    }
    /* Correct the extents for error bars if they exist. */
    if (elemPtr->xError.nValues > 0) {
	int i;
	double x;
	
	/* Correct the data limits for error bars */
	nPoints = MIN(elemPtr->xError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
	    if (x > extsPtr->right) {
................................................................................
	    }
	    if (left < extsPtr->left) {
		extsPtr->left = left;
	    }
	}
    }
    if (elemPtr->yError.nValues > 0) {
	int i;
	double y;
	
	nPoints = MIN(elemPtr->yError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
	    if (y > extsPtr->bottom) {
		extsPtr->bottom = y;
................................................................................
    Bar *barPtr = (Bar *)elemPtr;
    Point2D *pointPtr, *endPtr;
    Point2D t, outline[5];
    XRectangle *rectPtr;
    double left, right, top, bottom;
    double minDist, dist;
    int imin;
    int i;

    minDist = searchPtr->dist;
    imin = 0;
    
    rectPtr = barPtr->rectangles;
    for (i = 0; i < barPtr->nRects; i++) {
	if (PointInRectangle(rectPtr, searchPtr->x, searchPtr->y)) {
................................................................................
    /* We have more than one style. Group bar segments of like pen
     * styles together.  */

    if (barPtr->nRects > 0) {
	XRectangle *rectangles;
	int *rectToData;
	int dataIndex;
	XRectangle *rectPtr;
	int *indexPtr;
	int i;

	rectangles = Blt_Malloc(barPtr->nRects * sizeof(XRectangle));
	rectToData = Blt_Malloc(barPtr->nRects * sizeof(int));
	assert(rectangles && rectToData);

	rectPtr = rectangles, indexPtr = rectToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
................................................................................
	Blt_Free(barPtr->rectToData);
	barPtr->rectToData = rectToData;
    }
    if (barPtr->xErrorBarCnt > 0) {
	Segment2D *errorBars, *segPtr;
	int *errorToData, *indexPtr;
	int dataIndex;
	int i;

	errorBars = Blt_Malloc(barPtr->xErrorBarCnt * sizeof(Segment2D));
	errorToData = Blt_Malloc(barPtr->xErrorBarCnt * sizeof(int));
	assert(errorBars);
	segPtr = errorBars, indexPtr = errorToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
	Blt_Free(barPtr->xErrorToData);
	barPtr->xErrorToData = errorToData;
    }
    if (barPtr->yErrorBarCnt > 0) {
	Segment2D *errorBars, *segPtr;
	int *errorToData, *indexPtr;
	int dataIndex;
	int i;

	errorBars = Blt_Malloc(barPtr->yErrorBarCnt * sizeof(Segment2D));
	errorToData = Blt_Malloc(barPtr->yErrorBarCnt * sizeof(int));
	assert(errorBars);
	segPtr = errorBars, indexPtr = errorToData;
	for (linkPtr = Blt_ChainFirstLink(barPtr->palette); 
	     linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................
	barPtr->activeToData = NULL;
    }
    barPtr->nActive = 0;

    if (barPtr->nActiveIndices > 0) {
	XRectangle *activeRects;
	int *activeToData;
	int i, n;
	int count;

	activeRects = Blt_Malloc(sizeof(XRectangle) * barPtr->nActiveIndices);
	assert(activeRects);
	activeToData = Blt_Malloc(sizeof(int) * barPtr->nActiveIndices);
	assert(activeToData);
	count = 0;
	for (i = 0; i < barPtr->nRects; i++) {
................................................................................
    double barWidth, barOffset;
    double baseline;
    double dx, dy;
    int *rectToData;		/* Maps rectangles to data point indices */
    int height;
    int invertBar;
    int nPoints, count;
    XRectangle *rectPtr, *rectangles;
    int i;
    int size;
    Blt_ChainLink *linkPtr;
    BarPenStyle *stylePtr;

    ResetBar(barPtr);
    nPoints = NumberOfPoints(barPtr);
    if (nPoints < 1) {
................................................................................
DrawBarSegments(
    Graph *graphPtr,
    Drawable drawable,		/* Pixmap or window to draw into */
    BarPen *penPtr,
    XRectangle *rectangles,
    int nRects)
{
    XRectangle *rectPtr;

    if ((penPtr->border == NULL) && (penPtr->fgColor == NULL)) {
	return;
    }
    XFillRectangles(graphPtr->display, drawable, penPtr->gc, rectangles, 
		    nRects);
    if ((penPtr->border != NULL) && (penPtr->borderWidth > 0) && 
................................................................................
    Graph *graphPtr;
    Drawable drawable;
    Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    int count;
    Blt_ChainLink *linkPtr;
    BarPenStyle *stylePtr;
    BarPen *penPtr;

    count = 0;
    for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	penPtr = stylePtr->penPtr;
................................................................................
}

static void
SegmentsToPostScript(graphPtr, psToken, penPtr, rectPtr, nRects)
    Graph *graphPtr;
    PsToken psToken;
    BarPen *penPtr;
    XRectangle *rectPtr;
    int nRects;
{
    XRectangle *endPtr;

    if ((penPtr->border == NULL) && (penPtr->fgColor == NULL)) {
	return;
    }
................................................................................
NormalBarToPostScript(graphPtr, psToken, elemPtr)
    Graph *graphPtr;
    PsToken psToken;
    Element *elemPtr;
{
    Bar *barPtr = (Bar *)elemPtr;
    Blt_ChainLink *linkPtr;
    BarPenStyle *stylePtr;
    int count;
    BarPen *penPtr;
    XColor *colorPtr;

    count = 0;
    for (linkPtr = Blt_ChainFirstLink(barPtr->palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
................................................................................

Element *
Blt_BarElement(graphPtr, name, type)
    Graph *graphPtr;
    char *name;
    Blt_Uid type;
{
    Bar *barPtr;

    barPtr = Blt_Calloc(1, sizeof(Bar));
    assert(barPtr);
    barPtr->normalPenPtr = &(barPtr->builtinPen);
    barPtr->procsPtr = &barProcs;
    barPtr->specsPtr = barElemConfigSpecs;
    barPtr->labelRelief = TK_RELIEF_FLAT;
................................................................................
 *
 * ----------------------------------------------------------------------
 */
void
Blt_InitFreqTable(graphPtr)
    Graph *graphPtr;
{
    Element *elemPtr;
    Blt_ChainLink *linkPtr;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    Bar *barPtr;
    int isNew, count;
    int nStacks, nSegs;
    int nPoints;
    FreqKey key;
    Blt_HashTable freqTable;
    int i;
    double *xArr;
    /*
     * Free resources associated with a previous frequency table. This
     * includes the array of frequency information and the table itself
     */
    if (graphPtr->freqArr != NULL) {
	Blt_Free(graphPtr->freqArr);
................................................................................
{
    Element *elemPtr;
    Bar *barPtr;
    FreqKey key;
    Blt_ChainLink *linkPtr;
    Blt_HashEntry *hPtr;
    int nPoints;
    int i;
    FreqInfo *infoPtr;
    double *xArr, *yArr;

    if ((graphPtr->mode != MODE_STACKED) || (graphPtr->nStacks == 0)) {
	return;
    }
    /* Reset the sums for all duplicate values to zero. */

................................................................................
    }
}

void
Blt_ResetStacks(graphPtr)
    Graph *graphPtr;
{
    FreqInfo *infoPtr, *endPtr;

    for (infoPtr = graphPtr->freqArr, 
	     endPtr = graphPtr->freqArr + graphPtr->nStacks;
	 infoPtr < endPtr; infoPtr++) {
	infoPtr->lastY = 0.0;
	infoPtr->count = 0;
    }
}

Changes to jni/blt/src/bltGrElem.c.

26
27
28
29
30
31
32
33
34
35
36

37
38















39
40


41
42

43
44


45
46

47
48


49
50

51
52
53
54
55
56
57
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
...
343
344
345
346
347
348
349
350
351
352
353
354
355


356
357

358


359
360
361
362
363
364
365
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
...
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
771
772
773
774
775
776
777

778
779
780
781
782
783
784
...
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
...
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
....
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
....
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
....
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
....
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
....
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
....
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
....
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
....
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
....
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
....
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
....
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
....
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
....
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
....
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
....
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
....
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
....
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
 */

#include "bltGraph.h"
#include "bltChain.h"
#include <X11/Xutil.h>


static Tk_OptionParseProc StringToData;
static Tk_OptionPrintProc DataToString;
static Tk_OptionParseProc StringToDataPairs;
static Tk_OptionPrintProc DataPairsToString;

static Tk_OptionParseProc StringToAlong;
static Tk_OptionPrintProc AlongToString;















static Tk_CustomOption alongOption =
{


    StringToAlong, AlongToString, (ClientData)0
};

Tk_CustomOption bltDataOption =
{


    StringToData, DataToString, (ClientData)0
};

Tk_CustomOption bltDataPairsOption =
{


    StringToDataPairs, DataPairsToString, (ClientData)0
};

extern Tk_CustomOption bltDistanceOption;

 
static int counter;

#include "bltGrElem.h"

................................................................................
 * ----------------------------------------------------------------------
 * Custom option parse and print procedures
 * ----------------------------------------------------------------------
 */
static int
GetPenStyle(graphPtr, string, type, stylePtr)
    Graph *graphPtr;
    char *string;
    Blt_Uid type;
    PenStyle *stylePtr;
{
    Pen *penPtr;
    Tcl_Interp *interp = graphPtr->interp;
    char **elemArr;
    int nElem;

    elemArr = NULL;
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((nElem != 1) && (nElem != 3)) {
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
FindRange(vPtr)
    ElemVector *vPtr;
{
    register int i;
    register double *x;
    register double min, max;

    if ((vPtr->nValues < 1) || (vPtr->valueArr == NULL)) {
	return;			/* This shouldn't ever happen. */
    }
    x = vPtr->valueArr;

    min = DBL_MAX, max = -DBL_MAX;
................................................................................
 *----------------------------------------------------------------------
 */
double
Blt_FindElemVectorMinimum(vPtr, minLimit)
    ElemVector *vPtr;
    double minLimit;
{
    register int i;
    register double *arr;
    register double min, x;

    min = DBL_MAX;
    arr = vPtr->valueArr;
    for (i = 0; i < vPtr->nValues; i++) {
	x = arr[i];
	if (x < 0.0) {
	    /* What do you do about negative values when using log
................................................................................
	Blt_EventuallyRedrawGraph(graphPtr);
    }
}

static int
EvalExprList(interp, list, nElemPtr, arrayPtr)
    Tcl_Interp *interp;
    char *list;
    int *nElemPtr;
    double **arrayPtr;
{
    int nElem;
    char **elemArr;
    double *array;
    int result;

    result = TCL_ERROR;
    elemArr = NULL;
    if (Tcl_SplitList(interp, list, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }
    array = NULL;
    if (nElem > 0) {
	register double *valuePtr;
	register int i;

	counter++;
	array = Blt_Malloc(sizeof(double) * nElem);
	if (array == NULL) {
	    Tcl_AppendResult(interp, "can't allocate new vector", (char *)NULL);
	    goto badList;
	}
................................................................................
 */
/*ARGSUSED*/
static int
StringToData(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Type of axis vector to fill */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Tcl list of expressions */
    char *widgRec;		/* Element record */
    int offset;			/* Offset of vector in Element record */
{
    Element *elemPtr = (Element *)(widgRec);
    ElemVector *vPtr = (ElemVector *)(widgRec + offset);



    FreeDataVector(vPtr);

    if (Blt_VectorExists2(interp, string)) {


	Blt_VectorId clientId;

	clientId = Blt_AllocVectorId(interp, string);
	if (Blt_GetVectorById(interp, clientId, &vPtr->vecPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	Blt_SetVectorChangedProc(clientId, VectorChangedProc, vPtr);
................................................................................
 */
/*ARGSUSED*/
static int
StringToDataPairs(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Tcl list of numeric expressions */
    char *widgRec;		/* Element record */
    int offset;			/* Not used. */
{
    Element *elemPtr = (Element *)widgRec;
    int nElem;
    unsigned int newSize;
    double *newArr;
................................................................................

    elemPtr->x.valueArr = Blt_Malloc(newSize);
    elemPtr->y.valueArr = Blt_Malloc(newSize);
    assert(elemPtr->x.valueArr && elemPtr->y.valueArr);
    elemPtr->x.nValues = elemPtr->y.nValues = nElem;

    if (newSize > 0) {
	register double *dataPtr;
	register int i;

	for (dataPtr = newArr, i = 0; i < nElem; i++) {
	    elemPtr->x.valueArr[i] = *dataPtr++;
	    elemPtr->y.valueArr[i] = *dataPtr++;
	}
	Blt_Free(newArr);
	FindRange(&elemPtr->x);
................................................................................
 */
/*ARGSUSED*/
static int
StringToAlong(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representation of value. */
    char *widgRec;		/* Widget record. */
    int offset;			/* Offset of field in widget record. */
{
    int *intPtr = (int *)(widgRec + offset);

    if ((string[0] == 'x') && (string[1] == '\0')) {
	*intPtr = SEARCH_X;
................................................................................
{
    Blt_ChainLink *linkPtr;

    /* Skip the first slot. It contains the built-in "normal" pen of
     * the element.  */
    linkPtr = Blt_ChainFirstLink(palette);
    if (linkPtr != NULL) {
	register PenStyle *stylePtr;
	Blt_ChainLink *nextPtr;

	for (linkPtr = Blt_ChainNextLink(linkPtr); linkPtr != NULL; 
	     linkPtr = nextPtr) {
	    nextPtr =  Blt_ChainNextLink(linkPtr);
	    stylePtr = Blt_ChainGetValue(linkPtr);
	    Blt_FreePen(graphPtr, stylePtr->penPtr);
................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToStyles(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing style list */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of symbol type field in record */
{
    Blt_Chain *palette = *(Blt_Chain **)(widgRec + offset);
    Blt_ChainLink *linkPtr;
    Element *elemPtr = (Element *)(widgRec);
    PenStyle *stylePtr;
    char **elemArr;
    int nStyles;
    register int i;
    size_t size = (size_t)clientData;

    elemArr = NULL;
    Blt_FreePalette(elemPtr->graphPtr, palette);
    if ((string == NULL) || (*string == '\0')) {
	nStyles = 0;
    } else if (Tcl_SplitList(interp, string, &nStyles, &elemArr) != TCL_OK) {
................................................................................
	    Tcl_DStringAppendElement(&dString, string);
	    Tcl_PrintDouble(interp, stylePtr->weight.max, string);
	    Tcl_DStringAppendElement(&dString, string);
	    Tcl_DStringEndSublist(&dString);
	}
    }
    result = Blt_Strdup(Tcl_DStringValue(&dString));

    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
................................................................................
 *----------------------------------------------------------------------
 */

PenStyle **
Blt_StyleMap(elemPtr)
    Element *elemPtr;
{
    register int i;
    int nWeights;		/* Number of weights to be examined.
				 * If there are more data points than
				 * weights, they will default to the
				 * normal pen. */

    PenStyle **dataToStyle;	/* Directory of styles.  Each array
				 * element represents the style for
................................................................................
    if (n > 0) {
	Segment2D *errorBars;
	Segment2D *segPtr;
	double high, low;
	double x, y;
	int *errorToData;
	int *indexPtr;
	register int i;
		
	segPtr = errorBars = Blt_Malloc(n * 3 * sizeof(Segment2D));
	indexPtr = errorToData = Blt_Malloc(n * 3 * sizeof(int));
	for (i = 0; i < n; i++) {
	    x = elemPtr->x.valueArr[i];
	    y = elemPtr->y.valueArr[i];
	    stylePtr = dataToStyle[i];
................................................................................
    if (n > 0) {
	Segment2D *errorBars;
	Segment2D *segPtr;
	double high, low;
	double x, y;
	int *errorToData;
	int *indexPtr;
	register int i;
		
	segPtr = errorBars = Blt_Malloc(n * 3 * sizeof(Segment2D));
	indexPtr = errorToData = Blt_Malloc(n * 3 * sizeof(int));
	for (i = 0; i < n; i++) {
	    x = elemPtr->x.valueArr[i];
	    y = elemPtr->y.valueArr[i];
	    stylePtr = dataToStyle[i];
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateElement(graphPtr, interp, argc, argv, classUid)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
    Blt_Uid classUid;
{
    Element *elemPtr;
    Blt_HashEntry *hPtr;
    int isNew;

    if (argv[3][0] == '-') {
................................................................................
 */
static int
RebuildDisplayList(graphPtr, newList)
    Graph *graphPtr;		/* Graph widget record */
    char *newList;		/* Tcl list of element names */
{
    int nNames;			/* Number of names found in Tcl name list */
    char **nameArr;		/* Broken out array of element names */
    register int i;
    Element *elemPtr;		/* Element information record */

    if (Tcl_SplitList(graphPtr->interp, newList, &nNames, &nameArr) != TCL_OK) {
	Tcl_AppendResult(graphPtr->interp, "can't split name list \"", newList,
	    "\"", (char *)NULL);
	return TCL_ERROR;
    }
................................................................................
ActivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;			/* Number of element names */
    char **argv;		/* List of element names */
{
    Element *elemPtr;
    register int i;
    int *activeArr;
    int nActiveIndices;

    if (argc == 3) {
	register Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;

	/* List all the currently active elements */
	for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.table, &cursor);
	    hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	    elemPtr = (Element *)Blt_GetHashValue(hPtr);
	    if (elemPtr->flags & ELEM_ACTIVE) {
................................................................................
	return TCL_ERROR;	/* Can't find named element */
    }
    elemPtr->flags |= ELEM_ACTIVE | ACTIVE_PENDING;

    activeArr = NULL;
    nActiveIndices = -1;
    if (argc > 4) {
	register int *activePtr;

	nActiveIndices = argc - 4;
	activePtr = activeArr = Blt_Malloc(sizeof(int) * nActiveIndices);
	assert(activeArr);
	for (i = 4; i < argc; i++) {
	    if (GetIndex(interp, elemPtr, argv[i], activePtr) != TCL_OK) {
		return TCL_ERROR;
................................................................................
    Blt_EventuallyRedrawGraph(graphPtr);
    return TCL_OK;
}

ClientData
Blt_MakeElementTag(graphPtr, tagName)
    Graph *graphPtr;
    char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->elements.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->elements.tagTable, hPtr);
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;

	for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.tagTable, &cursor);
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateOp(graphPtr, interp, argc, argv, type)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
    Blt_Uid type;
{
    return CreateElement(graphPtr, interp, argc, argv, type);
}

/*
 *----------------------------------------------------------------------
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char *argv[];
{
    Element *elemPtr;

    if (NameToElement(graphPtr, argv[3], &elemPtr) != TCL_OK) {
	return TCL_ERROR;	/* Can't find named element */
    }
    if (Tk_ConfigureValue(interp, graphPtr->tkwin, elemPtr->specsPtr,
................................................................................
};

static int
ClosestOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of element names */
    char **argv;		/* List of element names */
{
    Element *elemPtr;
    ClosestSearch search;
    int i, x, y;
    int flags = TCL_LEAVE_ERR_MSG;
    int found;

................................................................................
 *---------------------------------------------------------------------- 
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char *argv[];
{
    Element *elemPtr;
    int flags;
    int numNames, numOpts;
    char **options;
    register int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 */
/*ARGSUSED*/
static int
DeactivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Not used. */
    int argc;			/* Number of element names */
    char **argv;		/* List of element names */
{
    Element *elemPtr;
    register int i;

    for (i = 3; i < argc; i++) {
	if (NameToElement(graphPtr, argv[i], &elemPtr) != TCL_OK) {
	    return TCL_ERROR;	/* Can't find named element */
	}
	elemPtr->flags &= ~ELEM_ACTIVE;
	if (elemPtr->activeIndices != NULL) {
................................................................................
 */
/*ARGSUSED*/
static int
DeleteOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Not used. */
    int argc;			/* Number of element names */
    char **argv;		/* List of element names */
{
    Element *elemPtr;
    register int i;

    for (i = 3; i < argc; i++) {
	if (NameToElement(graphPtr, argv[i], &elemPtr) != TCL_OK) {
	    return TCL_ERROR;	/* Can't find named element */
	}
	DestroyElement(graphPtr, elemPtr);
    }
................................................................................
 */
/* ARGSUSED */
static int
ExistsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    Blt_HashEntry *hPtr;

    hPtr = Blt_FindHashEntry(&graphPtr->elements.table, argv[3]);
    Blt_SetBooleanResult(interp, (hPtr != NULL));
    return TCL_OK;
}
................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char *argv[];
{
    register Element *elemPtr;

    if ((argv[3][0] == 'c') && (strcmp(argv[3], "current") == 0)) {
	elemPtr = (Element *)Blt_GetCurrentItem(graphPtr->bindTable);
	/* Report only on elements. */
	if ((elemPtr != NULL) && 
	    ((elemPtr->classUid == bltBarElementUid) ||
	    (elemPtr->classUid == bltLineElementUid) ||
................................................................................
 *----------------------------------------------------------------------
 */
static int
NamesOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Element *elemPtr;
    Blt_HashSearch cursor;
    register Blt_HashEntry *hPtr;
    register int i;

    for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	elemPtr = (Element *)Blt_GetHashValue(hPtr);
	if (argc == 3) {
	    Tcl_AppendElement(graphPtr->interp, elemPtr->name);
	    continue;
................................................................................
 *----------------------------------------------------------------------
 */
static int
ShowOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Element *elemPtr;
    Blt_ChainLink *linkPtr;

    if (argc == 4) {
	if (RebuildDisplayList(graphPtr, argv[3]) != TCL_OK) {
	    return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;		/* Element name */
{
    Element *elemPtr;

    if (NameToElement(graphPtr, argv[3], &elemPtr) != TCL_OK) {
	return TCL_ERROR;	/* Can't find named element */
    }
    Tcl_SetResult(interp, elemPtr->classUid, TCL_STATIC);
................................................................................
 * ----------------------------------------------------------------
 */
int
Blt_ElementOp(graphPtr, interp, argc, argv, type)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* # arguments */
    char **argv;		/* Argument list */
    Blt_Uid type;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, numElemOps, elemOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {







|
|
|
<
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
|

>


>
>
|

>


>
>
|

>







 







|





|







 







|
|
|







 







|
|
|







 







|




|










|
|







 







|





>
>


>
|
>
>







 







|







 







|
|







 







|







 







|







 







|







|

|







 







>







 







|







 







|







 







|







 







|







 







|
|







 







|




|







 







|







 







|







 







|







 







|







 







|







 







|







 







|




|
|







 







|


|







 







|


|







 







|







 







|

|







 







|



|
|







 







|







 







|







 







|







26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
...
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
...
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
...
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
...
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
....
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
....
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
....
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
....
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
....
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
....
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
....
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
....
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
....
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
....
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
....
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
....
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
....
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
....
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
....
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
....
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
....
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
....
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
 */

#include "bltGraph.h"
#include "bltChain.h"
#include <X11/Xutil.h>


static int StringToData _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *DataToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToDataPairs _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *DataPairsToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToAlong _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *AlongToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption alongOption =
{
    (Tk_OptionParseProc *)StringToAlong,
    (Tk_OptionPrintProc *)AlongToString,
    (ClientData)0
};

Tk_CustomOption bltDataOption =
{
    (Tk_OptionParseProc *)StringToData,
    (Tk_OptionPrintProc *)DataToString,
    (ClientData)0
};

Tk_CustomOption bltDataPairsOption =
{
    (Tk_OptionParseProc *)StringToDataPairs,
    (Tk_OptionPrintProc *)DataPairsToString,
    (ClientData)0
};

extern Tk_CustomOption bltDistanceOption;

 
static int counter;

#include "bltGrElem.h"

................................................................................
 * ----------------------------------------------------------------------
 * Custom option parse and print procedures
 * ----------------------------------------------------------------------
 */
static int
GetPenStyle(graphPtr, string, type, stylePtr)
    Graph *graphPtr;
    CONST char *string;
    Blt_Uid type;
    PenStyle *stylePtr;
{
    Pen *penPtr;
    Tcl_Interp *interp = graphPtr->interp;
    CONST char **elemArr;
    int nElem;

    elemArr = NULL;
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((nElem != 1) && (nElem != 3)) {
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
FindRange(vPtr)
    ElemVector *vPtr;
{
    int i;
    double *x;
    double min, max;

    if ((vPtr->nValues < 1) || (vPtr->valueArr == NULL)) {
	return;			/* This shouldn't ever happen. */
    }
    x = vPtr->valueArr;

    min = DBL_MAX, max = -DBL_MAX;
................................................................................
 *----------------------------------------------------------------------
 */
double
Blt_FindElemVectorMinimum(vPtr, minLimit)
    ElemVector *vPtr;
    double minLimit;
{
    int i;
    double *arr;
    double min, x;

    min = DBL_MAX;
    arr = vPtr->valueArr;
    for (i = 0; i < vPtr->nValues; i++) {
	x = arr[i];
	if (x < 0.0) {
	    /* What do you do about negative values when using log
................................................................................
	Blt_EventuallyRedrawGraph(graphPtr);
    }
}

static int
EvalExprList(interp, list, nElemPtr, arrayPtr)
    Tcl_Interp *interp;
    CONST char *list;
    int *nElemPtr;
    double **arrayPtr;
{
    int nElem;
    CONST char **elemArr;
    double *array;
    int result;

    result = TCL_ERROR;
    elemArr = NULL;
    if (Tcl_SplitList(interp, list, &nElem, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }
    array = NULL;
    if (nElem > 0) {
	double *valuePtr;
	int i;

	counter++;
	array = Blt_Malloc(sizeof(double) * nElem);
	if (array == NULL) {
	    Tcl_AppendResult(interp, "can't allocate new vector", (char *)NULL);
	    goto badList;
	}
................................................................................
 */
/*ARGSUSED*/
static int
StringToData(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Type of axis vector to fill */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Tcl list of expressions */
    char *widgRec;		/* Element record */
    int offset;			/* Offset of vector in Element record */
{
    Element *elemPtr = (Element *)(widgRec);
    ElemVector *vPtr = (ElemVector *)(widgRec + offset);
    char *nameCopy;
    int result;

    FreeDataVector(vPtr);
    nameCopy = Blt_Strdup(string);
    result = Blt_VectorExists2(interp, nameCopy);
    Blt_Free(nameCopy);
    if (result) {
	Blt_VectorId clientId;

	clientId = Blt_AllocVectorId(interp, string);
	if (Blt_GetVectorById(interp, clientId, &vPtr->vecPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	Blt_SetVectorChangedProc(clientId, VectorChangedProc, vPtr);
................................................................................
 */
/*ARGSUSED*/
static int
StringToDataPairs(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Tcl list of numeric expressions */
    char *widgRec;		/* Element record */
    int offset;			/* Not used. */
{
    Element *elemPtr = (Element *)widgRec;
    int nElem;
    unsigned int newSize;
    double *newArr;
................................................................................

    elemPtr->x.valueArr = Blt_Malloc(newSize);
    elemPtr->y.valueArr = Blt_Malloc(newSize);
    assert(elemPtr->x.valueArr && elemPtr->y.valueArr);
    elemPtr->x.nValues = elemPtr->y.nValues = nElem;

    if (newSize > 0) {
	double *dataPtr;
	int i;

	for (dataPtr = newArr, i = 0; i < nElem; i++) {
	    elemPtr->x.valueArr[i] = *dataPtr++;
	    elemPtr->y.valueArr[i] = *dataPtr++;
	}
	Blt_Free(newArr);
	FindRange(&elemPtr->x);
................................................................................
 */
/*ARGSUSED*/
static int
StringToAlong(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representation of value. */
    char *widgRec;		/* Widget record. */
    int offset;			/* Offset of field in widget record. */
{
    int *intPtr = (int *)(widgRec + offset);

    if ((string[0] == 'x') && (string[1] == '\0')) {
	*intPtr = SEARCH_X;
................................................................................
{
    Blt_ChainLink *linkPtr;

    /* Skip the first slot. It contains the built-in "normal" pen of
     * the element.  */
    linkPtr = Blt_ChainFirstLink(palette);
    if (linkPtr != NULL) {
	PenStyle *stylePtr;
	Blt_ChainLink *nextPtr;

	for (linkPtr = Blt_ChainNextLink(linkPtr); linkPtr != NULL; 
	     linkPtr = nextPtr) {
	    nextPtr =  Blt_ChainNextLink(linkPtr);
	    stylePtr = Blt_ChainGetValue(linkPtr);
	    Blt_FreePen(graphPtr, stylePtr->penPtr);
................................................................................
 */
/*ARGSUSED*/
int
Blt_StringToStyles(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing style list */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of symbol type field in record */
{
    Blt_Chain *palette = *(Blt_Chain **)(widgRec + offset);
    Blt_ChainLink *linkPtr;
    Element *elemPtr = (Element *)(widgRec);
    PenStyle *stylePtr;
    CONST char **elemArr;
    int nStyles;
    int i;
    size_t size = (size_t)clientData;

    elemArr = NULL;
    Blt_FreePalette(elemPtr->graphPtr, palette);
    if ((string == NULL) || (*string == '\0')) {
	nStyles = 0;
    } else if (Tcl_SplitList(interp, string, &nStyles, &elemArr) != TCL_OK) {
................................................................................
	    Tcl_DStringAppendElement(&dString, string);
	    Tcl_PrintDouble(interp, stylePtr->weight.max, string);
	    Tcl_DStringAppendElement(&dString, string);
	    Tcl_DStringEndSublist(&dString);
	}
    }
    result = Blt_Strdup(Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);
    *freeProcPtr = (Tcl_FreeProc *)Blt_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
................................................................................
 *----------------------------------------------------------------------
 */

PenStyle **
Blt_StyleMap(elemPtr)
    Element *elemPtr;
{
    int i;
    int nWeights;		/* Number of weights to be examined.
				 * If there are more data points than
				 * weights, they will default to the
				 * normal pen. */

    PenStyle **dataToStyle;	/* Directory of styles.  Each array
				 * element represents the style for
................................................................................
    if (n > 0) {
	Segment2D *errorBars;
	Segment2D *segPtr;
	double high, low;
	double x, y;
	int *errorToData;
	int *indexPtr;
	int i;
		
	segPtr = errorBars = Blt_Malloc(n * 3 * sizeof(Segment2D));
	indexPtr = errorToData = Blt_Malloc(n * 3 * sizeof(int));
	for (i = 0; i < n; i++) {
	    x = elemPtr->x.valueArr[i];
	    y = elemPtr->y.valueArr[i];
	    stylePtr = dataToStyle[i];
................................................................................
    if (n > 0) {
	Segment2D *errorBars;
	Segment2D *segPtr;
	double high, low;
	double x, y;
	int *errorToData;
	int *indexPtr;
	int i;
		
	segPtr = errorBars = Blt_Malloc(n * 3 * sizeof(Segment2D));
	indexPtr = errorToData = Blt_Malloc(n * 3 * sizeof(int));
	for (i = 0; i < n; i++) {
	    x = elemPtr->x.valueArr[i];
	    y = elemPtr->y.valueArr[i];
	    stylePtr = dataToStyle[i];
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateElement(graphPtr, interp, argc, argv, classUid)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
    Blt_Uid classUid;
{
    Element *elemPtr;
    Blt_HashEntry *hPtr;
    int isNew;

    if (argv[3][0] == '-') {
................................................................................
 */
static int
RebuildDisplayList(graphPtr, newList)
    Graph *graphPtr;		/* Graph widget record */
    char *newList;		/* Tcl list of element names */
{
    int nNames;			/* Number of names found in Tcl name list */
    CONST char **nameArr;	/* Broken out array of element names */
    int i;
    Element *elemPtr;		/* Element information record */

    if (Tcl_SplitList(graphPtr->interp, newList, &nNames, &nameArr) != TCL_OK) {
	Tcl_AppendResult(graphPtr->interp, "can't split name list \"", newList,
	    "\"", (char *)NULL);
	return TCL_ERROR;
    }
................................................................................
ActivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Interpreter to report errors to */
    int argc;			/* Number of element names */
    char **argv;		/* List of element names */
{
    Element *elemPtr;
    int i;
    int *activeArr;
    int nActiveIndices;

    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;

	/* List all the currently active elements */
	for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.table, &cursor);
	    hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	    elemPtr = (Element *)Blt_GetHashValue(hPtr);
	    if (elemPtr->flags & ELEM_ACTIVE) {
................................................................................
	return TCL_ERROR;	/* Can't find named element */
    }
    elemPtr->flags |= ELEM_ACTIVE | ACTIVE_PENDING;

    activeArr = NULL;
    nActiveIndices = -1;
    if (argc > 4) {
	int *activePtr;

	nActiveIndices = argc - 4;
	activePtr = activeArr = Blt_Malloc(sizeof(int) * nActiveIndices);
	assert(activeArr);
	for (i = 4; i < argc; i++) {
	    if (GetIndex(interp, elemPtr, argv[i], activePtr) != TCL_OK) {
		return TCL_ERROR;
................................................................................
    Blt_EventuallyRedrawGraph(graphPtr);
    return TCL_OK;
}

ClientData
Blt_MakeElementTag(graphPtr, tagName)
    Graph *graphPtr;
    CONST char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->elements.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->elements.tagTable, hPtr);
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;

	for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.tagTable, &cursor);
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateOp(graphPtr, interp, argc, argv, type)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
    Blt_Uid type;
{
    return CreateElement(graphPtr, interp, argc, argv, type);
}

/*
 *----------------------------------------------------------------------
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char *argv[];
{
    Element *elemPtr;

    if (NameToElement(graphPtr, argv[3], &elemPtr) != TCL_OK) {
	return TCL_ERROR;	/* Can't find named element */
    }
    if (Tk_ConfigureValue(interp, graphPtr->tkwin, elemPtr->specsPtr,
................................................................................
};

static int
ClosestOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Interpreter to report results to */
    int argc;			/* Number of element names */
    CONST char **argv;		/* List of element names */
{
    Element *elemPtr;
    ClosestSearch search;
    int i, x, y;
    int flags = TCL_LEAVE_ERR_MSG;
    int found;

................................................................................
 *---------------------------------------------------------------------- 
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char *argv[];
{
    Element *elemPtr;
    int flags;
    int numNames, numOpts;
    CONST char **options;
    int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 */
/*ARGSUSED*/
static int
DeactivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Not used. */
    int argc;			/* Number of element names */
    CONST char **argv;		/* List of element names */
{
    Element *elemPtr;
    int i;

    for (i = 3; i < argc; i++) {
	if (NameToElement(graphPtr, argv[i], &elemPtr) != TCL_OK) {
	    return TCL_ERROR;	/* Can't find named element */
	}
	elemPtr->flags &= ~ELEM_ACTIVE;
	if (elemPtr->activeIndices != NULL) {
................................................................................
 */
/*ARGSUSED*/
static int
DeleteOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;		/* Not used. */
    int argc;			/* Number of element names */
    CONST char **argv;		/* List of element names */
{
    Element *elemPtr;
    int i;

    for (i = 3; i < argc; i++) {
	if (NameToElement(graphPtr, argv[i], &elemPtr) != TCL_OK) {
	    return TCL_ERROR;	/* Can't find named element */
	}
	DestroyElement(graphPtr, elemPtr);
    }
................................................................................
 */
/* ARGSUSED */
static int
ExistsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    Blt_HashEntry *hPtr;

    hPtr = Blt_FindHashEntry(&graphPtr->elements.table, argv[3]);
    Blt_SetBooleanResult(interp, (hPtr != NULL));
    return TCL_OK;
}
................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char *argv[];
{
    Element *elemPtr;

    if ((argv[3][0] == 'c') && (strcmp(argv[3], "current") == 0)) {
	elemPtr = (Element *)Blt_GetCurrentItem(graphPtr->bindTable);
	/* Report only on elements. */
	if ((elemPtr != NULL) && 
	    ((elemPtr->classUid == bltBarElementUid) ||
	    (elemPtr->classUid == bltLineElementUid) ||
................................................................................
 *----------------------------------------------------------------------
 */
static int
NamesOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Element *elemPtr;
    Blt_HashSearch cursor;
    Blt_HashEntry *hPtr;
    int i;

    for (hPtr = Blt_FirstHashEntry(&graphPtr->elements.table, &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	elemPtr = (Element *)Blt_GetHashValue(hPtr);
	if (argc == 3) {
	    Tcl_AppendElement(graphPtr->interp, elemPtr->name);
	    continue;
................................................................................
 *----------------------------------------------------------------------
 */
static int
ShowOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Element *elemPtr;
    Blt_ChainLink *linkPtr;

    if (argc == 4) {
	if (RebuildDisplayList(graphPtr, argv[3]) != TCL_OK) {
	    return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;		/* Element name */
{
    Element *elemPtr;

    if (NameToElement(graphPtr, argv[3], &elemPtr) != TCL_OK) {
	return TCL_ERROR;	/* Can't find named element */
    }
    Tcl_SetResult(interp, elemPtr->classUid, TCL_STATIC);
................................................................................
 * ----------------------------------------------------------------
 */
int
Blt_ElementOp(graphPtr, interp, argc, argv, type)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* # arguments */
    CONST char **argv;		/* Argument list */
    Blt_Uid type;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, numElemOps, elemOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {

Changes to jni/blt/src/bltGrElem.h.

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    int state;
};


extern double Blt_FindElemVectorMinimum _ANSI_ARGS_((ElemVector *vecPtr,
	double minLimit));
extern void Blt_ResizeStatusArray _ANSI_ARGS_((Element *elemPtr, int nPoints));
extern int Blt_GetPenStyle _ANSI_ARGS_((Graph *graphPtr, char *name,
	Blt_Uid classUid, PenStyle *stylePtr));
extern void Blt_FreePalette _ANSI_ARGS_((Graph *graphPtr, Blt_Chain *palette));
extern PenStyle **Blt_StyleMap _ANSI_ARGS_((Element *elemPtr));
extern void Blt_MapErrorBars _ANSI_ARGS_((Graph *graphPtr, Element *elemPtr, 
	       PenStyle **dataToStyle));

#endif /* _BLT_GR_ELEM_H */







<
<






281
282
283
284
285
286
287


288
289
290
291
292
293
    int state;
};


extern double Blt_FindElemVectorMinimum _ANSI_ARGS_((ElemVector *vecPtr,
	double minLimit));
extern void Blt_ResizeStatusArray _ANSI_ARGS_((Element *elemPtr, int nPoints));


extern void Blt_FreePalette _ANSI_ARGS_((Graph *graphPtr, Blt_Chain *palette));
extern PenStyle **Blt_StyleMap _ANSI_ARGS_((Element *elemPtr));
extern void Blt_MapErrorBars _ANSI_ARGS_((Graph *graphPtr, Element *elemPtr, 
	       PenStyle **dataToStyle));

#endif /* _BLT_GR_ELEM_H */

Changes to jni/blt/src/bltGrGrid.c.

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
...
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522

    gridPtr = Blt_Calloc(1, sizeof(Grid));
    assert(gridPtr);
    gridPtr->minorGrid = TRUE;
    graphPtr->gridPtr = gridPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin, "grid",
	    "Grid", configSpecs, 0, (char **)NULL, (char *)gridPtr,
	    Blt_GraphType(graphPtr)) != TCL_OK) {
	return TCL_ERROR;
    }
    ConfigureGrid(graphPtr, gridPtr);
    return TCL_OK;
}

................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	(char *)gridPtr, argv[3], Blt_GraphType(graphPtr));
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;
    int flags;

    flags = Blt_GraphType(graphPtr) | TK_CONFIG_ARGV_ONLY;
    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)gridPtr, (char *)NULL, flags);
    } else if (argc == 4) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)gridPtr, argv[3], flags);
    }
    if (Blt_ConfigureWidget(graphPtr->interp, graphPtr->tkwin, configSpecs,
	    argc - 3, argv + 3, (char *)gridPtr, flags) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
MapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    if (gridPtr->hidden) {
	gridPtr->hidden = FALSE;/* Changes "-hide" configuration option */
	graphPtr->flags |= REDRAW_BACKING_STORE;
	Blt_EventuallyRedrawGraph(graphPtr);
................................................................................
 */
/*ARGSUSED*/
static int
UnmapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    if (!gridPtr->hidden) {
	gridPtr->hidden = TRUE;	/* Changes "-hide" configuration option */
	graphPtr->flags |= REDRAW_BACKING_STORE;
	Blt_EventuallyRedrawGraph(graphPtr);
................................................................................
 */
/*ARGSUSED*/
static int
ToggleOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    gridPtr->hidden = (!gridPtr->hidden);
    graphPtr->flags |= REDRAW_BACKING_STORE;
    Blt_EventuallyRedrawGraph(graphPtr);
    return TCL_OK;
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_GridOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nGridOps, gridOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (graphPtr, interp, argc, argv);
}







|







 







|







 







|







|







 







|







 







|







 







|







 







|









296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
...
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522

    gridPtr = Blt_Calloc(1, sizeof(Grid));
    assert(gridPtr);
    gridPtr->minorGrid = TRUE;
    graphPtr->gridPtr = gridPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin, "grid",
	    "Grid", configSpecs, 0, NULL, (char *)gridPtr,
	    Blt_GraphType(graphPtr)) != TCL_OK) {
	return TCL_ERROR;
    }
    ConfigureGrid(graphPtr, gridPtr);
    return TCL_OK;
}

................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	(char *)gridPtr, argv[3], Blt_GraphType(graphPtr));
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;
    int flags;

    flags = Blt_GraphType(graphPtr) | TK_CONFIG_ARGV_ONLY;
    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)gridPtr, NULL, flags);
    } else if (argc == 4) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)gridPtr, argv[3], flags);
    }
    if (Blt_ConfigureWidget(graphPtr->interp, graphPtr->tkwin, configSpecs,
	    argc - 3, argv + 3, (char *)gridPtr, flags) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
MapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    if (gridPtr->hidden) {
	gridPtr->hidden = FALSE;/* Changes "-hide" configuration option */
	graphPtr->flags |= REDRAW_BACKING_STORE;
	Blt_EventuallyRedrawGraph(graphPtr);
................................................................................
 */
/*ARGSUSED*/
static int
UnmapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    if (!gridPtr->hidden) {
	gridPtr->hidden = TRUE;	/* Changes "-hide" configuration option */
	graphPtr->flags |= REDRAW_BACKING_STORE;
	Blt_EventuallyRedrawGraph(graphPtr);
................................................................................
 */
/*ARGSUSED*/
static int
ToggleOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Grid *gridPtr = (Grid *)graphPtr->gridPtr;

    gridPtr->hidden = (!gridPtr->hidden);
    graphPtr->flags |= REDRAW_BACKING_STORE;
    Blt_EventuallyRedrawGraph(graphPtr);
    return TCL_OK;
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_GridOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nGridOps, gridOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (graphPtr, interp, argc, argv);
}

Changes to jni/blt/src/bltGrHairs.c.

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
    chPtr = Blt_Calloc(1, sizeof(Crosshairs));
    assert(chPtr);
    chPtr->hidden = TRUE;
    chPtr->hotSpot.x = chPtr->hotSpot.y = -1;
    graphPtr->crosshairs = chPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "crosshairs", "Crosshairs", configSpecs, 0, (char **)NULL,
	    (char *)chPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	    (char *)chPtr, argv[3], 0);
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
		(char *)chPtr, (char *)NULL, 0);
    } else if (argc == 4) {
................................................................................
 */
/*ARGSUSED*/
static int
OnOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (chPtr->hidden) {
	TurnOnHairs(graphPtr, chPtr);
	chPtr->hidden = FALSE;
    }
................................................................................
 */
/*ARGSUSED*/
static int
OffOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (!chPtr->hidden) {
	TurnOffHairs(graphPtr->tkwin, chPtr);
	chPtr->hidden = TRUE;
    }
................................................................................
 */
/*ARGSUSED*/
static int
ToggleOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    chPtr->hidden = (chPtr->hidden == 0);
    if (chPtr->hidden) {
	TurnOffHairs(graphPtr->tkwin, chPtr);
    } else {
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_CrosshairsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nXhairOps, xhairOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (graphPtr, interp, argc, argv);
}







|







 







|







 







|







 







|







 







|







 







|







 







|









329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
    chPtr = Blt_Calloc(1, sizeof(Crosshairs));
    assert(chPtr);
    chPtr->hidden = TRUE;
    chPtr->hotSpot.x = chPtr->hotSpot.y = -1;
    graphPtr->crosshairs = chPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "crosshairs", "Crosshairs", configSpecs, 0, NULL,
	    (char *)chPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	    (char *)chPtr, argv[3], 0);
}

................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
		(char *)chPtr, (char *)NULL, 0);
    } else if (argc == 4) {
................................................................................
 */
/*ARGSUSED*/
static int
OnOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (chPtr->hidden) {
	TurnOnHairs(graphPtr, chPtr);
	chPtr->hidden = FALSE;
    }
................................................................................
 */
/*ARGSUSED*/
static int
OffOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    if (!chPtr->hidden) {
	TurnOffHairs(graphPtr->tkwin, chPtr);
	chPtr->hidden = TRUE;
    }
................................................................................
 */
/*ARGSUSED*/
static int
ToggleOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Crosshairs *chPtr = graphPtr->crosshairs;

    chPtr->hidden = (chPtr->hidden == 0);
    if (chPtr->hidden) {
	TurnOffHairs(graphPtr->tkwin, chPtr);
    } else {
................................................................................
 *----------------------------------------------------------------------
 */
int
Blt_CrosshairsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nXhairOps, xhairOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (graphPtr, interp, argc, argv);
}

Changes to jni/blt/src/bltGrLegd.c.

120
121
122
123
124
125
126
127
128





129
130


131
132

133
134
135
136
137
138
139
...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
...
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
...
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
....
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
....
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
....
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
....
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
....
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
....
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
....
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
#define DEF_LEGEND_RAISED       	"no"
#define DEF_LEGEND_RELIEF		"sunken"
#define DEF_LEGEND_SHADOW_COLOR		(char *)NULL
#define DEF_LEGEND_SHADOW_MONO		(char *)NULL
#define DEF_LEGEND_ROWS			"0"
#define DEF_LEGEND_COLUMNS		"0"

static Tk_OptionParseProc StringToPosition;
static Tk_OptionPrintProc PositionToString;





static Tk_CustomOption legendPositionOption =
{


    StringToPosition, PositionToString, (ClientData)0
};

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltCountOption;

static Tk_ConfigSpec configSpecs[] =
{
................................................................................
 *	redisplayed.
 *
 *--------------------------------------------------------------
 */
static void
LegendEventProc(clientData, eventPtr)
    ClientData clientData;	/* Legend record */
    register XEvent *eventPtr;	/* Event which triggered call to routine */
{
    Legend *legendPtr = clientData;

    if (eventPtr->type == Expose) {
	if (eventPtr->xexpose.count == 0) {
	    EventuallyRedrawLegend(legendPtr);
	}
................................................................................
 */
/*ARGSUSED*/
static int
StringToPosition(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* New legend position string */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to XPoint structure */
{
    Legend *legendPtr = (Legend *)widgRec;
    char c;
    unsigned int length;

................................................................................
    Tk_FontMetrics fontMetrics;
    Tk_Window tkwin;
    int count;
    int labelX, startY, symbolX, symbolY;
    int symbolSize, midX, midY;
    int width, height;
    int x, y;
    register Element *elemPtr;

    graphPtr = legendPtr->graphPtr;
    graphPtr->flags &= ~DRAW_LEGEND;
    if ((legendPtr->hidden) || (legendPtr->nEntries == 0)) {
	return;
    }
    SetLegendOrigin(legendPtr);
................................................................................
    Blt_InitTextStyle(&(legendPtr->style));
    legendPtr->style.justify = TK_JUSTIFY_LEFT;
    legendPtr->style.anchor = TK_ANCHOR_NW;
    legendPtr->bindTable = Blt_CreateBindingTable(graphPtr->interp,
	graphPtr->tkwin, graphPtr, PickLegendEntry, Blt_GraphTags);

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "legend", "Legend", configSpecs, 0, (char **)NULL,
	    (char *)legendPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    ConfigureLegend(graphPtr, legendPtr);
    return TCL_OK;
}

................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char *argv[];
{
    register Element *elemPtr;
    Legend *legendPtr = graphPtr->legend;
    int x, y;
    char c;

    if ((legendPtr->hidden) || (legendPtr->nEntries == 0)) {
	return TCL_OK;
    }
................................................................................
 *----------------------------------------------------------------------
 */
static int
ActivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char *argv[];
{
    Legend *legendPtr = graphPtr->legend;
    Element *elemPtr;
    unsigned int active, redraw;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    register int i;

    active = (argv[2][0] == 'a') ? LABEL_ACTIVE : 0;
    redraw = 0;
    for (hPtr = Blt_FirstHashEntry(&(graphPtr->elements.table), &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	elemPtr = Blt_GetHashValue(hPtr);
	for (i = 3; i < argc; i++) {
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;

	for (hPtr = Blt_FirstHashEntry(&(graphPtr->elements.tagTable), &cursor);
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	    (char *)graphPtr->legend, argv[3], 0);
}

/*
 *----------------------------------------------------------------------
................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    int flags = TK_CONFIG_ARGV_ONLY;
    Legend *legendPtr;

    legendPtr = graphPtr->legend;
    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
................................................................................
static int nLegendOps = sizeof(legendOps) / sizeof(Blt_OpSpec);

int
Blt_LegendOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nLegendOps, legendOps, BLT_OP_ARG2, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;







|
|
>
>
>
>
>


>
>
|

>







 







|







 







|







 







|







 







|







 







|

|







 







|






|







 







|







 







|







 







|







 







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
...
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
....
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
....
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
....
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
....
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
....
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
....
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
#define DEF_LEGEND_RAISED       	"no"
#define DEF_LEGEND_RELIEF		"sunken"
#define DEF_LEGEND_SHADOW_COLOR		(char *)NULL
#define DEF_LEGEND_SHADOW_MONO		(char *)NULL
#define DEF_LEGEND_ROWS			"0"
#define DEF_LEGEND_COLUMNS		"0"

static int StringToPosition _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *PositionToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption legendPositionOption =
{
    (Tk_OptionParseProc *)StringToPosition,
    (Tk_OptionPrintProc *)PositionToString,
    (ClientData)0
};

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltCountOption;

static Tk_ConfigSpec configSpecs[] =
{
................................................................................
 *	redisplayed.
 *
 *--------------------------------------------------------------
 */
static void
LegendEventProc(clientData, eventPtr)
    ClientData clientData;	/* Legend record */
    XEvent *eventPtr;	/* Event which triggered call to routine */
{
    Legend *legendPtr = clientData;

    if (eventPtr->type == Expose) {
	if (eventPtr->xexpose.count == 0) {
	    EventuallyRedrawLegend(legendPtr);
	}
................................................................................
 */
/*ARGSUSED*/
static int
StringToPosition(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* New legend position string */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to XPoint structure */
{
    Legend *legendPtr = (Legend *)widgRec;
    char c;
    unsigned int length;

................................................................................
    Tk_FontMetrics fontMetrics;
    Tk_Window tkwin;
    int count;
    int labelX, startY, symbolX, symbolY;
    int symbolSize, midX, midY;
    int width, height;
    int x, y;
    Element *elemPtr;

    graphPtr = legendPtr->graphPtr;
    graphPtr->flags &= ~DRAW_LEGEND;
    if ((legendPtr->hidden) || (legendPtr->nEntries == 0)) {
	return;
    }
    SetLegendOrigin(legendPtr);
................................................................................
    Blt_InitTextStyle(&(legendPtr->style));
    legendPtr->style.justify = TK_JUSTIFY_LEFT;
    legendPtr->style.anchor = TK_ANCHOR_NW;
    legendPtr->bindTable = Blt_CreateBindingTable(graphPtr->interp,
	graphPtr->tkwin, graphPtr, PickLegendEntry, Blt_GraphTags);

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "legend", "Legend", configSpecs, 0, NULL,
	    (char *)legendPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    ConfigureLegend(graphPtr, legendPtr);
    return TCL_OK;
}

................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char *argv[];
{
    Element *elemPtr;
    Legend *legendPtr = graphPtr->legend;
    int x, y;
    char c;

    if ((legendPtr->hidden) || (legendPtr->nEntries == 0)) {
	return TCL_OK;
    }
................................................................................
 *----------------------------------------------------------------------
 */
static int
ActivateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char *argv[];
{
    Legend *legendPtr = graphPtr->legend;
    Element *elemPtr;
    unsigned int active, redraw;
    Blt_HashEntry *hPtr;
    Blt_HashSearch cursor;
    int i;

    active = (argv[2][0] == 'a') ? LABEL_ACTIVE : 0;
    redraw = 0;
    for (hPtr = Blt_FirstHashEntry(&(graphPtr->elements.table), &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	elemPtr = Blt_GetHashValue(hPtr);
	for (i = 3; i < argc; i++) {
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tagName;

	for (hPtr = Blt_FirstHashEntry(&(graphPtr->elements.tagTable), &cursor);
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	    (char *)graphPtr->legend, argv[3], 0);
}

/*
 *----------------------------------------------------------------------
................................................................................
 *----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    int flags = TK_CONFIG_ARGV_ONLY;
    Legend *legendPtr;

    legendPtr = graphPtr->legend;
    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
................................................................................
static int nLegendOps = sizeof(legendOps) / sizeof(Blt_OpSpec);

int
Blt_LegendOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nLegendOps, legendOps, BLT_OP_ARG2, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;

Changes to jni/blt/src/bltGrLegd.h.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

extern int Blt_CreateLegend _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DestroyLegend _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DrawLegend _ANSI_ARGS_((Legend *legendPtr, Drawable drawable));
extern void Blt_MapLegend _ANSI_ARGS_((Legend *legendPtr, int width,
	int height));
extern int Blt_LegendOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_LegendSite _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendWidth _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendHeight _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendIsHidden _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendIsRaised _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendX _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendY _ANSI_ARGS_((Legend *legendPtr));
extern void Blt_LegendRemoveElement _ANSI_ARGS_((Legend *legendPtr, 
	Element *elemPtr));
#endif /* BLT_GR_LEGEND_H */







|










39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

extern int Blt_CreateLegend _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DestroyLegend _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DrawLegend _ANSI_ARGS_((Legend *legendPtr, Drawable drawable));
extern void Blt_MapLegend _ANSI_ARGS_((Legend *legendPtr, int width,
	int height));
extern int Blt_LegendOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_LegendSite _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendWidth _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendHeight _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendIsHidden _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendIsRaised _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendX _ANSI_ARGS_((Legend *legendPtr));
extern int Blt_LegendY _ANSI_ARGS_((Legend *legendPtr));
extern void Blt_LegendRemoveElement _ANSI_ARGS_((Legend *legendPtr, 
	Element *elemPtr));
#endif /* BLT_GR_LEGEND_H */

Changes to jni/blt/src/bltGrLine.c.

21
22
23
24
25
26
27

28
29
30
31
32
33
34
...
398
399
400
401
402
403
404
405
406
407
408

409
410
411

412
413
414
415
























416
417


418
419

420
421


422
423

424
425


426
427

428
429


430
431

432
433


434
435

436
437
438
439
440
441
442
...
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
...
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
....
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
....
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
....
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
....
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
....
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
....
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
....
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
....
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
....
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
....
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
....
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
....
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
....
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
....
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
....
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
....
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
....
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
....
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
....
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
....
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
....
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
....
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
....
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
....
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
....
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
....
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
....
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
....
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
....
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
....
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
....
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
....
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
....
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
....
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
....
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
....
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
....
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
....
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
....
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
....
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
....
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
....
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
....
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
 * fitness.  In no event shall Lucent Technologies be liable for any
 * special, indirect or consequential damages or any damages
 * whatsoever resulting from loss of use, data or profits, whether in
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */

#include "bltGraph.h"
#include "bltChain.h"
#include <X11/Xutil.h>

#include "bltGrElem.h"

#define COLOR_DEFAULT	(XColor *)1
................................................................................
				 * element trace. The segments are
				 * grouped by pen style. */
    int nStrips;		/* Number of line segments to be drawn. */
    int *stripToData;		/* Pen to visible line segment mapping. */

} Line;

static Tk_OptionParseProc StringToPattern;
static Tk_OptionPrintProc PatternToString;
static Tk_OptionParseProc StringToSmooth;
static Tk_OptionPrintProc SmoothToString;

extern Tk_OptionParseProc Blt_StringToStyles;
extern Tk_OptionPrintProc Blt_StylesToString;
static Tk_OptionParseProc StringToPenDir;

static Tk_OptionPrintProc PenDirToString;
static Tk_OptionParseProc StringToSymbol;
static Tk_OptionPrintProc SymbolToString;

























static Tk_CustomOption patternOption =
{


    StringToPattern, PatternToString, (ClientData)0
};

static Tk_CustomOption smoothOption =
{


    StringToSmooth, SmoothToString, (ClientData)0
};

static Tk_CustomOption stylesOption =
{


    Blt_StringToStyles, Blt_StylesToString, (ClientData)sizeof(LinePenStyle)
};

static Tk_CustomOption penDirOption =
{


    StringToPenDir, PenDirToString, (ClientData)0
};

static Tk_CustomOption symbolOption =
{


    StringToSymbol, SymbolToString, (ClientData)0
};

extern Tk_CustomOption bltColorOption;
extern Tk_CustomOption bltDashesOption;
extern Tk_CustomOption bltDataOption;
extern Tk_CustomOption bltDataPairsOption;
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltListOption;
extern Tk_CustomOption bltLinePenOption;
................................................................................
static DistanceProc DistanceToY;
static DistanceProc DistanceToX;
static DistanceProc DistanceToLine;
#ifndef NO_TILE
static Blt_TileChangedProc TileChangedProc;
#endif

#ifdef WIN32

static int tkpWinRopModes[] =
{
    R2_BLACK,			/* GXclear */
    R2_MASKPEN,			/* GXand */
    R2_MASKPENNOT,		/* GXandReverse */
    R2_COPYPEN,			/* GXcopy */
................................................................................
    R2_WHITE			/* GXset */
};

#endif

INLINE static int
Round(x)
    register double x;
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

/*
 * ----------------------------------------------------------------------
 * 	Custom configuration option (parse and print) routines
................................................................................
 */

static int
StringToBitmap(interp, tkwin, symbolPtr, string)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    Symbol *symbolPtr;
    char *string;
{
    Pixmap bitmap, mask;
    char **elemArr;
    int nElems;
    int result;

    if (Tcl_SplitList(interp, string, &nElems, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }

................................................................................

    if (stipple == None) {
	return "";
    } 
    if (stipple == PATTERN_SOLID) {
	return "solid";
    } 
    return Tk_NameOfBitmap(Tk_Display(tkwin), stipple);
}

/*ARGSUSED*/
static int
StringToPattern(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing field */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of field in record */
{
    Pixmap *stipplePtr = (Pixmap *)(widgRec + offset);
    Pixmap stipple;

    if ((string == NULL) || (string[0] == '\0')) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToSymbol(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing symbol type */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of symbol type field in record */
{
    Symbol *symbolPtr = (Symbol *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
static int
StringToSmooth(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing smooth type */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of smooth type field in record */
{
    Smoothing *valuePtr = (Smoothing *)(widgRec + offset);
    register SmoothingInfo *siPtr;

    for (siPtr = smoothingInfo; siPtr->name != NULL; siPtr++) {
	if (strcmp(string, siPtr->name) == 0) {
	    *valuePtr = siPtr->value;
	    return TCL_OK;
	}
    }
................................................................................
 */
/*ARGSUSED*/
static int
StringToPenDir(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing pen direction */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of pen direction field in record */
{
    int *penDirPtr = (int *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 * Clear the number of points and segments, in case there are no
 * segments or points
 */
static void
ClearPalette(palette)
    Blt_Chain *palette;
{
    register LinePenStyle *stylePtr;
    Blt_ChainLink *linkPtr;

    for (linkPtr = Blt_ChainFirstLink(palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->nStrips = stylePtr->nSymbolPts = 0;
	stylePtr->xErrorBarCnt = stylePtr->yErrorBarCnt = 0;
................................................................................
    penPtr->symbol.outlineWidth = penPtr->traceWidth = 1;
    penPtr->symbol.type = SYMBOL_CIRCLE;
    penPtr->valueShow = SHOW_NONE;
}

Pen *
Blt_LinePen(penName)
    char *penName;
{
    LinePen *penPtr;

    penPtr = Blt_Calloc(1, sizeof(LinePen));
    assert(penPtr);
    InitPen(penPtr);
    penPtr->name = Blt_Strdup(penName);
................................................................................
static void
GetScreenPoints(graphPtr, linePtr, mapPtr)
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    double *x, *y;
    register int i, n;
    register int count;
    register Point2D *screenPts;
    register int *indices;

    n = NumberOfPoints(linePtr);
    x = linePtr->x.valueArr;
    y = linePtr->y.valueArr;
    screenPts = Blt_Malloc(sizeof(Point2D) * n);
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * n);
................................................................................
 *----------------------------------------------------------------------
 */
static void
ReducePoints(mapPtr, tolerance)
    MapInfo *mapPtr;
    double tolerance;
{
    register int i, k, n;
    Point2D *screenPts;
    int *indices, *simple;

    simple	= Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    indices	= Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    screenPts	= Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
    n = Blt_SimplifyLine(mapPtr->screenPts, 0, mapPtr->nScreenPts - 1, 
................................................................................
 *---------------------------------------------------------------------- 
 */
static void
GenerateSteps(mapPtr)
    MapInfo *mapPtr;
{
    int newSize;
    register int i, count;
    Point2D *screenPts;
    int *indices;

    newSize = ((mapPtr->nScreenPts - 1) * 2) + 1;
    screenPts = Blt_Malloc(newSize * sizeof(Point2D));
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * newSize);
................................................................................
static void
GenerateSpline(graphPtr, linePtr, mapPtr)
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    int extra;
    register int i, j, count;
    Point2D *origPts, *intpPts;
    int *indices;
    int nIntpPts, nOrigPts;
    int result;
    int x;

    nOrigPts = mapPtr->nScreenPts;
................................................................................
    Extents2D exts;
    Point2D *origPts, *intpPts;
    Point2D p, q;
    double dist;
    int *indices;
    int nIntpPts, nOrigPts;
    int result;
    register int i, j, count;

    nOrigPts = mapPtr->nScreenPts;
    origPts = mapPtr->screenPts;
    assert(mapPtr->nScreenPts > 0);

    Blt_GraphExtents(graphPtr, &exts);

................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Extents2D exts;
    Point2D *symbolPts;
    int *indices;
    register int i, count;

    symbolPts = Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
    assert(symbolPts);

    indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    assert(indices);

................................................................................
    Graph *graphPtr;
    Line *linePtr;
{
    Extents2D exts;
    double x, y;
    int count;
    Point2D *activePts;
    register int i;
    int pointIndex;
    int nPoints;
    int *activeToData;

    if (linePtr->activePts != NULL) {
	Blt_Free(linePtr->activePts);
	linePtr->activePts = NULL;
................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Extents2D exts;
    Segment2D *strips;
    int *indices, *indexPtr;
    register Point2D *endPtr, *pointPtr;
    register Segment2D *segPtr;
    register int count;

    indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    assert(indices);

    /* 
     * Create array to hold points for line segments (not polyline 
     * coordinates).  So allocate twice the number of points.  
................................................................................
 */
static void
MergePens(linePtr, dataToStyle)
    Line *linePtr;
    PenStyle **dataToStyle;
{
    LinePenStyle *stylePtr;
    register int i;
    Blt_ChainLink *linkPtr;

    if (Blt_ChainGetLength(linePtr->palette) < 2) {
	linkPtr = Blt_ChainFirstLink(linePtr->palette);
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->nStrips = linePtr->nStrips;
	stylePtr->strips = linePtr->strips;
................................................................................

    /* We have more than one style. Group line segments and points of
     * like pen styles.  */

    if (linePtr->nStrips > 0) {
	Segment2D *strips;
	int *stripToData;
	register Segment2D *segPtr;
	register int *indexPtr;
	int dataIndex;

	strips = Blt_Malloc(linePtr->nStrips * sizeof(Segment2D));
	stripToData = Blt_Malloc(linePtr->nStrips * sizeof(int));
	assert(strips && stripToData);
	segPtr = strips, indexPtr = stripToData;
	for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
................................................................................
	Blt_Free(linePtr->strips);
	linePtr->strips = strips;
	Blt_Free(linePtr->stripToData);
	linePtr->stripToData = stripToData;
    }
    if (linePtr->nSymbolPts > 0) {
	int *indexPtr;
	register Point2D *symbolPts, *pointPtr;
	register int *symbolToData;
	int dataIndex;

	symbolPts = Blt_Malloc(linePtr->nSymbolPts * sizeof(Point2D));
	symbolToData = Blt_Malloc(linePtr->nSymbolPts * sizeof(int));
	assert(symbolPts && symbolToData);
	pointPtr = symbolPts, indexPtr = symbolToData;
	for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
................................................................................
    }
    return code;
}

static int
ClipSegment(extsPtr, code1, code2, p, q)
    Extents2D *extsPtr;
    register int code1, code2;
    register Point2D *p, *q;
{
    int inside, outside;

    inside = ((code1 | code2) == 0);
    outside = ((code1 & code2) != 0);

    /*
................................................................................
				 * array.  Used to figure out closest point */
    int length;			/* Number of points forming the trace */
    MapInfo *mapPtr;
{
    Trace *tracePtr;
    Point2D *screenPts;
    int *indices;
    register int i, j;

    tracePtr = Blt_Malloc(sizeof(Trace));
    assert(tracePtr);
    screenPts = Blt_Malloc(sizeof(Point2D) * length);
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * length);
    assert(indices);
................................................................................
    MapInfo *mapPtr;
{
    int start, count;
    int code1, code2;
    Point2D *p, *q;
    Point2D s;
    Extents2D exts;
    register int i;
    int broken, offscreen;

    Blt_GraphExtents(graphPtr, &exts);
    count = 1;
    code1 = OutCode(&exts, mapPtr->screenPts);
    p = mapPtr->screenPts;
    q = p + 1;
................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Point2D *origPts, *clipPts;
    Extents2D exts;
    double maxY;
    register int i, n;

    if (linePtr->fillPts != NULL) {
	Blt_Free(linePtr->fillPts);
	linePtr->fillPts = NULL;
	linePtr->nFillPts = 0;
    }
    if (mapPtr->nScreenPts < 3) {
................................................................................
    ClosestSearch *searchPtr;	/* Info about closest point in element */
    DistanceProc *distProc;
{
    Blt_ChainLink *linkPtr;
    Point2D closest, b;
    Trace *tracePtr;
    double dist, minDist;
    register Point2D *pointPtr, *endPtr;
    int i;

    i = -1;			/* Suppress compiler warning. */
    minDist = searchPtr->dist;
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	tracePtr = Blt_ChainGetValue(linkPtr);
................................................................................
    ClosestSearch *searchPtr;	/* Info about closest point in element */
    DistanceProc *distProc;
{
    Point2D closest, b;
    double dist, minDist;
    int count;
    int i;
    register Segment2D *s;

    i = 0;
    minDist = searchPtr->dist;
    s = linePtr->strips;
    for (count = 0; count < linePtr->nStrips; count++, s++) {
	dist = (*distProc)(searchPtr->x, searchPtr->y, &(s->p), &(s->q), &b);
	if (dist < minDist) {
................................................................................
    Line *linePtr;		/* Line element that we are looking at */
    ClosestSearch *searchPtr;	/* Assorted information related to searching
				 * for the closest point */
{
    double dist, minDist;
    double dx, dy;
    int count, i;
    register Point2D *pointPtr;

    minDist = searchPtr->dist;
    i = 0;

    /*
     * Instead of testing each data point in graph coordinates, look at
     * the array of mapped screen coordinates. The advantages are
................................................................................
    } else {
	extsPtr->top = elemPtr->y.min;
    }

    /* Correct the data limits for error bars */

    if (elemPtr->xError.nValues > 0) {
	register int i;
	double x;
	
	nPoints = MIN(elemPtr->xError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
	    if (x > extsPtr->right) {
		extsPtr->right = x;
................................................................................
	    if (left < extsPtr->left) {
		extsPtr->left = left;
	    }
	}
    }
    
    if (elemPtr->yError.nValues > 0) {
	register int i;
	double y;
	
	nPoints = MIN(elemPtr->yError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
	    if (y > extsPtr->bottom) {
		extsPtr->bottom = y;
................................................................................

#define MAX_DRAWLINES(d)	Blt_MaxRequestSize(d, sizeof(XPoint))
#define MAX_DRAWPOLYGON(d)	Blt_MaxRequestSize(d, sizeof(XPoint))
#define MAX_DRAWSEGMENTS(d)	Blt_MaxRequestSize(d, sizeof(XSegment))
#define MAX_DRAWRECTANGLES(d)	Blt_MaxRequestSize(d, sizeof(XRectangle))
#define MAX_DRAWARCS(d)		Blt_MaxRequestSize(d, sizeof(XArc))

#ifdef WIN32

static void
DrawCircles(
    Display *display,
    Drawable drawable,
    Line *linePtr,
    LinePen *penPtr,
................................................................................
    Point2D *symbolPts,
    int radius)
{
    HBRUSH brush, oldBrush;
    HPEN pen, oldPen;
    HDC dc;
    TkWinDCState state;
    register Point2D *pointPtr, *endPtr;

    if (drawable == None) {
	return;			/* Huh? */
    }
    if ((penPtr->symbol.fillGC == NULL) && 
	(penPtr->symbol.outlineWidth == 0)) {
	return;
................................................................................
    Drawable drawable;
    Line *linePtr;
    LinePen *penPtr;
    int nSymbolPts;
    Point2D *symbolPts;
    int radius;
{
    register int i;
    XArc *arcArr;		/* Array of arcs (circle) */
    register XArc *arcPtr;
    int reqSize, nArcs;
    int s;
    int count;
    register Point2D *pointPtr, *endPtr;

    s = radius + radius;
    arcArr = Blt_Malloc(nSymbolPts * sizeof(XArc));
    arcPtr = arcArr;

    if (linePtr->symbolInterval > 0) {
	count = 0;
................................................................................
static void
DrawSquares(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, r)
    Display *display;
    Drawable drawable;
    Line *linePtr;
    LinePen *penPtr;
    int nSymbolPts;
    register Point2D *symbolPts;
    int r;
{
    XRectangle *rectArr;
    register Point2D *pointPtr, *endPtr;
    register XRectangle *rectPtr;
    int reqSize, nRects;
    int s;
    register int i;
    int count;

    s = r + r;
    rectArr = Blt_Malloc(nSymbolPts * sizeof(XRectangle));
    rectPtr = rectArr;

    if (linePtr->symbolInterval > 0) {
................................................................................
    LinePen *penPtr;
    int size;			/* Size of element */
    int nSymbolPts;		/* Number of coordinates in array */
    Point2D *symbolPts;		/* Array of x,y coordinates for line */
{
    XPoint pattern[13];		/* Template for polygon symbols */
    int r1, r2;
    register int i, n;
    int count;
    register Point2D *pointPtr, *endPtr;
#define SQRT_PI		1.77245385090552
#define S_RATIO		0.886226925452758

    if (size < 3) {
	if (penPtr->symbol.fillGC != NULL) {
	    XPoint *points;
	    
................................................................................
	    symbolPts, r1);
	break;

    case SYMBOL_SPLUS:
    case SYMBOL_SCROSS:
	{
	    XSegment *segArr;	/* Array of line segments (splus, scross) */
	    register XSegment *segPtr;
	    int reqSize, nSegs, chunk;

	    if (penPtr->symbol.type == SYMBOL_SCROSS) {
		r2 = Round(r2 * M_SQRT1_2);
		pattern[3].y = pattern[2].x = pattern[0].x = pattern[0].y = -r2;
		pattern[3].x = pattern[2].y = pattern[1].y = pattern[1].x = r2;
	    } else {
................................................................................
	}
	break;

    case SYMBOL_PLUS:
    case SYMBOL_CROSS:
	{
	    XPoint *polygon;
	    register XPoint *p;
	    int d;		/* Small delta for cross/plus thickness */

	    d = (r2 / 3);

	    /*
	     *
	     *          2   3       The plus/cross symbol is a closed polygon
................................................................................
	    Blt_Free(polygon);
	}
	break;

    case SYMBOL_DIAMOND:
	{
	    XPoint *polygon;
	    register XPoint *p;

	    /*
	     *
	     *                      The plus symbol is a closed polygon
	     *            1         of 4 points. The diagram to the left
	     *                      represents the positions of the points
	     *       0,4 x,y  2     which are computed below. The extra
................................................................................
	}
	break;

    case SYMBOL_TRIANGLE:
    case SYMBOL_ARROW:
	{
	    XPoint *polygon;
	    register XPoint *p;
	    double b;
	    int b2, h1, h2;
#define H_RATIO		1.1663402261671607
#define B_RATIO		1.3467736870885982
#define TAN30		0.57735026918962573
#define COS30		0.86602540378443871

................................................................................
	break;
    case SYMBOL_BITMAP:
	{
	    Pixmap bitmap, mask;
	    int width, height, bmWidth, bmHeight;
	    double scale, sx, sy;
	    int dx, dy;
	    register int x, y;

	    Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
		&width, &height);
	    mask = None;

	    /*
	     * Compute the size of the scaled bitmap.  Stretch the
................................................................................

	point.x = x, point.y = y;
	DrawSymbols(graphPtr, drawable, linePtr, linePtr->normalPenPtr, size,
	    1, &point);
    }
}

#ifdef WIN32

static void
DrawTraces(
    Graph *graphPtr,
    Drawable drawable,		/* Pixmap or window to draw into */
    Line *linePtr,
    LinePen *penPtr)
................................................................................
    HDC dc;
    HPEN pen, oldPen;
    POINT *points;
    TkWinDCState state;
    Trace *tracePtr;
    int j;
    int nPoints, remaining;
    register POINT *p;
    register int count;

    /*  
     * Depending if the line is wide (> 1 pixel), arbitrarily break
     * the line in sections of 100 points.  This bit of weirdness has
     * to do with wide geometric pens.  The longer the polyline, the
     * slower it draws.  The trade off is that we lose dash and cap
     * uniformity for unbearably slow polyline draws.
................................................................................
    LinePen *penPtr;
{
    Blt_ChainLink *linkPtr;
    Trace *tracePtr;
    XPoint *points;
    int j;
    int nPoints, remaining;
    register XPoint *p;
    register int count;

    nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(XPoint)) - 1;
    points = Blt_Malloc((nPoints + 1) * sizeof(XPoint));
	    
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	int n;
................................................................................
    Graph *graphPtr;		/* Graph widget record */
    Drawable drawable;		/* Pixmap or window to draw into */
    Element *elemPtr;		/* Element to be drawn */
{
    Line *linePtr = (Line *)elemPtr;
    LinePen *penPtr;
    Blt_ChainLink *linkPtr;
    register LinePenStyle *stylePtr;
    unsigned int count;

    /* Fill area under the curve */
    if (linePtr->fillPts != NULL) {
	XPoint *points;
	Point2D *endPtr, *pointPtr;

................................................................................
    PsToken psToken;
    LinePen *penPtr;
    int size;
    int nSymbolPts;
    Point2D *symbolPts;
{
    double symbolSize;
    register Point2D *pointPtr, *endPtr;
    static char *symbolMacros[] =
    {
	"Li", "Sq", "Ci", "Di", "Pl", "Cr", "Sp", "Sc", "Tr", "Ar", "Bm", 
	(char *)NULL,
    };
    GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size);

................................................................................
TracesToPostScript(psToken, linePtr, penPtr)
    PsToken psToken;
    Line *linePtr;
    LinePen *penPtr;
{
    Blt_ChainLink *linkPtr;
    Trace *tracePtr;
    register Point2D *pointPtr, *endPtr;
    int count;

    SetLineAttributes(psToken, penPtr);
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	tracePtr = Blt_ChainGetValue(linkPtr);
	if (tracePtr->nScreenPts <= 0) {
................................................................................
static void
NormalLineToPostScript(graphPtr, psToken, elemPtr)
    Graph *graphPtr;
    PsToken psToken;
    Element *elemPtr;
{
    Line *linePtr = (Line *)elemPtr;
    register LinePenStyle *stylePtr;
    Blt_ChainLink *linkPtr;
    LinePen *penPtr;
    unsigned int count;
    XColor *colorPtr;

    /* Draw fill area */
    if (linePtr->fillPts != NULL) {
................................................................................

Element *
Blt_LineElement(graphPtr, name, classUid)
    Graph *graphPtr;
    char *name;
    Blt_Uid classUid;
{
    register Line *linePtr;

    linePtr = Blt_Calloc(1, sizeof(Line));
    assert(linePtr);
    linePtr->procsPtr = &lineProcs;
    if (classUid == bltLineElementUid) {
	linePtr->configSpecs = lineElemConfigSpecs;
    } else {







>







 







|
|
|
<
>
|
|
<
>
|
|
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
|

>


>
>
|

>


>
>
|

>


>
>
|

>


>
>
|

>







 







|







 







|







 







|


|







 







|








|







 







|







 







|




|







 







|







 







|







 







|







 







|
|
|
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|
|
|







 







|







 







|
|







 







|
|







 







|
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|

|



|







 







|



|
|


|







 







|

|







 







|







 







|







 







|







 







|







 







|







 







|







 







|
|







 







|
|







 







|







 







|







 







|







 







|







 







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
399
400
401
402
403
404
405
406
407
408

409
410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
...
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
...
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
....
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
....
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
....
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
....
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
....
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
....
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
....
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
....
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
....
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
....
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
....
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
....
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
....
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
....
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
....
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
....
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
....
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
....
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
....
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
....
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
....
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
....
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
....
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
....
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
....
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
....
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
....
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
....
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
....
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
....
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
....
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
....
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
....
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
....
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
....
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
....
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
....
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
....
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
....
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
....
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
....
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
....
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
....
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
 * fitness.  In no event shall Lucent Technologies be liable for any
 * special, indirect or consequential damages or any damages
 * whatsoever resulting from loss of use, data or profits, whether in
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */
#include "bltInt.h"
#include "bltGraph.h"
#include "bltChain.h"
#include <X11/Xutil.h>

#include "bltGrElem.h"

#define COLOR_DEFAULT	(XColor *)1
................................................................................
				 * element trace. The segments are
				 * grouped by pen style. */
    int nStrips;		/* Number of line segments to be drawn. */
    int *stripToData;		/* Pen to visible line segment mapping. */

} Line;

static int StringToPattern _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *PatternToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));


static int StringToSmooth _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *SmoothToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

extern int Blt_StringToStyles _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

extern char *Blt_StylesToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToPenDir _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *PenDirToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToSymbol _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *SymbolToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption patternOption =
{
    (Tk_OptionParseProc *)StringToPattern,
    (Tk_OptionPrintProc *)PatternToString,
    (ClientData)0
};

static Tk_CustomOption smoothOption =
{
    (Tk_OptionParseProc *)StringToSmooth,
    (Tk_OptionPrintProc *)SmoothToString,
    (ClientData)0
};

static Tk_CustomOption stylesOption =
{
    (Tk_OptionParseProc *)Blt_StringToStyles,
    (Tk_OptionPrintProc *)Blt_StylesToString,
    (ClientData)sizeof(LinePenStyle)
};

static Tk_CustomOption penDirOption =
{
    (Tk_OptionParseProc *)StringToPenDir,
    (Tk_OptionPrintProc *)PenDirToString,
    (ClientData)0
};

static Tk_CustomOption symbolOption =
{
    (Tk_OptionParseProc *)StringToSymbol,
    (Tk_OptionPrintProc *)SymbolToString,
    (ClientData)0
};

extern Tk_CustomOption bltColorOption;
extern Tk_CustomOption bltDashesOption;
extern Tk_CustomOption bltDataOption;
extern Tk_CustomOption bltDataPairsOption;
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltListOption;
extern Tk_CustomOption bltLinePenOption;
................................................................................
static DistanceProc DistanceToY;
static DistanceProc DistanceToX;
static DistanceProc DistanceToLine;
#ifndef NO_TILE
static Blt_TileChangedProc TileChangedProc;
#endif

#if defined(WIN32) && !defined(PLATFORM_SDL)

static int tkpWinRopModes[] =
{
    R2_BLACK,			/* GXclear */
    R2_MASKPEN,			/* GXand */
    R2_MASKPENNOT,		/* GXandReverse */
    R2_COPYPEN,			/* GXcopy */
................................................................................
    R2_WHITE			/* GXset */
};

#endif

INLINE static int
Round(x)
    double x;
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

/*
 * ----------------------------------------------------------------------
 * 	Custom configuration option (parse and print) routines
................................................................................
 */

static int
StringToBitmap(interp, tkwin, symbolPtr, string)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    Symbol *symbolPtr;
    CONST char *string;
{
    Pixmap bitmap, mask;
    CONST char **elemArr;
    int nElems;
    int result;

    if (Tcl_SplitList(interp, string, &nElems, &elemArr) != TCL_OK) {
	return TCL_ERROR;
    }

................................................................................

    if (stipple == None) {
	return "";
    } 
    if (stipple == PATTERN_SOLID) {
	return "solid";
    } 
    return (char *) Tk_NameOfBitmap(Tk_Display(tkwin), stipple);
}

/*ARGSUSED*/
static int
StringToPattern(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing field */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of field in record */
{
    Pixmap *stipplePtr = (Pixmap *)(widgRec + offset);
    Pixmap stipple;

    if ((string == NULL) || (string[0] == '\0')) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToSymbol(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing symbol type */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of symbol type field in record */
{
    Symbol *symbolPtr = (Symbol *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
static int
StringToSmooth(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing smooth type */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of smooth type field in record */
{
    Smoothing *valuePtr = (Smoothing *)(widgRec + offset);
    SmoothingInfo *siPtr;

    for (siPtr = smoothingInfo; siPtr->name != NULL; siPtr++) {
	if (strcmp(string, siPtr->name) == 0) {
	    *valuePtr = siPtr->value;
	    return TCL_OK;
	}
    }
................................................................................
 */
/*ARGSUSED*/
static int
StringToPenDir(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing pen direction */
    char *widgRec;		/* Element information record */
    int offset;			/* Offset of pen direction field in record */
{
    int *penDirPtr = (int *)(widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 * Clear the number of points and segments, in case there are no
 * segments or points
 */
static void
ClearPalette(palette)
    Blt_Chain *palette;
{
    LinePenStyle *stylePtr;
    Blt_ChainLink *linkPtr;

    for (linkPtr = Blt_ChainFirstLink(palette); linkPtr != NULL;
	 linkPtr = Blt_ChainNextLink(linkPtr)) {
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->nStrips = stylePtr->nSymbolPts = 0;
	stylePtr->xErrorBarCnt = stylePtr->yErrorBarCnt = 0;
................................................................................
    penPtr->symbol.outlineWidth = penPtr->traceWidth = 1;
    penPtr->symbol.type = SYMBOL_CIRCLE;
    penPtr->valueShow = SHOW_NONE;
}

Pen *
Blt_LinePen(penName)
    CONST char *penName;
{
    LinePen *penPtr;

    penPtr = Blt_Calloc(1, sizeof(LinePen));
    assert(penPtr);
    InitPen(penPtr);
    penPtr->name = Blt_Strdup(penName);
................................................................................
static void
GetScreenPoints(graphPtr, linePtr, mapPtr)
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    double *x, *y;
    int i, n;
    int count;
    Point2D *screenPts;
    int *indices;

    n = NumberOfPoints(linePtr);
    x = linePtr->x.valueArr;
    y = linePtr->y.valueArr;
    screenPts = Blt_Malloc(sizeof(Point2D) * n);
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * n);
................................................................................
 *----------------------------------------------------------------------
 */
static void
ReducePoints(mapPtr, tolerance)
    MapInfo *mapPtr;
    double tolerance;
{
    int i, k, n;
    Point2D *screenPts;
    int *indices, *simple;

    simple	= Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    indices	= Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    screenPts	= Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
    n = Blt_SimplifyLine(mapPtr->screenPts, 0, mapPtr->nScreenPts - 1, 
................................................................................
 *---------------------------------------------------------------------- 
 */
static void
GenerateSteps(mapPtr)
    MapInfo *mapPtr;
{
    int newSize;
    int i, count;
    Point2D *screenPts;
    int *indices;

    newSize = ((mapPtr->nScreenPts - 1) * 2) + 1;
    screenPts = Blt_Malloc(newSize * sizeof(Point2D));
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * newSize);
................................................................................
static void
GenerateSpline(graphPtr, linePtr, mapPtr)
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    int extra;
    int i, j, count;
    Point2D *origPts, *intpPts;
    int *indices;
    int nIntpPts, nOrigPts;
    int result;
    int x;

    nOrigPts = mapPtr->nScreenPts;
................................................................................
    Extents2D exts;
    Point2D *origPts, *intpPts;
    Point2D p, q;
    double dist;
    int *indices;
    int nIntpPts, nOrigPts;
    int result;
    int i, j, count;

    nOrigPts = mapPtr->nScreenPts;
    origPts = mapPtr->screenPts;
    assert(mapPtr->nScreenPts > 0);

    Blt_GraphExtents(graphPtr, &exts);

................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Extents2D exts;
    Point2D *symbolPts;
    int *indices;
    int i, count;

    symbolPts = Blt_Malloc(sizeof(Point2D) * mapPtr->nScreenPts);
    assert(symbolPts);

    indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    assert(indices);

................................................................................
    Graph *graphPtr;
    Line *linePtr;
{
    Extents2D exts;
    double x, y;
    int count;
    Point2D *activePts;
    int i;
    int pointIndex;
    int nPoints;
    int *activeToData;

    if (linePtr->activePts != NULL) {
	Blt_Free(linePtr->activePts);
	linePtr->activePts = NULL;
................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Extents2D exts;
    Segment2D *strips;
    int *indices, *indexPtr;
    Point2D *endPtr, *pointPtr;
    Segment2D *segPtr;
    int count;

    indices = Blt_Malloc(sizeof(int) * mapPtr->nScreenPts);
    assert(indices);

    /* 
     * Create array to hold points for line segments (not polyline 
     * coordinates).  So allocate twice the number of points.  
................................................................................
 */
static void
MergePens(linePtr, dataToStyle)
    Line *linePtr;
    PenStyle **dataToStyle;
{
    LinePenStyle *stylePtr;
    int i;
    Blt_ChainLink *linkPtr;

    if (Blt_ChainGetLength(linePtr->palette) < 2) {
	linkPtr = Blt_ChainFirstLink(linePtr->palette);
	stylePtr = Blt_ChainGetValue(linkPtr);
	stylePtr->nStrips = linePtr->nStrips;
	stylePtr->strips = linePtr->strips;
................................................................................

    /* We have more than one style. Group line segments and points of
     * like pen styles.  */

    if (linePtr->nStrips > 0) {
	Segment2D *strips;
	int *stripToData;
	Segment2D *segPtr;
	int *indexPtr;
	int dataIndex;

	strips = Blt_Malloc(linePtr->nStrips * sizeof(Segment2D));
	stripToData = Blt_Malloc(linePtr->nStrips * sizeof(int));
	assert(strips && stripToData);
	segPtr = strips, indexPtr = stripToData;
	for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
................................................................................
	Blt_Free(linePtr->strips);
	linePtr->strips = strips;
	Blt_Free(linePtr->stripToData);
	linePtr->stripToData = stripToData;
    }
    if (linePtr->nSymbolPts > 0) {
	int *indexPtr;
	Point2D *symbolPts, *pointPtr;
	int *symbolToData;
	int dataIndex;

	symbolPts = Blt_Malloc(linePtr->nSymbolPts * sizeof(Point2D));
	symbolToData = Blt_Malloc(linePtr->nSymbolPts * sizeof(int));
	assert(symbolPts && symbolToData);
	pointPtr = symbolPts, indexPtr = symbolToData;
	for (linkPtr = Blt_ChainFirstLink(linePtr->palette); linkPtr != NULL;
................................................................................
    }
    return code;
}

static int
ClipSegment(extsPtr, code1, code2, p, q)
    Extents2D *extsPtr;
    int code1, code2;
    Point2D *p, *q;
{
    int inside, outside;

    inside = ((code1 | code2) == 0);
    outside = ((code1 & code2) != 0);

    /*
................................................................................
				 * array.  Used to figure out closest point */
    int length;			/* Number of points forming the trace */
    MapInfo *mapPtr;
{
    Trace *tracePtr;
    Point2D *screenPts;
    int *indices;
    int i, j;

    tracePtr = Blt_Malloc(sizeof(Trace));
    assert(tracePtr);
    screenPts = Blt_Malloc(sizeof(Point2D) * length);
    assert(screenPts);
    indices = Blt_Malloc(sizeof(int) * length);
    assert(indices);
................................................................................
    MapInfo *mapPtr;
{
    int start, count;
    int code1, code2;
    Point2D *p, *q;
    Point2D s;
    Extents2D exts;
    int i;
    int broken, offscreen;

    Blt_GraphExtents(graphPtr, &exts);
    count = 1;
    code1 = OutCode(&exts, mapPtr->screenPts);
    p = mapPtr->screenPts;
    q = p + 1;
................................................................................
    Graph *graphPtr;
    Line *linePtr;
    MapInfo *mapPtr;
{
    Point2D *origPts, *clipPts;
    Extents2D exts;
    double maxY;
    int i, n;

    if (linePtr->fillPts != NULL) {
	Blt_Free(linePtr->fillPts);
	linePtr->fillPts = NULL;
	linePtr->nFillPts = 0;
    }
    if (mapPtr->nScreenPts < 3) {
................................................................................
    ClosestSearch *searchPtr;	/* Info about closest point in element */
    DistanceProc *distProc;
{
    Blt_ChainLink *linkPtr;
    Point2D closest, b;
    Trace *tracePtr;
    double dist, minDist;
    Point2D *pointPtr, *endPtr;
    int i;

    i = -1;			/* Suppress compiler warning. */
    minDist = searchPtr->dist;
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	tracePtr = Blt_ChainGetValue(linkPtr);
................................................................................
    ClosestSearch *searchPtr;	/* Info about closest point in element */
    DistanceProc *distProc;
{
    Point2D closest, b;
    double dist, minDist;
    int count;
    int i;
    Segment2D *s;

    i = 0;
    minDist = searchPtr->dist;
    s = linePtr->strips;
    for (count = 0; count < linePtr->nStrips; count++, s++) {
	dist = (*distProc)(searchPtr->x, searchPtr->y, &(s->p), &(s->q), &b);
	if (dist < minDist) {
................................................................................
    Line *linePtr;		/* Line element that we are looking at */
    ClosestSearch *searchPtr;	/* Assorted information related to searching
				 * for the closest point */
{
    double dist, minDist;
    double dx, dy;
    int count, i;
    Point2D *pointPtr;

    minDist = searchPtr->dist;
    i = 0;

    /*
     * Instead of testing each data point in graph coordinates, look at
     * the array of mapped screen coordinates. The advantages are
................................................................................
    } else {
	extsPtr->top = elemPtr->y.min;
    }

    /* Correct the data limits for error bars */

    if (elemPtr->xError.nValues > 0) {
	int i;
	double x;
	
	nPoints = MIN(elemPtr->xError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    x = elemPtr->x.valueArr[i] + elemPtr->xError.valueArr[i];
	    if (x > extsPtr->right) {
		extsPtr->right = x;
................................................................................
	    if (left < extsPtr->left) {
		extsPtr->left = left;
	    }
	}
    }
    
    if (elemPtr->yError.nValues > 0) {
	int i;
	double y;
	
	nPoints = MIN(elemPtr->yError.nValues, nPoints);
	for (i = 0; i < nPoints; i++) {
	    y = elemPtr->y.valueArr[i] + elemPtr->yError.valueArr[i];
	    if (y > extsPtr->bottom) {
		extsPtr->bottom = y;
................................................................................

#define MAX_DRAWLINES(d)	Blt_MaxRequestSize(d, sizeof(XPoint))
#define MAX_DRAWPOLYGON(d)	Blt_MaxRequestSize(d, sizeof(XPoint))
#define MAX_DRAWSEGMENTS(d)	Blt_MaxRequestSize(d, sizeof(XSegment))
#define MAX_DRAWRECTANGLES(d)	Blt_MaxRequestSize(d, sizeof(XRectangle))
#define MAX_DRAWARCS(d)		Blt_MaxRequestSize(d, sizeof(XArc))

#if defined(WIN32) && !defined(PLATFORM_SDL)

static void
DrawCircles(
    Display *display,
    Drawable drawable,
    Line *linePtr,
    LinePen *penPtr,
................................................................................
    Point2D *symbolPts,
    int radius)
{
    HBRUSH brush, oldBrush;
    HPEN pen, oldPen;
    HDC dc;
    TkWinDCState state;
    Point2D *pointPtr, *endPtr;

    if (drawable == None) {
	return;			/* Huh? */
    }
    if ((penPtr->symbol.fillGC == NULL) && 
	(penPtr->symbol.outlineWidth == 0)) {
	return;
................................................................................
    Drawable drawable;
    Line *linePtr;
    LinePen *penPtr;
    int nSymbolPts;
    Point2D *symbolPts;
    int radius;
{
    int i;
    XArc *arcArr;		/* Array of arcs (circle) */
    XArc *arcPtr;
    int reqSize, nArcs;
    int s;
    int count;
    Point2D *pointPtr, *endPtr;

    s = radius + radius;
    arcArr = Blt_Malloc(nSymbolPts * sizeof(XArc));
    arcPtr = arcArr;

    if (linePtr->symbolInterval > 0) {
	count = 0;
................................................................................
static void
DrawSquares(display, drawable, linePtr, penPtr, nSymbolPts, symbolPts, r)
    Display *display;
    Drawable drawable;
    Line *linePtr;
    LinePen *penPtr;
    int nSymbolPts;
    Point2D *symbolPts;
    int r;
{
    XRectangle *rectArr;
    Point2D *pointPtr, *endPtr;
    XRectangle *rectPtr;
    int reqSize, nRects;
    int s;
    int i;
    int count;

    s = r + r;
    rectArr = Blt_Malloc(nSymbolPts * sizeof(XRectangle));
    rectPtr = rectArr;

    if (linePtr->symbolInterval > 0) {
................................................................................
    LinePen *penPtr;
    int size;			/* Size of element */
    int nSymbolPts;		/* Number of coordinates in array */
    Point2D *symbolPts;		/* Array of x,y coordinates for line */
{
    XPoint pattern[13];		/* Template for polygon symbols */
    int r1, r2;
    int i, n;
    int count;
    Point2D *pointPtr, *endPtr;
#define SQRT_PI		1.77245385090552
#define S_RATIO		0.886226925452758

    if (size < 3) {
	if (penPtr->symbol.fillGC != NULL) {
	    XPoint *points;
	    
................................................................................
	    symbolPts, r1);
	break;

    case SYMBOL_SPLUS:
    case SYMBOL_SCROSS:
	{
	    XSegment *segArr;	/* Array of line segments (splus, scross) */
	    XSegment *segPtr;
	    int reqSize, nSegs, chunk;

	    if (penPtr->symbol.type == SYMBOL_SCROSS) {
		r2 = Round(r2 * M_SQRT1_2);
		pattern[3].y = pattern[2].x = pattern[0].x = pattern[0].y = -r2;
		pattern[3].x = pattern[2].y = pattern[1].y = pattern[1].x = r2;
	    } else {
................................................................................
	}
	break;

    case SYMBOL_PLUS:
    case SYMBOL_CROSS:
	{
	    XPoint *polygon;
	    XPoint *p;
	    int d;		/* Small delta for cross/plus thickness */

	    d = (r2 / 3);

	    /*
	     *
	     *          2   3       The plus/cross symbol is a closed polygon
................................................................................
	    Blt_Free(polygon);
	}
	break;

    case SYMBOL_DIAMOND:
	{
	    XPoint *polygon;
	    XPoint *p;

	    /*
	     *
	     *                      The plus symbol is a closed polygon
	     *            1         of 4 points. The diagram to the left
	     *                      represents the positions of the points
	     *       0,4 x,y  2     which are computed below. The extra
................................................................................
	}
	break;

    case SYMBOL_TRIANGLE:
    case SYMBOL_ARROW:
	{
	    XPoint *polygon;
	    XPoint *p;
	    double b;
	    int b2, h1, h2;
#define H_RATIO		1.1663402261671607
#define B_RATIO		1.3467736870885982
#define TAN30		0.57735026918962573
#define COS30		0.86602540378443871

................................................................................
	break;
    case SYMBOL_BITMAP:
	{
	    Pixmap bitmap, mask;
	    int width, height, bmWidth, bmHeight;
	    double scale, sx, sy;
	    int dx, dy;
	    int x, y;

	    Tk_SizeOfBitmap(graphPtr->display, penPtr->symbol.bitmap,
		&width, &height);
	    mask = None;

	    /*
	     * Compute the size of the scaled bitmap.  Stretch the
................................................................................

	point.x = x, point.y = y;
	DrawSymbols(graphPtr, drawable, linePtr, linePtr->normalPenPtr, size,
	    1, &point);
    }
}

#if defined(WIN32) && !defined(PLATFORM_SDL)

static void
DrawTraces(
    Graph *graphPtr,
    Drawable drawable,		/* Pixmap or window to draw into */
    Line *linePtr,
    LinePen *penPtr)
................................................................................
    HDC dc;
    HPEN pen, oldPen;
    POINT *points;
    TkWinDCState state;
    Trace *tracePtr;
    int j;
    int nPoints, remaining;
    POINT *p;
    int count;

    /*  
     * Depending if the line is wide (> 1 pixel), arbitrarily break
     * the line in sections of 100 points.  This bit of weirdness has
     * to do with wide geometric pens.  The longer the polyline, the
     * slower it draws.  The trade off is that we lose dash and cap
     * uniformity for unbearably slow polyline draws.
................................................................................
    LinePen *penPtr;
{
    Blt_ChainLink *linkPtr;
    Trace *tracePtr;
    XPoint *points;
    int j;
    int nPoints, remaining;
    XPoint *p;
    int count;

    nPoints = Blt_MaxRequestSize(graphPtr->display, sizeof(XPoint)) - 1;
    points = Blt_Malloc((nPoints + 1) * sizeof(XPoint));
	    
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	int n;
................................................................................
    Graph *graphPtr;		/* Graph widget record */
    Drawable drawable;		/* Pixmap or window to draw into */
    Element *elemPtr;		/* Element to be drawn */
{
    Line *linePtr = (Line *)elemPtr;
    LinePen *penPtr;
    Blt_ChainLink *linkPtr;
    LinePenStyle *stylePtr;
    unsigned int count;

    /* Fill area under the curve */
    if (linePtr->fillPts != NULL) {
	XPoint *points;
	Point2D *endPtr, *pointPtr;

................................................................................
    PsToken psToken;
    LinePen *penPtr;
    int size;
    int nSymbolPts;
    Point2D *symbolPts;
{
    double symbolSize;
    Point2D *pointPtr, *endPtr;
    static char *symbolMacros[] =
    {
	"Li", "Sq", "Ci", "Di", "Pl", "Cr", "Sp", "Sc", "Tr", "Ar", "Bm", 
	(char *)NULL,
    };
    GetSymbolPostScriptInfo(graphPtr, psToken, penPtr, size);

................................................................................
TracesToPostScript(psToken, linePtr, penPtr)
    PsToken psToken;
    Line *linePtr;
    LinePen *penPtr;
{
    Blt_ChainLink *linkPtr;
    Trace *tracePtr;
    Point2D *pointPtr, *endPtr;
    int count;

    SetLineAttributes(psToken, penPtr);
    for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
	linkPtr = Blt_ChainNextLink(linkPtr)) {
	tracePtr = Blt_ChainGetValue(linkPtr);
	if (tracePtr->nScreenPts <= 0) {
................................................................................
static void
NormalLineToPostScript(graphPtr, psToken, elemPtr)
    Graph *graphPtr;
    PsToken psToken;
    Element *elemPtr;
{
    Line *linePtr = (Line *)elemPtr;
    LinePenStyle *stylePtr;
    Blt_ChainLink *linkPtr;
    LinePen *penPtr;
    unsigned int count;
    XColor *colorPtr;

    /* Draw fill area */
    if (linePtr->fillPts != NULL) {
................................................................................

Element *
Blt_LineElement(graphPtr, name, classUid)
    Graph *graphPtr;
    char *name;
    Blt_Uid classUid;
{
    Line *linePtr;

    linePtr = Blt_Calloc(1, sizeof(Line));
    assert(linePtr);
    linePtr->procsPtr = &lineProcs;
    if (classUid == bltLineElementUid) {
	linePtr->configSpecs = lineElemConfigSpecs;
    } else {

Changes to jni/blt/src/bltGrMarker.c.

81
82
83
84
85
86
87
88
89





90
91
92


93

94
95
96
97
98
99
100
....
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
....
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
....
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
....
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
....
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
....
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
....
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
....
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
....
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
....
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
....
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
....
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
....
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
....
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
....
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
....
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
....
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
....
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
....
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
....
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
....
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
....
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
....
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
....
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
....
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
....
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
....
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
....
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
....
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
#define DEF_MARKER_TEXT_TAGS	"Text all"
#define DEF_MARKER_IMAGE_TAGS	"Image all"
#define DEF_MARKER_BITMAP_TAGS	"Bitmap all"
#define DEF_MARKER_WINDOW_TAGS	"Window all"
#define DEF_MARKER_POLYGON_TAGS	"Polygon all"
#define DEF_MARKER_LINE_TAGS	"Line all"

static Tk_OptionParseProc StringToCoordinates;
static Tk_OptionPrintProc CoordinatesToString;





static Tk_CustomOption coordsOption =
{
    StringToCoordinates, CoordinatesToString, (ClientData)0


};

extern Tk_CustomOption bltColorPairOption;
extern Tk_CustomOption bltDashesOption;
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltListOption;
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltShadowOption;
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ParseCoordinates(interp, markerPtr, nExprs, exprArr)
    Tcl_Interp *interp;
    Marker *markerPtr;
    int nExprs;
    char **exprArr;
{
    int nWorldPts;
    int minArgs, maxArgs;
    Point2D *worldPts;
    register int i;
    register Point2D *pointPtr;
    double x, y;

    if (nExprs == 0) {
	return TCL_OK;
    }
    if (nExprs & 1) {
	Tcl_AppendResult(interp, "odd number of marker coordinates specified",
................................................................................
 */
/*ARGSUSED*/
static int
StringToCoordinates(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* Tcl list of numeric expressions */
    char *widgRec;		/* Marker record */
    int offset;			/* Not used. */
{
    Marker *markerPtr = (Marker *)widgRec;
    int nExprs;
    char **exprArr;
    int result;

    nExprs = 0;
    if ((string != NULL) &&
	(Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK)) {
	return TCL_ERROR;
    }
................................................................................
    int offset;			/* Not used. */
    Tcl_FreeProc **freeProcPtr;	/* Memory deallocation scheme to use */
{
    Marker *markerPtr = (Marker *)widgRec;
    Tcl_Interp *interp;
    Tcl_DString dString;
    char *result;
    register int i;
    register Point2D *p;

    if (markerPtr->nWorldPts < 1) {
	return "";
    }
    interp = markerPtr->graphPtr->interp;

    Tcl_DStringInit(&dString);
................................................................................
 */
static double
HMap(graphPtr, axisPtr, x)
    Graph *graphPtr;
    Axis *axisPtr;
    double x;
{
    register double norm;

    if (x == DBL_MAX) {
	norm = 1.0;
    } else if (x == -DBL_MAX) {
	norm = 0.0;
    } else {
	if (axisPtr->logScale) {
................................................................................
 */
static double
VMap(graphPtr, axisPtr, y)
    Graph *graphPtr;
    Axis *axisPtr;
    double y;
{
    register double norm;

    if (y == DBL_MAX) {
	norm = 1.0;
    } else if (y == -DBL_MAX) {
	norm = 0.0;
    } else {
	if (axisPtr->logScale) {
................................................................................
    }
    return result;		/* Result is screen coordinate. */
}

static Marker *
CreateMarker(graphPtr, name, classUid)
    Graph *graphPtr;
    char *name;
    Blt_Uid classUid;    
{    
    Marker *markerPtr;

    /* Create the new marker based upon the given type */
    if (classUid == bltBitmapMarkerUid) {
	markerPtr = CreateBitmapMarker(); /* bitmap */
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;
    Extents2D exts;
    Graph *graphPtr = markerPtr->graphPtr;
    Point2D anchorPos;
    Point2D corner1, corner2;
    int destWidth, destHeight;
    int srcWidth, srcHeight;
    register int i;

    if (bmPtr->srcBitmap == None) {
	return;
    }
    if (bmPtr->destBitmap != None) {
	Tk_FreePixmap(graphPtr->display, bmPtr->destBitmap);
	bmPtr->destBitmap = None;
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;

    if (bmPtr->srcBitmap == None) {
	return 0;
    }
    if (bmPtr->theta != 0.0) {
	Point2D points[MAX_OUTLINE_POINTS];
	register int i;

	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < bmPtr->nOutlinePts; i++) {
	    points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x;
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;

    if (bmPtr->nWorldPts < 1) {
	return FALSE;
    }
    if (bmPtr->theta != 0.0) {
	Point2D points[MAX_OUTLINE_POINTS];
	register int i;
	
	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < bmPtr->nOutlinePts; i++) {
	    points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x;
................................................................................
	(char *)NULL)) {
	if (tmPtr->textPtr != NULL) {
	    Blt_Free(tmPtr->textPtr);
	    tmPtr->textPtr = NULL;
	}
	tmPtr->width = tmPtr->height = 0;
	if (tmPtr->string != NULL) {
	    register int i;
	    double rotWidth, rotHeight;

	    tmPtr->textPtr = Blt_GetTextLayout(tmPtr->string, &tmPtr->style);
	    Blt_GetBoundingBox(tmPtr->textPtr->width, tmPtr->textPtr->height, 
	       tmPtr->style.theta, &rotWidth, &rotHeight, tmPtr->outline);
	    tmPtr->width = ROUND(rotWidth);
	    tmPtr->height = ROUND(rotHeight);
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->string == NULL) {
	return 0;
    }
    if (tmPtr->style.theta != 0.0) {
	Point2D points[5];
	register int i;

	/* 
	 * Figure out the bounding polygon (isolateral) for the text
	 * and see if the point is inside of it.
	 */

	for (i = 0; i < 5; i++) {
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->nWorldPts < 1) {
	return FALSE;
    }
    if (tmPtr->style.theta != 0.0) {
	Point2D points[5];
	register int i;
	
	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < 4; i++) {
	    points[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x;
................................................................................
    Graph *graphPtr = markerPtr->graphPtr;

    if (tmPtr->string == NULL) {
	return;
    }
    if (tmPtr->fillGC != NULL) {
	XPoint pointArr[4];
	register int i;

	/*
	 * Simulate the rotated background of the bitmap by
	 * filling a bounding polygon with the background color.
	 */
	for (i = 0; i < 4; i++) {
	    pointArr[i].x = (short int)
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->string == NULL) {
	return;
    }
    if (tmPtr->fillGC != NULL) {
	Point2D polygon[4];
	register int i;

	/*
	 * Simulate the rotated background of the bitmap by
	 * filling a bounding polygon with the background color.
	 */
	for (i = 0; i < 4; i++) {
	    polygon[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x;
................................................................................
	    pmPtr->nFillPts = n;
	    pmPtr->fillPts = fillPts;
	    pmPtr->clipped = FALSE;
	}
    }
    if ((pmPtr->outline.fgColor != NULL) && (pmPtr->lineWidth > 0)) { 
	Segment2D *outlinePts;
	register Segment2D *segPtr;
	/* 
	 * Generate line segments representing the polygon outline.
	 * The resulting outline may or may not be closed from
	 * viewport clipping.  
	 */
	outlinePts = Blt_Malloc(nScreenPts * sizeof(Segment2D));
	if (outlinePts == NULL) {
................................................................................
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;
    Blt_ChainLink *linkPtr;
    register int i;

    Tcl_ResetResult(interp);
    for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList);
	linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	markerPtr = Blt_ChainGetValue(linkPtr);
	if (argc == 3) {
	    Tcl_AppendElement(interp, markerPtr->name);
................................................................................
    }
    return TCL_OK;
}

ClientData
Blt_MakeMarkerTag(graphPtr, tagName)
    Graph *graphPtr;
    char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->markers.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->markers.tagTable, hPtr);
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tag;

	for (hPtr = Blt_FirstHashEntry(&graphPtr->markers.tagTable, &cursor);
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;

    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tk_ConfigureValue(interp, graphPtr->tkwin, 
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;
    int flags = TK_CONFIG_ARGV_ONLY;
    char *oldName;
    int nNames, nOpts;
    char **options;
    register int i;
    int under;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
................................................................................
 * ----------------------------------------------------------------------
 */
static int
CreateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;
    Blt_HashEntry *hPtr;
    int isNew;
    Blt_Uid classUid;
    register int i;
    char *name;
    char string[200];
    unsigned int length;
    char c;

    c = argv[3][0];
    /* Create the new marker based upon the given type */
    if ((c == 't') && (strcmp(argv[3], "text") == 0)) {
................................................................................
    markerPtr->hashPtr = hPtr;
    markerPtr->linkPtr = 
	Blt_ChainAppend(graphPtr->markers.displayList, markerPtr);
    if (markerPtr->drawUnder) {
	graphPtr->flags |= REDRAW_BACKING_STORE;
    }
    Blt_EventuallyRedrawGraph(graphPtr);
    Tcl_SetResult(interp, name, TCL_VOLATILE);
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * DeleteOp --
................................................................................
 */
/*ARGSUSED*/
static int
DeleteOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Marker *markerPtr;
    register int i;

    for (i = 3; i < argc; i++) {
	if (NameToMarker(graphPtr, argv[i], &markerPtr) == TCL_OK) {
	    DestroyMarker(markerPtr);
	}
    }
    Tcl_ResetResult(interp);
................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char *argv[];
{
    register Marker *markerPtr;

    if ((argv[3][0] == 'c') && (strcmp(argv[3], "current") == 0)) {
	markerPtr = (Marker *)Blt_GetCurrentItem(graphPtr->bindTable);
	/* Report only on markers. */
	if (markerPtr == NULL) {
	    return TCL_OK;
	}
................................................................................
 */
/*ARGSUSED*/
static int
RelinkOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Blt_ChainLink *linkPtr, *placePtr;
    Marker *markerPtr;

    /* Find the marker to be raised or lowered. */
    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
FindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_ChainLink *linkPtr;
    Extents2D exts;
    Marker *markerPtr;
    int mode;
    int left, right, top, bottom;
    int enclosed;
................................................................................
 */
/*ARGSUSED*/
static int
ExistsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_HashEntry *hPtr;

    hPtr = Blt_FindHashEntry(&graphPtr->markers.table, argv[3]);
    Blt_SetBooleanResult(interp, (hPtr != NULL));
    return TCL_OK;
}
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;

    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_SetResult(interp, markerPtr->classUid, TCL_STATIC);
................................................................................

/*ARGSUSED*/
int
Blt_MarkerOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nMarkerOps, markerOps, BLT_OP_ARG2, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;
................................................................................
void
Blt_MarkersToPostScript(graphPtr, psToken, under)
    Graph *graphPtr;
    PsToken psToken;
    int under;
{
    Blt_ChainLink *linkPtr;
    register Marker *markerPtr;

    for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList);
	linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	markerPtr = Blt_ChainGetValue(linkPtr);
	if ((markerPtr->classPtr->postscriptProc == NULL) || 
	    (markerPtr->nWorldPts == 0)) {
	    continue;







|
|
>
>
>
>
>


|
>
>

>







 







|




|
|







 







|





|







 







|
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|





|
|







 







|





|
|







 







|







 







|


|







 







|

|







 







|







 







|







 







|







 







|







 







|







 







|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
....
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
....
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
....
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
....
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
....
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
....
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
....
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
....
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
....
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
....
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
....
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
....
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
....
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
....
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
....
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
....
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
....
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
....
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
....
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
....
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
....
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
....
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
....
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
....
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
....
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
....
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
....
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
....
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
....
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
....
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
#define DEF_MARKER_TEXT_TAGS	"Text all"
#define DEF_MARKER_IMAGE_TAGS	"Image all"
#define DEF_MARKER_BITMAP_TAGS	"Bitmap all"
#define DEF_MARKER_WINDOW_TAGS	"Window all"
#define DEF_MARKER_POLYGON_TAGS	"Polygon all"
#define DEF_MARKER_LINE_TAGS	"Line all"

static int StringToCoordinates _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *CoordinatesToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption coordsOption =
{
    (Tk_OptionParseProc *)StringToCoordinates,
    (Tk_OptionPrintProc *)CoordinatesToString,
    (ClientData)0
};

extern Tk_CustomOption bltColorPairOption;
extern Tk_CustomOption bltDashesOption;
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltListOption;
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltShadowOption;
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ParseCoordinates(interp, markerPtr, nExprs, exprArr)
    Tcl_Interp *interp;
    Marker *markerPtr;
    int nExprs;
    CONST char **exprArr;
{
    int nWorldPts;
    int minArgs, maxArgs;
    Point2D *worldPts;
    int i;
    Point2D *pointPtr;
    double x, y;

    if (nExprs == 0) {
	return TCL_OK;
    }
    if (nExprs & 1) {
	Tcl_AppendResult(interp, "odd number of marker coordinates specified",
................................................................................
 */
/*ARGSUSED*/
static int
StringToCoordinates(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* Tcl list of numeric expressions */
    char *widgRec;		/* Marker record */
    int offset;			/* Not used. */
{
    Marker *markerPtr = (Marker *)widgRec;
    int nExprs;
    CONST char **exprArr;
    int result;

    nExprs = 0;
    if ((string != NULL) &&
	(Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK)) {
	return TCL_ERROR;
    }
................................................................................
    int offset;			/* Not used. */
    Tcl_FreeProc **freeProcPtr;	/* Memory deallocation scheme to use */
{
    Marker *markerPtr = (Marker *)widgRec;
    Tcl_Interp *interp;
    Tcl_DString dString;
    char *result;
    int i;
    Point2D *p;

    if (markerPtr->nWorldPts < 1) {
	return "";
    }
    interp = markerPtr->graphPtr->interp;

    Tcl_DStringInit(&dString);
................................................................................
 */
static double
HMap(graphPtr, axisPtr, x)
    Graph *graphPtr;
    Axis *axisPtr;
    double x;
{
    double norm;

    if (x == DBL_MAX) {
	norm = 1.0;
    } else if (x == -DBL_MAX) {
	norm = 0.0;
    } else {
	if (axisPtr->logScale) {
................................................................................
 */
static double
VMap(graphPtr, axisPtr, y)
    Graph *graphPtr;
    Axis *axisPtr;
    double y;
{
    double norm;

    if (y == DBL_MAX) {
	norm = 1.0;
    } else if (y == -DBL_MAX) {
	norm = 0.0;
    } else {
	if (axisPtr->logScale) {
................................................................................
    }
    return result;		/* Result is screen coordinate. */
}

static Marker *
CreateMarker(graphPtr, name, classUid)
    Graph *graphPtr;
    CONST char *name;
    Blt_Uid classUid;    
{    
    Marker *markerPtr;

    /* Create the new marker based upon the given type */
    if (classUid == bltBitmapMarkerUid) {
	markerPtr = CreateBitmapMarker(); /* bitmap */
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;
    Extents2D exts;
    Graph *graphPtr = markerPtr->graphPtr;
    Point2D anchorPos;
    Point2D corner1, corner2;
    int destWidth, destHeight;
    int srcWidth, srcHeight;
    int i;

    if (bmPtr->srcBitmap == None) {
	return;
    }
    if (bmPtr->destBitmap != None) {
	Tk_FreePixmap(graphPtr->display, bmPtr->destBitmap);
	bmPtr->destBitmap = None;
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;

    if (bmPtr->srcBitmap == None) {
	return 0;
    }
    if (bmPtr->theta != 0.0) {
	Point2D points[MAX_OUTLINE_POINTS];
	int i;

	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < bmPtr->nOutlinePts; i++) {
	    points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x;
................................................................................
    BitmapMarker *bmPtr = (BitmapMarker *)markerPtr;

    if (bmPtr->nWorldPts < 1) {
	return FALSE;
    }
    if (bmPtr->theta != 0.0) {
	Point2D points[MAX_OUTLINE_POINTS];
	int i;
	
	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < bmPtr->nOutlinePts; i++) {
	    points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x;
................................................................................
	(char *)NULL)) {
	if (tmPtr->textPtr != NULL) {
	    Blt_Free(tmPtr->textPtr);
	    tmPtr->textPtr = NULL;
	}
	tmPtr->width = tmPtr->height = 0;
	if (tmPtr->string != NULL) {
	    int i;
	    double rotWidth, rotHeight;

	    tmPtr->textPtr = Blt_GetTextLayout(tmPtr->string, &tmPtr->style);
	    Blt_GetBoundingBox(tmPtr->textPtr->width, tmPtr->textPtr->height, 
	       tmPtr->style.theta, &rotWidth, &rotHeight, tmPtr->outline);
	    tmPtr->width = ROUND(rotWidth);
	    tmPtr->height = ROUND(rotHeight);
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->string == NULL) {
	return 0;
    }
    if (tmPtr->style.theta != 0.0) {
	Point2D points[5];
	int i;

	/* 
	 * Figure out the bounding polygon (isolateral) for the text
	 * and see if the point is inside of it.
	 */

	for (i = 0; i < 5; i++) {
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->nWorldPts < 1) {
	return FALSE;
    }
    if (tmPtr->style.theta != 0.0) {
	Point2D points[5];
	int i;
	
	/*  
	 * Generate the bounding polygon (isolateral) for the bitmap
	 * and see if the point is inside of it.  
	 */
	for (i = 0; i < 4; i++) {
	    points[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x;
................................................................................
    Graph *graphPtr = markerPtr->graphPtr;

    if (tmPtr->string == NULL) {
	return;
    }
    if (tmPtr->fillGC != NULL) {
	XPoint pointArr[4];
	int i;

	/*
	 * Simulate the rotated background of the bitmap by
	 * filling a bounding polygon with the background color.
	 */
	for (i = 0; i < 4; i++) {
	    pointArr[i].x = (short int)
................................................................................
    TextMarker *tmPtr = (TextMarker *)markerPtr;

    if (tmPtr->string == NULL) {
	return;
    }
    if (tmPtr->fillGC != NULL) {
	Point2D polygon[4];
	int i;

	/*
	 * Simulate the rotated background of the bitmap by
	 * filling a bounding polygon with the background color.
	 */
	for (i = 0; i < 4; i++) {
	    polygon[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x;
................................................................................
	    pmPtr->nFillPts = n;
	    pmPtr->fillPts = fillPts;
	    pmPtr->clipped = FALSE;
	}
    }
    if ((pmPtr->outline.fgColor != NULL) && (pmPtr->lineWidth > 0)) { 
	Segment2D *outlinePts;
	Segment2D *segPtr;
	/* 
	 * Generate line segments representing the polygon outline.
	 * The resulting outline may or may not be closed from
	 * viewport clipping.  
	 */
	outlinePts = Blt_Malloc(nScreenPts * sizeof(Segment2D));
	if (outlinePts == NULL) {
................................................................................
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Marker *markerPtr;
    Blt_ChainLink *linkPtr;
    int i;

    Tcl_ResetResult(interp);
    for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList);
	linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	markerPtr = Blt_ChainGetValue(linkPtr);
	if (argc == 3) {
	    Tcl_AppendElement(interp, markerPtr->name);
................................................................................
    }
    return TCL_OK;
}

ClientData
Blt_MakeMarkerTag(graphPtr, tagName)
    Graph *graphPtr;
    CONST char *tagName;
{
    Blt_HashEntry *hPtr;
    int isNew;

    hPtr = Blt_CreateHashEntry(&graphPtr->markers.tagTable, tagName, &isNew);
    assert(hPtr);
    return Blt_GetHashKey(&graphPtr->markers.tagTable, hPtr);
................................................................................
 */
/*ARGSUSED*/
static int
BindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    if (argc == 3) {
	Blt_HashEntry *hPtr;
	Blt_HashSearch cursor;
	char *tag;

	for (hPtr = Blt_FirstHashEntry(&graphPtr->markers.tagTable, &cursor);
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Marker *markerPtr;

    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tk_ConfigureValue(interp, graphPtr->tkwin, 
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Marker *markerPtr;
    int flags = TK_CONFIG_ARGV_ONLY;
    char *oldName;
    int nNames, nOpts;
    CONST char **options;
    int i;
    int under;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
................................................................................
 * ----------------------------------------------------------------------
 */
static int
CreateOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Marker *markerPtr;
    Blt_HashEntry *hPtr;
    int isNew;
    Blt_Uid classUid;
    int i;
    CONST char *name;
    char string[200];
    unsigned int length;
    char c;

    c = argv[3][0];
    /* Create the new marker based upon the given type */
    if ((c == 't') && (strcmp(argv[3], "text") == 0)) {
................................................................................
    markerPtr->hashPtr = hPtr;
    markerPtr->linkPtr = 
	Blt_ChainAppend(graphPtr->markers.displayList, markerPtr);
    if (markerPtr->drawUnder) {
	graphPtr->flags |= REDRAW_BACKING_STORE;
    }
    Blt_EventuallyRedrawGraph(graphPtr);
    Tcl_SetResult(interp, (char *) name, TCL_VOLATILE);
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * DeleteOp --
................................................................................
 */
/*ARGSUSED*/
static int
DeleteOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    Marker *markerPtr;
    int i;

    for (i = 3; i < argc; i++) {
	if (NameToMarker(graphPtr, argv[i], &markerPtr) == TCL_OK) {
	    DestroyMarker(markerPtr);
	}
    }
    Tcl_ResetResult(interp);
................................................................................
 */
/*ARGSUSED*/
static int
GetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char *argv[];
{
    Marker *markerPtr;

    if ((argv[3][0] == 'c') && (strcmp(argv[3], "current") == 0)) {
	markerPtr = (Marker *)Blt_GetCurrentItem(graphPtr->bindTable);
	/* Report only on markers. */
	if (markerPtr == NULL) {
	    return TCL_OK;
	}
................................................................................
 */
/*ARGSUSED*/
static int
RelinkOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    Blt_ChainLink *linkPtr, *placePtr;
    Marker *markerPtr;

    /* Find the marker to be raised or lowered. */
    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
FindOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_ChainLink *linkPtr;
    Extents2D exts;
    Marker *markerPtr;
    int mode;
    int left, right, top, bottom;
    int enclosed;
................................................................................
 */
/*ARGSUSED*/
static int
ExistsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_HashEntry *hPtr;

    hPtr = Blt_FindHashEntry(&graphPtr->markers.table, argv[3]);
    Blt_SetBooleanResult(interp, (hPtr != NULL));
    return TCL_OK;
}
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Marker *markerPtr;

    if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_SetResult(interp, markerPtr->classUid, TCL_STATIC);
................................................................................

/*ARGSUSED*/
int
Blt_MarkerOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nMarkerOps, markerOps, BLT_OP_ARG2, argc, argv,0);
    if (proc == NULL) {
	return TCL_ERROR;
................................................................................
void
Blt_MarkersToPostScript(graphPtr, psToken, under)
    Graph *graphPtr;
    PsToken psToken;
    int under;
{
    Blt_ChainLink *linkPtr;
    Marker *markerPtr;

    for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList);
	linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
	markerPtr = Blt_ChainGetValue(linkPtr);
	if ((markerPtr->classPtr->postscriptProc == NULL) || 
	    (markerPtr->nWorldPts == 0)) {
	    continue;

Changes to jni/blt/src/bltGrMisc.c.

32
33
34
35
36
37
38
39
40
41
42











43
44


45
46

47
48


49
50
51
52
53
54
55
56
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
...
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
....
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
....
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
....
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
....
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
....
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
....
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
....
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
....
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
#if defined(__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif


static Tk_OptionParseProc StringToPoint;
static Tk_OptionPrintProc PointToString;
static Tk_OptionParseProc StringToColorPair;
static Tk_OptionPrintProc ColorPairToString;











Tk_CustomOption bltPointOption =
{


    StringToPoint, PointToString, (ClientData)0
};

Tk_CustomOption bltColorPairOption =
{


    StringToColorPair, ColorPairToString, (ClientData)0
};

/* ----------------------------------------------------------------------
 * Custom option parse and print procedures
 * ----------------------------------------------------------------------
 */

................................................................................
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetXY(interp, tkwin, string, xPtr, yPtr)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    char *string;
    int *xPtr, *yPtr;
{
    char *comma;
    int result;
    int x, y;

    if ((string == NULL) || (*string == '\0')) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToPoint(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* New legend position string */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to XPoint structure */
{
    XPoint *pointPtr = (XPoint *)(widgRec + offset);
    int x, y;

    if (Blt_GetXY(interp, tkwin, string, &x, &y) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToColorPair(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing color */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of color field in record */
{
    ColorPair *pairPtr = (ColorPair *)(widgRec + offset);
    ColorPair sample;
    int allowDefault = (int)clientData;

    sample.fgColor = sample.bgColor = NULL;
    if ((string != NULL) && (*string != '\0')) {
	int nColors;
	char **colors;
	int result;

	if (Tcl_SplitList(interp, string, &nColors, &colors) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch (nColors) {
	case 0:
................................................................................
 *	Convert the color option value into a string.
 *
 * Results:
 *	The static string representing the color option is returned.
 *
 *----------------------------------------------------------------------
 */
static char *
NameOfColor(colorPtr)
    XColor *colorPtr;
{
    if (colorPtr == NULL) {
	return "";
    } else if (colorPtr == COLOR_DEFAULT) {
	return "defcolor";
................................................................................
int
Blt_PointInSegments(samplePtr, segments, nSegments, halo)
    Point2D *samplePtr;
    Segment2D *segments;
    int nSegments;
    double halo;
{
    register Segment2D *segPtr, *endPtr;
    double left, right, top, bottom;
    Point2D p, t;
    double dist, minDist;

    minDist = DBL_MAX;
    for (segPtr = segments, endPtr = segments + nSegments; segPtr < endPtr; 
	 segPtr++) {
................................................................................
int
Blt_PointInPolygon(samplePtr, points, nPoints)
    Point2D *samplePtr;
    Point2D *points;
    int nPoints;
{
    double b;
    register Point2D *p, *q, *endPtr;
    register int count;

    count = 0;
    for (p = points, q = p + 1, endPtr = p + nPoints; q < endPtr; p++, q++) {
	if (((p->y <= samplePtr->y) && (samplePtr->y < q->y)) || 
	    ((q->y <= samplePtr->y) && (samplePtr->y < p->y))) {
	    b = (q->x - p->x) * (samplePtr->y - p->y) / (q->y - p->y) + p->x;
	    if (samplePtr->x < b) {
................................................................................
int
Blt_RegionInPolygon(extsPtr, points, nPoints, enclosed)
    Extents2D *extsPtr;
    Point2D *points;
    int nPoints;
    int enclosed;
{
    register Point2D *pointPtr, *endPtr;

    if (enclosed) {
	/*  
	 * All points of the polygon must be inside the rectangle.
	 */
	for (pointPtr = points, endPtr = points + nPoints; pointPtr < endPtr; 
	     pointPtr++) {
................................................................................
{
    Point2D *endPtr;
    double dx, dy;
    double tin1, tin2;
    double tinx, tiny;
    double xin, yin, xout, yout;
    int count;
    register Point2D *p;	/* First vertex of input polygon edge. */
    register Point2D *q;	/* Last vertex of input polygon edge. */
    register Point2D *r;

    r = clipPts;
    count = 0;			/* Counts # of vertices in output polygon. */

    points[nPoints] = points[0];

    for (p = points, q = p + 1, endPtr = p + nPoints; p < endPtr; p++, q++) {
................................................................................
	offset += (int)fract;
    }
    *offsetPtr = Blt_AdjustViewport(offset, worldSize, windowSize, scrollUnits,
	scrollMode);
    return TCL_OK;
}

#if (TCL_MAJOR_VERSION >= 8)
int
Blt_GetScrollInfoFromObj(interp, objc, objv, offsetPtr, worldSize, windowSize,
    scrollUnits, scrollMode)
    Tcl_Interp *interp;
    int objc;
    Tcl_Obj *CONST *objv;
    int *offsetPtr;
................................................................................
	fract = (double)count *scrollUnits;
	offset += (int)fract;
    }
    *offsetPtr = Blt_AdjustViewport(offset, worldSize, windowSize, scrollUnits,
	scrollMode);
    return TCL_OK;
}
#endif /* TCL_MAJOR_VERSION >= 8 */

/*
 * ----------------------------------------------------------------------
 *
 * Blt_UpdateScrollbar --
 *
 * 	Invoke a Tcl command to the scrollbar, defining the new
................................................................................
    Display *display;
    Drawable drawable;
    unsigned long gcMask;
    XGCValues *valuePtr;
{
    GC newGC;

#ifdef WIN32
    newGC = Blt_EmulateXCreateGC(display, drawable, gcMask, valuePtr);
#else
    newGC = XCreateGC(display, drawable, gcMask, valuePtr);
#endif
    return newGC;
}

................................................................................
Blt_FreePrivateGC(display, gc)
    Display *display;
    GC gc;
{
    XFreeGC(display, gc);
}

#ifndef WIN32
void
Blt_SetDashes(display, gc, dashesPtr)
    Display *display;
    GC gc;
    Blt_Dashes *dashesPtr;
{
    XSetDashes(display, gc, dashesPtr->offset, 
................................................................................
    Point2D points[];
    int i, j;			/* Indices specifying the range of points. */
    int *split;			/* (out) Index of next split. */
{    double maxDist;
    
    maxDist = -1.0;
    if ((i + 1) < j) {
	register int k;
	double a, b, c;	
	double sqDist;

	/* 
	 * 
	 * sqDist P(k) =  |  1  P(i).x  P(i).y  |
	 *		  |  1  P(j).x  P(j).y  |
................................................................................
}

void
Blt_Draw2DSegments(display, drawable, gc, segPtr, nSegments)
    Display *display;
    Drawable drawable;
    GC gc;
    register Segment2D *segPtr;
    int nSegments;
{
    XSegment *xSegPtr, *xSegArr;
    Segment2D *endPtr;

    xSegArr = Blt_Malloc(nSegments * sizeof(XSegment));
    if (xSegArr == NULL) {
................................................................................

	x2 = x + width - 1;
	y2 = y + height - 1;
#define TK_3D_LIGHT2_GC TK_3D_DARK_GC+1
#define TK_3D_DARK2_GC TK_3D_DARK_GC+2
	if (relief == TK_RELIEF_RAISED) {
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#ifdef WIN32
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
	    darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	} else {
#ifdef WIN32
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
	    lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	}
	XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x2, y);
................................................................................
	GC lightGC, darkGC;
	int x2, y2;

	x2 = x + width - 1;
	y2 = y + height - 1;
	if (relief == TK_RELIEF_RAISED) {
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#ifdef WIN32
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
	    darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	} else {
#ifdef WIN32
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
	    lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	}
	XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x2, y);







|
|
|
<
>
>
>
>
>
>
>
>
>
>
>


>
>
|

>


>
>
|







 







|







 







|







 







|










|







 







|







 







|







 







|
|







 







|







 







|
|
|







 







<







 







<







 







|







 







|







 







|







 







|







 







|





|







 







|





|







32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
...
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
....
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
....
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
....
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
....
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
....
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
....
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
....
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
....
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
#if defined(__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif


static int StringToPoint _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *PointToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToColorPair _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *ColorPairToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltPointOption =
{
    (Tk_OptionParseProc *)StringToPoint,
    (Tk_OptionPrintProc *)PointToString,
    (ClientData)0
};

Tk_CustomOption bltColorPairOption =
{
    (Tk_OptionParseProc *)StringToColorPair,
    (Tk_OptionPrintProc *)ColorPairToString,
    (ClientData)0
};

/* ----------------------------------------------------------------------
 * Custom option parse and print procedures
 * ----------------------------------------------------------------------
 */

................................................................................
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetXY(interp, tkwin, string, xPtr, yPtr)
    Tcl_Interp *interp;
    Tk_Window tkwin;
    CONST char *string;
    int *xPtr, *yPtr;
{
    char *comma;
    int result;
    int x, y;

    if ((string == NULL) || (*string == '\0')) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToPoint(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* New legend position string */
    char *widgRec;		/* Widget record */
    int offset;			/* offset to XPoint structure */
{
    XPoint *pointPtr = (XPoint *)(widgRec + offset);
    int x, y;

    if (Blt_GetXY(interp, tkwin, string, &x, &y) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
StringToColorPair(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing color */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of color field in record */
{
    ColorPair *pairPtr = (ColorPair *)(widgRec + offset);
    ColorPair sample;
    int allowDefault = (int)clientData;

    sample.fgColor = sample.bgColor = NULL;
    if ((string != NULL) && (*string != '\0')) {
	int nColors;
	CONST char **colors;
	int result;

	if (Tcl_SplitList(interp, string, &nColors, &colors) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch (nColors) {
	case 0:
................................................................................
 *	Convert the color option value into a string.
 *
 * Results:
 *	The static string representing the color option is returned.
 *
 *----------------------------------------------------------------------
 */
static CONST char *
NameOfColor(colorPtr)
    XColor *colorPtr;
{
    if (colorPtr == NULL) {
	return "";
    } else if (colorPtr == COLOR_DEFAULT) {
	return "defcolor";
................................................................................
int
Blt_PointInSegments(samplePtr, segments, nSegments, halo)
    Point2D *samplePtr;
    Segment2D *segments;
    int nSegments;
    double halo;
{
    Segment2D *segPtr, *endPtr;
    double left, right, top, bottom;
    Point2D p, t;
    double dist, minDist;

    minDist = DBL_MAX;
    for (segPtr = segments, endPtr = segments + nSegments; segPtr < endPtr; 
	 segPtr++) {
................................................................................
int
Blt_PointInPolygon(samplePtr, points, nPoints)
    Point2D *samplePtr;
    Point2D *points;
    int nPoints;
{
    double b;
    Point2D *p, *q, *endPtr;
    int count;

    count = 0;
    for (p = points, q = p + 1, endPtr = p + nPoints; q < endPtr; p++, q++) {
	if (((p->y <= samplePtr->y) && (samplePtr->y < q->y)) || 
	    ((q->y <= samplePtr->y) && (samplePtr->y < p->y))) {
	    b = (q->x - p->x) * (samplePtr->y - p->y) / (q->y - p->y) + p->x;
	    if (samplePtr->x < b) {
................................................................................
int
Blt_RegionInPolygon(extsPtr, points, nPoints, enclosed)
    Extents2D *extsPtr;
    Point2D *points;
    int nPoints;
    int enclosed;
{
    Point2D *pointPtr, *endPtr;

    if (enclosed) {
	/*  
	 * All points of the polygon must be inside the rectangle.
	 */
	for (pointPtr = points, endPtr = points + nPoints; pointPtr < endPtr; 
	     pointPtr++) {
................................................................................
{
    Point2D *endPtr;
    double dx, dy;
    double tin1, tin2;
    double tinx, tiny;
    double xin, yin, xout, yout;
    int count;
    Point2D *p;	/* First vertex of input polygon edge. */
    Point2D *q;	/* Last vertex of input polygon edge. */
    Point2D *r;

    r = clipPts;
    count = 0;			/* Counts # of vertices in output polygon. */

    points[nPoints] = points[0];

    for (p = points, q = p + 1, endPtr = p + nPoints; p < endPtr; p++, q++) {
................................................................................
	offset += (int)fract;
    }
    *offsetPtr = Blt_AdjustViewport(offset, worldSize, windowSize, scrollUnits,
	scrollMode);
    return TCL_OK;
}


int
Blt_GetScrollInfoFromObj(interp, objc, objv, offsetPtr, worldSize, windowSize,
    scrollUnits, scrollMode)
    Tcl_Interp *interp;
    int objc;
    Tcl_Obj *CONST *objv;
    int *offsetPtr;
................................................................................
	fract = (double)count *scrollUnits;
	offset += (int)fract;
    }
    *offsetPtr = Blt_AdjustViewport(offset, worldSize, windowSize, scrollUnits,
	scrollMode);
    return TCL_OK;
}


/*
 * ----------------------------------------------------------------------
 *
 * Blt_UpdateScrollbar --
 *
 * 	Invoke a Tcl command to the scrollbar, defining the new
................................................................................
    Display *display;
    Drawable drawable;
    unsigned long gcMask;
    XGCValues *valuePtr;
{
    GC newGC;

#if defined(WIN32) && !defined(PLATFORM_SDL)
    newGC = Blt_EmulateXCreateGC(display, drawable, gcMask, valuePtr);
#else
    newGC = XCreateGC(display, drawable, gcMask, valuePtr);
#endif
    return newGC;
}

................................................................................
Blt_FreePrivateGC(display, gc)
    Display *display;
    GC gc;
{
    XFreeGC(display, gc);
}

#if !defined(WIN32) || defined(PLATFORM_SDL)
void
Blt_SetDashes(display, gc, dashesPtr)
    Display *display;
    GC gc;
    Blt_Dashes *dashesPtr;
{
    XSetDashes(display, gc, dashesPtr->offset, 
................................................................................
    Point2D points[];
    int i, j;			/* Indices specifying the range of points. */
    int *split;			/* (out) Index of next split. */
{    double maxDist;
    
    maxDist = -1.0;
    if ((i + 1) < j) {
	int k;
	double a, b, c;	
	double sqDist;

	/* 
	 * 
	 * sqDist P(k) =  |  1  P(i).x  P(i).y  |
	 *		  |  1  P(j).x  P(j).y  |
................................................................................
}

void
Blt_Draw2DSegments(display, drawable, gc, segPtr, nSegments)
    Display *display;
    Drawable drawable;
    GC gc;
    Segment2D *segPtr;
    int nSegments;
{
    XSegment *xSegPtr, *xSegArr;
    Segment2D *endPtr;

    xSegArr = Blt_Malloc(nSegments * sizeof(XSegment));
    if (xSegArr == NULL) {
................................................................................

	x2 = x + width - 1;
	y2 = y + height - 1;
#define TK_3D_LIGHT2_GC TK_3D_DARK_GC+1
#define TK_3D_DARK2_GC TK_3D_DARK_GC+2
	if (relief == TK_RELIEF_RAISED) {
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#if defined(WIN32) && !defined(PLATFORM_SDL)
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
	    darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	} else {
#if defined(WIN32) && !defined(PLATFORM_SDL)
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
	    lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	}
	XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x2, y);
................................................................................
	GC lightGC, darkGC;
	int x2, y2;

	x2 = x + width - 1;
	y2 = y + height - 1;
	if (relief == TK_RELIEF_RAISED) {
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#if defined(WIN32) && !defined(PLATFORM_SDL)
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
	    darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	} else {
#if defined(WIN32) && !defined(PLATFORM_SDL)
	    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
	    lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
	    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	}
	XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x2, y);

Changes to jni/blt/src/bltGrPen.c.

24
25
26
27
28
29
30
31
32
33
34











35
36


37
38

39
40


41
42

43
44


45
46

47
48


49
50
51
52
53
54
55
56
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
...
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
...
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
 * out of or in connection with the use or performance of this
 * software.
 */

#include "bltGraph.h"
#include <X11/Xutil.h>

static Tk_OptionParseProc StringToColor;
static Tk_OptionPrintProc ColorToString;
static Tk_OptionParseProc StringToPen;
static Tk_OptionPrintProc PenToString;











Tk_CustomOption bltColorOption =
{


    StringToColor, ColorToString, (ClientData)0
};

Tk_CustomOption bltPenOption =
{


    StringToPen, PenToString, (ClientData)0
};

Tk_CustomOption bltBarPenOption =
{


    StringToPen, PenToString, (ClientData)&bltBarElementUid
};

Tk_CustomOption bltLinePenOption =
{


    StringToPen, PenToString, (ClientData)&bltLineElementUid
};

/*
 *----------------------------------------------------------------------

 * StringToColor --
 *
................................................................................
 */
/*ARGSUSED*/
static int
StringToColor(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing color */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of color field in record */
{
    XColor **colorPtrPtr = (XColor **)(widgRec + offset);
    XColor *colorPtr;
    unsigned int length;
    char c;
................................................................................
    XColor *colorPtr;
{
    if (colorPtr == NULL) {
	return "";
    } else if (colorPtr == COLOR_DEFAULT) {
	return "defcolor";
    } else {
	return Tk_NameOfColor(colorPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ColorToString --
................................................................................
 */
/*ARGSUSED*/
static int
StringToPen(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* String representing pen */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pen field in record */
{
    Blt_Uid classUid = *(Blt_Uid *)clientData; /* Element type. */
    Pen **penPtrPtr = (Pen **)(widgRec + offset);
    Pen *penPtr;
    Graph *graphPtr;
................................................................................
	DestroyPen(graphPtr, penPtr);
    }
}

Pen *
Blt_CreatePen(graphPtr, penName, classUid, nOpts, options)
    Graph *graphPtr;
    char *penName;
    Blt_Uid classUid;
    int nOpts;
    char **options;
{
    
    Pen *penPtr;
    Blt_HashEntry *hPtr;
    unsigned int length, configFlags;
    int isNew;
    register int i;

    /*
     * Scan the option list for a "-type" entry.  This will indicate
     * what type of pen we are creating. Otherwise we'll default to the
     * suggested type.  Last -type option wins.
     */
    for (i = 0; i < nOpts; i += 2) {
	length = strlen(options[i]);
	if ((length > 2) && (strncmp(options[i], "-type", length) == 0)) {
	    char *arg;

	    arg = options[i + 1];
	    if (strcmp(arg, "bar") == 0) {
		classUid = bltBarElementUid;
	    } else if (strcmp(arg, "line") != 0) {
		classUid = bltLineElementUid;
	    } else if (strcmp(arg, "strip") != 0) {
................................................................................
    (*penPtr->configProc) (graphPtr, penPtr);
    return penPtr;
}

int
Blt_GetPen(graphPtr, name, classUid, penPtrPtr)
    Graph *graphPtr;
    char *name;
    Blt_Uid classUid;
    Pen **penPtrPtr;
{
    Pen *penPtr;

    penPtr = NameToPen(graphPtr, name);
    if (penPtr == NULL) {
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;			/* Not used. */
    char *argv[];
{
    Pen *penPtr;
    unsigned int configFlags;

    penPtr = NameToPen(graphPtr, argv[3]);
    if (penPtr == NULL) {
	return TCL_ERROR;
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    char *argv[];
{
    int flags;
    Pen *penPtr;
    int nNames, nOpts;
    int redraw;
    char **options;
    register int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Pen *penPtr;

    penPtr = Blt_CreatePen(graphPtr, argv[3], graphPtr->classUid, argc - 4, 
	argv + 4);
    if (penPtr == NULL) {
	return TCL_ERROR;
................................................................................

/*ARGSUSED*/
static int
DeleteOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Pen *penPtr;
    int i;

    for (i = 3; i < argc; i++) {
	penPtr = NameToPen(graphPtr, argv[i]);
	if (penPtr == NULL) {
................................................................................
 */
/*ARGSUSED*/
static int
NamesOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Blt_HashSearch cursor;
    Pen *penPtr;
    register int i;
    register Blt_HashEntry *hPtr;

    for (hPtr = Blt_FirstHashEntry(&(graphPtr->penTable), &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	penPtr = (Pen *)Blt_GetHashValue(hPtr);
	if (penPtr->flags & PEN_DELETE_PENDING) {
	    continue;
	}
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    char **argv;
{
    Pen *penPtr;

    penPtr = NameToPen(graphPtr, argv[3]);
    if (penPtr == NULL) {
	return TCL_ERROR;
    }
................................................................................
static int nPenOps = sizeof(penOps) / sizeof(Blt_OpSpec);

int
Blt_PenOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nPenOps, penOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (interp, graphPtr, argc, argv);
}







|
|
|
<
>
>
>
>
>
>
>
>
>
>
>


>
>
|

>


>
>
|

>


>
>
|

>


>
>
|







 







|







 







|







 







|







 







|


|

<




|









|







 







|







 







|







 







|





|
|







 







|







 







|







 







|



|
|







 







|







 







|









24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
...
300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
...
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
...
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
...
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
 * out of or in connection with the use or performance of this
 * software.
 */

#include "bltGraph.h"
#include <X11/Xutil.h>

static int StringToColor _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));


static char *ColorToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToPen _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *PenToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

Tk_CustomOption bltColorOption =
{
    (Tk_OptionParseProc *)StringToColor,
    (Tk_OptionPrintProc *)ColorToString,
    (ClientData)0
};

Tk_CustomOption bltPenOption =
{
    (Tk_OptionParseProc *)StringToPen,
    (Tk_OptionPrintProc *)PenToString,
    (ClientData)0
};

Tk_CustomOption bltBarPenOption =
{
    (Tk_OptionParseProc *)StringToPen,
    (Tk_OptionPrintProc *)PenToString,
    (ClientData)&bltBarElementUid
};

Tk_CustomOption bltLinePenOption =
{
    (Tk_OptionParseProc *)StringToPen,
    (Tk_OptionPrintProc *)PenToString,
    (ClientData)&bltLineElementUid
};

/*
 *----------------------------------------------------------------------

 * StringToColor --
 *
................................................................................
 */
/*ARGSUSED*/
static int
StringToColor(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing color */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of color field in record */
{
    XColor **colorPtrPtr = (XColor **)(widgRec + offset);
    XColor *colorPtr;
    unsigned int length;
    char c;
................................................................................
    XColor *colorPtr;
{
    if (colorPtr == NULL) {
	return "";
    } else if (colorPtr == COLOR_DEFAULT) {
	return "defcolor";
    } else {
	return (char *) Tk_NameOfColor(colorPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ColorToString --
................................................................................
 */
/*ARGSUSED*/
static int
StringToPen(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* String representing pen */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of pen field in record */
{
    Blt_Uid classUid = *(Blt_Uid *)clientData; /* Element type. */
    Pen **penPtrPtr = (Pen **)(widgRec + offset);
    Pen *penPtr;
    Graph *graphPtr;
................................................................................
	DestroyPen(graphPtr, penPtr);
    }
}

Pen *
Blt_CreatePen(graphPtr, penName, classUid, nOpts, options)
    Graph *graphPtr;
    CONST char *penName;
    Blt_Uid classUid;
    int nOpts;
    CONST char **options;
{

    Pen *penPtr;
    Blt_HashEntry *hPtr;
    unsigned int length, configFlags;
    int isNew;
    int i;

    /*
     * Scan the option list for a "-type" entry.  This will indicate
     * what type of pen we are creating. Otherwise we'll default to the
     * suggested type.  Last -type option wins.
     */
    for (i = 0; i < nOpts; i += 2) {
	length = strlen(options[i]);
	if ((length > 2) && (strncmp(options[i], "-type", length) == 0)) {
	    CONST char *arg;

	    arg = options[i + 1];
	    if (strcmp(arg, "bar") == 0) {
		classUid = bltBarElementUid;
	    } else if (strcmp(arg, "line") != 0) {
		classUid = bltLineElementUid;
	    } else if (strcmp(arg, "strip") != 0) {
................................................................................
    (*penPtr->configProc) (graphPtr, penPtr);
    return penPtr;
}

int
Blt_GetPen(graphPtr, name, classUid, penPtrPtr)
    Graph *graphPtr;
    CONST char *name;
    Blt_Uid classUid;
    Pen **penPtrPtr;
{
    Pen *penPtr;

    penPtr = NameToPen(graphPtr, name);
    if (penPtr == NULL) {
................................................................................
 */
/* ARGSUSED */
static int
CgetOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;			/* Not used. */
    CONST char *argv[];
{
    Pen *penPtr;
    unsigned int configFlags;

    penPtr = NameToPen(graphPtr, argv[3]);
    if (penPtr == NULL) {
	return TCL_ERROR;
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    CONST char *argv[];
{
    int flags;
    Pen *penPtr;
    int nNames, nOpts;
    int redraw;
    CONST char **options;
    int i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-') {
	    break;
................................................................................
 *----------------------------------------------------------------------
 */
static int
CreateOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Pen *penPtr;

    penPtr = Blt_CreatePen(graphPtr, argv[3], graphPtr->classUid, argc - 4, 
	argv + 4);
    if (penPtr == NULL) {
	return TCL_ERROR;
................................................................................

/*ARGSUSED*/
static int
DeleteOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Pen *penPtr;
    int i;

    for (i = 3; i < argc; i++) {
	penPtr = NameToPen(graphPtr, argv[i]);
	if (penPtr == NULL) {
................................................................................
 */
/*ARGSUSED*/
static int
NamesOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Blt_HashSearch cursor;
    Pen *penPtr;
    int i;
    Blt_HashEntry *hPtr;

    for (hPtr = Blt_FirstHashEntry(&(graphPtr->penTable), &cursor);
	hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
	penPtr = (Pen *)Blt_GetHashValue(hPtr);
	if (penPtr->flags & PEN_DELETE_PENDING) {
	    continue;
	}
................................................................................
 */
/*ARGSUSED*/
static int
TypeOp(interp, graphPtr, argc, argv)
    Tcl_Interp *interp;
    Graph *graphPtr;
    int argc;
    CONST char **argv;
{
    Pen *penPtr;

    penPtr = NameToPen(graphPtr, argv[3]);
    if (penPtr == NULL) {
	return TCL_ERROR;
    }
................................................................................
static int nPenOps = sizeof(penOps) / sizeof(Blt_OpSpec);

int
Blt_PenOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;

    proc = Blt_GetOp(interp, nPenOps, penOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    return (*proc) (interp, graphPtr, argc, argv);
}

Changes to jni/blt/src/bltGrPs.c.

29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49





50
51


52
53
54
55








56
57


58
59

60
61
62
63
64
65
66
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
...
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
...
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
...
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
....
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
....
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
....
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
....
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
/*
 * -----------------------------------------------------------------
 *
 * PostScript routines to print a graph
 *
 * -----------------------------------------------------------------
 */

#include "bltGraph.h"
#include <X11/Xutil.h>
#if defined(__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif

#define PS_PREVIEW_EPSI	0
#define PS_PREVIEW_WMF	1
#define PS_PREVIEW_TIFF	2

static Tk_OptionParseProc StringToColorMode;
static Tk_OptionPrintProc ColorModeToString;





static Tk_CustomOption colorModeOption =
{


    StringToColorMode, ColorModeToString, (ClientData)0,
};
static Tk_OptionParseProc StringToFormat;
static Tk_OptionPrintProc FormatToString;








static Tk_CustomOption formatOption =
{


    StringToFormat, FormatToString, (ClientData)0,
};

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltPadOption;

#define DEF_PS_CENTER		"yes"
#define DEF_PS_COLOR_MAP	(char *)NULL
#define DEF_PS_COLOR_MODE	"color"
................................................................................
 */
/*ARGSUSED*/
static int
StringToColorMode(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* New value. */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of field in record */
{
    PsColorMode *modePtr = (PsColorMode *) (widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
static int
StringToFormat(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    char *string;		/* New value. */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of field in record */
{
    int *formatPtr = (int *) (widgRec + offset);
    unsigned int length;
    char c;

    c = string[0];
    length = strlen(string);
    if ((c == 'c') && (strncmp(string, "epsi", length) == 0)) {
	*formatPtr = PS_PREVIEW_EPSI;
#ifdef WIN32
#ifdef HAVE_TIFF_H
    } else if ((c == 't') && (strncmp(string, "tiff", length) == 0)) {
	*formatPtr = PS_PREVIEW_TIFF;
#endif /* HAVE_TIFF_H */
    } else if ((c == 'w') && (strncmp(string, "wmf", length) == 0)) {
	*formatPtr = PS_PREVIEW_WMF;
#endif /* WIN32 */
    } else {
	Tcl_AppendResult(interp, "bad format \"", string, "\": should be ",
#ifdef WIN32
#ifdef HAVE_TIFF_H
			 "\"tiff\" or ",
#endif /* HAVE_TIFF_H */
			 "\"wmf\" or ",
#endif /* WIN32 */
			 "\"epsi\"", (char *)NULL);
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char *argv[];
{
    PostScript *psPtr = (PostScript *)graphPtr->postscript;

    if (Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs, (char *)psPtr,
	    argv[3], 0) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Number of options in argv vector */
    char **argv;		/* Option vector */
{
    int flags = TK_CONFIG_ARGV_ONLY;
    PostScript *psPtr = (PostScript *)graphPtr->postscript;

    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
		(char *)psPtr, (char *)NULL, flags);
................................................................................
    Blt_AxesToPostScript(graphPtr, psToken);
}


static int
GraphToPostScript(graphPtr, ident, psToken)
    Graph *graphPtr;
    char *ident;		/* Identifier string (usually the filename) */
    PsToken psToken;
{
    int x, y, width, height;
    int result;

    /*   
     * We need to know how big a graph to print.  If the graph hasn't
................................................................................
    Blt_ActiveElementsToPostScript(graphPtr, psToken);
    Blt_AppendToPostScript(psToken, "\n",
	"% Unset clipping\n",
	"grestore\n\n", (char *)NULL);
    MarginsToPostScript(graphPtr, psToken);
    Blt_AppendToPostScript(psToken,
	"showpage\n",
	"%Trailer\n",
	"grestore\n",
	"end\n",
	"%EOF\n", (char *)NULL);
  error:
    /* Reset height and width of graph window */
    graphPtr->width = Tk_Width(graphPtr->tkwin);
    graphPtr->height = Tk_Height(graphPtr->tkwin);
    graphPtr->flags = MAP_WORLD;

    /*
................................................................................
     * Redraw the graph in order to re-calculate the layout as soon as
     * possible. This is in the case the crosshairs are active.
     */
    Blt_EventuallyRedrawGraph(graphPtr);
    return result;
}

#ifdef WIN32

static void
InitAPMHeader(
    Tk_Window tkwin,
    int width, int height,
    APMHEADER *headerPtr)
{
................................................................................
 *----------------------------------------------------------------------
 */
static int
OutputOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Number of options in argv vector */
    char **argv;		/* Option vector */
{
    PostScript *psPtr = (PostScript *)graphPtr->postscript;
    Tcl_Channel chan = NULL;
    PsToken psToken;
    char *fileName;		/* Name of file to write PostScript output
                                 * If NULL, output is returned via
                                 * interp->result. */

    fileName = NULL;
    if (argc > 3) {
	if (argv[3][0] != '-') {
	    fileName = argv[3];	/* First argument is the file name. */
................................................................................
    /*
     * If a file name was given, write the results to that file
     */
    if (chan != NULL) {
	char *buffer = Blt_PostScriptFromToken(psToken);
	int wrote, length = strlen(buffer);

#ifdef WIN32
	if ((psPtr->addPreview) && (psPtr->previewFormat != PS_PREVIEW_EPSI)) {
	    if (CreateWindowsEPS(graphPtr, psToken, chan)) {
		return TCL_ERROR;
	    }
	} else
#endif
	{
................................................................................
    assert(psPtr);
    psPtr->colorMode = PS_MODE_COLOR;
    psPtr->center = TRUE;
    psPtr->decorations = TRUE;
    graphPtr->postscript = psPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "postscript", "Postscript", configSpecs, 0, (char **)NULL,
	    (char *)psPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
................................................................................
static int nPsOps = sizeof(psOps) / sizeof(Blt_OpSpec);

int
Blt_PostScriptOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* # arguments */
    char **argv;		/* Argument list */
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nPsOps, psOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    result = (*proc) (graphPtr, interp, argc, argv);
    return result;
}








>












|
|
>
>
>
>
>


>
>
|

<
<
>
>
>
>
>
>
>
>


>
>
|

>







 







|







 







|











|









|







 







|







 







|







 







|







 







|


|







 







|







 







|




|







 







|







 







|







 







|












29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
...
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
...
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
...
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
....
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
....
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
....
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
....
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
/*
 * -----------------------------------------------------------------
 *
 * PostScript routines to print a graph
 *
 * -----------------------------------------------------------------
 */
#include "bltInt.h"
#include "bltGraph.h"
#include <X11/Xutil.h>
#if defined(__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif

#define PS_PREVIEW_EPSI	0
#define PS_PREVIEW_WMF	1
#define PS_PREVIEW_TIFF	2

static int StringToColorMode _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *ColorModeToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption colorModeOption =
{
    (Tk_OptionParseProc *)StringToColorMode,
    (Tk_OptionPrintProc *)ColorModeToString,
    (ClientData)0,
};



static int StringToFormat _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec,
    int offset));

static char *FormatToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static Tk_CustomOption formatOption =
{
    (Tk_OptionParseProc *)StringToFormat,
    (Tk_OptionPrintProc *)FormatToString,
    (ClientData)0,
};

extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltPadOption;

#define DEF_PS_CENTER		"yes"
#define DEF_PS_COLOR_MAP	(char *)NULL
#define DEF_PS_COLOR_MODE	"color"
................................................................................
 */
/*ARGSUSED*/
static int
StringToColorMode(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* New value. */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of field in record */
{
    PsColorMode *modePtr = (PsColorMode *) (widgRec + offset);
    unsigned int length;
    char c;

................................................................................
 */
/*ARGSUSED*/
static int
StringToFormat(clientData, interp, tkwin, string, widgRec, offset)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Not used. */
    CONST char *string;		/* New value. */
    char *widgRec;		/* Widget record */
    int offset;			/* Offset of field in record */
{
    int *formatPtr = (int *) (widgRec + offset);
    unsigned int length;
    char c;

    c = string[0];
    length = strlen(string);
    if ((c == 'c') && (strncmp(string, "epsi", length) == 0)) {
	*formatPtr = PS_PREVIEW_EPSI;
#if defined(WIN32) && !defined(PLATFORM_SDL)
#ifdef HAVE_TIFF_H
    } else if ((c == 't') && (strncmp(string, "tiff", length) == 0)) {
	*formatPtr = PS_PREVIEW_TIFF;
#endif /* HAVE_TIFF_H */
    } else if ((c == 'w') && (strncmp(string, "wmf", length) == 0)) {
	*formatPtr = PS_PREVIEW_WMF;
#endif /* WIN32 */
    } else {
	Tcl_AppendResult(interp, "bad format \"", string, "\": should be ",
#if defined(WIN32) && !defined(PLATFORM_SDL)
#ifdef HAVE_TIFF_H
			 "\"tiff\" or ",
#endif /* HAVE_TIFF_H */
			 "\"wmf\" or ",
#endif /* WIN32 */
			 "\"epsi\"", (char *)NULL);
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char *argv[];
{
    PostScript *psPtr = (PostScript *)graphPtr->postscript;

    if (Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs, (char *)psPtr,
	    argv[3], 0) != TCL_OK) {
	return TCL_ERROR;
    }
................................................................................
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Number of options in argv vector */
    CONST char **argv;		/* Option vector */
{
    int flags = TK_CONFIG_ARGV_ONLY;
    PostScript *psPtr = (PostScript *)graphPtr->postscript;

    if (argc == 3) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
		(char *)psPtr, (char *)NULL, flags);
................................................................................
    Blt_AxesToPostScript(graphPtr, psToken);
}


static int
GraphToPostScript(graphPtr, ident, psToken)
    Graph *graphPtr;
    CONST char *ident;		/* Identifier string (usually the filename) */
    PsToken psToken;
{
    int x, y, width, height;
    int result;

    /*   
     * We need to know how big a graph to print.  If the graph hasn't
................................................................................
    Blt_ActiveElementsToPostScript(graphPtr, psToken);
    Blt_AppendToPostScript(psToken, "\n",
	"% Unset clipping\n",
	"grestore\n\n", (char *)NULL);
    MarginsToPostScript(graphPtr, psToken);
    Blt_AppendToPostScript(psToken,
	"showpage\n",
	"%%Trailer\n",
	"grestore\n",
	"end\n",
	"%%EOF\n", (char *)NULL);
  error:
    /* Reset height and width of graph window */
    graphPtr->width = Tk_Width(graphPtr->tkwin);
    graphPtr->height = Tk_Height(graphPtr->tkwin);
    graphPtr->flags = MAP_WORLD;

    /*
................................................................................
     * Redraw the graph in order to re-calculate the layout as soon as
     * possible. This is in the case the crosshairs are active.
     */
    Blt_EventuallyRedrawGraph(graphPtr);
    return result;
}

#if defined(WIN32) && !defined(PLATFORM_SDL)

static void
InitAPMHeader(
    Tk_Window tkwin,
    int width, int height,
    APMHEADER *headerPtr)
{
................................................................................
 *----------------------------------------------------------------------
 */
static int
OutputOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Number of options in argv vector */
    CONST char **argv;		/* Option vector */
{
    PostScript *psPtr = (PostScript *)graphPtr->postscript;
    Tcl_Channel chan = NULL;
    PsToken psToken;
    CONST char *fileName;	/* Name of file to write PostScript output
                                 * If NULL, output is returned via
                                 * interp->result. */

    fileName = NULL;
    if (argc > 3) {
	if (argv[3][0] != '-') {
	    fileName = argv[3];	/* First argument is the file name. */
................................................................................
    /*
     * If a file name was given, write the results to that file
     */
    if (chan != NULL) {
	char *buffer = Blt_PostScriptFromToken(psToken);
	int wrote, length = strlen(buffer);

#if defined(WIN32) && !defined(PLATFORM_SDL)
	if ((psPtr->addPreview) && (psPtr->previewFormat != PS_PREVIEW_EPSI)) {
	    if (CreateWindowsEPS(graphPtr, psToken, chan)) {
		return TCL_ERROR;
	    }
	} else
#endif
	{
................................................................................
    assert(psPtr);
    psPtr->colorMode = PS_MODE_COLOR;
    psPtr->center = TRUE;
    psPtr->decorations = TRUE;
    graphPtr->postscript = psPtr;

    if (Blt_ConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
	    "postscript", "Postscript", configSpecs, 0, NULL,
	    (char *)psPtr, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
................................................................................
static int nPsOps = sizeof(psOps) / sizeof(Blt_OpSpec);

int
Blt_PostScriptOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* # arguments */
    CONST char **argv;		/* Argument list */
{
    Blt_Op proc;
    int result;

    proc = Blt_GetOp(interp, nPsOps, psOps, BLT_OP_ARG2, argc, argv, 0);
    if (proc == NULL) {
	return TCL_ERROR;
    }
    result = (*proc) (graphPtr, interp, argc, argv);
    return result;
}

Changes to jni/blt/src/bltGraph.c.

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
...
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
...
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
....
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
....
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
....
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
....
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
....
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
....
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
....
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
....
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
....
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
....
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
....
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
....
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
....
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
....
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
....
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
....
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
static Blt_SwitchParseProc StringToFormat;
static Blt_SwitchCustom formatSwitch =
{
    StringToFormat, (Blt_SwitchFreeProc *)NULL, (ClientData)0,
};

typedef struct {
    char *name;
    int width, height;
    int format;
} SnapData;

enum SnapFormats { FORMAT_PHOTO, FORMAT_EMF, FORMAT_WMF };

static Blt_SwitchSpec snapSwitches[] = 
................................................................................
 *	redisplayed.
 *
 *--------------------------------------------------------------
 */
static void
GraphEventProc(clientData, eventPtr)
    ClientData clientData;	/* Graph widget record */
    register XEvent *eventPtr;	/* Event which triggered call to routine */
{
    Graph *graphPtr = clientData;

    if (eventPtr->type == Expose) {
	if (eventPtr->xexpose.count == 0) {
	    graphPtr->flags |= REDRAW_WORLD;
	    Blt_EventuallyRedrawGraph(graphPtr);
................................................................................

static int
InitPens(graphPtr)
    Graph *graphPtr;
{
    Blt_InitHashTable(&graphPtr->penTable, BLT_STRING_KEYS);
    if (Blt_CreatePen(graphPtr, "activeLine", bltLineElementUid, 0, 
	      (char **)NULL) == NULL) {
  	return TCL_ERROR;
    }
    if (Blt_CreatePen(graphPtr, "activeBar", bltBarElementUid, 0, 
	      (char **)NULL) == NULL) {
  	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
................................................................................
    }
    /*
     * Always add the name of the object to the tag array.
     */
    Blt_ListAppend(list, (*tagProc) (graphPtr, elemPtr->name), 0);
    Blt_ListAppend(list, (*tagProc) (graphPtr, elemPtr->classUid), 0);
    if (elemPtr->tags != NULL) {
	register char **p;

	for (p = elemPtr->tags; *p != NULL; p++) {
	    Blt_ListAppend(list, (*tagProc) (graphPtr, *p), 0);
	}
    }
}

................................................................................
 *----------------------------------------------------------------------
 */

static Graph *
CreateGraph(interp, argc, argv, classUid)
    Tcl_Interp *interp;
    int argc;
    char **argv;
    Blt_Uid classUid;
{
    Graph *graphPtr;
    Tk_Window tkwin;

    tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1], 
	    (char *)NULL);
................................................................................

/*ARGSUSED*/
static int
XAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_LEFT : MARGIN_BOTTOM;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
X2AxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_RIGHT : MARGIN_TOP;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
YAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_BOTTOM : MARGIN_LEFT;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
Y2AxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_TOP : MARGIN_RIGHT;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
BarOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, bltBarElementUid);
}

/*ARGSUSED*/
static int
LineOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, bltLineElementUid);
}

/*ARGSUSED*/
static int
ElementOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, graphPtr->classUid);
}

static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    int flags;

    flags = TK_CONFIG_ARGV_ONLY;
    if (argc == 2) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)graphPtr, (char *)NULL, flags);
................................................................................

/* ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	(char *)graphPtr, argv[2], 0);
}

/*
 *--------------------------------------------------------------
................................................................................
 */
/* ARGSUSED*/
static int
ExtentsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    char c;
    unsigned int length;
    char string[200];

    c = argv[2][0];
    length = strlen(argv[2]);
................................................................................
 */
/* ARGSUSED*/
static int
InsideOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    int x, y;
    Extents2D exts;
    int result;

    if (Tk_GetPixels(interp, graphPtr->tkwin, argv[2], &x) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
InvtransformOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    double x, y;
    Point2D point;
    Axis2D axes;

    if (Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK ||
	Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
TransformOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    double x, y;
    Point2D point;
    Axis2D axes;

    if ((Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK) ||
	(Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK)) {
................................................................................
 */
/*ARGSUSED*/
static int
Print1Op(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    int noBackingStore = 0;
    BITMAPINFO info;
    void *data;
    TkWinDCState state;
    TkWinBitmap bd;
    DIBSECTION ds;
................................................................................
 */
/*ARGSUSED*/
static int
Print2Op(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    Drawable drawable;
    int noBackingStore = 0;
    int result;

    graphPtr->width = Tk_Width(graphPtr->tkwin);
    graphPtr->height = Tk_Height(graphPtr->tkwin);
................................................................................
{
    int *formatPtr = (int *)(record + offset);
    char c;

    c = string[0];
    if ((c == 'p') && (strcmp(string, "photo") == 0)) {
	*formatPtr = FORMAT_PHOTO;
#ifdef WIN32
    } else if ((c == 'e') && (strcmp(string, "emf") == 0)) {
	*formatPtr = FORMAT_EMF;
    } else if ((c == 'w') && (strcmp(string, "wmf") == 0)) {
	*formatPtr = FORMAT_WMF;
#endif /* WIN32 */
    } else {
#ifdef WIN32
	Tcl_AppendResult(interp, "bad format \"", string, 
		 "\": should be photo, emf, or wmf.", (char *)NULL);
#else
	Tcl_AppendResult(interp, "bad format \"", string, 
		 "\": should be photo.", (char *)NULL);
#endif /* WIN32 */
	return TCL_ERROR;
    }
    return TCL_OK;
}

#ifdef WIN32
static int InitMetaFileHeader(
    Tk_Window tkwin,
    int width, int height,
    APMHEADER *mfhPtr)
{
    unsigned int *p;
    unsigned int sum;
................................................................................
 */
/*ARGSUSED*/
static int
SnapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    int result;
    Pixmap drawable;
    int noBackingStore = 0;
    register int i;
    SnapData data;

    /* .g snap ?switches? name */
    data.height = Tk_Height(graphPtr->tkwin);
    data.width = Tk_Width(graphPtr->tkwin);
    data.format = FORMAT_PHOTO;
    /* Process switches  */
................................................................................
	assert(drawable != None);
#endif
	graphPtr->flags |= RESET_WORLD;
	Blt_DrawGraph(graphPtr, drawable, noBackingStore);
	result = Blt_SnapPhoto(interp, graphPtr->tkwin, drawable, 0, 0, 
	    data.width, data.height, data.width, data.height, data.name, 1.0);
	Tk_FreePixmap(graphPtr->display, drawable);
#ifdef WIN32
    } else if ((data.format == FORMAT_WMF) || (data.format == FORMAT_EMF)) {
	TkWinDC drawableDC;
	TkWinDCState state;
	HDC hRefDC, hDC;
	HENHMETAFILE hMetaFile;
	Tcl_DString dString;
	char *title;
................................................................................
static int nGraphOps = sizeof(graphOps) / sizeof(Blt_OpSpec);

int
Blt_GraphInstCmdProc(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Blt_Op proc;
    int result;
    Graph *graphPtr = clientData;

    proc = Blt_GetOp(interp, nGraphOps, graphOps, BLT_OP_ARG1, argc, argv, 0);
    if (proc == NULL) {
................................................................................
 *
 * --------------------------------------------------------------------------
 */
static int
NewGraph(interp, argc, argv, classUid)
    Tcl_Interp *interp;
    int argc;
    char **argv;
    Blt_Uid classUid;
{
    Graph *graphPtr;

    if (argc < 2) {
	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
	    " pathName ?option value?...\"", (char *)NULL);
................................................................................
 */
/*ARGSUSED*/
static int
GraphCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    return NewGraph(interp, argc, argv, bltLineElementUid);
}

/*
 *--------------------------------------------------------------
 *
................................................................................
 */
/*ARGSUSED*/
static int
BarchartCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    return NewGraph(interp, argc, argv, bltBarElementUid);
}

/*
 *--------------------------------------------------------------
 *
................................................................................
 */
/*ARGSUSED*/
static int
StripchartCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    return NewGraph(interp, argc, argv, bltStripElementUid);
}

/*
 * -----------------------------------------------------------------------
 *
................................................................................

static void
UpdateMarginTraces(graphPtr)
    Graph *graphPtr;
{
    Margin *marginPtr;
    int size;
    register int i;

    for (i = 0; i < 4; i++) {
	marginPtr = graphPtr->margins + i;
	if (marginPtr->varName != NULL) {	/* Trigger variable traces */
	    if ((marginPtr->site == MARGIN_LEFT) || 
		(marginPtr->site == MARGIN_RIGHT)) {
		size = marginPtr->width;







|







 







|







 







|



|







 







|







 







|







 







|













|













|













|













|










|










|









|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|






|











|







 







|




|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
...
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
...
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
....
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
....
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
....
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
....
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
....
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
....
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
....
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
....
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
....
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
....
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
....
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
....
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
....
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
....
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
....
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
....
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
static Blt_SwitchParseProc StringToFormat;
static Blt_SwitchCustom formatSwitch =
{
    StringToFormat, (Blt_SwitchFreeProc *)NULL, (ClientData)0,
};

typedef struct {
    CONST char *name;
    int width, height;
    int format;
} SnapData;

enum SnapFormats { FORMAT_PHOTO, FORMAT_EMF, FORMAT_WMF };

static Blt_SwitchSpec snapSwitches[] = 
................................................................................
 *	redisplayed.
 *
 *--------------------------------------------------------------
 */
static void
GraphEventProc(clientData, eventPtr)
    ClientData clientData;	/* Graph widget record */
    XEvent *eventPtr;	/* Event which triggered call to routine */
{
    Graph *graphPtr = clientData;

    if (eventPtr->type == Expose) {
	if (eventPtr->xexpose.count == 0) {
	    graphPtr->flags |= REDRAW_WORLD;
	    Blt_EventuallyRedrawGraph(graphPtr);
................................................................................

static int
InitPens(graphPtr)
    Graph *graphPtr;
{
    Blt_InitHashTable(&graphPtr->penTable, BLT_STRING_KEYS);
    if (Blt_CreatePen(graphPtr, "activeLine", bltLineElementUid, 0, 
	      NULL) == NULL) {
  	return TCL_ERROR;
    }
    if (Blt_CreatePen(graphPtr, "activeBar", bltBarElementUid, 0, 
	      NULL) == NULL) {
  	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
................................................................................
    }
    /*
     * Always add the name of the object to the tag array.
     */
    Blt_ListAppend(list, (*tagProc) (graphPtr, elemPtr->name), 0);
    Blt_ListAppend(list, (*tagProc) (graphPtr, elemPtr->classUid), 0);
    if (elemPtr->tags != NULL) {
	char **p;

	for (p = elemPtr->tags; *p != NULL; p++) {
	    Blt_ListAppend(list, (*tagProc) (graphPtr, *p), 0);
	}
    }
}

................................................................................
 *----------------------------------------------------------------------
 */

static Graph *
CreateGraph(interp, argc, argv, classUid)
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
    Blt_Uid classUid;
{
    Graph *graphPtr;
    Tk_Window tkwin;

    tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1], 
	    (char *)NULL);
................................................................................

/*ARGSUSED*/
static int
XAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_LEFT : MARGIN_BOTTOM;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
X2AxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_RIGHT : MARGIN_TOP;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
YAxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_BOTTOM : MARGIN_LEFT;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
Y2AxisOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    int margin;

    margin = (graphPtr->inverted) ? MARGIN_TOP : MARGIN_RIGHT;
    return Blt_AxisOp(graphPtr, margin, argc, argv);
}

/*ARGSUSED*/
static int
BarOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, bltBarElementUid);
}

/*ARGSUSED*/
static int
LineOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, bltLineElementUid);
}

/*ARGSUSED*/
static int
ElementOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    CONST char **argv;
{
    return Blt_ElementOp(graphPtr, interp, argc, argv, graphPtr->classUid);
}

static int
ConfigureOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    int flags;

    flags = TK_CONFIG_ARGV_ONLY;
    if (argc == 2) {
	return Tk_ConfigureInfo(interp, graphPtr->tkwin, configSpecs,
	    (char *)graphPtr, (char *)NULL, flags);
................................................................................

/* ARGSUSED*/
static int
CgetOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    return Tk_ConfigureValue(interp, graphPtr->tkwin, configSpecs,
	(char *)graphPtr, argv[2], 0);
}

/*
 *--------------------------------------------------------------
................................................................................
 */
/* ARGSUSED*/
static int
ExtentsOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    char c;
    unsigned int length;
    char string[200];

    c = argv[2][0];
    length = strlen(argv[2]);
................................................................................
 */
/* ARGSUSED*/
static int
InsideOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    int x, y;
    Extents2D exts;
    int result;

    if (Tk_GetPixels(interp, graphPtr->tkwin, argv[2], &x) != TCL_OK) {
	return TCL_ERROR;
................................................................................
 */
/*ARGSUSED*/
static int
InvtransformOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    double x, y;
    Point2D point;
    Axis2D axes;

    if (Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK ||
	Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK) {
................................................................................
 */
/*ARGSUSED*/
static int
TransformOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    double x, y;
    Point2D point;
    Axis2D axes;

    if ((Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK) ||
	(Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK)) {
................................................................................
 */
/*ARGSUSED*/
static int
Print1Op(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    int noBackingStore = 0;
    BITMAPINFO info;
    void *data;
    TkWinDCState state;
    TkWinBitmap bd;
    DIBSECTION ds;
................................................................................
 */
/*ARGSUSED*/
static int
Print2Op(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    Drawable drawable;
    int noBackingStore = 0;
    int result;

    graphPtr->width = Tk_Width(graphPtr->tkwin);
    graphPtr->height = Tk_Height(graphPtr->tkwin);
................................................................................
{
    int *formatPtr = (int *)(record + offset);
    char c;

    c = string[0];
    if ((c == 'p') && (strcmp(string, "photo") == 0)) {
	*formatPtr = FORMAT_PHOTO;
#if defined(WIN32) && !defined(PLATFORM_SDL)
    } else if ((c == 'e') && (strcmp(string, "emf") == 0)) {
	*formatPtr = FORMAT_EMF;
    } else if ((c == 'w') && (strcmp(string, "wmf") == 0)) {
	*formatPtr = FORMAT_WMF;
#endif /* WIN32 */
    } else {
#if defined(WIN32) && !defined(PLATFORM_SDL)
	Tcl_AppendResult(interp, "bad format \"", string, 
		 "\": should be photo, emf, or wmf.", (char *)NULL);
#else
	Tcl_AppendResult(interp, "bad format \"", string, 
		 "\": should be photo.", (char *)NULL);
#endif /* WIN32 */
	return TCL_ERROR;
    }
    return TCL_OK;
}

#if defined(WIN32) && !defined(PLATFORM_SDL)
static int InitMetaFileHeader(
    Tk_Window tkwin,
    int width, int height,
    APMHEADER *mfhPtr)
{
    unsigned int *p;
    unsigned int sum;
................................................................................
 */
/*ARGSUSED*/
static int
SnapOp(graphPtr, interp, argc, argv)
    Graph *graphPtr;		/* Graph widget record */
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    CONST char **argv;
{
    int result;
    Pixmap drawable;
    int noBackingStore = 0;
    int i;
    SnapData data;

    /* .g snap ?switches? name */
    data.height = Tk_Height(graphPtr->tkwin);
    data.width = Tk_Width(graphPtr->tkwin);
    data.format = FORMAT_PHOTO;
    /* Process switches  */
................................................................................
	assert(drawable != None);
#endif
	graphPtr->flags |= RESET_WORLD;
	Blt_DrawGraph(graphPtr, drawable, noBackingStore);
	result = Blt_SnapPhoto(interp, graphPtr->tkwin, drawable, 0, 0, 
	    data.width, data.height, data.width, data.height, data.name, 1.0);
	Tk_FreePixmap(graphPtr->display, drawable);
#if defined(WIN32) && !defined(PLATFORM_SDL)
    } else if ((data.format == FORMAT_WMF) || (data.format == FORMAT_EMF)) {
	TkWinDC drawableDC;
	TkWinDCState state;
	HDC hRefDC, hDC;
	HENHMETAFILE hMetaFile;
	Tcl_DString dString;
	char *title;
................................................................................
static int nGraphOps = sizeof(graphOps) / sizeof(Blt_OpSpec);

int
Blt_GraphInstCmdProc(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    Blt_Op proc;
    int result;
    Graph *graphPtr = clientData;

    proc = Blt_GetOp(interp, nGraphOps, graphOps, BLT_OP_ARG1, argc, argv, 0);
    if (proc == NULL) {
................................................................................
 *
 * --------------------------------------------------------------------------
 */
static int
NewGraph(interp, argc, argv, classUid)
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
    Blt_Uid classUid;
{
    Graph *graphPtr;

    if (argc < 2) {
	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
	    " pathName ?option value?...\"", (char *)NULL);
................................................................................
 */
/*ARGSUSED*/
static int
GraphCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    return NewGraph(interp, argc, argv, bltLineElementUid);
}

/*
 *--------------------------------------------------------------
 *
................................................................................
 */
/*ARGSUSED*/
static int
BarchartCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    return NewGraph(interp, argc, argv, bltBarElementUid);
}

/*
 *--------------------------------------------------------------
 *
................................................................................
 */
/*ARGSUSED*/
static int
StripchartCmd(clientData, interp, argc, argv)
    ClientData clientData;	/* Not used. */
    Tcl_Interp *interp;
    int argc;
    CONST char **argv;
{
    return NewGraph(interp, argc, argv, bltStripElementUid);
}

/*
 * -----------------------------------------------------------------------
 *
................................................................................

static void
UpdateMarginTraces(graphPtr)
    Graph *graphPtr;
{
    Margin *marginPtr;
    int size;
    int i;

    for (i = 0; i < 4; i++) {
	marginPtr = graphPtr->margins + i;
	if (marginPtr->varName != NULL) {	/* Trigger variable traces */
	    if ((marginPtr->site == MARGIN_LEFT) || 
		(marginPtr->site == MARGIN_RIGHT)) {
		size = marginPtr->width;

Changes to jni/blt/src/bltGraph.h.

21
22
23
24
25
26
27

28
29
30
31
32
33
34
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664

665
666
667
668
669
670
671
 * out of or in connection with the use or performance of this
 * software.
 */

#ifndef _BLT_GRAPH_H
#define _BLT_GRAPH_H


#include "bltInt.h"
#include "bltHash.h"
#include "bltBind.h"
#include "bltChain.h"
#include "bltPs.h"
#include "bltTile.h"

................................................................................
extern void Blt_MapAxes _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapElements _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapGraph _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapMarkers _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapGrid _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_UpdateCrosshairs _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DestroyPens _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_GetPen _ANSI_ARGS_((Graph *graphPtr, char *name, 
	Blt_Uid classUid, Pen **penPtrPtr));
extern Pen *Blt_BarPen _ANSI_ARGS_((char *penName));
extern Pen *Blt_LinePen _ANSI_ARGS_((char *penName));
extern Pen *Blt_CreatePen _ANSI_ARGS_((Graph *graphPtr, char *penName,
	Blt_Uid classUid, int nOpts, char **options));
extern int Blt_InitLinePens _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_InitBarPens _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_FreePen _ANSI_ARGS_((Graph *graphPtr, Pen *penPtr));

extern int Blt_VirtualAxisOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_AxisOp _ANSI_ARGS_((Graph *graphPtr, int margin, int argc, 
	char **argv));
extern int Blt_ElementOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv, Blt_Uid classUid));
extern int Blt_GridOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_CrosshairsOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_MarkerOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_PenOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_PointInPolygon _ANSI_ARGS_((Point2D *samplePtr, 
	Point2D *screenPts, int nScreenPts));
extern int Blt_RegionInPolygon _ANSI_ARGS_((Extents2D *extsPtr, Point2D *points,
	int nPoints, int enclosed));
extern int Blt_PointInSegments _ANSI_ARGS_((Point2D *samplePtr, 
	Segment2D *segments, int nSegments, double halo));
extern int Blt_PostScriptOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, char **argv));
extern int Blt_GraphUpdateNeeded _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_DefaultAxes _ANSI_ARGS_((Graph *graphPtr));
extern Axis *Blt_GetFirstAxis _ANSI_ARGS_((Blt_Chain *chainPtr));
extern void Blt_UpdateAxisBackgrounds _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_GetAxisSegments _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr,
	Segment2D **segPtrPtr, int *nSegmentsPtr));
extern Marker *Blt_NearestMarker _ANSI_ARGS_((Graph *graphPtr, int x, int y,
	int under));
extern Axis *Blt_NearestAxis _ANSI_ARGS_((Graph *graphPtr, int x, int y));


typedef ClientData (MakeTagProc) _ANSI_ARGS_((Graph *graphPtr, char *tagName));

extern MakeTagProc Blt_MakeElementTag;
extern MakeTagProc Blt_MakeMarkerTag;
extern MakeTagProc Blt_MakeAxisTag;

extern Blt_BindTagProc Blt_GraphTags;
extern Blt_BindTagProc Blt_AxisTags;








>







 







|

|
|
|
|





|

|

|

|

|

|

|







|











|
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
 * out of or in connection with the use or performance of this
 * software.
 */

#ifndef _BLT_GRAPH_H
#define _BLT_GRAPH_H

#include "blt.h"
#include "bltInt.h"
#include "bltHash.h"
#include "bltBind.h"
#include "bltChain.h"
#include "bltPs.h"
#include "bltTile.h"

................................................................................
extern void Blt_MapAxes _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapElements _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapGraph _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapMarkers _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_MapGrid _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_UpdateCrosshairs _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_DestroyPens _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_GetPen _ANSI_ARGS_((Graph *graphPtr, CONST char *name, 
	Blt_Uid classUid, Pen **penPtrPtr));
extern Pen *Blt_BarPen _ANSI_ARGS_((CONST char *penName));
extern Pen *Blt_LinePen _ANSI_ARGS_((CONST char *penName));
extern Pen *Blt_CreatePen _ANSI_ARGS_((Graph *graphPtr, CONST char *penName,
	Blt_Uid classUid, int nOpts, CONST char **options));
extern int Blt_InitLinePens _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_InitBarPens _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_FreePen _ANSI_ARGS_((Graph *graphPtr, Pen *penPtr));

extern int Blt_VirtualAxisOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_AxisOp _ANSI_ARGS_((Graph *graphPtr, int margin, int argc, 
	CONST char **argv));
extern int Blt_ElementOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv, Blt_Uid classUid));
extern int Blt_GridOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_CrosshairsOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_MarkerOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_PenOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_PointInPolygon _ANSI_ARGS_((Point2D *samplePtr, 
	Point2D *screenPts, int nScreenPts));
extern int Blt_RegionInPolygon _ANSI_ARGS_((Extents2D *extsPtr, Point2D *points,
	int nPoints, int enclosed));
extern int Blt_PointInSegments _ANSI_ARGS_((Point2D *samplePtr, 
	Segment2D *segments, int nSegments, double halo));
extern int Blt_PostScriptOp _ANSI_ARGS_((Graph *graphPtr, Tcl_Interp *interp,
	int argc, CONST char **argv));
extern int Blt_GraphUpdateNeeded _ANSI_ARGS_((Graph *graphPtr));
extern int Blt_DefaultAxes _ANSI_ARGS_((Graph *graphPtr));
extern Axis *Blt_GetFirstAxis _ANSI_ARGS_((Blt_Chain *chainPtr));
extern void Blt_UpdateAxisBackgrounds _ANSI_ARGS_((Graph *graphPtr));
extern void Blt_GetAxisSegments _ANSI_ARGS_((Graph *graphPtr, Axis *axisPtr,
	Segment2D **segPtrPtr, int *nSegmentsPtr));
extern Marker *Blt_NearestMarker _ANSI_ARGS_((Graph *graphPtr, int x, int y,
	int under));
extern Axis *Blt_NearestAxis _ANSI_ARGS_((Graph *graphPtr, int x, int y));


typedef ClientData (MakeTagProc) _ANSI_ARGS_((Graph *graphPtr,
	CONST char *tagName));
extern MakeTagProc Blt_MakeElementTag;
extern MakeTagProc Blt_MakeMarkerTag;
extern MakeTagProc Blt_MakeAxisTag;

extern Blt_BindTagProc Blt_GraphTags;
extern Blt_BindTagProc Blt_AxisTags;

Changes to jni/blt/src/bltHash.c.

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
...
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
...
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
....
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
....
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
....
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
static Blt_Hash
HashString(register CONST char *string) /* String from which to
					 * compute hash value. */
{
    register Blt_Hash result;
    register Blt_Hash c;

    /*
     * I tried a zillion different hash functions and asked many other
     * people for advice.  Many people had their own favorite functions,
     * all different, but no-one had much idea why they were good ones.
     * I chose the one below (multiply by 9 and add new character)
     * because of the following reasons:
................................................................................
 */
static Blt_HashEntry *
StringFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key)		/* Key to use to find matching entry. */
{
    Blt_Hash hval;
    register Blt_HashEntry *hPtr;
    size_t hindex;

    hval = HashString((char *)key);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in the appropriate bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    register CONST char *p1, *p2;

	    for (p1 = key, p2 = hPtr->key.string; ; p1++, p2++) {
		if (*p1 != *p2) {
		    break;
		}
		if (*p1 == '\0') {
		    return hPtr;
................................................................................
    CONST void *key,		/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_Hash hval;
    Blt_HashEntry **bucketPtr;
    register Blt_HashEntry *hPtr;
    size_t size, hindex;

    hval = HashString(key);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in this bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    register CONST char *p1, *p2;

	    for (p1 = key, p2 = hPtr->key.string; ; p1++, p2++) {
		if (*p1 != *p2) {
		    break;
		}
		if (*p1 == '\0') {
		    *newPtr = FALSE;
................................................................................
 *	None.
 *
 *---------------------------------------------------------------------- 
 */
static Blt_HashEntry *
OneWordFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    register CONST void *key)	/* Key to use to find matching entry. */
{
    register Blt_HashEntry *hPtr;
    size_t hindex;

    hindex = RANDOM_INDEX(tablePtr, key);

    /*
     * Search all of the entries in the appropriate bucket.
     */
................................................................................
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key,		/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_HashEntry **bucketPtr;
    register Blt_HashEntry *hPtr;
    size_t hindex;

    hindex = RANDOM_INDEX(tablePtr, key);

    /*
     * Search all of the entries in this bucket.
     */
................................................................................
 * --------------------------------------------------------------------
 */
static Blt_Hash
HashArray(
    CONST void *key, 
    size_t length)		/* Length of the key in 32-bit words */
{
    register uint32_t a, b, c, len;
    register uint32_t *arrayPtr = (uint32_t *)key;
    /* Set up the internal state */
    len = length;
    a = b = GOLDEN_RATIO32;	/* An arbitrary value */
    c = 0;			/* Previous hash value */

    while (len >= 3) {		/* Handle most of the key */
	a += arrayPtr[0];
................................................................................
 * --------------------------------------------------------------------
 */
static Blt_Hash
HashArray(
    CONST void *key, 
    size_t length)		/* Length of key in 32-bit words. */
{
    register uint64_t a, b, c, len;
    register uint32_t *iPtr = (uint32_t *)key;

#ifdef WORDS_BIGENDIAN
#define PACK(a,b)	((uint64_t)(b) | ((uint64_t)(a) << 32))
#else
#define PACK(a,b)	((uint64_t)(a) | ((uint64_t)(b) << 32))
#endif
    /* Set up the internal state */
................................................................................
 */
static Blt_HashEntry *
ArrayFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key)		/* Key to use to find matching entry. */
{
    Blt_Hash hval;
    register Blt_HashEntry *hPtr;
    size_t hindex;

    hval = HashArray(key, tablePtr->keyType);
    hindex = hval & tablePtr->mask;
    /*
     * Search all of the entries in the appropriate bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    register unsigned int *iPtr1, *iPtr2;
	    unsigned int count;

	    for (iPtr1 = (uint32_t *)key, iPtr2 = (uint32_t *)hPtr->key.words,
		     count = tablePtr->keyType; ; count--, iPtr1++, iPtr2++) {
		if (count == 0) {
		    return hPtr;
		}
................................................................................
 *	A new entry may be added to the hash table.
 *
 *----------------------------------------------------------------------
 */
static Blt_HashEntry *
ArrayCreate(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    register CONST void *key,	/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_Hash hval;
    Blt_HashEntry **bucketPtr;
    int count;
    register Blt_HashEntry *hPtr;
    register uint32_t *iPtr1, *iPtr2;
    size_t size, hindex;

    hval = HashArray(key, tablePtr->keyType);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in the appropriate bucket.
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
RebuildTable(Blt_HashTable *tablePtr) /* Table to enlarge. */
{
    Blt_HashEntry **bucketPtr, **oldBuckets;
    register Blt_HashEntry **oldChainPtr, **endPtr;
    register Blt_HashEntry *hPtr, *nextPtr;
    size_t hindex;

    oldBuckets = tablePtr->buckets;
    endPtr = tablePtr->buckets + tablePtr->numBuckets;
    /*
     * Allocate and initialize the new bucket array, and set up
     * hashing constants for new array size.
................................................................................
 *	TablePtr is now ready to be passed to Blt_FindHashEntry and
 *	Blt_CreateHashEntry.
 *
 *----------------------------------------------------------------------
 */
void
Blt_InitHashTable(
    register Blt_HashTable *tablePtr,	/* Pointer to table record, which
					 * is supplied by the caller. */
    size_t keyType)	                /* Type of keys to use in table. */
{
#if (BLT_SMALL_HASH_TABLE != 4) 
    Blt_Panic("Blt_InitHashTable: BLT_SMALL_HASH_TABLE is %d, not 4\n",
	    BLT_SMALL_HASH_TABLE);
#endif
................................................................................
 *	TablePtr is now ready to be passed to Blt_FindHashEntry and
 *	Blt_CreateHashEntry.
 *
 *----------------------------------------------------------------------
 */
void
Blt_InitHashTableWithPool(
    register Blt_HashTable *tablePtr,	/* Pointer to table record, which
					 * is supplied by the caller. */
    size_t keyType)			/* Type of keys to use in table. */
{
    Blt_InitHashTable(tablePtr, keyType);
    if (keyType == BLT_STRING_KEYS) {
	tablePtr->hPool = Blt_PoolCreate(BLT_VARIABLE_SIZE_ITEMS);
    } else {
................................................................................
 *----------------------------------------------------------------------
 */
void
Blt_DeleteHashEntry(
    Blt_HashTable *tablePtr,
    Blt_HashEntry *entryPtr)
{
    register Blt_HashEntry *prevPtr;
    Blt_HashEntry **bucketPtr;
    size_t hindex;

    if (tablePtr->keyType == BLT_ONE_WORD_KEYS) {
	hindex = RANDOM_INDEX(tablePtr, (CONST void *)entryPtr->hval);
    } else {
	hindex = (entryPtr->hval & tablePtr->mask);
................................................................................
    /*
     * Free up all the entries in the table.
     */
    if (tablePtr->hPool != NULL) {
	Blt_PoolDestroy(tablePtr->hPool);
	tablePtr->hPool = NULL;
    } else {
	register Blt_HashEntry *hPtr, *nextPtr;
	size_t i;

	for (i = 0; i < tablePtr->numBuckets; i++) {
	    hPtr = tablePtr->buckets[i];
	    while (hPtr != NULL) {
		nextPtr = hPtr->nextPtr;
		Blt_Free(hPtr);
................................................................................
 */
char *
Blt_HashStats(Blt_HashTable *tablePtr) /* Table for which to produce stats. */
{
#define NUM_COUNTERS 10
    size_t count[NUM_COUNTERS], overflow, i, j, max;
    double average, tmp;
    register Blt_HashEntry *hPtr;
    Blt_HashEntry **bucketPtr, **endPtr;
    char *result, *p;

    /*
     * Compute a histogram of bucket usage.
     */
    for (i = 0; i < NUM_COUNTERS; i++) {







|


|
|







 







|












|







 







|












|







 







|

|







 







|







 







|
|







 







|
|







 







|











|







 







|







|
|







 







|
|







 







|







 







|







 







|







 







|







 







|







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
...
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
...
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
....
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
....
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
....
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
static Blt_Hash
HashString(CONST char *string) /* String from which to
					 * compute hash value. */
{
    Blt_Hash result;
    Blt_Hash c;

    /*
     * I tried a zillion different hash functions and asked many other
     * people for advice.  Many people had their own favorite functions,
     * all different, but no-one had much idea why they were good ones.
     * I chose the one below (multiply by 9 and add new character)
     * because of the following reasons:
................................................................................
 */
static Blt_HashEntry *
StringFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key)		/* Key to use to find matching entry. */
{
    Blt_Hash hval;
    Blt_HashEntry *hPtr;
    size_t hindex;

    hval = HashString((char *)key);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in the appropriate bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    CONST char *p1, *p2;

	    for (p1 = key, p2 = hPtr->key.string; ; p1++, p2++) {
		if (*p1 != *p2) {
		    break;
		}
		if (*p1 == '\0') {
		    return hPtr;
................................................................................
    CONST void *key,		/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_Hash hval;
    Blt_HashEntry **bucketPtr;
    Blt_HashEntry *hPtr;
    size_t size, hindex;

    hval = HashString(key);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in this bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    CONST char *p1, *p2;

	    for (p1 = key, p2 = hPtr->key.string; ; p1++, p2++) {
		if (*p1 != *p2) {
		    break;
		}
		if (*p1 == '\0') {
		    *newPtr = FALSE;
................................................................................
 *	None.
 *
 *---------------------------------------------------------------------- 
 */
static Blt_HashEntry *
OneWordFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key)	/* Key to use to find matching entry. */
{
    Blt_HashEntry *hPtr;
    size_t hindex;

    hindex = RANDOM_INDEX(tablePtr, key);

    /*
     * Search all of the entries in the appropriate bucket.
     */
................................................................................
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key,		/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_HashEntry **bucketPtr;
    Blt_HashEntry *hPtr;
    size_t hindex;

    hindex = RANDOM_INDEX(tablePtr, key);

    /*
     * Search all of the entries in this bucket.
     */
................................................................................
 * --------------------------------------------------------------------
 */
static Blt_Hash
HashArray(
    CONST void *key, 
    size_t length)		/* Length of the key in 32-bit words */
{
    uint32_t a, b, c, len;
    uint32_t *arrayPtr = (uint32_t *)key;
    /* Set up the internal state */
    len = length;
    a = b = GOLDEN_RATIO32;	/* An arbitrary value */
    c = 0;			/* Previous hash value */

    while (len >= 3) {		/* Handle most of the key */
	a += arrayPtr[0];
................................................................................
 * --------------------------------------------------------------------
 */
static Blt_Hash
HashArray(
    CONST void *key, 
    size_t length)		/* Length of key in 32-bit words. */
{
    uint64_t a, b, c, len;
    uint32_t *iPtr = (uint32_t *)key;

#ifdef WORDS_BIGENDIAN
#define PACK(a,b)	((uint64_t)(b) | ((uint64_t)(a) << 32))
#else
#define PACK(a,b)	((uint64_t)(a) | ((uint64_t)(b) << 32))
#endif
    /* Set up the internal state */
................................................................................
 */
static Blt_HashEntry *
ArrayFind(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key)		/* Key to use to find matching entry. */
{
    Blt_Hash hval;
    Blt_HashEntry *hPtr;
    size_t hindex;

    hval = HashArray(key, tablePtr->keyType);
    hindex = hval & tablePtr->mask;
    /*
     * Search all of the entries in the appropriate bucket.
     */

    for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL;
	    hPtr = hPtr->nextPtr) {
	if (hPtr->hval == hval) {
	    unsigned int *iPtr1, *iPtr2;
	    unsigned int count;

	    for (iPtr1 = (uint32_t *)key, iPtr2 = (uint32_t *)hPtr->key.words,
		     count = tablePtr->keyType; ; count--, iPtr1++, iPtr2++) {
		if (count == 0) {
		    return hPtr;
		}
................................................................................
 *	A new entry may be added to the hash table.
 *
 *----------------------------------------------------------------------
 */
static Blt_HashEntry *
ArrayCreate(
    Blt_HashTable *tablePtr,	/* Table in which to lookup entry. */
    CONST void *key,	/* Key to use to find or create matching
				 * entry. */
    int *newPtr)		/* Store info here telling whether a new
				 * entry was created. */
{
    Blt_Hash hval;
    Blt_HashEntry **bucketPtr;
    int count;
    Blt_HashEntry *hPtr;
    uint32_t *iPtr1, *iPtr2;
    size_t size, hindex;

    hval = HashArray(key, tablePtr->keyType);
    hindex = hval & tablePtr->mask;

    /*
     * Search all of the entries in the appropriate bucket.
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
RebuildTable(Blt_HashTable *tablePtr) /* Table to enlarge. */
{
    Blt_HashEntry **bucketPtr, **oldBuckets;
    Blt_HashEntry **oldChainPtr, **endPtr;
    Blt_HashEntry *hPtr, *nextPtr;
    size_t hindex;

    oldBuckets = tablePtr->buckets;
    endPtr = tablePtr->buckets + tablePtr->numBuckets;
    /*
     * Allocate and initialize the new bucket array, and set up
     * hashing constants for new array size.
................................................................................
 *	TablePtr is now ready to be passed to Blt_FindHashEntry and
 *	Blt_CreateHashEntry.
 *
 *----------------------------------------------------------------------
 */
void
Blt_InitHashTable(
    Blt_HashTable *tablePtr,	/* Pointer to table record, which
					 * is supplied by the caller. */
    size_t keyType)	                /* Type of keys to use in table. */
{
#if (BLT_SMALL_HASH_TABLE != 4) 
    Blt_Panic("Blt_InitHashTable: BLT_SMALL_HASH_TABLE is %d, not 4\n",
	    BLT_SMALL_HASH_TABLE);
#endif
................................................................................
 *	TablePtr is now ready to be passed to Blt_FindHashEntry and
 *	Blt_CreateHashEntry.
 *
 *----------------------------------------------------------------------
 */
void
Blt_InitHashTableWithPool(
    Blt_HashTable *tablePtr,	/* Pointer to table record, which
					 * is supplied by the caller. */
    size_t keyType)			/* Type of keys to use in table. */
{
    Blt_InitHashTable(tablePtr, keyType);
    if (keyType == BLT_STRING_KEYS) {
	tablePtr->hPool = Blt_PoolCreate(BLT_VARIABLE_SIZE_ITEMS);
    } else {
................................................................................
 *----------------------------------------------------------------------
 */
void
Blt_DeleteHashEntry(
    Blt_HashTable *tablePtr,
    Blt_HashEntry *entryPtr)
{
    Blt_HashEntry *prevPtr;
    Blt_HashEntry **bucketPtr;
    size_t hindex;

    if (tablePtr->keyType == BLT_ONE_WORD_KEYS) {
	hindex = RANDOM_INDEX(tablePtr, (CONST void *)entryPtr->hval);
    } else {
	hindex = (entryPtr->hval & tablePtr->mask);
................................................................................
    /*
     * Free up all the entries in the table.
     */
    if (tablePtr->hPool != NULL) {
	Blt_PoolDestroy(tablePtr->hPool);
	tablePtr->hPool = NULL;
    } else {
	Blt_HashEntry *hPtr, *nextPtr;
	size_t i;

	for (i = 0; i < tablePtr->numBuckets; i++) {
	    hPtr = tablePtr->buckets[i];
	    while (hPtr != NULL) {
		nextPtr = hPtr->nextPtr;
		Blt_Free(hPtr);
................................................................................
 */
char *
Blt_HashStats(Blt_HashTable *tablePtr) /* Table for which to produce stats. */
{
#define NUM_COUNTERS 10
    size_t count[NUM_COUNTERS], overflow, i, j, max;
    double average, tmp;
    Blt_HashEntry *hPtr;
    Blt_HashEntry **bucketPtr, **endPtr;
    char *result, *p;

    /*
     * Compute a histogram of bucket usage.
     */
    for (i = 0; i < NUM_COUNTERS; i++) {

Changes to jni/blt/src/bltHash.h.

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

#include "bltPool.h"

/*
 * Acceptable key types for hash tables:
 */
#define BLT_STRING_KEYS		0
#define BLT_ONE_WORD_KEYS	((size_t)-1)

/*
 * Forward declaration of Blt_HashTable.  Needed by some C++ compilers
 * to prevent errors when the forward reference to Blt_HashTable is
 * encountered in the Blt_HashEntry structure.
 */








|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

#include "bltPool.h"

/*
 * Acceptable key types for hash tables:
 */
#define BLT_STRING_KEYS		0
#define BLT_ONE_WORD_KEYS	(-1)

/*
 * Forward declaration of Blt_HashTable.  Needed by some C++ compilers
 * to prevent errors when the forward reference to Blt_HashTable is
 * encountered in the Blt_HashEntry structure.
 */

Changes to jni/blt/src/bltHash.h.in.

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

#include "bltPool.h"

/*
 * Acceptable key types for hash tables:
 */
#define BLT_STRING_KEYS		0
#define BLT_ONE_WORD_KEYS	((size_t)-1)

/*
 * Forward declaration of Blt_HashTable.  Needed by some C++ compilers
 * to prevent errors when the forward reference to Blt_HashTable is
 * encountered in the Blt_HashEntry structure.
 */








|







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

#include "bltPool.h"

/*
 * Acceptable key types for hash tables:
 */
#define BLT_STRING_KEYS		0
#define BLT_ONE_WORD_KEYS	(-1)

/*
 * Forward declaration of Blt_HashTable.  Needed by some C++ compilers
 * to prevent errors when the forward reference to Blt_HashTable is
 * encountered in the Blt_HashEntry structure.
 */

Changes to jni/blt/src/bltHierbox.c.

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
292
293
294
295
296
297
298
299
300
301
302

303
304
305

306




















307
308
309
310
311
312
313
314


315
316

317
318


319
320

321
322


323
324

325
326


327
328

329
330
331
332
333
334
335
....
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
....
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
....
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
....
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
....
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
....
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
....
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
....
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
....
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
....
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
....
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
....
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
....
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
....
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
....
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
....
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
....
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
....
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
....
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
....
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
....
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
....
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
....
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
....
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
....
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
....
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
....
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
....
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
....
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
....
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
....
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
....
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013

6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
....
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
....
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
....
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
....
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
....
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
....
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
....
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
....
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
....
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
#include "bltList.h"
#ifndef NO_TILE
#include "bltTile.h"
#endif
#include <X11/Xutil.h>
#include <X11/Xatom.h>

#if HAVE_UTF
#else
#define Tcl_NumUtfChars(s,n)	(((n) == -1) ? strlen((s)) : (n))
#define Tcl_UtfAtIndex(s,i)	((s) + (i))
#endif

#define SEPARATOR_NONE		((char *)-1)
#define SEPARATOR_LIST		((char *)NULL)
#define APPEND			(-1)

/*
 * The macro below is used to modify a "char" value (e.g. by casting
 * it to an unsigned character) so that it can be used safely with
................................................................................
#define DEF_ENTRY_TEXT			(char *)NULL

#define DEF_BUTTON_ACTIVE_BACKGROUND	RGB_WHITE
#define DEF_BUTTON_ACTIVE_BG_MONO	STD_ACTIVE_BG_MONO
#define DEF_BUTTON_ACTIVE_FOREGROUND	STD_ACTIVE_FOREGROUND
#define DEF_BUTTON_ACTIVE_FG_MONO	STD_ACTIVE_FG_MONO
#define DEF_BUTTON_BORDERWIDTH		"1"
#if (TK_MAJOR_VERSION == 4) 
#define DEF_BUTTON_CLOSE_RELIEF		"flat"
#define DEF_BUTTON_OPEN_RELIEF		"flat"
#else
#define DEF_BUTTON_CLOSE_RELIEF		"solid"
#define DEF_BUTTON_OPEN_RELIEF		"solid"
#endif
#define DEF_BUTTON_IMAGES		(char *)NULL
#define DEF_BUTTON_NORMAL_BACKGROUND	RGB_WHITE
#define DEF_BUTTON_NORMAL_BG_MONO	STD_NORMAL_BG_MONO
#define DEF_BUTTON_NORMAL_FOREGROUND	STD_NORMAL_FOREGROUND
#define DEF_BUTTON_NORMAL_FG_MONO	STD_NORMAL_FG_MONO
#define DEF_BUTTON_SIZE			"7"

................................................................................
#define DEF_HIERBOX_LINE_WIDTH		"1"
#define DEF_HIERBOX_MAKE_PATH		"no"
#define DEF_HIERBOX_NORMAL_BACKGROUND 	STD_NORMAL_BACKGROUND
#define DEF_HIERBOX_NORMAL_FG_MONO	STD_ACTIVE_FG_MONO
#define DEF_HIERBOX_RELIEF		"sunken"
#define DEF_HIERBOX_SCROLL_INCREMENT 	"0"
#define DEF_HIERBOX_SCROLL_MODE		"hierbox"
#define DEF_HIERBOX_SCROLL_TILE		"yes"
#define DEF_HIERBOX_SELECT_BACKGROUND 	RGB_LIGHTSKYBLUE1
#define DEF_HIERBOX_SELECT_BG_MONO  	STD_SELECT_BG_MONO
#define DEF_HIERBOX_SELECT_BORDERWIDTH "1"
#define DEF_HIERBOX_SELECT_CMD		(char *)NULL
#define DEF_HIERBOX_SELECT_FOREGROUND 	STD_SELECT_FOREGROUND
#define DEF_HIERBOX_SELECT_FG_MONO  	STD_SELECT_FG_MONO
#define DEF_HIERBOX_SELECT_MODE		"single"
................................................................................
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltShadowOption;
#ifndef NO_TILE
extern Tk_CustomOption bltTileOption;
#endif
extern Tk_CustomOption bltUidOption;

static Tk_OptionParseProc StringToButton;
static Tk_OptionPrintProc ButtonToString;
static Tk_OptionParseProc StringToImages;
static Tk_OptionPrintProc ImagesToString;

static Tk_OptionParseProc StringToScrollMode;
static Tk_OptionPrintProc ScrollModeToString;
static Tk_OptionParseProc StringToSeparator;

static Tk_OptionPrintProc SeparatorToString;




















/*
 * Contains a pointer to the widget that's currently being configured.
 * This is used in the custom configuration parse routine for images.
 */
static Hierbox *hierBox;

static Tk_CustomOption imagesOption =
{


    StringToImages, ImagesToString, (ClientData)&hierBox,
};

static Tk_CustomOption buttonOption =
{


    StringToButton, ButtonToString, (ClientData)0,
};

static Tk_CustomOption scrollModeOption =
{


    StringToScrollMode, ScrollModeToString, (ClientData)0,
};

static Tk_CustomOption separatorOption = 
{


    StringToSeparator, SeparatorToString, (ClientData)0,
};

/*
 * CachedImage --
 *
 *	Since instances of the same Tk image can be displayed in
 *	different windows with possibly different color palettes, Tk
 *	internally stores each instance in a linked list.  But if
 *	the instances are used in the same widget and therefore use
................................................................................
	int nNames;
	char **nameArr;

	if (Tcl_SplitList(interp, string, &nNames, &nameArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nNames > 0) {
	    register int i;

	    imageArr = Blt_Malloc(sizeof(CachedImage *) * (nNames + 1));
	    assert(imageArr);
	    for (i = 0; i < nNames; i++) {
		imageArr[i] = GetCachedImage(hboxPtr, interp, tkwin, nameArr[i]);
		if (imageArr[i] == NULL) {
		    result = TCL_ERROR;
................................................................................
		}
	    }
	    Blt_Free(nameArr);
	    imageArr[nNames] = NULL;
	}
    }
    if (*imagePtrPtr != NULL) {
	register CachedImage *imagePtr;

	for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) {
	    FreeCachedImage(hboxPtr, *imagePtr);
	}
	Blt_Free(*imagePtrPtr);
    }
    *imagePtrPtr = imageArr;
................................................................................
{
    CachedImage **imagePtrPtr = (CachedImage **) (widgRec + offset);
    Tcl_DString dString;
    char *result;

    Tcl_DStringInit(&dString);
    if (*imagePtrPtr != NULL) {
	register CachedImage *imagePtr;

	for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) {
	    Tcl_DStringAppendElement(&dString, 
			     Blt_NameOfImage((*imagePtr)->tkImage));
	}
    }
    result = Blt_Strdup(Tcl_DStringValue(&dString));
................................................................................
    if (buttonPtr->activeGC != NULL) {
	Tk_FreeGC(hboxPtr->display, buttonPtr->activeGC);
    }
    buttonPtr->activeGC = newGC;

    buttonPtr->width = buttonPtr->height = ODD(buttonPtr->reqSize);
    if (buttonPtr->images != NULL) {
	register int i;

	for (i = 0; i < 2; i++) {
	    if (buttonPtr->images[i] == NULL) {
		break;
	    }
	    if (buttonPtr->width < ImageWidth(buttonPtr->images[i])) {
		buttonPtr->width = ImageWidth(buttonPtr->images[i]);
................................................................................
}

static void
DestroyEntry(entryPtr)
    Entry *entryPtr;
{
    Hierbox *hboxPtr = entryPtr->hboxPtr;
    register CachedImage *imagePtr;

    Tk_FreeOptions(entryConfigSpecs, (char *)entryPtr, hboxPtr->display, 0);
    if (entryPtr->labelGC != NULL) {
	Tk_FreeGC(hboxPtr->display, entryPtr->labelGC);
    }
    if (entryPtr->dataGC != NULL) {
	Tk_FreeGC(hboxPtr->display, entryPtr->dataGC);
................................................................................
    }
    Blt_Free(entryPtr);
}

/*ARGSUSED*/
static Tree *
LastNode(treePtr, mask)
    register Tree *treePtr;
    unsigned int mask;
{
    Blt_ChainLink *linkPtr;

    if (treePtr->parentPtr == NULL) {
	return NULL;		/* The root is the first node. */
    }
................................................................................
	linkPtr = Blt_ChainLastLink(treePtr->chainPtr);
    }
    return treePtr;
}

static void
ExposeAncestors(treePtr)
    register Tree *treePtr;
{
    treePtr = treePtr->parentPtr;
    while (treePtr != NULL) {
	treePtr->entryPtr->flags |= (ENTRY_OPEN | ENTRY_MAPPED);
	treePtr = treePtr->parentPtr;
    }
}

static int
IsBefore(t1Ptr, t2Ptr)
    register Tree *t1Ptr, *t2Ptr;
{
    int depth;
    register int i;
    Blt_ChainLink *linkPtr;
    Tree *treePtr;

    depth = MIN(t1Ptr->level, t2Ptr->level);

    if (depth == 0) {		/* One of the nodes is root. */
	if (t1Ptr->parentPtr == NULL) {
................................................................................
	}
    }
    return 0;
}

static int
IsHidden(treePtr)
    register Tree *treePtr;
{
    if (treePtr != NULL) {
	unsigned int mask;

	if (!(treePtr->entryPtr->flags & ENTRY_MAPPED)) {
	    return TRUE;
	}
................................................................................
static void
GetFullPath(treePtr, separator, resultPtr)
    Tree *treePtr;
    char *separator;
    Tcl_DString *resultPtr;
{
    char **nameArr;		/* Used the stack the component names. */
    register int i;
    int level;

    level = treePtr->level;
    nameArr = Blt_Malloc((level + 1) * sizeof(char *));
    assert(nameArr);
    for (i = level; i >= 0; i--) {
	/* Save the name of each ancestor in the name array. */
................................................................................
    Tree *parentPtr;
    char *name;
{
    Blt_Uid nameId;

    nameId = Blt_FindUid(name);
    if (nameId != NULL) {
	register Tree *treePtr;
	Blt_ChainLink *linkPtr;

	/* The component identifier must already exist if the node exists. */
	for (linkPtr = Blt_ChainFirstLink(parentPtr->chainPtr); linkPtr != NULL;
	    linkPtr = Blt_ChainNextLink(linkPtr)) {
	    treePtr = Blt_ChainGetValue(linkPtr);
	    if (nameId == treePtr->nameId) {
................................................................................
    int *levelPtr;
    char ***compPtrPtr;
{
    int skipLen, pathLen;
    char *sep;
    int level, listSize;
    char **components;
    register char *p;

    skipLen = strlen(hboxPtr->separator);
    path = SkipSeparators(path, hboxPtr->separator, skipLen);
    pathLen = strlen(path);

    level = pathLen / skipLen;
    listSize = (level + 1) * sizeof(char *);
................................................................................
 */
static Tree *
FindPath(hboxPtr, rootPtr, path)
    Hierbox *hboxPtr;
    Tree *rootPtr;
    char *path;
{
    register char *p;
    int skip;
    char *sep;
    Tree *treePtr;
    char save;

    /* Trim off characters that we don't want */
    if (hboxPtr->trimLeft != NULL) {
	register char *s;

	/* Trim off leading character string if one exists. */
	for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) {
	    if (*p != *s) {
		break;
	    }
	}
................................................................................
    }
    if (hboxPtr->separator == SEPARATOR_NONE) { 
	return FindComponent(rootPtr, path);
    } 
    if (hboxPtr->separator == SEPARATOR_LIST) {
	char **nameArr;
	int nComp;
	register int i;

	/*
	 * No separator, so this must be a Tcl list of components.
	 */
	if (Tcl_SplitList(hboxPtr->interp, path, &nComp, &nameArr)
	    != TCL_OK) {
	    return NULL;
................................................................................
/*ARGSUSED*/
static Tree *
NearestNode(hboxPtr, x, y, selectOne)
    Hierbox *hboxPtr;
    int x, y;
    int selectOne;
{
    register Tree *lastPtr, **treePtrPtr;
    register Entry *entryPtr;

    /*
     * We implicitly can pick only visible entries.  So make sure that
     * the tree exists.
     */
    if (hboxPtr->nVisible == 0) {
	return NULL;
................................................................................
PercentSubst(hboxPtr, treePtr, command, resultPtr)
    Hierbox *hboxPtr;
    Tree *treePtr;
    char *command;
    Tcl_DString *resultPtr;
{
    Tcl_DString dString;
    register char *last, *p;

    /*
     * Get the full path name of the node, in case we need to
     * substitute for it.
     */
    GetFullPath(treePtr, hboxPtr->separator, &dString);
    Tcl_DStringInit(resultPtr);
................................................................................
 *----------------------------------------------------------------------
 */
static int
SelectRange(hboxPtr, fromPtr, toPtr)
    Hierbox *hboxPtr;
    Tree *fromPtr, *toPtr;
{
    register Tree *treePtr;
    IterProc *proc;

    /* From the range determine the direction to select entries. */
    proc = (IsBefore(toPtr, fromPtr)) ? LastNode : NextNode;
    for (treePtr = fromPtr; treePtr != NULL;
	 treePtr = (*proc)(treePtr, ENTRY_OPEN | ENTRY_MAPPED)) {
	SelectNode(hboxPtr, treePtr);
................................................................................
    Tree *treePtr;

    Blt_ListAppend(list, (char *)object, 0);
    treePtr = (Tree *) object;
    if (treePtr->entryPtr->tags != NULL) {
	int nNames;
	char **names;
	register char **p;

	if (Tcl_SplitList((Tcl_Interp *)NULL, treePtr->entryPtr->tags, &nNames,
		&names) == TCL_OK) {
	    for (p = names; *p != NULL; p++) {
		Blt_ListAppend(list, Tk_GetUid(*p), 0);
	    }
	    Blt_Free(names);
................................................................................
    hierBox = hboxPtr;
    if (Blt_ConfigureWidget(hboxPtr->interp, hboxPtr->tkwin, entryConfigSpecs,
	    argc, argv, (char *)entryPtr, flags) != TCL_OK) {
	return TCL_ERROR;
    }
    entryPtr->iconWidth = entryPtr->iconHeight = 0;
    if (entryPtr->icons != NULL) {
	register int i;

	for (i = 0; i < 2; i++) {
	    if (entryPtr->icons[i] == NULL) {
		break;
	    }
	    if (entryPtr->iconWidth < ImageWidth(entryPtr->icons[i])) {
		entryPtr->iconWidth = ImageWidth(entryPtr->icons[i]);
................................................................................
    if (entryHeight < height) {
	entryHeight = height;
    }
    entryPtr->labelWidth = width;
    entryPtr->labelHeight = height;
    width = height = 0;
    if (entryPtr->images != NULL) {
	register CachedImage *imagePtr;

	for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) {
	    width += ImageWidth(*imagePtr);
	    if (height < ImageHeight(*imagePtr)) {
		height = ImageHeight(*imagePtr);
	    }
	}
................................................................................
    Blt_InitHashTable(&(hboxPtr->selectTable), BLT_ONE_WORD_KEYS);
    Blt_InitHashTable(&(hboxPtr->nodeTable), BLT_ONE_WORD_KEYS);
    Blt_InitHashTable(&(hboxPtr->imageTable), BLT_STRING_KEYS);
    hboxPtr->bindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, 
	PickEntry, GetTags);
    hboxPtr->buttonBindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, 
	PickButton, GetTags);
#if (TK_MAJOR_VERSION > 4)
    Blt_SetWindowInstanceData(tkwin, hboxPtr);
#endif
    return hboxPtr;
}

/*
 * ----------------------------------------------------------------------
 *
 * DestroyHierbox --
................................................................................
    if (hboxPtr->iconMask != None) {
	Tk_FreeBitmap(hboxPtr->display, hboxPtr->iconMask);
    }
    if (hboxPtr->iconColor != NULL) {
	Tk_FreeColor(hboxPtr->iconColor);
    }
    if (buttonPtr->images != NULL) {
	register CachedImage *imagePtr;

	for (imagePtr = buttonPtr->images; *imagePtr != NULL; imagePtr++) {
	    FreeCachedImage(hboxPtr, *imagePtr);
	}
	Blt_Free(buttonPtr->images);
    }
    if (buttonPtr->activeGC != NULL) {
................................................................................
	Blt_Free(hboxPtr->levelInfo);
    }
    hboxPtr->levelInfo = Blt_Calloc(hboxPtr->depth + 2, sizeof(LevelInfo));
    assert(hboxPtr->levelInfo);
    ComputeWidths(hboxPtr, hboxPtr->rootPtr);
    {
	int sum, width;
	register int i;

	sum = 0;
	for (i = 0; i <= hboxPtr->depth; i++) {
	    width = hboxPtr->levelInfo[i].width;
	    width |= 0x01;
	    hboxPtr->levelInfo[i].width = width;
	    sum += width;
................................................................................
static int
ComputeVisibleEntries(hboxPtr)
    Hierbox *hboxPtr;
{
    Entry *entryPtr;
    int height;
    Blt_ChainLink *linkPtr;
    register Tree *treePtr;
    int x, maxX;
    int nSlots;

    hboxPtr->xOffset = Blt_AdjustViewport(hboxPtr->xOffset, hboxPtr->worldWidth,
	VPORTWIDTH(hboxPtr), hboxPtr->xScrollUnits, hboxPtr->scrollMode);
    hboxPtr->yOffset = Blt_AdjustViewport(hboxPtr->yOffset,
	hboxPtr->worldHeight, VPORTHEIGHT(hboxPtr), hboxPtr->yScrollUnits,
	hboxPtr->scrollMode);

    height = VPORTHEIGHT(hboxPtr);

    /* Allocate worst case number of slots for entry array. */
    nSlots = (height / hboxPtr->minHeight) + 3;
    if ((nSlots != hboxPtr->nVisible) && (hboxPtr->visibleArr != NULL)) {
	Blt_Free(hboxPtr->visibleArr);
    }
    hboxPtr->visibleArr = Blt_Calloc(nSlots, sizeof(Tree *));
    assert(hboxPtr->visibleArr);
    hboxPtr->nVisible = 0;

    /* Find the node where the view port starts. */
................................................................................
    TextStyle ts;
    TextLayout *textPtr;
    Tk_FontMetrics fontMetrics;
    int nBytes;
    int sum;
    Entry *entryPtr;
    TextFragment *fragPtr;
    register int i;

    entryPtr = treePtr->entryPtr;
    font = GETFONT(hboxPtr, entryPtr->labelFont);
    memset(&ts, 0, sizeof(TextStyle));
    ts.font = font;
    ts.justify = TK_JUSTIFY_LEFT;
    ts.shadow.offset = entryPtr->labelShadow.offset;
................................................................................
	int count;

	gc = (treePtr == hboxPtr->activeButtonPtr)
	    ? buttonPtr->activeGC : buttonPtr->normalGC;
	count = 1;
	segArr[0].y1 = segArr[0].y2 = y + height / 2;
	segArr[0].x1 = x + BUTTON_IPAD;
#ifdef WIN32
	segArr[0].x2 = x + width - BUTTON_IPAD;
#else
	segArr[0].x2 = x + width - BUTTON_IPAD - 1;
#endif
	if (!(entryPtr->flags & ENTRY_OPEN)) {
	    segArr[1].x1 = segArr[1].x2 = x + width / 2;
	    segArr[1].y1 = y + BUTTON_IPAD;
#ifdef WIN32
	    segArr[1].y2 = y + height - BUTTON_IPAD;
#else
	    segArr[1].y2 = y + height - BUTTON_IPAD - 1;
#endif
	    count++;
	}
	XDrawSegments(hboxPtr->display, drawable, gc, segArr, count);
................................................................................
    Drawable drawable;		/* Pixmap or window to draw into. */
{
    Entry *entryPtr = treePtr->entryPtr;
    /*
     * Auxillary data: text string or images.
     */
    if (entryPtr->images != NULL) {
	register CachedImage *imagePtr;
	int imageY;

	for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) {
	    imageY = y;
	    if (ImageHeight(*imagePtr) < entryHeight) {
		imageY += (entryHeight - ImageHeight(*imagePtr)) / 2;
	    }
................................................................................
    {
	Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->border, 0, 0,
	    Tk_Width(hboxPtr->tkwin), Tk_Height(hboxPtr->tkwin), 0,
	    TK_RELIEF_FLAT);
    }

    if (hboxPtr->nVisible > 0) {
	register Tree **treePtrPtr;

	if (hboxPtr->activePtr != NULL) {
	    int y, height;

	    y = SCREENY(hboxPtr, hboxPtr->activePtr->entryPtr->worldY);
	    height = MAX(hboxPtr->activePtr->entryPtr->iconHeight, 
		hboxPtr->activePtr->entryPtr->labelHeight);
................................................................................
BboxOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    Tree *treePtr;
    register int i;
    Entry *entryPtr;
    char string[200];
    int width, height, yBot;
    int left, top, right, bottom;
    int screen;

    if (hboxPtr->flags & HIERBOX_LAYOUT) {
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Tree *rootPtr;
    unsigned int flags;
    register int i;

    flags = 0;
    if (argc > 2) {
	int length;

	length = strlen(argv[2]);
	if ((argv[2][0] == '-') && (length > 1) &&
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    int nIds, nOpts;
    char **options;
    register int i;
    Tree *treePtr;


    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
................................................................................
    TextLayout *textPtr;
    Tk_FontMetrics fontMetrics;
    TextFragment *fragPtr;
    int nBytes;
    Entry *entryPtr;
    Tree *treePtr;
    int lineNum;
    register int i;

    treePtr = hboxPtr->focusPtr;
    entryPtr = treePtr->entryPtr;

    if (*entryPtr->labelText == '\0') {
	return 0;
    }
................................................................................
	/* Find the character underneath the pointer. */
	nBytes = Tk_MeasureChars(font, fragPtr->text, fragPtr->count, x, 0,
	    &newX);
	if ((newX < x) && (nBytes < fragPtr->count)) {
	    double fract;
	    int length, charSize;
	    char *next;

	    next = fragPtr->text + nBytes;
#if HAVE_UTF
	    {
		Tcl_UniChar dummy;


		length = Tcl_UtfToUniChar(next, &dummy);
	    }
#else
	    length = 1;
#endif
	    charSize = Tk_TextWidth(font, next, length);
	    fract = ((double)(x - newX) / (double)charSize);
	    if (ROUND(fract)) {
		nBytes += length;
	    }
	}
    }
................................................................................
static int
FindOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    register Tree *treePtr;
    Tree *firstPtr, *lastPtr;
    int nMatches, maxMatches;
    char c;
    int length;
    CompareProc *compareProc;
    IterProc *nextProc;
    int invertMatch;		/* normal search mode (matching entries) */
    char *namePattern, *fullPattern;
    char *execCmd;
    register int i;
    int result;
    char *pattern;
    char *option;
    char *value;
    Tcl_DString dString, pathString;
    Blt_List optionList;
    register Blt_ListNode node;

    invertMatch = FALSE;
    maxMatches = 0;
    execCmd = namePattern = fullPattern = NULL;
    compareProc = ExactCompare;
    nextProc = NextNode;
    optionList = Blt_ListCreate(BLT_STRING_KEYS);
................................................................................
    int argc;
    char **argv;
{
    int fullName;
    Tree *treePtr;
    Tcl_DString dString;
    Tcl_DString pathString;
    register int i;

    fullName = FALSE;
    if ((argc > 2) && (argv[2][0] == '-') && (strcmp(argv[2], "-full") == 0)) {
	fullName = TRUE;
	argv++, argc--;
    }
    Tcl_DStringInit(&dString);
................................................................................
    char **argv;
    ApplyProc *proc;
    int *nonMatchPtr;		/* returns: inverted search indicator */
{
    CompareProc *compareProc;
    int invertMatch;		/* normal search mode (matching entries) */
    char *namePattern, *fullPattern;
    register int i;
    int length;
    int result;
    char *option, *pattern;
    char *value;
    Tree *treePtr;
    char c;
    Blt_List optionList;
    register Blt_ListNode node;

    optionList = Blt_ListCreate(BLT_STRING_KEYS);
    invertMatch = FALSE;
    namePattern = fullPattern = NULL;
    compareProc = ExactCompare;
    for (i = 2; i < argc; i++) {
	if (argv[i][0] != '-') {
................................................................................
    char **argv;
{
    Tree *rootPtr, *nodePtr, *parentPtr;
    int position;
    int level, count;
    char *path;
    Tcl_DString dString;
    register int i, l;
    int nOpts;
    char **options;
    char **nameArr;

    rootPtr = hboxPtr->rootPtr;
    if ((argv[2][0] == '-') && (strcmp(argv[2], "-at") == 0)) {
	if (StringToNode(hboxPtr, argv[3], &rootPtr) != TCL_OK) {
................................................................................
    nOpts = argc - count;
    options = argv + count;

    Tcl_DStringInit(&dString);
    for (i = 0; i < count; i++) {
	path = argv[i];
	if (hboxPtr->trimLeft != NULL) {
	    register char *p, *s;

	    /* Trim off leading character string if one exists. */
	    for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) {
		if (*p != *s) {
		    break;
		}
	    }
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    ButtonAttributes *buttonPtr = &(hboxPtr->button);
    int x, y;			/* Screen coordinates of the test point. */
    register Entry *entryPtr;
    register Tree *treePtr;

    if ((Tk_GetPixels(interp, hboxPtr->tkwin, argv[2], &x) != TCL_OK) ||
	(Tk_GetPixels(interp, hboxPtr->tkwin, argv[3], &y) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (hboxPtr->nVisible == 0) {
	return TCL_OK;
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Tree *rootPtr;
    unsigned int flags;
    register int i;

    flags = 0;
    if (argc > 2) {
	int length;

	length = strlen(argv[2]);
	if ((argv[2][0] == '-') && (length > 1) &&
................................................................................
RangeOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Tree *firstPtr, *lastPtr;
    register Tree *treePtr;
    unsigned int flags;
    int length;

    flags = 0;
    length = strlen(argv[2]);
    if ((argv[2][0] == '-') && (length > 1) &&
	(strncmp(argv[2], "-open", length) == 0)) {
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int length;
    Tree *rootPtr;
    register int i;
    unsigned int flags;

    flags = 0;
    hboxPtr->sortCmd = NULL;
    for (i = 2; i < argc; i++) {
	if (argv[i][0] != '-') {
	    break;		/* Found start of indices */







<
<
<
<
<
<







 







<
<
<
<


<







 







|







 







|
|
|
<
>
|
|
<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
|

>


>
>
|

>


>
>
|

>


>
>
|

>







 







|







 







|







 







|







 







|







 







|







 







|







 







|










|


|







 







|







 







|







 







|







 







|







 







|







|







 







|







 







|
|







 







|







 







|







 







|







 







|







 







|







 







<

<







 







|







 







|







 







|













|







 







|







 







|







|







 







|







 







|







 







|







 







|







 







|







 







|







 







<
<
<
<
|

>
|
<
<
<
<







 







|









|






|







 







|







 







|







|







 







|







 







|







 







|
|







 







|







 







|







 







|







47
48
49
50
51
52
53






54
55
56
57
58
59
60
...
200
201
202
203
204
205
206




207
208

209
210
211
212
213
214
215
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
...
281
282
283
284
285
286
287
288
289
290

291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
....
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
....
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
....
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
....
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
....
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
....
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
....
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
....
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
....
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
....
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
....
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
....
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
....
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
....
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
....
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
....
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
....
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
....
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
....
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
....
3622
3623
3624
3625
3626
3627
3628

3629

3630
3631
3632
3633
3634
3635
3636
....
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
....
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
....
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
....
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
....
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
....
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
....
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
....
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
....
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
....
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
....
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
....
6020
6021
6022
6023
6024
6025
6026




6027
6028
6029
6030




6031
6032
6033
6034
6035
6036
6037
....
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
....
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
....
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
....
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
....
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
....
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
....
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
....
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
....
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
#include "bltList.h"
#ifndef NO_TILE
#include "bltTile.h"
#endif
#include <X11/Xutil.h>
#include <X11/Xatom.h>







#define SEPARATOR_NONE		((char *)-1)
#define SEPARATOR_LIST		((char *)NULL)
#define APPEND			(-1)

/*
 * The macro below is used to modify a "char" value (e.g. by casting
 * it to an unsigned character) so that it can be used safely with
................................................................................
#define DEF_ENTRY_TEXT			(char *)NULL

#define DEF_BUTTON_ACTIVE_BACKGROUND	RGB_WHITE
#define DEF_BUTTON_ACTIVE_BG_MONO	STD_ACTIVE_BG_MONO
#define DEF_BUTTON_ACTIVE_FOREGROUND	STD_ACTIVE_FOREGROUND
#define DEF_BUTTON_ACTIVE_FG_MONO	STD_ACTIVE_FG_MONO
#define DEF_BUTTON_BORDERWIDTH		"1"




#define DEF_BUTTON_CLOSE_RELIEF		"solid"
#define DEF_BUTTON_OPEN_RELIEF		"solid"

#define DEF_BUTTON_IMAGES		(char *)NULL
#define DEF_BUTTON_NORMAL_BACKGROUND	RGB_WHITE
#define DEF_BUTTON_NORMAL_BG_MONO	STD_NORMAL_BG_MONO
#define DEF_BUTTON_NORMAL_FOREGROUND	STD_NORMAL_FOREGROUND
#define DEF_BUTTON_NORMAL_FG_MONO	STD_NORMAL_FG_MONO
#define DEF_BUTTON_SIZE			"7"

................................................................................
#define DEF_HIERBOX_LINE_WIDTH		"1"
#define DEF_HIERBOX_MAKE_PATH		"no"
#define DEF_HIERBOX_NORMAL_BACKGROUND 	STD_NORMAL_BACKGROUND
#define DEF_HIERBOX_NORMAL_FG_MONO	STD_ACTIVE_FG_MONO
#define DEF_HIERBOX_RELIEF		"sunken"
#define DEF_HIERBOX_SCROLL_INCREMENT 	"0"
#define DEF_HIERBOX_SCROLL_MODE		"hierbox"
#define DEF_HIERBOX_SCROLL_TILE		"no"
#define DEF_HIERBOX_SELECT_BACKGROUND 	RGB_LIGHTSKYBLUE1
#define DEF_HIERBOX_SELECT_BG_MONO  	STD_SELECT_BG_MONO
#define DEF_HIERBOX_SELECT_BORDERWIDTH "1"
#define DEF_HIERBOX_SELECT_CMD		(char *)NULL
#define DEF_HIERBOX_SELECT_FOREGROUND 	STD_SELECT_FOREGROUND
#define DEF_HIERBOX_SELECT_FG_MONO  	STD_SELECT_FG_MONO
#define DEF_HIERBOX_SELECT_MODE		"single"
................................................................................
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltShadowOption;
#ifndef NO_TILE
extern Tk_CustomOption bltTileOption;
#endif
extern Tk_CustomOption bltUidOption;

static int StringToButton _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window *tkwin, CONST char *value, char *widgRec,
    int offset));


static char *ButtonToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));


static int StringToImages _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window *tkwin, CONST char *value, char *widgRec,
    int offset));

static char *ImagesToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToScrollMode _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window *tkwin, CONST char *value, char *widgRec,
    int offset));

static char *ScrollModeToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

static int StringToSeparator _ANSI_ARGS_((ClientData clientData,
    Tcl_Interp *interp, Tk_Window *tkwin, CONST char *value, char *widgRec,
    int offset));

static char *SeparatorToString _ANSI_ARGS_((ClientData clientData,
    Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr));

/*
 * Contains a pointer to the widget that's currently being configured.
 * This is used in the custom configuration parse routine for images.
 */
static Hierbox *hierBox;

static Tk_CustomOption imagesOption =
{
    (Tk_OptionParseProc *)StringToImages,
    (Tk_OptionPrintProc *)ImagesToString,
    (ClientData)&hierBox,
};

static Tk_CustomOption buttonOption =
{
    (Tk_OptionParseProc *)StringToButton,
    (Tk_OptionPrintProc *)ButtonToString,
    (ClientData)0,
};

static Tk_CustomOption scrollModeOption =
{
    (Tk_OptionParseProc *)StringToScrollMode,
    (Tk_OptionPrintProc *)ScrollModeToString,
    (ClientData)0,
};

static Tk_CustomOption separatorOption = 
{
    (Tk_OptionParseProc *)StringToSeparator,
    (Tk_OptionPrintProc *)SeparatorToString,
    (ClientData)0,
};

/*
 * CachedImage --
 *
 *	Since instances of the same Tk image can be displayed in
 *	different windows with possibly different color palettes, Tk
 *	internally stores each instance in a linked list.  But if
 *	the instances are used in the same widget and therefore use
................................................................................
	int nNames;
	char **nameArr;

	if (Tcl_SplitList(interp, string, &nNames, &nameArr) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (nNames > 0) {
	    int i;

	    imageArr = Blt_Malloc(sizeof(CachedImage *) * (nNames + 1));
	    assert(imageArr);
	    for (i = 0; i < nNames; i++) {
		imageArr[i] = GetCachedImage(hboxPtr, interp, tkwin, nameArr[i]);
		if (imageArr[i] == NULL) {
		    result = TCL_ERROR;
................................................................................
		}
	    }
	    Blt_Free(nameArr);
	    imageArr[nNames] = NULL;
	}
    }
    if (*imagePtrPtr != NULL) {
	CachedImage *imagePtr;

	for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) {
	    FreeCachedImage(hboxPtr, *imagePtr);
	}
	Blt_Free(*imagePtrPtr);
    }
    *imagePtrPtr = imageArr;
................................................................................
{
    CachedImage **imagePtrPtr = (CachedImage **) (widgRec + offset);
    Tcl_DString dString;
    char *result;

    Tcl_DStringInit(&dString);
    if (*imagePtrPtr != NULL) {
	CachedImage *imagePtr;

	for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) {
	    Tcl_DStringAppendElement(&dString, 
			     Blt_NameOfImage((*imagePtr)->tkImage));
	}
    }
    result = Blt_Strdup(Tcl_DStringValue(&dString));
................................................................................
    if (buttonPtr->activeGC != NULL) {
	Tk_FreeGC(hboxPtr->display, buttonPtr->activeGC);
    }
    buttonPtr->activeGC = newGC;

    buttonPtr->width = buttonPtr->height = ODD(buttonPtr->reqSize);
    if (buttonPtr->images != NULL) {
	int i;

	for (i = 0; i < 2; i++) {
	    if (buttonPtr->images[i] == NULL) {
		break;
	    }
	    if (buttonPtr->width < ImageWidth(buttonPtr->images[i])) {
		buttonPtr->width = ImageWidth(buttonPtr->images[i]);
................................................................................
}

static void
DestroyEntry(entryPtr)
    Entry *entryPtr;
{
    Hierbox *hboxPtr = entryPtr->hboxPtr;
    CachedImage *imagePtr;

    Tk_FreeOptions(entryConfigSpecs, (char *)entryPtr, hboxPtr->display, 0);
    if (entryPtr->labelGC != NULL) {
	Tk_FreeGC(hboxPtr->display, entryPtr->labelGC);
    }
    if (entryPtr->dataGC != NULL) {
	Tk_FreeGC(hboxPtr->display, entryPtr->dataGC);
................................................................................
    }
    Blt_Free(entryPtr);
}

/*ARGSUSED*/
static Tree *
LastNode(treePtr, mask)
    Tree *treePtr;
    unsigned int mask;
{
    Blt_ChainLink *linkPtr;

    if (treePtr->parentPtr == NULL) {
	return NULL;		/* The root is the first node. */
    }
................................................................................
	linkPtr = Blt_ChainLastLink(treePtr->chainPtr);
    }
    return treePtr;
}

static void
ExposeAncestors(treePtr)
    Tree *treePtr;
{
    treePtr = treePtr->parentPtr;
    while (treePtr != NULL) {
	treePtr->entryPtr->flags |= (ENTRY_OPEN | ENTRY_MAPPED);
	treePtr = treePtr->parentPtr;
    }
}

static int
IsBefore(t1Ptr, t2Ptr)
    Tree *t1Ptr, *t2Ptr;
{
    int depth;
    int i;
    Blt_ChainLink *linkPtr;
    Tree *treePtr;

    depth = MIN(t1Ptr->level, t2Ptr->level);

    if (depth == 0) {		/* One of the nodes is root. */
	if (t1Ptr->parentPtr == NULL) {
................................................................................
	}
    }
    return 0;
}

static int
IsHidden(treePtr)
    Tree *treePtr;
{
    if (treePtr != NULL) {
	unsigned int mask;

	if (!(treePtr->entryPtr->flags & ENTRY_MAPPED)) {
	    return TRUE;
	}
................................................................................
static void
GetFullPath(treePtr, separator, resultPtr)
    Tree *treePtr;
    char *separator;
    Tcl_DString *resultPtr;
{
    char **nameArr;		/* Used the stack the component names. */
    int i;
    int level;

    level = treePtr->level;
    nameArr = Blt_Malloc((level + 1) * sizeof(char *));
    assert(nameArr);
    for (i = level; i >= 0; i--) {
	/* Save the name of each ancestor in the name array. */
................................................................................
    Tree *parentPtr;
    char *name;
{
    Blt_Uid nameId;

    nameId = Blt_FindUid(name);
    if (nameId != NULL) {
	Tree *treePtr;
	Blt_ChainLink *linkPtr;

	/* The component identifier must already exist if the node exists. */
	for (linkPtr = Blt_ChainFirstLink(parentPtr->chainPtr); linkPtr != NULL;
	    linkPtr = Blt_ChainNextLink(linkPtr)) {
	    treePtr = Blt_ChainGetValue(linkPtr);
	    if (nameId == treePtr->nameId) {
................................................................................
    int *levelPtr;
    char ***compPtrPtr;
{
    int skipLen, pathLen;
    char *sep;
    int level, listSize;
    char **components;
    char *p;

    skipLen = strlen(hboxPtr->separator);
    path = SkipSeparators(path, hboxPtr->separator, skipLen);
    pathLen = strlen(path);

    level = pathLen / skipLen;
    listSize = (level + 1) * sizeof(char *);
................................................................................
 */
static Tree *
FindPath(hboxPtr, rootPtr, path)
    Hierbox *hboxPtr;
    Tree *rootPtr;
    char *path;
{
    char *p;
    int skip;
    char *sep;
    Tree *treePtr;
    char save;

    /* Trim off characters that we don't want */
    if (hboxPtr->trimLeft != NULL) {
	char *s;

	/* Trim off leading character string if one exists. */
	for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) {
	    if (*p != *s) {
		break;
	    }
	}
................................................................................
    }
    if (hboxPtr->separator == SEPARATOR_NONE) { 
	return FindComponent(rootPtr, path);
    } 
    if (hboxPtr->separator == SEPARATOR_LIST) {
	char **nameArr;
	int nComp;
	int i;

	/*
	 * No separator, so this must be a Tcl list of components.
	 */
	if (Tcl_SplitList(hboxPtr->interp, path, &nComp, &nameArr)
	    != TCL_OK) {
	    return NULL;
................................................................................
/*ARGSUSED*/
static Tree *
NearestNode(hboxPtr, x, y, selectOne)
    Hierbox *hboxPtr;
    int x, y;
    int selectOne;
{
    Tree *lastPtr, **treePtrPtr;
    Entry *entryPtr;

    /*
     * We implicitly can pick only visible entries.  So make sure that
     * the tree exists.
     */
    if (hboxPtr->nVisible == 0) {
	return NULL;
................................................................................
PercentSubst(hboxPtr, treePtr, command, resultPtr)
    Hierbox *hboxPtr;
    Tree *treePtr;
    char *command;
    Tcl_DString *resultPtr;
{
    Tcl_DString dString;
    char *last, *p;

    /*
     * Get the full path name of the node, in case we need to
     * substitute for it.
     */
    GetFullPath(treePtr, hboxPtr->separator, &dString);
    Tcl_DStringInit(resultPtr);
................................................................................
 *----------------------------------------------------------------------
 */
static int
SelectRange(hboxPtr, fromPtr, toPtr)
    Hierbox *hboxPtr;
    Tree *fromPtr, *toPtr;
{
    Tree *treePtr;
    IterProc *proc;

    /* From the range determine the direction to select entries. */
    proc = (IsBefore(toPtr, fromPtr)) ? LastNode : NextNode;
    for (treePtr = fromPtr; treePtr != NULL;
	 treePtr = (*proc)(treePtr, ENTRY_OPEN | ENTRY_MAPPED)) {
	SelectNode(hboxPtr, treePtr);
................................................................................
    Tree *treePtr;

    Blt_ListAppend(list, (char *)object, 0);
    treePtr = (Tree *) object;
    if (treePtr->entryPtr->tags != NULL) {
	int nNames;
	char **names;
	char **p;

	if (Tcl_SplitList((Tcl_Interp *)NULL, treePtr->entryPtr->tags, &nNames,
		&names) == TCL_OK) {
	    for (p = names; *p != NULL; p++) {
		Blt_ListAppend(list, Tk_GetUid(*p), 0);
	    }
	    Blt_Free(names);
................................................................................
    hierBox = hboxPtr;
    if (Blt_ConfigureWidget(hboxPtr->interp, hboxPtr->tkwin, entryConfigSpecs,
	    argc, argv, (char *)entryPtr, flags) != TCL_OK) {
	return TCL_ERROR;
    }
    entryPtr->iconWidth = entryPtr->iconHeight = 0;
    if (entryPtr->icons != NULL) {
	int i;

	for (i = 0; i < 2; i++) {
	    if (entryPtr->icons[i] == NULL) {
		break;
	    }
	    if (entryPtr->iconWidth < ImageWidth(entryPtr->icons[i])) {
		entryPtr->iconWidth = ImageWidth(entryPtr->icons[i]);
................................................................................
    if (entryHeight < height) {
	entryHeight = height;
    }
    entryPtr->labelWidth = width;
    entryPtr->labelHeight = height;
    width = height = 0;
    if (entryPtr->images != NULL) {
	CachedImage *imagePtr;

	for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) {
	    width += ImageWidth(*imagePtr);
	    if (height < ImageHeight(*imagePtr)) {
		height = ImageHeight(*imagePtr);
	    }
	}
................................................................................
    Blt_InitHashTable(&(hboxPtr->selectTable), BLT_ONE_WORD_KEYS);
    Blt_InitHashTable(&(hboxPtr->nodeTable), BLT_ONE_WORD_KEYS);
    Blt_InitHashTable(&(hboxPtr->imageTable), BLT_STRING_KEYS);
    hboxPtr->bindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, 
	PickEntry, GetTags);
    hboxPtr->buttonBindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, 
	PickButton, GetTags);

    Blt_SetWindowInstanceData(tkwin, hboxPtr);

    return hboxPtr;
}

/*
 * ----------------------------------------------------------------------
 *
 * DestroyHierbox --
................................................................................
    if (hboxPtr->iconMask != None) {
	Tk_FreeBitmap(hboxPtr->display, hboxPtr->iconMask);
    }
    if (hboxPtr->iconColor != NULL) {
	Tk_FreeColor(hboxPtr->iconColor);
    }
    if (buttonPtr->images != NULL) {
	CachedImage *imagePtr;

	for (imagePtr = buttonPtr->images; *imagePtr != NULL; imagePtr++) {
	    FreeCachedImage(hboxPtr, *imagePtr);
	}
	Blt_Free(buttonPtr->images);
    }
    if (buttonPtr->activeGC != NULL) {
................................................................................
	Blt_Free(hboxPtr->levelInfo);
    }
    hboxPtr->levelInfo = Blt_Calloc(hboxPtr->depth + 2, sizeof(LevelInfo));
    assert(hboxPtr->levelInfo);
    ComputeWidths(hboxPtr, hboxPtr->rootPtr);
    {
	int sum, width;
	int i;

	sum = 0;
	for (i = 0; i <= hboxPtr->depth; i++) {
	    width = hboxPtr->levelInfo[i].width;
	    width |= 0x01;
	    hboxPtr->levelInfo[i].width = width;
	    sum += width;
................................................................................
static int
ComputeVisibleEntries(hboxPtr)
    Hierbox *hboxPtr;
{
    Entry *entryPtr;
    int height;
    Blt_ChainLink *linkPtr;
    Tree *treePtr;
    int x, maxX;
    int nSlots;

    hboxPtr->xOffset = Blt_AdjustViewport(hboxPtr->xOffset, hboxPtr->worldWidth,
	VPORTWIDTH(hboxPtr), hboxPtr->xScrollUnits, hboxPtr->scrollMode);
    hboxPtr->yOffset = Blt_AdjustViewport(hboxPtr->yOffset,
	hboxPtr->worldHeight, VPORTHEIGHT(hboxPtr), hboxPtr->yScrollUnits,
	hboxPtr->scrollMode);

    height = VPORTHEIGHT(hboxPtr);

    /* Allocate worst case number of slots for entry array. */
    nSlots = (height / hboxPtr->minHeight) + 3;
    if (hboxPtr->visibleArr != NULL) {
	Blt_Free(hboxPtr->visibleArr);
    }
    hboxPtr->visibleArr = Blt_Calloc(nSlots, sizeof(Tree *));
    assert(hboxPtr->visibleArr);
    hboxPtr->nVisible = 0;

    /* Find the node where the view port starts. */
................................................................................
    TextStyle ts;
    TextLayout *textPtr;
    Tk_FontMetrics fontMetrics;
    int nBytes;
    int sum;
    Entry *entryPtr;
    TextFragment *fragPtr;
    int i;

    entryPtr = treePtr->entryPtr;
    font = GETFONT(hboxPtr, entryPtr->labelFont);
    memset(&ts, 0, sizeof(TextStyle));
    ts.font = font;
    ts.justify = TK_JUSTIFY_LEFT;
    ts.shadow.offset = entryPtr->labelShadow.offset;
................................................................................
	int count;

	gc = (treePtr == hboxPtr->activeButtonPtr)
	    ? buttonPtr->activeGC : buttonPtr->normalGC;
	count = 1;
	segArr[0].y1 = segArr[0].y2 = y + height / 2;
	segArr[0].x1 = x + BUTTON_IPAD;
#if defined(WIN32) && !defined(PLATFORM_SDL)
	segArr[0].x2 = x + width - BUTTON_IPAD;
#else
	segArr[0].x2 = x + width - BUTTON_IPAD - 1;
#endif
	if (!(entryPtr->flags & ENTRY_OPEN)) {
	    segArr[1].x1 = segArr[1].x2 = x + width / 2;
	    segArr[1].y1 = y + BUTTON_IPAD;
#if defined(WIN32) && !defined(PLATFORM_SDL)
	    segArr[1].y2 = y + height - BUTTON_IPAD;
#else
	    segArr[1].y2 = y + height - BUTTON_IPAD - 1;
#endif
	    count++;
	}
	XDrawSegments(hboxPtr->display, drawable, gc, segArr, count);
................................................................................
    Drawable drawable;		/* Pixmap or window to draw into. */
{
    Entry *entryPtr = treePtr->entryPtr;
    /*
     * Auxillary data: text string or images.
     */
    if (entryPtr->images != NULL) {
	CachedImage *imagePtr;
	int imageY;

	for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) {
	    imageY = y;
	    if (ImageHeight(*imagePtr) < entryHeight) {
		imageY += (entryHeight - ImageHeight(*imagePtr)) / 2;
	    }
................................................................................
    {
	Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->border, 0, 0,
	    Tk_Width(hboxPtr->tkwin), Tk_Height(hboxPtr->tkwin), 0,
	    TK_RELIEF_FLAT);
    }

    if (hboxPtr->nVisible > 0) {
	Tree **treePtrPtr;

	if (hboxPtr->activePtr != NULL) {
	    int y, height;

	    y = SCREENY(hboxPtr, hboxPtr->activePtr->entryPtr->worldY);
	    height = MAX(hboxPtr->activePtr->entryPtr->iconHeight, 
		hboxPtr->activePtr->entryPtr->labelHeight);
................................................................................
BboxOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    Tree *treePtr;
    int i;
    Entry *entryPtr;
    char string[200];
    int width, height, yBot;
    int left, top, right, bottom;
    int screen;

    if (hboxPtr->flags & HIERBOX_LAYOUT) {
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Tree *rootPtr;
    unsigned int flags;
    int i;

    flags = 0;
    if (argc > 2) {
	int length;

	length = strlen(argv[2]);
	if ((argv[2][0] == '-') && (length > 1) &&
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    int nIds, nOpts;
    char **options;
    int i;
    Tree *treePtr;


    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
................................................................................
    TextLayout *textPtr;
    Tk_FontMetrics fontMetrics;
    TextFragment *fragPtr;
    int nBytes;
    Entry *entryPtr;
    Tree *treePtr;
    int lineNum;
    int i;

    treePtr = hboxPtr->focusPtr;
    entryPtr = treePtr->entryPtr;

    if (*entryPtr->labelText == '\0') {
	return 0;
    }
................................................................................
	/* Find the character underneath the pointer. */
	nBytes = Tk_MeasureChars(font, fragPtr->text, fragPtr->count, x, 0,
	    &newX);
	if ((newX < x) && (nBytes < fragPtr->count)) {
	    double fract;
	    int length, charSize;
	    char *next;




	    Tcl_UniChar dummy;

	    next = fragPtr->text + nBytes;
	    length = Tcl_UtfToUniChar(next, &dummy);




	    charSize = Tk_TextWidth(font, next, length);
	    fract = ((double)(x - newX) / (double)charSize);
	    if (ROUND(fract)) {
		nBytes += length;
	    }
	}
    }
................................................................................
static int
FindOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Tree *treePtr;
    Tree *firstPtr, *lastPtr;
    int nMatches, maxMatches;
    char c;
    int length;
    CompareProc *compareProc;
    IterProc *nextProc;
    int invertMatch;		/* normal search mode (matching entries) */
    char *namePattern, *fullPattern;
    char *execCmd;
    int i;
    int result;
    char *pattern;
    char *option;
    char *value;
    Tcl_DString dString, pathString;
    Blt_List optionList;
    Blt_ListNode node;

    invertMatch = FALSE;
    maxMatches = 0;
    execCmd = namePattern = fullPattern = NULL;
    compareProc = ExactCompare;
    nextProc = NextNode;
    optionList = Blt_ListCreate(BLT_STRING_KEYS);
................................................................................
    int argc;
    char **argv;
{
    int fullName;
    Tree *treePtr;
    Tcl_DString dString;
    Tcl_DString pathString;
    int i;

    fullName = FALSE;
    if ((argc > 2) && (argv[2][0] == '-') && (strcmp(argv[2], "-full") == 0)) {
	fullName = TRUE;
	argv++, argc--;
    }
    Tcl_DStringInit(&dString);
................................................................................
    char **argv;
    ApplyProc *proc;
    int *nonMatchPtr;		/* returns: inverted search indicator */
{
    CompareProc *compareProc;
    int invertMatch;		/* normal search mode (matching entries) */
    char *namePattern, *fullPattern;
    int i;
    int length;
    int result;
    char *option, *pattern;
    char *value;
    Tree *treePtr;
    char c;
    Blt_List optionList;
    Blt_ListNode node;

    optionList = Blt_ListCreate(BLT_STRING_KEYS);
    invertMatch = FALSE;
    namePattern = fullPattern = NULL;
    compareProc = ExactCompare;
    for (i = 2; i < argc; i++) {
	if (argv[i][0] != '-') {
................................................................................
    char **argv;
{
    Tree *rootPtr, *nodePtr, *parentPtr;
    int position;
    int level, count;
    char *path;
    Tcl_DString dString;
    int i, l;
    int nOpts;
    char **options;
    char **nameArr;

    rootPtr = hboxPtr->rootPtr;
    if ((argv[2][0] == '-') && (strcmp(argv[2], "-at") == 0)) {
	if (StringToNode(hboxPtr, argv[3], &rootPtr) != TCL_OK) {
................................................................................
    nOpts = argc - count;
    options = argv + count;

    Tcl_DStringInit(&dString);
    for (i = 0; i < count; i++) {
	path = argv[i];
	if (hboxPtr->trimLeft != NULL) {
	    char *p, *s;

	    /* Trim off leading character string if one exists. */
	    for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) {
		if (*p != *s) {
		    break;
		}
	    }
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;			/* Not used. */
    char **argv;
{
    ButtonAttributes *buttonPtr = &(hboxPtr->button);
    int x, y;			/* Screen coordinates of the test point. */
    Entry *entryPtr;
    Tree *treePtr;

    if ((Tk_GetPixels(interp, hboxPtr->tkwin, argv[2], &x) != TCL_OK) ||
	(Tk_GetPixels(interp, hboxPtr->tkwin, argv[3], &y) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (hboxPtr->nVisible == 0) {
	return TCL_OK;
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    Tree *rootPtr;
    unsigned int flags;
    int i;

    flags = 0;
    if (argc > 2) {
	int length;

	length = strlen(argv[2]);
	if ((argv[2][0] == '-') && (length > 1) &&
................................................................................
RangeOp(hboxPtr, interp, argc, argv)
    Hierbox *hboxPtr;
    Tcl_Interp *interp;
    int argc;
    char **argv;
{
    Tree *firstPtr, *lastPtr;
    Tree *treePtr;
    unsigned int flags;
    int length;

    flags = 0;
    length = strlen(argv[2]);
    if ((argv[2][0] == '-') && (length > 1) &&
	(strncmp(argv[2], "-open", length) == 0)) {
................................................................................
    Hierbox *hboxPtr;
    Tcl_Interp *interp;		/* Not used. */
    int argc;
    char **argv;
{
    int length;
    Tree *rootPtr;
    int i;
    unsigned int flags;

    flags = 0;
    hboxPtr->sortCmd = NULL;
    for (i = 2; i < argc; i++) {
	if (argv[i][0] != '-') {
	    break;		/* Found start of indices */

Changes to jni/blt/src/bltHtext.c.

44
45
46
47
48
49
50

51
52
53
54
55
56
57
....
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
....
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
....
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
....
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
 * the htext widget is broken in tk8.5.6 as
 * Tk_ConfigureWidget no longer supports
 * queries of changed options. Need to migrate to Tk_SetOptions
 * instead hack a wrapper Blt_ConfigureWidget
 */

#include "bltInt.h"


#ifndef NO_HTEXT
#include <bltChain.h>
#include <bltHash.h>
#ifndef NO_TILE
#include "bltTile.h"
#endif
................................................................................
    textLength = (segPtr->textEnd - segPtr->textStart) + 1;
    if (textLength < 1) {
	return;
    }
    Tk_GetFontMetrics(htPtr->font, &fontMetrics);
    if ((segPtr->textEnd < htPtr->selFirst) ||
	(segPtr->textStart > htPtr->selLast)) {	/* No selected text */
#ifdef TK_DRAWCHARS_ANLGE
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, textLength - 1,
		     x, y + linePtr->baseline, 0.);
#else
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, textLength - 1,
	    x, y + linePtr->baseline);
#endif
	return;
    }
    /*
     *	Text in a segment (with selected text) may have
     *	up to three regions:
     *
     *	1) the text before the start the selection
................................................................................
    curPos = segPtr->textStart;

    if (selStart > segPtr->textStart) {	/* Text preceding selection */
	nChars = (selStart - segPtr->textStart);
	Tk_MeasureChars(htPtr->font, htPtr->charArr + segPtr->textStart,
	    nChars, 10000, DEF_TEXT_FLAGS, &lastX);
	lastX += x;
#ifdef TK_DRAWCHARS_ANGLE
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, nChars, x,
		     y + linePtr->baseline, 0.);
#else
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, nChars, x,
	    y + linePtr->baseline);
#endif
	curPos = selStart;
    }
    if (selLength > 0) {	/* The selection itself */
	int width, nextX;

	Tk_MeasureChars(htPtr->font, htPtr->charArr + selStart,
	    selLength, 10000, DEF_TEXT_FLAGS, &nextX);
................................................................................
	width = (selEnd == linePtr->textEnd)
	    ? htPtr->worldWidth - htPtr->xOffset - lastX :
	    nextX - lastX;
	Blt_Fill3DRectangle(htPtr->tkwin, draw, htPtr->selBorder,
	    lastX, y + linePtr->baseline - fontMetrics.ascent,
	    width, fontMetrics.linespace, htPtr->selBorderWidth,
	    TK_RELIEF_RAISED);
#ifdef TK_DRAWCHARS_ANGLE
	Tk_DrawChars(htPtr->display, draw, htPtr->selectGC,
	    htPtr->font, htPtr->charArr + selStart, selLength,
		     lastX, y + linePtr->baseline, 0.);
#else
	Tk_DrawChars(htPtr->display, draw, htPtr->selectGC,
	    htPtr->font, htPtr->charArr + selStart, selLength,
	    lastX, y + linePtr->baseline);
#endif
	lastX = nextX;
	curPos = selStart + selLength;
    }
    nChars = segPtr->textEnd - curPos;
    if (nChars > 0) {		/* Text following the selection */
#ifdef TK_DRAWCHARS_ANGLE
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
		     htPtr->charArr + curPos, nChars - 1,
		     lastX, y + linePtr->baseline, 0.);
#else
	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + curPos, nChars - 1, lastX, y + linePtr->baseline);
#endif
    }
}

/*
 * ----------------------------------------------------------------------
 *
 * MoveEmbeddedWidget --
................................................................................
    htPtr->maxHeight = HeightOfScreen(screenPtr);
    Blt_InitHashTable(&(htPtr->widgetTable), BLT_ONE_WORD_KEYS);

    Tk_CreateSelHandler(tkwin, XA_PRIMARY, XA_STRING, TextSelectionProc,
	htPtr, XA_STRING);
    Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask,
	TextEventProc, htPtr);
#if (TK_MAJOR_VERSION > 4)
    Blt_SetWindowInstanceData(tkwin, htPtr);
#endif
    /*
     * -----------------------------------------------------------------
     *
     *  Create the widget command before configuring the widget. This
     *  is because the "-file" and "-text" options may have embedded
     *  commands that self-reference the widget through the
     *  "$blt_htext(widget)" variable.







>







 







<
<
<
<
<



<







 







<
<
<
<
<



<







 







<
<
<
<
<



<





<

<
<
<
<

<







 







<

<







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
....
2843
2844
2845
2846
2847
2848
2849





2850
2851
2852

2853
2854
2855
2856
2857
2858
2859
....
2874
2875
2876
2877
2878
2879
2880





2881
2882
2883

2884
2885
2886
2887
2888
2889
2890
....
2892
2893
2894
2895
2896
2897
2898





2899
2900
2901

2902
2903
2904
2905
2906

2907




2908

2909
2910
2911
2912
2913
2914
2915
....
4488
4489
4490
4491
4492
4493
4494

4495

4496
4497
4498
4499
4500
4501
4502
 * the htext widget is broken in tk8.5.6 as
 * Tk_ConfigureWidget no longer supports
 * queries of changed options. Need to migrate to Tk_SetOptions
 * instead hack a wrapper Blt_ConfigureWidget
 */

#include "bltInt.h"
#include "bltTkInt.h"

#ifndef NO_HTEXT
#include <bltChain.h>
#include <bltHash.h>
#ifndef NO_TILE
#include "bltTile.h"
#endif
................................................................................
    textLength = (segPtr->textEnd - segPtr->textStart) + 1;
    if (textLength < 1) {
	return;
    }
    Tk_GetFontMetrics(htPtr->font, &fontMetrics);
    if ((segPtr->textEnd < htPtr->selFirst) ||
	(segPtr->textStart > htPtr->selLast)) {	/* No selected text */





	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, textLength - 1,
	    x, y + linePtr->baseline);

	return;
    }
    /*
     *	Text in a segment (with selected text) may have
     *	up to three regions:
     *
     *	1) the text before the start the selection
................................................................................
    curPos = segPtr->textStart;

    if (selStart > segPtr->textStart) {	/* Text preceding selection */
	nChars = (selStart - segPtr->textStart);
	Tk_MeasureChars(htPtr->font, htPtr->charArr + segPtr->textStart,
	    nChars, 10000, DEF_TEXT_FLAGS, &lastX);
	lastX += x;





	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,
	    htPtr->charArr + segPtr->textStart, nChars, x,
	    y + linePtr->baseline);

	curPos = selStart;
    }
    if (selLength > 0) {	/* The selection itself */
	int width, nextX;

	Tk_MeasureChars(htPtr->font, htPtr->charArr + selStart,
	    selLength, 10000, DEF_TEXT_FLAGS, &nextX);
................................................................................
	width = (selEnd == linePtr->textEnd)
	    ? htPtr->worldWidth - htPtr->xOffset - lastX :
	    nextX - lastX;
	Blt_Fill3DRectangle(htPtr->tkwin, draw, htPtr->selBorder,
	    lastX, y + linePtr->baseline - fontMetrics.ascent,
	    width, fontMetrics.linespace, htPtr->selBorderWidth,
	    TK_RELIEF_RAISED);





	Tk_DrawChars(htPtr->display, draw, htPtr->selectGC,
	    htPtr->font, htPtr->charArr + selStart, selLength,
	    lastX, y + linePtr->baseline);

	lastX = nextX;
	curPos = selStart + selLength;
    }
    nChars = segPtr->textEnd - curPos;
    if (nChars > 0) {		/* Text following the selection */

	Tk_DrawChars(htPtr->display, draw, htPtr->drawGC, htPtr->font,




	    htPtr->charArr + curPos, nChars - 1, lastX, y + linePtr->baseline);

    }
}

/*
 * ----------------------------------------------------------------------
 *
 * MoveEmbeddedWidget --
................................................................................
    htPtr->maxHeight = HeightOfScreen(screenPtr);
    Blt_InitHashTable(&(htPtr->widgetTable), BLT_ONE_WORD_KEYS);

    Tk_CreateSelHandler(tkwin, XA_PRIMARY, XA_STRING, TextSelectionProc,
	htPtr, XA_STRING);
    Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask,
	TextEventProc, htPtr);

    Blt_SetWindowInstanceData(tkwin, htPtr);

    /*
     * -----------------------------------------------------------------
     *
     *  Create the widget command before configuring the widget. This
     *  is because the "-file" and "-text" options may have embedded
     *  commands that self-reference the widget through the
     *  "$blt_htext(widget)" variable.

Changes to jni/blt/src/bltImage.c.

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
...
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
...
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
...
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
....
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
....
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
....
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
....
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
....
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
....
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
....
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
....
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
....
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
....
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
....
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
....
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
....
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
....
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
....
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
....
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
....
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
....
2768
2769
2770
2771
2772
2773
2774
2775
2776

void
Blt_GammaCorrectColorImage(src, newGamma)
    Blt_ColorImage src;
    double newGamma;
{
    unsigned int nPixels;
    register Pix32 *srcPtr, *endPtr;
    register unsigned int i;
    double value;
    unsigned char lut[256];
    double invGamma;

    invGamma = 1.0 / newGamma;
    for (i = 0; i < 256; i++) {
	value = 255.0 * pow((double)i / 255.0, invGamma);
................................................................................
 *
 *----------------------------------------------------------------------
 */
void
Blt_ColorImageToGreyscale(image)
    Blt_ColorImage image;
{
    register Pix32 *srcPtr, *endPtr;
    double Y;
    int nPixels;
    int width, height;

    width = Blt_ColorImageWidth(image);
    height = Blt_ColorImageHeight(image);
    nPixels = width * height;
................................................................................
Blt_PhotoRegionToColorImage(photo, x, y, width, height)
    Tk_PhotoHandle photo;	/* Source photo image to scale */
    int x, y;
    int width, height;
{
    Tk_PhotoImageBlock src;
    Blt_ColorImage image;
    register Pix32 *destPtr;
    register unsigned char *srcData;
    register int offset;
    unsigned int offR, offG, offB, offA;

    Tk_PhotoGetImage(photo, &src);
    if (x < 0) {
	x = 0;
    } 
    if (y < 0) {
................................................................................
Blt_PhotoToColorImage(photo)
    Tk_PhotoHandle photo;	/* Source photo image to scale */

{
    Blt_ColorImage image;
    Tk_PhotoImageBlock src;
    int width, height;
    register Pix32 *destPtr;
    register int offset;
    register int x, y;
    register unsigned char *srcData;

    Tk_PhotoGetImage(photo, &src);
    width = src.width;
    height = src.height;
    image = Blt_CreateColorImage(width, height);
    destPtr = Blt_ColorImageBits(image);
    offset = 0;
................................................................................
 *	message is left in interp->result.
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetResampleFilter(interp, name, filterPtrPtr)
    Tcl_Interp *interp;
    char *name;
    ResampleFilter **filterPtrPtr;
{
    ResampleFilter *filterPtr, *endPtr;

    endPtr = filterTable + nFilters;
    for (filterPtr = filterTable; filterPtr < endPtr; filterPtr++) {
	if (strcmp(name, filterPtr->name) == 0) {
................................................................................
    ResampleFilter *filterPtr;
    Sample **samplePtrPtr;
{
    Sample *samples;
    double scale;
    int filterSize;
    double center;
    register Sample *s;
    register Weight *weight;
    register int x, i;
    register int left, right;	/* filter bounds */
    double factor, sum;
    size_t size;

    /* Pre-calculate filter contributions for a row */
    scale = (double)destWidth / (double)srcWidth;

    if (scale < 1.0) {
................................................................................
    Blt_ColorImage src, dest;
    ResampleFilter *filterPtr;
{
    Sample *samples, *s, *endPtr;
    int destWidth, destHeight;
    int red, green, blue, alpha;
    int srcWidth, srcHeight;
    register Pix32 *srcColumnPtr;
    register Pix32 *srcPtr, *destPtr;
    register Weight *weight;
    int x, i;
    size_t size;		/* Size of sample. */

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
    destWidth = Blt_ColorImageWidth(dest);
    destHeight = Blt_ColorImageHeight(dest);
................................................................................
{
    Sample *samples, *s, *endPtr;
    Weight *weight;
    int destWidth;
    int red, green, blue, alpha;
    int srcWidth, srcHeight;
    int y, i;
    register Pix32 *srcPtr, *destPtr;
    register Pix32 *srcRowPtr;
    size_t size;		/* Size of sample. */

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
    destWidth = Blt_ColorImageWidth(dest);

    /* Pre-calculate filter contributions for a row */
................................................................................
 *	color image. The original photo is left intact.
 *
 *----------------------------------------------------------------------
 */
void
Blt_ResizePhoto(srcPhoto, x, y, width, height, destPhoto)
    Tk_PhotoHandle srcPhoto;	/* Source photo image to scaled. */
    register int x, y;		/* Region of source photo to be
				 * scaled. */
    int width, height;
    Tk_PhotoHandle destPhoto;	/* (out) Resulting scaled photo image.
				 * Scaling factors are derived from
				 * the destination photo's
				 * dimensions. */
{
    double xScale, yScale;
    Blt_ColorImage destImage;
    Pix32 *destPtr;
    Tk_PhotoImageBlock src, dest;
    unsigned char *srcPtr, *srcRowPtr;
    int *mapX, *mapY;
    register int sx, sy;
    int left, right, top, bottom;

    Tk_PhotoGetImage(srcPhoto, &src);
    Tk_PhotoGetImage(destPhoto, &dest);

    left = x, top = y, right = x + width - 1, bottom = y + height - 1;
    destImage = Blt_CreateColorImage(dest.width, dest.height);
................................................................................
 *	is left intact.
 *
 *----------------------------------------------------------------------
 */
Blt_ColorImage
Blt_ResizeColorImage(src, x, y, width, height, destWidth, destHeight)
    Blt_ColorImage src;		/* Source color image to be scaled. */
    register int x, y;		/* Region of source image to scaled. */
    int width, height;
    int destWidth, destHeight;	/* Requested dimensions of the scaled
				 * image. */
{
    register int sx, sy;
    double xScale, yScale;
    Blt_ColorImage dest;
    Pix32 *srcPtr, *srcRowPtr, *destPtr;
    int *mapX, *mapY;
    int left, right, top, bottom;

    left = x, top = y; right = x + width - 1, bottom = y + height - 1;
................................................................................
				   image. */
{
    Blt_ColorImage dest;
    Pix32 *srcPtr, *srcRowPtr, *destPtr;
    double xScale, yScale;
    int *mapX, *mapY;
    int srcWidth, srcHeight;
    register int sx, sy;
    register int x, y;

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);

    xScale = (double)srcWidth / (double)destWidth;
    yScale = (double)srcHeight / (double)destHeight;
    mapX = Blt_Malloc(sizeof(int) * regionWidth);
................................................................................
 */
Blt_ColorImage
Blt_ConvolveColorImage(src, filterPtr)
    Blt_ColorImage src;
    Filter2D *filterPtr;
{
    Blt_ColorImage dest;
    register Pix32 *srcPtr, *destPtr;
#define MAXROWS	24
    register int sx, sy, dx, dy;
    register int x, y;
    double red, green, blue;
    int width, height;
    int radius;
    register double *valuePtr;

    width = Blt_ColorImageWidth(src);
    height = Blt_ColorImageHeight(src);

    dest = Blt_CreateColorImage(width, height);
    radius = (int)filterPtr->support;
    if (radius < 1) {
................................................................................
	destHeight, photoName, inputGamma)
    Tcl_Interp *interp;		/* Interpreter to report errors back to */
    Tk_Window tkwin;
    Drawable drawable;		/* Window or pixmap to be snapped */
    int x, y;			/* Offset of image from drawable origin. */
    int width, height;		/* Dimension of the drawable */
    int destWidth, destHeight;	/* Desired size of the Tk photo */
    char *photoName;		/* Name of an existing Tk photo image. */
    double inputGamma;
{
    Tk_PhotoHandle photo;	/* The photo image to write into. */
    Blt_ColorImage image;

    photo = Blt_FindPhoto(interp, photoName);
    if (photo == NULL) {
................................................................................
    int y;			/* Designates the row to be sheared */
    int offset;			/* Difference between  of  */
    double frac;
    Pix32 bgColor;
{
    Pix32 *srcPtr, *destPtr;
    Pix32 *srcRowPtr, *destRowPtr;
    register int x, dx;
    int destWidth;
    int srcWidth;
    int red, blue, green, alpha;
    int leftRed, leftGreen, leftBlue, leftAlpha;
    int oldLeftRed, oldLeftGreen, oldLeftBlue, oldLeftAlpha;
    int ifrac;

................................................................................
    Blt_ColorImage src, dest;
    int x;			/* Column in source image to be sheared. */
    int offset;			/* Offset of */
    double frac;			/* Fraction of subpixel. */
    Pix32 bgColor;
{
    Pix32 *srcPtr, *destPtr;
    register int y, dy;
#ifdef notef
    int srcWidth;
    int destWidth;
#endif
    int destHeight;
    int srcHeight;
    int red, blue, green, alpha;
................................................................................
{
    int tmpWidth, tmpHeight;
    int srcWidth, srcHeight;
    double sinTheta, cosTheta, tanTheta;
    double  skewf;
    int skewi;
    Blt_ColorImage tmp1, tmp2, dest;
    register int x, y;

    sinTheta = sin(theta);
    cosTheta = cos(theta);
    tanTheta = tan(theta * 0.5);
    
    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
................................................................................
static Blt_ColorImage
Rotate90(src)
    Blt_ColorImage src;
{
    int width, height, offset;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    register int x, y;

    height = Blt_ColorImageWidth(src);
    width = Blt_ColorImageHeight(src);

    srcPtr = Blt_ColorImageBits(src);
    dest = Blt_CreateColorImage(width, height);
    offset = (height - 1) * width;
................................................................................
static Blt_ColorImage
Rotate180(src)
    Blt_ColorImage src;
{
    int width, height, offset;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    register int x, y;

    width = Blt_ColorImageWidth(src);
    height = Blt_ColorImageHeight(src);
    dest = Blt_CreateColorImage(width, height);

    srcPtr = Blt_ColorImageBits(src);
    offset = (height - 1) * width;
................................................................................
static Blt_ColorImage
Rotate270(src)
    Blt_ColorImage src;
{
    int width, height;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    register int x, y;

    height = Blt_ColorImageWidth(src);
    width = Blt_ColorImageHeight(src);
    dest = Blt_CreateColorImage(width, height);

    srcPtr = Blt_ColorImageBits(src);
    for (x = width - 1; x >= 0; x--) {
................................................................................
/*
 * Build 3-D color histogram of counts, R/G/B, c^2
 */
static ColorImageStatistics *
GetColorImageStatistics(image)
    Blt_ColorImage image;
{
    register int r, g, b;
#define MAX_INTENSITIES	256
    unsigned int sqr[MAX_INTENSITIES];
    int numPixels;
    Pix32 *srcPtr, *endPtr;
    register int i;
    ColorImageStatistics *s;

    s = Blt_Calloc(1, sizeof(ColorImageStatistics));
    assert(s);

    /* Precompute table of squares. */
    for (i = 0; i < MAX_INTENSITIES; i++) {
................................................................................
 *----------------------------------------------------------------------
 */

static void
M3d(s)	/* compute cumulative moments. */
    ColorImageStatistics *s;
{
    register unsigned char i, r, g, b, r0;
    long int line, rLine, gLine, bLine;
    long int area[33], rArea[33], gArea[33], bArea[33];
    unsigned int line2, area2[33];

    for (r = 1, r0 = 0; r <= 32; r++, r0++) {
	for (i = 0; i <= 32; ++i) {
	    area2[i] = area[i] = rArea[i] = gArea[i] = bArea[i] = 0;
................................................................................
Maximize(cubePtr, dir, first, last, cut, rWhole, gWhole, bWhole, wWhole, s)
    Cube *cubePtr;
    unsigned char dir;
    int first, last, *cut;
    long int rWhole, gWhole, bWhole, wWhole;
    ColorImageStatistics *s;
{
    register long int rHalf, gHalf, bHalf, wHalf;
    long int rBase, gBase, bBase, wBase;
    register int i;
    register double temp, max;

    rBase = Bottom(cubePtr, dir, s->mR);
    gBase = Bottom(cubePtr, dir, s->mG);
    bBase = Bottom(cubePtr, dir, s->mB);
    wBase = Bottom(cubePtr, dir, s->wt);
    max = 0.0;
    *cut = -1;
................................................................................
static int
SplitColorSpace(s, cubes, nColors)
    ColorImageStatistics *s;
    Cube *cubes;
    int nColors;
{
    double *vv, temp;
    register int i;
    register int n, k;

    vv = Blt_Malloc(sizeof(double) * nColors);
    assert(vv);
    
    cubes[0].r0 = cubes[0].g0 = cubes[0].b0 = 0;
    cubes[0].r1 = cubes[0].g1 = cubes[0].b1 = 32;
    for (i = 1, n = 0; i < nColors; i++) {
................................................................................
 */
static void
Mark(cubePtr, label, tag)
    Cube *cubePtr;
    int label;
    unsigned int tag[33][33][33];
{
    register int r, g, b;

    for (r = R0 + 1; r <= R1; r++) {
	for (g = G0 + 1; g <= G1; g++) {
	    for (b = B0 + 1; b <= B1; b++) {
		tag[r][g][b] = label;
	    }
	}
................................................................................
    Cube *cubes;
    int nColors;
{
    unsigned int *lut;
    Pix32 color;
    unsigned int red, green, blue;
    unsigned int weight;
    register Cube *cubePtr;
    register int i;

    lut = Blt_Calloc(sizeof(unsigned int), 33 * 33 * 33);
    assert(lut);

    color.Alpha = (unsigned char)-1;
    for (cubePtr = cubes, i = 0; i < nColors; i++, cubePtr++) {
	weight = Volume(cubePtr, s->wt);
................................................................................
char *
Blt_NameOfImage(tkImage)
    Tk_Image tkImage;
{
    Tk_ImageMaster master;

    master = Tk_ImageGetMaster(tkImage);
    return Tk_NameOfImage(master);
}







|
|







 







|







 







|
|
|







 







|
|
|
|







 







|







 







|
|
|
|







 







|
|
|







 







|
|







 







|













|







 







|




|







 







|
|







 







|

|
|



|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|




|







 







|







 







|

|
|







 







|
|







 







|







 







|
|







 







|

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
...
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
...
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
...
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
....
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
....
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
....
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
....
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
....
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
....
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
....
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
....
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
....
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
....
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
....
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
....
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
....
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
....
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
....
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
....
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
....
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
....
2768
2769
2770
2771
2772
2773
2774
2775
2776

void
Blt_GammaCorrectColorImage(src, newGamma)
    Blt_ColorImage src;
    double newGamma;
{
    unsigned int nPixels;
    Pix32 *srcPtr, *endPtr;
    unsigned int i;
    double value;
    unsigned char lut[256];
    double invGamma;

    invGamma = 1.0 / newGamma;
    for (i = 0; i < 256; i++) {
	value = 255.0 * pow((double)i / 255.0, invGamma);
................................................................................
 *
 *----------------------------------------------------------------------
 */
void
Blt_ColorImageToGreyscale(image)
    Blt_ColorImage image;
{
    Pix32 *srcPtr, *endPtr;
    double Y;
    int nPixels;
    int width, height;

    width = Blt_ColorImageWidth(image);
    height = Blt_ColorImageHeight(image);
    nPixels = width * height;
................................................................................
Blt_PhotoRegionToColorImage(photo, x, y, width, height)
    Tk_PhotoHandle photo;	/* Source photo image to scale */
    int x, y;
    int width, height;
{
    Tk_PhotoImageBlock src;
    Blt_ColorImage image;
    Pix32 *destPtr;
    unsigned char *srcData;
    int offset;
    unsigned int offR, offG, offB, offA;

    Tk_PhotoGetImage(photo, &src);
    if (x < 0) {
	x = 0;
    } 
    if (y < 0) {
................................................................................
Blt_PhotoToColorImage(photo)
    Tk_PhotoHandle photo;	/* Source photo image to scale */

{
    Blt_ColorImage image;
    Tk_PhotoImageBlock src;
    int width, height;
    Pix32 *destPtr;
    int offset;
    int x, y;
    unsigned char *srcData;

    Tk_PhotoGetImage(photo, &src);
    width = src.width;
    height = src.height;
    image = Blt_CreateColorImage(width, height);
    destPtr = Blt_ColorImageBits(image);
    offset = 0;
................................................................................
 *	message is left in interp->result.
 *
 *----------------------------------------------------------------------
 */
int
Blt_GetResampleFilter(interp, name, filterPtrPtr)
    Tcl_Interp *interp;
    CONST char *name;
    ResampleFilter **filterPtrPtr;
{
    ResampleFilter *filterPtr, *endPtr;

    endPtr = filterTable + nFilters;
    for (filterPtr = filterTable; filterPtr < endPtr; filterPtr++) {
	if (strcmp(name, filterPtr->name) == 0) {
................................................................................
    ResampleFilter *filterPtr;
    Sample **samplePtrPtr;
{
    Sample *samples;
    double scale;
    int filterSize;
    double center;
    Sample *s;
    Weight *weight;
    int x, i;
    int left, right;	/* filter bounds */
    double factor, sum;
    size_t size;

    /* Pre-calculate filter contributions for a row */
    scale = (double)destWidth / (double)srcWidth;

    if (scale < 1.0) {
................................................................................
    Blt_ColorImage src, dest;
    ResampleFilter *filterPtr;
{
    Sample *samples, *s, *endPtr;
    int destWidth, destHeight;
    int red, green, blue, alpha;
    int srcWidth, srcHeight;
    Pix32 *srcColumnPtr;
    Pix32 *srcPtr, *destPtr;
    Weight *weight;
    int x, i;
    size_t size;		/* Size of sample. */

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
    destWidth = Blt_ColorImageWidth(dest);
    destHeight = Blt_ColorImageHeight(dest);
................................................................................
{
    Sample *samples, *s, *endPtr;
    Weight *weight;
    int destWidth;
    int red, green, blue, alpha;
    int srcWidth, srcHeight;
    int y, i;
    Pix32 *srcPtr, *destPtr;
    Pix32 *srcRowPtr;
    size_t size;		/* Size of sample. */

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
    destWidth = Blt_ColorImageWidth(dest);

    /* Pre-calculate filter contributions for a row */
................................................................................
 *	color image. The original photo is left intact.
 *
 *----------------------------------------------------------------------
 */
void
Blt_ResizePhoto(srcPhoto, x, y, width, height, destPhoto)
    Tk_PhotoHandle srcPhoto;	/* Source photo image to scaled. */
    int x, y;		/* Region of source photo to be
				 * scaled. */
    int width, height;
    Tk_PhotoHandle destPhoto;	/* (out) Resulting scaled photo image.
				 * Scaling factors are derived from
				 * the destination photo's
				 * dimensions. */
{
    double xScale, yScale;
    Blt_ColorImage destImage;
    Pix32 *destPtr;
    Tk_PhotoImageBlock src, dest;
    unsigned char *srcPtr, *srcRowPtr;
    int *mapX, *mapY;
    int sx, sy;
    int left, right, top, bottom;

    Tk_PhotoGetImage(srcPhoto, &src);
    Tk_PhotoGetImage(destPhoto, &dest);

    left = x, top = y, right = x + width - 1, bottom = y + height - 1;
    destImage = Blt_CreateColorImage(dest.width, dest.height);
................................................................................
 *	is left intact.
 *
 *----------------------------------------------------------------------
 */
Blt_ColorImage
Blt_ResizeColorImage(src, x, y, width, height, destWidth, destHeight)
    Blt_ColorImage src;		/* Source color image to be scaled. */
    int x, y;		/* Region of source image to scaled. */
    int width, height;
    int destWidth, destHeight;	/* Requested dimensions of the scaled
				 * image. */
{
    int sx, sy;
    double xScale, yScale;
    Blt_ColorImage dest;
    Pix32 *srcPtr, *srcRowPtr, *destPtr;
    int *mapX, *mapY;
    int left, right, top, bottom;

    left = x, top = y; right = x + width - 1, bottom = y + height - 1;
................................................................................
				   image. */
{
    Blt_ColorImage dest;
    Pix32 *srcPtr, *srcRowPtr, *destPtr;
    double xScale, yScale;
    int *mapX, *mapY;
    int srcWidth, srcHeight;
    int sx, sy;
    int x, y;

    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);

    xScale = (double)srcWidth / (double)destWidth;
    yScale = (double)srcHeight / (double)destHeight;
    mapX = Blt_Malloc(sizeof(int) * regionWidth);
................................................................................
 */
Blt_ColorImage
Blt_ConvolveColorImage(src, filterPtr)
    Blt_ColorImage src;
    Filter2D *filterPtr;
{
    Blt_ColorImage dest;
    Pix32 *srcPtr, *destPtr;
#define MAXROWS	24
    int sx, sy, dx, dy;
    int x, y;
    double red, green, blue;
    int width, height;
    int radius;
    double *valuePtr;

    width = Blt_ColorImageWidth(src);
    height = Blt_ColorImageHeight(src);

    dest = Blt_CreateColorImage(width, height);
    radius = (int)filterPtr->support;
    if (radius < 1) {
................................................................................
	destHeight, photoName, inputGamma)
    Tcl_Interp *interp;		/* Interpreter to report errors back to */
    Tk_Window tkwin;
    Drawable drawable;		/* Window or pixmap to be snapped */
    int x, y;			/* Offset of image from drawable origin. */
    int width, height;		/* Dimension of the drawable */
    int destWidth, destHeight;	/* Desired size of the Tk photo */
    CONST char *photoName;	/* Name of an existing Tk photo image. */
    double inputGamma;
{
    Tk_PhotoHandle photo;	/* The photo image to write into. */
    Blt_ColorImage image;

    photo = Blt_FindPhoto(interp, photoName);
    if (photo == NULL) {
................................................................................
    int y;			/* Designates the row to be sheared */
    int offset;			/* Difference between  of  */
    double frac;
    Pix32 bgColor;
{
    Pix32 *srcPtr, *destPtr;
    Pix32 *srcRowPtr, *destRowPtr;
    int x, dx;
    int destWidth;
    int srcWidth;
    int red, blue, green, alpha;
    int leftRed, leftGreen, leftBlue, leftAlpha;
    int oldLeftRed, oldLeftGreen, oldLeftBlue, oldLeftAlpha;
    int ifrac;

................................................................................
    Blt_ColorImage src, dest;
    int x;			/* Column in source image to be sheared. */
    int offset;			/* Offset of */
    double frac;			/* Fraction of subpixel. */
    Pix32 bgColor;
{
    Pix32 *srcPtr, *destPtr;
    int y, dy;
#ifdef notef
    int srcWidth;
    int destWidth;
#endif
    int destHeight;
    int srcHeight;
    int red, blue, green, alpha;
................................................................................
{
    int tmpWidth, tmpHeight;
    int srcWidth, srcHeight;
    double sinTheta, cosTheta, tanTheta;
    double  skewf;
    int skewi;
    Blt_ColorImage tmp1, tmp2, dest;
    int x, y;

    sinTheta = sin(theta);
    cosTheta = cos(theta);
    tanTheta = tan(theta * 0.5);
    
    srcWidth = Blt_ColorImageWidth(src);
    srcHeight = Blt_ColorImageHeight(src);
................................................................................
static Blt_ColorImage
Rotate90(src)
    Blt_ColorImage src;
{
    int width, height, offset;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    int x, y;

    height = Blt_ColorImageWidth(src);
    width = Blt_ColorImageHeight(src);

    srcPtr = Blt_ColorImageBits(src);
    dest = Blt_CreateColorImage(width, height);
    offset = (height - 1) * width;
................................................................................
static Blt_ColorImage
Rotate180(src)
    Blt_ColorImage src;
{
    int width, height, offset;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    int x, y;

    width = Blt_ColorImageWidth(src);
    height = Blt_ColorImageHeight(src);
    dest = Blt_CreateColorImage(width, height);

    srcPtr = Blt_ColorImageBits(src);
    offset = (height - 1) * width;
................................................................................
static Blt_ColorImage
Rotate270(src)
    Blt_ColorImage src;
{
    int width, height;
    Pix32 *srcPtr, *destPtr;
    Blt_ColorImage dest;
    int x, y;

    height = Blt_ColorImageWidth(src);
    width = Blt_ColorImageHeight(src);
    dest = Blt_CreateColorImage(width, height);

    srcPtr = Blt_ColorImageBits(src);
    for (x = width - 1; x >= 0; x--) {
................................................................................
/*
 * Build 3-D color histogram of counts, R/G/B, c^2
 */
static ColorImageStatistics *
GetColorImageStatistics(image)
    Blt_ColorImage image;
{
    int r, g, b;
#define MAX_INTENSITIES	256
    unsigned int sqr[MAX_INTENSITIES];
    int numPixels;
    Pix32 *srcPtr, *endPtr;
    int i;
    ColorImageStatistics *s;

    s = Blt_Calloc(1, sizeof(ColorImageStatistics));
    assert(s);

    /* Precompute table of squares. */
    for (i = 0; i < MAX_INTENSITIES; i++) {
................................................................................
 *----------------------------------------------------------------------
 */

static void
M3d(s)	/* compute cumulative moments. */
    ColorImageStatistics *s;
{
    unsigned char i, r, g, b, r0;
    long int line, rLine, gLine, bLine;
    long int area[33], rArea[33], gArea[33], bArea[33];
    unsigned int line2, area2[33];

    for (r = 1, r0 = 0; r <= 32; r++, r0++) {
	for (i = 0; i <= 32; ++i) {
	    area2[i] = area[i] = rArea[i] = gArea[i] = bArea[i] = 0;
................................................................................
Maximize(cubePtr, dir, first, last, cut, rWhole, gWhole, bWhole, wWhole, s)
    Cube *cubePtr;
    unsigned char dir;
    int first, last, *cut;
    long int rWhole, gWhole, bWhole, wWhole;
    ColorImageStatistics *s;
{
    long int rHalf, gHalf, bHalf, wHalf;
    long int rBase, gBase, bBase, wBase;
    int i;
    double temp, max;

    rBase = Bottom(cubePtr, dir, s->mR);
    gBase = Bottom(cubePtr, dir, s->mG);
    bBase = Bottom(cubePtr, dir, s->mB);
    wBase = Bottom(cubePtr, dir, s->wt);
    max = 0.0;
    *cut = -1;
................................................................................
static int
SplitColorSpace(s, cubes, nColors)
    ColorImageStatistics *s;
    Cube *cubes;
    int nColors;
{
    double *vv, temp;
    int i;
    int n, k;

    vv = Blt_Malloc(sizeof(double) * nColors);
    assert(vv);
    
    cubes[0].r0 = cubes[0].g0 = cubes[0].b0 = 0;
    cubes[0].r1 = cubes[0].g1 = cubes[0].b1 = 32;
    for (i = 1, n = 0; i < nColors; i++) {
................................................................................
 */
static void
Mark(cubePtr, label, tag)
    Cube *cubePtr;
    int label;
    unsigned int tag[33][33][33];
{
    int r, g, b;

    for (r = R0 + 1; r <= R1; r++) {
	for (g = G0 + 1; g <= G1; g++) {
	    for (b = B0 + 1; b <= B1; b++) {
		tag[r][g][b] = label;
	    }
	}
................................................................................
    Cube *cubes;
    int nColors;
{
    unsigned int *lut;
    Pix32 color;
    unsigned int red, green, blue;
    unsigned int weight;
    Cube *cubePtr;
    int i;

    lut = Blt_Calloc(sizeof(unsigned int), 33 * 33 * 33);
    assert(lut);

    color.Alpha = (unsigned char)-1;
    for (cubePtr = cubes, i = 0; i < nColors; i++, cubePtr++) {
	weight = Volume(cubePtr, s->wt);
................................................................................
char *
Blt_NameOfImage(tkImage)
    Tk_Image tkImage;
{
    Tk_ImageMaster master;

    master = Tk_ImageGetMaster(tkImage);
    return (char *) Tk_NameOfImage(master);
}

Changes to jni/blt/src/bltImage.h.

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
 *
 *      Contains information about a 1-D filter (its support and
 *	the procedure implementing the filter).
 *
 *----------------------------------------------------------------------
 */
typedef struct {
    char *name;			/* Name of the filter */
    ResampleFilterProc *proc;	/* 1-D filter procedure. */
    double support;		/* Width of 1-D filter */
} ResampleFilter;

extern ResampleFilter *bltBoxFilterPtr; /* The ubiquitous box filter */


................................................................................
extern Blt_ColorImage Blt_CreateColorImage _ANSI_ARGS_((int width,int height));

extern Blt_ColorImage Blt_DrawableToColorImage _ANSI_ARGS_((Tk_Window tkwin, 
	Drawable drawable, int x, int y, int width, int height, 
	double inputGamma));

extern int Blt_GetResampleFilter _ANSI_ARGS_((Tcl_Interp *interp,
	char *filterName, ResampleFilter **filterPtrPtr));

extern void Blt_FreeColorImage _ANSI_ARGS_((Blt_ColorImage image));

#if HAVE_JPEG
extern Blt_ColorImage Blt_JPEGToColorImage _ANSI_ARGS_((Tcl_Interp *interp,
	char *fileName));
#endif
................................................................................
	double theta));

extern void Blt_ResizePhoto _ANSI_ARGS_((Tk_PhotoHandle srcPhoto, int x, int y,
	int width, int height, Tk_PhotoHandle destPhoto));

extern int Blt_SnapPhoto _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	Drawable drawable, int x, int y, int width, int height, int destWidth,
	int destHeight, char *photoName, double inputGamma));

extern void Blt_ImageRegion _ANSI_ARGS_((Blt_ColorImage image, 
	Region2D *regionPtr));

extern Region2D *Blt_ColorImageRegion _ANSI_ARGS_((Blt_ColorImage image, 
	Region2D *regionPtr));








|







 







|







 







|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
 *
 *      Contains information about a 1-D filter (its support and
 *	the procedure implementing the filter).
 *
 *----------------------------------------------------------------------
 */
typedef struct {
    CONST char *name;		/* Name of the filter */
    ResampleFilterProc *proc;	/* 1-D filter procedure. */
    double support;		/* Width of 1-D filter */
} ResampleFilter;

extern ResampleFilter *bltBoxFilterPtr; /* The ubiquitous box filter */


................................................................................
extern Blt_ColorImage Blt_CreateColorImage _ANSI_ARGS_((int width,int height));

extern Blt_ColorImage Blt_DrawableToColorImage _ANSI_ARGS_((Tk_Window tkwin, 
	Drawable drawable, int x, int y, int width, int height, 
	double inputGamma));

extern int Blt_GetResampleFilter _ANSI_ARGS_((Tcl_Interp *interp,
	CONST char *filterName, ResampleFilter **filterPtrPtr));

extern void Blt_FreeColorImage _ANSI_ARGS_((Blt_ColorImage image));

#if HAVE_JPEG
extern Blt_ColorImage Blt_JPEGToColorImage _ANSI_ARGS_((Tcl_Interp *interp,
	char *fileName));
#endif
................................................................................
	double theta));

extern void Blt_ResizePhoto _ANSI_ARGS_((Tk_PhotoHandle srcPhoto, int x, int y,
	int width, int height, Tk_PhotoHandle destPhoto));

extern int Blt_SnapPhoto _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	Drawable drawable, int x, int y, int width, int height, int destWidth,
	int destHeight, CONST char *photoName, double inputGamma));

extern void Blt_ImageRegion _ANSI_ARGS_((Blt_ColorImage image, 
	Region2D *regionPtr));

extern Region2D *Blt_ColorImageRegion _ANSI_ARGS_((Blt_ColorImage image, 
	Region2D *regionPtr));

Changes to jni/blt/src/bltInit.c.

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406









407
408
409
410
411
412
413
414
415
416
417
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
...
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
 */

#include <bltInt.h>

#define EXACT 0

#ifndef BLT_LIBRARY
#ifdef WIN32
#define BLT_LIBRARY  "c:/Program Files/Tcl/lib/blt"##BLT_VERSION
#else
#define BLT_LIBRARY "unknown"
#endif
#endif

#define BLT_THREAD_KEY		"BLT Initialized"
#define BLT_TCL_CMDS		(1<<0)
#define BLT_TK_CMDS		(1<<1)

double bltNaN;
#if (TCL_MAJOR_VERSION > 7)
Tcl_Obj *bltEmptyStringObjPtr;
#endif

static Tcl_MathProc MinMathProc, MaxMathProc;
static char libPath[1024] =
{
    BLT_LIBRARY
};

................................................................................
    Tcl_DStringFree(&dString);
    if (value == NULL) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

#if (TCL_MAJOR_VERSION > 7)

/*LINTLIBRARY*/
EXPORT int
Blt_Init(interp)
    Tcl_Interp *interp;		/* Interpreter to add extra commands */
{
    int flags;










    flags = (int)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL);
    if ((flags & BLT_TCL_CMDS) == 0) {
	register Tcl_AppInitProc **p;
	Tcl_Namespace *nsPtr;
	Tcl_ValueType args[2];

	/*
	 * Check that the versions of Tcl that have been loaded are
	 * the same ones that BLT was compiled against.
	 */
................................................................................
	    return TCL_ERROR;
	}
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TCL_CMDS));
    }
#ifndef TCL_ONLY
    if ((flags & BLT_TK_CMDS) == 0) {
	register Tcl_AppInitProc **p;
	Tcl_Namespace *nsPtr;

#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
	if (Tcl_PkgPresent(interp, "Tk", TK_VERSION, EXACT) == NULL) {
	    return TCL_OK;
	} 
#else
	if (Tcl_PkgRequire(interp, "Tk", TK_VERSION, EXACT) == NULL) {
	    Tcl_ResetResult(interp);
	    return TCL_OK;
	} 
#endif
	nsPtr = Tcl_CreateNamespace(interp, "blt::tile", NULL, 
			    (Tcl_NamespaceDeleteProc *) NULL);
	if (nsPtr == NULL) {
	    return TCL_ERROR;
................................................................................
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TK_CMDS));
    }
#endif
    return TCL_OK;
}

#else

/*LINTLIBRARY*/
EXPORT int
Blt_Init(interp)
    Tcl_Interp *interp;		/* Interpreter to add extra commands */
{
    int flags;

    flags = (int)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL);
    if ((flags & BLT_TCL_CMDS) == 0) {
	register Tcl_AppInitProc **p;
	Tcl_ValueType args[2];

	/*
	 * Check that the versions of Tcl that have been loaded are
	 * the same ones that BLT was compiled against.
	 */
	if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, EXACT) == NULL) {
	    return TCL_ERROR;
	}
	/* Set the "blt_version", "blt_patchLevel", and "blt_libPath" Tcl
	 * variables. We'll use them in the following script. */
	if ((Tcl_SetVar(interp, "blt_version", BLT_VERSION, 
			TCL_GLOBAL_ONLY) == NULL) ||
	    (Tcl_SetVar(interp, "blt_patchLevel", BLT_PATCH_LEVEL, 
			TCL_GLOBAL_ONLY) == NULL)) {
	    return TCL_ERROR;
	}
	if (SetLibraryPath(interp) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tcl_Eval(interp, initScript) != TCL_OK) {
	    return TCL_ERROR;
	}
	/* Initialize the BLT commands that only require Tcl. */
	for (p = tclCmds; *p != NULL; p++) {
	    if ((**p) (interp) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	args[0] = args[1] = TCL_EITHER;
	Tcl_CreateMathFunc(interp, "min", 2, args, MinMathProc, (ClientData)0);
	Tcl_CreateMathFunc(interp, "max", 2, args, MaxMathProc, (ClientData)0);
	bltNaN = MakeNaN();
	if (Tcl_PkgProvide(interp, "BLT", BLT_VERSION) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TCL_CMDS));
    }
#ifndef TCL_ONLY
    if ((flags & BLT_TK_CMDS) == 0) {
	register Tcl_AppInitProc **p;

#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) 
	if (Tcl_PkgPresent(interp, "Tk", TK_VERSION, EXACT) == NULL) {
	    return TCL_OK;
	} 
#else
	if (Tcl_PkgRequire(interp, "Tk", TK_VERSION, EXACT) == NULL) {
	    Tcl_ResetResult(interp);
	    return TCL_OK;
	} 
#endif
	/* Initialize the BLT commands that use Tk too. */
	for (p = tkCmds; *p != NULL; p++) {
	    if ((**p) (interp) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
#ifndef NO_EPSCANV
	Blt_InitEpsCanvasItem(interp);
#endif
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TK_CMDS));
    }
#endif
    return TCL_OK;
}

#endif /* TCL_MAJOR_VERION >= 8 */

/*LINTLIBRARY*/
EXPORT int
Blt_SafeInit(interp)
    Tcl_Interp *interp;		/* Interpreter to add extra commands */
{
    return Blt_Init(interp);
}
................................................................................
	Tcl_DStringFree(&dString);
	return cmdToken;	/* Assume command was already initialized */
    }
    cmdToken = Tcl_CreateCommand(interp, cmdPath, specPtr->cmdProc,
	specPtr->clientData, specPtr->cmdDeleteProc);
    Tcl_DStringFree(&dString);

#if (HAVE_NAMESPACES) && (TCL_MAJOR_VERSION > 7)
    {
	Tcl_Namespace *nsPtr;
	int dontResetList = 0;

	nsPtr = Tcl_FindNamespace(interp, nsName, (Tcl_Namespace *)NULL,
	    TCL_LEAVE_ERR_MSG);
	if (nsPtr == NULL) {
	    return NULL;
	}
	if (Tcl_Export(interp, nsPtr, specPtr->name, dontResetList) != TCL_OK) {
	    return NULL;
	}
    }
#endif /* TCL_MAJOR_VERSION > 7 */
    return cmdToken;
}

#if (TCL_MAJOR_VERSION > 7)
/*
 *----------------------------------------------------------------------
 *
 * Blt_InitObjCmd --
 *
 *      Given the name of a command, return a pointer to the
 *      clientData field of the command.
................................................................................
    }
    if (Tcl_Export(interp, nsPtr, specPtr->name, FALSE) != TCL_OK) {
	return NULL;
    }
    return cmdToken;
}

#endif /* TCL_MAJOR_VERSION > 7 */

/*
 *----------------------------------------------------------------------
 *
 * Blt_InitCmds --
 *
 *      Given the name of a command, return a pointer to the
 *      clientData field of the command.







<
<
<

<







<

<







 







<
<






>
>
>
>
>
>
>
>
>



|







 







|


|
|
|
|

|
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|













|



<







 







<
<







27
28
29
30
31
32
33



34

35
36
37
38
39
40
41

42

43
44
45
46
47
48
49
...
386
387
388
389
390
391
392


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
...
494
495
496
497
498
499
500



















































































501
502
503
504
505
506
507
...
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
...
633
634
635
636
637
638
639


640
641
642
643
644
645
646
 */

#include <bltInt.h>

#define EXACT 0

#ifndef BLT_LIBRARY



#define BLT_LIBRARY "unknown"

#endif

#define BLT_THREAD_KEY		"BLT Initialized"
#define BLT_TCL_CMDS		(1<<0)
#define BLT_TK_CMDS		(1<<1)

double bltNaN;

Tcl_Obj *bltEmptyStringObjPtr;


static Tcl_MathProc MinMathProc, MaxMathProc;
static char libPath[1024] =
{
    BLT_LIBRARY
};

................................................................................
    Tcl_DStringFree(&dString);
    if (value == NULL) {
	return TCL_ERROR;
    }
    return TCL_OK;
}



/*LINTLIBRARY*/
EXPORT int
Blt_Init(interp)
    Tcl_Interp *interp;		/* Interpreter to add extra commands */
{
    int flags;

#ifdef USE_TCL_STUBS
    if (!Tcl_InitStubs(interp, "8.4", 0)) {
	return TCL_ERROR;
    }
    Blt_MallocProcPtr = (Blt_MallocProc *)Tcl_Alloc;
    Blt_FreeProcPtr = (Blt_FreeProc *)Tcl_Free;
    Blt_ReallocProcPtr = (Blt_ReallocProc *)Tcl_Realloc;
#endif

    flags = (int)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL);
    if ((flags & BLT_TCL_CMDS) == 0) {
	Tcl_AppInitProc **p;
	Tcl_Namespace *nsPtr;
	Tcl_ValueType args[2];

	/*
	 * Check that the versions of Tcl that have been loaded are
	 * the same ones that BLT was compiled against.
	 */
................................................................................
	    return TCL_ERROR;
	}
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TCL_CMDS));
    }
#ifndef TCL_ONLY
    if ((flags & BLT_TK_CMDS) == 0) {
	Tcl_AppInitProc **p;
	Tcl_Namespace *nsPtr;

#ifdef USE_TK_STUBS
	if (!Tk_InitStubs(interp, "8.4", 0)) {
	    return TCL_ERROR;
	}
#else
	if (Tcl_PkgPresent(interp, "Tk", TK_VERSION, EXACT) == NULL) {

	    return TCL_OK;
	} 
#endif
	nsPtr = Tcl_CreateNamespace(interp, "blt::tile", NULL, 
			    (Tcl_NamespaceDeleteProc *) NULL);
	if (nsPtr == NULL) {
	    return TCL_ERROR;
................................................................................
	Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, 
		(ClientData)(flags | BLT_TK_CMDS));
    }
#endif
    return TCL_OK;
}




















































































/*LINTLIBRARY*/
EXPORT int
Blt_SafeInit(interp)
    Tcl_Interp *interp;		/* Interpreter to add extra commands */
{
    return Blt_Init(interp);
}
................................................................................
	Tcl_DStringFree(&dString);
	return cmdToken;	/* Assume command was already initialized */
    }
    cmdToken = Tcl_CreateCommand(interp, cmdPath, specPtr->cmdProc,
	specPtr->clientData, specPtr->cmdDeleteProc);
    Tcl_DStringFree(&dString);

#if (HAVE_NAMESPACES)
    {
	Tcl_Namespace *nsPtr;
	int dontResetList = 0;

	nsPtr = Tcl_FindNamespace(interp, nsName, (Tcl_Namespace *)NULL,
	    TCL_LEAVE_ERR_MSG);
	if (nsPtr == NULL) {
	    return NULL;
	}
	if (Tcl_Export(interp, nsPtr, specPtr->name, dontResetList) != TCL_OK) {
	    return NULL;
	}
    }
#endif
    return cmdToken;
}


/*
 *----------------------------------------------------------------------
 *
 * Blt_InitObjCmd --
 *
 *      Given the name of a command, return a pointer to the
 *      clientData field of the command.
................................................................................
    }
    if (Tcl_Export(interp, nsPtr, specPtr->name, FALSE) != TCL_OK) {
	return NULL;
    }
    return cmdToken;
}



/*
 *----------------------------------------------------------------------
 *
 * Blt_InitCmds --
 *
 *      Given the name of a command, return a pointer to the
 *      clientData field of the command.

Changes to jni/blt/src/bltInt.h.

21
22
23
24
25
26
27





28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
...
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
...
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723

724




725
726
727
728
729
730
731
732
733
734
...
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757
758
...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
...
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */

#ifndef _BLT_INT_H
#define _BLT_INT_H






#ifdef WIN32
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef STRICT
#undef WIN32_LEAN_AND_MEAN
#include <windowsx.h>
#endif /* WIN32 */

#define USE_NON_CONST
#include <tcl.h>
#define USE_COMPOSITELESS_PHOTO_PUT_BLOCK 
#include <tk.h>

#define _VERSION(a,b,c)	    (((a) << 16) + ((b) << 8) + (c))
#define TCL_VERSION_NUMBER _VERSION(TCL_MAJOR_VERSION, TCL_MINOR_VERSION, TCL_RELEASE_SERIAL)
#define TK_VERSION_NUMBER _VERSION(TK_MAJOR_VERSION, TK_MINOR_VERSION, TK_RELEASE_SERIAL)

#include "bltTkInt.h"

#include <stdio.h>
#include <assert.h>

#if defined(WIN32) && !defined(__GNUC__)
#include "bltWinConfig.h"
................................................................................
#define	assert(EX) (void)((EX) || (Blt_Assert(#EX, __FILE__, __LINE__), 0))
#else
#define	assert(EX) (void)((EX) || (Blt_Assert("EX", __FILE__, __LINE__), 0))
#endif /* __STDC__ */

#endif /* NDEBUG */

#if (TCL_MAJOR_VERSION >= 8)
extern Tcl_Obj *bltEmptyStringObjPtr;
#endif /* TCL_MAJOR_VERSION >= 8 */

/*
 * ----------------------------------------------------------------------
 *
 * Blt_CmdSpec --
 *
 * ----------------------------------------------------------------------
................................................................................
typedef struct {
    char *name;			/* Name of command */
    Tcl_CmdProc *cmdProc;
    Tcl_CmdDeleteProc *cmdDeleteProc;
    ClientData clientData;
} Blt_CmdSpec;

#if (TCL_MAJOR_VERSION >= 8)
/*
 * ----------------------------------------------------------------------
 *
 * Blt_CmdSpec --
 *
 * ----------------------------------------------------------------------
 */
typedef struct {
    char *name;			/* Name of command */
    Tcl_ObjCmdProc *cmdProc;
    Tcl_CmdDeleteProc *cmdDeleteProc;
    ClientData clientData;
} Blt_ObjCmdSpec;

#endif /* TCL_MAJOR_VERSION >= 8 */

/*
 * ----------------------------------------------------------------------
 *
 * Blt_Op --
 *
 * 	Generic function prototype of CmdOptions.
 *
................................................................................

} Blt_OpIndex;

#define BLT_OP_LINEAR_SEARCH	1
#define BLT_OP_BINARY_SEARCH	0

extern Blt_Op Blt_GetOp _ANSI_ARGS_((Tcl_Interp *interp, int nSpecs, 
	Blt_OpSpec *specArr, int operPos, int argc, char **argv, int flags));

#if (TCL_VERSION_NUMBER >= _VERSION(8,0,0)) 
extern Blt_Op Blt_GetOpFromObj _ANSI_ARGS_((Tcl_Interp *interp,
	int nSpecs, Blt_OpSpec *specArr, int operPos, int objc, 
	Tcl_Obj *CONST *objv, int flags));
#endif

/*
 * ----------------------------------------------------------------------
 *
 *	Assume we need to declare free if there's no stdlib.h or malloc.h
 *
 * ----------------------------------------------------------------------
................................................................................
#define STD_SELECT_FOREGROUND	RGB_BLACK
#define STD_SELECT_FG_MONO	RGB_WHITE
#define STD_SHADOW_COLOR	RGB_GREY64
#define STD_SHADOW_MONO		RGB_BLACK

#define LineWidth(w)	(((w) > 1) ? (w) : 0)

#ifdef TCL_UTF_MAX
#define HAVE_UTF	1
#else
#define HAVE_UTF	0
#endif /* TCL_UTF_MAX */

typedef char *DestroyData;
 

#ifndef TK_RELIEF_SOLID
#define TK_RELIEF_SOLID		TK_RELIEF_FLAT
#endif

/*
 * Tcl/Tk Backward compatibility section.
 */
#if (TCL_MAJOR_VERSION > 7)

#define NO_FLAGS			0
#define Blt_FindPhoto(interp, name)	Tk_FindPhoto(interp, name)

#else

#define Tcl_GetStringResult(interp)	((interp)->result)
#define Blt_FindPhoto(interp, name)	Tk_FindPhoto(name)

#define Tcl_DeleteCommandFromToken(interp, token) \
	Tcl_DeleteCommand(interp, Tcl_GetCommandName(interp, token))

/*
 *--------------------------------------------------------------
 *
 * The definitions below provide foreward compatibility for
 * functions and types related to event handling that used to
 * be in Tk but have moved to Tcl.
 *
 *--------------------------------------------------------------
 */

#define Tcl_IdleProc		Tk_IdleProc
#define Tcl_FileProc		Tk_FileProc
#define Tcl_TimerProc		Tk_TimerProc
#define Tcl_TimerToken		Tk_TimerToken

#define Tcl_BackgroundError	Tk_BackgroundError
#define Tcl_CancelIdleCall	Tk_CancelIdleCall

#define Tcl_CreateTimerHandler	Tk_CreateTimerHandler
#define Tcl_DeleteTimerHandler	Tk_DeleteTimerHandler
#define Tcl_DoOneEvent		Tk_DoOneEvent
#define Tcl_DoWhenIdle		Tk_DoWhenIdle
#define Tcl_Sleep		Tk_Sleep

/* Additional stuff that has moved to Tcl: */

#define Tcl_AfterCmd		Tk_AfterCmd
#define Tcl_EventuallyFree	Tk_EventuallyFree
#define Tcl_FreeProc		Tk_FreeProc
#define Tcl_Preserve		Tk_Preserve
#define Tcl_Release		Tk_Release

#endif /* TCL_MAJOR_VERSION > 7 */

typedef int (QSortCompareProc) _ANSI_ARGS_((const void *, const void *));


/*
 * ----------------------------------------------------------------------
 *
 * Blt_Pad --
 *
 * 	Specifies vertical and horizontal padding.
................................................................................

extern char *Blt_Itoa _ANSI_ARGS_((int value));
extern char *Blt_Utoa _ANSI_ARGS_((unsigned int value));
extern char *Blt_Dtoa _ANSI_ARGS_((Tcl_Interp *interp, double value));
extern Tcl_Command Blt_InitCmd _ANSI_ARGS_((Tcl_Interp *interp,
	char *namespace, Blt_CmdSpec *specPtr));

#if (TCL_VERSION_NUMBER >= _VERSION(8,0,0)) 
extern Tcl_Command Blt_InitObjCmd _ANSI_ARGS_((Tcl_Interp *interp,
	char *namespace, Blt_ObjCmdSpec *specPtr));
#if (TCL_VERSION_NUMBER < _VERSION(8,1,0))
extern char *Tcl_GetString _ANSI_ARGS_((Tcl_Obj *objPtr));
extern int Tcl_EvalObjv _ANSI_ARGS_((Tcl_Interp *interp, int objc, 
	Tcl_Obj **objv, int flags));
extern int Tcl_WriteObj _ANSI_ARGS_((Tcl_Channel channel, Tcl_Obj *objPtr));
extern char *Tcl_SetVar2Ex _ANSI_ARGS_((Tcl_Interp *interp, char *part1, 
	char *part2, Tcl_Obj *objPtr, int flags));
extern Tcl_Obj *Tcl_GetVar2Ex _ANSI_ARGS_((Tcl_Interp *interp, char *part1, 
	char *part2, int flags));
#endif /* TCL_VERSION_NUMBER < 8.2.0 */
#endif /* TCL_VERSION_NUMBER >= 8.0.0 */


extern int Blt_InitCmds _ANSI_ARGS_((Tcl_Interp *interp, char *namespace,
	Blt_CmdSpec *specPtr, int nCmds));

extern int Blt_NaturalSpline _ANSI_ARGS_((Point2D *origPts, int nOrigPts, 
	Point2D *intpPts, int nIntpPts));

................................................................................
	int nOrigPts, Extents2D *extsPtr, int isClosed, Point2D *intpPts, 
	int nIntpPts));

extern int Blt_CatromParametricSpline _ANSI_ARGS_((Point2D *origPts, 
	int nOrigPts, Point2D *intpPts, int nIntpPts));

extern int Blt_StringToFlag _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
	int flags));
extern char *Blt_FlagToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *string, int offset, Tcl_FreeProc **freeProc));

extern void Blt_InitHexTable _ANSI_ARGS_((char *table));

extern GC Blt_GetPrivateGC _ANSI_ARGS_((Tk_Window tkwin, unsigned long gcMask,
................................................................................

extern void Blt_RelinkWindow _ANSI_ARGS_((Tk_Window tkwin, Tk_Window newParent,
	int x, int y));

extern Tk_Window Blt_Toplevel _ANSI_ARGS_((Tk_Window tkwin));

extern int Blt_GetPixels _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	char *string, int check, int *valuePtr));
extern int Blt_GetPosition _ANSI_ARGS_((Tcl_Interp *interp, char *string,
	int *indexPtr));
extern int Blt_GetCount _ANSI_ARGS_((Tcl_Interp *interp, char *string,
	int check, int *valuePtr));

extern char *Blt_NameOfFill _ANSI_ARGS_((int fill));

extern int Blt_GetXY _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	char *string, int *x, int *y));

extern Point2D Blt_GetProjection _ANSI_ARGS_((int x, int y, Point2D *p, 
	Point2D *q));

extern void Blt_DrawArrow _ANSI_ARGS_((Display *display, Drawable drawable,
	GC gc, int x, int y, int arrowHeight, int orientation));

extern Tk_OptionParseProc Blt_StringToEnum;
extern Tk_OptionPrintProc Blt_EnumToString;






extern int Blt_ConfigureWidget _ANSI_ARGS_((Tcl_Interp *interp,
       Tk_Window tkwin, Tk_ConfigSpec *specs, int argc, char **argv,
       char *widgRec, int flags));

extern int Blt_ConfigModified _ANSI_ARGS_(TCL_VARARGS(Tk_ConfigSpec *, specs));

extern void Blt_DStringAppendElements _ANSI_ARGS_(TCL_VARARGS(Tcl_DString *, args));

extern void Blt_MakeTransparentWindowExist _ANSI_ARGS_((Tk_Window tkwin,
	Window parent, int isBusy));
................................................................................
extern void Blt_TranslateAnchor _ANSI_ARGS_((int x, int y, int width,
	int height, Tk_Anchor anchor, int *transXPtr, int *transYPtr));

extern Point2D Blt_TranslatePoint _ANSI_ARGS_((Point2D *pointPtr, int width,
	int height, Tk_Anchor anchor));

extern int Blt_ConfigureWidgetComponent _ANSI_ARGS_((Tcl_Interp *interp,

	Tk_Window tkwin, char *name, char *class, Tk_ConfigSpec *specs,
	int argc, char **argv, char *widgRec, int flags));

extern void Blt_HSV _ANSI_ARGS_((XColor *colorPtr, double *huePtr,
	double *valPtr, double *satPtr));

extern void Blt_RGB _ANSI_ARGS_((double hue, double sat, double val,
	XColor *colorPtr));

................................................................................
extern int Blt_AdjustViewport _ANSI_ARGS_((int offset, int worldSize,
	int windowSize, int scrollUnits, int scrollMode));

extern int Blt_GetScrollInfo _ANSI_ARGS_((Tcl_Interp *interp, int argc,
	char **argv, int *offsetPtr, int worldSize, int windowSize,
	int scrollUnits, int scrollMode));

#if (TK_MAJOR_VERSION >= 8) 
extern int Blt_GetScrollInfoFromObj _ANSI_ARGS_((Tcl_Interp *interp, int objc,
	Tcl_Obj *CONST *objv, int *offsetPtr, int worldSize, int windowSize,
	int scrollUnits, int scrollMode));
#endif

extern void Blt_UpdateScrollbar _ANSI_ARGS_((Tcl_Interp *interp,
	char *scrollCmd, double firstFract, double lastFract));

extern int Blt_ReparentWindow _ANSI_ARGS_((Display *display, Window window,
	Window newParent, int x, int y));

................................................................................
 * Define this if you want to be able to tile to the main window "."
 * This will cause a conflict with Tk if you try to compile and link
 * statically.
 */
#undef TILE_MAINWINDOW

#ifdef WIN32
#if (TCL_MAJOR_VERSION == 8)  && (TCL_MINOR_VERSION == 0)
#else
#define NO_DDE		1
#endif
#else 
#define NO_DDE		1
#define NO_PRINTER	1
#endif /* WIN32 */

#if (TCL_MAJOR_VERSION == 7) 
#define NO_TREE		1
#define NO_ARRAY	1
#define NO_TREEVIEW	1
#endif

/* #define NO_TED */

#ifndef NO_BEEP
extern Tcl_AppInitProc Blt_BeepInit;
#endif
#ifndef NO_BGEXEC
extern Tcl_AppInitProc Blt_BgexecInit;
................................................................................
#define Blt_Malloc(size)	(*Blt_MallocProcPtr)(size)
#define Blt_Free		(*Blt_FreeProcPtr)
#define Blt_Realloc(ptr, size)  (*Blt_ReallocProcPtr)(ptr, size)

EXTERN char *Blt_Strdup _ANSI_ARGS_((CONST char *ptr));
EXTERN void *Blt_Calloc _ANSI_ARGS_((unsigned int nElem, size_t size));

#ifdef WIN32
#include "bltWin.h"
#endif

#ifndef WIN32
#define PurifyPrintf  printf
#endif /* WIN32 */
#endif /*_BLT_INT_H*/







>
>
>
>
>










<




<
<
<
<







 







<

<







 







<



|










<
<







 







|
|
|



<







 







<
<
<
<
<
<










<




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<







 







<


<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







|
|

<
<




|







|
|
>

>
>
>
>

|
|







 







>
|
|







 







<



<







 







<
<
<
<
<
<



<
<
<
<
<
<







 







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46




47
48
49
50
51
52
53
...
168
169
170
171
172
173
174

175

176
177
178
179
180
181
182
...
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204


205
206
207
208
209
210
211
...
243
244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
...
358
359
360
361
362
363
364






365
366
367
368
369
370
371
372
373
374

375
376
377
378










































379

380
381
382
383
384
385
386
...
579
580
581
582
583
584
585

586
587












588
589
590
591
592
593
594
...
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
629
630
631
632
633
634
635
636
637
638


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
...
723
724
725
726
727
728
729

730
731
732

733
734
735
736
737
738
739
...
750
751
752
753
754
755
756






757
758
759






760
761
762
763
764
765
766
...
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
 * an action of contract, negligence or other tortuous action, arising
 * out of or in connection with the use or performance of this
 * software.
 */

#ifndef _BLT_INT_H
#define _BLT_INT_H

#if (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 6)
#define Tcl_GetStringResult(interp) interp->result
#define Tcl_SetResult(interp,val,val2) interp->result = val
#endif

#ifdef WIN32
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef STRICT
#undef WIN32_LEAN_AND_MEAN
#include <windowsx.h>
#endif /* WIN32 */


#include <tcl.h>
#define USE_COMPOSITELESS_PHOTO_PUT_BLOCK 
#include <tk.h>





#include "bltTkInt.h"

#include <stdio.h>
#include <assert.h>

#if defined(WIN32) && !defined(__GNUC__)
#include "bltWinConfig.h"
................................................................................
#define	assert(EX) (void)((EX) || (Blt_Assert(#EX, __FILE__, __LINE__), 0))
#else
#define	assert(EX) (void)((EX) || (Blt_Assert("EX", __FILE__, __LINE__), 0))
#endif /* __STDC__ */

#endif /* NDEBUG */


extern Tcl_Obj *bltEmptyStringObjPtr;


/*
 * ----------------------------------------------------------------------
 *
 * Blt_CmdSpec --
 *
 * ----------------------------------------------------------------------
................................................................................
typedef struct {
    char *name;			/* Name of command */
    Tcl_CmdProc *cmdProc;
    Tcl_CmdDeleteProc *cmdDeleteProc;
    ClientData clientData;
} Blt_CmdSpec;


/*
 * ----------------------------------------------------------------------
 *
 * Blt_ObjCmdSpec --
 *
 * ----------------------------------------------------------------------
 */
typedef struct {
    char *name;			/* Name of command */
    Tcl_ObjCmdProc *cmdProc;
    Tcl_CmdDeleteProc *cmdDeleteProc;
    ClientData clientData;
} Blt_ObjCmdSpec;



/*
 * ----------------------------------------------------------------------
 *
 * Blt_Op --
 *
 * 	Generic function prototype of CmdOptions.
 *
................................................................................

} Blt_OpIndex;

#define BLT_OP_LINEAR_SEARCH	1
#define BLT_OP_BINARY_SEARCH	0

extern Blt_Op Blt_GetOp _ANSI_ARGS_((Tcl_Interp *interp, int nSpecs, 
	Blt_OpSpec *specArr, int operPos, int argc, CONST char **argv,
	int flags));

extern Blt_Op Blt_GetOpFromObj _ANSI_ARGS_((Tcl_Interp *interp,
	int nSpecs, Blt_OpSpec *specArr, int operPos, int objc, 
	Tcl_Obj *CONST *objv, int flags));


/*
 * ----------------------------------------------------------------------
 *
 *	Assume we need to declare free if there's no stdlib.h or malloc.h
 *
 * ----------------------------------------------------------------------
................................................................................
#define STD_SELECT_FOREGROUND	RGB_BLACK
#define STD_SELECT_FG_MONO	RGB_WHITE
#define STD_SHADOW_COLOR	RGB_GREY64
#define STD_SHADOW_MONO		RGB_BLACK

#define LineWidth(w)	(((w) > 1) ? (w) : 0)







typedef char *DestroyData;
 

#ifndef TK_RELIEF_SOLID
#define TK_RELIEF_SOLID		TK_RELIEF_FLAT
#endif

/*
 * Tcl/Tk Backward compatibility section.
 */


#define NO_FLAGS			0
#define Blt_FindPhoto(interp, name)	Tk_FindPhoto(interp, name)











































typedef int (QSortCompareProc) _ANSI_ARGS_((const void *, const void *));


/*
 * ----------------------------------------------------------------------
 *
 * Blt_Pad --
 *
 * 	Specifies vertical and horizontal padding.
................................................................................

extern char *Blt_Itoa _ANSI_ARGS_((int value));
extern char *Blt_Utoa _ANSI_ARGS_((unsigned int value));
extern char *Blt_Dtoa _ANSI_ARGS_((Tcl_Interp *interp, double value));
extern Tcl_Command Blt_InitCmd _ANSI_ARGS_((Tcl_Interp *interp,
	char *namespace, Blt_CmdSpec *specPtr));


extern Tcl_Command Blt_InitObjCmd _ANSI_ARGS_((Tcl_Interp *interp,
	char *namespace, Blt_ObjCmdSpec *specPtr));













extern int Blt_InitCmds _ANSI_ARGS_((Tcl_Interp *interp, char *namespace,
	Blt_CmdSpec *specPtr, int nCmds));

extern int Blt_NaturalSpline _ANSI_ARGS_((Point2D *origPts, int nOrigPts, 
	Point2D *intpPts, int nIntpPts));

................................................................................
	int nOrigPts, Extents2D *extsPtr, int isClosed, Point2D *intpPts, 
	int nIntpPts));

extern int Blt_CatromParametricSpline _ANSI_ARGS_((Point2D *origPts, 
	int nOrigPts, Point2D *intpPts, int nIntpPts));

extern int Blt_StringToFlag _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, char *widgRec,
	int flags));
extern char *Blt_FlagToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *string, int offset, Tcl_FreeProc **freeProc));

extern void Blt_InitHexTable _ANSI_ARGS_((char *table));

extern GC Blt_GetPrivateGC _ANSI_ARGS_((Tk_Window tkwin, unsigned long gcMask,
................................................................................

extern void Blt_RelinkWindow _ANSI_ARGS_((Tk_Window tkwin, Tk_Window newParent,
	int x, int y));

extern Tk_Window Blt_Toplevel _ANSI_ARGS_((Tk_Window tkwin));

extern int Blt_GetPixels _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	CONST char *string, int check, int *valuePtr));
extern int Blt_GetPosition _ANSI_ARGS_((Tcl_Interp *interp, CONST char *string,
	int *indexPtr));



extern char *Blt_NameOfFill _ANSI_ARGS_((int fill));

extern int Blt_GetXY _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
	CONST char *string, int *x, int *y));

extern Point2D Blt_GetProjection _ANSI_ARGS_((int x, int y, Point2D *p, 
	Point2D *q));

extern void Blt_DrawArrow _ANSI_ARGS_((Display *display, Drawable drawable,
	GC gc, int x, int y, int arrowHeight, int orientation));

extern int Blt_StringToEnum _ANSI_ARGS_((ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, CONST char *value,
	char *widgRec, int offset));

extern char *Blt_EnumToString _ANSI_ARGS_((ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset,
	Tcl_FreeProc **freeProcPtr));

extern int Blt_ConfigureWidget _ANSI_ARGS_((Tcl_Interp *interp,
	Tk_Window tkwin, Tk_ConfigSpec *specs, int argc, CONST char **argv,
	char *widgRec, int flags));

extern int Blt_ConfigModified _ANSI_ARGS_(TCL_VARARGS(Tk_ConfigSpec *, specs));

extern void Blt_DStringAppendElements _ANSI_ARGS_(TCL_VARARGS(Tcl_DString *, args));

extern void Blt_MakeTransparentWindowExist _ANSI_ARGS_((Tk_Window tkwin,
	Window parent, int isBusy));
................................................................................
extern void Blt_TranslateAnchor _ANSI_ARGS_((int x, int y, int width,
	int height, Tk_Anchor anchor, int *transXPtr, int *transYPtr));

extern Point2D Blt_TranslatePoint _ANSI_ARGS_((Point2D *pointPtr, int width,
	int height, Tk_Anchor anchor));

extern int Blt_ConfigureWidgetComponent _ANSI_ARGS_((Tcl_Interp *interp,
	Tk_Window tkwin, CONST char *name, CONST char *class,
	Tk_ConfigSpec *specs, int argc, CONST char **argv,
	char *widgRec, int flags));

extern void Blt_HSV _ANSI_ARGS_((XColor *colorPtr, double *huePtr,
	double *valPtr, double *satPtr));

extern void Blt_RGB _ANSI_ARGS_((double hue, double sat, double val,
	XColor *colorPtr));

................................................................................
extern int Blt_AdjustViewport _ANSI_ARGS_((int offset, int worldSize,
	int windowSize, int scrollUnits, int scrollMode));

extern int Blt_GetScrollInfo _ANSI_ARGS_((Tcl_Interp *interp, int argc,
	char **argv, int *offsetPtr, int worldSize, int windowSize,
	int scrollUnits, int scrollMode));


extern int Blt_GetScrollInfoFromObj _ANSI_ARGS_((Tcl_Interp *interp, int objc,
	Tcl_Obj *CONST *objv, int *offsetPtr, int worldSize, int windowSize,
	int scrollUnits, int scrollMode));


extern void Blt_UpdateScrollbar _ANSI_ARGS_((Tcl_Interp *interp,
	char *scrollCmd, double firstFract, double lastFract));

extern int Blt_ReparentWindow _ANSI_ARGS_((Display *display, Window window,
	Window newParent, int x, int y));

................................................................................
 * Define this if you want to be able to tile to the main window "."
 * This will cause a conflict with Tk if you try to compile and link
 * statically.
 */
#undef TILE_MAINWINDOW

#ifdef WIN32






#define NO_PRINTER	1
#endif /* WIN32 */







/* #define NO_TED */

#ifndef NO_BEEP
extern Tcl_AppInitProc Blt_BeepInit;
#endif
#ifndef NO_BGEXEC
extern Tcl_AppInitProc Blt_BgexecInit;
................................................................................
#define Blt_Malloc(size)	(*Blt_MallocProcPtr)(size)
#define Blt_Free		(*Blt_FreeProcPtr)
#define Blt_Realloc(ptr, size)  (*Blt_ReallocProcPtr)(ptr, size)

EXTERN char *Blt_Strdup _ANSI_ARGS_((CONST char *ptr));
EXTERN void *Blt_Calloc _ANSI_ARGS_((unsigned int nElem, size_t size));

#if defined(WIN32) && !defined(PLATFORM_SDL)
#include "bltWin.h"
#endif

#ifndef WIN32
#define PurifyPrintf  printf
#endif /* WIN32 */
#endif /*_BLT_INT_H*/

Changes to jni/blt/src/bltList.c.

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
...
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
...
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#include "bltList.h"

static struct Blt_ListNodeStruct *
FindString(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    register struct Blt_ListNodeStruct *nodePtr;
    char c;

    c = key[0];
    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if ((c == nodePtr->key.string[0]) &&
	    (strcmp(key, nodePtr->key.string) == 0)) {
................................................................................
}

static Blt_ListNode
FindOneWord(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    register struct Blt_ListNodeStruct *nodePtr;

    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if (key == nodePtr->key.oneWordValue) {
	    return nodePtr;
	}
    }
................................................................................
}

static Blt_ListNode
FindArray(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    register struct Blt_ListNodeStruct *nodePtr;
    int nBytes;

    nBytes = sizeof(int) * listPtr->type;
    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if (memcmp(key, nodePtr->key.words, nBytes) == 0) {
	    return nodePtr;
................................................................................
 */
/*LINTLIBRARY*/
Blt_ListNode
Blt_ListCreateNode(listPtr, key)
    struct Blt_ListStruct *listPtr;
    CONST char *key;		/* Unique key to reference object */
{
    register struct Blt_ListNodeStruct *nodePtr;
    int keySize;

    if (listPtr->type == BLT_STRING_KEYS) {
	keySize = strlen(key) + 1;
    } else if (listPtr->type == BLT_ONE_WORD_KEYS) {
	keySize = sizeof(int);
    } else {
................................................................................
 */
/*LINTLIBRARY*/
void
Blt_ListReset(listPtr)
    struct Blt_ListStruct *listPtr; /* List to clear */
{
    if (listPtr != NULL) {
	register struct Blt_ListNodeStruct *oldPtr;
	register struct Blt_ListNodeStruct *nodePtr = listPtr->headPtr;

	while (nodePtr != NULL) {
	    oldPtr = nodePtr;
	    nodePtr = nodePtr->nextPtr;
	    FreeNode(oldPtr);
	}
	Blt_ListInit(listPtr, listPtr->type);
................................................................................
Blt_ListNode
Blt_ListGetNthNode(listPtr, position, direction)
    struct Blt_ListStruct *listPtr; /* List to traverse */
    int position;		/* Index of node to select from front
				 * or back of the list. */
    int direction;
{
    register struct Blt_ListNodeStruct *nodePtr;

    if (listPtr != NULL) {
	if (direction > 0) {
	    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
		 nodePtr = nodePtr->nextPtr) {
		if (position == 0) {
		    return nodePtr;
................................................................................
/*LINTLIBRARY*/
void
Blt_ListSort(listPtr, proc)
    struct Blt_ListStruct *listPtr; /* List to traverse */
    Blt_ListCompareProc *proc;
{
    struct Blt_ListNodeStruct **nodeArr;
    register struct Blt_ListNodeStruct *nodePtr;
    register int i;

    if (listPtr->nNodes < 2) {
	return;
    }
    nodeArr = Blt_Malloc(sizeof(Blt_List) * (listPtr->nNodes + 1));
    if (nodeArr == NULL) {
	return;			/* Out of memory. */







|







 







|







 







|







 







|







 







|
|







 







|







 







|
|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
...
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
...
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#include "bltList.h"

static struct Blt_ListNodeStruct *
FindString(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    struct Blt_ListNodeStruct *nodePtr;
    char c;

    c = key[0];
    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if ((c == nodePtr->key.string[0]) &&
	    (strcmp(key, nodePtr->key.string) == 0)) {
................................................................................
}

static Blt_ListNode
FindOneWord(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    struct Blt_ListNodeStruct *nodePtr;

    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if (key == nodePtr->key.oneWordValue) {
	    return nodePtr;
	}
    }
................................................................................
}

static Blt_ListNode
FindArray(listPtr, key)
    struct Blt_ListStruct *listPtr; /* List to search */
    CONST char *key;		/* Key to match */
{
    struct Blt_ListNodeStruct *nodePtr;
    int nBytes;

    nBytes = sizeof(int) * listPtr->type;
    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
	 nodePtr = nodePtr->nextPtr) {
	if (memcmp(key, nodePtr->key.words, nBytes) == 0) {
	    return nodePtr;
................................................................................
 */
/*LINTLIBRARY*/
Blt_ListNode
Blt_ListCreateNode(listPtr, key)
    struct Blt_ListStruct *listPtr;
    CONST char *key;		/* Unique key to reference object */
{
    struct Blt_ListNodeStruct *nodePtr;
    int keySize;

    if (listPtr->type == BLT_STRING_KEYS) {
	keySize = strlen(key) + 1;
    } else if (listPtr->type == BLT_ONE_WORD_KEYS) {
	keySize = sizeof(int);
    } else {
................................................................................
 */
/*LINTLIBRARY*/
void
Blt_ListReset(listPtr)
    struct Blt_ListStruct *listPtr; /* List to clear */
{
    if (listPtr != NULL) {
	struct Blt_ListNodeStruct *oldPtr;
	struct Blt_ListNodeStruct *nodePtr = listPtr->headPtr;

	while (nodePtr != NULL) {
	    oldPtr = nodePtr;
	    nodePtr = nodePtr->nextPtr;
	    FreeNode(oldPtr);
	}
	Blt_ListInit(listPtr, listPtr->type);
................................................................................
Blt_ListNode
Blt_ListGetNthNode(listPtr, position, direction)
    struct Blt_ListStruct *listPtr; /* List to traverse */
    int position;		/* Index of node to select from front
				 * or back of the list. */
    int direction;
{
    struct Blt_ListNodeStruct *nodePtr;

    if (listPtr != NULL) {
	if (direction > 0) {
	    for (nodePtr = listPtr->headPtr; nodePtr != NULL; 
		 nodePtr = nodePtr->nextPtr) {
		if (position == 0) {
		    return nodePtr;
................................................................................
/*LINTLIBRARY*/
void
Blt_ListSort(listPtr, proc)
    struct Blt_ListStruct *listPtr; /* List to traverse */
    Blt_ListCompareProc *proc;
{
    struct Blt_ListNodeStruct **nodeArr;
    struct Blt_ListNodeStruct *nodePtr;
    int i;

    if (listPtr->nNodes < 2) {
	return;
    }
    nodeArr = Blt_Malloc(sizeof(Blt_List) * (listPtr->nNodes + 1));
    if (nodeArr == NULL) {
	return;			/* Out of memory. */

Changes to jni/blt/src/bltMath.h.

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
extern char *strdup _ANSI_ARGS_((CONST char *s));
#endif /* NEED_DECL_STRDUP */

#ifndef HAVE_STRTOLOWER
extern void strtolower _ANSI_ARGS_((char *s));
#endif /* HAVE_STRTOLOWER */

#ifdef NEED_DECL_DRAND48
extern double drand48 _ANSI_ARGS_((void));
extern void srand48 _ANSI_ARGS_((long seed));
#endif /* NEED_DECL_DRAND48 */

#ifdef NEED_DECL_STRCASECMP
extern int strcasecmp _ANSI_ARGS_((CONST char *s1, CONST char *s2));
#endif /* NEED_DECL_STRCASECMP */

#endif /* BLT_MATH_H */







|









182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
extern char *strdup _ANSI_ARGS_((CONST char *s));
#endif /* NEED_DECL_STRDUP */

#ifndef HAVE_STRTOLOWER
extern void strtolower _ANSI_ARGS_((char *s));
#endif /* HAVE_STRTOLOWER */

#if defined(NEED_DECL_DRAND48) || defined(WIN32)
extern double drand48 _ANSI_ARGS_((void));
extern void srand48 _ANSI_ARGS_((long seed));
#endif /* NEED_DECL_DRAND48 */

#ifdef NEED_DECL_STRCASECMP
extern int strcasecmp _ANSI_ARGS_((CONST char *s1, CONST char *s2));
#endif /* NEED_DECL_STRCASECMP */

#endif /* BLT_MATH_H */

Changes to jni/blt/src/bltNsUtil.c.

23
24
25
26
27
28
29



30
31
32
33
34
35
36
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239


240
241
242
243
244
245
246
...
281
282
283
284
285
286
287


288
289
290
291
292
293
294
...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495