File: ItemInspector.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (997 lines) | stat: -rw-r--r-- 27,026 bytes parent folder | download | duplicates (4)
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
#  ItemInspector.tcl ---
#  
#      This file is part of The Coccinella application. It lets the user 
#      inspect and configure item options in the canvas.
#      
#  Copyright (c) 1999-2006  Mats Bengtsson
#  
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  
# $Id: ItemInspector.tcl,v 1.17 2008-03-10 14:08:10 matben Exp $

package provide ItemInspector 1.0

namespace eval ::ItemInspector::  {
    
    option add *ItemInspector*Menu.font           CociSmallFont       widgetDefault

    option add *ItemInspector*TLabel.style        Small.TLabel        widgetDefault
    option add *ItemInspector*TLabelframe.style   Small.TLabelframe   widgetDefault
    option add *ItemInspector*TMenubutton.style   Small.TMenubutton   widgetDefault
    option add *ItemInspector*TRadiobutton.style  Small.TRadiobutton  widgetDefault
    option add *ItemInspector*TCheckbutton.style  Small.TCheckbutton  widgetDefault
    option add *ItemInspector*TEntry.style        Small.TEntry        widgetDefault
    option add *ItemInspector*TEntry.font         CociSmallFont       widgetDefault

    # Only the main procedure is exported.
    namespace export ItemInspector
    
    # Maps 0, 1 to and from false, true. Strange in tcl8.3; bezier? boolean?
    variable boolFull2Short
    array set boolFull2Short {false 0 true 1}
        
    # Filter away options that we don't want to be set or displayed.
    variable notWantedOpts
    set notWantedOpts {
	activedash
	activefill
	activeimage
	activeoutline
	activeoutlinestipple
	activestipple
	activewidth
	dashoffset
	disableddash
	disabledfill
	disabledimage
	disabledoutline
	disabledoutlinestipple
	disabledstipple
	disabledwidth
	offset
	outlineoffset
	state
	splinesteps
    }
    
    # For QuickTime movies.
    variable skipMovieOpts
    set skipMovieOpts(std) {
	highlightbackground
	highlightcolor
	highlightthickness
	loadcommand
	mccommand
	resizable
	progressproc
	qtprogress
	qtvrqualitystatic
	qtvrqualitymotion
	swing
	swingspeed
    }
    set skipMovieOpts(qtvr) {
	highlightbackground
	highlightcolor
	highlightthickness
	loadcommand
	mccommand
	resizable
	progressproc
	qtprogress
	swing
	swingspeed
    }
    
    variable uid 0
}

# ItemInspector::ItemInspector --
#
#       Shows options dialog for the selected canvas item.
#   
# Arguments:
#       w           canvas widget
#       which       a valid specifier for a canvas item
#       args        ?-state normal|disabled?
#       
# Results:
#       dialog displayed.

proc ::ItemInspector::ItemInspector {wcan which args} {
        
    # We need to create an item specific instance. 
    # Use the item id for instance.
    set idlist [$wcan find withtag $which]
    if {$idlist == {}}  {
	return
    }
    set w [winfo toplevel $wcan]
    
    # Query the whiteboard's state.
    array set opts [::WB::ConfigureMain $w]
    array set opts $args
    foreach id $idlist {
	set tags [$wcan gettags $id]
	if {[lsearch $tags broken] >= 0} {
	    eval {Broken $wcan $id} [array get opts]
	} else {
	    eval {Build $wcan $id} [array get opts]
	}
    }
}

# ItemInspector::Build --
# 
#       Builds one inspector window for the specified item.
#
# Arguments:
#
#
# Results:
#       dialog window path

