TkListbox (Class)

In: tk/lib/tk/listbox.rb
Parent: TkTextWin

Constants

TkCommandNames = ['listbox'.freeze].freeze
WidgetClassName = 'Listbox'.freeze

Included Modules

TkTreatListItemFont Scrollable

Public Instance methods

[Source]

# File tk/lib/tk/listbox.rb, line 41
  def activate(y)
    tk_send_without_enc('activate', y)
    self
  end

[Source]

# File tk/lib/tk/listbox.rb, line 232
  def current_itemconfiginfo(index, key=nil)
    if TkComm::GET_CONFIGINFO_AS_ARRAY
      if key
        conf = itemconfiginfo(index, key)
        {conf[0] => conf[4]}
      else
        ret = {}
        itemconfiginfo(index).each{|conf|
          ret[conf[0]] = conf[4] if conf.size > 2
        }
        ret
      end
    else # ! TkComm::GET_CONFIGINFO_AS_ARRAY

      ret = {}
      itemconfiginfo(index, key).each{|k, conf|
        ret[k] = conf[-1] if conf.kind_of?(Array)
      }
      ret
    end
  end

[Source]

# File tk/lib/tk/listbox.rb, line 45
  def curselection
    list(tk_send_without_enc('curselection'))
  end

[Source]

# File tk/lib/tk/listbox.rb, line 48
  def get(first, last=nil)
    if last
      tk_split_simplelist(_fromUTF8(tk_send_without_enc('get', first, last)))
    else
      _fromUTF8(tk_send_without_enc('get', first))
    end
  end

[Source]

# File tk/lib/tk/listbox.rb, line 77
  def index(index)
    tk_send_without_enc('index', index).to_i
  end

[Source]

# File tk/lib/tk/listbox.rb, line 81
  def itemcget(index, key)
    case key.to_s
    when 'text', 'label', 'show'
      _fromUTF8(tk_send_without_enc('itemcget', index, "-#{key}"))
    when 'font', 'kanjifont'
      #fnt = tk_tcl2ruby(tk_send('itemcget', index, "-#{key}"))

      fnt = tk_tcl2ruby(_fromUTF8(tk_send_without_enc('itemcget', index, 
                                                      '-font')))
      unless fnt.kind_of?(TkFont)
        fnt = tagfontobj(index, fnt)
      end
      if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
        # obsolete; just for compatibility

        fnt.kanji_font
      else
        fnt
      end
    else
      tk_tcl2ruby(_fromUTF8(tk_send_without_enc('itemcget', index, "-#{key}")))
    end
  end

[Source]

# File tk/lib/tk/listbox.rb, line 130
  def itemconfiginfo(index, key=nil)
    if TkComm::GET_CONFIGINFO_AS_ARRAY
      if key
        case key.to_s
        when 'text', 'label', 'show'
          conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
        when 'font', 'kanjifont'
          conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
          conf[4] = tagfont_configinfo(index, conf[4])
        else
          conf = tk_split_list(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
        end
        conf[0] = conf[0][1..-1]
        conf
      else
        ret = tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure', index))).collect{|conflist|
          conf = tk_split_simplelist(conflist)
          conf[0] = conf[0][1..-1]
          case conf[0]
          when 'text', 'label', 'show'
          else
            if conf[3]
              if conf[3].index('{')
                conf[3] = tk_split_list(conf[3]) 
              else
                conf[3] = tk_tcl2ruby(conf[3]) 
              end
            end
            if conf[4]
              if conf[4].index('{')
                conf[4] = tk_split_list(conf[4]) 
              else
                conf[4] = tk_tcl2ruby(conf[4]) 
              end
            end
          end
          conf[1] = conf[1][1..-1] if conf.size == 2 # alias info

          conf
        }
        fontconf = ret.assoc('font')
        if fontconf
          ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
          fontconf[4] = tagfont_configinfo(index, fontconf[4])
          ret.push(fontconf)
        else
          ret
        end
      end
    else # ! TkComm::GET_CONFIGINFO_AS_ARRAY

      if key
        case key.to_s
        when 'text', 'label', 'show'
          conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
        when 'font', 'kanjifont'
          conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
          conf[4] = tagfont_configinfo(index, conf[4])
        else
          conf = tk_split_list(_fromUTF8(tk_send_without_enc('itemconfigure',index,"-#{key}")))
        end
        key = conf.shift[1..-1]
        { key => conf }
      else
        ret = {}
        tk_split_simplelist(_fromUTF8(tk_send_without_enc('itemconfigure', index))).each{|conflist|
          conf = tk_split_simplelist(conflist)
          key = conf.shift[1..-1]
          case key
          when 'text', 'label', 'show'
          else
            if conf[2]
              if conf[2].index('{')
                conf[2] = tk_split_list(conf[2]) 
              else
                conf[2] = tk_tcl2ruby(conf[2]) 
              end
            end
            if conf[3]
              if conf[3].index('{')
                conf[3] = tk_split_list(conf[3]) 
              else
                conf[3] = tk_tcl2ruby(conf[3]) 
              end
            end
          end
          if conf.size == 1
            ret[key] = conf[0][1..-1]  # alias info

          else
            ret[key] = conf
          end
        }
        fontconf = ret['font']
        if fontconf
          ret.delete('font')
          ret.delete('kanjifont')
          fontconf[3] = tagfont_configinfo(index, fontconf[3])
          ret['font'] = fontconf
        end
        ret
      end
    end
  end

[Source]

# File tk/lib/tk/listbox.rb, line 102
  def itemconfigure(index, key, val=None)
    if key.kind_of? Hash
      if (key['font'] || key[:font] || 
          key['kanjifont'] || key[:kanjifont] || 
          key['latinfont'] || key[:latinfont] || 
          key['asciifont'] || key[:asciifont] )
        tagfont_configure(index, _symbolkey2str(key))
      else
        tk_send_without_enc('itemconfigure', index, *hash_kv(key, true))
      end

    else
      if (key == 'font' || key == :font || 
          key == 'kanjifont' || key == :kanjifont || 
          key == 'latinfont' || key == :latinfont || 
          key == 'asciifont' || key == :asciifont )
        if val == None
          tagfontobj(index)
        else
          tagfont_configure(index, {key=>val})
        end
      else
        tk_call('itemconfigure', index, "-#{key}", val)
      end
    end
    self
  end

[Source]

# File tk/lib/tk/listbox.rb, line 55
  def nearest(y)
    tk_send_without_enc('nearest', y).to_i
  end

[Source]

# File tk/lib/tk/listbox.rb, line 61
  def selection_anchor(index)
    tk_send_without_enc('selection', 'anchor', index)
    self
  end

[Source]

# File tk/lib/tk/listbox.rb, line 65
  def selection_clear(first, last=None)
    tk_send_without_enc('selection', 'clear', first, last)
    self
  end

[Source]

# File tk/lib/tk/listbox.rb, line 69
  def selection_includes(index)
    bool(tk_send_without_enc('selection', 'includes', index))
  end

[Source]

# File tk/lib/tk/listbox.rb, line 72
  def selection_set(first, last=None)
    tk_send_without_enc('selection', 'set', first, last)
    self
  end

[Source]

# File tk/lib/tk/listbox.rb, line 58
  def size
    tk_send_without_enc('size').to_i
  end

[Validate]