This file is indexed.

/usr/share/saods9/src/layout.tcl is in saods9-data 7.3.2+repack-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   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
  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
 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
 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
 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
 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
 591
 592
 593
 594
 595
 596
 597
 598
 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
 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
 690
 691
 692
 693
 694
 695
 696
 697
 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
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 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
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 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
 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
 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
#  Copyright (C) 1999-2014
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

proc CanvasDef {} {
    global canvas
    global ds9

    set canvas(width) 680
    set canvas(height) 450
    set canvas(gap) 4

    switch $ds9(wm) {
	x11 {
	    # this is not fool proof. it does not take into account redirecting
	    # the DISPLAY. There must be a better way.
	    global tcl_platform
	    switch -- $tcl_platform(os) {
		Darwin {set canvas(gap,bottom) 14}
		default {set canvas(gap,bottom) 0}
	    }
	}
	aqua {set canvas(gap,bottom) 14}
	win32 {set canvas(gap,bottom) 0}
    }
}

proc BlinkDef {} {
    global blink
    global iblink
    global pblink

    set iblink(id) 0
    set iblink(index) -1

    set blink(interval) 500

    array set pblink [array get blink]
}

proc TileDef {} {
    global tile
    global itile
    global ptile

    set itile(top) .tile
    set itile(mb) .tilemb

    set tile(mode) grid
    set tile(grid,row) 10
    set tile(grid,col) 10
    set tile(grid,mode) automatic
    set tile(grid,gap) 4

    array set ptile [array get tile]
}

proc ViewDef {} {
    global view
    global pview

    set view(layout) horizontal
    set view(info) 1
    set view(panner) 1
    set view(magnifier) 1
    set view(buttons) 1
    set view(colorbar) 1
    set view(graph,horz) 0
    set view(graph,vert) 0

    set view(info,filename) 1
    set view(info,object) 1
    set view(info,minmax) 0
    set view(info,lowhigh) 0
    set view(info,wcs) 1
    foreach l {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
	set "view(info,wcs$l)" 0
    }
    set view(info,detector) 0
    set view(info,amplifier) 0
    set view(info,physical) 1
    set view(info,image) 1
    set view(info,frame) 1

    array set pview [array get view]
}

# canvas

proc CreateCanvas {} {
    global ds9
    global canvas

    LayoutViewAdjust diff
    set ww [expr $canvas(width)+$diff(x)]
    set hh [expr $canvas(height)+$diff(y)]

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "CreateCanvas $canvas(width) $canvas(height) ${ww}x${hh}"
    }

    set ds9(image) [ttk::frame $ds9(main).f]
    set ds9(canvas) [canvas $ds9(image).c -width $ww -height $hh \
			 -highlightthickness 0 -insertofftime 0 -bg $ds9(bg)]
    grid rowconfigure $ds9(image) 0 -weight 1
    grid columnconfigure $ds9(image) 0 -weight 1
    grid $ds9(canvas) -row 0 -column 0 -sticky news

    # extra space for window tab
    if {$canvas(gap,bottom)>0} {
	set f [frame $ds9(image).b -width 1 -height $canvas(gap,bottom) \
		   -bg $ds9(bg)]
	grid $f -row 1 -column 0 -sticky ew
    }
	
    # needed to realize window so Layout routines will work
    grid $ds9(image)
}