proc ::ItemInspector::Build {wcan itemid args} {
    global  prefs fontPoints2Size this wDlgs
    upvar ::WB::dashShort2Full dashShort2Full
    
    set w $wDlgs(iteminsp)$itemid
    
    # If window already there, just return silently.
    if {[winfo exists $w]} {
	raise $w
	return
    }
    set wtoplevel [winfo toplevel $wcan]
    
    # Keep state array for item options etc.
    set token [namespace current]::$itemid
    variable $token
    upvar 0 $token state

    set state(w)      $w
    set state(wcan)   $wcan
    set state(itemid) $itemid
    set state(finished) -1

    # The local namespace variables.
    variable boolFull2Short
    variable notWantedOpts

    array set argsArr {
	-state    normal
    }
    array set argsArr $args
    set canvasState $argsArr(-state)
    
    set nl_ {\\n}
    set utag [::CanvasUtils::GetUtag $wcan $itemid]
    if {$utag == {}}  {
	return
    }
    set state(utag) $utag
    
    # Movies may not be selected this way; temporary solution?
    if {[lsearch [$wcan gettags $utag] "frame"] >= 0}  {
	#return
    }	
    ::UI::Toplevel $w -class ItemInspector  \
      -macstyle documentProc -usemacmainmenu 1 \
      -macclass {document closeBox} \
      -closecommand [list [namespace current]::CloseCmd $token]
    wm title $w [mc "Edit Item"]
    bind $wcan <Destroy> +[list [namespace current]::Cancel $token]
    
    set typWidth 24
        
    # Global frame.
    ttk::frame $w.frall -padding [option get . dialogPadding {}]
    pack  $w.frall  -fill both -expand 1

    set w1 $w.frall.fr1
    ttk::frame $w1 -padding [option get . groupSmallPadding {}]
    pack $w1
    
    # Overall frame for whole container.
    set frtot $w1
    
    # Strings
    set MenuOpts [dict create]
    dict set MenuOpts fill [mc "Fill"]
    dict set MenuOpts none [mc "None"]
    dict set MenuOpts first [mc "First"]
    dict set MenuOpts last [mc "Last"]
    dict set MenuOpts both [mc "Both"]
    dict set MenuOpts butt [mc "Butt"]
    dict set MenuOpts projecting [mc "Projecting"]
    dict set MenuOpts round [mc "Round"]
    dict set MenuOpts bevel [mc "Bevel"]
    dict set MenuOpts miter [mc "Miter"]
    dict set MenuOpts dotted [mc "Dotted"]
    dict set MenuOpts dash-dotted [mc "Dash-dotted"]
    dict set MenuOpts dashed [mc "Dashed"]
    dict set MenuOpts false [mc "False"]
    dict set MenuOpts true [mc "True"]
    dict set MenuOpts gray75 [mc "Gray 75%"]
    dict set MenuOpts gray50 [mc "Gray 50%"]
    dict set MenuOpts gray25 [mc "Gray 25%"]
    dict set MenuOpts gray12 [mc "Gray 12%"]
    dict set MenuOpts pieslice [mc "Pieslice"]
    dict set MenuOpts chord [mc "Chord"]
    dict set MenuOpts arc [mc "Arc"]
    dict set MenuOpts n [mc "N"]
    dict set MenuOpts ne [mc "NE"]
    dict set MenuOpts e [mc "E"]
    dict set MenuOpts se [mc "SE"]
    dict set MenuOpts s [mc "S"]
    dict set MenuOpts sw [mc "SW"]
    dict set MenuOpts w [mc "W"]
    dict set MenuOpts nw [mc "NW"]
    dict set MenuOpts center [mc "Center"]
    dict set MenuOpts normal [mc "Normal"]
    dict set MenuOpts bold [mc "Bold"]
    dict set MenuOpts italic [mc "Italic"]
    dict set MenuOpts left [mc "Left"]
    dict set MenuOpts right [mc "Right"]
    dict set MenuOpts transparent [mc "Transparent"]
    
    # List available options of the option menus.
    array set menuOpts {
	arrow             {none first last both}
	capstyle          {butt projecting round}
	joinstyle         {bevel miter round}
	dash              {none dotted dash-dotted dashed}
	smooth            {false true}
	stipple           {none gray75 gray50 gray25 gray12}
	outlinestipple    {none gray75 gray50 gray25 gray12}
	style             {pieslice chord arc}
	anchor            {n ne e se s sw w nw center}
	fontsize          {1 2 3 4 5 6}
	fontweight        {normal bold italic}
	justify           {left right center}
	fill              {transparent fill}
	outline           {transparent fill}
    }
    set menuOpts(fontfamily) $prefs(canvasFonts)
    
    foreach {key values} [array get menuOpts] {
	set exlist {}
	foreach value $values {
	    if {[dict exists $MenuOpts $value]} {
		lappend exlist $value [dict get $MenuOpts $value]
	    } else {
		lappend exlist $value $value
	    }
	}
	set menuOptsEx($key) $exlist
    }

    set state(allopts) {}

    # Item type.
    set line 0
    set itemType [$wcan type $itemid]
    set state(type)       $itemType
    set state(type,value) $itemType
    set wlabel $frtot.l$line
    set wentry $frtot.e$line
    ttk::label $wlabel -text [mc "Type"]:
    ttk::entry $wentry -width $typWidth -textvariable $token\(type)
    $wentry state {disabled}
    grid  $wlabel  $wentry  -padx 2 -pady 2
    grid  $wlabel  -sticky e
    grid  $wentry  -sticky ew
    set state(type,w) $wentry
    
    # Coordinates.
    set theCoords [$wcan coords $itemid]
    set state(coords) $theCoords
    set state(coords,value) $theCoords
    lappend state(allopts) "coords"
    incr line
    set wlabel $frtot.l$line
    set wentry $frtot.e$line
    ttk::label $wlabel -text [mc "Coordinates"]:
    ttk::entry $wentry -width $typWidth -textvariable $token\(coords)
    $wentry state {disabled}
    grid  $wlabel  $wentry  -padx 2 -pady 2
    grid  $wlabel  -sticky e
    grid  $wentry  -sticky ew
    set state(coords,w) $wentry
        
    # Get all item options. Fonts need special treatment.
    set opts [$wcan itemconfigure $itemid]
    set ind [lsearch $opts "-font*"]
    
    # We have got a font option.
    if {$ind >= 0}  {
	
	# Find the actual values set for the text.
	set fontOpts [lindex $opts $ind 4]
	set opts [lreplace $opts $ind $ind   \
	  [list {-fontfamily} {} {} {} [lindex $fontOpts 0]]  \
	  [list {-fontsize} {} {} {} $fontPoints2Size([lindex $fontOpts 1])]  \
	  [list {-fontweight} {} {} {} [lindex $fontOpts 2]]]
	
	set state(-fontfamily) [lindex $fontOpts 0]
	set state(-fontsize)   $fontPoints2Size([lindex $fontOpts 1])
	set state(-fontweight) [lindex $fontOpts 2]
    }
    
    # Get any cached info for this id. Flat list!
    foreach {key value} [::CanvasUtils::ItemCGet $wtoplevel $itemid] {
	lappend opts [list $key {} {} {} $value]
    }
    
    # Loop over all options.
    foreach opt $opts {
	incr line
	set op  [lindex $opt 0]
	set val [lindex $opt 4]
	set opname [string trimleft $op "-"]
	
	# Skip not wanted options.
	if {[lsearch $notWantedOpts $opname] >= 0} {
	    continue
	}
	set state($op,value) $val
	lappend state(allopts) $op
	
	# If multine text, encode as one line with explicit "\n".
	if {[string equal $op "-text"]}  {
	    regsub -all "\n" $val $nl_ oneliner
	    regsub -all "\r" $oneliner $nl_ oneliner
	    set val $oneliner
	}
    set Op [dict create]
    dict set Op anchor [mc "Anchor"]:
    dict set Op arrow [mc "Arrow"]:
    dict set Op arrowshape [mc "Arrow shape"]:
    dict set Op capstyle [mc "Cap style"]:
    dict set Op dash [mc "Dash"]:
    dict set Op extend [mc "Extend"]:
    dict set Op file [mc "File"]:
    dict set Op fill [mc "Fill"]:
    dict set Op fontfamily [mc "Font familiy"]:
    dict set Op fontsize [mc "Font size"]:
    dict set Op fontweight [mc "Font weight"]:
    dict set Op image [mc "Image"]:
    dict set Op joinstyle [mc "Join style"]:
    dict set Op justify [mc "Justify"]:
    dict set Op outline [mc "Outline"]:
    dict set Op outlinestipple [mc "Outline stipple"]:
    dict set Op tags [mc "Tags"]:
    dict set Op text [mc "Text"]:
    dict set Op smooth [mc "Smooth"]:
    dict set Op stipple [mc "Stipple"]:
    dict set Op style [mc "Style"]:
    dict set Op underline [mc "Underline"]:
    dict set Op width [mc "Width"]:
	ttk::label $frtot.l$line -text [dict get $Op $opname]
	
	# Intercept options for nontext output.
	switch -exact -- $op {
	    -fill        -
	    -outline     {		
		frame $frtot.e$line
		if {$val eq ""}  {
		    set state($op) "transparent"
		} else {
		    set state($op) "fill"
		}
		set wmb    $frtot.menu$line
		set wentry $frtot.ente$line
		set wMenu [eval {
		    ttk::optionmenuex $wmb $token\($op)
		} $menuOptsEx($opname)]
		entry $wentry -width 4 -state disabled -highlightthickness 0
		if {$val ne ""} {
		    set rgb8 {}
		    # winfo rgb . white -> 65535 65535 65535
		    foreach rgb [winfo rgb . $val] {
			lappend rgb8 [expr {$rgb >> 8}]
		    }
		    set val [eval {format "#%02x%02x%02x"} $rgb8]
		    $wentry configure -disabledbackground $val
		}
		pack $wmb    -in $frtot.e$line -side left
		pack $wentry -in $frtot.e$line  \
		  -side left -fill x -expand 1
		if {$canvasState eq "normal"} {
		    bind $wentry <Double-Button-1>   \
		      [list [namespace current]::ChooseItemColor $wentry]
		} else {
		    $wmb state {disabled}
		}
		set state($op,w) $wentry
		set state($op,value) $val
	    } 
	    -tags             -
	    -image            {
		set wentry $frtot.e$line
		ttk::entry $wentry -width $typWidth -textvariable $token\($op)
		$wentry state {disabled}
		set state($op) $val
		set state($op,w) $wentry
		
		# Pure menu options.
	    } 
	    -arrow            -
	    -capstyle         -
	    -dash             -
	    -joinstyle        -
	    -smooth           -
	    -stipple          -
	    -outlinestipple   -
	    -style            -
	    -anchor           -
	    -fontfamily       -
	    -fontsize         -
	    -fontweight       -
	    -justify          {
		if {[string equal $op "-smooth"]}  {
		    
		    # Get full menu name.
		    if {$val eq ""}  {
			set state($op) "false"
		    } else  {
			set state($op) \
			  [string map {0 false 1 true bezier true} $val]
		    }
		} elseif {[string equal $op "-dash"]}  {
		    set state($op) $dashShort2Full($val)
		} else  {
		    if {$val eq ""}  {
			set state($op) "none"
		    } else  {
			set state($op) $val
		    }
		}
		set wmb $frtot.e$line
		set wMenu [eval {
		    ttk::optionmenuex $wmb $token\($op)
		} $menuOptsEx($opname)]
		if {$canvasState eq "disabled"} {
		    $wmb state {disabled}
		}
		set state($op,w) $wmb
	    } 
	    default  {
		
		# Just an editable text entry widget.
		set wentry $frtot.e$line
		ttk::entry $wentry -width $typWidth -textvariable $token\($op)
		if {$canvasState eq "disabled"} {
		    $wentry state {disabled}
		}
		set state($op) $val
		set state($op,w) $wentry
	    }
	}
	grid  $frtot.l$line  $frtot.e$line  -padx 2 -pady 2
	grid  $frtot.l$line  -sticky e
	grid  $frtot.e$line  -sticky ew
    }
    
    incr line
    set lockCmd [list [namespace current]::LockCmd $token]
    ttk::checkbutton $frtot.lock$line -text [mc "Lock this item from being edited"] \
      -variable $token\(locked) -command $lockCmd
    grid  x  $frtot.lock$line  -sticky w
    set state(locked) 0
    if {[::CanvasUtils::IsLocked $wcan $itemid]} {
	set state(locked) 1
    }
    set state(locked,value) $state(locked)
    
    # Button part.
    set saveCmd   [list [namespace current]::Configure $token]
    set cancelCmd [list [namespace current]::Cancel $token]
    set frbot $w.frall.frbot
    ttk::frame $frbot -padding [option get . okcancelTopPadding {}]
    ttk::button $frbot.btsave -text [mc "Save"] -default active \
      -command $saveCmd
    ttk::button $frbot.btcancel -text [mc "Cancel"] -command $cancelCmd
    set padx [option get . buttonPadX {}]
    if {[option get . okcancelButtonOrder {}] eq "cancelok"} {
	pack $frbot.btsave -side right
	pack $frbot.btcancel -side right -padx $padx
    } else {
	pack $frbot.btcancel -side right
	pack $frbot.btsave -side right -padx $padx
    }
    pack $frbot -side bottom -fill x
    
    if {$canvasState eq "disabled"} {
	$frbot.btsave state {disabled}
    }
    set state(wbtsave) $frbot.btsave
    
    wm resizable $w 0 0
    bind $w <Return> [list $frbot.btsave invoke]
    
    return $w
}

