summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/itemconfig.rb
blob: dbc45a9e7c6b91dd775ad85fe094939950cd457d (plain)
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
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
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
1113
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
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
#
# tk/itemconfig.rb : control item/tag configuration of widget
#
require 'tk'
require 'tkutil'
require 'tk/itemfont.rb'

module TkItemConfigOptkeys
  include TkUtil

  def __item_numval_optkeys(id)
    []
  end
  private :__item_numval_optkeys

  def __item_numstrval_optkeys(id)
    []
  end
  private :__item_numstrval_optkeys

  def __item_boolval_optkeys(id)
    ['exportselection', 'jump', 'setgrid', 'takefocus']
  end
  private :__item_boolval_optkeys

  def __item_strval_optkeys(id)
    # maybe need to override
    [
      'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile', 
      'activebackground', 'activeforeground', 'background', 
      'disabledforeground', 'disabledbackground', 'foreground', 
      'highlightbackground', 'highlightcolor', 'insertbackground', 
      'selectbackground', 'selectforeground', 'troughcolor'
    ]
  end
  private :__item_strval_optkeys

  def __item_listval_optkeys(id)
    []
  end
  private :__item_listval_optkeys

  def __item_numlistval_optkeys(id)
    # maybe need to override
    ['dash', 'activedash', 'disableddash']
  end
  private :__item_numlistval_optkeys

  def __item_tkvariable_optkeys(id)
    ['variable', 'textvariable']
  end
  private :__item_tkvariable_optkeys

  def __item_val2ruby_optkeys(id)  # { key=>method, ... }
    # The method is used to convert a opt-value to a ruby's object.
    # When get the value of the option "key", "method.call(id, val)" is called.
    {}
  end
  private :__item_val2ruby_optkeys

  def __item_ruby2val_optkeys(id)  # { key=>method, ... }
    # The method is used to convert a ruby's object to a opt-value.
    # When set the value of the option "key", "method.call(id, val)" is called.
    # That is, "-#{key} #{method.call(id, value)}".
    {}
  end
  private :__item_ruby2val_optkeys

  def __item_methodcall_optkeys(id)  # { key=>method, ... }
    # Use the method for both of get and set.
    # Usually, the 'key' will not be a widget option.
    #
    # maybe need to override
    # {'coords'=>'coords'}
    {}
  end
  private :__item_methodcall_optkeys

  ################################################

  def __item_keyonly_optkeys(id)  # { def_key=>(undef_key|nil), ... }
    # maybe need to override
    {}
  end
  private :__item_keyonly_optkeys


  def __conv_item_keyonly_opts(id, keys)
    return keys unless keys.kind_of?(Hash)
    keyonly = __item_keyonly_optkeys(id)
    keys2 = {}
    keys.each{|k, v|
      optkey = keyonly.find{|kk,vv| kk.to_s == k.to_s}
      if optkey
        defkey, undefkey = optkey
        if v
          keys2[defkey.to_s] = None
        else
          keys2[undefkey.to_s] = None
        end
      else
        keys2[k.to_s] = v
      end
    }
    keys2
  end

  def itemconfig_hash_kv(id, keys, enc_mode = nil, conf = nil)
    hash_kv(__conv_item_keyonly_opts(id, keys), enc_mode, conf)
  end
end