proc InitCanvas {} {
    global ds9

    # Bindings

    bind $ds9(canvas) <Tab> [list NextFrame]
    bind $ds9(canvas) <Shift-Tab> [list PrevFrame]
    switch $ds9(wm) {
	x11 {bind $ds9(canvas) <ISO_Left_Tab> [list PrevFrame]} 
	aqua {}
	win32 {}
    }

    bind $ds9(canvas) <Configure> [list ConfigureView]
    switch $ds9(wm) {
	x11 -
	aqua {
	    bind $ds9(canvas) <Enter> [list focus $ds9(canvas)]
	    bind $ds9(canvas) <Leave> [list focus {}]
	}
	win32 {}
    }
    switch $ds9(wm) {
	x11 {}
	aqua -
	win32 {bind $ds9(canvas) <MouseWheel> [list MouseWheelFrame %x %y %D]}
    }

    # backward compatible bindings
    switch $ds9(wm) {
	x11 -
	win32 {
	    bind $ds9(canvas) <Button-3> {Button3Canvas %x %y}
	    bind $ds9(canvas) <B3-Motion> {Motion3Canvas %x %y}
	    bind $ds9(canvas) <ButtonRelease-3> {Release3Canvas %x %y}
	} 
	aqua {
	    # swap button-2 and button-3 on the mighty mouse
	    bind $ds9(canvas) <Button-2> {Button3Canvas %x %y}
	    bind $ds9(canvas) <B2-Motion> {Motion3Canvas %x %y}
	    bind $ds9(canvas) <ButtonRelease-2> {Release3Canvas %x %y}

	    # x11 command key emulation
	    bind $ds9(canvas) <Command-Button-1> {Button3Canvas %x %y}
	    bind $ds9(canvas) <Command-B1-Motion> {Motion3Canvas %x %y}
	    bind $ds9(canvas) <Command-ButtonRelease-1> {Release3Canvas %x %y}
	}
    }

    # freeze
    bind $ds9(canvas) <f> {ToggleBindEvents}
}

proc Button3Canvas {x y} {
    global ds9

    global debug
    if {$debug(tcl,events)} {
	puts stderr "Button3Canvas"
    }

    set ds9(b3) 1
    Button3Colorbar $x $y
}

proc Motion3Canvas {x y} {
    global debug
    if {$debug(tcl,events)} {
	puts stderr "Motion3Canvas"
    }

    Motion3Colorbar $x $y
}

proc Release3Canvas {x y} {
    global ds9
    global debug
    if {$debug(tcl,events)} {
	puts stderr "Release3Canvas"
    }

    set ds9(b3) 0
    Release3Colorbar $x $y
}

proc UnBindEventsCanvas {} {
    global ds9

    foreach f $ds9(active) {
	UnBindEventsFrame $f
    }
}

proc BindEventsCanvas {} {
    global ds9
    global current

    switch -- $ds9(display) {
	single -
	blink {BindEventsFrame $current(frame)}
	tile {
	    foreach f $ds9(active) {
		BindEventsFrame $f
	    }
	}
    }
}

# view

proc ConfigureView {} {
    global ds9
    global canvas

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "ConfigureView old $canvas(width) $canvas(height)"
    }

    # calculate ds9(canvas) size
    LayoutViewAdjust diff

    # adjust window size
    set canvas(width) [expr [winfo width $ds9(canvas)]-$diff(x)]
    set canvas(height) [expr [winfo height $ds9(canvas)]-$diff(y)]

    if {$debug(tcl,layout)} {
	puts stderr "ConfigureView new $canvas(width) $canvas(height)"
    }

    LayoutView
}

proc UpdateView {} {
    global ds9
    global canvas

    # note: assume canvas(width) and canvas(height) have been set to desired
    # values.

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "UpdateView to $canvas(width) x $canvas(height)"
    }

    # save current size
    set wo [winfo width $ds9(top)]
    set ho [winfo height $ds9(top)]

    # calculate ds9(canvas) size
    LayoutViewAdjust diff

    # adjust window size
    set ww [expr $canvas(width)+$diff(x)]
    set hh [expr $canvas(height)+$diff(y)]

    # determine how much to change
    set wc [winfo width $ds9(canvas)]
    set hc [winfo height $ds9(canvas)]

    set wt [winfo width $ds9(top)]
    set ht [winfo height $ds9(top)]
    
    if {$debug(tcl,layout)} {
	puts stderr "UpdateView before ds9(top) $wt x $ht"
    }

    set w [expr $ww - $wc + $wt]
    set h [expr $hh - $hc + $ht]

    if {$debug(tcl,layout)} {
	puts stderr "UpdateView after ds9(top) $w x $h"
    }

    # change window size
    wm geometry $ds9(top) ${w}x${h}

    LayoutView
}