proc ::ItemInspector::LockCmd {token} {
    variable $token
    upvar 0 $token state
    
    # We have the possibility here to disable the Save button. Good or Bad?
    if {0} {
	if {$state(locked)} {
	    $state(wbtsave) state {disabled}
	} else {
	    $state(wbtsave) state {!disabled}
	}
    }
}

proc ::ItemInspector::CloseCmd {token w} {
    Cancel $token
}

proc ::ItemInspector::Cancel {token} {
    variable $token
    upvar 0 $token state

    if {[array exists state]} {
	set state(finished) 0
	Close $token
	Free $token
    }
}

# ItemInspector::Configure --
#
#       When the Save button is clicked in the item inspector dialog.
#   
# Arguments:
#
#       
# Results:
#       dialog closed, state freed

proc ::ItemInspector::Configure {token} {
    global  fontPoints2Size fontSize2Points
    
    variable $token
    upvar 0 $token state

    upvar ::WB::dashFull2Short dashFull2Short
    
    set utag $state(utag)
    set type $state(type)
    set wcan $state(wcan)
        
    # Loop through all options. Assemble a configure list.
    set allNewOpts {}
    foreach op $state(allopts) {
	set wname  $state($op,w)
	set opname [string trimleft $op "-"]
	set oldVal $state($op,value)
	set newVal $state($op)
	
	# Intercept options for nontext output.
	switch -- $op {
	    type         -
	    coords       -
	    -file        -
	    -tags        {
		
		# Do nothing
		continue
	    }
	    -fill        -
	    -outline     {		
		if {[string equal $newVal "transparent"]}  {
		    set newVal {}
		} else  {

		    # On MacOSX this can return systemWindowBody which 
		    # fails on other platforms.
		    set newVal [$wname cget -disabledbackground]
		    set rgb8 {}
		    # winfo rgb . white -> 65535 65535 65535
		    foreach rgb [winfo rgb . $newVal] {
			lappend rgb8 [expr {$rgb >> 8}]
		    }
		    set newVal [eval {format "#%02x%02x%02x"} $rgb8]
		}
		
		# Pure menu options.
	    } 
	    -arrow            -
	    -capstyle         -
	    -joinstyle        -
	    -smooth           -
	    -style            -
	    -anchor           -
	    -justify          {	    
		# empty
	    }
	    -fontfamily       {
		set fontFamily $newVal
	    }
	    -fontsize         {
		set fontSize $newVal
	    }
	    -fontweight       {
		set fontWeight $newVal
	    }
	    -dash             {
		if {[string equal $newVal "none"]}  {
		    set newVal {}
		} else  {
		    set newVal $dashFull2Short($newVal)
		}
	    }
	    -stipple          -
	    -outlinestipple   {	    
		if {[string equal $newVal "none"]}  {
		    set newVal {}
		}
	    }
	    default           {
		# empty
	    }
	}
	
	# If new different from old, reconfigure. Reinterpret \n"
	if {![string equal $oldVal $newVal]}  {
	    lappend allNewOpts $op $newVal
	}
    }
    
    # We need to collect all three artificial font options to the real one.
    # Only for the text item type.
    
    if {$type eq "text"}  {
	array set newOptsArr $allNewOpts
	
	# If any font attributes changed, need to collect them all.
	if {[info exists newOptsArr(-fontfamily)] ||     \
	  [info exists newOptsArr(-fontsize)] ||         \
	  [info exists newOptsArr(-fontweight)]}  {
	    set newFontOpts   \
	      [list $fontFamily $fontSize2Points($fontSize) $fontWeight]
	    unset -nocomplain newOptsArr(-fontfamily) \
	      newOptsArr(-fontsize) \
	      newOptsArr(-fontweight)
	    set newOptsArr(-font) $newFontOpts
	    set allNewOpts [array get newOptsArr]
	}
    }
    
    # Do the actual change.
    if {$allNewOpts != {}}  {
	eval {::CanvasUtils::ItemConfigure $wcan $utag} $allNewOpts
    }
    set selected 0
    if {[::CanvasDraw::IsSelected $wcan $utag]} {
	set selected 1
    }
    if {$state(locked,value) != $state(locked)} {
	::CanvasDraw::DeselectItem $wcan $utag
	if {$state(locked)} {
	    ::CanvasUtils::AddTag $wcan $utag "locked"
	} else {
	    ::CanvasUtils::DeleteTag $wcan $utag "locked"
	}
	if {$selected} {
	    ::CanvasDraw::SelectItem $wcan $utag
	}
    }
    set state(finished) 1 
    Close $token
    Free $token
}
    
