1#
2#  tkextlib/tcllib/ip_entry.rb
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5#   * Part of tcllib extension
6#   * An IP address entry widget
7#
8# (The following is the original description of the library.)
9#
10# This package provides a widget for the entering of a IP address.
11# It guarantees a valid address at all times.
12
13require 'tk'
14require 'tkextlib/tcllib.rb'
15
16# TkPackage.require('ipentry', '0.1')
17TkPackage.require('ipentry')
18
19module Tk
20  module Tcllib
21    class IP_Entry < Tk::Entry
22      PACKAGE_NAME = 'ipentry'.freeze
23      def self.package_name
24        PACKAGE_NAME
25      end
26
27      def self.package_version
28        begin
29          TkPackage.require('ipentry')
30        rescue
31          ''
32        end
33      end
34    end
35    IPEntry = IP_Entry
36
37    class IP_Entry6 < IP_Entry
38    end
39    IPEntry6 = IP_Entry6
40    IP6_Entry = IP_Entry6
41  end
42end
43
44class Tk::Tcllib::IP_Entry
45  TkCommandNames = ['::ipentry::ipentry'.freeze].freeze
46  WidgetClassName = 'IPEntry'.freeze
47  WidgetClassNames[WidgetClassName] ||= self
48
49  def create_self(keys)
50    if keys and keys != None
51      tk_call_without_enc(self.class::TkCommandNames[0], @path,
52                          *hash_kv(keys, true))
53    else
54      tk_call_without_enc(self.class::TkCommandNames[0], @path)
55    end
56  end
57  private :create_self
58
59  def __strval_optkeys
60    super() << 'fg' << 'bg' << 'insertbackground'
61  end
62  private :__strval_optkeys
63
64  def complete?
65    bool(tk_send_without_enc('complete'))
66  end
67
68  def insert(*ip)
69    tk_send_without_enc('insert', array2tk_list(ip.flatten))
70  end
71end
72
73class Tk::Tcllib::IP_Entry6 < Tk::Tcllib::IP_Entry
74  TkCommandNames = ['::ipentry::ipentry6'.freeze].freeze
75end
76