Exemple #1
1
void CTreeList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    PULONG  pMagic = (PULONG) lpDrawItemStruct->itemData;

    TCHAR  lpBuffer[256];
    LV_ITEM lvi;
    LV_COLUMN lvc, lvcprev ;

    memset(lpBuffer, 0, 256);
    lvi.mask = LVIF_TEXT | LVIF_PARAM ;
    lvi.iItem = lpDrawItemStruct->itemID ;  
    lvi.iSubItem = 0;
    lvi.pszText = lpBuffer ;
    lvi.cchTextMax = sizeof(lpBuffer);
    GetItem(&lvi);
    ::ZeroMemory(&lvc, sizeof(lvc));
    ::ZeroMemory(&lvcprev, sizeof(lvcprev));
    lvc.mask = LVCF_WIDTH |LVCF_FMT;
    lvcprev.mask = LVCF_WIDTH | LVCF_FMT;

    CDC* pDC;
    pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    int nCol;
    CRect rcText = lpDrawItemStruct->rcItem;

    CFont Fnt, *pOldFont = NULL;
    LOGFONT lf;

    int cyPixels = pDC->GetDeviceCaps(LOGPIXELSY);
    memset(&lf, 0, sizeof(LOGFONT));

    if (pMagic == NULL) {
        return;
    }

    if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) {

        if (IsVistaOrAbove()) {
            lstrcpy(lf.lfFaceName, "MS Sans Serif"); /*Courier New*/
            lf.lfHeight = -MulDiv(8, cyPixels, 72);
            lf.lfWeight = TRUE;
        } else {
            lstrcpy(lf.lfFaceName, "Arial Black"); /*Courier New*/
            lf.lfHeight = -MulDiv(8, cyPixels, 72);
            lf.lfWeight = TRUE;
        }
    } else {
        lstrcpy(lf.lfFaceName, "MS Sans Serif");
        lf.lfHeight = -MulDiv(8, cyPixels, 72);
    }

    Fnt.CreateFontIndirect(&lf);
    pOldFont = (CFont *) pDC->SelectObject(&Fnt);

    /* loading bitmap */
    if (m_hBitmap == NULL) {
        m_hBitmap = (HBITMAP)::LoadImage(GetModuleHandle(NULL), 
                             MAKEINTRESOURCE(IDB_LINE_SEP),
                             IMAGE_BITMAP, 0, 0, 0);

        if (m_hBitmap) {
            m_hMemDC  = ::CreateCompatibleDC(this->GetDC()->m_hDC);
            m_hOldBmp = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap);
        }
    }

    if (TRUE) {

        if (!m_SelectionFlag) {
            for (nCol=0; GetColumn(nCol, &lvc); nCol++) {
                if (nCol > 0) {
                    GetSubItemRect(lpDrawItemStruct->itemID, 
                        nCol,LVIR_BOUNDS, m_SelectionRect);
                } else {
                    GetItemRect(lpDrawItemStruct->itemID, 
                             m_SelectionRect,LVIR_BOUNDS);
                    m_SelectionRect.right = GetColumnWidth(0);
                    m_SelectionRect.left = 0;
                }

                if (m_SelectionRect.PtInRect(m_Point)) {
                    m_SelectionFlag = TRUE;
                    break;
                } else {
                    m_SelectionFlag = FALSE;
                }
            } 
        }
 
        if ((lpDrawItemStruct->itemState & ODS_SELECTED) && m_SelectionFlag ) {

            CRect rc = lpDrawItemStruct->rcItem;
            rc.left  += 4; rc.right -= 4;
            rc.top   += 1; rc.bottom -= 0;
            if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) {
                rc.bottom -= 3; rc.top -= 1;
                rc.right = (rc.Width() * 7 / 8) + rc.left;
            }
            pDC->FillSolidRect(&rc, GetSysColor(m_bFocus ? COLOR_HIGHLIGHT : COLOR_INACTIVEBORDER));
        } else {
            CRect rc = lpDrawItemStruct->rcItem;
            pDC->FillSolidRect(&rc, GetSysColor(COLOR_WINDOW)) ;
            pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ; 
        }
    }

    for (nCol=0; GetColumn(nCol, &lvc); nCol++) {

        UINT  uFormat    = DT_LEFT ;

        if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) {

            rcText = lpDrawItemStruct->rcItem;
            rcText.left += 4;
            rcText.bottom += 1;
            rcText.top = rcText.bottom - 6 + lf.lfHeight;

            ::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), 
                              &rcText, DT_LEFT) ;

            CRect rect = lpDrawItemStruct->rcItem;
            int rc = 0;
            BITMAP  cs;


            rect.top = rcText.bottom - 4;
            rc = ::GetObject(m_hBitmap, sizeof(cs), &cs);
            if (rc == 0) {
                pDC->SelectObject(pOldFont);
                return;
            }

            ::StretchBlt(pDC->m_hDC, rect.left + 4, (rect.bottom + rect.top) / 2,
                         rect.Width() * 7 / 8, cs.bmHeight,
                         m_hMemDC, 0, 0, cs.bmWidth, cs.bmHeight, SRCCOPY);

        } else {

            if (nCol > 0) {
               GetColumn(nCol, &lvcprev) ;
               rcText.left = rcText.right;
               rcText.right += lvcprev.cx;
               rcText.left += 4;

                if (nCol == 3 || nCol == 4) {
                    uFormat = DT_RIGHT;
                    rcText.right -= 4;
                }

            } else {
                rcText = lpDrawItemStruct->rcItem;
                rcText.top += (16 + lf.lfHeight) / 2;
                rcText.right = rcText.left + GetColumnWidth(0);
                rcText.left += 20;
            }

            // Get and draw the text 
            memset(lpBuffer, 0, 256);
            ::ZeroMemory(&lvi, sizeof(lvi));
            lvi.iItem = lpDrawItemStruct->itemID;
            lvi.mask = LVIF_TEXT | LVIF_PARAM;
            lvi.iSubItem = nCol;
            lvi.pszText = lpBuffer;
            lvi.cchTextMax = sizeof(lpBuffer);
            GetItem(&lvi);
   
            ::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), 
                              &rcText, uFormat) ;

            if (nCol == 0) {
                rcText.left -= 20;
            } else {
                rcText.left -= 4;
                if (nCol == 3 || nCol == 4) {
                    rcText.right += 4;
                }
            }
        }
    }

    pDC->SelectObject(pOldFont);

    return;
}
/*******************************************************************************
 Function Name  : pomNumItem
 Inputs         : nRow      - Index of the Row
                  nColumn   - Index of the Column
                  sInfo     - Numeric info like Min val, Max val, Base...
                  Please see the structure definition to get all field info
 Output         : CEdit * - Pointer to the control
 Description    : This function will create and show a numeric edit control with
                  or without spin control
 Member of      : CFlexListCtrl
 Author(s)      : Raja N
 Date Created   : 22.07.2004
 Modifications  :
*******************************************************************************/
CNumEdit *CFlexListCtrl::pomNumItem( int nItem, int nSubItem,
                                     const SNUMERICINFO& sInfo)
{
    CRect omRect;
    // Set the item to be visible
    if(!EnsureVisible(nItem, TRUE))
    { 
        return NULL;    
    }
    // Get the item rect
    GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, omRect);
    // Now scroll if we need to expose the column
    CRect omClientRect;
    GetClientRect(omClientRect);
    if( omRect.left < 0 || omRect.left > omClientRect.right )
    {
        CSize size( omRect.left, 0 );     
        Scroll( size );
        omRect.left -= size.cx;
    }
    omRect.right = omRect.left + GetColumnWidth(nSubItem);
    if(omRect.right > omClientRect.right)
    {
        omRect.right = omClientRect.right;
    }

    // Get Column alignment 
    LV_COLUMN lvcol;
    lvcol.mask = LVCF_FMT;
    GetColumn(nSubItem, &lvcol);

    DWORD dwStyle;
    if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
    {
        dwStyle = ES_LEFT;
    }
    else if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
    {
        dwStyle = ES_RIGHT;
    }
    else 
    {
        dwStyle = ES_CENTER;
    }
    // Set the standard windows style 
    dwStyle |=WS_BORDER|WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
    // Get the selected item text
    CString omStrText = GetItemText(nItem, nSubItem);
    // Create the control
    CNumEdit *pomEdit = NULL;
    pomEdit = new CNumEdit(nItem, nSubItem, omStrText, sInfo);
    if( pomEdit != NULL )
    {
        pomEdit->Create(dwStyle, omRect, this, IDC_CONTROL);
    }
    else
    {
        CString omStrErr;
        omStrErr.Format( defFLC_CREATE_FAILED, defNUM_ITEM );
        AfxMessageBox( omStrErr );
    }
    // Return the window pointer
    return pomEdit;
}
//绘画函数
void CUserListView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CRect rcItem=lpDrawItemStruct->rcItem;
	CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
	int nSavedDC = pDC->SaveDC();
	int iItem=lpDrawItemStruct->itemID;
	int iCount=GetHeaderCtrl()->GetItemCount();
	int iBeen=rcItem.left;
	LV_ITEM lvi;
	lvi.mask = LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = iItem;
	lvi.iSubItem = 0;
	lvi.stateMask = 0xFFFF;     // get all state flags
	GetItem(&lvi);

	BOOL bSelect =((lvi.state & LVIS_DROPHILITED)
		|| ( (lvi.state & LVIS_SELECTED)
		&& ((GetFocus() == this)
		|| (GetStyle() & LVS_SHOWSELALWAYS)
		)
		)
		);
	tagUserData * pUserItem=(tagUserData *)GetItemData(iItem);

	CRect rcBounds, rcLabel, rcIcon;
	GetItemRect(iItem, rcBounds, LVIR_BOUNDS);
	CRect rcHighlight;
	CRect rcWnd;
	GetClientRect(&rcWnd);
	rcHighlight = rcBounds;
	rcHighlight.left = rcLabel.left;
	rcHighlight.right = rcWnd.right +1 ;

	if (bSelect)
	{
		pDC->FillSolidRect(&rcHighlight,RGB(49,105,198)); 
		pDC->SetTextColor(RGB(255,255,255));
	}
	else
	{
		pDC->FillSolidRect(&rcHighlight,RGB(165,189,213)); 
		pDC->SetTextColor(RGB(49,85,132));
	}
	TCHAR szBuffer[1024];
	for (int i=0;i<iCount;i++)
	{

		int iWidth=GetColumnWidth(i);
		GetSubItemRect(iItem,i,LVIR_LABEL,rcItem);
		if (i==1)
		{
			if (m_StatusImage)
			{
				m_StatusImage.Draw(pDC, GetImageStation(pUserItem), 
					CPoint(rcItem.left, rcItem.top),
					ILD_TRANSPARENT |ILC_MASK );
			}
		}
		if (i==2)
		{
			m_pIUserFaceRes->DrawSmallFace(pDC,rcItem.left,rcItem.top,pUserItem->szFace,pUserItem->cbGender);

		}
		GetItemText(iItem,i,szBuffer,sizeof(szBuffer));

		pDC->DrawText(szBuffer,lstrlen(szBuffer),&rcItem,DT_LEFT|DT_END_ELLIPSIS);

	}

	pDC->RestoreDC( nSavedDC );

	return;


	/*	if (lpDrawItemStruct->itemState==0)
	{
	CDC BitmapDC;
	BitmapDC.CreateCompatibleDC(pDC);
	BitmapDC.SelectObject(&m_Bitmap);
	pDC->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BitmapDC,0,0,SRCCOPY);

	}
	else pDC->FillSolidRect(&rcItem,RGB(255,255,255)); 
	*/

}
Exemple #4
0
void MyListCtrl::OnListKeyDown(wxListEvent& event)
{
    long item;

    if ( !wxGetKeyState(WXK_SHIFT) )
    {
        LogEvent(event, wxT("OnListKeyDown"));
        event.Skip();
        return;
    }

    switch ( event.GetKeyCode() )
    {
        case 'C': // colorize
            {
                wxListItem info;
                info.m_itemId = event.GetIndex();
                if ( info.m_itemId == -1 )
                {
                    // no item
                    break;
                }

                GetItem(info);

                wxListItemAttr *attr = info.GetAttributes();
                if ( !attr || !attr->HasTextColour() )
                {
                    info.SetTextColour(*wxCYAN);

                    SetItem(info);

                    RefreshItem(info.m_itemId);
                }
            }
            break;

        case 'N': // next
            item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
            if ( item++ == GetItemCount() - 1 )
            {
                item = 0;
            }

            wxLogMessage(wxT("Focusing item %ld"), item);

            SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
            EnsureVisible(item);
            break;

        case 'R': // show bounding rectangle
            {
                item = event.GetIndex();
                wxRect r;
                if ( !GetItemRect(item, r) )
                {
                    wxLogError(wxT("Failed to retrieve rect of item %ld"), item);
                    break;
                }

                wxLogMessage(wxT("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
                             item, r.x, r.y, r.x + r.width, r.y + r.height);
            }
            break;

        case '1': // show sub item bounding rectangle for the given column
        case '2': // (and icon/label rectangle if Shift/Ctrl is pressed)
        case '3':
        case '4': // this column is invalid but we want to test it too
            if ( InReportView() )
            {
                int subItem = event.GetKeyCode() - '1';
                item = event.GetIndex();
                wxRect r;

                int code = wxLIST_RECT_BOUNDS;
                if ( wxGetKeyState(WXK_SHIFT) )
                    code = wxLIST_RECT_ICON;
                else if ( wxGetKeyState(WXK_CONTROL) )
                    code = wxLIST_RECT_LABEL;

                if ( !GetSubItemRect(item, subItem, r, code) )
                {
                    wxLogError(wxT("Failed to retrieve rect of item %ld column %d"), item, subItem + 1);
                    break;
                }

                wxLogMessage(wxT("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)"),
                             item, subItem + 1,
                             r.x, r.y, r.x + r.width, r.y + r.height);
            }
            break;

        case 'U': // update
            if ( !IsVirtual() )
                break;

            if ( m_updated != -1 )
                RefreshItem(m_updated);

            m_updated = event.GetIndex();
            if ( m_updated != -1 )
            {
                // we won't see changes to this item as it's selected, update
                // the next one (or the first one if we're on the last item)
                if ( ++m_updated == GetItemCount() )
                    m_updated = 0;

                wxLogMessage("Updating colour of the item %ld", m_updated);
                RefreshItem(m_updated);
            }
            break;

        case 'D': // delete
            item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            while ( item != -1 )
            {
                DeleteItem(item);

                wxLogMessage(wxT("Item %ld deleted"), item);

                // -1 because the indices were shifted by DeleteItem()
                item = GetNextItem(item - 1,
                                   wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            }
            break;

        case 'I': // insert
            if ( GetWindowStyle() & wxLC_REPORT )
            {
                if ( GetWindowStyle() & wxLC_VIRTUAL )
                {
                    SetItemCount(GetItemCount() + 1);
                }
                else // !virtual
                {
                    InsertItemInReportView(event.GetIndex());
                }
            }
            //else: fall through

        default:
            LogEvent(event, wxT("OnListKeyDown"));

            event.Skip();
    }
}
//绘画函数
void CUserListView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CRect rcItem=lpDrawItemStruct->rcItem;
	CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
	tagUserData const *pMeUserData = m_pIClientKernel->GetMeUserInfo();

	int iItem=lpDrawItemStruct->itemID;
	int iCount=GetHeaderCtrl()->GetItemCount();
	int iBeen=rcItem.left;
	TCHAR szBuffer[1024];
	tagUserData *pIUserItem = (tagUserData *)GetItemData(iItem);
	GetItemRect(iItem, rcItem, LVIR_LABEL);

	for (int i=0;i<iCount;i++)
	{
		CRect rcSubItem;
		int iWidth=GetColumnWidth(i);

		GetSubItemRect(iItem,i,LVIR_LABEL,rcSubItem);
		if ( i == 0 )
		{
			GetSubItemRect(iItem,i,LVIR_ICON,rcSubItem);
			//如果是焦点(被点击)
			if (lpDrawItemStruct->itemState&ODS_FOCUS) 
				pDC->FillSolidRect(&rcSubItem,RGB(212,204,193)); 
			else 
				pDC->FillSolidRect(&rcSubItem,GetBkColor());

			//如果是焦点(被点击)
			if (lpDrawItemStruct->itemState&ODS_FOCUS)
				pDC->SetTextColor(RGB(0,0,0));
			else if (pIUserItem->dwUserID == pMeUserData->dwUserID)
			{
				if(0 < pIUserItem->cbMemberOrder)
					pDC->SetTextColor(RGB(255,0,0));
				else
					pDC->SetTextColor(RGB(0,0,0));
				pDC->FillSolidRect(&rcSubItem,RGB(225,237,173)); 
			}
			else if ( 0 < pIUserItem->cbMemberOrder /*&& DTP_USER_ACCOUNTS== m_wDataDescribe[i]*/)
			{
				pDC->SetTextColor(RGB(255,0,0));
				pDC->FillSolidRect(&rcSubItem,RGB(251,237,166)); 
			}
			else
				pDC->SetTextColor(RGB(0,0,0));

			//绘画标志
			UINT uImageIndex=GetImageStation(pIUserItem);
			m_StatusImage.Draw(pDC,uImageIndex,CPoint(rcSubItem.left,rcSubItem.top),ILD_TRANSPARENT);

			GetItemText(iItem,i,szBuffer,sizeof(szBuffer));

			GetSubItemRect(iItem,i,LVIR_LABEL,rcSubItem);

			if (lpDrawItemStruct->itemState&ODS_FOCUS) 
				pDC->FillSolidRect(&rcSubItem,RGB(212,204,193));
			else if (pIUserItem->dwUserID == pMeUserData->dwUserID)
			{
				if(0 < pIUserItem->cbMemberOrder)
					pDC->SetTextColor(RGB(255,0,0));
				else
					pDC->SetTextColor(RGB(0,0,0));
				pDC->FillSolidRect(&rcSubItem,RGB(225,237,173)); 
			}
			else if ( 0 < pIUserItem->cbMemberOrder /*&& DTP_USER_ACCOUNTS== m_wDataDescribe[i]*/)
			{
				pDC->FillSolidRect(&rcSubItem,RGB(251,237,166)); 
			}
			else 
				pDC->FillSolidRect(&rcSubItem,GetBkColor());

			rcSubItem.top+=3;
			pDC->DrawText(szBuffer,lstrlen(szBuffer),&rcSubItem,DT_LEFT|DT_END_ELLIPSIS);
		}
		else
		{		
			//如果是焦点(被点击)
			if (lpDrawItemStruct->itemState&ODS_FOCUS)
				pDC->FillSolidRect(&rcSubItem,RGB(212,204,193)); 
			else
				pDC->FillSolidRect(&rcSubItem,GetBkColor());
			//如果是焦点(被点击)
			if (lpDrawItemStruct->itemState&ODS_FOCUS)
				pDC->SetTextColor(RGB(0,0,0));
			else if (pIUserItem->dwUserID == pMeUserData->dwUserID)
			{
				if(0 < pIUserItem->cbMemberOrder)
					pDC->SetTextColor(RGB(255,0,0));
				else
					pDC->SetTextColor(RGB(0,0,0));
				pDC->FillSolidRect(&rcSubItem,RGB(225,237,173)); 
			}
			else if ( 0 < pIUserItem->cbMemberOrder /*&& DTP_GAME_ID == m_wDataDescribe[i]*/)
			{
				pDC->SetTextColor(RGB(255,0,0));
				pDC->FillSolidRect(&rcSubItem,RGB(251,237,166)); 
			}
			else
				pDC->SetTextColor(RGB(0,0,0));

			GetItemText(iItem,i,szBuffer,sizeof(szBuffer));

			CRect rcTempItem =rcSubItem;
			rcTempItem.left +=2; 
			rcTempItem.right +=2; 
			rcTempItem.top +=3; 
			pDC->DrawText(szBuffer,lstrlen(szBuffer),&rcTempItem,DT_LEFT|DT_END_ELLIPSIS);
		}
	}

	//绘画选择
	if (lpDrawItemStruct->itemState&ODS_FOCUS) pDC->DrawFocusRect(&rcItem);

	return;
}
Exemple #6
0
// To reduce flicker, refresh only changed columns (except 
// on Mac, which is double-buffered to eliminate flicker.)
void CBOINCListCtrl::RefreshCell(int row, int col) {
    wxRect r;
    
    GetSubItemRect(row, col, r);
    RefreshRect(r);
}
Exemple #7
0
void CListDocs::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	if(lpDrawItemStruct->itemData<0)
		return;
	
   CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
   CRect rcItem(lpDrawItemStruct->rcItem);
   UINT uiFlags=ILD_TRANSPARENT;
   
   int nItem=lpDrawItemStruct->itemID;
   BOOL bFocus=(GetFocus()==this);
   
   static _TCHAR szBuff[MAX_PATH];
   
   COLORREF  BkText;
   if(lSelRow==lpDrawItemStruct->itemID)
   {
	   BkText = ::GetSysColor(COLOR_HIGHLIGHT);
	   pDC->SetTextColor(RGB(255,255,255));
   }
   else
   {
	   BkText = RGB(255,255,255);	
	   pDC->SetTextColor(RGB(0,0,0));
   }
   CRect rcLabel;
   
   GetItemRect(nItem,rcLabel,LVIR_LABEL);
   UINT nJustify=DT_LEFT;
   

   CBrush b(BkText);
   CRect rcAllLabels;
   GetItemRect(nItem,rcAllLabels,LVIR_BOUNDS);

   LV_ITEM lvi;
          lvi.mask=LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
          lvi.iItem=nItem;
          lvi.iSubItem=0;
          lvi.pszText=szBuff;
          lvi.cchTextMax=sizeof(szBuff);
          lvi.stateMask=0xFFFF;       // get all state flags
          GetItem(&lvi);
       
          BOOL bSelected=(bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
          bSelected=bSelected || (lvi.state & LVIS_DROPHILITED);

	
	
	pDC->FillRect(rcAllLabels,&b);
	
	long lCount;
	lCount = GetHeaderCtrl()->GetItemCount();
	for(int i = 0;i<lCount;i++)
	{
		CString sName = GetItemText(nItem,i);
		GetSubItemRect(nItem,i,LVIR_BOUNDS,rcLabel);
		rcLabel.left = rcLabel.left + 2;
		pDC->DrawText(sName,-1,rcLabel,nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
	}
}
/*******************************************************************************
 Function Name  : pomEditItem
 Inputs         : nRow      - Index of the Row
                  nColumn   - Index of the Column
 Output         : CEdit * - Pointer to the control
 Description    : This function will create and show a editbox.
 Member of      : CFlexListCtrl
 Author(s)      : Raja N
 Date Created   : 22.07.2004
 Modifications  :
*******************************************************************************/
CEdit* CFlexListCtrl::pomEditItem(int nItem, int nSubItem)
{
    // Item rect and Client rect
    CRect omRect, omClientRect;
    // Set the item to be visible
    if(!EnsureVisible(nItem, TRUE))
    {
        return NULL;
    }
    // Get the item rect
    GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, omRect);
    // Now scroll if we need to expose the column
    GetClientRect(omClientRect);
    if( omRect.left < 0 || omRect.left > omClientRect.right )
    {
        CSize size(omRect.left,0);
        Scroll(size);
        omRect.left -= size.cx;
    }

    omRect.right = omRect.left + GetColumnWidth(nSubItem);
    // If the size is bigger then the client size then resizes
    if(omRect.right > omClientRect.right)
    {
        omRect.right = omClientRect.right;
    }

    // Get Column alignment
    LV_COLUMN lvcol;
    lvcol.mask = LVCF_FMT;
    GetColumn(nSubItem, &lvcol);

    DWORD dwStyle;
    // Get the justification style of the list item
    if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
    {
        dwStyle = ES_LEFT;
    }
    else if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
    {
        dwStyle = ES_RIGHT;
    }
    else
    {
        dwStyle = ES_CENTER;
    }
    // Include standard styles
    dwStyle |=WS_BORDER|WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
    // Get the item text
    CString omStrText = GetItemText(nItem, nSubItem);
    // Create the control now
    CEdit* pomEdit = NULL;
    pomEdit = new CEditItem(nItem, nSubItem, omStrText);
    if( pomEdit != NULL )
    {
        pomEdit->Create(dwStyle, omRect, this, IDC_CONTROL);
    }
    else
    {
        CString omStrErr;
        omStrErr.Format( _(defFLC_CREATE_FAILED), defEDIT_ITEM );
        AfxMessageBox( omStrErr );
    }
    // Retrun the window pointer
    return pomEdit;
}
Exemple #9
0
void CEditListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	//draw each item.set txt color,bkcolor....
	NMLVCUSTOMDRAW* pNMLVCustomDraw = (NMLVCUSTOMDRAW*)pNMHDR;

	// Take the default processing unless we set this to something else below.
	*pResult = CDRF_DODEFAULT;

	// First thing - check the draw stage. If it's the control's prepaint
	// stage, then tell Windows we want messages for every item.

	if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
	{
		*pResult = CDRF_NOTIFYITEMDRAW;
	}
	else if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
	{
		// This is the notification message for an item.  We'll request
		// notifications before each subitem's prepaint stage.
		*pResult = CDRF_NOTIFYSUBITEMDRAW;
	}
	else if (pNMLVCustomDraw->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
	{
		// store the colors back in the NMLVCUSTOMDRAW struct
		// but it's effective only when *pResult = CDRF_DODEFAULT 

		//	pNMLVCustomDraw->clrText = RGB(0, 0, 255);
		//	pNMLVCustomDraw->clrTextBk = RGB(0, 255, 0);
		//	*pResult = CDRF_DODEFAULT;

		// This is the prepaint stage for a subitem. Here's where we set the
		// item's text and background colors. Our return value will tell
		// Windows to draw the subitem itself, but it will use the new colors
		// we set here.
		int iItem = (int)pNMLVCustomDraw->nmcd.dwItemSpec;
		int iSubItem = pNMLVCustomDraw->iSubItem;

		if (iSubItem != 1)
		{
			return;
		}

		CDC* pDC = CDC::FromHandle(pNMLVCustomDraw->nmcd.hdc);

		CString strItemText = GetItemText(iItem, iSubItem);
		CRect rcItem, rcText;
		GetSubItemRect(iItem, iSubItem, LVIR_LABEL, rcItem);
		rcText = rcItem;

		CSize size = pDC->GetTextExtent(strItemText);
		if(strItemText == _T(""))
		{
			size.cx = 41; 
		}

		//设置文本高亮矩形
		rcText.left += 4;
		rcText.right = rcText.left + size.cx + 6;
		if(rcText.right > rcItem.right)
		{
			rcText.right = rcItem.right;
		}

		COLORREF crOldTextColor = pDC->GetTextColor();

		//绘制项焦点/高亮效果
		if(m_bFocus)
		{

			if((m_iItem == iItem) && (m_iSubItem == iSubItem))
			{	
				if(m_bHighLight)
				{					
					pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
					pDC->FillSolidRect(&rcText, ::GetSysColor(COLOR_HIGHLIGHT));
				}
				pDC->DrawFocusRect(&rcText);
			}		
		}

		//绘制项文本
		rcItem.left += 6;
		pDC->DrawText(strItemText, &rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP);

		pDC->SetTextColor(crOldTextColor);
		*pResult = CDRF_SKIPDEFAULT;// We've painted everything.
	}	
}
Exemple #10
0
/////////////////////////////////////////////////////////////////////////////
// handle drawing
/////////////////////////////////////////////////////////////////////////////
void CCustomListCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

    BOOL bSelected;
    CDC *pDC;
    CRect rect, colorRect;
    CBrush *pBrush, brush;
    CPen *pPen, pen;
    COLORREF crColor;
    CString str;

    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;

    if(CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage)
    {
        GetClientRect(&rect);

        //get device context
        pDC = CDC::FromHandle(pLVCD->nmcd.hdc);

        //clear background
        pDC->FillSolidRect(&rect, COLOR_BLACK);

        *pResult = CDRF_NOTIFYITEMDRAW;
    }
    else if(CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
    {
        //set the font
        SelectObject(pLVCD->nmcd.hdc, m_font);

        // Tell Windows to paint the control itself.
        *pResult = CDRF_NEWFONT | CDRF_NOTIFYSUBITEMDRAW;
    }
    else if((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage)
    {
        //determine selection
        bSelected = ((int) pLVCD->nmcd.dwItemSpec == m_nSelection);

        //check for highlight
        if(TRUE == bSelected)
        {
            pLVCD->clrTextBk = ::GetSysColor(COLOR_HIGHLIGHT);
            pLVCD->clrText = COLOR_WHITE;
        }
        else
        {
            pLVCD->clrTextBk = COLOR_BLACK;
            pLVCD->clrText = COLOR_WHITE;
        }

        //draw normal
        if(0 != pLVCD->iSubItem)
        {
            *pResult = CDRF_DODEFAULT;
            return;
        }

        pDC = CDC::FromHandle (pLVCD->nmcd.hdc);

        //get item rect
        GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);

        //get correct color information here
        str = GetItemText(pLVCD->nmcd.dwItemSpec, 0);
        crColor = COLORS->getTextColor(atoi(str));

        //create the pen and brush
        pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
        brush.CreateSolidBrush(crColor);

        //select them in
        pPen = pDC->SelectObject(&pen);
        pBrush = pDC->SelectObject(&brush);

        //underdraw
        if(TRUE == bSelected)
        {
            pDC->FillSolidRect(&rect, ::GetSysColor(COLOR_HIGHLIGHT));
        }
        else
        {
            pDC->FillSolidRect(&rect, COLOR_BLACK);
        }

        //set max rect size
        if(rect.Width() > 38)
        {
            rect.right = rect.left + 38;
        }
        else if(rect.Width() < 0)
        {
            rect.right = rect.left;
        }

        //create the color rect
        colorRect = rect;
        colorRect.DeflateRect(4, 2, 7, 2);
        pDC->Rectangle(colorRect);

        //select back old
        pDC->SelectObject(pPen);
        pDC->SelectObject(pBrush);

        *pResult = CDRF_SKIPDEFAULT;
    }
}
void CTDLFindResultsListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	*pResult = CDRF_DODEFAULT;
	LPNMLVCUSTOMDRAW pLVCD = (LPNMLVCUSTOMDRAW)pNMHDR;

	int nItem = (int)pLVCD->nmcd.dwItemSpec;
	int nSubItem = (int)pLVCD->iSubItem;

	switch (pLVCD->nmcd.dwDrawStage)
	{
	case CDDS_PREPAINT:
		*pResult = (CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT);
		break;

	case CDDS_ITEMPREPAINT:
		{
			const FTDRESULT* pRes = (FTDRESULT*)pLVCD->nmcd.lItemlParam;
			ASSERT(pRes);

			// background
			BOOL bHot = IsResultHot(pLVCD->nmcd.rc);
			BOOL bSelected = IsItemSelected(nItem);
			
			if (bSelected || bHot)
			{
				CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
				BOOL bFocused = (GetFocus() == this);

				CRect rRow(pLVCD->nmcd.rc);
				
				// extra for XP
				if (OsIsXP())
					GetItemRect(nItem, rRow, LVIR_BOUNDS);

				GM_ITEMSTATE nState = ((bFocused && bSelected) ? GMIS_SELECTED : GMIS_SELECTEDNOTFOCUSED);
				GraphicsMisc::DrawExplorerItemBkgnd(pDC, *this, nState, rRow, GMIB_THEMECLASSIC);
			}
			
			// set the font once per item
			CFont* pFont = GetResultFont(pRes, bHot);
			ASSERT(pFont);

			if (pFont)
			{
				::SelectObject(pLVCD->nmcd.hdc, pFont->GetSafeHandle());
				*pResult = CDRF_NEWFONT;
			}

			// hide text because we will draw it in SUBITEMPREPAINT
			pLVCD->clrTextBk = pLVCD->clrText = GetSysColor(COLOR_WINDOW);
		}
		*pResult |= CDRF_NOTIFYSUBITEMDRAW;
		break;
		
	case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
		{
			const FTDRESULT* pRes = (FTDRESULT*)pLVCD->nmcd.lItemlParam;
			ASSERT(pRes);

			if (pRes)
			{
				CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
				BOOL bHot = IsResultHot(pLVCD->nmcd.rc);
				BOOL bSelected = IsItemSelected(nItem);

				COLORREF crText = GetResultTextColor(pRes, bSelected, bHot);
				pDC->SetTextColor(crText);

				CRect rRow(pLVCD->nmcd.rc);
				
				// extra for XP
				if (OsIsXP())
					GetSubItemRect(nItem, nSubItem, LVIR_LABEL, rRow);

				pDC->DrawText(GetItemText(nItem, nSubItem), rRow, (DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS));

				// references
				if ((nSubItem == 0) && (pLVCD->nmcd.rc.top > 0) && pRes->IsReference())
				{
					ShellIcons::DrawIcon(pDC, ShellIcons::SI_SHORTCUT, CRect(pLVCD->nmcd.rc).TopLeft());
				}
			}

			*pResult = CDRF_SKIPDEFAULT;
		}
		break;

	default:
		break;
	}
}
void CListViewCtrlEx::_DrawNormalItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem )
{
    if (!pItem)
        return;

    int nItem = lpdis->itemID;

    CDCHandle dc;
    dc.Attach(lpdis->hDC);

    HFONT	hOldFont = dc.SelectFont(m_fontDef);

    BOOL bSelect = FALSE ;
    if ((lpdis->itemAction | ODA_SELECT) &&
            (lpdis->itemState & ODS_SELECTED))
    {
        bSelect = TRUE ;
    }

    if ( bSelect )
        dc.FillSolidRect( &lpdis->rcItem, RGB(185,219,255));
    else
        dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg);

    // draw check box
    if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) )
        _DrawCheckBox(dc, lpdis->rcItem, _super::GetCheckState(nItem), pItem->dwFlags);

    COLORREF oldClr = dc.GetTextColor();
    for(int i=0; i<pItem->subItems.size(); ++i)
    {
        CRect	rcSubItem;
        DWORD	nMarginWidth = 0;
        CRect	rcBounds;
        GetSubItemRect(nItem, i, LVIR_LABEL, &rcSubItem);

        nMarginWidth = LEFT_MARGIN_TEXT_COLUMN+3;

        if(i==0)
        {
            if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) )
            {
                nMarginWidth+=rcSubItem.left;
            }
            else
            {
                rcSubItem.left -= 19;
                nMarginWidth+=5;
            }
        }