proc ::ItemInspector::ChooseItemColor {wEntry} {
    
    set col [$wEntry cget -disabledbackground]
    set col [tk_chooseColor -initialcolor $col]
    if {[string length $col] > 0}	 {
	$wEntry configure -disabledbackground $col
    }
}

proc ::ItemInspector::Close {token} {
    variable $token
    upvar 0 $token state

    destroy $state(w)
}

proc ::ItemInspector::Free {token} {
    variable $token
    upvar 0 $token state

    unset -nocomplain state
}

# ItemInspector::Movie --
#
#       As above but for QuickTime movies.
#
#

proc ::ItemInspector::Movie {wcan winfr args} {
    global  wDlgs
    
    variable skipMovieOpts
    variable boolFull2Short
    variable uid

    set w $wDlgs(iteminsp)m[incr uid]
    
    # If window already there, just return silently.
    if {[winfo exists $w]} {
	raise $w
	return
    }
    set wtoplevel [winfo toplevel $wcan]
    
    # Keep state array for item options etc.
    set token [namespace current]::m$uid
    variable $token
    upvar 0 $token state

    set state(w)      $w
    set state(wcan)   $wcan
    set state(finished) -1

    array set argsArr {
	-state    normal
    }
    array set argsArr $args
    set canvasState $argsArr(-state)
    
    if {0} {
	set utag [::CanvasUtils::GetUtag $wcan $itemid]
	if {$utag == {}}  {
	    return
	}
	set state(utag) $utag
    }
    
    ::UI::Toplevel $w -class ItemInspector  \
      -macstyle documentProc -usemacmainmenu 1 \
      -macclass {document closeBox}  \
      -closecommand [list [namespace current]::CloseCmd $token]
    wm title $w {Movie Inspector}
    bind $wcan  <Destroy> +[list [namespace current]::Cancel $token]
    bind $winfr <Destroy> +[list [namespace current]::Cancel $token]
    
    set typWidth 24
    
    set wmov $winfr.m
    set ispano [$wmov ispanoramic]
    set isvisual [$wmov isvisual]
    set type "std"
    if {$ispano} {
	set type "qtvr"
    }
    set state(wmov)  $wmov
    set state(winfr) $winfr
    set state(type)  $type
    
    # Global frame.
    ttk::frame $w.frall -padding [option get . dialogPadding {}]
    pack  $w.frall  -fill both -expand 1

    set w1 $w.frall.fr1
    ttk::frame $w1 -padding [option get . groupSmallPadding {}]
    pack $w1
    
    # Overall frame for whole container.
    set frtot $w1
    
    # Loop over all options.
    set i 0
    
    foreach opt [$wmov configure] {
	set op  [lindex $opt 0]
	set val [lindex $opt 4]
	set opname [string trimleft $op "-"]
	if {[lsearch $skipMovieOpts($type) $opname] >= 0} {
	    continue
	}
	if {!$isvisual && ($op eq "-height" || $op eq "-width")} {
	    continue
	}
	set state($op,isbool) 0
	lappend state(allopts) $op
	incr i
	ttk::label $frtot.l$i -text [string totitle "$opname:"]
	
	switch -- $op {
	    -controller     - 
	    -custombutton   - 
	    -loadintoram    - 
	    -loopstate      -
	    -mcedit         - 
	    -palindromeloopstate {
		set wmb $frtot.e$i
		set state($op) $val
		set wMenu [ttk::optionmenuex $wmb $token\($op)  \
		  1 [mc "True"] 0 [mc "False"]]
		if {$canvasState eq "disabled"} {
		    $wmb state disabled
		}
		set state($op,value) $state($op)
		set state($op,w) $wmb
		set state($op,isbool) 1
	    }
	    default {
		set wentry $frtot.e$i
		ttk::entry $wentry -width $typWidth -textvariable $token\($op)

		switch -- $op {
		    -file - -url {
			$wentry configure -state disabled
		    }
		}
		if {$canvasState eq "disabled"} {
		    $wentry configure -state disabled
		}
		set state($op) $val
		set state($op,value) $val
		set state($op,w) $wentry
	    }
	}
	grid  $frtot.l$i  $frtot.e$i  -padx 2 -pady 2
	grid  $frtot.l$i  -sticky e
	grid  $frtot.e$i  -sticky ew
    }
  
    # Button part.
    set saveCmd   [list [namespace current]::MovieConfigure $token]
    set cancelCmd [list [namespace current]::Cancel $token]
    set frbot $w.frall.frbot
    ttk::frame $frbot -padding [option get . okcancelTopPadding {}]
    ttk::button $frbot.btsave -text [mc "Save"] -default active \
      -command $saveCmd
    ttk::button $frbot.btcancel -text [mc "Cancel"] -command $cancelCmd
    set padx [option get . buttonPadX {}]
    if {[option get . okcancelButtonOrder {}] eq "cancelok"} {
	pack $frbot.btsave -side right
	pack $frbot.btcancel -side right -padx $padx
    } else {
	pack $frbot.btcancel -side right
	pack $frbot.btsave -side right -padx $padx
    }
    pack $frbot -side bottom -fill x
    
    wm resizable $w 0 0
    bind $w <Return> [list $frbot.btsave invoke]
}

