home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / format.h < prev    next >
C/C++ Source or Header  |  1995-04-06  |  15KB  |  346 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c) 1994                               *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. /*
  17.     This is the header file for formats.  It defines the format of what a
  18.     cell looks like.
  19.     3-29-94 dpp
  20.     
  21.     94-09-05 dpp defined the number formating
  22. */
  23.  
  24. #ifndef _MH_format
  25.  
  26. #define _MH_format
  27.  
  28. #include "color.h"
  29. #include "stream.h"
  30.  
  31. // 94-09-05 dpp
  32. // the number format is a 16 bit number that defines the formating of the contents
  33. // of the cell.  If bit 15 is set, the remaining number is a pointer to a "print using"
  34. // formating table in the model (this is currently not supported).
  35. // The formated numbers fall into four catagories: unformatted, decimal, currency, date
  36. // bits 9 - 11 designate the type
  37. // bits 6 - 8 designate the sub-type within a given type
  38. // bits 4 - 5 designate a selector (this is used for currency formating)
  39. // bits 0 - 3 is the number of decimal places
  40.  
  41. // this &'ed with the format should return 0
  42. const unsigned int maskOldFormat = 0xf000;
  43.  
  44. // decimal place mask
  45. const int maskDecimalFormat = 0xf;
  46.  
  47. // selector mask
  48. const maskSelectorFormat = 0x30;
  49. const rotateSelectorFormat = 4;
  50.  
  51. const int rotateTypeFormat = 9; // number of bits to rotate
  52. const unsigned int maskTypeFormat = (7 << rotateTypeFormat);
  53.  
  54. const unsigned int unformattedTypeFormat = (0 << rotateTypeFormat);
  55. const unsigned int decimalTypeFormat = (1 << rotateTypeFormat);
  56. const unsigned int currencyTypeFormat = (2 << rotateTypeFormat);
  57. const unsigned int dateTimeTypeFormat = (3 << rotateTypeFormat);
  58.  
  59. // within each type, there are a series of sub-types.  The sub-type is designation within
  60. // each type of what to do
  61.  
  62. const int rotateSubtypeFormat = 6;
  63. const unsigned int maskSubtypeFormat = (7 << rotateSubtypeFormat);
  64.  
  65. // unformattedType
  66. const unsigned int generalSubtypeFormat = (0 << rotateSubtypeFormat);
  67. const unsigned int textSubtypeFormat = (1 << rotateSubtypeFormat);
  68. const unsigned int hiddenSubtypeFormat = (2 << rotateSubtypeFormat);
  69.  
  70. // decimalType
  71. const unsigned int fixedSubtypeFormat = (0 << rotateSubtypeFormat);
  72. const unsigned int sciSubtypeFormat = (1 << rotateSubtypeFormat);
  73. const unsigned int percentSubtypeFormat (2 << rotateSubtypeFormat);
  74.  
  75. // currencyType
  76. const unsigned int currencySubtypeFormat = (0 << rotateSubtypeFormat);
  77. const unsigned int commaSubtypeFormat = (1 << rotateSubtypeFormat);
  78.  
  79. // dateTimeType
  80. const unsigned int dateSubtypeFormat = (0 << rotateSubtypeFormat);
  81. const unsigned int timeSubtypeFormat = (1 << rotateSubtypeFormat);
  82.  
  83. // the following are a series of constants for date formating
  84. const unsigned int dateMDYFormat = 0; // MM/DD/YY 01/02/64
  85. const unsigned int dateMMsDDsYYFormat = 0;        // same as above...
  86. const unsigned int dateMDFormat = 1; // MM/DD 01/02
  87. const unsigned int dateDMFormat = 2; // DD-MMM 02-Jan
  88. const unsigned int dateDMYFormat = 3; // DD-MMM-YY 02-Jan-64
  89. const unsigned int dateMYFormat = 4; // MMM-YY Jan-64
  90. const unsigned int dateYMDFormat = 5; // YY/MM/DD 64/01/02
  91. const unsigned int dateYYsMMsDDFormat = 5;    // same as above
  92. const unsigned int dateDDMonYYFormat = 6; // DDMonYY 02Jan64
  93. const unsigned int dateMonDDYYFormat = 7; // MonDDYY Jan0264
  94. const unsigned int dateDDMonFormat = 8; // DDMon 02Jan
  95. const unsigned int dateMMDDYYFormat = 9; // MMDDYY 010264
  96. const unsigned int dateMMDDFormat = 10; // MMDD 0102
  97. const unsigned int dateDDMMFormat = 11; // DDMM 0201
  98. const unsigned int dateDDMMYYFormat = 12; // DDMMYY 020164
  99. const unsigned int dateMDY2Format = 13; // Mon-DD-YY Jan-02-64
  100. const unsigned int dateMD2Format = 14; // Mon-DD Jan-02
  101. const unsigned int dateDATEFormat = 15; // Jan 02, 1964
  102. const unsigned int dateDDMMYYYYFormat = 16;
  103. const unsigned int dateMMDDYYYYFormat = 17;
  104. const unsigned int dateMMYYYYFormat = 18;
  105. const unsigned int dateYYMMDDFormat = 19;
  106. const unsigned int dateDD_MON_YYYYFormat = 20;
  107. const unsigned int dateMON_DD_YYYYFormat = 21;
  108. const unsigned int dateMON_YYYYFormat = 22;
  109. const unsigned int dateDD_MM_YYYYFormat = 23;
  110. const unsigned int dateMM_DD_YYYYFormat = 24;
  111. const unsigned int dateDD_MMFormat = 25;
  112. const unsigned int dateMM_DDFormat = 26;
  113. const unsigned int dateMM_YYYYFormat = 27;
  114. const unsigned int dateDD_MM_YYFormat = 28;
  115. const unsigned int dateMM_DD_YYFormat = 29;
  116. const unsigned int dateDDsMMsYYYYFormat = 30;
  117. const unsigned int dateMMsDDsYYYYFormat = 31;
  118. const unsigned int dateDDsMMFormat = 32;
  119. const unsigned int dateMMsYYYYFormat = 33;
  120. const unsigned int dateDDsMMsYYFormat = 34;
  121. const unsigned int dateDDpMMpYYYYFormat = 35;
  122. const unsigned int dateMMpDDpYYYYFormat = 36;
  123. const unsigned int dateDDpMMFormat = 37;
  124. const unsigned int dateMMpDDFormat = 38;
  125. const unsigned int dateMMpYYYYFormat = 39;
  126. const unsigned int dateDDpMMpYYFormat = 40;
  127. const unsigned int dateMMpDDpYYFormat = 41;    // 01x31x94, e.g.
  128. const unsigned int dateDDxMMxYYYYFormat = 42;
  129. const unsigned int dateMMxDDxYYYYFormat = 43;
  130. const unsigned int dateDDxMMFormat = 44;
  131. const unsigned int dateMMxDDFormat = 45;
  132. const unsigned int dateMMxYYYYFormat = 46;
  133. const unsigned int dateDDxMMxYYFormat = 47;
  134. const unsigned int dateMMxDDxYYFormat = 48;    // 01x31x94, e.g.
  135. const unsigned int dateDefaultFormat = 49;        // use system settings
  136. const unsigned int dateYYxMMxDDFormat = 50;
  137. const unsigned int dateYYpMMpDDFormat = 51;
  138. const unsigned int dateYY_MM_DDFormat = 52;
  139.  
  140. // the following are a series of constants for time formating
  141. const unsigned int timeHMS12Format = 0;
  142. const unsigned int timeHM12Format = 1;
  143. const unsigned int timeHMS24Format = 2;
  144. const unsigned int timeHM24Format = 3;
  145. const unsigned int timeDefaultFormat = 4;
  146. const unsigned int timeHMS24EditFormat = 5;    // hard-coded to be colons, so 
  147.                                         // we can edit it...
  148.  
  149. const int generalFormat = (unformattedTypeFormat | generalSubtypeFormat);
  150. const int hiddenFormat = (unformattedTypeFormat | hiddenSubtypeFormat);
  151. const int textFormat = (unformattedTypeFormat | textSubtypeFormat);
  152. const int fixedFormat = (decimalTypeFormat | fixedSubtypeFormat | 2);
  153. const int currencyFormat = (currencyTypeFormat | currencySubtypeFormat | 2);
  154. const int commaFormat = (currencyTypeFormat | commaSubtypeFormat | 2);
  155. const int percentFormat = (decimalTypeFormat | percentSubtypeFormat | 2);
  156. const int sciFormat = (decimalTypeFormat | sciSubtypeFormat | 3);
  157. const int timeFormat = (dateTimeTypeFormat | timeSubtypeFormat | timeDefaultFormat);
  158. const int dateFormat = (dateTimeTypeFormat | dateSubtypeFormat | dateDefaultFormat);
  159.  
  160. class MFormat {
  161.     public:
  162.     void init();
  163.     void init(const MFormat *);
  164.     void free() {};
  165.  
  166.     // file IO stuff
  167.     void init(MStream *);
  168.     void write(MStream *);
  169.  
  170.     int operator==(const MFormat &mf) const {
  171.         return (text == mf.text && bkg == mf.bkg &&
  172.             borderCols[0] == mf.borderCols[0] &&
  173.             borderCols[1] == mf.borderCols[1] &&
  174.             borderCols[2] == mf.borderCols[2] &&
  175.             borderCols[3] == mf.borderCols[3] &&
  176.             font == mf.font && format == mf.format &&
  177.             info == mf.info);
  178.     };
  179.  
  180.  
  181.     MColor getTextColor() const {return text;};
  182.     MColor getBkgColor() const {return bkg;};
  183.     MColor getBorderColor(int n) const {return borderCols[n];};
  184.     void setTextColor(MColor c) {text = c;};
  185.     void setTextColor(int c) {text.set(c);};
  186.     void setBkgColor(MColor c) {bkg = c;};
  187.     void setBkgColor(int c) {bkg.set(c);};
  188.     void setBorderColor(int n,MColor c) {borderCols[n] = c;};
  189.  
  190.     int getFont() const {return font;};
  191.     void setFont(int i) {font = i;};
  192.  
  193.     int getFormat() const {return format;};
  194.     int getFormatSansPrec() const
  195.     {
  196.         if ((format & maskTypeFormat) == decimalTypeFormat ||
  197.             (format & maskTypeFormat) == currencyTypeFormat)
  198.             return (format & ~maskDecimalFormat);
  199.             
  200.         return format;
  201.     };
  202.     void setFormat(int i) {format = i;};
  203.     // set the format to a named format type with a given precision
  204.     int setFormat(const char *,int);
  205.     int getPrecision() const {return format & maskDecimalFormat;};
  206.     void setPrecision(int i) {if ((format & maskTypeFormat) == decimalTypeFormat ||
  207.         (format & maskTypeFormat) == currencyTypeFormat)
  208.             format = (format & ~maskDecimalFormat) | (i & maskDecimalFormat);
  209.         };
  210.  
  211.     int hasBorders() const {return (info & 0xff);};
  212.     int getBorder(int i) const {return 0x3 & (info >> (i * 2));};
  213.     void setBorder(int i,int n) {info = (~(0x3 << (i * 2)) & info) | ((n & 0x3) << (i * 2));};
  214.  
  215.     int getAlignment() const {return (info & 0x700) >> 8;};
  216.     void setAlignment(int i) {info = (info & ~0x700) | (0x700 & (i << 8));};
  217.     int getProtected() const {return (info & 0x800) >> 11;};
  218.     void setProtected(int i) {info = (info & ~0x800) | (0x800 & (i << 11));};
  219.     int getInputType() const {return (info & 0x7000) >> 12;};
  220.     void setInputType(int i) {info = (info & ~0x7000) | (0x7000 & (i << 12));};
  221.     int getScriptOnInput() const {return ((info & 0x8000) >> 15);};
  222.     void setScriptOnInput(int i) {info = (info & ~0x8000) | (0x8000 & (i << 15));};
  223.     int getUnderline() const {return (info & 0x30000) >> 16;};
  224.     void setUnderline(int i) {info = (info & ~0x30000) | (0x30000 & (i << 16));};
  225.     int getWrap() const {return (info & 0x40000) >> 18;};
  226.     void setWrap(int i) {info = (info & ~0x40000) | (0x40000 & (i << 18));};
  227.     int getHidden() const {return (info & 0x80000) >> 19;};
  228.     void setHidden(int i) {info = (info & ~0x80000) | (0x80000 & (i << 19));};
  229.     int getVertAlign() const {return (info & 0x300000) >> 20;};
  230.     void setVertAlign(int i) {info = (info & ~0x300000) | (0x300000 & (i << 20));};
  231.     int getClearBkg() const {return (info & 0x400000) >> 22;};
  232.     void setClearBkg(int i) {info = (info & ~0x400000) | (0x400000 & (i << 22));};
  233.  
  234.     void setMergeTextColor(int i) {merge = (merge & ~0x1) | (1 & i);};
  235.     void setMergeBorderColor1(int i) {merge = (merge & ~0x2) | (0x2 & (i << 1));};
  236.     void setMergeBorderColor2(int i) {merge = (merge & ~0x4) | (0x4 & (i << 2));};
  237.     void setMergeBorderColor3(int i) {merge = (merge & ~0x8) | (0x8 & (i << 3));};
  238.     void setMergeBorderColor4(int i) {merge = (merge & ~0x10) | (0x10 & (i << 4));};
  239.     void setMergeBorder1(int i) {merge = (merge & ~0x20) | (0x20 & (i << 5));};
  240.     void setMergeBorder2(int i) {merge = (merge & ~0x40) | (0x40 & (i << 6));};
  241.     void setMergeBorder3(int i) {merge = (merge & ~0x80) | (0x80 & (i << 7));};
  242.     void setMergeBorder4(int i) {merge = (merge & ~0x100) | (0x100 & (i << 8));};
  243.     void setMergeAlignment(int i) {merge = (merge & ~0x200) | (0x200 & (i << 9));};
  244.     void setMergeProtected(int i) {merge = (merge & ~0x400) | (0x400 & (i << 10));};
  245.     void setMergeInputType(int i) {merge = (merge & ~0x800) | (0x800 & (i << 11));};
  246.     void setMergeScriptOnInput(int i) {merge = (merge & ~0x1000) | (0x1000 & (i << 12));};
  247.     void setMergeUnderline(int i) {merge = (merge & ~0x2000) | (0x2000 & (i << 13));};
  248.     void setMergeWrap(int i) {merge = (merge & ~0x4000) | (0x4000 & (i << 14));};
  249.     void setMergeHidden(int i) {merge = (merge & ~0x8000) | (0x8000 & (i << 15));};
  250.     void setMergeVertAlign(int i) {merge = (merge & ~0x10000) | (0x10000 & (i << 16));};
  251.     void setMergeBkgColor(int i) {merge = (merge & ~0x20000) | (0x20000 & (i << 17));};
  252.     void setMergeFont(int i) {merge = (merge & ~0x40000) | (0x40000 & (i << 18));};
  253.     void setMergePrecision(int i) {merge = (merge & ~0x80000) | (0x80000 & (i << 19));};
  254.     void setMergeFormat(int i) {merge = (merge & ~0x100000) | (0x100000 & (i << 20));};
  255.  
  256.     int getMergeTextColor() const {return merge & 0x1;};
  257.     int getMergeBorderColor1() const {return (merge & 0x2) >> 1;};
  258.     int getMergeBorderColor2() const {return (merge & 0x4) >> 2;};
  259.     int getMergeBorderColor3() const {return (merge & 0x8) >> 3;};
  260.     int getMergeBorderColor4() const {return (merge & 0x10) >> 4;};
  261.     int getMergeBorder1() const {return (merge & 0x20) >> 5;};
  262.     int getMergeBorder2() const {return (merge & 0x40) >> 6;};
  263.     int getMergeBorder3() const {return (merge & 0x80) >> 7;};
  264.     int getMergeBorder4() const {return (merge & 0x100) >> 8;};
  265.     int getMergeAlignment() const {return (merge & 0x200) >> 9;};
  266.     int getMergeProtected() const {return (merge & 0x400) >> 10;};
  267.     int getMergeInputType() const {return (merge & 0x800) >> 11;};
  268.     int getMergeScriptOnInput() const {return (merge & 0x1000) >> 12;};
  269.     int getMergeUnderline() const {return (merge & 0x2000) >> 13;};
  270.     int getMergeWrap() const {return (merge & 0x4000) >> 14;};
  271.     int getMergeHidden() const {return (merge & 0x8000) >> 15;};
  272.     int getMergeVertAlign() const {return (merge & 0x10000) >> 16;};
  273.     int getMergeBkgColor() const {return (merge & 0x20000) >> 17;};
  274.     int getMergeFont() const {return (merge & 0x40000) >> 18;};
  275.     int getMergePrecision() const {return (merge & 0x80000) >> 19;};
  276.     int getMergeFormat() const {return (merge & 0x100000) >> 20;};
  277.  
  278.     void mergeFormat(const MFormat &);
  279.  
  280.     private:
  281.     MColor text,bkg;
  282.     MColor borderCols[4];
  283.     unsigned short font;
  284.     unsigned short format;
  285.     unsigned int info;
  286.     unsigned int merge;
  287.  
  288.     /*
  289.     unsigned int borders; // 8 bits
  290.     int alignment; // 3 bits
  291.     int protection; // 1 bit
  292.     int inputType; // 3 bits
  293.     int scriptOnInput; // 1 bit
  294.     int underline; // 2 bits
  295.     int wrap; // 1 bit
  296.     int hidden; // 1 bit
  297.     int vert align // 2 bits
  298.     */
  299.  
  300.     /*
  301.     0 text color
  302.     1 bkg color
  303.     2 border color 1
  304.     3 border color 2
  305.     4 border color 3
  306.     5 border color 4
  307.     6 border 1
  308.     7 border 2
  309.     8 border 3
  310.     9 border 4
  311.     10 alignment
  312.     11 protection
  313.     12 input type
  314.     13 scriptOnInput
  315.     14 underline
  316.     15 wrap
  317.     16 hidden
  318.     17 vert alignment
  319.     */
  320. };
  321.  
  322.  
  323. const int generalAlignment = 0;
  324. const int leftAlignment = 1;
  325. const int rightAlignment = 2;
  326. const int centerAlignment = 3;
  327.  
  328. const int vertBottomAlignment = 0;
  329. const int vertTopAlignment = 1;
  330. const int vertCenterAlignment = 2;
  331.  
  332. const int allInputType = 0;
  333. const int numbersInputType = 1;
  334. const int stringsInputType = 2;
  335. const int datesInputType = 3;
  336. const int formulasInputType = 4;
  337.  
  338. const int topBorder = 2;
  339. const int bottomBorder = 3;
  340. const int leftBorder = 0;
  341. const int rightBorder = 1;
  342.  
  343. // ifdef _MH_format
  344. #endif
  345.  
  346.