/*************************************************** OnLClicked - overloaded CUGCellType::OnLClicked When the mouse button is depressed, the button down variables are set. When the mouse button is released and the mouse was over the button then send a button click notification. Redraw the cell based on the state of the mouse button. **See CUGCellType::OnLClicked for more details about this function Return TRUE - since the mouse click was handled here ****************************************************/ BOOL CUGButtonType::OnLClicked(int col,long row,int updn,RECT *rect,POINT *point){ UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(point); if(updn){ if(OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONDOWN,0) != TRUE){ m_btnDown = FALSE; } m_btnDown = TRUE; m_btnDownCol = col; m_btnDownRow = row; CopyRect(&m_btnDownRect,rect); } else{ OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONUP,0); if(m_mode != UGCT_BUTTONTOGGLE){ if(m_btnDownCol == col && m_btnDownRow == row && m_btnDown == TRUE){ OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONCLICK,0); } } m_btnDown = FALSE; } m_ctrl->RedrawCell(col,row); return TRUE; }
/*************************************************** OnLClicked - overloaded CUGCellType::OnLClicked Checks to see if the spin button was clicked on. If so, then it checks to see if it was the up or down spin arrow. If the up arrow was clicked then a cell type event is fired: UGCT_SPINBUTTONUP If the down arrow was clicked then a cell type event is fired: UGCT_SPINBUTTONDOWN The value within the cell is not modified, this must be done during the cell type even. The reason for this is to allow the spin control work with any data type rather than just numbers. **See CUGCellType::OnLClicked for more details about this function ****************************************************/ BOOL CUGSpinButtonType::OnLClicked(int col,long row,int updn,RECT *rect,POINT *point){ if(updn){ if(point->x > (rect->right -btnWidth)){ //copy the droplist button co-ords CopyRect(&btnRect,rect); btnRect.left = rect->right - btnWidth; btnCol = col; btnRow = row; //check to see which button if(point->y < (rect->top +(rect->bottom - rect->top)/2)){ //Top button btnTopDown = TRUE; btnBottomDown = FALSE; btnTopBottom = 1; btnRect.bottom = (rect->top +(rect->bottom - rect->top)/2); //notify the user of the list, so it can be modified if needed OnCellTypeNotify(m_ID,btnCol,btnRow,UGCT_SPINBUTTONUP,0); } else{ //bottom button btnBottomDown = TRUE; btnTopDown = FALSE; btnTopBottom = 2; btnRect.top = (rect->top +(rect->bottom - rect->top)/2); //notify the user of the list, so it can be modified if needed OnCellTypeNotify(m_ID,btnCol,btnRow,UGCT_SPINBUTTONDOWN,0); } m_ctrl->RedrawCell(btnCol,btnRow); return TRUE; } } else if(btnTopDown || btnBottomDown){ btnTopDown = FALSE; btnBottomDown = FALSE; btnTopBottom = 0; m_ctrl->RedrawCell(col,row); return TRUE; } return FALSE; }
/*************************************************** OnCharDown - overloaded CUGCellType::OnCharDown This function is called when a cell of this type has focus and a printable key is pressed.(WM_CHARDOWN) If the user has pressed SPACE bar than the check box cell type will interpret it as if the user wanted to change the state of the check box. **See CUGCellType::OnCharDown for more details about this function Params: col - column that has focus row - row that has focus vcKey - pointer to the virtual key code, of the key that was pressed. Return: TRUE - if the event was processed FALSE - if the event was not ***************************************************/ BOOL CUGCheckBoxType::OnCharDown(int col,long row,UINT *vcKey) { m_ctrl->GetCellIndirect( col, row, &m_cell ); if( m_cell.IsPropertySet( UGCELL_CELLTYPEEX_SET )) { int style = m_cell.GetCellTypeEx(); if ((style & UGCT_CHECKBOXDISABLED) > 0) { return FALSE; } } if ( *vcKey == VK_SPACE && m_cell.GetReadOnly() == FALSE ) { int style = 0; if(m_cell.IsPropertySet(UGCELL_CELLTYPEEX_SET)) style = m_cell.GetCellTypeEx(); int val; val = (int)m_cell.GetNumber(); m_cell.SetNumber((val = (val + 1) % ((style & UGCT_CHECKBOX3STATE) ? 3 : 2))); m_ctrl->SetCell(col,row,&m_cell); m_ctrl->RedrawCell(col,row); //notify the user that the checkbox was checked OnCellTypeNotify(m_ID,col,row,UGCT_CHECKBOXSET,(long)val); return TRUE; } return FALSE; }
/*************************************************** OnLClicked - overloaded CUGCellType::OnLClicked The handling of the OnLClicked event in the check box cell type is the most important for this cell type. Here is where the desired user actions are evaluated and if necessary the check state is updated. This function determines if the user clicked the left mouse button over the check area on the cell if he did, than the state of the check is changed. **See CUGCellType::OnLClicked for more details about this function Params: col - column that was clicked in row - row that was clicked in rect - rectangle of the cell that was clicked in point - point where the mouse was clicked Return: TRUE - if the event was processed FALSE - if the event was not ***************************************************/ BOOL CUGCheckBoxType::OnLClicked(int col,long row,int updn,RECT *rect,POINT *point) { int top, checkSize; CRect tempRect(0,0,0,0); m_ctrl->GetCellIndirect( col, row, &m_cell ); int style = 0; bool isDisabled = false; if( m_cell.IsPropertySet( UGCELL_CELLTYPEEX_SET )) { style = m_cell.GetCellTypeEx(); isDisabled = (style & UGCT_CHECKBOXDISABLED) > 0; } // If the cell is read only, user should not be // allowed to change the state of the check. if ( m_cell.GetReadOnly() || isDisabled) { return FALSE; } if( updn ) { // calculate height of the cell, based on // given rect parameter. checkSize = rect->bottom - rect->top - (UGCT_CHECKSIZE / 2); // the check box will never be smaller than // UGCT_CHECKSIZE if( checkSize > UGCT_CHECKSIZE ) checkSize = UGCT_CHECKSIZE; top = (rect->bottom - rect->top - checkSize) / 2; tempRect = *rect; AdjustRect ( &tempRect, m_cell.GetAlignment(), m_cell.GetCellTypeEx(), top, checkSize ); // determine if the user clicked within the check box area if(!tempRect.PtInRect ( *point )) return FALSE; int style = 0; if(m_cell.IsPropertySet(UGCELL_CELLTYPEEX_SET)) style = m_cell.GetCellTypeEx(); int val; val = (int)m_cell.GetNumber(); m_cell.SetNumber((val + 1) % ((style & UGCT_CHECKBOX3STATE) ? 3 : 2)); // set the new check state to the data source m_ctrl->SetCell(col,row,&m_cell); // notify the CUGCtrl derived class that the check state was changed OnCellTypeNotify(m_ID,col,row,UGCT_CHECKBOXSET,(long)m_cell.GetNumber()); // redraw the cell to reflect the changes. m_ctrl->RedrawCell(col,row); return TRUE; } return FALSE; }
/*************************************************** OnKeyDown - overloaded CUGCellType::OnKeyDown If the enter (return) key was pressed then this function will send a button click notification. Otherwise it will just return. **See CUGCellType::OnKeyDown for more details about this function Return TRUE - if the notification was processed FALSE - if the notification was not processed ****************************************************/ BOOL CUGButtonType::OnKeyDown(int col,long row,UINT *vcKey){ UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(row); if(*vcKey == VK_RETURN){ OnCellTypeNotify(m_ID,m_ctrl->m_GI->m_currentCol, m_ctrl->m_GI->m_currentRow,UGCT_BUTTONCLICK,0); return TRUE; } return FALSE; }
/*************************************************** 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; }
/*************************************************** StartDropList This internal function is used to parse out the label string, which contains the items to show in the list. Also this function will show the list box in the proper location on the screen. Params: <none> Return: UG_ERROR - the list is already visible. UG_SUCCESS - everything went smoothly, the drop list was shown ***************************************************/ int CUGDropListType::StartDropList() { RECT rect; RECT clientRect; int dif,len,pos,startpos; CFont * font = NULL; LOGFONT lf; CFont * cfont; CStringList list; //lists of strings for the list are assembed here CString * items; //points to the string used to assemble the list //return false if it is already up if( m_listBox->m_HasFocus) return UG_ERROR; CUGCell cell; m_ctrl->GetCellIndirect(m_btnCol,m_btnRow,&cell); // make sure that the read only cells do not show droplist if ( cell.GetReadOnly() == TRUE ) return UG_SUCCESS; //get the current row and col m_btnCol = m_ctrl->GetCurrentCol(); m_btnRow = m_ctrl->GetCurrentRow(); //add the strings to the CStringList CString string; cell.GetLabelText(&string); items = &string; len = items->GetLength(); pos =0; startpos =0; while(pos <len){ if(items->GetAt(pos)== _T('\n')){ list.AddTail(items->Mid(startpos,pos-startpos)); startpos = pos+1; } pos++; } //notify the user of the list, so it can be modified if needed if ( OnCellTypeNotify(m_ID,m_btnCol,m_btnRow,UGCT_DROPLISTSTART,(LONG_PTR)&list) == FALSE ) // if FALSE was returned from OnCellTypeNotify call, than the developer does not // wish to show the drop list at the moment. return UG_ERROR; // set default font height lf.lfHeight = 12; //get the font if(cell.IsPropertySet(UGCELL_FONT_SET)) font = cell.GetFont(); else if(m_ctrl->m_GI->m_defFont != NULL) font = m_ctrl->m_GI->m_defFont; if(font == NULL) font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FONT)); if(font != NULL) { //find the height of the font cfont = font; cfont->GetLogFont(&lf); // lf.lfHeight if( lf.lfHeight < 0 ){ HDC hDC = CreateCompatibleDC(NULL); lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hDC, LOGPIXELSY), 72); DeleteDC(hDC); } } //get the rectangle for the listbox m_ctrl->GetCellRect(m_btnCol,m_btnRow,&rect); rect.top = rect.bottom; rect.left+=10; rect.right+=10; len = (int)list.GetCount(); if(len >15) len = 15; rect.bottom += lf.lfHeight * len + 6; m_ctrl->m_CUGGrid->GetClientRect(&clientRect); if(rect.bottom > clientRect.bottom){ dif = rect.bottom - clientRect.bottom; rect.bottom -= dif; rect.top -= dif; if(rect.top <0) rect.top = 0; } if(rect.right > clientRect.right){ dif = rect.right - clientRect.right; rect.right -= dif; rect.left -= dif; if(rect.left <0) rect.left = 0; } //create the CListBox m_listBox->m_ctrl = m_ctrl; m_listBox->m_cellType = this; m_listBox->m_cellTypeId = m_ID; m_listBox->Create(WS_CHILD|WS_BORDER|WS_VSCROLL,rect,m_ctrl->m_CUGGrid,123); //set up the font if(font != NULL) m_listBox->SetFont(font); // v7.2 - update 03 - this works to eliminate blank lines that // can occur with odd sized fonts/number of items. Fix courtesy Gerbrand // .start int itHeight = m_listBox->GetItemHeight(0); if (len > 15) len = 15; rect.bottom = rect.top + len * itHeight + 6; if(rect.bottom > clientRect.bottom){ dif = rect.bottom - clientRect.bottom; rect.bottom -= dif; rect.top -= dif; if(rect.top <0) rect.top = 0; } // v7.2 - update 03 - Adjust the rect width to accomodate the largest string // Allen Shiels dif = GetMaxStringWidth(list) - (rect.right-rect.left); if (dif > 0) { if (len >= 15) // add a scroll bar width if max items in list dif += GetSystemMetrics(SM_CXVSCROLL); rect.right += dif; } if(rect.right > clientRect.right){ dif = rect.right - clientRect.right; rect.right -= dif; rect.left -= dif; if(rect.left <0) rect.left = 0; } // .end //resize the window again since a new font is being used m_listBox->MoveWindow(&rect,FALSE); //add the items to the list len = (int)list.GetCount(); POSITION position = list.GetHeadPosition(); pos =0; while(pos < len){ m_listBox->AddString(list.GetAt(position)); pos++; if(pos < len) list.GetNext(position); } //give the list box pointers to the cell m_listBox->m_col = &m_btnCol; m_listBox->m_row = &m_btnRow; m_listBox->ShowWindow(SW_SHOW); m_listBox->SetFocus(); m_btnDown = FALSE; m_ctrl->RedrawCell(m_btnCol,m_btnRow); return UG_SUCCESS; }