// Copyright (c) Sean Walton 1999-2006 All rights reserved // // Standard disclaimer: you use it --> you're responsible // Standard license: you can use it in any way, but keep // my copyright attached. /////////////////////////////////////////////////////////////////////////////////////// /// Grid Grid::Grid(unsigned char nrows, unsigned char width) : Field(), rows(nrows), cellwidth(width) { // cellwidth = CELLWIDTH; Clear(); } void Grid::Paint(Graphics& g) { int height = CELLHEIGHT; for ( int r = 0; r < rows; r++ ) for ( int c = 0; c < MAXCOLS; c++ ) if ( tab[r][c][0] != 0 ) g.DrawString(c*cellwidth+1, r*height, tab[r][c], strlen(tab[r][c]), GetFont(), 0); g.Invert(XYRect(0, 0, GetWidth(), height)); } int Grid::OnScroll(int axis, int directionMagnitude) { int retval=0; selected += directionMagnitude; if ( axis == 1 ) // X axis { if ( selectBy != eColumn ) { selectBy = eColumn; selected = 0; } if ( selected >= MAXCOLS ) { retval = 1; selected = MAXCOLS-1; } } else if ( axis == 2 ) // Y axis { if ( selectBy != eRow ) { selectBy = eRow; selected = 1; } else if ( selected == 0 ) selected += directionMagnitude; if ( selected >= rows ) { retval = 1; selected = rows-1; } } if ( selected < 0 ) { retval = -1; selected = 0; } return retval; } XYRect Grid::GetFocusRect(void) const { int height = CELLHEIGHT; switch ( selectBy ) { case eRow: if ( selected < rows ) return XYRect(0, selected*height, GetWidth(), height); break; case eColumn: if ( selected < MAXCOLS ) return XYRect(selected*cellwidth, height, cellwidth, GetHeight()); break; case eCell: int r = selected/MAXCOLS; int c = selected%MAXCOLS; return XYRect(c*cellwidth, r*height, cellwidth, height); } char temps[20]; RimSprintf(temps, sizeof(temps), "selected=%d", selected); Status status(temps); return XYRect(-1, -1, 0, 0); } void Grid::Clear(void) { selected = 1; selectBy = eRow; memset(&tab, 0, sizeof(tab)); SetCell(0, 0, "POWER"); SetCell(0, 2, "BID"); SetCell(0, 3, "ASK"); SetCell(0, 4, "LAST"); SetCell(0, 5, "CHNG"); } void Grid::SetCell(int row, int col, char *str) { strncpy(tab[row][col], str, MAXCHARS); tab[row][col][MAXCHARS-1] = 0; }