home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / Palettes / Clocks / Clock.h < prev    next >
Text File  |  1992-12-06  |  13KB  |  354 lines

  1. //----------------------------------------------------------------------------------------------------
  2. //
  3. //    Clock
  4. //
  5. //    Inherits From:        Control
  6. //
  7. //    Declared In:        Clock.h
  8. //
  9. //    Class Description
  10. //
  11. //        The Clock class models the general functionality of a basic clock
  12. //        with alarm capability.  Subclasses will, for the most part, only need
  13. //        to implement drawing methods to support their unique graphical
  14. //        representation. Clock uses the 'tm' struct (defined in time.h) to 
  15. //        maintain its time and date information.  See time.h or the supporting
  16. //        file ClockConstantsAndTypes.h for information on valid tm struct
  17. //        values.  In general, the underlying use of the tm struct is transparent.
  18. //        The class and instance methods setTimeAndDate, and macros defined
  19. //        in the constants and types file have been provided to work with tm if 
  20. //        required.
  21. //
  22. //        Display
  23. //        Clock is a graphical object, however, if you prefer to use only its 
  24. //        functionality, display may be disabled.  A Clock is drawn in the following
  25. //        manner.  A background image or color is painted over the entirity of the
  26. //        bounds rect.  A clock face image is then composited (centered) over this 
  27. //        rect. If the alarm is enabled, an optional visible alarm indicator is displayed
  28. //        in the lower left hand corner of the rect.  Then the time and date are drawn
  29. //        as appropriate for the particular style of clock (implemented by subclass). 
  30. //        At any given time, a Clock may be asked to display its current clock time,
  31. //        its current alarm time, the current system time, or any other arbitrary time 
  32. //        as specified by the user. These alternate displays will not affect the value 
  33. //        of the current running clock (to resume display of the current running clock, 
  34. //        use the resumeClockDisplay: method).  
  35. //
  36. //        Timer
  37. //        A clock instance does not have to be running.  It may be used simply to
  38. //        display static time and date information. To start the timer, use the following;
  39. //        startFromSystem:, startFromSelf:, or startFromTime:.  If startFromSystem: is 
  40. //        used, the current clock time will always be the current system time.  If the 
  41. //        startFromSelf: method is used, the clock will start from its current clock setting 
  42. //        (i.e. it will begin at 12:00 if the current clock time is 12:00).  If startFromTime:
  43. //        is used, the timer begins from the time information passed to it in the tm struct.
  44. //        The stop: method will stop the current timer.  
  45. //
  46. //        Alarm
  47. //        An alarm mechanism is provided such that when the specified alarm setting
  48. //        is matched, the clock's action will be sent to the clock's target (optionally,
  49. //        an audible notification will be sounded). An alarm setting may be matched 
  50. //        in one of three ways; by time only, by time and date, or by time and day of
  51. //        week.  Setting the alarm does not enable it (you must explicitly enable via
  52. //        the enableAlarm: method).  Also, an enabled alarm will have no affect if the 
  53. //        timer is not running.
  54. //
  55. //        Drag and Drop
  56. //        Clocks support drag and drop via the ClockPboardType. The following
  57. //        operations are provided: Holding down the command key or no key while
  58. //        dropping will copy both clock and alarm information.  Holding down the
  59. //        alternate key while dropping will copy only alarm information. Holding down 
  60. //        the control key while dropping will copy only clock information.
  61. //        
  62. //
  63. //    Disclaimer
  64. //
  65. //        You may freely copy, distribute and reuse this software and its
  66. //        associated documentation. I disclaim any warranty of any kind, 
  67. //        expressed or implied, as to its fitness for any particular use.
  68. //
  69. //----------------------------------------------------------------------------------------------------
  70. #import <appkit/appkit.h>
  71. #import "ClockConstantsAndTypes.h"
  72.  
  73.  
  74. @interface Clock : Control
  75. {
  76.     struct tm            clockTimeAndDate;
  77.     struct tm            alarmTimeAndDate;
  78.     struct tm*            displayTimeAndDate;
  79.     
  80.     NXColor            backgroundColor;
  81.     NXImage*        backgroundImage;
  82.     NXImage*        clockFace;
  83.  
  84.     Sound*            alarmSound;
  85.  
  86.     DPSTimedEntry    timedEntry;
  87.     int                previousClock;
  88.  
  89.         struct _flags 
  90.         {
  91.         unsigned int    wantsDisplay:1;
  92.         unsigned int    wantsMilitaryTime:1;
  93.         unsigned int    wantsSeconds:1;
  94.         unsigned int     wantsDate:1;
  95.         unsigned int     isDraggable:1;
  96.         unsigned int    willAcceptDrop:1;
  97.         unsigned int    isAlarmEnabled:1;
  98.         unsigned int    wantsAlarmIndicator:1;
  99.         unsigned int    activateOnAwake:2;
  100.             } flags;
  101.  
  102.     struct _privateFlags
  103.         {
  104.         unsigned int    timerMode:1;
  105.         unsigned int    alarmMode:3;
  106.         unsigned int    displayMode:2;
  107.         unsigned int     backgroundIsColor:1;
  108.         unsigned int    initRelativeTimerMode:1;
  109.         unsigned int    alarmSleep:1;
  110.         } privateFlags;
  111. }
  112.  
  113.  
  114. //----------------------------------------------------------------------------------------------------
  115. //    Accessing Display Characteristics
  116. //----------------------------------------------------------------------------------------------------
  117. - backgroundImage: (NXImage*) anImage;
  118. - backgroundColor: (NXColor) aColor;
  119. - clockFace: (NXImage*) anImage;
  120.  
  121. - setDisplayEnabled: (BOOL) aFlag;
  122. - wantsMilitaryTime: (BOOL) aFlag;
  123. - wantsDate: (BOOL) aFlag;
  124. - wantsSeconds: (BOOL) aFlag;
  125.  
  126. - (NXImage*) backgroundImage;
  127. - (NXColor) backgroundColor;
  128. - (NXImage*) clockFace;
  129.  
  130. - (BOOL) isDisplayEnabled;
  131. - (BOOL) wantsMilitaryTime;
  132. - (BOOL) wantsDate;
  133. - (BOOL) wantsSeconds;
  134.  
  135.  
  136. //----------------------------------------------------------------------------------------------------
  137. //    Accessing Clock Time and Date
  138. //----------------------------------------------------------------------------------------------------
  139. - clockTimeAndDate: (struct tm*) theClockTimeAndDate;
  140. - clockSecond: (int) theSecond;
  141. - clockMinute: (int) theMinute;
  142. - clockHour: (int) theHour;
  143. - clockDay: (int) theDay;
  144. - clockMonth: (int) theMonth;
  145. - clockYear: (int) theYear;
  146. - clockWeekday: (int) theWeekday;
  147.  
  148. - (struct tm*) clockTimeAndDate;
  149. - (int) clockSecond;
  150. - (int) clockMinute;
  151. - (int) clockHour;
  152. - (int) clockDay;
  153. - (int) clockMonth;
  154. - (int) clockYear;
  155. - (int) clockWeekday;
  156.  
  157.  
  158. //----------------------------------------------------------------------------------------------------
  159. //    Setting, Enabling and Executing the Alarm
  160. //----------------------------------------------------------------------------------------------------
  161. - enableAlarm: (BOOL) aFlag;
  162. - (BOOL) isAlarmEnabled;
  163.  
  164. - wantsAlarmIndicator: (BOOL) aFlag;
  165. - (BOOL) wantsAlarmIndicator;
  166.  
  167. - setAlarmTime: (struct tm*) theTime;
  168. - setAlarmTimeAndDate: (struct tm*) theTimeAndDate;
  169. - setAlarmTimeAndWeekday: (struct tm*) theTimeAndWeekday;
  170.  
  171. - executeAlarmAction: sender;
  172.  
  173.  
  174. //----------------------------------------------------------------------------------------------------
  175. //    Accessing Alarm Time and Date
  176. //----------------------------------------------------------------------------------------------------
  177. - alarmTimeAndDate: (struct tm*) theAlarmTimeAndDate;
  178. - alarmSecond: (int) theSecond;
  179. - alarmMinute: (int) theMinute;
  180. - alarmHour: (int) theHour;
  181. - alarmDay: (int) theDay;
  182. - alarmMonth: (int) theMonth;
  183. - alarmYear: (int) theYear;
  184. - alarmWeekday: (int) theWeekday;
  185.  
  186. - (struct tm*) alarmTimeAndDate;
  187. - (int) alarmSecond;
  188. - (int) alarmMinute;
  189. - (int) alarmHour;
  190. - (int) alarmDay;
  191. - (int) alarmMonth;
  192. - (int) alarmYear;
  193. - (int) alarmWeekday;
  194.  
  195.  
  196. //----------------------------------------------------------------------------------------------------
  197. //    Accessing Alarm Sound
  198. //----------------------------------------------------------------------------------------------------
  199. - alarmSound: aSound;
  200. - alarmSound;
  201.  
  202.  
  203. //----------------------------------------------------------------------------------------------------
  204. //    Starting and Stopping the Clock
  205. //----------------------------------------------------------------------------------------------------
  206. - startFromSystem: sender;
  207. - startFromSelf: sender;
  208. - startFromTime: (struct tm*) theTime;
  209. - stop: sender;
  210.  
  211. - activateOnAwake: (int) aFlag;
  212. - (int) activateOnAwake;
  213.  
  214.  
  215. //----------------------------------------------------------------------------------------------------
  216. //    Timer Status
  217. //----------------------------------------------------------------------------------------------------
  218. - (BOOL) isClockRunning;
  219.  
  220.  
  221. //----------------------------------------------------------------------------------------------------
  222. //    Utility Methods
  223. //----------------------------------------------------------------------------------------------------
  224. + setTimeAndDate:(struct tm*)time :(int)hour :(int)minute :(int)second :(int)month :(int)day :(int)year;
  225. - setTimeAndDate:(struct tm*)time :(int)hour :(int)minute :(int)second :(int)month :(int)day :(int)year;
  226. - (int) weekDay: (struct tm*) aTime;
  227.  
  228.  
  229. //----------------------------------------------------------------------------------------------------
  230. //    Display Methods
  231. //----------------------------------------------------------------------------------------------------
  232. - showClockTime: sender;
  233. - showSystemTime: sender;
  234. - showAlarmTime: sender;
  235. - showTime: (struct tm*) aTime;
  236. - resumeClockDisplay: sender;
  237.  
  238.  
  239. //----------------------------------------------------------------------------------------------------
  240. //    IB Action Methods
  241. //----------------------------------------------------------------------------------------------------
  242. - takeDisplayEnabledFlagFrom: sender;
  243. - takeWantsSecondsFlagFrom: sender;
  244. - takeWantsDateFlagFrom: sender;
  245. - takeWantsMilitaryTimeFlagFrom: sender;
  246. - takeIsDraggableFlagFrom: sender;
  247. - takeWillAcceptDropFlagFrom: sender;
  248. - takeEnableAlarmFlagFrom: sender;
  249. - takeWantsAlarmIndicatorFlagFrom: sender;
  250.  
  251. - takeBackgroundColorFrom: sender;
  252.  
  253. - takeClockSecondIntValueFrom: sender;
  254. - takeClockMinuteIntValueFrom: sender;
  255. - takeClockHourIntValueFrom: sender;
  256. - takeClockDayIntValueFrom: sender;
  257. - takeClockMonthIntValueFrom: sender;
  258. - takeClockYearIntValueFrom: sender;
  259. - takeClockWeekdayIntValueFrom: sender;
  260.  
  261. - takeAlarmSecondIntValueFrom: sender;
  262. - takeAlarmMinuteIntValueFrom: sender;
  263. - takeAlarmHourIntValueFrom: sender;
  264. - takeAlarmDayIntValueFrom: sender;
  265. - takeAlarmMonthIntValueFrom: sender;
  266. - takeAlarmYearIntValueFrom: sender;
  267. - takeAlarmWeekdayIntValueFrom: sender;
  268.  
  269. - takeAlarmModeIntValueFrom: sender;
  270.  
  271. - incrementClockSecond: sender;
  272. - incrementClockMinute: sender;
  273. - incrementClockHour: sender;
  274. - incrementClockDay: sender;
  275. - incrementClockMonth: sender;
  276. - incrementClockYear: sender;
  277. - incrementClockWeekday: sender;
  278. - decrementClockSecond: sender;
  279. - decrementClockMinute: sender;
  280. - decrementClockHour: sender;
  281. - decrementClockDay: sender;
  282. - decrementClockMonth: sender;
  283. - decrementClockYear: sender;
  284. - decrementClockWeekday: sender;
  285.  
  286. - incrementAlarmSecond: sender;
  287. - incrementAlarmMinute: sender;
  288. - incrementAlarmHour: sender;
  289. - incrementAlarmDay: sender;
  290. - incrementAlarmMonth: sender;
  291. - incrementAlarmYear: sender;
  292. - incrementAlarmWeekday: sender;
  293. - decrementAlarmSecond: sender;
  294. - decrementAlarmMinute: sender;
  295. - decrementAlarmHour: sender;
  296. - decrementAlarmDay: sender;
  297. - decrementAlarmMonth: sender;
  298. - decrementAlarmYear: sender;
  299. - decrementAlarmWeekday: sender;
  300.  
  301.  
  302. //----------------------------------------------------------------------------------------------------
  303. //    Draw Methods
  304. //----------------------------------------------------------------------------------------------------
  305. - drawBackground;
  306. - drawClockFace;
  307. - drawTime;
  308. - drawDate;
  309. - drawAlarmIndicator;
  310.  
  311.  
  312. //----------------------------------------------------------------------------------------------------
  313. //    Drag and Drop Support
  314. //----------------------------------------------------------------------------------------------------
  315. - isDraggable: (BOOL) aFlag;
  316. - willAcceptDrop: (BOOL) aFlag;
  317.  
  318. - (BOOL) isDraggable;
  319. - (BOOL) willAcceptDrop;
  320.  
  321. - (BOOL)acceptsFirstMouse;
  322. - mouseDown: (NXEvent*) theEvent;
  323. - beginDragOperationFor: (NXEvent*) originalEvent  nextEvent: (NXEvent*) nextEvent;
  324. - (NXImage*) dragImage;
  325.  
  326.  
  327. //----------------------------------------------------------------------------------------------------
  328. //    Clock Drag Operations
  329. //----------------------------------------------------------------------------------------------------
  330. - dragOperationCopy: pasteboardClock;
  331. - dragOperationLink: pasteboardClock;
  332. - dragOperationGeneric: pasteboardClock;
  333.  
  334.  
  335. //----------------------------------------------------------------------------------------------------
  336. //    Pasteboard Methods
  337. //----------------------------------------------------------------------------------------------------
  338. - writeToPasteboard: aPasteboard;
  339. - readFromPasteboard: aPasteboard;
  340.  
  341.  
  342. //----------------------------------------------------------------------------------------------------
  343. //    Private Mode Accessors (made public for IB Inspectors)
  344. //----------------------------------------------------------------------------------------------------
  345. - (int) _timerMode;
  346. - (int) _alarmMode;
  347. - (int) _displayMode;
  348. - (BOOL) _backgroundIsColor;
  349. - _timerMode: (int) aMode;
  350. - _alarmMode: (int) aMode;
  351. - _backgroundIsColor: (BOOL)aFlag;
  352.  
  353.  
  354. @end