int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn; RECT clipRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, fullText, false, hDC);
RECT clipRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, false, hDC);
void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int lParam) {	int hDC = nmcd.hdc;	int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;	if (hFont == -1) hFont = item.font;	int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;	if (clrText == -1) clrText = item.foreground;	int clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1;	if (clrTextBk == -1) clrTextBk = item.background;	/*	* Bug in Windows.  For some reason, CDIS_SELECTED always set,	* even for items that are not selected.  The fix is to get	* the selection state from the item.	*/	LVITEM lvItem = new LVITEM ();	lvItem.mask = OS.LVIF_STATE;	lvItem.stateMask = OS.LVIS_SELECTED;	lvItem.iItem = nmcd.dwItemSpec;	int result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);	boolean selected = (result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0);	GCData data = new GCData ();	data.device = display;	int clrSelectionBk = -1;	boolean drawSelected = false, drawBackground = false;	if (OS.IsWindowEnabled (handle)) {		if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) {			if (OS.GetFocus () == handle) {				drawSelected = true;				data.foreground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);				data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT);			} else {				drawSelected = (style & SWT.HIDE_SELECTION) == 0;				data.foreground = OS.GetTextColor (hDC);				data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_3DFACE);			}		} else {			drawBackground = clrTextBk != -1;			/*			* Bug in Windows.  When LVM_SETTEXTBKCOLOR or LVM_SETBKCOLOR			* is used to set the background color of the the text or the			* control, the color is not set in the HDC that is provided			* in Custom Draw.  The fix is to explicitly set the background			* color.			*/			if (clrTextBk == -1) {				Control control = findBackgroundControl ();				if (control == null) control = this;				clrTextBk = control.getBackgroundPixel ();			}			data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC);			data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC);		}	} else {		data.foreground = OS.GetSysColor (OS.COLOR_GRAYTEXT);		data.background = OS.GetSysColor (OS.COLOR_3DFACE);		if (selected) clrSelectionBk = data.background;	}	data.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);	data.hBrush = OS.CreateSolidBrush (data.background);	data.hFont = hFont;	int nSavedDC = OS.SaveDC (hDC);	GC gc = GC.win32_new (hDC, data);	RECT cellRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, true, hDC);	Event event = new Event ();	event.item = item;	event.gc = gc;	event.index = nmcd.iSubItem;	event.detail |= SWT.FOREGROUND;	if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {		if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {			if (handle == OS.GetFocus ()) {				int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);				if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;			}		}	}	if (drawSelected) event.detail |= SWT.SELECTED;	if (drawBackground) event.detail |= SWT.BACKGROUND;	event.x = cellRect.left;	event.y = cellRect.top;	event.width = cellRect.right - cellRect.left;	event.height = cellRect.bottom - cellRect.top;	gc.setClipping (event.x, event.y, event.width, event.height);	sendEvent (SWT.EraseItem, event);	event.gc = null;	int clrSelectionText = OS.GetTextColor (hDC);	gc.dispose ();	OS.RestoreDC (hDC, nSavedDC);	if (isDisposed () || item.isDisposed ()) return;	if (event.doit) {		ignoreDrawForeground = (event.detail & SWT.FOREGROUND) == 0;		ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0;		ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;	} else {		ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = true;	}	if (drawSelected) {		if (ignoreDrawSelection) {			if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {				selectionForeground = clrSelectionText;			}			nmcd.uItemState &= ~(OS.CDIS_SELECTED | OS.CDIS_FOCUS);			OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);		}	} else {		if (ignoreDrawSelection) {			nmcd.uItemState |= OS.CDIS_SELECTED;			OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);		}	}	if (ignoreDrawForeground) {		int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);		boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);		boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn;		RECT clipRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, fullText, false, hDC);		if (!ignoreDrawBackground && drawBackground) {			RECT backgroundRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, true, false, hDC);			fillBackground (hDC, clrTextBk, backgroundRect);		}		if (!ignoreDrawSelection && clrSelectionBk != -1) {			RECT textRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, fullText, false, hDC);			fillBackground (hDC, clrSelectionBk, textRect);		}		OS.SaveDC (hDC);		OS.SelectClipRgn (hDC, 0);		OS.ExcludeClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);	}}