Annotation of mstools/samples/gridfont/grid.hxx, revision 1.1

1.1     ! root        1: #ifndef __GRID_HXX_
        !             2: #define __GRID_HXX_
        !             3: 
        !             4: #include "canvas.hxx"
        !             5: 
        !             6: #include "font.hxx"
        !             7: 
        !             8: 
        !             9: //========== CGridIt ===========================================
        !            10: class CGridIt
        !            11: {
        !            12: public:
        !            13:         CGridIt(UINT cCol, UINT cRow, SIZE size, POINT pt) :
        !            14:                 _pt(pt), _size(size), _cCol(cCol), _cRow(cRow), 
        !            15:                 _iRow(0), _iCol(0), _cx(pt.x), _cy(pt.y)
        !            16:         {}
        !            17:         
        !            18:         BOOL Done() { return _iCol == _cCol; };
        !            19: 
        !            20:         UINT Row()  { return _iRow; };
        !            21:         UINT Col()  { return _iCol; };
        !            22:         
        !            23:         COORD Cx() { return _cx; }
        !            24:         COORD Cy() { return _cy; }
        !            25: 
        !            26:         void operator++()
        !            27:         {
        !            28:             if( !Done())
        !            29:             {
        !            30:                 _iRow++;
        !            31:                 _cy+=_size.cy;
        !            32:                 if( _iRow == _cRow )
        !            33:                 {
        !            34:                     _iRow = 0;
        !            35:                     _cy = _pt.y;
        !            36:                     _iCol++;
        !            37:                     _cx += _size.cx;
        !            38:                 }
        !            39:             }
        !            40:         }
        !            41: protected:
        !            42:         POINT   _pt;
        !            43:         SIZE    _size;
        !            44:         UINT    _cRow;
        !            45:         UINT    _iRow;
        !            46:         UINT    _cCol;
        !            47:         UINT    _iCol;
        !            48:         COORD _cx, _cy;
        !            49: };
        !            50: 
        !            51: //========== CGrid =============================================
        !            52: 
        !            53: class CGrid
        !            54: {
        !            55: public:
        !            56:         virtual void Paint(CCanvas& canvas, RECT rc, POINT pt)=0;
        !            57: protected:
        !            58:         SIZE    _size;
        !            59:         UINT    _cCol;
        !            60:         UINT    _cRow;
        !            61: };
        !            62: 
        !            63: //========== CLineGrid =========================================
        !            64: 
        !            65: class CLineGrid : public CGrid
        !            66: {
        !            67: public:
        !            68:         CLineGrid(UINT cCol, UINT cRow, SIZE size);
        !            69:         void SetStyle(int iStyle = PS_DOT );
        !            70:         void SetWeight(int nWeight = 1 );
        !            71:         void Paint(CCanvas& canvas, RECT rc, POINT pt);
        !            72: protected:
        !            73:         int     _iStyle;
        !            74:         int     _nWeight;
        !            75: };
        !            76: 
        !            77: //========== CTextGrid =========================================
        !            78: 
        !            79: class CTextGrid : public CGrid
        !            80: {
        !            81: public:
        !            82:         void SetFont(HFONT hfont);
        !            83:         void SetTextOrg() 
        !            84:         {
        !            85:             _ptOrg.x = _size.cx/2;
        !            86:             _ptOrg.y=7*_size.cy/11;
        !            87:         };
        !            88:         
        !            89:         void SetTextOrg(COORD x, COORD y) 
        !            90:         {
        !            91:             _ptOrg.x=x; 
        !            92:             _ptOrg.y=y;
        !            93:         };
        !            94:         
        !            95:         virtual void Paint(CCanvas& canvas, RECT rc, POINT pt);
        !            96:         virtual void DrawElement(CCanvas& canvas, COORD x, COORD y, UINT i, UINT j)=0;
        !            97:         UINT Hittest(POINT pt, POINT ptTest);
        !            98: protected:
        !            99:         POINT   _ptOrg;
        !           100:         HFONT   _font;
        !           101:         UINT    _iEltOffset;
        !           102: };
        !           103: 
        !           104: //========== CCharGrid =============================================
        !           105: 
        !           106: class CCharGrid : public CTextGrid
        !           107: {
        !           108: public:
        !           109:         CCharGrid(UINT cCol, UINT cRow, SIZE size, UINT iEltOffset=0);
        !           110:         virtual void DrawElement(CCanvas& canvas, COORD x, COORD y, UINT i, UINT j);
        !           111: };
        !           112: 
        !           113: 
        !           114: //========== CCodeGrid =============================================
        !           115: 
        !           116: #define HEXADECIMAL 0
        !           117: #define DECIMAL     1
        !           118: #define MASKROOT    1
        !           119: 
        !           120: class CCodeGrid : public CTextGrid
        !           121: {
        !           122: public:
        !           123:         CCodeGrid(UINT cCol, UINT cRow, SIZE size, UINT iEltOffset=0);
        !           124:         void SetFormat(UINT fuFormat=HEXADECIMAL, UINT cDigits=1);
        !           125:         void DrawElement(CCanvas& canvas, COORD x, COORD y, UINT i, UINT j);
        !           126: protected:
        !           127:         UINT    _cDigits;
        !           128:         TCHAR   _szFormat[5];
        !           129: };
        !           130: 
        !           131: //========== CBlockFormat =============================================
        !           132: // formatting elements common to all blocks 
        !           133: 
        !           134: 
        !           135: class CBlockFormat
        !           136: {
        !           137: public:
        !           138:         SIZE    _size;          // size of grid cell
        !           139:         CFont   _fontChar;
        !           140:         CFont   _fontCode;
        !           141: protected:
        !           142:         CBlockFormat();
        !           143: };
        !           144: 
        !           145: //========== CFrameFormat =============================================
        !           146: // formatting elements common to all frames
        !           147: class CFrameFormat : public CBlockFormat
        !           148: {
        !           149: public:
        !           150:         CFont   _fontHeader;
        !           151:         CFont   _fontLabel;
        !           152: protected:
        !           153:         CFrameFormat();
        !           154: };       
        !           155: 
        !           156: //========== CPageFormat =============================================
        !           157: //
        !           158: #define PAGEELEMS 2
        !           159: #define PAGEPRINT 4
        !           160: 
        !           161: class CPageFormat : public CFrameFormat
        !           162: {
        !           163: public: 
        !           164:         CPageFormat(UINT fuFormat);
        !           165:         void SetFormat(UINT fuFormat=HEXADECIMAL);
        !           166: 
        !           167:         CFont   _fontPageNum;
        !           168:         UINT    _fuFormat;
        !           169:         POINT   _ptPE[3];
        !           170:         POINT   _pt;            // "origin" of page proper
        !           171: };
        !           172: 
        !           173: //========== CCharBlock =============================================
        !           174: class CCharBlock
        !           175: {
        !           176: public:
        !           177:         CCharBlock(UINT cCol, UINT cRow, UINT iBlockOffset, const CBlockFormat &bf);
        !           178: 
        !           179:         void Paint(CCanvas& canvas, RECT rc, POINT pt);
        !           180:         UINT Hittest(POINT pt, POINT ptTest);
        !           181:         void SetFormat(UINT fuFormat=HEXADECIMAL);
        !           182:         void SetFont(HFONT font);
        !           183: protected:
        !           184:         CLineGrid       _Line;
        !           185:         CCharGrid       _Char;
        !           186:         CCodeGrid       _Code;
        !           187: };
        !           188: 
        !           189: 
        !           190: //========== CBlockFrame =============================================
        !           191: 
        !           192: class CBlockFrame : public CCharBlock
        !           193: {
        !           194: public:
        !           195:         CBlockFrame(UINT cCol, UINT cRow, POINT pt, UINT iBlockOffset, 
        !           196:                                     TCHAR *szHeader, const CFrameFormat &ff);
        !           197:         ~CBlockFrame();
        !           198:         void Paint(CCanvas& canvas, RECT rc, POINT pt);
        !           199: 
        !           200: protected:
        !           201:         void Draw(CCanvas& canvas, POINT pt);
        !           202:         TCHAR *         _szHeader;
        !           203:         SIZE            _size;
        !           204:         UINT            _cCol;
        !           205:         UINT            _cRow;   
        !           206:         HFONT           _fontHeader;
        !           207:         CCodeGrid       _Cols;
        !           208: 
        !           209:         // optional
        !           210:         CCodeGrid *     _pRows;
        !           211: };
        !           212: //========== CPage ===================================================
        !           213: 
        !           214: class CPage
        !           215: {
        !           216: public:
        !           217:         CPage(HINSTANCE hInst, CPageFormat& pf, UINT nPage=0);
        !           218:         ~CPage();
        !           219:       
        !           220:         void Paint(CCanvas& canvas, RECT rc);
        !           221:         void SetFormat(UINT fuFormat=HEXADECIMAL);
        !           222:         void SetFont( HFONT hfont);
        !           223:         UINT Hittest( POINT pt);
        !           224:         
        !           225: protected:
        !           226:         UINT InitPage(UINT nPage);
        !           227:         HINSTANCE       _hInst;
        !           228:         CPageFormat&    _pf;
        !           229: 
        !           230:         UINT            _cBlock;        // 0..4
        !           231:         CBlockFrame*    _apBlock[4];    // at most 4 blocks/page
        !           232:         POINT           _aptBlock[4];
        !           233: 
        !           234:         CCodeGrid       _PageHeadR;     // Right header 
        !           235:         CCodeGrid       _PageHeadL;     // Left  header 
        !           236:         CCodeGrid       _PageNums;      // Page number
        !           237: };
        !           238: 
        !           239: //========== CModel ==================================================
        !           240: 
        !           241: class CModel
        !           242: {
        !           243: public:
        !           244:         CModel(HINSTANCE hInst, UINT fuFormat=HEXADECIMAL);
        !           245:         ~CModel();
        !           246: 
        !           247:         // iteration
        !           248:         void NextPage();
        !           249:         void PrevPage();
        !           250:         void NextSection();
        !           251:         void PrevSection();
        !           252:         BOOL CanNextPage()      { return _iPage + 1 < _macPage; };
        !           253:         BOOL CanPrevPage()      { return _iPage;                };
        !           254:         BOOL CanNextSection()   { return _iPage +16 < _macPage; };
        !           255:         BOOL CanPrevSection()   { return _iPage + 1 >= 16;      };
        !           256:         UINT GetPage()          { return _iPage;                };
        !           257:         void SetPage(UINT nPage);
        !           258: 
        !           259:         UINT GetMaxPage()       { return _macPage; };
        !           260:         UINT GetMaxSection()    { return _macPage / 16; };
        !           261: 
        !           262:         // Layout
        !           263:         void Paint(CCanvas& canvas, RECT rc){_pPage->Paint(canvas, rc);};
        !           264:         UINT Hittest( POINT pt);
        !           265:         void GetLineSize( SIZE * psize) { psize->cx = 4*INCH2/5;
        !           266:                                           psize->cy = INCH2;
        !           267:                                         }
        !           268: 
        !           269:         // Formatting
        !           270:         BOOL ChooseFont(HWND hwnd);
        !           271:         HFONT GetFont();
        !           272:         BOOL CreateFont(LOGFONT &lf);
        !           273:         void GetFormat(UINT &fuFormat);
        !           274:         void SetFormat(UINT fuFormat=HEXADECIMAL);
        !           275: 
        !           276: protected:
        !           277:         UINT            _iPage;
        !           278:         UINT            _macPage;
        !           279:         CPageFormat     _pf;
        !           280:         CPage *         _pPage;
        !           281:         HINSTANCE       _hInst;
        !           282: };
        !           283: 
        !           284: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.