home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / goodies / finalwriter / arexx / calender / calendar < prev    next >
Encoding:
Text File  |  1995-04-08  |  7.1 KB  |  192 lines

  1. /*  A Final Writer Macro to draw monthly calendars       */
  2. /*          Written by William Barnes 4/95               */
  3. /*                                                       */
  4. /*  INTRO                                                */
  5. /*  This is my first attempt at writing a program        */
  6. /*  in ARexx.  The script will draw a calendar using     */
  7. /*  text blocks and boxes and group them into 1 giant    */
  8. /*  object that can be moved and resized as desired.     */
  9. /*                                                       */
  10. /*  USAGE:  Just run the script from withing Final       */
  11. /*          Writer. The script will ask you for the      */
  12. /*          month and the year and generate the          */
  13. /*          calendar.                                    */
  14. /*                                                       */
  15. /*  NOTE:  The 3 lines containing the font paths will    */
  16. /*         most likely need to be changed to fit your    */
  17. /*         system.                                       */
  18. /*                                                       */ 
  19. /*  TECHNICAL (?)                                        */ 
  20. /*  The code could probably be written                   */
  21. /*  more efficiently, but once I got it to work          */
  22. /*  I didn't want to mess anything up.  So far, it       */
  23. /*  accurately generates calendars for 1995 and 1996.    */
  24. /*  I set the limit on the years from 1900 - 2050        */
  25. /*  because I'm not sure how accurate the algorithm      */
  26. /*  to determine the day of the week is.  I don't        */
  27. /*  think many people need monthly calendars for the     */
  28. /*  1800's anyways.  Feel free to change the limits      */
  29. /*  if you need to.                                      */
  30. /*                                                       */
  31. /*  HISTORY                                              */
  32. /*  I saw a similar macro being used on Wordperfect      */
  33. /*  6.0 on a 486 laptop.  I'm not sure why, but it       */
  34. /*  was pretty slow.  Since I don't have an IBM and      */
  35. /*  I couldn't find anything similar for the Amiga       */
  36. /*  I decided to try and do it myself.                   */
  37. /*                                                       */
  38. /*  FUTURE IMPROVEMENTS                                  */
  39. /*  An event list manager.  I think that this is         */
  40. /*  beyond the scope of a simple macro as well as        */
  41. /*  way beyond my programming abilities.  Maybe          */
  42. /*  some day....                                         */
  43. /*                                                       */
  44. /*  BUGS, COMMENTS, ETC..                                */
  45. /*  This program is released as freeware.  Feel free     */
  46. /*  to do whatever you like with it.  If you like it,    */
  47. /*  or have any comments about it,, feel free to let     */
  48. /*  me know.  If there are any ARexx commandos out       */
  49. /*  there who would like to show me how I could improve  */
  50. /*  my programming skills feel please send me some input.*/  
  51. /*                                                       */
  52. /*  I can be contacted at:                               */
  53. /*                                                       */
  54. /*  CompuServe: 73060,65                                 */
  55. /*  InterNet: 73060.65@Compuserve.com                    */
  56. /*                                                       */
  57. /*  THANKS                                               */
  58. /*  I'd like to thank Russell Solub and Eduard Joseph    */
  59. /*  for their programming advice and SoftWood for a      */
  60. /*  great program and generous upgrade policy.           */
  61.     
  62.    
  63. Options Results
  64.  
  65. /***********    These are the paths for the fonts to be used    *************/
  66. /***********    and will probably need to be changed to fit     *************/
  67. /***********    your system.                                    *************/
  68.  
  69. TitleFont = "dh1:finalwriter/fwfonts/swolfonts/serif/Clearface_bolditalic"
  70. DaysOfWeekFont = "dh1:finalwriter/fwfonts/swolfonts/serif/valencia_bolditalic"
  71. DayNumberFont = "dh1:finalwriter/fwfonts/swolfonts/serif/valencia_bolditalic"
  72.  
  73. /*****************************************************************************/
  74.  
  75. monthtext = "January February March April May June July August September October November December"
  76. daystring = "31 28 31 30 31 30 31 31 30 31 30 31"
  77.  
  78. SetMeasure inches
  79. ClearDoc Force
  80. DisplayPrefs Rulers none
  81. BoxPrefs TEXTFLOW None LINEWT 1 FILL Transparent 
  82. TextBlockPrefs TextFlow None
  83.  
  84. /***********  Get month to be printed   **************/
  85. valid = 0
  86. do while valid = 0
  87. RequestText '"Enter Month" "Month number to be printed (1 - 12)" ""'
  88. month = Result
  89. if DATATYPE(month,Numeric) = 1
  90.    then 
  91.       if ((month >= 1) & (month <= 12))
  92.          then 
  93.             valid = 1
  94.          else NOP
  95.    else NOP           
  96. end
  97. mo = SUBWORD(monthtext,month,1)
  98.  
  99. /*********** Get year to be printed    *************/
  100. valid = 0
  101. do while valid = 0
  102. RequestText '"Enter Year" "Year to be printed (1900  - 2050)" ""'
  103. year = Result
  104. if DATATYPE(year,Numeric) = 1
  105.    then 
  106.       if ((year >= 1900) & (year <= 2050))
  107.          then 
  108.             valid = 1
  109.          else NOP
  110.    else NOP           
  111. end
  112.  
  113. /********  Determine # of days in the month (corrected for leapyear  *******/
  114. if ( (year // 4 = 0) & (year // 100 ~= 0) | (year // 400 = 0) )
  115.    then 
  116.       leapyear = 1
  117.    else 
  118.       leapyear = 0
  119. days = SUBWORD(daystring,month,1)
  120. if month = 2
  121.    then days = days + leapyear
  122.  
  123. /*****   Calculate 1st day of the week for the desired month   *****/
  124. realyear = year
  125. if month < 3 then do
  126.    year = year - 1
  127.    month = month + 13  
  128.    end
  129.    else do
  130.       month = month + 1
  131.       end
  132. n = (1461 * year)%4 + (153 * month)%5 + 1
  133. index = ((n - 621049)//7)
  134.  
  135. /******* Draw and center title   *********/
  136. TextBlockTypePrefs Size 45 Font TitleFont
  137. mo = mo realyear
  138. DrawTextBlock 1 .75 .75 mo 
  139. obnum = Result
  140. GetObjectCoords obnum
  141. coords = Result
  142. PARSE VAR coords page left top width height
  143. newleft = 4 - (width / 2)
  144. SetObjectCoords obnum 1 newleft top width height
  145. redraw
  146.  
  147. /****** Draw days of week and boxes around them  *****/
  148. TextBlockTypePrefs Size 10 Font DaysOfWeekFont
  149. DrawTextBlock 1  .625 1.625 "Sunday"
  150. DrawTextBlock 1 1.625 1.625 "Monday"
  151. DrawTextBlock 1 2.625 1.625 "Tuesday"
  152. DrawTextBlock 1 3.625 1.625 "Wednesday"
  153. DrawTextBlock 1 4.625 1.625 "Thursday"
  154. DrawTextBlock 1 5.625 1.625 "Friday"
  155. DrawTextBlock 1 6.625 1.625 "Saturday"
  156.  
  157. DrawBox 1   .5  1.5   1  .375 
  158. DrawBox 1  1.5  1.5   1  .375 
  159. DrawBox 1  2.5  1.5   1  .375 
  160. DrawBox 1  3.5  1.5   1  .375 
  161. DrawBox 1  4.5  1.5   1  .375 
  162. DrawBox 1  5.5  1.5   1  .375 
  163. DrawBox 1  6.5  1.5   1  .375 
  164. redraw
  165.  
  166. /****** Draw days of month boxes  ******/
  167. TextBlockTypePrefs Size 20 Font DayNumberFont
  168. boxheight = 1.5
  169. if days + index > 35 
  170.    then boxheight = 1.25
  171.    
  172. do loop = 1 to days
  173.    grid = loop + index
  174.    left = grid - (( (grid - 1) % 7) * 7) - .5
  175.    top =  ((grid - 1) % 7) * boxheight + 2
  176.    top1 = .125 + top           /** offset for day # textblock  **/
  177.    left1 = .125 + left         /** offset for day # textblock  **/
  178.    DrawBox 1 left top 1 boxheight     
  179.    DrawTextBlock 1 left1 top1 loop
  180.    obnum = Result
  181.    redraw
  182.    end
  183.  
  184. /*******  Select all objects and group them into 1 object  *******/
  185. do loop = 1 to obnum
  186.    SelectObject loop Multiple
  187.    end
  188. Group
  189.    
  190. SelectObject 0
  191. exit
  192.