proc LayoutView {} {
    global view

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "LayoutView"
    }

    switch $view(layout) {
	horizontal {LayoutViewHorz}
	vertical {LayoutViewVert}
    }

    LayoutInfoPanel
    LayoutButtons
    LayoutFrames
    LayoutColorbar
    LayoutGraphs
}

proc LayoutViewAdjust {varname} {
    upvar $varname var

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "LayoutViewAdjust"
    }

    global view
    global colorbar
    global icolorbar
    global igraph
    global canvas
    global ds9

    set var(x) 0
    set var(y) 0

    set cbh [expr $view(colorbar) && \
	     [string equal $colorbar(orientation) {horizontal}]]
    set cbv [expr $view(colorbar) && \
	     [string equal $colorbar(orientation) {vertical}]]
    set grh $view(graph,horz)
    set grv $view(graph,vert)

    if {$colorbar(numerics)} {
	# ww horizontal: tickgap
	set ww 12
	# hh vertical: approx number of numerals to display
	set hh 7

	set icolorbar(horizontal,height) \
	    [expr int($colorbar(size) + $colorbar(font,size)*[tk scaling]+$ww)]

	set icolorbar(vertical,width) \
	    [expr $colorbar(size) + $colorbar(font,size)*$hh]
    } else {
 	set icolorbar(horizontal,height) [expr $colorbar(size) +2]
 	set icolorbar(vertical,width) [expr $colorbar(size) +2]
    }

    # basics
    if {$cbh} {
	incr var(y) $icolorbar(horizontal,height)
    }

    if {$cbv} {
	incr var(x) $icolorbar(vertical,width)
    }

    if {$grh} {
	incr var(y)  $igraph(size)
    }

    if {$grv} {
	incr var(x)  $igraph(size)
    }

    # canvas gap
    if {$cbh || $grh} {
	incr var(y) $canvas(gap)
    }

    if {$cbv || $grv} {
	incr var(x) $canvas(gap)
    }

    # graph gap
    if {$grv && !$cbh} {
	incr var(y) $igraph(gap,y)
    }

    if {$grh && !$cbv} {
	incr var(x) $igraph(gap,x)
    }

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "LayoutViewAdjust $var(x) $var(y)"
    }
}

proc LayoutOrient {} {
    global ds9
    global canvas

    global debug
    if {$debug(tcl,layout)} {
	puts stderr "LayoutOrient"
    }

    # save original canvas size
    set ww $canvas(width)
    set hh $canvas(height)

    # horizontal
    grid rowconfigure $ds9(main) 4 -weight 0
    grid columnconfigure $ds9(main) 0 -weight 0

    # vertical
    grid rowconfigure $ds9(main) 0 -weight 0
    grid columnconfigure $ds9(main) 4 -weight 0

    grid forget $ds9(panel)
    grid forget $ds9(panel,sep)
    grid forget $ds9(buttons)
    grid forget $ds9(buttons,sep)
    grid forget $ds9(image)
    pack forget $ds9(info)
    pack forget $ds9(panner)
    pack forget $ds9(magnifier)

    UpdateView
    update

    # restore original canvas size
    set canvas(width) $ww
    set canvas(height) $hh
    UpdateView
}

