1#
2# tk/place.rb : control place geometry manager
3#
4require 'tk'
5
6module TkPlace
7  include Tk
8  extend Tk
9
10  TkCommandNames = ['place'.freeze].freeze
11
12  def configure(win, slot, value=None)
13    # for >= Tk8.4a2 ?
14    # win = win.epath if win.kind_of?(TkObject)
15    win = _epath(win)
16    if slot.kind_of? Hash
17      params = []
18      slot.each{|k, v|
19        params.push("-#{k}")
20        # params.push((v.kind_of?(TkObject))? v.epath: v)
21        params.push(_epath(v))
22      }
23      tk_call_without_enc('place', 'configure', win, *params)
24    else
25      # value = value.epath if value.kind_of?(TkObject)
26      value = _epath(value)
27      tk_call_without_enc('place', 'configure', win, "-#{slot}", value)
28    end
29  end
30  alias place configure
31
32  def configinfo(win, slot = nil)
33    # for >= Tk8.4a2 ?
34    if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
35      # win = win.epath if win.kind_of?(TkObject)
36      win = _epath(win)
37      if slot
38        #conf = tk_split_list(tk_call_without_enc('place', 'configure',
39        #                                        win, "-#{slot}") )
40        conf = tk_split_simplelist(tk_call_without_enc('place', 'configure',
41                                                       win, "-#{slot}") )
42        conf[0] = conf[0][1..-1]
43        conf[1] = tk_tcl2ruby(conf[1])
44        conf[2] = tk_tcl2ruby(conf[1])
45        conf[3] = tk_tcl2ruby(conf[1])
46        conf[4] = tk_tcl2ruby(conf[1])
47        conf
48      else
49        tk_split_simplelist(tk_call_without_enc('place', 'configure',
50                                                win)).collect{|conflist|
51          #conf = list(conflist)
52          conf = simplelist(conflist).collect!{|inf| tk_tcl2ruby(inf)}
53          conf[0] = conf[0][1..-1]
54          conf
55        }
56      end
57    else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
58      current_configinfo(win, slot)
59    end
60  end
61
62  def current_configinfo(win, slot = nil)
63    # win = win.epath if win.kind_of?(TkObject)
64    win = _epath(win)
65    if slot
66      #conf = tk_split_list(tk_call_without_enc('place', 'configure',
67      #                                         win, "-#{slot}") )
68      conf = tk_split_simplelist(tk_call_without_enc('place', 'configure',
69                                                     win, "-#{slot}") )
70      # { conf[0][1..-1] => conf[1] }
71      { conf[0][1..-1] => tk_tcl2ruby(conf[4]) }
72    else
73      ret = {}
74      #tk_split_list(tk_call_without_enc('place','configure',win)).each{|conf|
75      tk_split_simplelist(tk_call_without_enc('place', 'configure',
76                                              win)).each{|conf_list|
77        #ret[conf[0][1..-1]] = conf[1]
78        conf = simplelist(conf_list)
79        ret[conf[0][1..-1]] = tk_tcl2ruby(conf[4])
80      }
81      ret
82    end
83  end
84
85  def forget(win)
86    # win = win.epath if win.kind_of?(TkObject)
87    win = _epath(win)
88    tk_call_without_enc('place', 'forget', win)
89  end
90
91  def info(win)
92    # win = win.epath if win.kind_of?(TkObject)
93    win = _epath(win)
94    #ilist = list(tk_call_without_enc('place', 'info', win))
95    ilist = simplelist(tk_call_without_enc('place', 'info', win))
96    info = {}
97    while key = ilist.shift
98      #info[key[1..-1]] = ilist.shift
99      info[key[1..-1]] = tk_tcl2ruby(ilist.shift)
100    end
101    return info
102  end
103
104  def slaves(master)
105    # master = master.epath if master.kind_of?(TkObject)
106    master = _epath(master)
107    list(tk_call('place', 'slaves', master))
108  end
109
110  module_function :place, :configure, :configinfo, :current_configinfo
111  module_function :forget, :info, :slaves
112end
113=begin
114def TkPlace(win, slot, value=None)
115  win = win.epath if win.kind_of?(TkObject)
116  if slot.kind_of? Hash
117    params = []
118    slot.each{|k, v|
119      params.push("-#{k}")
120      params.push((v.kind_of?(TkObject))? v.epath: v)
121    }
122    tk_call_without_enc('place', win, *params)
123  else
124    value = value.epath if value.kind_of?(TkObject)
125    tk_call_without_enc('place', win, "-#{slot}", value)
126  end
127end
128=end
129