Module: TkItemConfigMethod

Constant Summary

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkItemConfigOptkeys

#__conv_item_keyonly_opts, #itemconfig_hash_kv

Methods included from TkUtil

_conv_args, #_conv_args, #_fromUTF8, _get_eval_enc_str, #_get_eval_enc_str, #_get_eval_string, _get_eval_string, _symbolkey2str, #_symbolkey2str, #_toUTF8, bool, #bool, callback, eval_cmd, #hash_kv, hash_kv, install_cmd, num_or_str, #num_or_str, number, #number, string, #string, uninstall_cmd

Methods included from TkTreatItemFont

#kanjifont_copy, #kanjitagfont_configure, #latintagfont_configure, #latintagfont_copy, #tagfont_configinfo, #tagfont_configure, #tagfont_copy

Class Method Details

.__IGNORE_UNKNOWN_CONFIGURE_OPTION__Object



123
124
125
# File 'ext/lib/tk/itemconfig.rb', line 123

def TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  @mode || false
end

.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) ⇒ Object



126
127
128
129
# File 'ext/lib/tk/itemconfig.rb', line 126

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

Instance Method Details

#__check_available_itemconfigure_options(tagOrId, keys) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'ext/lib/tk/itemconfig.rb', line 350

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

#__current_itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'ext/lib/tk/itemconfig.rb', line 1178

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

#current_itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1212
1213
1214
# File 'ext/lib/tk/itemconfig.rb', line 1212

def current_itemconfiginfo(tagOrId, slot = nil)
  __current_itemconfiginfo(tagOrId, slot)
end

#itemcget(tagOrId, option) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'ext/lib/tk/itemconfig.rb', line 247

def itemcget(tagOrId, option)
  unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    __itemcget_core(tagOrId, option)
  else
    begin
      __itemcget_core(tagOrId, option)
    rescue => e
      begin
        if __current_itemconfiginfo(tagOrId).has_key?(option.to_s)
          # not tag error & option is known -> error on known option
          fail e
        else
          # not tag error & option is unknown
          nil
        end
      rescue
        fail e  # tag error
      end
    end
  end
end

#itemcget_strict(tagOrId, option) ⇒ Object



268
269
270
271
# File 'ext/lib/tk/itemconfig.rb', line 268

def itemcget_strict(tagOrId, option)
  # never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  __itemcget_core(tagOrId, option)
end

#itemconfiginfo(tagOrId, slot = nil) ⇒ Object



1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'ext/lib/tk/itemconfig.rb', line 1160

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

#itemconfigure(tagOrId, slot, value = None) ⇒ Object



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
# File 'ext/lib/tk/itemconfig.rb', line 367

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_itemconfigure_options(tagOrId, slot)
        __itemconfigure_core(tagOrId, slot) unless slot.empty?
      end
    else
      begin
        __itemconfigure_core(tagOrId, slot, value)
      rescue => e
        begin
          if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s)
            # not tag error & option is known -> error on known option
            fail e
          else
            # not tag error & option is unknown
            nil
          end
        rescue
          fail e  # tag error
        end
      end
    end
  end
  self
end

#tagid(tagOrId) ⇒ Object



158
159
160
161
# File 'ext/lib/tk/itemconfig.rb', line 158

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