1#
2#  ttk::dialog  (tile-0.7+)
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5require 'tk'
6require 'tkextlib/tile.rb'
7
8module Tk
9  module Tile
10    class Dialog < TkWindow
11    end
12  end
13end
14
15begin
16  TkPackage.require('ttk::dialog') # this may be required.
17rescue RuntimeError
18  # ignore
19end
20
21class Tk::Tile::Dialog
22  TkCommandNames = ['::ttk::dialog'.freeze].freeze
23
24  def self.show(*args)
25    dialog = self.new(*args)
26    dialog.show
27    [dialog.status, dialog.value]
28  end
29  def self.display(*args)
30    self.show(*args)
31  end
32
33  def self.define_dialog_type(name, keys)
34    Tk.tk_call('::ttk::dialog::define', name, keys)
35    name
36  end
37
38  def self.style(*args)
39    ['Dialog', *(args.map!{|a| _get_eval_string(a)})].join('.')
40  end
41
42  #########################
43
44  def initialize(keys={})
45    @keys = _symbolkey2str(keys)
46    super(*args)
47  end
48
49  def create_self(keys)
50    # dummy
51  end
52  private :create_self
53
54  def show
55    tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys))
56  end
57  alias display show
58
59  def client_frame
60    window(tk_call_without_enc('::ttk::dialog::clientframe', @path))
61  end
62
63  def cget_strict(slot)
64    @keys[slot.to_s]
65  end
66  def cget(slot)
67    @keys[slot.to_s]
68  end
69=begin
70  def cget(slot)
71    unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
72      cget_strict(slot)
73    else
74      cget_strict(slot) rescue nil
75    end
76  end
77=end
78
79  def configure(slot, value=None)
80    if slot.kind_of?(Hash)
81      slot.each{|k, v| configure(k, v)}
82    else
83      slot = slot.to_s
84      value = _symbolkey2str(value) if value.kind_of?(Hash)
85      if value && value != None
86        @keys[slot] = value
87      else
88        @keys.delete(slot)
89      end
90    end
91    self
92  end
93
94  def configinfo(slot = nil)
95    if slot
96      slot = slot.to_s
97      [ slot, nil, nil, nil, @keys[slot] ]
98    else
99      @keys.collect{|k, v| [ k, nil, nil, nil, v ] }
100    end
101  end
102end
103