#define DT_FLAGS_DRAW_TEXT		(DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|DT_VCENTER)

        rcSubItem.left += LEFT_MARGIN_TEXT_COLUMN;
        rcSubItem.right -= 3;
        const TListSubItem &subItem = pItem->subItems[i];
        if(subItem.type == SUBITEM_LINK)
        {
            dc.SelectFont(m_fontLink);
            dc.SetTextColor(COLOR_LIST_LINK);

            CRect	rcProbeItem;
            dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT);
            dc.DrawText( subItem.str, -1, &rcSubItem, DT_FLAGS_DRAW_TEXT);

            DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth;
            _SetColumnNeedWidth(i,nMaxWidth);
        }
        else
        {
            if (subItem.type == SUBITEM_ICON && subItem.nImg != NULL)
            {
                dc.DrawIconEx( rcSubItem.left, rcSubItem.top + 3, (HICON)subItem.nImg, 16 , 16, 0, 0, DI_NORMAL );
                rcSubItem.left = rcSubItem.left + 18;
            }
            else if (subItem.type == SUBITEM_PNG)
            {
                Gdiplus::Image* pImg = BkPngPool::Get(subItem.nImg);
                if (pImg)
                {
                    Gdiplus::Graphics graphics(dc);

                    SIZE size = {0, 0};
                    if (pImg)
                    {
                        size.cx = pImg->GetWidth();
                        size.cy = pImg->GetHeight();
                    }

                    graphics.DrawImage(pImg, Gdiplus::Rect(rcSubItem.left, rcSubItem.top + 5, size.cx, size.cy));
                }
                rcSubItem.left = rcSubItem.left + 18;
            } else if(subItem.type==SUBITEM_COMBO)
            {
                CDC	dcTmp;
                dcTmp.CreateCompatibleDC(dc);
                HBITMAP hBmpOld	= dcTmp.SelectBitmap(m_bitmapCombo);
                dc.BitBlt(rcSubItem.right-20, rcSubItem.top + 3, 20, 20, dcTmp, 0, 0, SRCCOPY);
                dcTmp.SelectBitmap(hBmpOld);
                dcTmp.DeleteDC();
            }

            UINT uFormat = DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER;
            if (i == 3)
            {
                if (pItem->nLevel == enumLevelRisk)
                {
                    rcSubItem.DeflateRect(2, 3);

                    CPen penBorder;
                    penBorder.CreatePen( PS_SOLID, 1, RGB(224, 0, 0) );
                    CBrush bshInterior;
                    bshInterior.CreateSolidBrush( RGB(224, 0, 0)  );

                    HPEN hOldPen = dc.SelectPen( penBorder );
                    HBRUSH hOldBrush = dc.SelectBrush( bshInterior );

                    dc.RoundRect( rcSubItem, CPoint( 3, 3 ) );
                    dc.SelectPen(hOldPen);
                    dc.SelectBrush(hOldBrush);
                    dc.SetTextColor( RGB(255, 255, 255) );
                }
                else if (pItem->nLevel == enumLevelUnknown)
                {
                    rcSubItem.DeflateRect(2, 3);

                    CPen penBorder;
                    penBorder.CreatePen( PS_SOLID, 1, RGB(250, 115, 5) );
                    CBrush bshInterior;
                    bshInterior.CreateSolidBrush( RGB(250, 115, 5)  );

                    HPEN hOldPen = dc.SelectPen( penBorder );
                    HBRUSH hOldBrush = dc.SelectBrush( bshInterior );

                    dc.RoundRect( rcSubItem, CPoint( 3, 3 ) );
                    dc.SelectPen(hOldPen);
                    dc.SelectBrush(hOldBrush);
                    dc.SetTextColor( RGB(255, 255, 255) );
                }
                else
                    dc.SetTextColor( subItem.clr );

                uFormat = DT_SINGLELINE|DT_CENTER|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER;
            }
            else
                dc.SetTextColor( subItem.clr );

            dc.DrawText( subItem.str, -1, &rcSubItem, uFormat);
            if (subItem.type == SUBITEM_ICON || subItem.type == SUBITEM_PNG)
                rcSubItem.left = rcSubItem.left - 18;

            CRect	rcProbeItem;
            dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT);
            DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth;
            _SetColumnNeedWidth(i,nMaxWidth);
        }
    }

    CPen	penx;
    penx.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine);
    HPEN	penOld = dc.SelectPen(penx);
    dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 );
    CRect rcClient;
    GetClientRect(rcClient);

    dc.LineTo( lpdis->rcItem.left + rcClient.Width(), lpdis->rcItem.bottom-1);
    dc.SelectPen(penOld);

    dc.SelectFont(hOldFont);
    dc.SetTextColor(oldClr);
    dc.Detach();
}
Exemple #13
0
void KGListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
	if (m_nToolTipFlag)
	{
		CString szTipText = _T("");
		CRect	rect;
		SIZE    size;
		int nSubItemCount = 0;
		int nItemPos	  = 0;
		int nCurSubItem	  = 0;
		LPKGLISTITEM lpItem = NULL;
		nItemPos = HitTest(point);
		KG_PROCESS_ERROR(nItemPos != -1);
		nSubItemCount = GetHeaderCtrl()->GetItemCount();
		lpItem = (LPKGLISTITEM)GetItemData(nItemPos);
		KG_PROCESS_ERROR(lpItem);

		ZeroMemory(&size ,sizeof(size));
		if (*(lpItem->szTipText) == '\0')
		{
			for (nCurSubItem = nSubItemCount - 1; nCurSubItem >= 0; nCurSubItem--)
			{
				GetSubItemRect(nItemPos, nCurSubItem, LVIR_BOUNDS, rect);
				if (rect.PtInRect(point))
				{
					szTipText = GetItemText(nItemPos, nCurSubItem);
					CDC* pDC = GetDC();
					if (pDC && pDC->m_hDC)
						GetTextExtentPoint(
						pDC->m_hDC, szTipText.GetBuffer(), szTipText.GetLength(),
						&size
						);
					if (nCurSubItem == nSubItemCount - 1)
					{
						CRect rectClient;
						GetWindowRect(rectClient);
						ScreenToClient(rectClient);
						rect.right = rectClient.right;
						if (size.cx < rect.Width())
						{
							szTipText = _T(""); 
						}
					}
					else
					{
						if (size.cx < GetColumnWidth(nCurSubItem))
						{
							szTipText = _T("");
						}
					}
					break;
				}
			}
		}
		else
		{
			szTipText = lpItem->szTipText;
		}
		m_toolTipCtrl.Activate(TRUE);
		m_toolTipCtrl.UpdateTipText(szTipText.GetBuffer(), this);
		KillTimer(1);
		SetTimer(1, 2000, NULL);
	}

