// Display one month calendar // - By default, displays current months calendar. // For any other month, call the label "SET_MONTH" // - Opens a new buffer/window. // To close the calender, press undo and then close the window. // - Uses syntax file calendar.syn for color. // - Highlights todays day number by setting a block (if current month). // - Call the label "VIEW" to view current months calendar and to browse // months forward/backward. // // v1.0 10.06.2010 by Pauli Lindgren // v1.1 14.06.2010 by Pauli Lindgren // v1.2 27.01.2011 by Ted Green #1 = 0 // Month, 0 = current month // 2nd entry point: // Display calendar of a specific month, // #1 = month (0 = current month) // #2 = year // :SET_MONTH: #3 = 3 // #3 = Options: 1=Pull-down effect, 2=pull-up effect #20 = Reg_Free // #20 = tmp text register Buf_Switch(Buf_Free, ATTACH) #21 = WINW-(FONTW*23+1) // #21 = Window x position Win_Move(Win_Num, #21, -(FONTH*10), FONTW*23, FONTH*14) Update() Win_Title("Calendar") // Win_Color(48) Call("DRAW_CALENDAR") // Syntax highlighting Syntax_Load("calendar.syn") Config(PG_E_SYNTAX,1,LOCAL) if (#3 & 1) { // Effect enabled Call("pull_down") } else { Win_Move(Win_Num, #21, 0, FONTW*23, FONTH*14) } Reg_Empty(#20) Return // // Entry point 2: // View current months calendar. // PgUp/PgDn to browse months forward/backwards, any other key to close calendar window. // :VIEW: #1 = 0 // current month Call("SET_MONTH") // display the calendar do { // wait for key-press Update() #30 = Get_Key("PgDn/PgUp = Next/Prev month, Space to Exit:", STATLINE) if (#30 == 'P'+'U'*256) { #1-- if (#1 < 1) { #1=12 #2-- } Call("DRAW_CALENDAR") // re-display the calendar } if (#30 == 'P'+'D'*256) { #1++ if (#1 > 12) { #1=1 #2++ } Call("DRAW_CALENDAR") // re-display the calendar } if (#30=='E'+'S'*256) { // Escape Break } } while (#30 > 256); if (#3 & 2) { // Effect enabled Call("pull_up") } Buf_Quit(OK+DELETE) Return /////////////////////////////////////////////////////////////////////////// // // Subroutines... :DRAW_CALENDAR: BOF Del_Char(ALL) if (#1 == 0) { // if month==0, use current date #10 = Jdate() Num_Ins_Date(#10, NORMAL+NOCR) BOL #1 = Num_Eval(SUPPRESS+ADVANCE) // #1 = month Char IT("01", OVERWRITE) // day = 1 Char #2 = Num_Eval(SUPPRESS+ADVANCE) // #2 = year } else { Num_Ins(#1, LEFT+NOCR) IT("/01/") Num_Ins(#2, LEFT+NOCR) } RCB(#20, BOL_pos, EOL_pos, DELETE) // Date string for day 1 of the month #10 = Jdate(@(#20)) // #10 = Julian date number of the day 1 Num_Ins(#1 % 12 + 1, LEFT+NOCR) // Next month... #4 = #2 + (#1==12) // #4 = year of next month IT("/1/") Num_Ins(#4, LEFT+NOCR) RCB(#20, BOL_pos, CP, DELETE) // Date string for day 1 of next month #11 = Jdate(@(#20)) - #10 // #11 = Number of days in the month #12 = Jdate() // #12 = Julian date of today #7 = (#10-1) % 7 // #7 = weekday of day 1, monday = 0 // Convert month number (in #1) into word in T-reg #20 if (#1==1) { RS(#20,"January") } if (#1==2) { RS(#20,"February") } if (#1==3) { RS(#20,"March") } if (#1==4) { RS(#20,"April") } if (#1==5) { RS(#20,"May") } if (#1==6) { RS(#20,"June") } if (#1==7) { RS(#20,"July") } if (#1==8) { RS(#20,"August") } if (#1==9) { RS(#20,"September") } if (#1==10) { RS(#20,"October") } if (#1==11) { RS(#20,"November") } if (#1==12) { RS(#20,"December") } IT(" ") Reg_Ins(#20) Num_Ins(#2) IN IT(" Mo Tu We Th Fr Sa Su") IN IT(" --------------------") IN Ins_Char(' ', COUNT, #7*3) #6 = 0 for (#8 = 1; #8 <= #11; #8++) { Num_Ins(#8, COUNT, 3) if (#8+#10-1 == #12) { // today? #6 = CP } #5 = (#8+#10+5) % 7 if (#5 == 6) { IN } // next week } IT(" ") // Highlight todays day number if found if (#6) { BB(#6-2) BE(#6) } BOF Return // // Pull-down effect // :pull_down: for (#8 = -(FONTH*10); #8<=0; #8=#8+(FONTH*2)) { Win_Move(Win_Num, #21, #8, FONTW*23, FONTH*14) Update() Sleep(1) } Return :pull_up: for (#8 = -(FONTH*2); #8>-(FONTH*12); #8=#8-(FONTH*3)) { Win_Move(Win_Num, #21, #8, FONTW*23, FONTH*14) Update() Sleep(1) } Return