00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSGRID_H__
00021 #define __CS_CSGRID_H__
00022
00031 #include "csws/csscrbar.h"
00032 #include "csutil/csvector.h"
00033 #include "csutil/csstring.h"
00034
00047 typedef bool (*csRegionTreeFunc) (void* node, void* databag);
00048
00049 class csRegionTree2D;
00050 class csSparseGrid;
00051 class csGridCell;
00052 class csGridView;
00053 class csGrid;
00054 class csSplitter;
00055
00056 class csRegionTree2D
00057 {
00058 public:
00059 csRect region;
00060 csRegionTree2D *children[5];
00061 void* data;
00062
00063 public:
00065 csRegionTree2D ();
00067 csRegionTree2D (csRect area, void* data);
00069 ~csRegionTree2D ();
00070
00074 void Insert (csRect &area, void* data);
00075
00079 void FindRegion (const csRect &area, csVector &vLeafList);
00080
00084 void Traverse (csRegionTreeFunc userFunc, void* databag = NULL);
00085
00086 };
00087
00092 class csSparseGrid
00093 {
00094 friend class csGrid;
00095
00096
00097
00098 struct csGridRowEntry
00099 {
00100 int col;
00101 void* data;
00102
00103 csGridRowEntry (int theCol, void* theData) : col (theCol), data (theData) {}
00104 };
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 class csGridRow : public csVector
00115 {
00116 int col;
00117 public:
00118
00119 csGridRow (int theCol);
00120
00121 virtual ~csGridRow ();
00122
00123 void SetAt (int col, void* data);
00124
00125 csGridRowEntry *Get (int index);
00126
00127 virtual int Compare (void* Item1, void* Item2, int Mode) const;
00128
00129 virtual int CompareKey (void* Item1, const void* Key, int Mode) const;
00130
00131 virtual bool FreeItem (void* Item);
00132 };
00133 friend class csSparseGrid::csGridRow;
00134
00135
00136
00137
00138
00139 class csGridRowSet : public csGridRow
00140 {
00141 public:
00142
00143 csGridRowSet (int theRow) : csGridRow (theRow) {}
00144
00145 virtual ~csGridRowSet () {DeleteAll ();}
00146
00147 virtual bool FreeItem (void* Item)
00148 {
00149
00150
00151
00152
00153 delete (csGridRowEntry *)Item;
00154 return true;
00155 }
00156 };
00157
00158
00159 csGridRowSet rows;
00160
00161 public:
00163 csSparseGrid () : rows (8) {}
00164
00166 void* GetAt (int row, int col)
00167 {
00168 void* result = NULL;
00169 int idx1 = rows.FindSortedKey ((const void*)row);
00170 if (idx1 != -1)
00171 {
00172 int idx2 = ((csGridRow *)rows.Get (idx1)->data)->FindSortedKey ((const
00173 void*)col);
00174 if (idx2 != -1)
00175 result = ((csGridRow *)rows.Get (idx1)->data)->Get (idx2)->data;
00176 }
00177 return result;
00178 }
00179
00180
00181 void SetAt (int row, int col, void* data)
00182 {
00183 int idx = rows.FindSortedKey ((const void*)row);
00184 if (idx == -1)
00185 idx = rows.InsertSorted (new csGridRowEntry (row, new csGridRow (row)));
00186 ((csGridRow *)rows.Get (idx)->data)->SetAt (col, data);
00187 }
00188 };
00189
00193 enum csGridCellBorderStyle
00194 {
00196 gcbsNone = 0,
00198 gcbsDash,
00200 gcbsDashPoint,
00202 gcbsDashPointPoint,
00204 gcbsDashDashPoint,
00206 gcbsLine
00207 };
00208
00210 #define CSS_GRIDCELL_SELECTED 0x00010000
00211
00217 class csGridCell : public csComponent
00218 {
00220 class csCellBorder
00221 {
00222 public:
00224 csGridCellBorderStyle style;
00226 int thick;
00228 csCellBorder () : style (gcbsLine), thick (1) {}
00229 };
00230
00232 bool inUse;
00233
00234 public:
00236 csCellBorder upper, lower, left, right;
00238 int row, col;
00240 void* data;
00242 csString valuePattern;
00243
00245 csGridCell ();
00247 virtual void Draw ();
00249 bool IsUsed () { return inUse; }
00251 void SetUsed (bool iState = true) { inUse = iState; }
00252
00253 protected:
00255 void DrawLine (int x1, int y1, int x2, int y2, csCellBorder &border);
00256 };
00257
00258
00262
00263 #define CSGVS_HSCROLL 0x00000001
00264
00265 #define CSGVS_VSCROLL 0x00000002
00266
00267 #define CSGVS_DEFAULTVALUE (CSGVS_HSCROLL | CSGVS_VSCROLL)
00268
00276 class csGridView : public csComponent
00277 {
00278 protected:
00280 csRect area;
00282 csGrid *pGrid;
00284 int row, col;
00286 bool fPlaceItems;
00288 int Style;
00290 csScrollBar *hscroll, *vscroll;
00291
00293 void CooAt (int theX, int theY, int &theRow, int &theCol);
00294
00295 public:
00301 float areafactor;
00302
00304 csGridView (csGrid *pParent, const csRect ®ion,
00305 int iStyle = CSGVS_DEFAULTVALUE);
00307 csGridView (const csGridView &view, int iStyle = -1);
00308
00310 virtual void Draw ();
00312 virtual bool HandleEvent (iEvent& Event);
00314 virtual bool SetRect (int xmin, int ymin, int xmax, int ymax);
00316 const csRect& GetArea (){return area;}
00318 virtual void FixSize (int &newW, int &newH);
00320 virtual void SuggestSize (int &w, int &h);
00321
00326 csGridView *SplitX (int x, int iStyle = -1);
00331 csGridView *SplitY (int y, int iStyle = -1);
00332
00336 void SetViewArea (const csRect& rc)
00337 {
00338 area.Set (rc.xmin, rc.ymin, rc.xmax, rc.ymax);
00339 col = area.xmin; row = area.ymin;
00340 }
00341
00342 protected:
00346 virtual csGridView *CreateCopy (int iStyle);
00350 void PlaceItems ();
00351 };
00352
00360
00361 #define CSGS_HSPLIT 0x00000004
00362
00363 #define CSGS_VSPLIT 0x00000008
00364
00365 #define CSGS_DEFAULTVALUE (CSGS_HSPLIT | CSGS_VSPLIT)
00366
00368 #define CSGCS_NONE 1
00369
00370 #define CSGCS_CELL 2
00371
00372 #define CSGCS_ROW 3
00373
00374 #define CSGCS_COLUMN 4
00375
00377
00378 enum
00379 {
00384 cscmdGridCursorChanged = 0x00000F00
00385 };
00386
00394 class csGrid : public csComponent
00395 {
00396 protected:
00397 friend class csGridView;
00399 csRegionTree2D *regions, *viewlayout;
00401 csSparseGrid *grid;
00403 csVector vViews;
00405 csGridView *activeView;
00407 csVector vRegionStyles;
00409 csSplitter *splitterX, *splitterY;
00411 int cursorStyle;
00413 int xcur, ycur;
00414
00416 void CalcMinimalSize (csRegionTree2D *node, int &w, int &h);
00418 void PlaceGadgets ();
00419
00420 private:
00422 void init (csComponent *pParent, csRect &rc, int iStyle, csGridCell *gc);
00423
00424 public:
00426 csGrid (csComponent *pParent, int nRows, int nCols,
00427 int iStyle = CSGS_DEFAULTVALUE | CSGVS_DEFAULTVALUE);
00429 csGrid (csComponent *pParent, int nRows, int nCols, csGridCell *gridpattern,
00430 int iStyle = CSGS_DEFAULTVALUE | CSGVS_DEFAULTVALUE);
00432 virtual ~csGrid ();
00433
00435 virtual void SetCursorStyle (int iCursorStyle = CSGCS_NONE);
00437 virtual int GetCursorStyle ();
00439 virtual void GetCursorPos (int &row, int &col);
00441 virtual void SetCursorPos (int row, int col);
00442
00444 virtual void Draw ();
00446 virtual bool SetRect (int xmin, int ymin, int xmax, int ymax);
00448 virtual void FixSize (int &newW, int &newH);
00450 virtual void SuggestSize (int &w, int &h);
00452 virtual bool HandleEvent (iEvent &Event);
00453
00455 void CreateRegion (csRect& rc, csGridCell *cell);
00457 csGridView* GetRootView ()
00458 { return (csGridView*)vViews.Get (0); }
00460 csGridView *GetActiveView () {return activeView;}
00462 void SetActiveView (csGridView *view);
00463
00467 virtual void SetStringAt (int row, int col, const char *data);
00468 csString *GetStringAt (int row, int col);
00469 };
00470
00473 #endif // __CS_CSGRID_H__