TCHAR buffer = new TCHAR (getCodePage (), string, true); newWidth = Math.max (newWidth, OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));
if (font != -1) { int hDC = OS.GetDC (handle); int oldFont = OS.SelectObject (hDC, font); int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; TCHAR tchar = new TCHAR (getCodePage (), string, false); RECT rect = new RECT (); OS.DrawText (hDC, tchar, tchar.length (), rect, flags); OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); newWidth = Math.max (newWidth, rect.right - rect.left); } else { TCHAR buffer = new TCHAR (getCodePage (), string, true); newWidth = Math.max (newWidth, OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer)); }
boolean setScrollWidth (TableItem item, boolean force) {	if (ignoreRedraw) return false;	if (!force && (drawCount != 0 || !OS.IsWindowVisible (handle))) {		fixScrollWidth = true;		return false;	}	fixScrollWidth = false;	int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);	int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	/*	* NOTE: It is much faster to measure the strings and compute the	* width of the scroll bar in non-virtual table rather than using	* LVM_SETCOUMNWIDTH with LVSCW_AUTOSIZE.	*/	if (count == 1 && columns [0] == null) {		int newWidth = 0;		count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);		int index = 0;		int imageIndent = 0;		while (index < count) {			String string = null;			if (item != null) {				string = item.text;				imageIndent = Math.max (imageIndent, item.imageIndent);			} else {				if (items [index] != null) {					string = items [index].text;					imageIndent = Math.max (imageIndent, items [index].imageIndent);				}			}			if (string != null && string.length () != 0) {				TCHAR buffer = new TCHAR (getCodePage (), string, true);				newWidth = Math.max (newWidth, OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));			}			if (item != null) break;			index++;		}		int hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);		if (hStateList != 0) {			int [] cx = new int [1], cy = new int [1];			OS.ImageList_GetIconSize (hStateList, cx, cy);			newWidth += cx [0] + 4;		}		int hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);		if (hImageList != 0) {			int [] cx = new int [1], cy = new int [1];			OS.ImageList_GetIconSize (hImageList, cx, cy);			newWidth += (imageIndent + 1) * cx [0];		}		newWidth += 8;		int oldWidth = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);		if (newWidth > oldWidth) {			OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, newWidth);			return true;		}	}	return false;}