home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / CDEF Source / source / cdefDtc.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.1 KB  |  133 lines  |  [TEXT/KAHL]

  1. //------------------------- © 1992-1995 by James G. Stout --------------------------
  2. // File        : dtcCDEF.h
  3. // Date        : 20 June 1992
  4. // Author    : Jim Stout
  5. //            :
  6. // Purpose    : a "Date Time Control" CDEF that allows adjustment of date
  7. //            : and time as in the General Control Panel. Clicking on the
  8. //            : date or time numerals will show a 'small arrow' type control for
  9. //            : date or time adjustment.  Since CDEF's don't get key events,
  10. //            : this control does not respond to typing.
  11. //
  12. //            : Also, since controls must be "self contained", mouse clicks
  13. //            : on numbers select and de-select. Toggling the highlighting
  14. //            : in a manner slightly different from the control panel which
  15. //            : de-selects when you click outside the numbers (which would be
  16. //            : outside the control).
  17. //            :
  18. //            : The control respects the settings from the Date & Time
  19. //            : panel (mostly - it always displays leading zeros).  It
  20. //            : will use the user settings for date & time separators and
  21. //            : format.
  22. //            :
  23. //            : By passing a non-zero contrlMax, you can force the time
  24. //            : format to 24 hour format.
  25. //            : 
  26. //            : By passing a non-zero contrlMin, a 3D variant is drawn.
  27. //            :
  28. //            : The Control RefCon should be set with a long word as
  29. //            : returned from a "GetDateTime(&secs)" call. The control will
  30. //            : adjust this value and it can be retrieved by the calling
  31. //            : program with "GetCRefCon(theControl)" call.  If you don't
  32. //            : fill this in, the control will default the the current time.
  33. //            :
  34. //            : Use calls to SetControlValue to reset (no highlighting) or
  35. //            : highlight numbers programatically.
  36. //            :
  37. //            : Valid control values (partCodes returned) to highlight 
  38. //            : specific numbers are :
  39. //            :
  40. //            :    2    hours
  41. //            :    3    minutes
  42. //            :    4    AM/PM
  43. //            :    7    month  (7,8,9 match user order from Control Panel
  44. //            :    8    day        and may not have these meanings)
  45. //            :    9    year
  46. //            :
  47. //            : This control supports many variation codes, see the
  48. //            : #defines below.
  49. //            :
  50. //            : use procID :   103 * 16 + varCode 
  51. //            :      when calling NewControl() or in your resource template.
  52. //
  53. //----------------------------------------------------------------------------------
  54.  
  55. #define ARROWHT        18                // the size of the arrows
  56. #define ARROWID        11
  57.  
  58. //----------------------------------------------------------------------------------
  59. // variation codes    
  60. //----------------------------------------------------------------------------------
  61.  
  62. #define dateTime        0x00        // show both, date left, time right justified    
  63. #define dateOnly        0x01        // show date, left justified in control rect    
  64. #define timeOnly        0x02        // show time, right justified in control rect    
  65. #define dtStack            0x04        // show both on 2 lines, date then time    
  66. #ifndef useWindFont        
  67. #define useWindFont        0x08        // draw with window font instead of System font
  68. #endif
  69. #define showAMPM        0x10        // an extended variation code, used internally
  70. #define ctl3D            0x20        // likewise
  71.  
  72. //----------------------------------------------------------------------------------
  73. // partCodes - also returned as contrlValue to indicate hilited field    
  74. //----------------------------------------------------------------------------------    
  75.  
  76. enum {
  77. ALL        = 0,
  78. FRAMET,
  79. HOURS,
  80. MINUTES,
  81. AMPM,
  82. UPTIME,
  83. DOWNTIME,
  84. DT1,
  85. DT2,
  86. DT3,
  87. UPDATE,
  88. DOWNDATE,
  89. DATE,
  90. FRAMED,
  91. TITLE,
  92. FONTINFO,
  93. NUMPARTS
  94. };
  95.  
  96. //----------------------------------------------------------------------------------
  97. // the dtcCDEF private data    
  98. //----------------------------------------------------------------------------------
  99.  
  100. typedef struct {
  101. CGrafPtr        offPort;            // offscreen drawing port    
  102. PolyHandle        poly[6];            // polgons for up/down arrows & frames
  103. short            arrowHilite;        // 0 = not hilited                            
  104. short            varCode;            // we need a bigger varCode than 4 bits…    
  105. short            qdVers;                // QuickDraw version                        
  106. short            pDepth;                // pixel depth for control    
  107. short            currSel;                                    
  108. char            timeSep;            // next 4 from the Intl0 record 
  109. unsigned char    timeCycle;
  110. unsigned char    dateSep;
  111. unsigned char    dateOrder;
  112. }dtcData,**dtcHandle;
  113.  
  114. //----------------------------------------------------------------------------------
  115. //    Function prototypes
  116. //----------------------------------------------------------------------------------
  117.  
  118. static void doInit        (ControlHandle theControl, short varCode);
  119. static void doDisp        (ControlHandle theControl);
  120. static long doTest        (ControlHandle theControl, short varCode, long param);
  121. static void doDraw        (ControlHandle theControl, short varCode, short partCode);
  122. static void drawArrows    (ControlHandle theControl, short varCode, short partCode,
  123.                             Boolean inColor);
  124. static void updateValue    (ControlHandle theControl, short varCode, short partCode);
  125. static void doHilite    (ControlHandle theControl, short varCode, short flag,
  126.                             Boolean backPat);
  127. static void getRects    (ControlHandle theControl, short varCode, Rect r1[]);
  128. static void getTimeStr    (ControlHandle theControl, short varCode, long secs, Str31 string);
  129. static void getDateFmt    (ControlHandle theControl, short * m, short * d, short * y);
  130. static void getDateStr    (ControlHandle theControl, long secs, Str31 string);
  131. static char arrowPart    (short partCode);
  132. static void makePolys    (ControlHandle theControl, short varCode);
  133.