示例#1
0
BOOL CListBoxEx::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	if(zDelta > 0)
	{
		SetTopIndex(GetTopIndex()-1);
		m_pwndSBV->SetScrollPos(GetTopIndex()-1);
	}
	else
	{
		SetTopIndex(GetTopIndex()+1);
		m_pwndSBV->SetScrollPos(GetTopIndex()+1);
	}

	return CListBox::OnMouseWheel(nFlags, zDelta, pt);
}
BOOL CDomainListBox::SelectShortname( int nStart, CString strText )
{
	SelectItem( -1, FALSE );

	strText.MakeUpper();
	int	nLen	=	strText.GetLength();
	if( nLen <= 0 )
		return FALSE;

	CString	rString;
	int	nPos	=	nStart;
	for( int i=0; i<GetCount(); i++ )
	{
		if( nPos == GetCount() || nPos < 0 )
			nPos	=	0;

		GetText( nPos, rString );
		rString.MakeUpper();
		int	nIndex	=	rString.Find( '(' );
		if( -1 != nIndex )
		{
			rString	=	rString.Mid( nIndex+1 );
			if( 0 == strncmp( rString, strText, min(nLen,rString.GetLength()) ) )
			{
				SelectItem( i, TRUE );
				SetTopIndex( i > 6 ? i-6 : 0 );
				return TRUE;
			}
		}

		nPos	++;
	}
	return FALSE;
}
示例#3
0
int CLogListBox::AddString(LogMsgType Type, const CString& strTitle, const CString& strText, const CString& szInfo)
{
	LogListBoxItem * item = new  LogListBoxItem;
	item->Type = Type;

	SYSTEMTIME st;
	::GetLocalTime(&st);
	CString Data;
	Data.Format(_T("%02d:%02d:%02d"), (int)st.wHour, (int)st.wMinute, (int)st.wSecond);
	
	item->strText = trim(strText);
	item->strTitle = trim(strTitle);
	item->Info = trim(szInfo);
	item->Time = Data;

	SetRedraw(FALSE);
	int nPos = CListBox::AddString((LPCTSTR)item);

   if(nPos < 0) return -1;

   SetItemDataPtr(nPos, item);
	SetTopIndex(nPos-1);
	SetCurSel(nPos);
	SetRedraw(TRUE);
	return nPos;
}
BOOL CDomainListBox::SelectCode( int nStart, CString strText )
{
	SelectItem( -1, FALSE );

	int	nLen	=	strText.GetLength();
	if( nLen <= 0 )
		return FALSE;

	CString	rString;
	int	nPos	=	nStart;
	for( int i=0; i<GetCount(); i++ )
	{
		if( nPos >= GetCount() || nPos < 0 )
			nPos	=	0;

		GetText( nPos, rString );
		if( 0 == strncmp( rString, strText, min(nLen,rString.GetLength()) ) )
		{
			SelectItem( i, TRUE );
			SetTopIndex( i > 6 ? i-6 : 0 );
			return TRUE;
		}

		nPos	++;
	}
	return FALSE;
}
BOOL CDomainListBox::SelectAndShowItem( int nSel )
{
	int	nPageCount	=	GetCountPerPage( );

	SelectItem( nSel, TRUE );
	int nTopIndex = GetTopIndex();
	if( LB_ERR != nTopIndex && nTopIndex+nPageCount<nSel )
		SetTopIndex( nSel-nPageCount );
	return TRUE;
}
示例#6
0
//
/// Refresh the window.
//
void
TCheckList::Update()
{
  int topIndex = GetTopIndex();
  int selIndex = GetSelIndex();
  SendMessage(WM_SETREDRAW, false);
  Invalidate();
  SetTopIndex(topIndex);
  if (selIndex != LB_ERR)
    SetSelIndex(selIndex);
  SendMessage(WM_SETREDRAW, true);
}
示例#7
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
//
// Description:   Message handler for WM_HSCROLL
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* ) 
{
	int nScrollMin, nScrollMax ;
	int nOldPos = GetScrollPos( SB_HORZ ) ; 
	int nNewPos = nOldPos ;

	switch (nSBCode)
	{
	case SB_BOTTOM:
		nNewPos = m_nNumCols - 1 ;
		break ;

	case SB_LINEDOWN:
		nNewPos += 1 ;
		break ;
	
	case SB_LINEUP:
		nNewPos -= 1 ;
		break ;
	
	case SB_PAGEDOWN:
		nNewPos += m_cxVisibleCols ;
		break ;
	
	case SB_PAGEUP:
		nNewPos -= m_cxVisibleCols ;
		break ;
	
	case SB_THUMBPOSITION:
		nNewPos = nPos ;
		break ;
	
	case SB_THUMBTRACK:
		nNewPos = nPos ;
		break ;

	case SB_TOP:
		nNewPos = 0 ;
		break ;

	default:
		return ;
	}

	GetScrollRange( SB_HORZ, &nScrollMin, &nScrollMax ) ;
	nNewPos = min( nScrollMax, max( nScrollMin, nNewPos ) ) ;

	if (nNewPos != nOldPos )
	{
		SetTopIndex( m_nTopCellRow * m_nNumCols + nNewPos ) ;
	}
}
示例#8
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
//
// Description:   Message handler for WM_VSCROLL
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* ) 
{
	int nScrollMin, nScrollMax ;
//	int nOldPos = GetScrollPos( SB_VERT ) ; 
	int nNewPos = GetScrollPos( SB_VERT ) ;

	switch (nSBCode)
	{
	case SB_BOTTOM:
		nNewPos = GetCount() ;
		break ;

	case SB_LINEDOWN:
		nNewPos += 1 ;
		break ;
	
	case SB_LINEUP:
		nNewPos -= 1 ;
		break ;
	
	case SB_PAGEDOWN:
		nNewPos += m_cxVisibleRows ;
		break ;
	
	case SB_PAGEUP:
		nNewPos -= m_cxVisibleRows ;
		break ;
	
	case SB_THUMBPOSITION:
		nNewPos = nPos ;
		break ;
	
	case SB_THUMBTRACK:
		nNewPos = nPos ;
		break ;

	case SB_TOP:
		nNewPos = 0 ;
		break ;

	default:
		return ;
	}

	GetScrollRange( SB_VERT, &nScrollMin, &nScrollMax ) ;
	nNewPos = min( nScrollMax, max( nScrollMin, nNewPos ) ) ;

//	if (nNewPos != nOldPos )	
	SetTopIndex( nNewPos * m_nNumCols ) ;
}
示例#9
0
void CDropListBox::SetTopIdx(int nPos, BOOL bUpdateScrollbar)
{
	m_nLastTopIdx = nPos;
	SetTopIndex( nPos );
	if( bUpdateScrollbar )
	{
		SCROLLINFO info;
		info.cbSize = sizeof(SCROLLINFO);
		if( m_pScroll->GetScrollInfo( &info, SIF_ALL|SIF_DISABLENOSCROLL ) )
		{
			info.nPos = m_nLastTopIdx;
			m_pScroll->SetScrollInfo( &info );
		}
	}
}
示例#10
0
void CTDCTaskListCtrl::RestoreSelection(const TDCSELECTIONCACHE& cache)
{
	if (cache.aSelTaskIDs.GetSize() == 0)
	{
		DeselectAll();
		return;
	}

	DWORD dwFocusedTaskID = cache.dwFocusedTaskID;
	ASSERT(dwFocusedTaskID);
	
	if (FindTaskItem(dwFocusedTaskID) == -1)
	{
		dwFocusedTaskID = 0;
		int nID = cache.aBreadcrumbs.GetSize();
		
		while (nID--)
		{
			dwFocusedTaskID = cache.aBreadcrumbs[nID];
			
			if (FindTaskItem(dwFocusedTaskID) != -1)
				break;
			else
				dwFocusedTaskID = 0;
		}
	}
	
	// add focused task if it isn't already
	CDWordArray aTaskIDs;
	aTaskIDs.Copy(cache.aSelTaskIDs);

	if (Misc::FindT(aTaskIDs, dwFocusedTaskID) == -1)
		aTaskIDs.Add(dwFocusedTaskID);

	SetSelectedTasks(aTaskIDs, dwFocusedTaskID);
	
	// restore pos
	if (cache.dwFirstVisibleTaskID)
		SetTopIndex(FindTaskItem(cache.dwFirstVisibleTaskID));
}
示例#11
0
BOOL CSchemaCombo::OnClickItem(int nItem, BOOL bDown)
{
	if ( nItem > 0 && GetItemData( nItem ) == 0 )
	{
		if ( bDown )
		{
			int nOldTop = GetTopIndex();
			int nDelta = ( nOldTop != CB_ERR && nItem > nOldTop ) ? ( nItem - nOldTop ) : 0;
			DeleteString( nItem );
			Load( m_sPreDrop, m_nType, CSchema::saMax, FALSE );
			int nCurSel = GetCurSel();
			if ( nCurSel != CB_ERR )
			{
				if ( nCurSel >= nDelta )
				{
					SetTopIndex( nCurSel - nDelta );
				}
				SetCurSel( nCurSel );
			}
		}
		return TRUE;
	}
	return FALSE;
}
示例#12
0
//*****************************************************************************
//
// Function Name: RGridCtrlBase::SetCurSel()
//
// Description:   Selects an item and scrolls it into view, if 
//                necessary. When the new item is selected, the 
//                grid control removes the highlight from the 
//                previously selected item. 
//
//                Use this member function only with single-
//                selection grid controls. It cannot be used to 
//                set or remove a selection in a multiple-
//                selection grid control.
//
// Returns:	      LB_ERR if an error occurs.
//
// Exceptions:	   None
//
//*****************************************************************************
int RGridCtrlBase::SetCurSel( int nIndex )
{
	if (nIndex >= GetCount())
		return LB_ERR ;

	int nOldCell    = m_nCurCell ;

	CClientDC dc(this) ;

	CRect rect ;
	GetClientRect( rect ) ;
//	dc.IntersectClipRect( rect ) ;

	// Update the current selection
	m_nCurCell = nIndex ;

	if (LB_ERR != nOldCell)
	{
		// Reset the current selection
		SendDrawItem( dc, nOldCell, ODA_SELECT ) ;
	}
	else if ((CWnd *) this == GetFocus())
	{
		// When the list receives focus and there is no current
		// selection, the first item in the list is displayed
		// with focus, but unselected.  So in this case, we
		// need to go ahead and clear the input focus from this cell.
		SendDrawItem( dc, 0, ODA_FOCUS ) ;
	}

	if (LB_ERR != nIndex)
	{
		CRect rectItem ;

		
		if ((m_nTopCellRow * m_nNumCols) > nIndex)
		{
			// make the new item visible if it is before the existing
			// top index item
			SetTopIndex(nIndex);
		}

		GetItemRect( nIndex, rectItem ) ;

		int nTopRow = m_nTopCellRow ;
		int nTopCol = m_nTopCellCol ;

		if (rectItem.right > rect.right)
		{
			nTopCol += (rectItem.right - rect.right) / m_cxCellWidth + 1 ;
		}

		if (rectItem.bottom > rect.bottom)
		{
			nTopRow += (rectItem.bottom - rect.bottom) / m_cxCellHeight + 1 ;
		}

		if (nTopRow != m_nTopCellRow || nTopCol != m_nTopCellCol)
		{
			SetTopIndex( nTopRow * m_nNumCols + nTopCol ) ;
		}

		// Update the newly selected item
		SendDrawItem( dc, nIndex, ODA_SELECT ) ;
	}

//	dc.SelectClipRgn( NULL ) ;

	return TRUE ;
}
示例#13
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
//
// Description:   Message handler for WM_KEYDOWN.
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnKeyDown(UINT nChar, UINT, UINT) 
{
	int nCurSel = GetCurSel() ;

	int nRowOffset = 0 ;
	int nColOffset = 0 ;

	int nCurRow = nCurSel / m_nNumCols ;
	int nCurCol = nCurSel % m_nNumCols ;

	switch (nChar)
	{
	case VK_UP:
		nRowOffset = -1;
		break ;

	case VK_DOWN:
		nRowOffset = 1 ;
		break ;

	case VK_LEFT:
		nColOffset = -1 ;
		break ;

	case VK_RIGHT:
		nColOffset = 1 ;
		break ;

	case VK_PRIOR:
		nRowOffset = -m_cxVisibleRows ;
		break ;

	case VK_HOME:
		nRowOffset = -nCurRow ;
		nColOffset = -nCurCol ;
		break ;

	case VK_NEXT:
		nRowOffset = m_cxVisibleRows ;
		break ;

	case VK_END:
		nRowOffset = GetCount() / m_nNumCols - nCurRow ;
		nColOffset = GetCount() % m_nNumCols - nCurCol ;
		break ;

	default:

		// See if we're suppose to send it off to the parent
		if (GetStyle() & LBS_WANTKEYBOARDINPUT)
		{
			VKeyToItem( nChar, GetCurSel() ) ;
		}

		return ;
	}

	if (nCurSel < 0)
	{
		//
		// If there was no previously selected item, default
		// to the first item in the list.
		//

		nCurRow = nCurCol = 0 ;
		nRowOffset = nColOffset = 0 ;
	}
	else
	{
		//
		// Determine the new row and column, making sure to
		// keep them within bounds
		//

		nCurRow += nRowOffset ;
		nCurRow = max( 0, min( nCurRow, GetCount() / m_nNumCols ) ) ;
		
		nCurCol += nColOffset ;
		nCurCol = max( 0, min( nCurCol, m_nNumCols - 1 ) ) ;

		if (nCurRow == GetCount() / m_nNumCols)
		{
			nCurCol = min( nCurCol, GetCount() % m_nNumCols - 1 ) ;
		}
	}

	int nNewSel = nCurRow * m_nNumCols + nCurCol ;

	if (nNewSel != nCurSel)
	{

		if (nCurRow < m_nTopCellRow || nCurRow >= m_nTopCellRow + m_cxVisibleRows ||
			 nCurCol < m_nTopCellCol || nCurCol >= m_nTopCellCol + m_cxVisibleCols)
		{
			SetTopIndex( max( 0, GetTopIndex() + (nNewSel - nCurSel) )) ;
		}

		SetCurSel( nNewSel ) ;

		if (GetStyle() & LBS_NOTIFY)
		{
			GetParent()->PostMessage(WM_COMMAND,
				MAKEWPARAM( GetDlgCtrlID(), LBN_SELCHANGE ), 
				(LPARAM) GetSafeHwnd()) ;
		}
	}
}
int CResizableComboBox::MakeIntegralHeight(const int height)
{
    int inth = height;  // integral height (result)
    int availh = height;    // available height
    int n = GetCount();

    DWORD dwStyle = GetStyle();

    if (!m_bIntegralHeight || n == 0)
        return inth;

    if (dwStyle & CBS_OWNERDRAWVARIABLE)
    {
        inth = 0;   // try to reach availh by integral steps
        int i = 0;
        // use items below the first visible
        for (i=GetTopIndex(); availh>0 && i<n; i++)
        {
            int h = GetItemHeight(i);
            if (h == CB_ERR)
                break;

            inth += h;
            availh -= h;
        }
        // to fill the remaining height, use items above
        for (i=GetTopIndex()-1; availh>0 && i>=0; i--)
        {
            int h = GetItemHeight(i);
            if (h == CB_ERR)
                break;

            inth += h;
            availh -= h;
        }
        // scroll into view
        SetTopIndex(i);

        if (!m_bClipMaxHeight) // it can be higher than all the items
        {
            // to fill the remaining height, use last item
            int h = GetItemHeight(n-1);
            if (h != CB_ERR)
            {
                inth += availh - availh % h;
            }
        }
    }
    else
    {
        // every item has the same height (take the first)
        int h = GetItemHeight(0);
        if (h != CB_ERR && n != CB_ERR)
        {
            int rows = availh / h;
            // can't be higher than all the items
            if (m_bClipMaxHeight && rows > n)
                rows = n;
            inth = rows * h;
            // scroll into view
            if (n - rows < GetTopIndex())
                SetTopIndex(n-rows);
        }
    }

    return inth;
}
示例#15
0
LONG CAdvComboBox::OnSetTopIndex( WPARAM wIndex, LPARAM /*lParam*/ )
{
	return SetTopIndex(wIndex);
}
示例#16
0
//=============================================================================	
int CXListBox::AddLine(Color tc, Color bc, LPCTSTR lpszLine)
//=============================================================================	
{
	if (!::IsWindow(m_hWnd))
	{
		ASSERT(FALSE);
		return LB_ERR;
	}

	CString s = lpszLine;

	if (!m_bColor)
	{
		tc = Black;			// to force black-only text
		bc = White;
	}

	UINT nColor = (UINT) tc;
	ASSERT(nColor < 16);
	if (nColor >= 16)
		tc = Black;

	// don't display \r or \n characters
	int i = 0;
	while ((i = s.FindOneOf(_T("\r\n"))) != -1)
		s.SetAt(i, _T(' '));

	if (!s.IsEmpty() && !m_strLogFile.IsEmpty())
	{
		CTime t = CTime::GetCurrentTime();
		CString s2 = t.Format(_T("%Y-%m-%d %H:%M:%S "));
		TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH*2];
		szComputerName[0] = _T('\0');
		DWORD dwSize = sizeof(szComputerName)/sizeof(TCHAR)-1;
		GetComputerName(szComputerName, &dwSize);
		s2 += _T('[');
		s2 += szComputerName;
		s2 += _T("] ");
		s2 += s;
		s2 += _T("\r\n");

		// write string to log file
		HANDLE hFile = ::CreateFile(m_strLogFile, GENERIC_WRITE, FILE_SHARE_WRITE,
							NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile != INVALID_HANDLE_VALUE)
		{
			// set to end of file - always append
			DWORD dwRC = ::SetFilePointer(hFile,		// handle to file
										  0,			// bytes to move pointer
										  NULL,			// bytes to move pointer
										  FILE_END);	// starting point

			if (dwRC != INVALID_SET_FILE_POINTER)
			{
				DWORD dwWritten = 0;
				::WriteFile(hFile,						// handle to file
							s2,							// data buffer
							(DWORD)s2.GetLength()*sizeof(TCHAR),	// number of bytes to write
							&dwWritten,					// number of bytes written
							NULL);						// overlapped buffer
			}

			::CloseHandle(hFile);
		}
	}

	// first character in string is color -- add 1 to color
	// to avoid asserts by CString class
	CString t = _T("");
	t += (TCHAR) (tc + 1);
	t += (TCHAR) (bc + 1);
	t += s;

	// try to add the string to the listbox
	i = CListBox::AddString(t);
	if (i == LB_ERRSPACE)
	{
		// will get LB_ERRSPACE if listbox is out of memory
		int n = GetCount();

		if (n == LB_ERR)
			return LB_ERR;

		if (n < 2)
			return LB_ERR;

		// try to delete some strings to free up some room --
		// don't spend too much time deleting strings, since
		// we might be getting a burst of messages
		n = (n < 20) ? (n-1) : 20;
		if (n <= 0)
			n = 1;

		SetRedraw(FALSE);
		for (i = 0; i < n; i++)
			DeleteString(0);

		i = CListBox::AddString(t);

		SetRedraw(TRUE);
	}

	if (i >= 0)
	{
		SetTopIndex(i);
	}

	SetCurSel(-1);

	return i;
}
示例#17
0
BOOL CDUIListBox::OnKeyDown(const DUIEvent& info)
{
	BOOL bRet(FALSE);
	switch(info.wParam)
	{
// 	case VK_SPACE:
// 	case VK_RETURN:
// 		if(m_nSelectIndex >=0 && m_nSelectIndex < GetControlCount())
// 		{
// 			IDUIListItem* pItem = (IDUIListItem*)GetControlByIndex(m_nSelectIndex)->GetInterface(IListItem);
// 			if(pItem != NULL 
// 				&& pItem->IsVisible()
// 				&& pItem->IsEnabled()
// 				&& pItem->GetGroup())
// 			{
// 				ExpandGroup(m_nSelectIndex, !pItem->GetExpand());
// 			}
// 		}
// 		break;

	case VK_LEFT:
	case VK_UP:
		{
			INT nIndex = m_nSelectIndex;
			while(TRUE)
			{
				--nIndex;
				if(nIndex>=0 && nIndex<GetControlCount())
				{
					if((GetControlByIndex(nIndex)->IsVisible()))
					{
						SetCurSel(nIndex);
						if(nIndex < m_nTopIndex
							|| nIndex >= m_nLastIndex)
						{
							SetTopIndex(nIndex);
						}
						break;
					}
				}
				else
				{
					break;
				}
			}
		}

		bRet = TRUE;
		break;

	case VK_RIGHT:
	case VK_DOWN:
		{
			INT nIndex = m_nSelectIndex;
			while(TRUE)
			{
				++nIndex;
				if(nIndex>=0 && nIndex<GetControlCount())
				{
					if(GetControlByIndex(nIndex)->IsVisible())
					{
						SetCurSel(nIndex);
						if(nIndex >= m_nLastIndex
							|| nIndex < m_nTopIndex)
						{
							INT nTopIndex = m_nTopIndex;
							//SetTopIndex(++nTopIndex);
							SetTopIndex(nIndex);
						}
						break;
					}
				}
				else
				{
					break;
				}
			}

		}
		
		bRet = TRUE;
		break;
	}

	return bRet;
}