proc LayoutViewHorz {} {
    global ds9
    global current
    global view

    # canvas
    grid rowconfigure $ds9(main) 4 -weight 1
    grid columnconfigure $ds9(main) 0 -weight 1
    grid $ds9(image) -row 4 -column 0 -sticky news

    # info panel
    if {$view(info) || $view(magnifier) || $view(panner)} {
	grid $ds9(panel) -row 0 -column 0 -sticky ew -columnspan 3
	$ds9(panel,sep) configure -orient horizontal
	grid $ds9(panel,sep) -row 1 -column 0 -sticky ew -columnspan 3
    } else {
	grid forget $ds9(panel)
	grid forget $ds9(panel,sep)
    }

    if {$view(info)} {
	pack $ds9(info) -side left -anchor nw -padx 2 -pady 2 \
	    -fill x -expand true
    } else {
	pack forget $ds9(info)
    }

    if {$view(panner)} {
	pack $ds9(panner) -side right -padx 2 -pady 2
    } else {
	pack forget $ds9(panner)
    }

    if {$view(magnifier)} {
	pack $ds9(magnifier) -side right -padx 2 -pady 2
	if {$view(panner)} {
	    pack $ds9(magnifier) -before $ds9(panner)
	}
    } else {
	pack forget $ds9(magnifier)
    }

    # buttons
    if {$view(buttons)} {
	grid $ds9(buttons) -row 2 -sticky ew -columnspan 3
	$ds9(buttons,sep) configure -orient horizontal
	grid $ds9(buttons,sep) -row 3 -column 0 -sticky ew -columnspan 3
    } else {
	grid forget $ds9(buttons)
	grid forget $ds9(buttons,sep)
    }
}

proc LayoutViewVert {} {
    global ds9
    global current
    global view

    # canvas
    grid rowconfigure $ds9(main) 0 -weight 1
    grid columnconfigure $ds9(main) 4 -weight 1
    grid $ds9(image) -row 0 -column 4 -sticky news

    # info panel
    if {$view(info) || $view(magnifier) || $view(panner)} {
	grid $ds9(panel) -row 0 -column 0 -sticky ns
	$ds9(panel,sep) configure -orient vertical
	grid $ds9(panel,sep) -row 0 -column 1 -sticky ns
    } else {
	grid forget $ds9(panel)
	grid forget $ds9(panel,sep)
    }

    if {$view(magnifier)} {
	pack $ds9(magnifier) -side top -padx 2 -pady 2
    } else {
	pack forget $ds9(magnifier)
    }

    if {$view(info)} {
	pack $ds9(info) -side top -padx 2 -pady 2 -fill y -expand true
	if {$view(magnifier)} {
	    pack $ds9(info) -after $ds9(magnifier)
	}
    } else {
	pack forget $ds9(info)
    }

    if {$view(panner)} {
	pack $ds9(panner) -side bottom -padx 2 -pady 2
    } else {
	pack forget $ds9(panner)
    }

    # buttons
    if {$view(buttons)} {
	grid $ds9(buttons) -row 0 -column 2 -sticky ns
	$ds9(buttons,sep) configure -orient vertical
	grid $ds9(buttons,sep) -row 0 -column 3 -sticky ns
    } else {
	grid forget $ds9(buttons)
	grid forget $ds9(buttons,sep)
    }
}

proc LayoutFrames {} {
    global ds9
    global current
    global tile
    global view
    global colorbar
    
    # turn everything off
    foreach f $ds9(frames) {
	$f hide
	$f highlite off
	$f panner off
	$f magnifier off
	UnBindEventsFrame $f
    }

    if {$ds9(active,num) > 0} {
	switch -- $ds9(display) {
	    single {TileOne}
	    tile {
		switch -- $tile(mode) {
		    row {TileRect 1 $ds9(active,num) $tile(grid,gap)}
		    column {TileRect $ds9(active,num) 1 $tile(grid,gap)}
		    grid {
			switch -- $tile(grid,mode) {
			    automatic {
				TileRect [expr int(sqrt($ds9(active,num)-1))+1] \
				    [expr int(sqrt($ds9(active,num))+.5)] \
				    $tile(grid,gap)
			    }
			    manual {
				TileRect \
				    $tile(grid,col) \
				    $tile(grid,row) \
				    $tile(grid,gap)
			    }
			}
		    }
		}
	    }
	    blink {TileOne}
	}
    } else {
	set current(frame) {}
	set ds9(next) {}

	# panner
	if {$view(panner)} {
	    panner clear
	}

	# magnifier
	if {$view(magnifier)} {
	    magnifier clear
	}

	# process proper colorbar
	colorbar show
	colorbarrgb hide
	$ds9(canvas) raise colorbar colorbarrgb

	set current(colorbar) colorbar
	set colorbar(map) [colorbar get name]
	set colorbar(invert) [colorbar get invert]

	# update menus/dialogs
	UpdateDS9
    }
}


