Added custom field type support to Form
[tcl-tlc.git] / scripts / dateentry.itk
blob89d9c93ef488a547c7fbbdc4fce5a2cc814e3657
1 # vim: foldmarker=<<<,>>>
3 option add *Dateentry.labelBorderwidth  2                       widgetDefault
4 option add *Dateentry.labelRelief               sunken          widgetDefault
5 option add *Dateentry.labelWidth                14                      widgetDefault
6 option add *Dateentry.anchor                    nw                      widgetDefault
7 option add *Dateentry.buttonBorderwidth 1                       widgetDefault
8 option add *Dateentry.resultFormat              "%d/%m/%Y"      widgetDefault
10 class tlc::Dateentry {
11         inherit tlc::Mywidget tlc::Handlers tlc::Textvariable
13         constructor {args} {}
15         itk_option define -command command Command {}
16         itk_option define -state state State "normal"
17         itk_option define -textbackground textBackground TextBackground white
19         public {
20                 method rerender_dom_ref {}
21                 method get_date {}
22         }
24         protected {
25                 method textvariable_changed {newvalue}
26         }
28         private {
29                 variable date   ""
31                 method request_lookup {}
32                 method newselection {newdate}
33         }
37 configbody tlc::Dateentry::textbackground { #<<<1
38         if {$itk_option(-state) != "disabled"} {
39                 $w.label configure -background $itk_option(-textbackground)
40         }
44 configbody tlc::Dateentry::state { #<<<1
45         log debug "$w -state reconfigured: ($itk_option(-state))"
46         $w.datelookup popdown
47         $w.label configure -background \
48                         [expr {$itk_option(-state) == "disabled" ? \
49                                 $::tlc::config(disabledbackground) : $::tlc::config(textbackground)}]
50         $w.label configure -foreground \
51                         [expr {$itk_option(-state) == "disabled" ? \
52                                 $::tlc::config(disabledforeground) : $::tlc::config(enabledforeground)}]
56 body tlc::Dateentry::constructor {args} { #<<<1
57         log debug $w
58         itk_component add label {
59                 label $w.label -textvariable [scope date] -takefocus 1
60         } {
61                 usual
62                 rename -borderwidth -labelborderwidth labelBorderwidth LabelBorderwidth
63                 rename -relief -labelrelief labelRelief LabelRelief
64                 rename -background -textbackground textBackground TextBackground
65                 rename -width -labelwidth labelWidth LabelWidth
66                 rename -highlightthickness -labelhighlightthickness labelHighlightThickness LabelHighlightThickness
67                 rename -highlightbackground -labelhighlightbackground labelHighlightBackground LabelHighlightBackground
68                 keep -anchor
69                 ignore -state
70         }
71         bind $w.label <Button-1> [code $this request_lookup]
73         itk_component add button {
74                 Datelookup $w.datelookup -newselection [code $this newselection]
75         } {
76                 usual
77                 keep -buttonrelief
78                 rename -borderwidth -buttonborderwidth buttonBorderwidth ButtonBorderwidth
79                 rename -highlightbackground -buttonhighlightbackground buttonHighlightBackground ButtonHighLightBackground
80                 keep -resultformat -special_cb
81                 keep -validfrom -validto -state
82                 keep -onlyweekdays
83                 ignore -newselection
84         }
86         eval itk_initialize $args
88         table $w \
89                         $w.label                1,1 -fill x \
90                         $w.datelookup   1,2 -anchor e -pady {0 1}
91         table configure $w r1 c2 -resize none
95 body tlc::Dateentry::request_lookup {} { #<<<1
96         log debug $w
97         if {$itk_option(-state) != "disabled"} {
98                 $w.datelookup toggle
99         } else {
100                 $w.datelookup popdown
101         }
105 body tlc::Dateentry::newselection {newdate} { #<<<1
106         log debug $w
107         set date        $newdate
108         set_textvariable $date
109         if {$itk_option(-command) != ""} {
110                 uplevel #0 $itk_option(-command) [list $newdate]
111         }
112         invoke_handlers onselect [list $newdate]
116 body tlc::Dateentry::rerender_dom_ref {} { #<<<1
117         return [[[$w.datelookup component popup] component calendar] rerender_dom_ref]
121 body tlc::Dateentry::textvariable_changed {newvalue} { #<<<1
122         log debug $w
123         set date        $newvalue
127 body tlc::Dateentry::get_date {} { #<<<1
128         return $date