summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/wm.rb
blob: a2be51248dcfe1af70732f7c2803d6ae99d75d5e (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
#
# tk/wm.rb : methods for wm command
#
require 'tk'

module Tk
  module Wm
    include TkComm

    TkCommandNames = ['wm'.freeze].freeze

    def aspect(*args)
      if args.length == 0
        list(tk_call_without_enc('wm', 'aspect', path))
      else
        tk_call('wm', 'aspect', path, *args)
        self
      end
    end

    def attributes(slot=nil,value=None)
      if slot == nil
        lst = tk_split_list(tk_call('wm', 'attributes', path))
        info = {}
        while key = lst.shift
          info[key[1..-1]] = lst.shift
        end
        info
      elsif slot.kind_of? Hash
        tk_call('wm', 'attributes', path, *hash_kv(slot))
        self
      elsif value == None
        tk_call('wm', 'attributes', path, "-#{slot}")
      else
        tk_call('wm', 'attributes', path, "-#{slot}", value)
        self
      end
    end

    def client(name=None)
      if name == None
        tk_call('wm', 'client', path)
      else
        name = '' if name == nil
        tk_call('wm', 'client', path, name)
        self
      end
    end

    def colormapwindows(*args)
      if args.size == 0
        list(tk_call_without_enc('wm', 'colormapwindows', path))
      else
        tk_call_without_enc('wm', 'colormapwindows', path, *args)
        self
      end
    end

    def wm_command(value=nil)
      if value
        tk_call('wm', 'command', path, value)
        self
      else
        #procedure(tk_call('wm', 'command', path))
        tk_call('wm', 'command', path)
      end
    end

    def deiconify(ex = true)
      tk_call_without_enc('wm', 'deiconify', path) if ex
      self
    end

    def focusmodel(mode = nil)
      if mode
        tk_call_without_enc('wm', 'focusmodel', path, mode)
        self
      else
        tk_call_without_enc('wm', 'focusmodel', path)
      end
    end

    def frame
      tk_call_without_enc('wm', 'frame', path)
    end

    def geometry(geom=nil)
      if geom
        tk_call_without_enc('wm', 'geometry', path, geom)
        self
      else
        tk_call_without_enc('wm', 'geometry', path)
      end
    end

    def wm_grid(*args)
      if args.size == 0
        list(tk_call_without_enc('wm', 'grid', path))
      else
        tk_call_without_enc('wm', 'grid', path, *args)
        self
      end
    end

    def group(leader = nil)
      if leader
        tk_call('wm', 'group', path, leader)
        self
      else
        window(tk_call('wm', 'group', path))
      end
    end

    def iconbitmap(bmp=nil)
      if bmp
        tk_call_without_enc('wm', 'iconbitmap', path, bmp)
        self
      else
        image_obj(tk_call_without_enc('wm', 'iconbitmap', path))
      end
    end

    def iconphoto(*imgs)
      # Windows only
      tk_call_without_enc('wm', 'iconphoto', path, *imgs)
      self
    end

    def iconphoto_default(*imgs)
      # Windows only
      tk_call_without_enc('wm', 'iconphoto', path, '-default', *imgs)
      self
    end

    def iconify(ex = true)
      tk_call_without_enc('wm', 'iconify', path) if ex
      self
    end

    def iconmask(bmp=nil)
      if bmp
        tk_call_without_enc('wm', 'iconmask', path, bmp)
        self
      else
        image_obj(tk_call_without_enc('wm', 'iconmask', path))
      end
    end

    def iconname(name=nil)
      if name
        tk_call('wm', 'iconname', path, name)
        self
      else
        tk_call('wm', 'iconname', path)
      end
    end

    def iconposition(*args)
      if args.size == 0
        list(tk_call_without_enc('wm', 'iconposition', path))
      else
        tk_call_without_enc('wm', 'iconposition', path, *args)
        self
      end
    end

    def iconwindow(win = nil)
      if win
        tk_call_without_enc('wm', 'iconwindow', path, win)
        self
      else
        w = tk_call_without_enc('wm', 'iconwindow', path)
        (w == '')? nil: window(w)
      end
    end

    def maxsize(*args)
      if args.size == 0
        list(tk_call_without_enc('wm', 'maxsize', path))
      else
        tk_call_without_enc('wm', 'maxsize', path, *args)
        self
      end
    end

    def minsize(*args)
      if args.size == 0
        list(tk_call_without_enc('wm', 'minsize', path))
      else
        tk_call_without_enc('wm', 'minsize', path, *args)
        self
      end
    end

    def overrideredirect(bool=None)
      if bool == None
        bool(tk_call_without_enc('wm', 'overrideredirect', path))
      else
        tk_call_without_enc('wm', 'overrideredirect', path, bool)
        self
      end
    end

    def positionfrom(who=None)
      if who == None
        r = tk_call_without_enc('wm', 'positionfrom', path)
        (r == "")? nil: r
      else
        tk_call_without_enc('wm', 'positionfrom', path, who)
        self
      end
    end

    def protocol(name=nil, cmd=nil, &b)
      if cmd
        tk_call_without_enc('wm', 'protocol', path, name, cmd)
        self
      elsif b
        tk_call_without_enc('wm', 'protocol', path, name, proc(&b))
        self
      elsif name
        result = tk_call_without_enc('wm', 'protocol', path, name)
        (result == "")? nil : tk_tcl2ruby(result)
      else
        tk_split_simplelist(tk_call_without_enc('wm', 'protocol', path))
      end
    end

    def resizable(*args)
      if args.length == 0
        list(tk_call_without_enc('wm', 'resizable', path)).collect{|e| bool(e)}
      else
        tk_call_without_enc('wm', 'resizable', path, *args)
        self
      end
    end

    def sizefrom(who=None)
      if who == None
        r = tk_call_without_enc('wm', 'sizefrom', path)
        (r == "")? nil: r
      else
        tk_call_without_enc('wm', 'sizefrom', path, who)
        self
      end
    end

    def stackorder
      list(tk_call('wm', 'stackorder', path))
    end

    def stackorder_isabove(win)
      bool(tk_call('wm', 'stackorder', path, 'isabove', win))
    end

    def stackorder_isbelow(win)
      bool(tk_call('wm', 'stackorder', path, 'isbelow', win))
    end

    def state(state=nil)
      if state
        tk_call_without_enc('wm', 'state', path, state)
        self
      else
        tk_call_without_enc('wm', 'state', path)
      end
    end

    def title(str=nil)
      if str
        tk_call('wm', 'title', path, str)
        self
      else
        tk_call('wm', 'title', path)
      end
    end

    def transient(master=nil)
      if master
        tk_call_without_enc('wm', 'transient', path, master)
        self
      else
        window(tk_call_without_enc('wm', 'transient', path))
      end
    end

    def withdraw(ex = true)
      tk_call_without_enc('wm', 'withdraw', path) if ex
      self
    end
  end
end