# This procedure is called when we have only 1 frames to display

proc TileOne {} {
    global ds9
    global view
    global current
    global canvas
    global colorbar

    set ww $canvas(width)
    set hh $canvas(height)

    set xx 0
    set yy 0

    foreach f $ds9(active) {
	$f configure -x $xx -y $yy -width $ww -height $hh -anchor nw
    }

    # only show the current frame
    $current(frame) show
    FrameToFront
}

proc TileRect {numx numy gap} {
    global view
    global canvas

    set ww $canvas(width)
    set hh $canvas(height)

    set w [expr int(($ww-$gap*($numx-1))/$numx)]
    set h [expr int(($hh-$gap*($numy-1))/$numy)]
    
    for {set jj 0} {$jj<$numy} {incr jj} {
	for {set ii 0} {$ii<$numx} {incr ii} {
	    set c [expr $jj*$numx + $ii]
	    set x($c) [expr ($w+$gap)*$ii]
	    set y($c) [expr ($h+$gap)*$jj]
	}
    }

    TileIt $w $h x y [expr $numx*$numy]
}

proc TileIt {ww hh xx yy nn} {
    upvar $xx x
    upvar $yy y
    global ds9
    global current

    set i 0
    foreach f $ds9(active) {
	if {$i<$nn} {
	    $f configure -x $x($i) -y $y($i) -width $ww -height $hh -anchor nw
	    $f show
	    $ds9(canvas) raise $f
	    if {!$ds9(freeze)} {
		BindEventsFrame $f
	    }
	}
	incr i
    }

    # if manual grid, current frame could be not included
    if {$current(frame) != {}} {
	$current(frame) colorbar tag "\{[$current(colorbar) get tag]\}"
    }
    if {$ds9(active,num) > $nn} {
	set current(frame) [lindex $ds9(active) 0]
    }
    FrameToFront
}

proc DisplayDefaultDialog {} {
    global canvas
    global ed

    set w {.defdpy}

    set ed(ok) 0
    set ed(x) $canvas(width)
    set ed(y) $canvas(height)

    DialogCreate $w [msgcat::mc {Display Size}] ed(ok)

    # Param
    set f [ttk::frame $w.param]

    ttk::label $f.xTitle -text {X}
    ttk::label $f.yTitle -text {Y}
    ttk::entry $f.x -textvariable ed(x) -width 10
    ttk::entry $f.y -textvariable ed(y) -width 10
    ttk::label $f.xunit -text [msgcat::mc {Pixels}]
    ttk::label $f.yunit -text [msgcat::mc {Pixels}]
    
    grid $f.xTitle $f.x $f.xunit -padx 2 -pady 2 -sticky w
    grid $f.yTitle $f.y $f.yunit -padx 2 -pady 2 -sticky w

    # Buttons
    set f [ttk::frame $w.buttons]
    ttk::button $f.ok -text [msgcat::mc {OK}] -command {set ed(ok) 1} \
	-default active
    ttk::button $f.cancel -text [msgcat::mc {Cancel}] -command {set ed(ok) 0}
    pack $f.ok $f.cancel -side left -expand true -padx 2 -pady 4

    bind $w <Return> {set ed(ok) 1}

    # Fini
    ttk::separator $w.sep -orient horizontal
    pack $w.buttons $w.sep -side bottom -fill x
    pack $w.param -side top -fill both -expand true

    DialogCenter $w 
    $w.param.x select range 0 end
    DialogWait $w ed(ok) $w.param.x
    DialogDismiss $w

    if {$ed(ok)} {
	set canvas(width) $ed(x)
	set canvas(height) $ed(y)
	UpdateView
    }

    set rr $ed(ok)
    unset ed
    return $rr
}