module TkItemConfigMethod
  include TkUtil
  include TkTreatItemFont
  include TkItemConfigOptkeys

  def TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    @mode || false
  end
  def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
    fail SecurityError, "can't change the mode" if $SAFE>=4
    @mode = (mode)? true: false
  end

  def __item_cget_cmd(id)
    # maybe need to override
    [self.path, 'itemcget', id]
  end
  private :__item_cget_cmd

  def __item_config_cmd(id)
    # maybe need to override
    [self.path, 'itemconfigure', id]
  end
  private :__item_config_cmd

  def __item_confinfo_cmd(id)
    # maybe need to override
    __item_config_cmd(id)
  end
  private :__item_confinfo_cmd

  def __item_configinfo_struct(id)
    # maybe need to override
    {:key=>0, :alias=>1, :db_name=>1, :db_class=>2, 
      :default_value=>3, :current_value=>4}
  end
  private :__item_configinfo_struct

  ################################################

  def tagid(tagOrId)
    # maybe need to override
    tagOrId
  end

  ################################################

  def __itemcget_core(tagOrId, option)
    orig_opt = option
    option = option.to_s

    if option.length == 0
      fail ArgumentError, "Invalid option `#{orig_opt.inspect}'"
    end

    if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] )
      optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
      begin
        return method.call(tagOrId, optval)
      rescue => e
        warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
        return optval
      end
    end

    if ( method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[option] )
      return self.__send__(method, tagOrId)
    end

    case option
    when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
      begin
        number(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))
      rescue
        nil
      end

    when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
      num_or_str(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))

    when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
      begin
        bool(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))
      rescue
        nil
      end

    when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
      simplelist(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))

    when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
      conf = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
      if conf =~ /^[0-9]/
        list(conf)
      else
        conf
      end

    when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
      v = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
      (v.empty?)? nil: TkVarAccess.new(v)

    when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
      _fromUTF8(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))

    when /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/
      fontcode = $1
      fontkey  = $2
      fnt = tk_tcl2ruby(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{fontkey}")), true)
      unless fnt.kind_of?(TkFont)
        fnt = tagfontobj(tagid(tagOrId), fontkey)
      end
      if fontcode == 'kanji' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
        # obsolete; just for compatibility
        fnt.kanji_font
      else
        fnt
      end
    else
      tk_tcl2ruby(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")), true)
    end
  end
  private :__itemcget_core

  def itemcget(tagOrId, option)
    unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
      __itemcget_core(tagOrId, option)
    else
      begin
        __itemcget_core(tagOrId, option)
      rescue => e
        begin
          __itemconfiginfo_core(tagOrId)
          # not tag error -> option is unknown
          nil
        rescue
          fail e  # tag error
        end
      end
    end
  end

  def __itemconfigure_core(tagOrId, slot, value=None)
    if slot.kind_of? Hash
      slot = _symbolkey2str(slot)

      __item_methodcall_optkeys(tagid(tagOrId)).each{|key, method|
        value = slot.delete(key.to_s)
        self.__send__(method, tagOrId, value) if value
      }

      __item_ruby2val_optkeys(tagid(tagOrId)).each{|key, method|
        key = key.to_s
        slot[key] = method.call(tagOrId, slot[key]) if slot.has_key?(key)
      }

      __item_keyonly_optkeys(tagid(tagOrId)).each{|defkey, undefkey|
        conf = slot.find{|kk, vv| kk == defkey.to_s}
        if conf
          k, v = conf
          if v
            slot[k] = None
          else
            slot[undefkey.to_s] = None if undefkey
            slot.delete(k)
          end
        end
      }

      if (slot.find{|k, v| k =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/})
        tagfont_configure(tagid(tagOrId), slot)
      elsif slot.size > 0
        tk_call(*(__item_config_cmd(tagid(tagOrId)).concat(hash_kv(slot))))
      end

    else
      orig_slot = slot
      slot = slot.to_s
      if slot.length == 0
        fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
      end

      if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } )
        defkey, undefkey = conf
        if value
          tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{defkey}"))
        elsif undefkey
          tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{undefkey}"))
        end
      elsif ( method = _symbolkey2str(__item_ruby2val_optkeys(tagid(tagOrId)))[slot] )
        tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{slot}" << method.call(tagOrId, value)))
      elsif ( method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot] )
        self.__send__(method, tagOrId, value)
      elsif (slot =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/)
        if value == None
          tagfontobj(tagid(tagOrId), $2)
        else
          tagfont_configure(tagid(tagOrId), {slot=>value})
        end
      else
        tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{slot}" << value))
      end
    end
    self
  end
  private :__itemconfigure_core

  def __check_available_itemconfigure_options(tagOrId, keys)
    id = tagid(tagOrId)
    availables = self.current_itemconfiginfo(id).keys

    # add non-standard keys
    availables |= __font_optkeys.map{|k|
      [k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
    }.flatten
    availables |= __item_methodcall_optkeys(id).keys.map{|k| k.to_s}
    availables |= __item_keyonly_optkeys(id).keys.map{|k| k.to_s}

    keys = _symbolkey2str(keys)
    keys.delete_if{|k, v| !(availables.include?(k))}
  end

  def itemconfigure(tagOrId, slot, value=None)
    unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
      __itemconfigure_core(tagOrId, slot, value)
    else
      if slot.kind_of?(Hash)
        begin
          __itemconfigure_core(tagOrId, slot)
        rescue
          slot = __check_available_configure_options(tagOrId, slot)
          __itemconfigure_core(tagOrId, slot) unless slot.empty?
        end
      else
        begin
          __itemconfigure_core(tagOrId, slot, value)
        rescue => e
          begin
            __itemconfiginfo_core(tagOrId)
          rescue
            fail e  # tag error
          end
        end
      end
    end
    self
  end

  def __itemconfiginfo_core(tagOrId, slot = nil)
    if TkComm::GET_CONFIGINFO_AS_ARRAY
      if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/)
        fontkey  = $2
        # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}"))))
        conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}")), false, true)
        conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
          conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]
        if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
            || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
          fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
          if TkFont.is_system_font?(fnt)
            conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
          end
          conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
        elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
               && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 \
               && conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?- )
          conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
            conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
        end
        conf
      else
        if slot
          slot = slot.to_s
          case slot
          when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
            method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              begin
                val = method.call(tagOrId, optval)
              rescue => e
                warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                val = optval
              end
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
              begin
                val = method.call(tagOrId, optval)
              rescue => e
                warn("Warning:: #{e.message} (when #{method}lcall(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                val = optval
              end
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val
            end

          when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/
            method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot]
            return [slot, '', '', '', self.__send__(method, tagOrId)]

          when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  number(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  number(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              end
            end

          when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  bool(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  bool(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              end
            end

          when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] =~ /^[0-9]/ )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] =~ /^[0-9]/ )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

          when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              if v.empty?
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              else
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
              if v.empty?
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              else
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
              end
            end

          else
            # conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_list(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), 0, false, true)
          end
          conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
            conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]

          if ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
              && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 \
              && conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?- )
            conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
              conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
          end

          conf

        else
          # ret = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))))).collect{|conflist|
          #   conf = tk_split_simplelist(conflist)
          ret = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))), false, false).collect{|conflist|
            conf = tk_split_simplelist(conflist, false, true)
            conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
              conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]

            optkey = conf[__item_configinfo_struct(tagid(tagOrId))[:key]]
            case optkey
            when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
              method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[optkey]
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
                begin
                  val = method(tagOrId, optval)
                rescue => e
                  warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                  val = optval
                end
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                begin
                  val = method.call(tagOrId, optval)
                rescue => e
                  warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                  val = optval
                end
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val
              end

            when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
              # do nothing

            when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    number(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    number(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                end
              end

            when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    bool(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    bool(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                end
              end

            when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] =~ /^[0-9]/ )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] =~ /^[0-9]/ )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
                if v.empty?
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                if v.empty?
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
                end
              end

            else
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                if conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]].index('{')
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    tk_split_list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]) 
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    tk_tcl2ruby(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]) 
                end
              end
              if conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                if conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]].index('{')
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    tk_split_list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]) 
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    tk_tcl2ruby(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]) 
                end
              end
            end

            if ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
                && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?- )
              conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
                conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
            end

            conf
          }

          __item_font_optkeys(tagid(tagOrId)).each{|optkey|
            optkey = optkey.to_s
            fontconf = ret.assoc(optkey)
            if fontconf && fontconf.size > 2
              ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
              fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              if TkFont.is_system_font?(fnt)
                fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
              end
              fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
              ret.push(fontconf)
            end
          }

          __item_methodcall_optkeys(tagid(tagOrId)).each{|optkey, method|
            ret << [optkey.to_s, '', '', '', self.__send__(method, tagOrId)]
          }

          ret
        end
      end

    else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
      if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/)
        fontkey  = $2
        # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}"))))
        conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}")), false, true)
        conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
          conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]

        if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
            || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
          fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
          if TkFont.is_system_font?(fnt)
            conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
          end
          conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
          { conf.shift => conf }
        elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
               && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
          if conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?-
            conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
              conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
          end
          { conf[0] => conf[1] }
        else
          { conf.shift => conf }
        end
      else
        if slot
          slot = slot.to_s
          case slot
          when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
            method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              begin
                val = method.call(tagOrId, optval)
              rescue => e
                warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                val = optval
              end
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
              begin
                val = method.call(tagOrId, optval)
              rescue => e
                warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                val = optval
              end
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val
            end

          when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/
            method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot]
            return {slot => ['', '', '', self.__send__(method, tagOrId)]}

          when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  number(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  number(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              end
            end

          when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                num_or_stre(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  bool(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              begin
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  bool(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              rescue
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              end
            end

          when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] =~ /^[0-9]/ )
              conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] =~ /^[0-9]/ )
              conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
            end

          when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
            # conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

          when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
            conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)

            if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
              v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              if v.empty?
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
              else
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
              end
            end
            if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
              v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
              if v.empty?
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
              else
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
              end
            end

          else
            # conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
            conf = tk_split_list(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), 0, false, true)
          end
          conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
            conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]

          if ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
              && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
            if conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?-
              conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
                conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
            end
            { conf[0] => conf[1] }
          else
            { conf.shift => conf }
          end

        else
          ret = {}
          # tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))))).each{|conflist|
          #   conf = tk_split_simplelist(conflist)
          tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))), false, false).each{|conflist|
            conf = tk_split_simplelist(conflist, false, true)
            conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = 
              conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]

            optkey = conf[__item_configinfo_struct(tagid(tagOrId))[:key]]
            case optkey
            when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
              method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[optkey]
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
                begin
                  val = method.call(tagOrId, optval)
                rescue => e
                  warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                  val = optval
                end
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                begin
                  val = method.call(tagOrId, optval)
                rescue => e
                  warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
                  val = optval
                end
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val
              end

            when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
              # do nothing

            when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    number(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    number(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                end
              end

            when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  num_or_str(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    bool(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                begin
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    bool(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
                rescue
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                end
              end

            when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  simplelist(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] =~ /^[0-9]/ )
                conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                  list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] =~ /^[0-9]/ )
                conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                  list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
              end

            when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
                if v.empty?
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
                end
              end
              if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
                v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                if v.empty?
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
                end
              end

            else
              if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
                  && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
                if conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]].index('{')
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    tk_split_list(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]) 
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = 
                    tk_tcl2ruby(conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]])
                end
              end
              if conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
                if conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]].index('{')
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    tk_split_list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]) 
                else
                  conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = 
                    tk_tcl2ruby(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
                end
              end
            end

            if ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
                && conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
              if conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][0] == ?-
                conf[__item_configinfo_struct(tagid(tagOrId))[:alias]] = 
                  conf[__item_configinfo_struct(tagid(tagOrId))[:alias]][1..-1]
              end
              ret[conf[0]] = conf[1]
            else
              ret[conf.shift] = conf
            end
          }

          __item_font_optkeys(tagid(tagOrId)).each{|optkey|
            optkey = optkey.to_s
            fontconf = ret[optkey]
            if fontconf.kind_of?(Array)
              ret.delete(optkey)
              ret.delete('latin' << optkey)
              ret.delete('ascii' << optkey)
              ret.delete('kanji' << optkey)
              fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
              if TkFont.is_system_font?(fnt)
                fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
              end
              fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
              ret[optkey] = fontconf
            end
          }

          __item_methodcall_optkeys(tagid(tagOrId)).each{|optkey, method|
            ret[optkey.to_s] = ['', '', '', self.__send__(method, tagOrId)]
          }

          ret
        end
      end
    end
  end
  private :__itemconfiginfo_core

  def itemconfiginfo(tagOrId, slot = nil)
    if slot && TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
      begin
        __itemconfiginfo_core(tagOrId, slot)
      rescue => e
        begin
          __itemconfiginfo_core(tagOrId)
          # not tag error -> option is unknown
          Array.new(__item_configinfo_struct.values.max).unshift(slot.to_s)
        rescue
          fail e  # tag error
        end
      end
    else
      __itemconfiginfo_core(tagOrId, slot)
    end
  end

  def current_itemconfiginfo(tagOrId, slot = nil)
    if TkComm::GET_CONFIGINFO_AS_ARRAY
      if slot
        org_slot = slot
        begin
          conf = __itemconfiginfo_core(tagOrId, slot)
          if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
              || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
            return {conf[0] => conf[-1]}
          end
          slot = conf[__item_configinfo_struct(tagid(tagOrId))[:alias]]
        end while(org_slot != slot)
        fail RuntimeError, 
          "there is a configure alias loop about '#{org_slot}'"
      else
        ret = {}
        __itemconfiginfo_core(tagOrId).each{|conf|
          if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
              || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
            ret[conf[0]] = conf[-1]
          end
        }
        ret
      end
    else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
      ret = {}
      __itemconfiginfo_core(tagOrId, slot).each{|key, conf|
        ret[key] = conf[-1] if conf.kind_of?(Array)
      }
      ret
    end
  end
end