src/grid.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006 by Kirill Kolodyazhniy.
00003 * See the file "license.terms" for information on usage and redistribution
00004 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00005 */
00006 
00007 #ifndef M_GRID_H
00008 #define M_GRID_H
00009 
00010 namespace MWidgets
00011 {
00012 
00014         enum TextAlign
00015         {
00016                 ALIGN_LEFT,  
00017                 ALIGN_RIGHT, 
00018                 ALIGN_CENTER 
00019         };
00020         
00021         class Grid;
00023         class Cell
00024         {
00025         protected:
00026                 friend class Grid;
00027                 bool m_bBCChanged;
00028         public:
00029                 string text;
00030 
00031                 void* pData;
00032 
00033                 DWORD forecolor;
00034 
00035                 DWORD backcolor;
00036 
00039                 Cell();
00040         };
00041 
00042 
00044         class Grid:public Widget
00045         {
00046         protected:
00047                 typedef vector<Cell> CellArray; 
00048                 HWND m_hWndEdit; 
00049                 WNDPROC m_EditWndProc; 
00050                 HCURSOR m_hVertSizeCur; 
00051                 HCURSOR m_hHorzSizeCur; 
00052                 HCURSOR m_hMovingCur; 
00053                 HCURSOR m_hCrossCur; 
00054                 HCURSOR m_hArrowCur; 
00055                 //table
00056                 int m_nFixedColCount; 
00057                 int m_nFixedRowCount; 
00058                 vector<CellArray> m_vecTable; 
00059                 vector<int> m_vecColsWidths; 
00060                 vector<int> m_vecRowsHeights; 
00061                 HFONT m_hFont; 
00062                 TextAlign m_TextAlign; 
00063                 int m_iLeftMargin; 
00064                 int m_iTopMargin; 
00065                 int m_iRightMargin; 
00066                 int m_iBottomMargin; 
00067                 int m_iDefColWidth; 
00068                 int m_iDefRowHeight; 
00069                 bool m_bEditingMode; 
00070                 bool m_bSelectionMode; 
00071                 bool m_bColSeletion; 
00072                 bool m_bRowSeletion; 
00073 
00074                 //resising cols/rows
00075                 bool m_bOnResizeArea; 
00076                 bool m_bResizeMode; 
00077                 int  m_iResizeRow; 
00078                 int  m_iResizeCol; 
00079                 int  m_iPrevResizeVal; 
00080                 //moving cols/rows
00081                 bool m_bColRowOnMoveArea; 
00082                 bool m_bRowMovingMode; 
00083                 bool m_bColMovingMode; 
00084                 HRGN m_regColMoving; 
00085                 HRGN m_regRowMoving; 
00086                 //moving/copieng cells
00087                 bool m_bCellOnMoveArea; 
00088                 bool m_bCellOnCopiengArea; 
00089                 bool m_bCellMovingMode; 
00090                 bool m_bCellCopiengMode; 
00091                 HRGN m_regCellMoving; 
00092                 HRGN m_regCellCopieng; 
00093 
00094 
00095                 //cell
00096                 int m_iCurRow; 
00097                 int m_iCurCol; 
00098 
00099                 int m_iSelRow; 
00100                 int m_iSelCol; 
00101 
00102                 //drawing
00103                 DWORD m_dwSelctionOP; 
00104                 HBRUSH m_hSelectionBrush; 
00105                 HPEN m_hBlackPen3; 
00106                 HPEN m_hBlackPen2; 
00107                 HPEN m_hBlackPen1; 
00108                 HPEN m_hWhitePen; 
00109                 int m_iBroderWidth; 
00110                 COLORREF m_dwDefFixedCellColor; 
00111                 COLORREF m_dwDefCellColor; 
00112                 int m_iFixedColWidth; 
00113                 int m_iFixedRowHeight; 
00114                 int m_iTableWidth; 
00115                 int m_iTableHeight; 
00116 
00117                 //scroll
00118                 int m_iMinVisRow; 
00119                 int m_iMaxVisRow; 
00120                 int m_iMinVisCol; 
00121                 int m_iMaxVisCol; 
00122 
00123                 //Sorting
00124                 std::string m_sMinStr;
00125                 std::string m_sMaxStr;
00126         protected:
00130                 void Draw();
00138                 void DrawFixed(HDC hdc,RECT* cellRect,int r,int c,int w,int h);
00146                 void DrawNormal(HDC hdc,RECT* cellRect,int r,int c,int w,int h);
00150                 void ShowCellEdit(bool replace,string str="");
00152                 void HideCellEdit();
00157                 void RecalculateVisibles(int w=-1,int h=-1);
00161                 void TestColRowResizing(int x,int y);
00164                 void ResizeRow(int newPos);
00167                 void ResizeCol(int newPos);
00171                 void TestColRowMoving(int xPos,int yPos);
00175                 void TestCellMovingCopieng(int xPos,int yPos);
00181                 void GetFixedCellByPoint(int x, int y,int* row,int* col);       
00182 
00184                 static LRESULT CALLBACK EditWindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00186                 LRESULT CALLBACK EditOnMessage (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00187 
00188         protected:
00190                 virtual LRESULT OnMessage (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00191         public:
00193                 Grid();
00195                 ~Grid();
00202                 virtual void Create(Widget *parent,int x,int y,int w,int h);
00204                 virtual WIDGET_TYPE GetType();
00209                 void SetSize(int rows,int cols);
00212                 void SetFixedRowCount(int val);
00215                 void SetFixedColCount(int val);
00223                 void SetFont(string name,int size,bool bold,bool italic,bool underline);
00227                 void SetTextAlign(TextAlign align);
00231                 void SetRowHeight(int index,int h);
00235                 void SetColWidth(int index,int w);
00241                 void SetTextMargins(int l,int t,int r,int b);
00246                 void SetItemText(int row,int col,string text);
00251                 string GetItemText(int row,int col);
00256                 void SetItemData(int row,int col,void* data);
00261                 void SetItemForeColor(int row,int col,DWORD color);
00266                 void SetItemBackColor(int row,int col,DWORD color);
00269                 void SetDefColWidth(int w);
00272                 void SetDefRowHeight(int h);
00275                 void SetDefCellColor(DWORD color);
00278                 void SetDefFixedCellColor(DWORD color);
00281                 int  GetFocusCellRow();
00284                 int  GetFocusCellCol();
00287                 void Refresh(bool bRecalculateVisibles=false);
00293                 void GetCellByPoint(int x, int y,int* row,int* col);
00298                 void GetCellRect(int row,int col,LPRECT pRect);
00304                 virtual void OnSize(int left,int top,int right,int bottom);
00306                 void ResizeToMinSize();
00308                 void ResizeToMaxSize();
00310                 void ResizeToAlignCol();
00314                 void EnsureVisible(int row,int col);
00315         };
00316 };
00317 
00318 #endif

Generated on Thu Oct 26 13:47:45 2006 for MWidgets by  doxygen 1.4.7