proc ::ItemInspector::MovieConfigure {token} {
    
    variable $token
    upvar 0 $token state

    variable boolFull2Short
    
    set wmov $state(wmov)
    
    # Loop through all options. Assemble a configure list.
    set newOptList {}
    foreach op $state(allopts) {
	set wname  $state($op,w)
	set opname [string trimleft $op "-"]
	set oldVal $state($op,value)
	set newVal $state($op)
	set optVal $newVal
		
	# If new different from old, reconfigure.
	if {![string equal $oldVal $newVal]}  {
	    lappend newOptList $op $optVal
	}
    }
    if {$newOptList != {}} {
	
	# Remote???
	eval {$wmov configure} $newOptList
    }
    set state(finished) 1 
    Close $token
    Free $token
}

proc ::ItemInspector::Broken {wcan itemid args} {
    global  wDlgs
        
    set w $wDlgs(iteminsp)$itemid
    
    # If window already there, just return silently.
    if {[winfo exists $w]} {
	raise $w
	return
    }
    set wtoplevel [winfo toplevel $wcan]
    
    # Keep state array for item options etc.
    set token [namespace current]::$itemid
    variable $token
    upvar 0 $token state

    set state(w)      $w
    set state(wcan)   $wcan
    set state(itemid) $itemid
    set state(finished) -1

    set utag [::CanvasUtils::GetUtag $wcan $itemid]
    if {$utag == {}}  {
	return
    }
    set state(utag) $utag

    ::UI::Toplevel $w -class ItemInspector  \
      -macstyle documentProc -usemacmainmenu 1 \
      -macclass {document closeBox} \
      -closecommand [list [namespace current]::CloseCmd $token]
    wm title $w " Edit Item"
    bind $wcan <Destroy> +[list [namespace current]::Cancel $token]
            
    # Global frame.
    ttk::frame $w.frall -padding [option get . dialogPadding {}]
    pack  $w.frall  -fill both -expand 1

    set w1 $w.frall.fr1
    ttk::labelframe $w1 -padding [option get . groupSmallPadding {}]  \
      -text [mc "Broken Image"]
    pack $w1
    
    # Overall frame for whole container.
    set fr $w1
    
    # Get any cached info for this id.
    set itemcget [::CanvasUtils::ItemCGet $wtoplevel $itemid]
    set i 0
    foreach {key value} $itemcget {
	if {$key eq "-optlist"} {
	    foreach {optkey optvalue} $value {
		set name [string totitle [string trimright $optkey :]]
		ttk::label $fr.l$i -text $name
		ttk::label $fr.v$i -text $optvalue
		grid  $fr.l$i  $fr.v$i  -pady 2
		grid  $fr.l$i  -sticky e
		grid  $fr.v$i  -sticky w
		incr i
	    }
	} else {
	    set name [string totitle [string trimleft $key -]]
	    ttk::label $fr.l$i -text $name
	    ttk::label $fr.v$i -text $value
	    grid  $fr.l$i  $fr.v$i  -pady 2
	    grid  $fr.l$i  -sticky e
	    grid  $fr.v$i  -sticky w
	    incr i
	}
    }
    
    # Button part.
    set frbot $w.frall.frbot
    ttk::frame $w.frall.frbot
    ttk::button $frbot.btok -text [mc "OK"] -command [list destroy $w]
    pack $frbot.btok -side right
    pack $frbot -side top -fill both -expand 1
        
    wm resizable $w 0 0
    bind $w <Return> [list $frbot.btok invoke]
}

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