rndk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/COPYING +137 -0
  4. data/Gemfile +4 -0
  5. data/README.md +100 -0
  6. data/Rakefile +3 -0
  7. data/TODO +68 -0
  8. data/demos/appointment.rb +346 -0
  9. data/demos/clock.rb +56 -0
  10. data/examples/01-hello-world.rb +56 -0
  11. data/examples/05-position-widget.rb +108 -0
  12. data/lib/rndk.rb +912 -0
  13. data/lib/rndk/alphalist.rb +572 -0
  14. data/lib/rndk/button.rb +370 -0
  15. data/lib/rndk/buttonbox.rb +359 -0
  16. data/lib/rndk/calendar.rb +766 -0
  17. data/lib/rndk/core/display.rb +63 -0
  18. data/lib/rndk/core/draw.rb +238 -0
  19. data/lib/rndk/core/quick_widgets.rb +106 -0
  20. data/lib/rndk/core/screen.rb +269 -0
  21. data/lib/rndk/core/traverse.rb +289 -0
  22. data/lib/rndk/core/widget.rb +506 -0
  23. data/lib/rndk/dialog.rb +367 -0
  24. data/lib/rndk/dscale.rb +13 -0
  25. data/lib/rndk/entry.rb +575 -0
  26. data/lib/rndk/fscale.rb +61 -0
  27. data/lib/rndk/fselect.rb +940 -0
  28. data/lib/rndk/fslider.rb +80 -0
  29. data/lib/rndk/graph.rb +401 -0
  30. data/lib/rndk/histogram.rb +412 -0
  31. data/lib/rndk/itemlist.rb +474 -0
  32. data/lib/rndk/label.rb +218 -0
  33. data/lib/rndk/marquee.rb +244 -0
  34. data/lib/rndk/matrix.rb +1189 -0
  35. data/lib/rndk/mentry.rb +619 -0
  36. data/lib/rndk/menu.rb +478 -0
  37. data/lib/rndk/radio.rb +538 -0
  38. data/lib/rndk/scale.rb +538 -0
  39. data/lib/rndk/scroll.rb +633 -0
  40. data/lib/rndk/scroller.rb +183 -0
  41. data/lib/rndk/selection.rb +630 -0
  42. data/lib/rndk/slider.rb +545 -0
  43. data/lib/rndk/swindow.rb +766 -0
  44. data/lib/rndk/template.rb +560 -0
  45. data/lib/rndk/uscale.rb +14 -0
  46. data/lib/rndk/uslider.rb +14 -0
  47. data/lib/rndk/version.rb +6 -0
  48. data/lib/rndk/viewer.rb +825 -0
  49. data/rndk.gemspec +35 -0
  50. metadata +141 -0