# Process Cmds

proc ProcessHeightCmd {varname iname} {
    upvar $varname var
    upvar $iname i

    # we need to be realized
    # can't use ProcessRealize
    RealizeDS9

    global canvas
    set canvas(height) [lindex $var $i]
    UpdateView
}

proc ProcessSendHeightCmd {proc id param} {
    global canvas
    $proc $id "$canvas(height)\n"
}

proc ProcessWidthCmd {varname iname} {
    upvar $varname var
    upvar $iname i

    # we need to be realized
    # can't use ProcessRealize
    RealizeDS9

    global canvas
    set canvas(width) [lindex $var $i]
    UpdateView
}

proc ProcessSendWidthCmd {proc id param} {
    global canvas
    $proc $id "$canvas(width)\n"
}

proc ProcessViewCmd {varname iname} {
    upvar $varname var
    upvar $iname i

    global view
    global rgb

    set item [string tolower [lindex $var $i]]

    switch  -- $item {
	layout {
	    incr i
	    set item [string tolower [lindex $var $i]]
	    switch  -- $item {
		horizontal -
		vertical {set view(layout) $item; LayoutOrient}
	    }
	}
	horizontal -
	vertical {
	    # backward compatibility
	    set view(layout) $item
	    LayoutOrient
	}

	default {
	    set yesno [lindex $var [expr $i+1]]
	    switch -- $yesno {
		1 -
		0 -
		yes -
		no -
		on -
		off -
		true -
		false {incr i}
		default {
		    set yesno 1
		}
	    }

	    switch -- $item {
		info -
		panner - 
		magnifier - 
		buttons -
		colorbar {set view($item) [FromYesNo $yesno]}

		colorbarnumerics {
		    # backward compatibility
		    set colorbar(numerics) [FromYesNo $yesno]
		}
		graph {
		    incr i
		    set item [string tolower [lindex $var $i]]
		    switch -- $item {
			horizontal {
			    set yesno [lindex $var [expr $i+1]]
			    switch -- $yesno {
				1 -
				0 -
				yes -
				no -
				on -
				off -
				true -
				false {incr i}
				default {
				    set yesno 1
				}
			    }
			    set view(graph,horz) [FromYesNo $yesno]
			}
			vertical {
			    set yesno [lindex $var [expr $i+1]]
			    switch -- $yesno {
				1 -
				0 -
				yes -
				no -
				on -
				off -
				true -
				false {incr i}
				default {
				    set yesno 1
				}
			    }
			    set view(graph,vert) [FromYesNo $yesno]
			}
		    }
		}
		horzgraph {
		    # backward compatibility
		    set view(graph,horz) [FromYesNo $yesno]
		}
		vertgraph {
		    # backward compatibility
		    set view(graph,vert) [FromYesNo $yesno]
		}

		filename -
		object -
		minmax -
		lowhigh -
		frame -

		detector -
		amplifier -
		physical -
		image -
		wcs -
		wcsa -
		wcsb -
		wcsc -
		wcsd -
		wcse -
		wcsf -
		wcsg -
		wcsh -
		wcsi -
		wcsj -
		wcsk -
		wcsl -
		wcsm -
		wcsn -
		wcso -
		wcsp -
		wcsq -
		wcsr -
		wcss -
		wcst -
		wcsu -
		wcsv -
		wcsw -
		wcsx -
		wcsy -
		wcsz {set view(info,$item) [FromYesNo $yesno]}

		red -
		green -
		blue {set rgb($item) [FromYesNo $yesno]; RGBView}
	    }
	    UpdateView
	}
    }
}

