1#
2#  tkextlib/iwidgets/calendar.rb
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5
6require 'tk'
7require 'tkextlib/iwidgets.rb'
8
9module Tk
10  module Iwidgets
11    class Calendar < Tk::Itk::Widget
12    end
13  end
14end
15
16class Tk::Iwidgets::Calendar
17  TkCommandNames = ['::iwidgets::calendar'.freeze].freeze
18  WidgetClassName = 'Calendar'.freeze
19  WidgetClassNames[WidgetClassName] ||= self
20
21  def __strval_optkeys
22    super() + [
23      'buttonforeground', 'outline', 'selectcolor',
24      'weekdaybackground', 'weekendbackground'
25    ]
26  end
27  private :__strval_optkeys
28
29  def __listval_optkeys
30    super() << 'days'
31  end
32  private :__listval_optkeys
33
34  def __font_optkeys
35    super() + ['currentdatefont', 'datefont', 'dayfont', 'titlefont']
36  end
37  private :__font_optkeys
38
39  ####################################
40
41  include Tk::ValidateConfigure
42
43  class CalendarCommand < TkValidateCommand
44    #class CalCmdArgs < TkUtil::CallbackSubst
45    class ValidateArgs < TkUtil::CallbackSubst
46      KEY_TBL  = [ [?d, ?s, :date], nil ]
47      PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
48
49=begin
50      # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
51      KEY_TBL.map!{|inf|
52        if inf.kind_of?(Array)
53          inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
54          inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
55        end
56        inf
57      }
58
59      PROC_TBL.map!{|inf|
60        if inf.kind_of?(Array)
61          inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
62        end
63        inf
64      }
65=end
66
67      _setup_subst_table(KEY_TBL, PROC_TBL);
68
69      def self.ret_val(val)
70        val
71      end
72    end
73
74    def self._config_keys
75      # array of config-option key (string or symbol)
76      ['command']
77    end
78
79    #def initialize(cmd = Proc.new, *args)
80    #  _initialize_for_cb_class(CalCmdArgs, cmd, *args)
81    #end
82  end
83
84  def __validation_class_list
85    super() << CalendarCommand
86  end
87
88  Tk::ValidateConfigure.__def_validcmd(binding, CalendarCommand)
89=begin
90  def command(cmd = Proc.new, args = nil)
91    if cmd.kind_of?(CalendarCommand)
92      configure('command', cmd)
93    elsif args
94      configure('command', [cmd, args])
95    else
96      configure('command', cmd)
97    end
98  end
99=end
100
101  ####################################
102
103  def get_string
104    tk_call(@path, 'get', '-string')
105  end
106  alias get get_string
107
108  def get_clicks
109    number(tk_call(@path, 'get', '-clicks'))
110  end
111
112  def select(date)
113    tk_call(@path, 'select', date)
114    self
115  end
116
117  def show(date)
118    tk_call(@path, 'show', date)
119    self
120  end
121  def show_now
122    tk_call(@path, 'show', 'now')
123    self
124  end
125end
126