Esempio n. 1
0
/***************************************************
OnMouseMove - overloaded CUGCellType::OnMouseMove
	
    **See CUGCellType::OnMouseMove for more details
	about this function
****************************************************/
BOOL CUGNoteType::OnMouseMove(int col,long row,POINT *point,UINT nFlags){

	UNREFERENCED_PARAMETER(nFlags);
	
	RECT rect;
	m_ctrl->GetCellRect(col,row,&rect);

	if(point->x > rect.left && point->x < rect.right && point->y > rect.top && point->y < rect.bottom){
		if(m_noteWnd.IsWindowVisible() == FALSE ){

			//set the position of the note window
			RECT gridRect;
			m_ctrl->m_CUGGrid->GetClientRect(&gridRect);

			// show the note window to the right to the cell
			rect.left = rect.right + OFSET_HORIZ;
			rect.right = rect.left + m_nNoteWidth;

			if ( rect.top > OFSET_VERT )
				rect.top = rect.top - OFSET_VERT;
			rect.bottom = rect.top + m_nNoteHeight;

			CUGCell cell;
			m_ctrl->GetCell(col,row,&cell);

			m_noteWnd.SetWindowPos(&CWnd::wndTop,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
			m_noteWnd.MoveWindow(&rect);
			m_noteWnd.SetWindowText(cell.GetLabelText());
			m_noteWnd.ShowWindow(SW_SHOW);

			m_ctrl->GetCellRect(col,row,&m_noteCellRect);
			m_ctrl->m_CUGGrid->ClientToScreen(m_noteCellRect);

			if(m_timerID != 0)
				KillTimer(m_ctrl->m_hWnd,m_timerID);
			m_timerID = SetTimer(m_noteWnd.m_hWnd,100,200,TimerProc);
		}
		else if(m_timerID == 0){
			m_noteWnd.ShowWindow(SW_HIDE);
		}
	}
	else{
		m_noteWnd.ShowWindow(SW_HIDE);
		KillTimer(m_ctrl->m_hWnd,m_timerID);
	}
	
	return FALSE;
}
Esempio n. 2
0
/***************************************************
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;
}