1#
2#  tkextlib/blt/unix_dnd.rb
3#
4#    *** This is alpha version, because there is no document on BLT. ***
5#
6#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
7#
8
9require 'tk'
10require 'tkextlib/blt.rb'
11
12module Tk::BLT
13  module DnD
14    extend TkCore
15
16    TkCommandNames = ['::blt::dnd'.freeze].freeze
17
18    ##############################
19
20    extend TkItemConfigMethod
21
22    class << self
23      def __item_cget_cmd(id)
24        ['::blt::dnd', *id]
25      end
26      private :__item_cget_cmd
27
28      def __item_config_cmd(id)
29        ['::blt::dnd', *id]
30      end
31      private :__item_config_cmd
32
33      private :itemcget_tkstring, :itemcget, :itemcget_strict
34      private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
35
36      def cget_tkstring(win, option)
37        itemcget_tkstring(['cget', win], option)
38      end
39      def cget(win, option)
40        itemcget(['cget', win], option)
41      end
42      def cget_strict(win, option)
43        itemcget_strict(['cget', win], option)
44      end
45      def configure(win, slot, value=None)
46        itemconfigure(['configure', win], slot, value)
47      end
48      def configinfo(win, slot=nil)
49        itemconfiginfo(['configure', win], slot)
50      end
51      def current_configinfo(win, slot=nil)
52        current_itemconfiginfo(['configure', win], slot)
53      end
54
55      def token_cget_tkstring(win, option)
56        itemcget_tkstring(['token', 'cget', win], option)
57      end
58      def token_cget(win, option)
59        itemcget(['token', 'cget', win], option)
60      end
61      def token_cget_strict(win, option)
62        itemcget_strict(['token', 'cget', win], option)
63      end
64      def token_configure(win, slot, value=None)
65        itemconfigure(['token', 'configure', win], slot, value)
66      end
67      def token_configinfo(win, slot=nil)
68        itemconfiginfo(['token', 'configure', win], slot)
69      end
70      def current_token_configinfo(win, slot=nil)
71        current_itemconfiginfo(['token', 'configure', win], slot)
72      end
73
74      def token_windowconfigure(win, slot, value=None)
75        itemconfigure(['token', 'window', win], slot, value)
76      end
77      def token_windowconfiginfo(win, slot=nil)
78        itemconfiginfo(['token', 'window', win], slot)
79      end
80      def current_token_windowconfiginfo(win, slot=nil)
81        current_itemconfiginfo(['token', 'window', win], slot)
82      end
83    end
84
85    ##############################
86
87    def self.cancel(win)
88      tk_call('::blt::dnd', 'cancel', *wins)
89    end
90    def self.delete(*wins)
91      tk_call('::blt::dnd', 'delete', *wins)
92    end
93    def self.delete_source(*wins)
94      tk_call('::blt::dnd', 'delete', '-source', *wins)
95    end
96    def self.delete_target(*wins)
97      tk_call('::blt::dnd', 'delete', '-target', *wins)
98    end
99    def self.drag(win, x, y, token=None)
100      tk_call('::blt::dnd', 'drag', win, x, y, token)
101    end
102    def self.drop(win, x, y, token=None)
103      tk_call('::blt::dnd', 'drop', win, x, y, token)
104    end
105    def self.get_data(win, fmt=nil, cmd=nil)
106      if fmt
107        tk_call('::blt::dnd', 'getdata', win, fmt, cmd)
108      else
109        list(tk_call('::blt::dnd', 'getdata', win))
110      end
111    end
112    def self.names(pat=None)
113      list(tk_call('::blt::dnd', 'names', pat))
114    end
115    def self.source_names(pat=None)
116      list(tk_call('::blt::dnd', 'names', '-source', pat))
117    end
118    def self.target_names(pat=None)
119      list(tk_call('::blt::dnd', 'names', '-target', pat))
120    end
121    def self.pull(win, fmt)
122      tk_call('::blt::dnd', 'pull', win, fmt)
123    end
124    def self.register(win, keys={})
125      tk_call('::blt::dnd', 'register', win, keys)
126    end
127    def self.select(win, x, y, timestamp)
128      tk_call('::blt::dnd', 'select', win, x, y, timestamp)
129    end
130    def self.set_data(win, fmt=nil, cmd=nil)
131      if fmt
132        tk_call('::blt::dnd', 'setdata', win, fmt, cmd)
133      else
134        list(tk_call('::blt::dnd', 'setdata', win))
135      end
136    end
137    def self.token(*args)
138      tk_call('::blt::dnd', 'token', *args)
139    end
140  end
141end
142