Class: CDK::CALENDAR
Constant Summary collapse
- MONTHS_OF_THE_YEAR =
[ 'NULL', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ]
- DAYS_OF_THE_MONTH =
[ -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, ]
- MAX_DAYS =
32
- MAX_MONTHS =
13
- MAX_YEARS =
140
- CALENDAR_LIMIT =
MAX_DAYS * MAX_MONTHS * MAX_YEARS
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#week_base ⇒ Object
Returns the value of attribute week_base.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes included from HasTitle
Attributes included from HasScreen
#is_visible, #screen, #screen_index
Attributes included from ExitConditions
Attributes included from Bindings
Attributes included from Focusable
Attributes included from Borders
#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box
Class Method Summary collapse
- .CALENDAR_INDEX(d, m, y) ⇒ Object
-
.getMonthLength(year, month) ⇒ Object
This returns the length of the current month.
-
.getMonthStartWeekday(year, month) ⇒ Object
This returns what day of the week the month starts on.
-
.isLeapYear(year) ⇒ Object
This function returns a 1 if it’s a leap year and 0 if not.
- .YEAR2INDEX(year) ⇒ Object
Instance Method Summary collapse
-
#activate(actions) ⇒ Object
This function lets the user play with this widget.
-
#decrementCalendarDay(adjust) ⇒ Object
This decrements the current day by the given value.
-
#decrementCalendarMonth(adjust) ⇒ Object
This decrements the current month by the given value.
-
#decrementCalendarYear(adjust) ⇒ Object
This decrements the current year by the given value.
-
#destroy ⇒ Object
This destroys the calendar.
-
#draw(box) ⇒ Object
This draws the calendar widget.
-
#drawField ⇒ Object
This draws the month field.
-
#erase ⇒ Object
This erases the calendar widget.
- #focus ⇒ Object
- #getCalendarCell(d, m, y) ⇒ Object
-
#getCurrentTime ⇒ Object
This returns what day of the week the month starts on.
-
#getDate(day, month, year) ⇒ Object
This returns the current date on the calendar.
- #getDayAttribute ⇒ Object
- #getHighlight ⇒ Object
- #getMarker(day, month, year) ⇒ Object
- #getMonthAttribute ⇒ Object
- #getYearAttribute ⇒ Object
-
#incrementCalendarDay(adjust) ⇒ Object
This increments the current day by the given value.
-
#incrementCalendarMonth(adjust) ⇒ Object
This increments the current month by the given value.
-
#incrementCalendarYear(adjust) ⇒ Object
This increments the current year by the given value.
-
#initialize(cdkscreen, xplace, yplace, title, day, month, year, day_attrib, month_attrib, year_attrib, highlight, box, shadow) ⇒ CALENDAR
constructor
A new instance of CALENDAR.
-
#inject(input) ⇒ Object
This injects a single character into the widget.
-
#move(xplace, yplace, relative, refresh_flag) ⇒ Object
This moves the calendar field to the given location.
- #object_type ⇒ Object
- #position ⇒ Object
-
#removeMarker(day, month, year) ⇒ Object
This sets a marker on the calendar.
-
#set(day, month, year, day_attrib, month_attrib, year_attrib, highlight, box) ⇒ Object
This sets multiple attributes of the widget.
-
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
- #setCalendarCell(d, m, y, value) ⇒ Object
-
#setDate(day, month, year) ⇒ Object
This sets the date and some attributes.
-
#setDayAttribute(attribute) ⇒ Object
This sets the attribute of the days in the calendar.
-
#setDaysNames(days) ⇒ Object
This function sets the day’s name.
-
#setHighlight(highlight) ⇒ Object
This sets the attribute of the highlight box.
-
#setMarker(day, month, year, marker) ⇒ Object
This sets a marker on the calendar.
-
#setMonthAttribute(attribute) ⇒ Object
This sets the attribute of the month names in the calendar.
-
#setMonthNames(months) ⇒ Object
THis function sets the month name.
-
#setYearAttribute(attribute) ⇒ Object
This sets the attribute of the year in the calendar.
- #unfocus ⇒ Object
-
#verifyCalendarDate ⇒ Object
This makes sure that the dates provided exist.
Methods inherited from CDKOBJS
#setBackgroundColor, #timeout, #validCDKObject, #validObjType
Methods included from WindowHooks
Methods included from WindowInput
#getc, #getch, #setPostProcess, #setPreProcess
Methods included from HasTitle
#cleanTitle, #drawTitle, #init_title, #setTitle
Methods included from HasScreen
#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh
Methods included from ExitConditions
#init_exit_conditions, #resetExitType, #setExitType
Methods included from Bindings
#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind
Methods included from Focusable
Methods included from Borders
#getBox, #init_borders, #setBXattr, #setBox, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar
Methods included from Movement
Methods included from Converters
#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute
Methods included from Justifications
Methods included from Alignments
Constructor Details
#initialize(cdkscreen, xplace, yplace, title, day, month, year, day_attrib, month_attrib, year_attrib, highlight, box, shadow) ⇒ CALENDAR
Returns a new instance of CALENDAR.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/cdk/components/calendar.rb', line 58 def initialize(cdkscreen, xplace, yplace, title, day, month, year, day_attrib, month_attrib, year_attrib, highlight, box, shadow) super() parent_width = cdkscreen.window.getmaxx parent_height = cdkscreen.window.getmaxy box_width = 24 box_height = 11 dayname = 'Su Mo Tu We Th Fr Sa ' bindings = { 'T' => Ncurses::KEY_HOME, 't' => Ncurses::KEY_HOME, 'n' => Ncurses::KEY_NPAGE, CDK::FORCHAR => Ncurses::KEY_NPAGE, 'p' => Ncurses::KEY_PPAGE, CDK::BACKCHAR => Ncurses::KEY_PPAGE, } self.setBox(box) box_width = self.setTitle(title, box_width) box_height += @title_lines # Make sure we didn't extend beyond the dimensions of the window. box_width = [box_width, parent_width].min box_height = [box_height, parent_height].min # Rejustify the x and y positions if we need to. xtmp = [xplace] ytmp = [yplace] alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height) xpos = xtmp[0] ypos = ytmp[0] # Create the calendar window. @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos) # Is the window nil? if @win.nil? self.destroy return nil end @win.keypad(true) # Set some variables. @x_offset = (box_width - 20) / 2 @field_width = box_width - 2 * (1 + @border_size) # Set months and day names @month_name = CDK::CALENDAR::MONTHS_OF_THE_YEAR.clone @day_name = dayname # Set the rest of the widget values. @screen = cdkscreen @parent = cdkscreen.window @shadow_win = nil @xpos = xpos @ypos = ypos @box_width = box_width @box_height = box_height @day = day @month = month @year = year @day_attrib = day_attrib @month_attrib = month_attrib @year_attrib = year_attrib @highlight = highlight @width = box_width @accepts_focus = true @input_window = @win @week_base = 0 @shadow = shadow @label_win = @win.subwin(1, @field_width, ypos + @title_lines + 1, xpos + 1 + @border_size) if @label_win.nil? self.destroy return nil end @field_win = @win.subwin(7, 20, ypos + @title_lines + 3, xpos + @x_offset) if @field_win.nil? self.destroy return nil end self.setBox(box) @marker = [0] * CDK::CALENDAR::CALENDAR_LIMIT # If the day/month/year values were 0, then use today's date. if @day == 0 && @month == 0 && @year == 0 date_info = Time.new.gmtime @day = date_info.day @month = date_info.month @year = date_info end # Verify the dates provided. self.verifyCalendarDate # Determine which day the month starts on. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) # If a shadow was requested, then create the shadow window. if shadow @shadow_win = Ncurses::WINDOW.new(box_height, box_width, ypos + 1, xpos + 1) end # Setup the key bindings. bindings.each do |from, to| self.bind(:CALENDAR, from, :getc, to) end cdkscreen.register(:CALENDAR, self) end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/cdk/components/calendar.rb', line 6 def day @day end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
6 7 8 |
# File 'lib/cdk/components/calendar.rb', line 6 def month @month end |
#week_base ⇒ Object
Returns the value of attribute week_base.
5 6 7 |
# File 'lib/cdk/components/calendar.rb', line 5 def week_base @week_base end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
6 7 8 |
# File 'lib/cdk/components/calendar.rb', line 6 def year @year end |
Class Method Details
.CALENDAR_INDEX(d, m, y) ⇒ Object
46 47 48 |
# File 'lib/cdk/components/calendar.rb', line 46 def self.CALENDAR_INDEX(d, m, y) (y * CDK::CALENDAR::MAX_MONTHS + m) * CDK::CALENDAR::MAX_DAYS + d end |
.getMonthLength(year, month) ⇒ Object
This returns the length of the current month.
725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/cdk/components/calendar.rb', line 725 def self.getMonthLength(year, month) month_length = DAYS_OF_THE_MONTH[month] if month == 2 month_length += if CDK::CALENDAR.isLeapYear(year) then 1 else 0 end end return month_length end |
.getMonthStartWeekday(year, month) ⇒ Object
This returns what day of the week the month starts on.
548 549 550 |
# File 'lib/cdk/components/calendar.rb', line 548 def self.getMonthStartWeekday(year, month) return Time.mktime(year, month, 1, 10, 0, 0).wday end |
.isLeapYear(year) ⇒ Object
This function returns a 1 if it’s a leap year and 0 if not.
553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/cdk/components/calendar.rb', line 553 def self.isLeapYear(year) result = false if year % 4 == 0 if year % 100 == 0 if year % 400 == 0 result = true end else result = true end end return result end |
.YEAR2INDEX(year) ⇒ Object
754 755 756 757 758 759 760 |
# File 'lib/cdk/components/calendar.rb', line 754 def self.YEAR2INDEX(year) if year >= 1900 year - 1900 else year end end |
Instance Method Details
#activate(actions) ⇒ Object
This function lets the user play with this widget.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/cdk/components/calendar.rb', line 175 def activate(actions) ret = -1 self.draw(@box) if actions.nil? || actions.size == 0 while true input = self.getch([]) # Inject the character into the widget. ret = self.inject(input) if @exit_type != :EARLY_EXIT return ret end end else # Inject each character one at a time. actions.each do |action| ret = self.inject(action) if @exit_type != :EARLY_EXIT return ret end end end return ret end |
#decrementCalendarDay(adjust) ⇒ Object
This decrements the current day by the given value.
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/cdk/components/calendar.rb', line 583 def decrementCalendarDay(adjust) # Make sure we adjust the day correctly. if @day - adjust < 1 # Set the day according to the length of the month. if @month == 1 # make sure we aren't going past the year limit. if @year == 1900 mesg = [ '<C></U>Error', 'Can not go past the year 1900' ] CDK.Beep @screen.popupLabel(mesg, 2) return end month_length = CDK::CALENDAR.getMonthLength(@year - 1, 12) else month_length = CDK::CALENDAR.getMonthLength(@year, @month - 1) end @day = month_length - (adjust - @day) # Have to decrement the month by one. self.decrementCalendarMonth(1) else @day -= adjust self.drawField end end |
#decrementCalendarMonth(adjust) ⇒ Object
This decrements the current month by the given value.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/cdk/components/calendar.rb', line 638 def decrementCalendarMonth(adjust) # Are we at the end of the year. if @month <= adjust if @year == 1900 mesg = [ '<C></U>Error', 'Can not go past the year 1900', ] CDK.Beep @screen.popupLabel(mesg, 2) return else @month = 13 - adjust @year -= 1 end else @month -= adjust end # Get the length of the current month. month_length = CDK::CALENDAR.getMonthLength(@year, @month) if @day > month_length @day = month_length end # Get the start o the current month. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) # Redraw the calendar. self.erase self.draw(@box) end |
#decrementCalendarYear(adjust) ⇒ Object
This decrements the current year by the given value.
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/cdk/components/calendar.rb', line 693 def decrementCalendarYear(adjust) # Make sure we don't go out o bounds. if @year - adjust < 1900 mesg = [ '<C></U>Error', 'Can not go past the year 1900', ] CDK.Beep @screen.popupLabel(mesg, 2) return end # Decrement the year. @year -= adjust # If we are in Feb make sure we don't trip into voidness. if @month == 2 month_length = CDK::CALENDAR.getMonthLength(@year, @month) if @day > month_length @day = month_length end end # Get the start of the current month. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) # Redraw the calendar. self.erase self.draw(@box) end |
#destroy ⇒ Object
This destroys the calendar
466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/cdk/components/calendar.rb', line 466 def destroy self.cleanTitle CDK.deleteCursesWindow(@label_win) CDK.deleteCursesWindow(@field_win) CDK.deleteCursesWindow(@shadow_win) CDK.deleteCursesWindow(@win) # Clean the key bindings. self.cleanBindings(:CALENDAR) # Unregister the object. CDK::SCREEN.unregister(:CALENDAR, self) end |
#draw(box) ⇒ Object
This draws the calendar widget.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/cdk/components/calendar.rb', line 288 def draw(box) header_len = @day_name.size col_len = (6 + header_len) / 7 # Is there a shadow? unless @shadow_win.nil? Draw.drawShadow(@shadow_win) end # Box the widget if asked. if box Draw.drawObjBox(@win, self) end self.drawTitle(@win) # Draw in the day-of-the-week header. (0...7).each do |col| src = col_len * ((col + (@week_base % 7)) % 7) dst = col_len * col Draw.writeChar(@win, @x_offset + dst, @title_lines + 2, @day_name[src..-1], CDK::HORIZONTAL, 0, col_len) end wrefresh self.drawField end |
#drawField ⇒ Object
This draws the month field.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/cdk/components/calendar.rb', line 317 def drawField month_name = @month_name[@month] month_length = CDK::CALENDAR.getMonthLength(@year, @month) year_index = CDK::CALENDAR.YEAR2INDEX(@year) year_len = 0 save_y = -1 save_x = -1 day = (1 - @week_day + (@week_base % 7)) if day > 0 day -= 7 end (1..6).each do |row| (0...7).each do |col| if day >= 1 && day <= month_length xpos = col * 3 ypos = row marker = @day_attrib temp = '%02d' % day if @day == day marker = @highlight save_y = ypos + @field_win.getbegy - @input_window.getbegy save_x = 1 else marker |= self.getMarker(day, @month, year_index) end Draw.writeCharAttrib(@field_win, xpos, ypos, temp, marker, CDK::HORIZONTAL, 0, 2) end day += 1 end end wrefresh(@field_win) # Draw the month in. if !(@label_win.nil?) temp = '%s %d,' % [month_name, @day] Draw.writeChar(@label_win, 0, 0, temp, CDK::HORIZONTAL, 0, temp.size) @label_win.wclrtoeol # Draw the year in. temp = '%d' % [@year] year_len = temp.size Draw.writeChar(@label_win, @field_width - year_len, 0, temp, CDK::HORIZONTAL, 0, year_len) @label_win.wmove(0, 0) wrefresh(@label_win) elsif save_y >= 0 @input_window.wmove(save_y, save_x) wrefresh(@input_window) end end |
#erase ⇒ Object
This erases the calendar widget.
456 457 458 459 460 461 462 463 |
# File 'lib/cdk/components/calendar.rb', line 456 def erase if self.validCDKObject CDK.eraseCursesWindow(@label_win) CDK.eraseCursesWindow(@field_win) CDK.eraseCursesWindow(@win) CDK.eraseCursesWindow(@shadow_win) end end |
#focus ⇒ Object
744 745 746 747 |
# File 'lib/cdk/components/calendar.rb', line 744 def focus # Original: drawCDKFscale(widget, ObjOf (widget)->box); self.draw(@box) end |
#getCalendarCell(d, m, y) ⇒ Object
54 55 56 |
# File 'lib/cdk/components/calendar.rb', line 54 def getCalendarCell(d, m, y) @marker[CDK::CALENDAR.CALENDAR_INDEX(d, m, y)] end |
#getCurrentTime ⇒ Object
This returns what day of the week the month starts on.
739 740 741 742 |
# File 'lib/cdk/components/calendar.rb', line 739 def getCurrentTime # Determine the current time and determine if we are in DST. return Time.mktime(@year, @month, @day, 0, 0, 0).gmtime end |
#getDate(day, month, year) ⇒ Object
This returns the current date on the calendar.
404 405 406 407 408 |
# File 'lib/cdk/components/calendar.rb', line 404 def getDate(day, month, year) day << @day month << @month year << @year end |
#getDayAttribute ⇒ Object
415 416 417 |
# File 'lib/cdk/components/calendar.rb', line 415 def getDayAttribute return @day_attrib end |
#getHighlight ⇒ Object
442 443 444 |
# File 'lib/cdk/components/calendar.rb', line 442 def getHighlight return @highlight end |
#getMarker(day, month, year) ⇒ Object
495 496 497 498 499 500 501 502 |
# File 'lib/cdk/components/calendar.rb', line 495 def getMarker(day, month, year) result = 0 year = CDK::CALENDAR.YEAR2INDEX(year) if @marker != 0 result = self.getCalendarCell(day, month, year) end return result end |
#getMonthAttribute ⇒ Object
424 425 426 |
# File 'lib/cdk/components/calendar.rb', line 424 def getMonthAttribute return @month_attrib end |
#getYearAttribute ⇒ Object
433 434 435 |
# File 'lib/cdk/components/calendar.rb', line 433 def getYearAttribute return @year_attrib end |
#incrementCalendarDay(adjust) ⇒ Object
This increments the current day by the given value.
568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/cdk/components/calendar.rb', line 568 def incrementCalendarDay(adjust) month_length = CDK::CALENDAR.getMonthLength(@year, @month) # Make sure we adjust the day correctly. if adjust + @day > month_length # Have to increment the month by one. @day = @day + adjust - month_length self.incrementCalendarMonth(1) else @day += adjust self.drawField end end |
#incrementCalendarMonth(adjust) ⇒ Object
This increments the current month by the given value.
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/cdk/components/calendar.rb', line 614 def incrementCalendarMonth(adjust) # Are we at the end of the year. if @month + adjust > 12 @month = @month + adjust - 12 @year += 1 else @month += adjust end # Get the length of the current month. month_length = CDK::CALENDAR.getMonthLength(@year, @month) if @day > month_length @day = month_length end # Get the start of the current month. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) # Redraw the calendar. self.erase self.draw(@box) end |
#incrementCalendarYear(adjust) ⇒ Object
This increments the current year by the given value.
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/cdk/components/calendar.rb', line 672 def incrementCalendarYear(adjust) # Increment the year. @year += adjust # If we are in Feb make sure we don't trip into voidness. if @month == 2 month_length = CDK::CALENDAR.getMonthLength(@year, @month) if @day > month_length @day = month_length end end # Get the start of the current month. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) # Redraw the calendar. self.erase self.draw(@box) end |
#inject(input) ⇒ Object
This injects a single character into the widget.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/cdk/components/calendar.rb', line 202 def inject(input) # Declare local variables pp_return = 1 ret = -1 @complete = false # Set the exit type self.setExitType(0) # Refresh the widget field. self.drawField # Check if there is a pre-process function to be called. unless @pre_process_func.nil? pp_return = @pre_process_func.call(:CALENDAR, self, @pre_process_data, input) end # Should we continue? if pp_return != 0 # Check a predefined binding if self.checkBind(:CALENDAR, input) self.checkEarlyExit @complete = true else case input when Ncurses::KEY_UP self.decrementCalendarDay(7) when Ncurses::KEY_DOWN self.incrementCalendarDay(7) when Ncurses::KEY_LEFT self.decrementCalendarDay(1) when Ncurses::KEY_RIGHT self.incrementCalendarDay(1) when Ncurses::KEY_NPAGE self.incrementCalendarMonth(1) when Ncurses::KEY_PPAGE self.decrementCalendarMonth(1) when 'N'.ord self.incrementCalendarMonth(6) when 'P'.ord self.decrementCalendarMonth(6) when '-'.ord self.decrementCalendarYear(1) when '+'.ord self.incrementCalendarYear(1) when Ncurses::KEY_HOME self.setDate(-1, -1, -1) when CDK::KEY_ESC self.setExitType(input) @complete = true when Ncurses::ERR self.setExitType(input) @complete = true when CDK::KEY_TAB, CDK::KEY_RETURN, Ncurses::KEY_ENTER self.setExitType(input) ret = self.getCurrentTime @complete = true when CDK::REFRESH @screen.erase @screen.refresh end end # Should we do a post-process? if !@complete && !(@post_process_func.nil?) @post_process_func.call(:CALENDAR, self, @post_process_data, input) end end if !@complete self.setExitType(0) end @result_data = ret return ret end |
#move(xplace, yplace, relative, refresh_flag) ⇒ Object
This moves the calendar field to the given location.
281 282 283 284 285 |
# File 'lib/cdk/components/calendar.rb', line 281 def move(xplace, yplace, relative, refresh_flag) windows = [@win, @field_win, @label_win, @shadow_win] self.move_specific(xplace, yplace, relative, refresh_flag, windows, []) end |
#object_type ⇒ Object
766 767 768 |
# File 'lib/cdk/components/calendar.rb', line 766 def object_type :CALENDAR end |
#position ⇒ Object
762 763 764 |
# File 'lib/cdk/components/calendar.rb', line 762 def position super(@win) end |
#removeMarker(day, month, year) ⇒ Object
This sets a marker on the calendar.
505 506 507 508 |
# File 'lib/cdk/components/calendar.rb', line 505 def removeMarker(day, month, year) year_index = CDK::CALENDAR.YEAR2INDEX(year) self.setCalendarCell(day, month, year_index, 0) end |
#set(day, month, year, day_attrib, month_attrib, year_attrib, highlight, box) ⇒ Object
This sets multiple attributes of the widget
375 376 377 378 379 380 381 382 383 |
# File 'lib/cdk/components/calendar.rb', line 375 def set(day, month, year, day_attrib, month_attrib, year_attrib, highlight, box) self.setDate(day, month, yar) self.setDayAttribute(day_attrib) self.setMonthAttribute(month_attrib) self.setYearAttribute(year_attrib) self.setHighlight(highlight) self.setBox(box) end |
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
447 448 449 450 451 452 453 |
# File 'lib/cdk/components/calendar.rb', line 447 def setBKattr(attrib) @win.wbkgd(attrib) @field_win.wbkgd(attrib) unless @label_win.nil? @label_win.wbkgd(attrib) end end |
#setCalendarCell(d, m, y, value) ⇒ Object
50 51 52 |
# File 'lib/cdk/components/calendar.rb', line 50 def setCalendarCell(d, m, y, value) @marker[CDK::CALENDAR.CALENDAR_INDEX(d, m, y)] = value end |
#setDate(day, month, year) ⇒ Object
This sets the date and some attributes.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/cdk/components/calendar.rb', line 386 def setDate(day, month, year) # Get the current dates and set the default values for the # day/month/year values for the calendar date_info = Time.new.gmtime # Set the date elements if we need to. @day = if day == -1 then date_info.day else day end @month = if month == -1 then date_info.month else month end @year = if year == -1 then date_info.year else year end # Verify the date information. self.verifyCalendarDate # Get the start of the current month. @week_day = CDK::CALENDAR.getMonthStartWeekday(@year, @month) end |
#setDayAttribute(attribute) ⇒ Object
This sets the attribute of the days in the calendar.
411 412 413 |
# File 'lib/cdk/components/calendar.rb', line 411 def setDayAttribute(attribute) @day_attrib = attribute end |
#setDaysNames(days) ⇒ Object
This function sets the day’s name
518 519 520 |
# File 'lib/cdk/components/calendar.rb', line 518 def setDaysNames(days) @day_name = days.clone end |
#setHighlight(highlight) ⇒ Object
This sets the attribute of the highlight box.
438 439 440 |
# File 'lib/cdk/components/calendar.rb', line 438 def setHighlight(highlight) @highlight = highlight end |
#setMarker(day, month, year, marker) ⇒ Object
This sets a marker on the calendar.
482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/cdk/components/calendar.rb', line 482 def setMarker(day, month, year, marker) year_index = CDK::CALENDAR.YEAR2INDEX(year) oldmarker = self.getMarker(day, month, year) # Check to see if a marker has not already been set if oldmarker != 0 self.setCalendarCell(day, month, year_index, oldmarker | Ncurses::A_BLINK) else self.setCalendarCell(day, month, year_index, marker) end end |
#setMonthAttribute(attribute) ⇒ Object
This sets the attribute of the month names in the calendar.
420 421 422 |
# File 'lib/cdk/components/calendar.rb', line 420 def setMonthAttribute(attribute) @month_attrib = attribute end |
#setMonthNames(months) ⇒ Object
THis function sets the month name.
511 512 513 514 515 |
# File 'lib/cdk/components/calendar.rb', line 511 def setMonthNames(months) (1...[months.size, @month_name.size].min).each do |x| @month_name[x] = months[x] end end |
#setYearAttribute(attribute) ⇒ Object
This sets the attribute of the year in the calendar.
429 430 431 |
# File 'lib/cdk/components/calendar.rb', line 429 def setYearAttribute(attribute) @year_attrib = attribute end |
#unfocus ⇒ Object
749 750 751 752 |
# File 'lib/cdk/components/calendar.rb', line 749 def unfocus # Original: drawCDKFscale(widget, ObjOf (widget)->box); self.draw(@box) end |
#verifyCalendarDate ⇒ Object
This makes sure that the dates provided exist.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/cdk/components/calendar.rb', line 523 def verifyCalendarDate # Make sure the given year is not less than 1900. if @year < 1900 @year = 1900 end # Make sure the month is within range. if @month > 12 @month = 12 end if @month < 1 @month = 1 end # Make sure the day given is within range of the month. month_length = CDK::CALENDAR.getMonthLength(@year, @month) if @day < 1 @day = 1 end if @day > month_length @day = month_length end end |