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

GridCtrl.h

00001 
00002 // GridCtrl.h : header file
00003 //
00004 // MFC Grid Control - main header
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_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
00026 #define AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
00027 
00028 #if _MSC_VER >= 1000
00029 #pragma once
00030 #endif // _MSC_VER >= 1000
00031 
00032 #include "CellRange.h"
00033 #include "GridCell.h"
00034 #include <afxtempl.h>
00035 
00036 
00038 // Defines - these determine the features (and the final size) of the final code
00040 
00041 //#define GRIDCONTROL_NO_TITLETIPS   // Do not use titletips for cells with large data
00042 //#define GRIDCONTROL_NO_DRAGDROP    // Do not use OLE drag and drop
00043 //#define GRIDCONTROL_NO_CLIPBOARD   // Do not use clipboard routines
00044 
00045 #ifdef _WIN32_WCE
00046 #   define GRIDCONTROL_NO_TITLETIPS   // Do not use titletips for cells with large data
00047 #   define GRIDCONTROL_NO_DRAGDROP    // Do not use OLE drag and drop
00048 #   define GRIDCONTROL_NO_CLIPBOARD   // Do not use clipboard routines
00049 #   define GRIDCONTROL_NO_PRINTING    // Do not use printing routines
00050 #   ifdef WCE_NO_PRINTING                         // Older versions of CE had different #def's
00051 #       define _WIN32_WCE_NO_PRINTING
00052 #   endif
00053 #   ifdef WCE_NO_CURSOR
00054 #       define _WIN32_WCE_NO_CURSOR
00055 #   endif
00056 #endif  // _WIN32_WCE
00057 
00058 // Use this as the classname when inserting this control as a custom control
00059 // in the MSVC++ dialog editor
00060 #define GRIDCTRL_CLASSNAME    _T("MFCGridCtrl")  // Window class name
00061 #define IDC_INPLACE_CONTROL   8                  // ID of inplace edit controls
00062 
00063 
00065 // Conditional includes
00067 
00068 #ifndef GRIDCONTROL_NO_TITLETIPS
00069 #   include "TitleTip.h"
00070 #endif
00071 
00072 #ifndef GRIDCONTROL_NO_DRAGDROP
00073 #   include "GridDropTarget.h"
00074 #   undef GRIDCONTROL_NO_CLIPBOARD     // Force clipboard functions on
00075 #endif
00076 
00077 #ifndef GRIDCONTROL_NO_CLIPBOARD
00078 #   include <afxole.h>
00079 #endif
00080 
00081 
00083 // Helper functions
00085 
00086 // Handy functions
00087 #define IsSHIFTpressed() ( (GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT)*8-1))) != 0   )
00088 #define IsCTRLpressed()  ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )
00089 
00090 // Backwards compatibility for pre 2.20 grid versions
00091 #define DDX_GridControl(pDX, nIDC, rControl)  DDX_Control(pDX, nIDC, rControl)     
00092 
00093 
00095 // Structures
00097 
00098 // This structure sent to Grid's parent in a WM_NOTIFY message
00099 typedef struct tagNM_GRIDVIEW {
00100     NMHDR hdr;
00101     int   iRow;
00102     int   iColumn;
00103 } NM_GRIDVIEW;
00104 
00105 // This is sent to the Grid from child in-place edit controls
00106 typedef struct tagGV_DISPINFO {
00107     NMHDR   hdr;
00108     GV_ITEM item;
00109 } GV_DISPINFO;
00110 
00111 // This is sent to the Grid from child in-place edit controls
00112 typedef struct tagGV_CACHEHINT {
00113     NMHDR      hdr;
00114     CCellRange range;
00115 } GV_CACHEHINT;
00116 
00117 // storage typedef for each row in the grid
00118 typedef CTypedPtrArray<CObArray, CGridCellBase*> GRID_ROW;
00119 
00120 // For virtual mode callback
00121 typedef BOOL (CALLBACK* GRIDCALLBACK)(GV_DISPINFO *, LPARAM);
00122 
00124 // Defines
00126 
00127 // Grid line/scrollbar selection
00128 #define GVL_NONE                0L      // Neither
00129 #define GVL_HORZ                1L      // Horizontal line or scrollbar
00130 #define GVL_VERT                2L      // Vertical line or scrollbar
00131 #define GVL_BOTH                3L      // Both
00132 
00133 // Autosizing option
00134 #define GVS_DEFAULT             0
00135 #define GVS_HEADER              1       // Size using column fixed cells data only
00136 #define GVS_DATA                2       // Size using column non-fixed cells data only
00137 #define GVS_BOTH                3       // Size using column fixed and non-fixed
00138 
00139 // Cell Searching options
00140 #define GVNI_FOCUSED            0x0001
00141 #define GVNI_SELECTED           0x0002
00142 #define GVNI_DROPHILITED        0x0004
00143 #define GVNI_READONLY           0x0008
00144 #define GVNI_FIXED              0x0010
00145 #define GVNI_MODIFIED           0x0020
00146 
00147 #define GVNI_ABOVE              LVNI_ABOVE
00148 #define GVNI_BELOW              LVNI_BELOW
00149 #define GVNI_TOLEFT             LVNI_TOLEFT
00150 #define GVNI_TORIGHT            LVNI_TORIGHT
00151 #define GVNI_ALL                (LVNI_BELOW|LVNI_TORIGHT|LVNI_TOLEFT)
00152 #define GVNI_AREA               (LVNI_BELOW|LVNI_TORIGHT)
00153 
00154 // Hit test values (not yet implemented)
00155 #define GVHT_DATA               0x0000
00156 #define GVHT_TOPLEFT            0x0001
00157 #define GVHT_COLHDR             0x0002
00158 #define GVHT_ROWHDR             0x0004
00159 #define GVHT_COLSIZER           0x0008
00160 #define GVHT_ROWSIZER           0x0010
00161 #define GVHT_LEFT               0x0020
00162 #define GVHT_RIGHT              0x0040
00163 #define GVHT_ABOVE              0x0080
00164 #define GVHT_BELOW              0x0100
00165 
00166 // Messages sent to the grid's parent (More will be added in future)
00167 #define GVN_BEGINDRAG           LVN_BEGINDRAG        // LVN_FIRST-9
00168 #define GVN_BEGINLABELEDIT      LVN_BEGINLABELEDIT   // LVN_FIRST-5
00169 #define GVN_BEGINRDRAG          LVN_BEGINRDRAG
00170 #define GVN_COLUMNCLICK         LVN_COLUMNCLICK
00171 #define GVN_DELETEITEM          LVN_DELETEITEM
00172 #define GVN_ENDLABELEDIT        LVN_ENDLABELEDIT     // LVN_FIRST-6
00173 #define GVN_SELCHANGING         LVN_ITEMCHANGING
00174 #define GVN_SELCHANGED          LVN_ITEMCHANGED
00175 #define GVN_GETDISPINFO         LVN_GETDISPINFO 
00176 #define GVN_ODCACHEHINT         LVN_ODCACHEHINT 
00177 
00178 class CGridCtrl;
00179 
00181 // CGridCtrl window
00182 
00183 class CGridCtrl : public CWnd
00184 {
00185     DECLARE_DYNCREATE(CGridCtrl)
00186     friend class CGridCell;
00187     friend class CGridCellBase;
00188 
00189 // Construction
00190 public:
00191     CGridCtrl(int nRows = 0, int nCols = 0, int nFixedRows = 0, int nFixedCols = 0);
00192 
00193     BOOL Create(const RECT& rect, CWnd* parent, UINT nID,
00194                 DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
00195 
00197 // Attributes
00199 public:
00200     int  GetRowCount() const                    { return m_nRows; }
00201     int  GetColumnCount() const                 { return m_nCols; }
00202     int  GetFixedRowCount() const               { return m_nFixedRows; }
00203     int  GetFixedColumnCount() const            { return m_nFixedCols; }
00204     BOOL SetRowCount(int nRows = 10);
00205     BOOL SetColumnCount(int nCols = 10);
00206     BOOL SetFixedRowCount(int nFixedRows = 1);
00207     BOOL SetFixedColumnCount(int nFixedCols = 1);
00208 
00209     int  GetRowHeight(int nRow) const;
00210     BOOL SetRowHeight(int row, int height);
00211     int  GetColumnWidth(int nCol) const;
00212     BOOL SetColumnWidth(int col, int width);
00213 
00214     BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p);
00215     BOOL GetCellOrigin(const CCellID& cell, LPPOINT p);
00216     BOOL GetCellRect(int nRow, int nCol, LPRECT pRect);
00217     BOOL GetCellRect(const CCellID& cell, LPRECT pRect);
00218 
00219     BOOL GetTextRect(const CCellID& cell, LPRECT pRect);
00220     BOOL GetTextRect(int nRow, int nCol, LPRECT pRect);
00221 
00222     CCellID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE);
00223 
00224     int  GetFixedRowHeight() const;
00225     int  GetFixedColumnWidth() const;
00226     long GetVirtualWidth() const;
00227     long GetVirtualHeight() const;
00228 
00229     CSize GetTextExtent(int nRow, int nCol, LPCTSTR str);
00230     // EFW - Get extent of current text in cell
00231     inline CSize GetCellTextExtent(int nRow, int nCol)  { return GetTextExtent(nRow, nCol, GetItemText(nRow,nCol)); }
00232 
00233     void     SetGridBkColor(COLORREF clr)         { m_crGridBkColour = clr;           }
00234     COLORREF GetGridBkColor() const               { return m_crGridBkColour;          }
00235     void     SetGridLineColor(COLORREF clr)       { m_crGridLineColour = clr;         }
00236     COLORREF GetGridLineColor() const             { return m_crGridLineColour;        }
00237 
00238         void     SetTitleTipBackClr(COLORREF clr = CLR_DEFAULT) { m_crTTipBackClr = clr;  }
00239         COLORREF GetTitleTipBackClr()                                       { return m_crTTipBackClr; }
00240         void     SetTitleTipTextClr(COLORREF clr = CLR_DEFAULT) { m_crTTipTextClr = clr;  }
00241         COLORREF GetTitleTipTextClr()                                       { return m_crTTipTextClr; }
00242 
00243     // ***************************************************************************** //
00244     // These have been deprecated. Use GetDefaultCell and then set the colors
00245     void     SetTextColor(COLORREF clr)      { m_cellDefault.SetTextClr(clr);        }
00246     COLORREF GetTextColor()                  { return m_cellDefault.GetTextClr();    }
00247     void     SetTextBkColor(COLORREF clr)    { m_cellDefault.SetBackClr(clr);        }
00248     COLORREF GetTextBkColor()                { return m_cellDefault.GetBackClr();    }
00249     void     SetFixedTextColor(COLORREF clr) { m_cellFixedRowDef.SetTextClr(clr); 
00250                                                m_cellFixedColDef.SetTextClr(clr); 
00251                                                m_cellFixedRowColDef.SetTextClr(clr); }
00252     COLORREF GetFixedTextColor() const       { return m_cellFixedRowDef.GetTextClr(); }
00253     void     SetFixedBkColor(COLORREF clr)   { m_cellFixedRowDef.SetBackClr(clr); 
00254                                                m_cellFixedColDef.SetBackClr(clr); 
00255                                                m_cellFixedRowColDef.SetBackClr(clr); }
00256     COLORREF GetFixedBkColor() const         { return m_cellFixedRowDef.GetBackClr(); }
00257     void     SetGridColor(COLORREF clr)      { SetGridLineColor(clr);                }
00258     COLORREF GetGridColor()                  { return GetGridLineColor();            }
00259     void     SetBkColor(COLORREF clr)        { SetGridBkColor(clr);                  }
00260     COLORREF GetBkColor()                    { return GetGridBkColor();              }
00261 
00262     void     SetDefCellMargin( int nMargin)  { m_cellDefault.SetMargin(nMargin); 
00263                                                m_cellFixedRowDef.SetMargin(nMargin); 
00264                                                m_cellFixedColDef.SetMargin(nMargin); 
00265                                                m_cellFixedRowColDef.SetMargin(nMargin); }
00266     int      GetDefCellMargin() const        { return m_cellDefault.GetMargin();     }
00267 
00268     int      GetDefCellHeight() const        { return m_cellDefault.GetHeight();     }
00269     void     SetDefCellHeight(int nHeight)   { m_cellDefault.SetHeight(nHeight); 
00270                                                m_cellFixedRowDef.SetHeight(nHeight); 
00271                                                m_cellFixedColDef.SetHeight(nHeight); 
00272                                                m_cellFixedRowColDef.SetHeight(nHeight); }
00273     int      GetDefCellWidth() const         { return m_cellDefault.GetWidth();     }
00274     void     SetDefCellWidth(int nWidth)     { m_cellDefault.SetWidth(nWidth); 
00275                                                m_cellFixedRowDef.SetWidth(nWidth); 
00276                                                m_cellFixedColDef.SetWidth(nWidth); 
00277                                                m_cellFixedRowColDef.SetWidth(nWidth); }
00278 
00279     // ***************************************************************************** //
00280 
00281     int GetSelectedCount() const                  { return (int)m_SelectedCellMap.GetCount(); }
00282 
00283     CCellID SetFocusCell(CCellID cell);
00284     CCellID SetFocusCell(int nRow, int nCol);
00285     CCellID GetFocusCell() const                  { return m_idCurrentCell;           }
00286 
00287 
00288     void SetVirtualMode(BOOL bVirtual);
00289     BOOL GetVirtualMode() const                   { return m_bVirtualMode;            }
00290     void SetCallbackFunc(GRIDCALLBACK pCallback, 
00291                          LPARAM lParam)           { m_pfnCallback = pCallback; m_lParam = lParam; }
00292     GRIDCALLBACK GetCallbackFunc()                { return m_pfnCallback;             }
00293 
00294 
00295     void SetImageList(CImageList* pList)          { m_pImageList = pList;             }
00296     CImageList* GetImageList() const              { return m_pImageList;              }
00297 
00298     void SetGridLines(int nWhichLines = GVL_BOTH);
00299     int  GetGridLines() const                     { return m_nGridLines;              }
00300     void SetEditable(BOOL bEditable = TRUE)       { m_bEditable = bEditable;          }
00301     BOOL IsEditable() const                       { return m_bEditable;               }
00302     void SetListMode(BOOL bEnableListMode = TRUE);
00303     BOOL GetListMode() const                      { return m_bListMode;               }
00304     void SetSingleRowSelection(BOOL bSing = TRUE) { m_bSingleRowSelection = bSing;    }
00305     BOOL GetSingleRowSelection()                  { return m_bSingleRowSelection & m_bListMode; }
00306     void SetSingleColSelection(BOOL bSing = TRUE) { m_bSingleColSelection = bSing;    }
00307     BOOL GetSingleColSelection()                  { return m_bSingleColSelection;     }
00308     void EnableSelection(BOOL bEnable = TRUE)     { ResetSelectedRange(); m_bEnableSelection = bEnable; ResetSelectedRange(); }
00309     BOOL IsSelectable() const                     { return m_bEnableSelection;        }
00310     void SetFixedColumnSelection(BOOL bSelect)    { m_bFixedColumnSelection = bSelect;}
00311     BOOL GetFixedColumnSelection()                { return m_bFixedColumnSelection;   }
00312     void SetFixedRowSelection(BOOL bSelect)       { m_bFixedRowSelection = bSelect;   }
00313     BOOL GetFixedRowSelection()                   { return m_bFixedRowSelection;      }
00314     void EnableDragAndDrop(BOOL bAllow = TRUE)    { m_bAllowDragAndDrop = bAllow;     }
00315     BOOL GetDragAndDrop() const                   { return m_bAllowDragAndDrop;       }
00316     void SetRowResize(BOOL bResize = TRUE)        { m_bAllowRowResize = bResize;      }
00317     BOOL GetRowResize() const                     { return m_bAllowRowResize;         }
00318     void SetColumnResize(BOOL bResize = TRUE)     { m_bAllowColumnResize = bResize;   }
00319     BOOL GetColumnResize() const                  { return m_bAllowColumnResize;      }
00320     void SetHeaderSort(BOOL bSortOnClick = TRUE)  { m_bSortOnClick = bSortOnClick;    }
00321     BOOL GetHeaderSort() const                    { return m_bSortOnClick;            }
00322     void SetHandleTabKey(BOOL bHandleTab = TRUE)  { m_bHandleTabKey = bHandleTab;     }
00323     BOOL GetHandleTabKey() const                  { return m_bHandleTabKey;           }
00324     void SetDoubleBuffering(BOOL bBuffer = TRUE)  { m_bDoubleBuffer = bBuffer;        }
00325     BOOL GetDoubleBuffering() const               { return m_bDoubleBuffer;           }
00326     void EnableTitleTips(BOOL bEnable = TRUE)     { m_bTitleTips = bEnable;           }
00327     BOOL GetTitleTips()                           { return m_bTitleTips;              }
00328     void SetSortColumn(int nCol);
00329     int  GetSortColumn() const                    { return m_nSortColumn;             }
00330     void SetSortAscending(BOOL bAscending)        { m_bAscending = bAscending;        }
00331     BOOL GetSortAscending() const                 { return m_bAscending;              }
00332     void SetTrackFocusCell(BOOL bTrack)           { m_bTrackFocusCell = bTrack;       }
00333     BOOL GetTrackFocusCell()                      { return m_bTrackFocusCell;         }
00334     void SetFrameFocusCell(BOOL bFrame)           { m_bFrameFocus = bFrame;           }
00335     BOOL GetFrameFocusCell()                      { return m_bFrameFocus;             }
00336     void SetAutoSizeStyle(int nStyle = GVS_BOTH)  { m_nAutoSizeColumnStyle = nStyle;  }
00337     int  GetAutoSizeStyle()                       { return m_nAutoSizeColumnStyle; }
00338 
00339     void EnableHiddenColUnhide(BOOL bEnable = TRUE){ m_bHiddenColUnhide = bEnable;    }
00340     BOOL GetHiddenColUnhide()                     { return m_bHiddenColUnhide;        }
00341     void EnableHiddenRowUnhide(BOOL bEnable = TRUE){ m_bHiddenRowUnhide = bEnable;    }
00342     BOOL GetHiddenRowUnhide()                     { return m_bHiddenRowUnhide;        }
00343 
00344     void EnableColumnHide(BOOL bEnable = TRUE)    { m_bAllowColHide = bEnable;        }
00345     BOOL GetColumnHide()                          { return m_bAllowColHide;           }
00346     void EnableRowHide(BOOL bEnable = TRUE)       { m_bAllowRowHide = bEnable;        }
00347     BOOL GetRowHide()                             { return m_bAllowRowHide;           }
00348 
00350 // default Grid cells. Use these for setting default values such as colors and fonts
00352 public:
00353     CGridCellBase* GetDefaultCell(BOOL bFixedRow, BOOL bFixedCol) const;
00354 
00356 // Grid cell Attributes
00358 public:
00359     CGridCellBase* GetCell(int nRow, int nCol) const;   // Get the actual cell!
00360 
00361     void SetModified(BOOL bModified = TRUE, int nRow = -1, int nCol = -1);
00362     BOOL GetModified(int nRow = -1, int nCol = -1);
00363     BOOL IsCellFixed(int nRow, int nCol);
00364 
00365     BOOL   SetItem(const GV_ITEM* pItem);
00366     BOOL   GetItem(GV_ITEM* pItem);
00367     BOOL   SetItemText(int nRow, int nCol, LPCTSTR str);
00368     // The following was virtual. If you want to override, use 
00369     //  CGridCellBase-derived class's GetText() to accomplish same thing
00370     CString GetItemText(int nRow, int nCol) const;
00371 
00372     // EFW - 06/13/99 - Added to support printf-style formatting codes.
00373     // Also supports use with a string resource ID
00374 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 210)
00375     BOOL   SetItemTextFmt(int nRow, int nCol, LPCTSTR szFmt, ...);
00376     BOOL   SetItemTextFmtID(int nRow, int nCol, UINT nID, ...);
00377 #endif
00378 
00379     BOOL   SetItemData(int nRow, int nCol, LPARAM lParam);
00380     LPARAM GetItemData(int nRow, int nCol) const;
00381     BOOL   SetItemImage(int nRow, int nCol, int iImage);
00382     int    GetItemImage(int nRow, int nCol) const;
00383     BOOL   SetItemState(int nRow, int nCol, UINT state);
00384     UINT   GetItemState(int nRow, int nCol) const;
00385     BOOL   SetItemFormat(int nRow, int nCol, UINT nFormat);
00386     UINT   GetItemFormat(int nRow, int nCol) const;
00387     BOOL   SetItemBkColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
00388     COLORREF GetItemBkColour(int nRow, int nCol) const;
00389     BOOL   SetItemFgColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
00390     COLORREF GetItemFgColour(int nRow, int nCol) const;
00391     BOOL SetItemFont(int nRow, int nCol, const LOGFONT* lf);
00392     const LOGFONT* GetItemFont(int nRow, int nCol);
00393 
00394     BOOL IsItemEditing(int nRow, int nCol);
00395 
00396     BOOL SetCellType(int nRow, int nCol, CRuntimeClass* pRuntimeClass);
00397     BOOL SetDefaultCellType( CRuntimeClass* pRuntimeClass);
00398 
00400 // Operations
00402 public:
00403     int  InsertColumn(LPCTSTR strHeading, UINT nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE,
00404                       int nColumn = -1);
00405     int  InsertRow(LPCTSTR strHeading, int nRow = -1);
00406     BOOL DeleteColumn(int nColumn);
00407     BOOL DeleteRow(int nRow);
00408     BOOL DeleteNonFixedRows();
00409     BOOL DeleteAllItems();
00410 
00411         void ClearCells(CCellRange Selection);
00412 
00413     BOOL AutoSizeRow(int nRow, BOOL bResetScroll = TRUE);
00414     BOOL AutoSizeColumn(int nCol, UINT nAutoSizeStyle = GVS_DEFAULT, BOOL bResetScroll = TRUE);
00415     void AutoSizeRows();
00416     void AutoSizeColumns(UINT nAutoSizeStyle = GVS_DEFAULT);
00417     void AutoSize(UINT nAutoSizeStyle = GVS_DEFAULT);
00418     void ExpandColumnsToFit(BOOL bExpandFixed = TRUE);
00419     void ExpandLastColumn();
00420     void ExpandRowsToFit(BOOL bExpandFixed = TRUE);
00421     void ExpandToFit(BOOL bExpandFixed = TRUE);
00422 
00423     void Refresh();
00424     void AutoFill();   // Fill grid with blank cells
00425 
00426     void EnsureVisible(CCellID &cell)       { EnsureVisible(cell.row, cell.col); }
00427     void EnsureVisible(int nRow, int nCol);
00428     BOOL IsCellVisible(int nRow, int nCol);
00429     BOOL IsCellVisible(CCellID cell);
00430     BOOL IsCellEditable(int nRow, int nCol) const;
00431     BOOL IsCellEditable(CCellID &cell) const;
00432     BOOL IsCellSelected(int nRow, int nCol) const;
00433     BOOL IsCellSelected(CCellID &cell) const;
00434 
00435     // SetRedraw stops/starts redraws on things like changing the # rows/columns
00436     // and autosizing, but not for user-intervention such as resizes
00437     void SetRedraw(BOOL bAllowDraw, BOOL bResetScrollBars = FALSE);
00438     BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
00439     BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL);
00440     BOOL RedrawRow(int row);
00441     BOOL RedrawColumn(int col);
00442 
00443 #ifndef _WIN32_WCE
00444     BOOL Save(LPCTSTR filename, TCHAR chSeparator = _T(','));
00445     BOOL Load(LPCTSTR filename, TCHAR chSeparator = _T(','));
00446 #endif
00447 
00449 // Cell Ranges
00451  public:
00452     CCellRange GetCellRange() const;
00453     CCellRange GetSelectedCellRange() const;
00454     void SetSelectedRange(const CCellRange& Range, BOOL bForceRepaint = FALSE, BOOL bSelectCells = TRUE);
00455     void SetSelectedRange(int nMinRow, int nMinCol, int nMaxRow, int nMaxCol,
00456                           BOOL bForceRepaint = FALSE, BOOL bSelectCells = TRUE);
00457     BOOL IsValid(int nRow, int nCol) const;
00458     BOOL IsValid(const CCellID& cell) const;
00459     BOOL IsValid(const CCellRange& range) const;
00460 
00462 // Clipboard, drag and drop, and cut n' paste operations
00464 #ifndef GRIDCONTROL_NO_CLIPBOARD
00465     virtual void CutSelectedText();
00466     virtual COleDataSource* CopyTextFromGrid();
00467     virtual BOOL PasteTextToGrid(CCellID cell, COleDataObject* pDataObject, BOOL bSelectPastedCells=TRUE);
00468 #endif
00469 
00470 #ifndef GRIDCONTROL_NO_DRAGDROP
00471  public:
00472     virtual void OnBeginDrag();
00473     virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
00474     virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
00475     virtual void OnDragLeave();
00476     virtual BOOL OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
00477 #endif
00478 
00479 #ifndef GRIDCONTROL_NO_CLIPBOARD
00480     virtual void OnEditCut();
00481     virtual void OnEditCopy();
00482     virtual void OnEditPaste();
00483 #endif
00484     virtual void OnEditSelectAll();
00485 
00487 // Misc.
00489 public:
00490     CCellID GetNextItem(CCellID& cell, int nFlags) const;
00491 
00492         BOOL SortItems(int nCol, BOOL bAscending, LPARAM data = 0);
00493     BOOL SortTextItems(int nCol, BOOL bAscending, LPARAM data = 0);
00494     BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data = 0);
00495 
00496         void SetCompareFunction(PFNLVCOMPARE pfnCompare);
00497 
00498         // in-built sort functions
00499         static int CALLBACK pfnCellTextCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
00500         static int CALLBACK pfnCellNumericCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
00501 
00503 // Printing
00505 #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
00506 public:
00507     void Print(CPrintDialog* pPrntDialog = NULL);
00508 
00509     // EFW - New printing support functions
00510     void EnableWysiwygPrinting(BOOL bEnable = TRUE) { m_bWysiwygPrinting = bEnable;     }
00511     BOOL GetWysiwygPrinting()                       { return m_bWysiwygPrinting;        }
00512 
00513     void SetShadedPrintOut(BOOL bEnable = TRUE)     {   m_bShadedPrintOut = bEnable;    }
00514     BOOL GetShadedPrintOut(void)                    {   return m_bShadedPrintOut;       }
00515 
00516     // Use -1 to have it keep the existing value
00517     void SetPrintMarginInfo(int nHeaderHeight, int nFooterHeight,
00518         int nLeftMargin, int nRightMargin, int nTopMargin,
00519         int nBottomMargin, int nGap);
00520 
00521     void GetPrintMarginInfo(int &nHeaderHeight, int &nFooterHeight,
00522         int &nLeftMargin, int &nRightMargin, int &nTopMargin,
00523         int &nBottomMargin, int &nGap);
00524 
00526 // Printing overrides for derived classes
00528 public:
00529     virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
00530     virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
00531     virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
00532 
00533 #endif // #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
00534 
00535 // Implementation
00536 public:
00537     virtual ~CGridCtrl();
00538 
00539 protected:
00540     BOOL RegisterWindowClass();
00541     BOOL Initialise();
00542     void SetupDefaultCells();
00543 
00544     LRESULT SendMessageToParent(int nRow, int nCol, int nMessage) const;
00545     LRESULT SendDisplayRequestToParent(GV_DISPINFO* pDisplayInfo) const;
00546     LRESULT SendCacheHintToParent(const CCellRange& range) const;
00547 
00548     BOOL InvalidateCellRect(const int row, const int col);
00549     BOOL InvalidateCellRect(const CCellID& cell);
00550     BOOL InvalidateCellRect(const CCellRange& cellRange);
00551     void EraseBkgnd(CDC* pDC);
00552 
00553     BOOL GetCellRangeRect(const CCellRange& cellRange, LPRECT lpRect);
00554 
00555     BOOL SetCell(int nRow, int nCol, CGridCellBase* pCell);
00556 
00557     int  SetMouseMode(int nMode) { int nOldMode = m_MouseMode; m_MouseMode = nMode; return nOldMode; }
00558     int  GetMouseMode() const    { return m_MouseMode; }
00559 
00560     BOOL MouseOverRowResizeArea(CPoint& point);
00561     BOOL MouseOverColumnResizeArea(CPoint& point);
00562 
00563     CCellID GetTopleftNonFixedCell(BOOL bForceRecalculation = FALSE);
00564     CCellRange GetUnobstructedNonFixedCellRange(BOOL bForceRecalculation = FALSE);
00565     CCellRange GetVisibleNonFixedCellRange(LPRECT pRect = NULL, BOOL bForceRecalculation = FALSE);
00566 
00567     BOOL IsVisibleVScroll() { return ( (m_nBarState & GVL_VERT) > 0); } 
00568     BOOL IsVisibleHScroll() { return ( (m_nBarState & GVL_HORZ) > 0); }
00569     void ResetSelectedRange();
00570     void ResetScrollBars();
00571     void EnableScrollBars(int nBar, BOOL bEnable = TRUE);
00572     int  GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
00573     BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);
00574 
00575     BOOL SortTextItems(int nCol, BOOL bAscending, int low, int high);
00576     BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data,
00577                    int low, int high);
00578 
00579     CPoint GetPointClicked(int nRow, int nCol, const CPoint& point);
00580 
00581         void ValidateAndModifyCellContents(int nRow, int nCol, LPCTSTR strText);
00582 
00583 // Overrrides
00584     // ClassWizard generated virtual function overrides
00585     //{{AFX_VIRTUAL(CGridCtrl)
00586     protected:
00587     virtual void PreSubclassWindow();
00588     //}}AFX_VIRTUAL
00589 
00590 protected:
00591 #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
00592     // Printing
00593         virtual void PrintFixedRowCells(int nStartColumn, int nStopColumn, int& row, CRect& rect,
00594                                     CDC *pDC, BOOL& bFirst);
00595     virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
00596     virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
00597     virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
00598     virtual void PrintRowButtons(CDC *pDC, CPrintInfo* /*pInfo*/);
00599 #endif
00600 
00601 #ifndef GRIDCONTROL_NO_DRAGDROP
00602     // Drag n' drop
00603     virtual CImageList* CreateDragImage(CPoint *pHotSpot);    // no longer necessary
00604 #endif
00605 
00606     // Mouse Clicks
00607     virtual void  OnFixedColumnClick(CCellID& cell);
00608     virtual void  OnFixedRowClick(CCellID& cell);
00609 
00610     // Editing
00611     virtual void  OnEditCell(int nRow, int nCol, CPoint point, UINT nChar);
00612     virtual void  OnEndEditCell(int nRow, int nCol, CString str);
00613         virtual BOOL  ValidateEdit(int nRow, int nCol, LPCTSTR str);
00614     virtual void  EndEditing();
00615 
00616     // Drawing
00617     virtual void  OnDraw(CDC* pDC);
00618 
00619     // CGridCellBase Creation and Cleanup
00620     virtual CGridCellBase* CreateCell(int nRow, int nCol);
00621     virtual void DestroyCell(int nRow, int nCol);
00622 
00623 // Attributes
00624 protected:
00625     // General attributes
00626     COLORREF    m_crFixedTextColour, m_crFixedBkColour;
00627     COLORREF    m_crGridBkColour, m_crGridLineColour;
00628     COLORREF    m_crWindowText, m_crWindowColour, m_cr3DFace,     // System colours
00629                 m_crShadow;
00630     COLORREF    m_crTTipBackClr, m_crTTipTextClr;                 // Titletip colours - FNA
00631     
00632     BOOL        m_bVirtualMode;
00633     LPARAM      m_lParam;                                           // lParam for callback
00634     GRIDCALLBACK m_pfnCallback;                                     // The callback function
00635 
00636     int         m_nGridLines;
00637     BOOL        m_bEditable;
00638     BOOL        m_bModified;
00639     BOOL        m_bAllowDragAndDrop;
00640     BOOL        m_bListMode;
00641     BOOL        m_bSingleRowSelection;
00642     BOOL        m_bSingleColSelection;
00643     BOOL        m_bAllowDraw;
00644     BOOL        m_bEnableSelection;
00645     BOOL        m_bFixedRowSelection, m_bFixedColumnSelection;
00646     BOOL        m_bSortOnClick;
00647     BOOL        m_bHandleTabKey;
00648     BOOL        m_bDoubleBuffer;
00649     BOOL        m_bTitleTips;
00650     int         m_nBarState;
00651     BOOL        m_bWysiwygPrinting;
00652     BOOL        m_bHiddenColUnhide, m_bHiddenRowUnhide;
00653     BOOL        m_bAllowColHide, m_bAllowRowHide;
00654     BOOL        m_bAutoSizeSkipColHdr;
00655     BOOL        m_bTrackFocusCell;
00656     BOOL        m_bFrameFocus;
00657     UINT        m_nAutoSizeColumnStyle;
00658 
00659     // Cell size details
00660     int         m_nRows, m_nFixedRows, m_nCols, m_nFixedCols;
00661     CUIntArray  m_arRowHeights, m_arColWidths;
00662     int         m_nVScrollMax, m_nHScrollMax;
00663 
00664     // Fonts and images
00665     CRuntimeClass*   m_pRtcDefault; // determines kind of Grid Cell created by default
00666     CGridDefaultCell m_cellDefault;  // "default" cell. Contains default colours, font etc.
00667     CGridDefaultCell m_cellFixedColDef, m_cellFixedRowDef, m_cellFixedRowColDef;
00668     CFont       m_PrinterFont;  // for the printer
00669     CImageList* m_pImageList;
00670 
00671     // Cell data
00672     CTypedPtrArray<CObArray, GRID_ROW*> m_RowData;
00673 
00674     // Mouse operations such as cell selection
00675     int         m_MouseMode;
00676     BOOL        m_bLMouseButtonDown, m_bRMouseButtonDown;
00677     CPoint      m_LeftClickDownPoint, m_LastMousePoint;
00678     CCellID     m_LeftClickDownCell, m_SelectionStartCell;
00679     CCellID     m_idCurrentCell, m_idTopLeftCell;
00680     int         m_nTimerID;
00681     int         m_nTimerInterval;
00682     int         m_nResizeCaptureRange;
00683     BOOL        m_bAllowRowResize, m_bAllowColumnResize;
00684     int         m_nRowsPerWheelNotch;
00685     CMap<DWORD,DWORD, CCellID, CCellID&> m_SelectedCellMap, m_PrevSelectedCellMap;
00686 
00687 #ifndef GRIDCONTROL_NO_TITLETIPS
00688     CTitleTip   m_TitleTip;             // Title tips for cells
00689 #endif
00690 
00691     // Drag and drop
00692     CCellID     m_LastDragOverCell;
00693 #ifndef GRIDCONTROL_NO_DRAGDROP
00694     CGridDropTarget m_DropTarget;       // OLE Drop target for the grid
00695 #endif
00696 
00697     // Printing information
00698     CSize       m_CharSize;
00699     int         m_nPageHeight;
00700     CSize       m_LogicalPageSize,      // Page size in gridctrl units.
00701                 m_PaperSize;            // Page size in device units.
00702     // additional properties to support Wysiwyg printing
00703     int         m_nPageWidth;
00704     int         m_nPrintColumn;
00705     int         m_nCurrPrintRow;
00706     int         m_nNumPages;
00707     int         m_nPageMultiplier;
00708 
00709     // sorting
00710     int          m_bAscending;
00711     int          m_nSortColumn;
00712         PFNLVCOMPARE m_pfnCompare;
00713 
00714     // EFW - Added to support shaded/unshaded printout.  If true, colored
00715     // cells will print as-is.  If false, all text prints as black on white.
00716     BOOL        m_bShadedPrintOut;
00717 
00718     // EFW - Added support for user-definable margins.  Top and bottom are in 
00719     // lines.  Left, right, and gap are in characters (avg width is used).
00720     int         m_nHeaderHeight, m_nFooterHeight, m_nLeftMargin,
00721                 m_nRightMargin, m_nTopMargin, m_nBottomMargin, m_nGap;
00722 
00723 protected:
00724     void SelectAllCells();
00725     void SelectColumns(CCellID currentCell, BOOL bForceRedraw=FALSE, BOOL bSelectCells=TRUE);
00726     void SelectRows(CCellID currentCell, BOOL bForceRedraw=FALSE, BOOL bSelectCells=TRUE);
00727     void SelectCells(CCellID currentCell, BOOL bForceRedraw=FALSE, BOOL bSelectCells=TRUE);
00728     void OnSelecting(const CCellID& currentCell);
00729 
00730     // Generated message map functions
00731     //{{AFX_MSG(CGridCtrl)
00732     afx_msg void OnPaint();
00733     afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
00734     afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
00735     afx_msg void OnSize(UINT nType, int cx, int cy);
00736     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
00737     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
00738     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
00739     afx_msg void OnTimer(UINT nIDEvent);
00740     afx_msg UINT OnGetDlgCode();
00741     afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
00742         afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
00743     afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
00744     afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
00745     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
00746     afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
00747     afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI);
00748     //}}AFX_MSG
00749 #ifndef _WIN32_WCE_NO_CURSOR
00750     afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
00751 #endif
00752 #ifndef _WIN32_WCE
00753     afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
00754     afx_msg void OnRButtonUp(UINT nFlags, CPoint point);    // EFW - Added
00755     afx_msg void OnSysColorChange();
00756 #endif
00757 #ifndef _WIN32_WCE_NO_CURSOR
00758     afx_msg void OnCaptureChanged(CWnd *pWnd);
00759 #endif
00760 #ifndef GRIDCONTROL_NO_CLIPBOARD
00761     afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
00762     afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
00763     afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
00764 #endif
00765 #if (_MFC_VER >= 0x0421) || (_WIN32_WCE >= 210)
00766     afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
00767 #endif
00768 #if !defined(_WIN32_WCE) && (_MFC_VER >= 0x0421)
00769     afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
00770 #endif
00771     afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam);
00772     afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
00773     afx_msg LRESULT OnImeChar(WPARAM wCharCode, LPARAM lParam);
00774     afx_msg void OnEndInPlaceEdit(NMHDR* pNMHDR, LRESULT* pResult);
00775     DECLARE_MESSAGE_MAP()
00776 
00777     enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW,
00778                        MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS,
00779                        MOUSE_OVER_ROW_DIVIDE, MOUSE_SIZING_ROW,
00780                        MOUSE_OVER_COL_DIVIDE, MOUSE_SIZING_COL,
00781                        MOUSE_PREPARE_EDIT,
00782 #ifndef GRIDCONTROL_NO_DRAGDROP
00783                        MOUSE_PREPARE_DRAG, MOUSE_DRAGGING
00784 #endif
00785     };
00786 };
00787 
00788 // Returns the default cell implementation for the given grid region
00789 inline CGridCellBase* CGridCtrl::GetDefaultCell(BOOL bFixedRow, BOOL bFixedCol) const
00790 { 
00791     if (bFixedRow && bFixedCol) return (CGridCellBase*) &m_cellFixedRowColDef;
00792     if (bFixedRow)              return (CGridCellBase*) &m_cellFixedRowDef;
00793     if (bFixedCol)              return (CGridCellBase*) &m_cellFixedColDef;
00794     return (CGridCellBase*) &m_cellDefault;
00795 }
00796 
00797 inline CGridCellBase* CGridCtrl::GetCell(int nRow, int nCol) const
00798 {
00799     if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) 
00800         return NULL;
00801 
00802     if (GetVirtualMode())
00803     {
00804         CGridCellBase* pCell = GetDefaultCell(nRow < m_nFixedRows, nCol < m_nFixedCols);
00805         static GV_DISPINFO gvdi;
00806         gvdi.item.row     = nRow;
00807         gvdi.item.col     = nCol;
00808         gvdi.item.mask    = 0xFFFFFFFF;
00809         gvdi.item.nState  = 0;
00810         gvdi.item.nFormat = pCell->GetFormat();
00811         gvdi.item.iImage  = pCell->GetImage();
00812         gvdi.item.crBkClr = pCell->GetBackClr();
00813         gvdi.item.crFgClr = pCell->GetTextClr();
00814         gvdi.item.lParam  = pCell->GetData();
00815         memcpy(&gvdi.item.lfFont, pCell->GetFont(), sizeof(LOGFONT));
00816         gvdi.item.nMargin = pCell->GetMargin();
00817         gvdi.item.strText.Empty();
00818 
00819         // Fix the state bits
00820         if (IsCellSelected(nRow, nCol))   gvdi.item.nState |= GVIS_SELECTED;
00821         if (nRow < GetFixedRowCount())    gvdi.item.nState |= (GVIS_FIXED | GVIS_FIXEDROW);
00822         if (nCol < GetFixedColumnCount()) gvdi.item.nState |= (GVIS_FIXED | GVIS_FIXEDCOL);
00823         if (GetFocusCell() == CCellID(nRow, nCol)) gvdi.item.nState |= GVIS_FOCUSED;
00824         
00825         if (m_pfnCallback)
00826             m_pfnCallback(&gvdi, m_lParam);
00827         else
00828             SendDisplayRequestToParent(&gvdi);
00829 
00830         static CGridCell cell;
00831         cell.SetState(gvdi.item.nState);
00832         cell.SetFormat(gvdi.item.nFormat);
00833         cell.SetImage(gvdi.item.iImage);
00834         cell.SetBackClr(gvdi.item.crBkClr);
00835         cell.SetTextClr(gvdi.item.crFgClr);
00836         cell.SetData(gvdi.item.lParam);
00837         cell.SetFont(&(gvdi.item.lfFont));
00838         cell.SetMargin(gvdi.item.nMargin);
00839         cell.SetText(gvdi.item.strText);
00840         cell.SetGrid((CGridCtrl*)this);
00841 
00842         return (CGridCellBase*) &cell;
00843     }
00844 
00845     GRID_ROW* pRow = m_RowData[nRow];
00846     if (!pRow) return NULL;
00847     return pRow->GetAt(nCol);
00848 }
00849 
00850 inline BOOL CGridCtrl::SetCell(int nRow, int nCol, CGridCellBase* pCell)
00851 {
00852     if (GetVirtualMode())
00853         return FALSE;
00854 
00855     if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) 
00856         return FALSE;
00857 
00858     GRID_ROW* pRow = m_RowData[nRow];
00859     if (!pRow) return FALSE;
00860 
00861     pCell->SetCoords( nRow, nCol); 
00862     pRow->SetAt(nCol, pCell);
00863 
00864     return TRUE;
00865 }
00866 
00868 
00869 //{{AFX_INSERT_LOCATION}}
00870 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
00871 
00872 #endif // !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)

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