Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

CellRange.h

00001 
00002 // CellRange.h: header file
00003 //
00004 // MFC Grid Control - interface for the CCellRange class.
00005 //
00006 // Written by Chris Maunder <cmaunder@mail.com>
00007 // Copyright (c) 1998-2002. All Rights Reserved.
00008 //
00009 // This code may be used in compiled form in any way you desire. This
00010 // file may be redistributed unmodified by any means PROVIDING it is 
00011 // not sold for profit without the authors written consent, and 
00012 // providing that this notice and the authors name and all copyright 
00013 // notices remains intact. 
00014 //
00015 // An email letting me know how you are using it would be nice as well. 
00016 //
00017 // This file is provided "as is" with no expressed or implied warranty.
00018 // The author accepts no liability for any damage/loss of business that
00019 // this product may cause.
00020 //
00021 // For use with CGridCtrl v2.20+
00022 //
00024 
00025 #if !defined(AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_)
00026 #define AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_
00027 
00028 #if _MSC_VER >= 1000
00029 #pragma once
00030 #endif // _MSC_VER >= 1000
00031 
00032 // The code contained in this file is based on the original
00033 // WorldCom Grid control written by Joe Willcoxson,
00034 //      mailto:chinajoe@aol.com
00035 //      http://users.aol.com/chinajoe
00036 
00037 class CCellID
00038 {    
00039 // Attributes
00040 public:
00041     int row, col;
00042 
00043 // Operations
00044 public:
00045     explicit CCellID(int nRow = -1, int nCol = -1) : row(nRow), col(nCol) {}
00046 
00047     int IsValid() const { return (row >= 0 && col >= 0); }
00048     int operator==(const CCellID& rhs) const { return (row == rhs.row && col == rhs.col); }
00049     int operator!=(const CCellID& rhs) const { return !operator==(rhs); }
00050 };
00051 
00052 class CCellRange
00053 { 
00054 public:
00055     
00056     CCellRange(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1)
00057     {
00058         Set(nMinRow, nMinCol, nMaxRow, nMaxCol);
00059     }
00060 
00061     void Set(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1);
00062     
00063     int  IsValid() const;
00064     int  InRange(int row, int col) const;
00065     int  InRange(const CCellID& cellID) const;
00066     int  Count() { return (m_nMaxRow - m_nMinRow + 1) * (m_nMaxCol - m_nMinCol + 1); }
00067     
00068     CCellID  GetTopLeft() const;
00069     CCellRange  Intersect(const CCellRange& rhs) const;
00070     
00071     int GetMinRow() const {return m_nMinRow;}
00072     void SetMinRow(int minRow) {m_nMinRow = minRow;}
00073     
00074     int GetMinCol() const {return m_nMinCol;}
00075     void SetMinCol(int minCol) {m_nMinCol = minCol;}
00076     
00077     int GetMaxRow() const {return m_nMaxRow;}
00078     void SetMaxRow(int maxRow) {m_nMaxRow = maxRow;}
00079     
00080     int GetMaxCol() const {return m_nMaxCol;}
00081     void SetMaxCol(int maxCol) {m_nMaxCol = maxCol;}
00082 
00083     int GetRowSpan() const {return m_nMaxRow - m_nMinRow + 1;}
00084     int GetColSpan() const {return m_nMaxCol - m_nMinCol + 1;}
00085     
00086     void operator=(const CCellRange& rhs);
00087     int  operator==(const CCellRange& rhs);
00088     int  operator!=(const CCellRange& rhs);
00089     
00090 protected:
00091     int m_nMinRow;
00092     int m_nMinCol;
00093     int m_nMaxRow;
00094     int m_nMaxCol;
00095 };
00096 
00097 inline void CCellRange::Set(int minRow, int minCol, int maxRow, int maxCol)
00098 {
00099      m_nMinRow = minRow;
00100      m_nMinCol = minCol;
00101      m_nMaxRow = maxRow;
00102      m_nMaxCol = maxCol;
00103 }
00104 
00105 inline void CCellRange::operator=(const CCellRange& rhs)
00106 {
00107     if (this != &rhs) Set(rhs.m_nMinRow, rhs.m_nMinCol, rhs.m_nMaxRow, rhs.m_nMaxCol);
00108 }
00109 
00110 inline int CCellRange::operator==(const CCellRange& rhs)
00111 {
00112      return ((m_nMinRow == rhs.m_nMinRow) && (m_nMinCol == rhs.m_nMinCol) &&
00113              (m_nMaxRow == rhs.m_nMaxRow) && (m_nMaxCol == rhs.m_nMaxCol));
00114 }
00115 
00116 inline int CCellRange::operator!=(const CCellRange& rhs)
00117 {
00118      return !operator==(rhs);
00119 }
00120 
00121 inline int CCellRange::IsValid() const
00122 {
00123      return (m_nMinRow >= 0 && m_nMinCol >= 0 && m_nMaxRow >= 0 && m_nMaxCol >= 0 &&
00124              m_nMinRow <= m_nMaxRow && m_nMinCol <= m_nMaxCol);
00125 }
00126 
00127 inline int CCellRange::InRange(int row, int col) const
00128 {
00129      return (row >= m_nMinRow && row <= m_nMaxRow && col >= m_nMinCol && col <= m_nMaxCol);
00130 }
00131 
00132 inline int CCellRange::InRange(const CCellID& cellID) const
00133 {
00134      return InRange(cellID.row, cellID.col);
00135 }
00136 
00137 inline CCellID CCellRange::GetTopLeft() const
00138 {
00139      return CCellID(m_nMinRow, m_nMinCol);
00140 }
00141 
00142 inline CCellRange CCellRange::Intersect(const CCellRange& rhs) const
00143 {
00144      return CCellRange(kmax(m_nMinRow,rhs.m_nMinRow), kmax(m_nMinCol,rhs.m_nMinCol),
00145                        kmin(m_nMaxRow,rhs.m_nMaxRow), kmin(m_nMaxCol,rhs.m_nMaxCol));
00146 }
00147 
00148 #endif // !defined(AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_)

Generated on Tue Feb 17 02:03:02 2004 for harlem by doxygen 1.3.6