Fixes
[tcl-tlc.git] / scripts / dateentry.itk
blob87f7576b8a16c9dc73675ad47e3ff6f4a78cfaeb
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                 ttk::entry $w.label -textvariable [scope date]
60         } {
61                 rename -width -labelwidth labelWidth LabelWidth
62                 ignore -state
63         }
64         $w.label state readonly
65         bind $w.label <Button-1> [code $this request_lookup]
67         itk_component add button {
68                 Datelookup $w.datelookup -newselection [code $this newselection]
69         } {
70                 usual
71                 keep -buttonrelief
72                 keep -resultformat -special_cb
73                 keep -validfrom -validto -state
74                 keep -onlyweekdays
75                 ignore -newselection
76         }
78         eval itk_initialize $args
80         table $w \
81                         $w.label                1,1 -fill x \
82                         $w.datelookup   1,2 -anchor e -pady {0 1}
83         table configure $w r1 c2 -resize none
87 body tlc::Dateentry::request_lookup {} { #<<<1
88         log debug $w
89         if {$itk_option(-state) != "disabled"} {
90                 $w.datelookup toggle
91         } else {
92                 $w.datelookup popdown
93         }
97 body tlc::Dateentry::newselection {newdate} { #<<<1
98         log debug $w
99         set date        $newdate
100         set_textvariable $date
101         if {$itk_option(-command) != ""} {
102                 uplevel #0 $itk_option(-command) [list $newdate]
103         }
104         invoke_handlers onselect [list $newdate]
108 body tlc::Dateentry::rerender_dom_ref {} { #<<<1
109         return [[[$w.datelookup component popup] component calendar] rerender_dom_ref]
113 body tlc::Dateentry::textvariable_changed {newvalue} { #<<<1
114         log debug $w
115         set date        $newvalue
119 body tlc::Dateentry::get_date {} { #<<<1
120         return $date