proc ProcessSendViewCmd {proc id param} {
    global view

    switch -- [string tolower [lindex $param 0]] {
	layout {$proc $id "$view(layout)\n"}
	info {$proc $id [ToYesNo $view(info)]}
	panner {$proc $id [ToYesNo $view(panner)]}
	magnifier {$proc $id [ToYesNo $view(magnifier)]}
	buttons {$proc $id [ToYesNo $view(buttons)]}
	colorbar {$proc $id [ToYesNo $view(colorbar)]}
	colorbarnumerics {
	    # backward compatibility
	    $proc $id [ToYesNo $colorbar(numerics)]
	}
	graph {
	    switch -- [string tolower [lindex $param 1]] {
		horizontal {$proc $id [ToYesNo $view(graph,horz)]}
		vertical {$proc $id [ToYesNo $view(graph,vert)]}
	    }
	}
	horzgraph {
	    # backward compatibility
	    $proc $id [ToYesNo $view(graph,horz)]
	}
	vertgraph {
	    # backward compatibility
	    $proc $id [ToYesNo $view(graph,vert)]
	}

	filename {$proc $id [ToYesNo $view(info,filename)]}
	object {$proc $id [ToYesNo $view(info,object)]}
	minmax {$proc $id [ToYesNo $view(info,minmax)]}
	lowhigh {$proc $id [ToYesNo $view(info,lowhigh)]}
	frame {$proc $id [ToYesNo $view(info,frame)]}

	detector {$proc $id [ToYesNo $view(info,detector)]}
	amplifier {$proc $id [ToYesNo $view(info,amplifier)]}
	physical {$proc $id [ToYesNo $view(info,physical)]}
	image {$proc $id [ToYesNo $view(info,image)]}
	wcs {$proc $id [ToYesNo $view(info,wcs)]}
	wcsa {$proc $id [ToYesNo $view(info,wcsa)]}
	wcsb {$proc $id [ToYesNo $view(info,wcsb)]}
	wcsc {$proc $id [ToYesNo $view(info,wcsc)]}
	wcsd {$proc $id [ToYesNo $view(info,wcsd)]}
	wcse {$proc $id [ToYesNo $view(info,wcse)]}
	wcsf {$proc $id [ToYesNo $view(info,wcsf)]}
	wcsg {$proc $id [ToYesNo $view(info,wcsg)]}
	wcsh {$proc $id [ToYesNo $view(info,wcsh)]}
	wcsi {$proc $id [ToYesNo $view(info,wcsi)]}
	wcsj {$proc $id [ToYesNo $view(info,wcsj)]}
	wcsk {$proc $id [ToYesNo $view(info,wcsk)]}
	wcsl {$proc $id [ToYesNo $view(info,wcsl)]}
	wcsm {$proc $id [ToYesNo $view(info,wcsm)]}
	wcsn {$proc $id [ToYesNo $view(info,wcsn)]}
	wcso {$proc $id [ToYesNo $view(info,wcso)]}
	wcsp {$proc $id [ToYesNo $view(info,wcsp)]}
	wcsq {$proc $id [ToYesNo $view(info,wcsq)]}
	wcsr {$proc $id [ToYesNo $view(info,wcsr)]}
	wcss {$proc $id [ToYesNo $view(info,wcss)]}
	wcst {$proc $id [ToYesNo $view(info,wcst)]}
	wcsu {$proc $id [ToYesNo $view(info,wcsu)]}
	wcsv {$proc $id [ToYesNo $view(info,wcsv)]}
	wcsw {$proc $id [ToYesNo $view(info,wcsw)]}
	wcsx {$proc $id [ToYesNo $view(info,wcsx)]}
	wcsy {$proc $id [ToYesNo $view(info,wcsy)]}
	wcsz {$proc $id [ToYesNo $view(info,wcsz)]}
	default {
	    # backward compatibility
	    $proc $id "$view(layout)\n"
	}
    }
}