source: tol/tolbase/lib/toltk/calendar.tcl @ c14b554

1941-docker-image-to-testdevel
Last change on this file since c14b554 was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 30.8 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : calendar.tcl
3# PURPOSE : This file contains the namespace CalendarTms.
4#           CalendarTms is for creating a several months calendar to
5#           highlight dates in a TOL TimeSet.
6#/////////////////////////////////////////////////////////////////////////////
7
8
9#/////////////////////////////////////////////////////////////////////////////
10# Namespace CalendarTms
11#/////////////////////////////////////////////////////////////////////////////
12
13#/////////////////////////////////////////////////////////////////////////////
14  namespace eval CalendarTms {
15#
16# PURPOSE: The purpose of this namespace is organize code and functions.
17#          A special namespace is created for each instance of CalendarTms.
18#
19# VARIABLES:
20#   tmpOpt  -> temporary array used to store the widgets and variables of the
21#              options dialog.
22#   calendarExpert ->
23#
24#/////////////////////////////////////////////////////////////////////////////
25  variable tmpOpt
26  variable calendarExpert ""
27}
28
29#/////////////////////////////////////////////////////////////////////////////
30  proc ::CalendarTms::Create {path {tms {}} } {
31#
32# PURPOSE: Creates a CalendarTms instance. Creates and packs the calendar
33#          window (frame with toolbar, month calendars and status bar)
34#
35# PARAMETERS:
36#   path ->
37#   tms  -> Timeset that is used.
38#
39# RETURN: CalendarTms instance
40#
41#/////////////////////////////////////////////////////////////////////////////
42  set instance ::CalendarTms::$path
43
44  #  A namespace is created for each bayes graph widget.
45
46  namespace eval $instance {
47 
48    # data -> array with information about the instance:
49    #   this  -> path to frame of the widget
50    #   all   -> if it's a general CalendarTms
51    #   tms   -> if it isn't a general CalendarTms, the TimeSet to highlight
52    #   rows  -> number of rows
53    #   cols  -> number of cols
54    #   n     -> number of months that are in the calendar
55    #   day   -> day selected
56    #   month -> month selected
57    #   year  -> year selected
58
59    variable data
60
61  }
62  upvar \#0 ${instance}::data data
63   
64  # Use or not of timeset specify
65  if {($tms == "")} {
66    set data(all)   1
67  } else  {
68    set data(tms)   $tms
69  }
70  # Read the origin configuration
71  ReadIni $instance 
72
73  set data(n) [expr $data(rows)*$data(cols)] 
74  set data(day)   1
75
76  # Create the widgets
77  set data(this)  [frame $path -class CalendarTms]
78
79  bind $data(this) <Destroy> [list ::CalendarTms::Destroy $instance]
80  set sw [ScrolledWindow $path.sw]
81  # buttons
82  set bbox [ButtonBox $path.bb -orient horizontal -spacing 5 -padx 0 -pady 0]
83  $bbox add -image [Bitmap::get "begin"] -height 16 -width 16\
84    -command [list ::CalendarTms::Adjust $instance  0 -1]\
85    -helptext [mc "Moves to previous year"] -relief link
86  $bbox add -image [Bitmap::get "reverse"] -height 16 -width 16\
87    -command [list ::CalendarTms::Adjust $instance -1 0]\
88    -helptext [mc "Moves to previous month"] -relief link
89  set data(back) [$bbox add -image [Bitmap::get "backward"] -height 1 -width 3\
90        -command [list ::CalendarTms::Back $instance]\
91        -helptext [mc "Moves to previous %1\$d months" $data(n)] -relief link]
92  set data(next) [$bbox add -image [Bitmap::get "forward"] -height 1 -width 3\
93        -command [list ::CalendarTms::Next $instance]\
94        -helptext [mc "Moves to next %1\$d months" $data(n)] -relief link]
95  $bbox add -image [Bitmap::get "play"] -height 16 -width 16\
96    -command [list ::CalendarTms::Adjust $instance  1  0]\
97    -helptext [mc "Moves to next month"] -relief link
98  $bbox add -image [Bitmap::get "end"] -height 16 -width 16\
99    -command [list ::CalendarTms::Adjust $instance  0  1]\
100    -helptext [mc "Moves to next year"] -relief link
101  set data(zoomin) [$bbox add -image [Bitmap::get "zoomin"] -height 16\
102         -width 16\
103         -command [list ::CalendarTms::ZoomIn $instance]\
104          -helptext [mc "Zoom In"] -relief link]
105  set data(zoomout) [$bbox add -image [Bitmap::get "zoomout"] -height 16\
106          -width 16\
107          -command [list ::CalendarTms::ZoomOut $instance]\
108          -helptext [mc "Zoom Out"] -relief link]
109  $bbox add -image [Bitmap::get "tools"] -height 16 -width 16\
110     -command [list ::CalendarTms::OptionsCreate $instance]\
111     -helptext [mc Options] -relief link
112 
113  if {[info exists data(all)]} { ;# General calendar
114    set data(allTms) [::tol::info variable TimeSet]
115    foreach item $data(allTms) {
116      ::tol::timeset create $item $item
117    }
118    label $path.lTms -text [mc TimeSet]:
119    # Combobox with the timesets
120    bcombobox $path.cbTms -width 18 -height 5 -editable false \
121        -values $data(allTms) \
122        -textvariable ::CalendarTms::${path}::data(tms) \
123        -modifycmd [list ::CalendarTms::Display $instance]
124  }
125 
126  set sf [ScrollableFrame $path.sw.fr -width 450]
127  $sw setwidget $sf
128  set f [$sf getframe]
129  set data(frame) $f
130  # Creation of the calendar
131  CreateCalendars $instance
132  # Set the statusbars
133  set data(statusbar) [frame $path.status]
134  set status_sep [Separator $data(statusbar).ss -orient horizontal]
135  set sf [frame $data(statusbar).sf]
136  set data(statusbar,cursor) [label $sf.cursor -text "" -relief sunken\
137                              -width 13]
138  grid $data(statusbar,cursor) -sticky w
139  grid columnconfigure $sf 1 -weight 1
140  grid $status_sep -sticky ew -pady 2
141  grid $sf         -sticky ew
142
143  grid columnconfigure $data(statusbar) 0 -weight 1
144
145  if {[info exists data(all)]} {
146    # If it's a general calendar
147    grid $path.bb $path.lTms $path.cbTms -sticky nw -padx 2
148    grid $path.sw     -columnspan 3      -sticky news
149    grid $path.status -columnspan 3      -sticky  ew
150  } else  {
151    # If the calendar is of specific timeset
152    grid $path.bb     -sticky nw -padx 2
153    grid $path.sw     -sticky news
154    grid $path.status -sticky  ew
155  }
156  # Packing the canvas
157  grid rowconfigure    $path 1 -weight 1
158  grid columnconfigure $path 0 -weight 1
159
160}
161
162#/////////////////////////////////////////////////////////////////////////////
163proc ::CalendarTms::CreateCalendars {instance} {
164#
165# PURPOSE:  Associates the events and packs every month of calendar.
166#
167#/////////////////////////////////////////////////////////////////////////////
168  upvar \#0 ${instance}::data data
169 
170  set month $data(month)
171  set year  $data(year)
172 
173  for {set i 0} {$i < $data(n)} {incr i} {
174    # associates the events of every month of the calendar.
175    date::Chooser $data(frame).$i $month $year \
176        [list OnClickDay "::CalendarTms::GetDay $instance" \
177             CheckDate   "::CalendarTms::CheckDate $instance" \
178             OnDoubleDay "::CalendarTms::ShowHours $instance"]
179    incr month
180    if {$month>12} {set month 1; incr year}
181  }
182  # Pack every month of calendar
183  for {set i 0} {$i < $data(rows)} {incr i} {
184    for {set j 0} {$j < $data(cols)} {incr j} {
185        grid $data(frame).[expr $data(cols)*$i + $j] -row $i -column $j \
186                                                     -sticky news
187
188    }
189  }
190}
191
192#/////////////////////////////////////////////////////////////////////////////
193proc  ::CalendarTms::Destroy { instance } {
194#
195# PURPOSE: Destroy the instance of CalendarTms
196#
197#/////////////////////////////////////////////////////////////////////////////   
198  upvar \#0 ${instance}::data data
199  # Eliminates the different used timesets
200  if {[info exists data(all)]} {
201    foreach item $data(allTms) {
202      ::tol::timeset destroy $item
203    }
204  }
205  # Save the state 
206  WriteIni $instance
207  # Delete the namespace of the instace
208  namespace delete $instance
209}
210
211#/////////////////////////////////////////////////////////////////////////////
212proc ::CalendarTms::ReadIni {instance} {
213#
214# PURPOSE: Load the configuration of calendar.
215#
216#/////////////////////////////////////////////////////////////////////////////
217  upvar \#0 ${instance}::data data
218  ::date::Init
219  upvar \#0 ::date::a a
220  set rini ::iniFile::Read
221
222  # Definition of options of the calendar
223  # Year of the first month of calendar 
224  set data(year)     [$rini Calendar year  [lindex [::tol::date now] 0]]
225  # First month of calendar
226  set data(month)    [$rini Calendar month [lindex [::tol::date now] 1]]
227  # Definition of position and separation between the elements of calendar
228  set data(rows)     [$rini Calendar rows 2]
229  set data(cols)     [$rini Calendar cols 3]
230  set a(dx)          [$rini Calendar dx  18]
231  set a(dy)          [$rini Calendar dy  14]
232  set a(-mon)        [$rini Calendar mon  0]
233  set a(otherday)    [$rini Calendar otherday 1]
234  set a(-bg)         [$rini Calendar bg white]
235  # Definition of values of presentation of calendar.
236  array set def {
237    titlefont     {Helvetica 10 bold}
238    weekdaysfont  {Helvetica 9}
239    dayfont       {Helvetica 9}
240    otherfont     {Helvetica 9}
241    titlefill     black
242    weekdaysfill  blue
243    dayfill       black
244    otherfill     grey
245    h1type        oval
246    h1font        {Helvetica 9 bold}
247    h1color       red
248    #h1fill        LightYellow
249    #h1outline     red
250    h1fill        ""
251    h1outline     ""
252    h2type        rect
253    h2font        {Helvetica 9 italic}
254    h2color       orange
255    #h2fill        white
256    #h2outline     blue
257    h2fill        ""
258    h2outline     ""
259  }
260  # Load of values of configuration
261  # Example: -$pre$post-> -dayfill 
262  foreach pre {title weekdays other day} {
263    foreach post {font fill} {
264        set a(-$pre$post) [$rini Calendar $pre$post $def($pre$post)]
265    }
266  }
267  foreach pre {h1 h2} {
268    foreach post {font color type fill outline} {
269       set a(-$pre$post) [$rini Calendar $pre$post $def($pre$post)]
270    }
271  }
272}
273
274#/////////////////////////////////////////////////////////////////////////////
275proc ::CalendarTms::WriteIni {instance} {
276#
277# PURPOSE: Save the configuration of calendar.
278#
279#/////////////////////////////////////////////////////////////////////////////
280  upvar \#0 ${instance}::data data
281  upvar \#0 ::date::a a
282  set wini ::iniFile::Write
283  # Write the values of position and separation between the elements
284  $wini Calendar year     $data(year)
285  $wini Calendar month    $data(month)
286  $wini Calendar rows     $data(rows)
287  $wini Calendar cols     $data(cols)
288  $wini Calendar dx       $a(dx)
289  $wini Calendar dy       $a(dy)
290  $wini Calendar mon      $a(-mon)
291  $wini Calendar otherday $a(otherday)
292  $wini Calendar bg       $a(-bg)
293
294  # Write of values of configuration
295  foreach pre {title weekdays other day} {
296    foreach post {font fill} {
297      $wini Calendar $pre$post $a(-$pre$post)
298    }
299  }
300  foreach pre {h1 h2} {
301    foreach post {font color type fill outline} {
302      $wini Calendar $pre$post $a(-$pre$post)
303    }
304  }
305  ::iniFile::Flush
306}
307
308#/////////////////////////////////////////////////////////////////////////////
309proc ::CalendarTms::GetDay {instance day month year tags} {
310#
311# PURPOSE: Shows the date in format tol in the bottom bar
312#
313#/////////////////////////////////////////////////////////////////////////////
314  upvar \#0 ${instance}::data data   
315###    puts "##################"
316###  puts [ListHours $instance $day $month $year]
317  set data(date) $day/$month/$year
318  $data(statusbar,cursor) configure\
319       -text "y${year}m[format "%02d" $month]d[format "%02d" $day]"   
320}
321
322#/////////////////////////////////////////////////////////////////////////////
323proc ::CalendarTms::ShowHours {instance day month year tags} {
324#/////////////////////////////////////////////////////////////////////////////   
325  if { [lsearch $tags type2] != -1 } {
326#    puts "day: $day"
327#    puts "month: $month"
328#    puts "year: $year"
329#    puts "tags: $tags"
330#    puts [concat "textSalida: " [ListHours $instance $day $month $year] ]
331           
332    Tolcon_Trace [ListHours $instance $day $month $year]
333  }
334}
335
336#/////////////////////////////////////////////////////////////////////////////
337proc ::CalendarTms::DateTol {day month year} {
338#/////////////////////////////////////////////////////////////////////////////
339#    set day   
340#    set month 
341#    set year   
342}
343
344#/////////////////////////////////////////////////////////////////////////////
345proc ::CalendarTms::ZoomIn {instance} {
346#
347# PURPOSE: Increases the distance between the elements of calendar.
348#
349#/////////////////////////////////////////////////////////////////////////////   
350  upvar \#0 ${instance}::data data
351  upvar \#0 ::date::a a   
352  # Increases the distance between the elements
353  set a(dx) [expr $a(dx)+1]
354  set a(dy) [expr $a(dy)+1]
355  # It isn't possible to be extended more
356  if {$a(dx) >= $a(dxmax)} { ;# Horizontally
357    set a(dx) $a(dxmax)
358    $data(zoomin) configure -state disabled
359  }
360  if {$a(dy) >= $a(dymax)} { ;# Vertically
361    set a(dy) $a(dymax)
362    $data(zoomin) configure -state disabled
363  }
364  # Now it's possible to zoom out 
365  $data(zoomout) configure -state normal
366  Display $instance
367}
368
369#/////////////////////////////////////////////////////////////////////////////
370proc ::CalendarTms::ZoomOut {instance} {
371#
372# PURPOSE: Decreases the distance between the elements of calendar.
373#
374#/////////////////////////////////////////////////////////////////////////////   
375  upvar \#0 ${instance}::data data   
376  upvar \#0 ::date::a a
377  # Decreases the distance between the elements
378  set a(dx) [expr $a(dx)-1]
379  set a(dy) [expr $a(dy)-1]
380  # It isn't possible to be reduced more
381  if {$a(dx) <= $a(dxmin)} { ;# Horizontally
382    set a(dx) $a(dxmin)
383    $data(zoomout) configure -state disabled
384  }
385  if {$a(dy) <= $a(dymin)} { ;# Vertically
386    set a(dy) $a(dymin)
387    $data(zoomout) configure -state disabled
388  }
389   # Now it's possible to zoom in
390  $data(zoomin) configure -state normal
391  Display $instance
392}
393
394#/////////////////////////////////////////////////////////////////////////////
395proc ::CalendarTms::Display {instance} {
396#
397# PURPOSE: Displays each one of the months of calendar
398#
399#/////////////////////////////////////////////////////////////////////////////   
400  upvar \#0 ${instance}::data data 
401  set n [expr $data(rows)*$data(cols)]
402  # Display each month
403  for {set i 0} {$i < $n} {incr i} {   
404    date::Display ::date::$data(frame).$i
405  }
406}
407
408#/////////////////////////////////////////////////////////////////////////////
409proc ::CalendarTms::ReDisplay {instance} {
410#
411# PURPOSE: Refresh the calendar.
412#
413#/////////////////////////////////////////////////////////////////////////////   
414  upvar \#0 ${instance}::data data
415  # Destroy the previous calendar
416  for {set i 0} {$i < $data(n)} {incr i} {
417    destroy $data(frame).$i
418  }
419  set data(n) [expr $data(rows)*$data(cols)]
420  # Configure back and next buttons   
421  $data(back) configure -helptext \
422        [mc "Moves to previous %1\$d months" $data(n)]
423  $data(next) configure -helptext \
424        [mc "Moves to next %1\$d months" $data(n)]
425  # Create and display updated calendar
426  CreateCalendars $instance
427  Display $instance
428}
429
430#/////////////////////////////////////////////////////////////////////////////
431proc ::CalendarTms::Adjust {instance dmonth dyear} {
432#
433# PURPOSE: Move to a calendar witch starts in a concrete month and year,
434#          with a displacement respect to the present values.
435#
436# PARAMETERS:
437#     dmonth -> Amount of months to displace. Example: 1 next or -1 previous
438#     dyear -> Amount of years to displace. Example: 1 next or -1 previous
439#
440#/////////////////////////////////////////////////////////////////////////////
441  upvar \#0 ${instance}::data data
442  # The increases or decrements are applied
443  incr data(year)  $dyear
444  incr data(month) $dmonth
445  # Increases the year of the calendar
446  if {$data(month)>12} {
447    incr data(year)  [expr $data(month)/12]
448    set data(month)  [expr $data(month)%12]
449  }
450  # Decreases the year of the calendar
451  if {$data(month)<1}  {
452    incr data(year) -[expr 1+abs($data(month))/12]
453    set data(month) [expr 12 - (abs($data(month))%12)]       
454  }
455  # Adjust the calendars of all the months
456  set n [expr $data(rows)*$data(cols)]
457  for {set i 0} {$i < $n} {incr i} {
458    date::Adjust ::date::$data(frame).$i $dmonth $dyear
459  }
460}
461
462#/////////////////////////////////////////////////////////////////////////////
463proc ::CalendarTms::Back {instance} {
464#
465# PURPOSE: Moves the calendar to the previous [n number of months].
466#
467#/////////////////////////////////////////////////////////////////////////////   
468  upvar \#0 ${instance}::data data
469  Adjust $instance -$data(n) 0
470}
471
472#/////////////////////////////////////////////////////////////////////////////
473proc ::CalendarTms::Next {instance} {
474#
475# PURPOSE: Moves the calendar to the following [n number of months].
476#
477#/////////////////////////////////////////////////////////////////////////////
478  upvar \#0 ${instance}::data data
479  Adjust $instance $data(n) 0
480}
481
482# Return -
483
484#/////////////////////////////////////////////////////////////////////////////
485proc ::CalendarTms::CheckDate {instance day month year} {
486#
487# PURPOSE: Check if a date is belongs to a Timeset.
488#
489# PARAMETERS:
490#     day, month, year -> Date to check.
491#       
492# RETURN:
493#    0 - date does not belong to tms
494#    1 - date does belong to tms but only the hour 0 of that day
495#    2 - date does belong and some other hour of the same day
496#
497#/////////////////////////////////////////////////////////////////////////////   
498  upvar \#0 ${instance}::data data
499  set result 0
500  set date "$year $month $day"
501  # The calendar has a Timeset
502  if { [string length $data(tms)] } {
503    # The date belongs to the Timeset 
504    set result [$data(tms) contain $date]
505   #foreach {y0 m0 d0 h0 mi0 s0} [$data(tms) start [list $year $month $day]] break
506   # if { $y0 == $year && $m0 == $month && $d0 == $day } {
507   #   if { [expr $h0 + $mi0 + $s0 > 0] } {
508   #     set result 2
509   #   } else {
510   #     foreach {y0 m0 d0} [$data(tms) next] break
511   #     set result [expr (($y0 == $year) && ($m0 == $month) && ($d0 == $day))+1]
512   #   }
513   # }
514  }
515  return $result
516}
517
518#/////////////////////////////////////////////////////////////////////////////
519proc ::CalendarTms::ListHours {instance day month year} {
520#
521# PURPOSE:
522#
523# PARAMETERS:
524#     day, month, year -> Date
525#
526#/////////////////////////////////////////////////////////////////////////////   
527  upvar \#0 ${instance}::data data
528  set lstHours {}
529  # The calendar has a Timeset
530  if { [string length $data(tms)] } {
531    set tick [$data(tms) start [list $year $month $day]]
532    foreach {y0 m0 d0} $tick break
533    while { ($y0 == $year) && ($m0 == $month) && ($d0 == $day) } {
534      lappend lstHours [lrange $tick 3 end]
535      set tick [$data(tms) next]
536      foreach {y0 m0 d0} $tick {
537        break
538      }
539    }
540  }
541  set lstHours
542}
543
544#/////////////////////////////////////////////////////////////////////////////
545proc ::CalendarTms::ViewTimeSet {} {
546#
547# PURPOSE:
548#
549#/////////////////////////////////////////////////////////////////////////////   
550  # create
551  if { [winfo exists $::CalendarTms::calendarExpert] } {
552    if { [$::CalendarTms::calendarExpert cget -state] eq "minimized" } {
553      $::CalendarTms::calendarExpert restore
554    }
555    $::CalendarTms::calendarExpert raise
556        return
557  } else {
558    set tl [::project::CreateForm \
559              -width 470 -height 345 \
560              -iniconfig Calendar -title [mc "TimeSets calendar"] \
561              -helpkey  "Tb4Cal"]
562        set tlf [$tl getframe]
563    set ::CalendarTms::calendarExpert $tl
564    # config
565        ::CalendarTms::Create $tlf.t
566    $tl bind <Control-F4> [list $tl kill]
567    pack $tlf.t -fill both -expand yes
568  }
569}
570
571#/////////////////////////////////////////////////////////////////////////////
572proc ::CalendarTms::OptionsCreate {instance} {
573#
574# PURPOSE: It creates the a dialog of options of the calendar
575#
576#/////////////////////////////////////////////////////////////////////////////   
577  upvar \#0 ${instance}::data data
578  variable tmpOpt
579  # Read the options that the calendar had previously
580  OptionsGet $instance
581  # Create the dialog 
582  set path $data(this)
583  set dialog [Dialog $data(this).t -title [mc "Calendar Options"]\
584            -default 0 \
585            -parent $data(this) -modal local]
586  wm protocol $dialog WM_DELETE_WINDOW \
587        [list ::CalendarTms::OptionsDestroy $instance $dialog]
588  # Create the frame within the dialog
589  set w [$dialog getframe]
590  wm resizable $dialog 0 0
591  # Create the set of tabs
592  set w_tabset [::blt::tabset $w.ts -relief flat -highlightthickness 0\
593            -bd 0 -outerpad 0 -tier 2 -slant right -textside right]
594  $w_tabset insert end General Style Highlight
595  # Create each one of frames
596  set f1 [frame $w_tabset.f1]
597  set f2 [frame $w_tabset.f2]
598  set f3 [frame $w_tabset.f3]
599  # Create each one of tabs
600  $w_tabset tab configure "General" -text [mc "General"]\
601          -window $f1 -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
602  $w_tabset tab configure "Style" -text [mc "Style"]\
603          -window $f2 -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
604  $w_tabset tab configure "Highlight" -text [mc "Highligth"]\
605          -window $f3 -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
606  # Fill up each one of the tabs
607  OptionsCreateGeneral $instance $f1
608  OptionsCreateStyle   $instance $f2
609  OptionsCreateHighlight $instance $f3
610   
611  set w_bbox \
612          [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
613          -homogeneous false]
614  $w_bbox add -text [mc "Accept"] -relief link \
615          -helptext [mc "Accept"] \
616          -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
617          -command [list ::CalendarTms::OptionsOK $instance $dialog]
618  $w_bbox add -text [mc "Cancel"] -relief link \
619          -helptext [mc "Cancel"]\
620          -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
621          -command [list ::CalendarTms::OptionsDestroy $instance $dialog]
622  $w_bbox add -text [mc "Apply"] -relief link \
623          -helptext [mc "Apply"]\
624          -image [::Bitmap::get apply] -compound left -padx 5 -pady 1 \
625          -command [list ::CalendarTms::OptionsApply $instance]     
626   
627    # Pack all created components
628    pack $w_bbox -fill x -expand false -side bottom
629    pack $w_tabset -fill both -expand true
630   
631  $dialog draw
632}
633
634#/////////////////////////////////////////////////////////////////////////////
635proc ::CalendarTms::OptionsCreateGeneral {instance w} {
636#
637# PURPOSE: Creation of the tab "General Options"
638#
639# PARAMETERS:
640#     w -> frame container
641#
642#/////////////////////////////////////////////////////////////////////////////
643  variable tmpOpt
644  TitleFrame $w.tf -text [mc "General Options"]
645  set f [$w.tf getframe]
646
647  #month and year
648  label $f.lm -text [mc Month]:
649  SpinBox $f.sbm -range {1 12 1}\
650    -textvariable ::CalendarTms::tmpOpt(var,month) -width 6 -editable 0
651  label $f.ly -text [mc Year]:
652  SpinBox $f.sby -range {0 9999 1}\
653     -textvariable ::CalendarTms::tmpOpt(var,year) -width 6
654  #rows and columns
655  label $f.lr -text [mc Rows]:
656  SpinBox $f.sbr -range {1 8 1}\
657    -textvariable ::CalendarTms::tmpOpt(var,rows) -width 6 -editable 0
658  label $f.lc -text [mc Columns]:
659  SpinBox $f.sbc -range {1 8 1}\
660    -textvariable ::CalendarTms::tmpOpt(var,cols)  -width 6 -editable 0
661  #other options
662  checkbutton $f.mon -text [mc "Sunday starts week"]\
663     -variable ::CalendarTms::tmpOpt(var,-mon)   
664  checkbutton $f.oth  -text [mc "Other days"]\
665     -variable ::CalendarTms::tmpOpt(var,otherday)
666
667  frame $f.f -width 25
668  grid $f.f $f.lm   $f.sbm  $f.ly   $f.sby -sticky nw -pady 1 -padx 2
669  grid ^    $f.lr   $f.sbr  $f.lc   $f.sbc -sticky nw -pady 1 -padx 2
670  grid ^    $f.mon  -       -       $f.oth -sticky nw -pady 2 -padx 2
671  grid columnconfigure $f 4 -weight 1
672  grid rowconfigure    $f 2 -weight 1
673  grid columnconfigure $f 1 -pad 20
674
675  grid $w.tf -sticky news -padx 2
676  grid rowconfigure    $w 0 -weight 1
677  grid columnconfigure $w 0 -weight 1
678}
679
680#/////////////////////////////////////////////////////////////////////////////
681proc ::CalendarTms::OptionsCreateStyle {instance w} {
682#
683# PURPOSE: Creation of the tab "Appareance Options"
684#
685# PARAMETERS:
686#     w -> frame container
687#
688#/////////////////////////////////////////////////////////////////////////////   
689  global toltk_options
690  variable tmpOpt
691  TitleFrame $w.tf -text [mc "Appareance Options"]
692  set f [$w.tf getframe]
693  #Colors and fonts
694  label $f.lbg -text [mc "Background"]:
695  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-bg) $f.fbg
696
697  label $f.lFont  -text [mc "Font"]  -font $toltk_options(fonts,Title1)
698  label $f.lColor -text [mc "Color"] -font $toltk_options(fonts,Title1)
699
700  label $f.lt -text [mc "Month names"]:
701  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-titlefont) $f.btf
702  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-titlefill) $f.ftc
703  label $f.lw -text [mc "Weekdays"]:
704  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-weekdaysfont) $f.bwf
705  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-weekdaysfill) $f.fwc
706  label $f.ld -text [mc "Month days"]:
707  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-dayfont) $f.bdf
708  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-dayfill) $f.fdc
709  label $f.lo -text [mc "Other days"]:
710  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-otherfont) $f.bof
711  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-otherfill) $f.foc
712
713  frame $f.f -width 25
714  grid $f.f $f.lbg $f.fbg    -          -sticky nw -pady 0 -padx 2
715  grid ^    ^      $f.lFont  $f.lColor  -sticky n -pady 2 -padx 2
716  grid ^    $f.lt  $f.btf    $f.ftc     -sticky n -pady 0 -padx 2
717  grid ^    $f.lw  $f.bwf    $f.fwc     -sticky n -pady 0 -padx 2
718  grid ^    $f.ld  $f.bdf    $f.fdc     -sticky n -pady 0 -padx 2
719  grid ^    $f.lo  $f.bof    $f.foc     -sticky n -pady 0 -padx 2
720 
721  grid configure $f.lbg $f.lt $f.lw $f.ld $f.lo -sticky nw
722
723  grid columnconfigure $f 4 -weight 1
724  grid rowconfigure    $f 6 -weight 1
725
726  grid $w.tf -sticky news -padx 2
727  grid rowconfigure    $w 0 -weight 1
728  grid columnconfigure $w 0 -weight 1
729}
730
731#/////////////////////////////////////////////////////////////////////////////
732proc ::CalendarTms::OptionsCreateHighlight {instance w} {
733#
734# PURPOSE: Creation of the tab "Highligth Appareance Options"
735#
736# PARAMETERS:
737#     w -> frame container
738#
739#/////////////////////////////////////////////////////////////////////////////   
740  global toltk_options
741  variable tmpOpt
742  TitleFrame $w.tf -text [mc "Highligth Appareance Options"]
743  set f [$w.tf getframe]
744
745
746  frame $f.f
747  label $f.lFont    -text [mc "Font"]    -font $toltk_options(fonts,Title1)
748  label $f.lColor   -text [mc "Color"]   -font $toltk_options(fonts,Title1)
749  label $f.lType    -text [mc "Type"]    -font $toltk_options(fonts,Title1)
750  label $f.lFill    -text [mc "Fill"]    -font $toltk_options(fonts,Title1)
751  label $f.lOutline -text [mc "Outline"] -font $toltk_options(fonts,Title1)
752
753  label $f.lh1 -text [mc "Full highligth"]:
754  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-h1font) $f.bh1fo
755  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h1color) $f.fh1c
756  radiobutton $f.rbh1O -text [mc oval] -value oval -highlightthickness 0 \
757    -pady 0 -variable ::CalendarTms::tmpOpt(var,-h1type)
758  radiobutton $f.rbh1R -text [mc "rectangle"] -value rect -highlightthickness 0\
759    -pady 0 -variable ::CalendarTms::tmpOpt(var,-h1type)
760  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h1fill)    $f.fh1f "" 1
761  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h1outline) $f.fh1o "" 1
762  label $f.lh2 -text [mc "Partial highligth"]: -anchor w
763  ::Objects::FontCreate ::CalendarTms::tmpOpt(var,-h2font) $f.bh2fo
764  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h2color) $f.fh2c
765  radiobutton $f.rbh2O -text [mc "oval"] -value oval -highlightthickness 0\
766    -pady 0 -variable ::CalendarTms::tmpOpt(var,-h2type)
767  radiobutton $f.rbh2R -text [mc "rectangle"] -value rect -highlightthickness 0\
768    -pady 0 -variable ::CalendarTms::tmpOpt(var,-h2type)
769  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h2fill)    $f.fh2f "" 1
770  ::Objects::ColorCreate ::CalendarTms::tmpOpt(var,-h2outline) $f.fh2o "" 1
771
772  grid $f.f   $f.lFont $f.lColor $f.lType  -         $f.lFill $f.lOutline \
773    -sticky n -pady 2 -padx 2
774  grid $f.lh1 $f.bh1fo $f.fh1c   $f.rbh1O  $f.rbh1R  $f.fh1f  $f.fh1o     \
775    -sticky n
776  grid $f.lh2 $f.bh2fo $f.fh2c   $f.rbh2O  $f.rbh2R  $f.fh2f  $f.fh2o     \
777    -sticky n
778
779  grid configure $f.lh1 $f.lh2 -sticky nw
780
781  grid columnconfigure $f 7 -weight 1
782  grid rowconfigure    $f 3 -weight 1
783
784  grid $w.tf -sticky news -padx 2
785  grid rowconfigure    $w 0 -weight 1
786  grid columnconfigure $w 0 -weight 1
787}
788
789#/////////////////////////////////////////////////////////////////////////////
790  proc ::CalendarTms::OptionsDestroy {this dialog} {
791#
792# PURPOSE: Destroy options dialog
793#
794# PARAMETERS:
795#   this   -> Instance of CalendarTms
796#   dialog -> Options dialog
797#
798#/////////////////////////////////////////////////////////////////////////////
799  variable tmpOpt
800  array unset tmpOpt
801  destroy $dialog
802}
803
804#/////////////////////////////////////////////////////////////////////////////
805proc ::CalendarTms::OptionsGet {instance} {
806#
807# PURPOSE: Get the options from the variable temporary tmpOpt to the Calendar
808#   
809#/////////////////////////////////////////////////////////////////////////////   
810  upvar \#0 ${instance}::data data
811  upvar \#0 ::date::a a
812  variable tmpOpt
813  # Get the the own options of the calendar
814  set tmpOpt(var,year)       $data(year)
815  set tmpOpt(var,month)      $data(month)
816  set tmpOpt(var,rows)       $data(rows)
817  set tmpOpt(var,cols)       $data(cols)
818  set tmpOpt(var,-mon)       $a(-mon)
819  set tmpOpt(var,otherday)   $a(otherday)
820  set tmpOpt(var,-bg)        $a(-bg)
821  # Get the options of presentation of the calendar 
822  foreach pre {-title -weekdays -other -day} {
823    foreach post {font fill} {
824      set tmpOpt(var,$pre$post) $a($pre$post)
825    }
826  }
827  foreach pre {-h1 -h2} {
828    foreach post {font color type fill outline} {
829      set tmpOpt(var,$pre$post) $a($pre$post)
830    }
831  }
832}
833
834#/////////////////////////////////////////////////////////////////////////////
835proc ::CalendarTms::OptionsSet {instance} {
836#
837# PURPOSE: Set the options from the Calendar to the variable temporary tmpOpt
838#
839#/////////////////////////////////////////////////////////////////////////////
840  upvar \#0 ${instance}::data data
841  upvar \#0 ::date::a a
842  variable tmpOpt
843  # Set the the own options of the calendar
844  set data(year)    $tmpOpt(var,year)
845  set data(month)   $tmpOpt(var,month)
846  set data(rows)    $tmpOpt(var,rows)
847  set data(cols)    $tmpOpt(var,cols)
848  set a(-mon)       $tmpOpt(var,-mon)
849  set a(otherday)   $tmpOpt(var,otherday)
850  set a(-bg)        $tmpOpt(var,-bg)
851  # Set the options of presentation of the calendar
852  foreach pre {-title -weekdays -other -day} {
853    foreach post {font fill} {
854      set a($pre$post) $tmpOpt(var,$pre$post)
855    }
856  }
857  foreach pre {-h1 -h2} {
858    foreach post {font color type fill outline} {
859      set a($pre$post) $tmpOpt(var,$pre$post)
860    }
861  }
862}
863
864#/////////////////////////////////////////////////////////////////////////////
865proc ::CalendarTms::OptionsApply {instance} {
866#
867# PURPOSE: The options are applied, and the dialogue is refreshed without
868#          destroying it
869#
870#/////////////////////////////////////////////////////////////////////////////   
871  OptionsSet $instance
872  ReDisplay  $instance
873}
874
875#/////////////////////////////////////////////////////////////////////////////
876proc ::CalendarTms::OptionsOK {instance dialog} {
877#
878# PURPOSE: The options are applied, and the dialogue is destroyed
879#
880#/////////////////////////////////////////////////////////////////////////////   
881  OptionsApply $instance
882  OptionsDestroy $instance $dialog
883}
Note: See TracBrowser for help on using the repository browser.