Class: Gtk::TreeStore

Inherits:
GObject show all
Defined in:
lib/gtk/tree_store.rb

Constant Summary collapse

TYPE_MAP =
{
  Integer => 24, # GObject::TYPE_INT,
  String  => 64  # GObject::TYPE_STRING
}

Instance Attribute Summary

Attributes inherited from GObject

#native, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GObject

#method_missing, #signal_connect, type_register, #unref

Constructor Details

#initialize(*types) ⇒ TreeStore

Returns a new instance of TreeStore.



21
22
23
24
25
26
27
28
# File 'lib/gtk/tree_store.rb', line 21

def initialize(*types)
  @native = Gtk::Lib.gtk_tree_store_new(
    types.size,
    *self.class.type_mapped_types(*types).map{ |type|
      [:int,type]
    }.flatten
  )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gtk::GObject

Class Method Details

.type_mapped_types(*types) ⇒ Object



16
17
18
19
# File 'lib/gtk/tree_store.rb', line 16

def self.type_mapped_types(*types)
  types = types.first if types.size == 1 && types.first.is_a?(Array)
  types.map{ |type| TYPE_MAP[type] }
end

Instance Method Details

#append(parent = nil) ⇒ Object



37
38
39
40
41
42
# File 'lib/gtk/tree_store.rb', line 37

def append parent=nil
  iter = Gtk::TreeIter.new
  Gtk::Lib.gtk_tree_store_append(native,iter,parent)
  iter.owner = self
  iter
end

#set_column_types(*types) ⇒ Object



30
31
32
33
34
35
# File 'lib/gtk/tree_store.rb', line 30

def set_column_types *types
  types = self.class.type_mapped_types(*types)
  array = FFI::MemoryPointer.new(:long,types.size)
  array.write_array_of_long(types)
  Lib.gtk_tree_store_set_column_types(@native,types.size,array)
end