@@ -0,0 +1,766 @@
1
+ require 'rndk'
2
+
3
+ module RNDK
4
+ class CALENDAR < RNDK::Widget
5
+ attr_accessor :week_base
6
+ attr_reader :day, :month, :year
7
+
8
+ MONTHS_OF_THE_YEAR = [
9
+ 'NULL',
10
+ 'January',
11
+ 'February',
12
+ 'March',
13
+ 'April',
14
+ 'May',
15
+ 'June',
16
+ 'July',
17
+ 'August',
18
+ 'September',
19
+ 'October',
20
+ 'November',
21
+ 'December',
22
+ ]
23
+
24
+ DAYS_OF_THE_MONTH = [
25
+ -1,
26
+ 31,
27
+ 28,
28
+ 31,
29
+ 30,
30
+ 31,
31
+ 30,
32
+ 31,
33
+ 31,
34
+ 30,
35
+ 31,
36
+ 30,
37
+ 31,
38
+ ]
39
+
40
+ MAX_DAYS = 32
41
+ MAX_MONTHS = 13
42
+ MAX_YEARS = 140
43
+
44
+ CALENDAR_LIMIT = MAX_DAYS * MAX_MONTHS * MAX_YEARS
45
+
46
+ def self.CALENDAR_INDEX(d, m, y)
47
+ (y * RNDK::CALENDAR::MAX_MONTHS + m) * RNDK::CALENDAR::MAX_DAYS + d
48
+ end
49
+
50
+ def setCalendarCell(d, m, y, value)
51
+ @marker[RNDK::CALENDAR.CALENDAR_INDEX(d, m, y)] = value
52
+ end
53
+
54
+ def getCalendarCell(d, m, y)
55
+ @marker[RNDK::CALENDAR.CALENDAR_INDEX(d, m, y)]
56
+ end
57
+
58
+ def initialize(rndkscreen, xplace, yplace, title, day, month, year,
59
+ day_attrib, month_attrib, year_attrib, highlight, box, shadow)
60
+ super()
61
+ parent_width = Ncurses.getmaxx(rndkscreen.window)
62
+ parent_height = Ncurses.getmaxy(rndkscreen.window)
63
+ box_width = 24
64
+ box_height = 11
65
+ dayname = 'Su Mo Tu We Th Fr Sa '
66
+ bindings = {
67
+ 'T' => Ncurses::KEY_HOME,
68
+ 't' => Ncurses::KEY_HOME,
69
+ 'n' => Ncurses::KEY_NPAGE,
70
+ RNDK::FORCHAR => Ncurses::KEY_NPAGE,
71
+ 'p' => Ncurses::KEY_PPAGE,
72
+ RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
73
+ }
74
+
75
+ self.setBox(box)
76
+
77
+ box_width = self.setTitle(title, box_width)
78
+ box_height += @title_lines
79
+
80
+ # Make sure we didn't extend beyond the dimensions of the window.
81
+ box_width = [box_width, parent_width].min
82
+ box_height = [box_height, parent_height].min
83
+
84
+ # Rejustify the x and y positions if we need to.
85
+ xtmp = [xplace]
86
+ ytmp = [yplace]
87
+ RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
88
+ xpos = xtmp[0]
89
+ ypos = ytmp[0]
90
+
91
+ # Create the calendar window.
92
+ @win = Ncurses.newwin(box_height, box_width, ypos, xpos)
93
+
94
+ # Is the window nil?
95
+ if @win.nil?
96
+ self.destroy
97
+ return nil
98
+ end
99
+ Ncurses.keypad(@win, true)
100
+
101
+ # Set some variables.
102
+ @x_offset = (box_width - 20) / 2
103
+ @field_width = box_width - 2 * (1 + @border_size)
104
+
105
+ # Set months and day names
106
+ @month_name = RNDK::CALENDAR::MONTHS_OF_THE_YEAR.clone
107
+ @day_name = dayname
108
+
109
+ # Set the rest of the widget values.
110
+ @screen = rndkscreen
111
+ @parent = rndkscreen.window
112
+ @shadow_win = nil
113
+ @xpos = xpos
114
+ @ypos = ypos
115
+ @box_width = box_width
116
+ @box_height = box_height
117
+ @day = day
118
+ @month = month
119
+ @year = year
120
+ @day_attrib = day_attrib
121
+ @month_attrib = month_attrib
122
+ @year_attrib = year_attrib
123
+ @highlight = highlight
124
+ @width = box_width
125
+ @accepts_focus = true
126
+ @input_window = @win
127
+ @week_base = 0
128
+ @shadow = shadow
129
+ @label_win = Ncurses.subwin(@win, 1, @field_width,
130
+ ypos + @title_lines + 1, xpos + 1 + @border_size)
131
+ if @label_win.nil?
132
+ self.destroy
133
+ return nil
134
+ end
135
+
136
+ @field_win = Ncurses.subwin(@win, 7, 20,
137
+ ypos + @title_lines + 3, xpos + @x_offset)
138
+ if @field_win.nil?
139
+ self.destroy
140
+ return nil
141
+ end
142
+ self.setBox(box)
143
+
144
+ @marker = [0] * RNDK::CALENDAR::CALENDAR_LIMIT
145
+
146
+ # If the day/month/year values were 0, then use today's date.
147
+ if @day == 0 && @month == 0 && @year == 0
148
+ date_info = Time.new.gmtime
149
+ @day = date_info.day
150
+ @month = date_info.month
151
+ @year = date_info
152
+ end
153
+
154
+ # Verify the dates provided.
155
+ self.verifyCalendarDate
156
+
157
+ # Determine which day the month starts on.
158
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
159
+
160
+ # If a shadow was requested, then create the shadow window.
161
+ if shadow
162
+ @shadow_win = Ncurses.newwin(box_height, box_width,
163
+ ypos + 1, xpos + 1)
164
+ end
165
+
166
+ # Setup the key bindings.
167
+ bindings.each do |from, to|
168
+ self.bind(:CALENDAR, from, :getc, to)
169
+ end
170
+
171
+ rndkscreen.register(:CALENDAR, self)
172
+ end
173
+
174
+ # This function lets the user play with this widget.
175
+ def activate(actions)
176
+ ret = -1
177
+ self.draw(@box)
178
+
179
+ if actions.nil? || actions.size == 0
180
+ while true
181
+ input = self.getch([])
182
+
183
+ # Inject the character into the widget.
184
+ ret = self.inject(input)
185
+ if @exit_type != :EARLY_EXIT
186
+ return ret
187
+ end
188
+ end
189
+ else
190
+ # Inject each character one at a time.
191
+ actions.each do |action|
192
+ ret = self.inject(action)
193
+ if @exit_type != :EARLY_EXIT
194
+ return ret
195
+ end
196
+ end
197
+ end
198
+ return ret
199
+ end
200
+
201
+ # This injects a single character into the widget.
202
+ def inject(input)
203
+ # Declare local variables
204
+ pp_return = 1
205
+ ret = -1
206
+ complete = false
207
+
208
+ # Set the exit type
209
+ self.setExitType(0)
210
+
211
+ # Refresh the widget field.
212
+ self.drawField
213
+
214
+ # Check if there is a pre-process function to be called.
215
+ unless @pre_process_func.nil?
216
+ pp_return = @pre_process_func.call(:CALENDAR, self,
217
+ @pre_process_data, input)
218
+ end
219
+
220
+ # Should we continue?
221
+ if pp_return != 0
222
+ # Check a predefined binding
223
+ if self.checkBind(:CALENDAR, input)
224
+
225
+ ## FIXME What the heck? Missing method?
226
+ #self.checkEarlyExit
227
+
228
+ complete = true
229
+ else
230
+ case input
231
+ when Ncurses::KEY_UP then self.decrementCalendarDay 7
232
+ when Ncurses::KEY_DOWN then self.incrementCalendarDay 7
233
+ when Ncurses::KEY_LEFT then self.decrementCalendarDay 1
234
+ when Ncurses::KEY_RIGHT then self.incrementCalendarDay 1
235
+ when Ncurses::KEY_NPAGE then self.incrementCalendarMonth 1
236
+ when Ncurses::KEY_PPAGE then self.decrementCalendarMonth 1
237
+ when 'N'.ord then self.incrementCalendarMonth 6
238
+ when 'P'.ord then self.decrementCalendarMonth 6
239
+ when '-'.ord then self.decrementCalendarYear 1
240
+ when '+'.ord then self.incrementCalendarYear 1
241
+
242
+ when Ncurses::KEY_HOME then self.setDate(-1, -1, -1)
243
+
244
+ when RNDK::KEY_ESC
245
+ self.setExitType(input)
246
+ complete = true
247
+ when Ncurses::ERR
248
+ self.setExitType(input)
249
+ complete = true
250
+ when RNDK::KEY_TAB, RNDK::KEY_RETURN, Ncurses::KEY_ENTER
251
+ self.setExitType(input)
252
+ ret = self.getCurrentTime
253
+ complete = true
254
+ when RNDK::REFRESH
255
+ @screen.erase
256
+ @screen.refresh
257
+ end
258
+ end
259
+
260
+ # Should we do a post-process?
261
+ if !complete && !(@post_process_func.nil?)
262
+ @post_process_func.call(:CALENDAR, self, @post_process_data, input)
263
+ end
264
+ end
265
+
266
+ if !complete
267
+ self.setExitType(0)
268
+ end
269
+
270
+ @result_data = ret
271
+ return ret
272
+ end
273
+
274
+ # This moves the calendar field to the given location.
275
+ def move(xplace, yplace, relative, refresh_flag)
276
+ windows = [@win, @field_win, @label_win, @shadow_win]
277
+
278
+ self.move_specific(xplace, yplace, relative, refresh_flag, windows, [])
279
+ end
280
+
281
+ # This draws the calendar widget.
282
+ def draw(box)
283
+ header_len = @day_name.size
284
+ col_len = (6 + header_len) / 7
285
+
286
+ # Is there a shadow?
287
+ unless @shadow_win.nil?
288
+ Draw.drawShadow(@shadow_win)
289
+ end
290
+
291
+ # Box the widget if asked.
292
+ if box
293
+ Draw.drawObjBox(@win, self)
294
+ end
295
+
296
+ self.drawTitle(@win)
297
+
298
+ # Draw in the day-of-the-week header.
299
+ (0...7).each do |col|
300
+ src = col_len * ((col + (@week_base % 7)) % 7)
301
+ dst = col_len * col
302
+ Draw.writeChar(@win,
303
+ @x_offset + dst,
304
+ @title_lines + 2,
305
+ @day_name[src..-1],
306
+ RNDK::HORIZONTAL,
307
+ 0,
308
+ col_len)
309
+ end
310
+
311
+ Ncurses.wrefresh @win
312
+ self.drawField
313
+ end
314
+
315
+ # This draws the month field.
316
+ def drawField
317
+ month_name = @month_name[@month]
318
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
319
+ year_index = RNDK::CALENDAR.YEAR2INDEX(@year)
320
+ year_len = 0
321
+ save_y = -1
322
+ save_x = -1
323
+
324
+ day = (1 - @week_day + (@week_base % 7))
325
+ if day > 0
326
+ day -= 7
327
+ end
328
+
329
+ (1..6).each do |row|
330
+ (0...7).each do |col|
331
+ if day >= 1 && day <= month_length
332
+ xpos = col * 3
333
+ ypos = row
334
+
335
+ marker = @day_attrib
336
+ temp = '%02d' % day
337
+
338
+ if @day == day
339
+ marker = @highlight
340
+ save_y = ypos + Ncurses.getbegy(@field_win) - Ncurses.getbegy(@input_window)
341
+ save_x = 1
342
+ else
343
+ marker |= self.getMarker(day, @month, year_index)
344
+ end
345
+ Draw.writeCharAttrib(@field_win, xpos, ypos, temp, marker, RNDK::HORIZONTAL, 0, 2)
346
+ end
347
+ day += 1
348
+ end
349
+ end
350
+ Ncurses.wrefresh @field_win
351
+
352
+ # Draw the month in.
353
+ if !(@label_win.nil?)
354
+ temp = '%s %d,' % [month_name, @day]
355
+ Draw.writeChar(@label_win, 0, 0, temp, RNDK::HORIZONTAL, 0, temp.size)
356
+ Ncurses.wclrtoeol @label_win
357
+
358
+ # Draw the year in.
359
+ temp = '%d' % [@year]
360
+ year_len = temp.size
361
+ Draw.writeChar(@label_win, @field_width - year_len, 0, temp,
362
+ RNDK::HORIZONTAL, 0, year_len)
363
+
364
+ Ncurses.wmove(@label_win, 0, 0)
365
+ Ncurses.wrefresh @label_win
366
+
367
+ elsif save_y >= 0
368
+ Ncurses.wmove(@input_window, save_y, save_x)
369
+ Ncurses.wrefresh @input_window
370
+ end
371
+ end
372
+
373
+ # This sets multiple attributes of the widget
374
+ def set(day, month, year, day_attrib, month_attrib, year_attrib, highlight, box)
375
+ self.setDate(day, month, yar)
376
+ self.setDayAttribute(day_attrib)
377
+ self.setMonthAttribute(month_attrib)
378
+ self.setYearAttribute(year_attrib)
379
+ self.setHighlight(highlight)
380
+ self.setBox(box)
381
+ end
382
+
383
+ # This sets the date and some attributes.
384
+ def setDate(day, month, year)
385
+ # Get the current dates and set the default values for the
386
+ # day/month/year values for the calendar
387
+ date_info = Time.new.gmtime
388
+
389
+ # Set the date elements if we need to.
390
+ @day = if day == -1 then date_info.day else day end
391
+ @month = if month == -1 then date_info.month else month end
392
+ @year = if year == -1 then date_info.year else year end
393
+
394
+ # Verify the date information.
395
+ self.verifyCalendarDate
396
+
397
+ # Get the start of the current month.
398
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
399
+ end
400
+
401
+ # This returns the current date on the calendar.
402
+ def getDate(day, month, year)
403
+ day << @day
404
+ month << @month
405
+ year << @year
406
+ end
407
+
408
+ # This sets the attribute of the days in the calendar.
409
+ def setDayAttribute(attribute)
410
+ @day_attrib = attribute
411
+ end
412
+
413
+ def getDayAttribute
414
+ return @day_attrib
415
+ end
416
+
417
+ # This sets the attribute of the month names in the calendar.
418
+ def setMonthAttribute(attribute)
419
+ @month_attrib = attribute
420
+ end
421
+
422
+ def getMonthAttribute
423
+ return @month_attrib
424
+ end
425
+
426
+ # This sets the attribute of the year in the calendar.
427
+ def setYearAttribute(attribute)
428
+ @year_attrib = attribute
429
+ end
430
+
431
+ def getYearAttribute
432
+ return @year_attrib
433
+ end
434
+
435
+ # This sets the attribute of the highlight box.
436
+ def setHighlight(highlight)
437
+ @highlight = highlight
438
+ end
439
+
440
+ def getHighlight
441
+ return @highlight
442
+ end
443
+
444
+ # This sets the background attribute of the widget.
445
+ def setBKattr(attrib)
446
+ Ncurses.wbkgd(@win, attrib)
447
+ Ncurses.wbkgd(@field_win, attrib)
448
+ Ncurses.wbkgd(@label_win, attrib) unless @label_win.nil?
449
+ end
450
+
451
+ # This erases the calendar widget.
452
+ def erase
453
+ if self.validRNDKObject
454
+ RNDK.eraseCursesWindow @label_win
455
+ RNDK.eraseCursesWindow @field_win
456
+ RNDK.eraseCursesWindow @win
457
+ RNDK.eraseCursesWindow @shadow_win
458
+ end
459
+ end
460
+
461
+ # This destroys the calendar
462
+ def destroy
463
+ self.cleanTitle
464
+
465
+ RNDK.deleteCursesWindow @label_win
466
+ RNDK.deleteCursesWindow @field_win
467
+ RNDK.deleteCursesWindow @shadow_win
468
+ RNDK.deleteCursesWindow @win
469
+
470
+ # Clean the key bindings.
471
+ self.cleanBindings(:CALENDAR)
472
+
473
+ # Unregister the object.
474
+ RNDK::Screen.unregister(:CALENDAR, self)
475
+ end
476
+
477
+ # This sets a marker on the calendar.
478
+ def setMarker(day, month, year, marker)
479
+ year_index = RNDK::CALENDAR.YEAR2INDEX(year)
480
+ oldmarker = self.getMarker(day, month, year)
481
+
482
+ # Check to see if a marker has not already been set
483
+ if oldmarker != 0
484
+ self.setCalendarCell(day, month, year_index,
485
+ oldmarker | Ncurses::A_BLINK)
486
+ else
487
+ self.setCalendarCell(day, month, year_index, marker)
488
+ end
489
+ end
490
+
491
+ def getMarker(day, month, year)
492
+ result = 0
493
+ year = RNDK::CALENDAR.YEAR2INDEX(year)
494
+ if @marker != 0
495
+ result = self.getCalendarCell(day, month, year)
496
+ end
497
+ return result
498
+ end
499
+
500
+ # This sets a marker on the calendar.
501
+ def removeMarker(day, month, year)
502
+ year_index = RNDK::CALENDAR.YEAR2INDEX(year)
503
+ self.setCalendarCell(day, month, year_index, 0)
504
+ end
505
+
506
+ # THis function sets the month name.
507
+ def setMonthNames(months)
508
+ (1...[months.size, @month_name.size].min).each do |x|
509
+ @month_name[x] = months[x]
510
+ end
511
+ end
512
+
513
+ # This function sets the day's name
514
+ def setDaysNames(days)
515
+ @day_name = days.clone
516
+ end
517
+
518
+ # This makes sure that the dates provided exist.
519
+ def verifyCalendarDate
520
+ # Make sure the given year is not less than 1900.
521
+ if @year < 1900
522
+ @year = 1900
523
+ end
524
+
525
+ # Make sure the month is within range.
526
+ if @month > 12
527
+ @month = 12
528
+ end
529
+ if @month < 1
530
+ @month = 1
531
+ end
532
+
533
+ # Make sure the day given is within range of the month.
534
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
535
+ if @day < 1
536
+ @day = 1
537
+ end
538
+ if @day > month_length
539
+ @day = month_length
540
+ end
541
+ end
542
+
543
+ # This returns what day of the week the month starts on.
544
+ def self.getMonthStartWeekday(year, month)
545
+ return Time.mktime(year, month, 1, 10, 0, 0).wday
546
+ end
547
+
548
+ # This function returns a 1 if it's a leap year and 0 if not.
549
+ def self.isLeapYear(year)
550
+ result = false
551
+ if year % 4 == 0
552
+ if year % 100 == 0
553
+ if year % 400 == 0
554
+ result = true
555
+ end
556
+ else
557
+ result = true
558
+ end
559
+ end
560
+ return result
561
+ end
562
+
563
+ # This increments the current day by the given value.
564
+ def incrementCalendarDay(adjust)
565
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
566
+
567
+ # Make sure we adjust the day correctly.
568
+ if adjust + @day > month_length
569
+ # Have to increment the month by one.
570
+ @day = @day + adjust - month_length
571
+ self.incrementCalendarMonth(1)
572
+ else
573
+ @day += adjust
574
+ self.drawField
575
+ end
576
+ end
577
+
578
+ # This decrements the current day by the given value.
579
+ def decrementCalendarDay(adjust)
580
+ # Make sure we adjust the day correctly.
581
+ if @day - adjust < 1
582
+ # Set the day according to the length of the month.
583
+ if @month == 1
584
+ # make sure we aren't going past the year limit.
585
+ if @year == 1900
586
+ mesg = [
587
+ '<C></U>Error',
588
+ 'Can not go past the year 1900'
589
+ ]
590
+ RNDK.beep
591
+ @screen.popupLabel(mesg, 2)
592
+ return
593
+ end
594
+ month_length = RNDK::CALENDAR.getMonthLength(@year - 1, 12)
595
+ else
596
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month - 1)
597
+ end
598
+
599
+ @day = month_length - (adjust - @day)
600
+
601
+ # Have to decrement the month by one.
602
+ self.decrementCalendarMonth(1)
603
+ else
604
+ @day -= adjust
605
+ self.drawField
606
+ end
607
+ end
608
+
609
+ # This increments the current month by the given value.
610
+ def incrementCalendarMonth(adjust)
611
+ # Are we at the end of the year.
612
+ if @month + adjust > 12
613
+ @month = @month + adjust - 12
614
+ @year += 1
615
+ else
616
+ @month += adjust
617
+ end
618
+
619
+ # Get the length of the current month.
620
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
621
+ if @day > month_length
622
+ @day = month_length
623
+ end
624
+
625
+ # Get the start of the current month.
626
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
627
+
628
+ # Redraw the calendar.
629
+ self.erase
630
+ self.draw(@box)
631
+ end
632
+
633
+ # This decrements the current month by the given value.
634
+ def decrementCalendarMonth(adjust)
635
+ # Are we at the end of the year.
636
+ if @month <= adjust
637
+ if @year == 1900
638
+ mesg = [
639
+ '<C></U>Error',
640
+ 'Can not go past the year 1900',
641
+ ]
642
+ RNDK.beep
643
+ @screen.popupLabel(mesg, 2)
644
+ return
645
+ else
646
+ @month = 13 - adjust
647
+ @year -= 1
648
+ end
649
+ else
650
+ @month -= adjust
651
+ end
652
+
653
+ # Get the length of the current month.
654
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
655
+ if @day > month_length
656
+ @day = month_length
657
+ end
658
+
659
+ # Get the start o the current month.
660
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
661
+
662
+ # Redraw the calendar.
663
+ self.erase
664
+ self.draw(@box)
665
+ end
666
+
667
+ # This increments the current year by the given value.
668
+ def incrementCalendarYear(adjust)
669
+ # Increment the year.
670
+ @year += adjust
671
+
672
+ # If we are in Feb make sure we don't trip into voidness.
673
+ if @month == 2
674
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
675
+ if @day > month_length
676
+ @day = month_length
677
+ end
678
+ end
679
+
680
+ # Get the start of the current month.
681
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
682
+
683
+ # Redraw the calendar.
684
+ self.erase
685
+ self.draw(@box)
686
+ end
687
+
688
+ # This decrements the current year by the given value.
689
+ def decrementCalendarYear(adjust)
690
+ # Make sure we don't go out o bounds.
691
+ if @year - adjust < 1900
692
+ mesg = [
693
+ '<C></U>Error',
694
+ 'Can not go past the year 1900',
695
+ ]
696
+ RNDK.beep
697
+ @screen.popupLabel(mesg, 2)
698
+ return
699
+ end
700
+
701
+ # Decrement the year.
702
+ @year -= adjust
703
+
704
+ # If we are in Feb make sure we don't trip into voidness.
705
+ if @month == 2
706
+ month_length = RNDK::CALENDAR.getMonthLength(@year, @month)
707
+ if @day > month_length
708
+ @day = month_length
709
+ end
710
+ end
711
+
712
+ # Get the start of the current month.
713
+ @week_day = RNDK::CALENDAR.getMonthStartWeekday(@year, @month)
714
+
715
+ # Redraw the calendar.
716
+ self.erase
717
+ self.draw(@box)
718
+ end
719
+
720
+ # This returns the length of the current month.
721
+ def self.getMonthLength(year, month)
722
+ month_length = DAYS_OF_THE_MONTH[month]
723
+
724
+ if month == 2
725
+ month_length += if RNDK::CALENDAR.isLeapYear(year)
726
+ then 1
727
+ else 0
728
+ end
729
+ end
730
+
731
+ return month_length
732
+ end
733
+
734
+ # This returns what day of the week the month starts on.
735
+ def getCurrentTime
736
+ # Determine the current time and determine if we are in DST.
737
+ return Time.mktime(@year, @month, @day, 0, 0, 0).gmtime
738
+ end
739
+
740
+ def focus
741
+ # Original: drawRNDKFscale(widget, ObjOf (widget)->box);
742
+ self.draw(@box)
743
+ end
744
+
745
+ def unfocus
746
+ # Original: drawRNDKFscale(widget, ObjOf (widget)->box);
747
+ self.draw(@box)
748
+ end
749
+
750
+ def self.YEAR2INDEX(year)
751
+ if year >= 1900
752
+ year - 1900
753
+ else
754
+ year
755
+ end
756
+ end
757
+
758
+ def position
759
+ super(@win)
760
+ end
761
+
762
+ def object_type
763
+ :CALENDAR
764
+ end
765
+ end
766
+ end