/*************************************************** OnLClicked - overloaded CUGCellType::OnLClicked Allows the progress bars value to be set interactivly if SetCanAdjust() is set to TRUE. **See CUGCellType::OnLClicked for more details about this function ****************************************************/ BOOL CUGAdvProgressType::OnLClicked(int col, long row, int updn, RECT *rect, POINT *point){ if (!m_canAdjust) return UG_SUCCESS; int ref = 0, span = 0; CUGCell mycell; float ftemp; if (updn==1){ m_ctrl->GetCell(col, row, &mycell); switch(m_direction){ case UGCT_PROGRESS_LEFT: ref = point->x - rect->left; span = rect->right - rect->left; break; case UGCT_PROGRESS_TOP: ref = point->y - rect->top; span = rect->bottom - rect->top; break; case UGCT_PROGRESS_RIGHT: ref = point->x - rect->right; span = rect->left - rect->right; break; case UGCT_PROGRESS_BOTTOM: ref = point->y - rect->bottom; span = rect->top - rect->bottom; break; } ftemp = ((float)ref / (float)span) * 100; if (ftemp>98) ftemp=(float)100; if (ftemp<2) ftemp=(float)0; mycell.SetNumber(ftemp); m_ctrl->SetCell(col, row, &mycell); m_lbuttondown = TRUE; m_row = row; m_col = col; CopyRect(&m_rect,rect); m_ctrl->RedrawCell(col, row); return TRUE; } else { // the mouse button was released m_lbuttondown = FALSE; } return FALSE; }
int CDDBaseGrid::QuickSetNumber(int col, long row, int number) { // The standard set number takes double args, and one can set number of // decimal places. This convenience func just puts them together in one place. CUGCell cell; this->GetCell(col, row, &cell); cell.SetPropertyFlags( cell.GetPropertyFlags() | UGCELL_DONOT_LOCALIZE ); cell.SetNumber( (double)number ); cell.SetNumberDecimals( 0 ); cell.SetTextColor(colorBlack); this->SetCell(col, row, &cell); return UG_SUCCESS; }
int CDDBaseGrid::QuickSetNumber(int col, long row, double number, int decimals) { // This convenience func lets us set the cell value and number of decimal // places to display, in one call. if (decimals < 0 || decimals > 20 /*arbitrary*/) decimals = 3; // also arbitrary CUGCell cell; this->GetCell(col, row, &cell); cell.SetPropertyFlags( cell.GetPropertyFlags() | UGCELL_DONOT_LOCALIZE ); // stop turning period into comma for decimal pt in Gemany cell.SetNumber( number ); cell.SetNumberDecimals( decimals ); cell.SetTextColor(colorBlack); this->SetCell(col, row, &cell); return UG_SUCCESS; }
/*************************************************** OnMouseMove - overloaded CUGCellType::OnMouseMove If the slider update state has been activated with during OnLClicked. Then this function tracks the position of the mouse and updates the cells value according to the mouses position along the slider (0-100 percent). As the value changes the slider is redrawn. **See CUGCellType::OnMouseMove for more details about this function ****************************************************/ BOOL CUGSliderType::OnMouseMove(int col,long row,POINT *point,UINT flags){ if((flags& MK_LBUTTON)== FALSE){ return FALSE; } if(m_updateSlider){ RECT rect; m_ctrl->GetCellRect(col,row,&rect); long mouseX = point->x - rect.left - 3; if(mouseX < 0) mouseX = 0; long width = rect.right - rect.left - 6; long percent = (mouseX*100)/width; if(percent < 0) percent = 0; if(percent > 100) percent = 100; CUGCell cell; m_ctrl->GetCellIndirect(col,row,&cell); if ( cell.GetReadOnly() == TRUE ) return FALSE; if(percent != (long)cell.GetNumber()) { cell.SetNumber(percent); m_ctrl->SetCell(col,row,&cell); m_ctrl->RedrawCell(col,row); OnCellTypeNotify(m_ID, col, row, UGCT_SLIDER_MOVED, percent); } return TRUE; } return FALSE; }
/*************************************************** OnSetup This function is called just after the grid window is created or attached to a dialog item. It can be used to initially setup the grid ****************************************************/ void MyCug::OnSetup(){ // initailize local vatiables int rows = 24; int cols = 14; int i,j; CString tmpNum; CUGCell cell; // setup rows and columns SetNumberRows(rows); SetNumberCols(cols); // fill-in cells with numbers // limit number of decimal places to 0 GetCell (0,0,&cell); cell.SetNumberDecimals(0); cell.SetAlignment (UG_ALIGNRIGHT); for (i = 0; i < cols; i++) for (j = 0; j < rows; j++) { cell.SetNumber(rand()%1000); SetCell (i,j,&cell); } GetColDefault (10,&cell); m_pen.CreatePen (PS_SOLID,1,RGB(255,0,0)); cell.SetBorderColor (&m_pen); cell.SetBorder (UG_BDR_LTHIN); SetColDefault (10,&cell); // create 3 column side heading SetSH_NumberCols(2); // ensure that side heading is large enough to fit 3 cols SetSH_Width(80); SetSH_ColWidth(-1,30); // resize columns in the side heading SetSH_ColWidth(-2,50); // create 3 row top heading SetTH_NumberRows(3); // ensure that top heading is large enough to fit 3 rows SetTH_Height(60); SetTH_RowHeight(-1,20); // resize rows in the top heading SetTH_RowHeight(-2,20); SetTH_RowHeight(-3,20); // join cells and assign text values in the top headings JoinCells (0,-3,9,-3); JoinCells (10,-3,13,-3); QuickSetText (0,-3,"Week-days"); QuickSetTextColor (10,-3,RGB(255,0,10)); QuickSetText (10,-3,"Week-end"); for (i=0;i<cols;i+=2){ JoinCells (i,-2,i+1,-2); if (i >= 10){ QuickSetTextColor (i,-1,RGB(255,0,10)); QuickSetTextColor (i+1,-1,RGB(255,0,10)); QuickSetTextColor (i,-2,RGB(255,0,10)); } QuickSetText (i,-1,"Sched."); QuickSetText (i+1,-1,"To Do"); } QuickSetText (0,-2,"Monday"); QuickSetText (2,-2,"Tuesday"); QuickSetText (4,-2,"Wednesday"); QuickSetText (6,-2,"Thursday"); QuickSetText (8,-2,"Friday"); QuickSetText (10,-2,"Satruday"); QuickSetText (12,-2,"Sunday"); // join cells and assign text in the side headings j = 8; for (i=0;i<rows;i+=2) { JoinCells (-2,i,-2,i+1); tmpNum.Format ("%d",j++); if (j < 13) tmpNum += " AM"; else tmpNum += " PM"; QuickSetText (-2,i,tmpNum); QuickSetText (-1,i,":00"); QuickSetText (-1,i+1,":30"); } }
/*************************************************** OnMouseMove - overloaded CUGCellType::OnMouseMove Allows the progress bars value to be set interactivly if SetCanAdjust() is set to TRUE. **See CUGCellType::OnMouseMove for more details about this function ****************************************************/ BOOL CUGAdvProgressType::OnMouseMove(int col,long row,POINT *point,UINT flags){ UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(row); if((flags&MK_LBUTTON) == FALSE) return FALSE; if (!m_canAdjust) return FALSE; int ref = 0, span = 0; float ftemp; CUGCell mycell; if (point->x>m_rect.right) point->x = m_rect.right; if (point->x<m_rect.left) point->x = m_rect.left; if (point->y>m_rect.bottom) point->y = m_rect.bottom; if (point->y<m_rect.top) point->y = m_rect.top; m_ctrl->GetCell(m_col, m_row, &mycell); switch(m_direction){ case UGCT_PROGRESS_LEFT: ref = point->x - m_rect.left; span = m_rect.right - m_rect.left; break; case UGCT_PROGRESS_TOP: ref = point->y - m_rect.top; span = m_rect.bottom - m_rect.top; break; case UGCT_PROGRESS_RIGHT: ref = point->x - m_rect.right; span = m_rect.left - m_rect.right; break; case UGCT_PROGRESS_BOTTOM: ref = point->y - m_rect.bottom; span = m_rect.top - m_rect.bottom; break; } ftemp = ((float)ref / (float)span) * 100; if((flags&MK_LBUTTON)){ // we are resizing the progress bar // find the new mouse position, and change the percent value in the // cell to reflect the mouse position mycell.SetNumber(ftemp); m_ctrl->SetCell(m_col, m_row, &mycell); m_ctrl->RedrawCell(m_col, m_row); } else { // we just moving over the resize area, not changing the progress bar // if the mouse pointer moves within 5 pixels of the current progress bar setting // then we should change the mouse pointer to double resize arrows. if (abs((int)ftemp - (int)mycell.GetNumber()) < 5){ if (m_direction == UGCT_PROGRESS_TOP || m_direction == UGCT_PROGRESS_BOTTOM){ // change the mouse pointer to double arrows left and right } else { // change the mouse pointer to double up and down arrows } }else{ } // change mouse pointer to normal } return TRUE; }