Exit0:
	return CListCtrl::OnMouseMove(nFlags, point);
}
Exemple #14
0
/*******************************************************************************
 Function Name  : pomComboItem
 Inputs         : nRow      - Index of the Row
                  nColumn   - Index of the Column
                  omList    - List of strings
 Output         : CComboItem* - Pointer to the control
 Description    : This function will create and show non editable combo box.This
                  control will be placed over the list item. The combobox will
                  be filled with the data given the omList.
 Member of      : CListCtrlEx
 Author(s)      : Raja N
 Date Created   : 22.07.2004
 Modifications  :
*******************************************************************************/
CComboItem * CListCtrlEx::pomComboItem(int nItem,
                                      int nSubItem,
                                      const CStringArray& omList)
{
    // Get the item text from the list control
    CString strFind = GetItemText(nItem, nSubItem);

    //basic code start
    CRect omRect;
    // Make sure that the item is visible
    if( !EnsureVisible(nItem, TRUE)) 
        return NULL;
    // Get the size of the list item
    GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, omRect);
    // Now scroll if we need to expose the column
    CRect omClientRect;
    // Get the list rect
    GetClientRect(omClientRect);
    // Check for scrolling
    if( omRect.left < 0 || omRect.left > omClientRect.right )
    {
        CSize size;
        size.cx = omRect.left;
        size.cy = 0;
        Scroll(size);
        omRect.left -= size.cx;
    }

    omRect.right = omRect.left + GetColumnWidth(nSubItem);
    // Reduce the size of the control if the list item is not completely
    // Visible
    if(omRect.right > omClientRect.right)
    {
        omRect.right = omClientRect.right;
    }
    //basic code end
    
    //dropdown area
    omRect.bottom += 100;
    
    // Set the standard style and combobox type
    DWORD dwStyle =  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
                     CBS_DROPDOWNLIST;
    // Create the non editable combobox
    CComboItem *pomCBox = NULL;
    // Create the control
    pomCBox = new CComboItem( nItem,        // Item Index
                              nSubItem,     // Sub Item Index
                              omList,       // Lsit of strings
                              strFind,      // Selected Text
                              FALSE);       // Editing is FALSE
    if( pomCBox != NULL )
    {
        // Create the UI
        pomCBox->Create(dwStyle, omRect, this, IDC_CONTROL);
        // Set the text
        pomCBox->SetWindowText(strFind);
        // Select the text from the list
        pomCBox->SelectString(-1 , strFind.GetBuffer(1)); 
        // Show the drop-down list
        pomCBox->ShowDropDown();
    }
    else
    {
        CString omStrErr;
        omStrErr.Format(defFLC_CREATE_FAILED,defCOMBO_ITEM);
        AfxMessageBox( omStrErr );
    }    
    // The return the pointer just for reference
    // Destroy will delete this memory. So this should not be deleted outside
    return pomCBox;
}
Exemple #15
0
void CSCWListCtrl::OnCustomDraw(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
  NMLVCUSTOMDRAW *pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNotifyStruct);

  *pLResult = CDRF_DODEFAULT;

  static bool bchanged_subitem_font(false);
  static CDC *pDC = NULL;
  static COLORREF crWindowText;
  static CFont *pCurrentFont = NULL;
  static CFont *pPasswordFont = NULL;

  switch (pLVCD->nmcd.dwDrawStage) {
    case CDDS_PREPAINT:
      // PrePaint
      crWindowText = GetTextColor();
      pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
      pCurrentFont = Fonts::GetInstance()->GetCurrentFont();
      pPasswordFont = Fonts::GetInstance()->GetPasswordFont();
      *pLResult = CDRF_NOTIFYITEMDRAW;
      break;

    case CDDS_ITEMPREPAINT:
      // Item PrePaint
      *pLResult |= CDRF_NOTIFYSUBITEMDRAW;
      break;

    case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
      // Sub-item PrePaint
      if (pLVCD->iSubItem == 0) {
        CRect rect;
        GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
        if (rect.top < 0) {
          *pLResult = CDRF_SKIPDEFAULT;
          break;
        }
        CRect rect1;
        GetSubItemRect(pLVCD->nmcd.dwItemSpec, 1, LVIR_BOUNDS, rect1);
        rect.right = rect1.left;
        rect.DeflateRect(2, 2);

        CString str = GetItemText(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem);
        pDC->SetTextColor(((pLVCD->nmcd.lItemlParam & REDTEXT) == REDTEXT) ?
                                RGB(255, 0, 0) : crWindowText);

        int iFormat = (pLVCD->nmcd.lItemlParam & 0x0F);
        UINT nFormat = DT_VCENTER | DT_SINGLELINE;
        if (iFormat == LVCFMT_RIGHT)
          nFormat |= DT_RIGHT;
        else if (iFormat == LVCFMT_CENTER)
          nFormat |= DT_CENTER;
        pDC->DrawText(str, &rect, nFormat);
        *pLResult = CDRF_SKIPDEFAULT;
      } else {
        // For Password values
        if ((pLVCD->nmcd.lItemlParam & PASSWORDFONT) == PASSWORDFONT) {
          bchanged_subitem_font = true;
          pDC->SelectObject(pPasswordFont);
        }
        pLVCD->clrText = crWindowText;
        *pLResult |= CDRF_NOTIFYPOSTPAINT;
      }
      break;

    case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
      // Sub-item PostPaint - restore old font if any
      if (bchanged_subitem_font) {
        bchanged_subitem_font = false;
        pDC->SelectObject(pCurrentFont);
        *pLResult |= CDRF_NEWFONT;
      }
      break;

    /*
    case CDDS_PREERASE:
    case CDDS_POSTERASE:
    case CDDS_ITEMPREERASE:
    case CDDS_ITEMPOSTERASE:
    case CDDS_ITEMPOSTPAINT:
    case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
    case CDDS_POSTPAINT:
    */
    default:
      break;
  }
}
Exemple #16
0
/*******************************************************************************
 Function Name  : pomComboList
 Inputs         : nRow      - Index of the Row
                  nColumn   - Index of the Column
                  omList    - List of strings
 Output         : CComboItem* - Pointer to the control
 Description    : This function will create and show editable combo box.This
                  control will be placed over the list item. The combobox will
                  be filled with the data given the omList.
 Member of      : CListCtrlEx
 Author(s)      : Raja N
 Date Created   : 22.07.2004
 Modifications  :
*******************************************************************************/
CComboItem * CListCtrlEx::pomComboList( int nItem,
                                          int nSubItem,
                                          const CStringArray& omList)
{
    // Get the item text from the list control
    CString strFind = GetItemText(nItem, nSubItem);

    //basic code start
    CRect omRect;
    // Make sure that the item is visible
    if( !EnsureVisible(nItem, TRUE)) 
        return NULL;
    // Get the size of the list item
    GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, omRect);
    // Now scroll if we need to expose the column
    CRect omClientRect;
    // Get the list rect
    GetClientRect(omClientRect);
    // Check for scrolling
    if( omRect.left < 0 || omRect.left > omClientRect.right )
    {
        CSize size;
        size.cx = omRect.left;
        size.cy = 0;
        Scroll(size);
        omRect.left -= size.cx;
    }

    omRect.right = omRect.left + GetColumnWidth(nSubItem);
    // Reduce the size of the control if the list item is not completely
    // Visible
    if(omRect.right > omClientRect.right)
    {
        omRect.right = omClientRect.right;
    }
    //basic code end

    //dropdown area
    omRect.bottom += 100;

    // Set the standard style and combobox type
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
                    CBS_DROPDOWN;

    CComboItem *pomCBox = NULL;
    pomCBox = new CComboItem(nItem, nSubItem, omList, strFind, TRUE);
    
    if( pomCBox != NULL )
    {
        // Create the UI control
        pomCBox->Create(dwStyle, omRect, this, IDC_CONTROL);
        // Show the Drop-down list
        pomCBox->ShowDropDown();
        // Set the seleted item text
        pomCBox->SetWindowText(strFind);
        // Select the item from the list. If it is not available the
        // Set the text with out any selection
        if (pomCBox->SelectString(-1, strFind.GetBuffer(1)) == CB_ERR )
        {
            // Set the with out any selection from the list
            pomCBox->SetWindowText(strFind);
        }
    }
    else
    {
        CString omStrErr;
        omStrErr.Format(defFLC_CREATE_FAILED,defCOMBO_LIST);
        AfxMessageBox( omStrErr );
    }
    
    // The returned pointer should not be saved
    return pomCBox;
}
CAlphaCharEdit* CLinFlexListCtrl::pomAlphaNumericChar( int nItem, int nSubItem)
{
    CRect omRect;
    // Set the item to be visible
    if(!EnsureVisible(nItem, TRUE))
    {
        return NULL;
    }
    // Get the item rect
    GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, omRect);

    sUserProgInfo ouUserProg;
    bool bIsIconAvail = false;
    if( m_omUserProg.Lookup(lGetMapID(nItem, nSubItem) , ouUserProg) == TRUE )
    {
        bIsIconAvail = ouUserProg.m_bIcon;
    }

    if ( true == bIsIconAvail )
    {
        CRect omRect2;
        GetSubItemRect(nItem, nSubItem, LVIR_ICON , omRect2);
        omRect.left = omRect2.right;
        //omRect.right = omRect2.right;
    }
    else
    {
        omRect.right = omRect.left + GetColumnWidth(nSubItem);
    }

    // Now scroll if we need to expose the column
    CRect omClientRect;
    GetClientRect(omClientRect);
    if( omRect.left < 0 || omRect.left > omClientRect.right )
    {
        CSize size( omRect.left, 0 );
        Scroll( size );
        omRect.left -= size.cx;
    }

    if(omRect.right > omClientRect.right)
    {
        omRect.right = omClientRect.right;
    }

    // Get Column alignment
    LV_COLUMN lvcol;
    lvcol.mask = LVCF_FMT;
    GetColumn(nSubItem, &lvcol);

    DWORD dwStyle;
    if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
    {
        dwStyle = ES_LEFT;
    }
    else if((lvcol.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
    {
        dwStyle = ES_RIGHT;
    }
    else
    {
        dwStyle = ES_CENTER;
    }
    // Set the standard windows style
    dwStyle |=WS_BORDER|WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
    // Get the selected item text
    CString omStrText = GetItemText(nItem, nSubItem);
    // Create the control
    CAlphaCharEdit* pomEdit2 = NULL;
    SNUMERICINFO info;
    info.m_uMaxVal.m_n64Value = 5;
    info.m_uMaxVal.m_n64Value = 0;
    //omStrText = "";
    CAlphaCharEdit* pomEdit = new CAlphaCharEdit(nItem, nSubItem, omStrText);
    if( pomEdit != NULL )
    {

        pomEdit->Create(WS_BORDER|WS_CHILD | WS_VISIBLE, omRect, this, IDC_CONTROL);
        pomEdit->SetLimitText(1);
        pomEdit->SetFocus();
    }
    else
    {
        CString omStrErr;
        omStrErr.Format( _(defFLC_CREATE_FAILED), defNUM_ITEM );
        AfxMessageBox( omStrErr );
    }
    // Return the window pointer
    return pomEdit2;
}